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\" [email protected]",
"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.
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: [email protected]
To: [email protected]
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, '[email protected]', '[email protected]'
end
Naturally, you can explore, use and modify the @event variable to create your subject and body.