0

I am working on implementing Sensu monitoring ( work with graphite + e-mail alert).. everything is OK but only the email alert part. I managed to get the e-mail system to send out the alert but it in below format: {"id":"a1c608aa-e207-49fe-905d-6037f6db01f2","client":

{"name":"ABC","address":"0.0.0.0","subscriptions":["abc"],"version":"0.23.3","timestamp":1464499552},"check":{"command":"/etc/sensu/plugins/check_load 
-w 8.00,5.00,2.00 -c 
10.00,8.00,3.00","subscribers":["ABC","adef","xyz"],"handlers":["default","email"],"interval":60,"name":"check_CPU_usage","issued":1464499558,"executed":1464499558,"duration":0.005,"output":"CRITICAL 
- load average: 5.54, 5.44, 4.09|load1=5.540;8.000;10.000;0; 
load5=5.440;5.000;8.000;0; load15=4.090;2.000;3.000;0; 
\n","status":2,"history":["1","1","1","1","1","1","1","1","1","1","1","0","1","2","2","2","2","2","2","2","2"],"total_state_change":15},"occurrences":8,"action":"create","timestamp":1464499558}

But both of support team and my teammate would like to have both friendly user format at the first half of the e-mail alert and the raw log OR the only "output" attribute in the second half.

Now my e-mail.json is as below: I know i did try to add "output" here but still does not work..:(

{
  "handlers": {
    "email_devops": {
      "type": "pipe",
      "command": "mail -s \"Development environment sensu alert\" myemail@company.com",
      "severities": ["warning","critical"],
      "output": " Warning : the process of ::name:: had reached to warning threshold"

    }
  }
}

I found some article , i found something about as per link: http://search-devops.com/m/wbRqS5nPvh2WnZfj1&subj=Sensu+alert+in+Html+format

But i still stuck on how to push together..

Please kindly help.

Thanks in advance.

Miss Sumana W.

swongr18
  • 33
  • 6

1 Answers1

0

I suggest you use an additional handler to parse the output, make it use it user-friendly and then sent it by email.

"email_devops": {
  "type": "pipe",
  "command": "my_mail_handler",
  "severities": ["warning","critical"]
}

And then, in "my_mail_handler", which can be a script in any language, but let's say is a ruby script:

#!/opt/sensu/embedded/bin/ruby
require 'json'
require 'net/smtp'

@event = JSON.parse(STDIN.read, :symbolize_names => true)

message = <<MESSAGE_END
From: myemail@company.com
To: myemail@company.com
Subject: Sensu Check Event. Check '#{@event[:check][:name]}' in Node: '#{@event[:client][:name]}' #{@event[:occurrences]} times

Output:
#{@event[:check][:output]}
MESSAGE_END

Net::SMTP.start('localhost') do |smtp|
  smtp.send_message message, 'myemail@company.com', 'myemail@company.com'
end

Naturally, you can explore, use and modify the @event variable to create your subject and body.

Enrique Arriaga
  • 499
  • 2
  • 6
  • Thank you :)... this way does it means i need to have mail server installed in the same sever? I plan to use only mail command (postfix feature).. because i think i did configure the mail server and it seems to have issue.. Right now, i just add body to the mail command and provide the attachment of the log (latest with combination of can, grep, tail) file. – swongr18 Jun 29 '16 at 09:53
  • { "handlers": { "email_alarm": { "type": "pipe", "command": "(echo \":::SENSU ALARM WARNING::: Threshould reach to more than 80%, Please check your application.\n \"; cat /var/log/sensu/sensu-server.log | grep output | grep CheckRabbitMQMessages | tail -1 > /etc/sensu/log/alarm.txt ; uuencode /etc/sensu/log/alarm.txt /etc/sensu/log/alarm.txt) | mail -s \"Development environment sensu alert\" email@company.com ", "severities": ["warning","critical"] } } } – swongr18 Jun 29 '16 at 10:00
  • No need for a mail server installed. In the example I pasted, is all managed by ruby's 'net/smtp'. You probably only need to install this gem (if is not installed yet). – Enrique Arriaga Jun 30 '16 at 22:53
  • Ohh then it is super cool .. :).. i will work on that.. thank you very much – swongr18 Jul 01 '16 at 02:34