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.

4

1 回答 1

0

我建议您使用额外的处理程序来解析输出,使其对用户友好,然后通过电子邮件发送。

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

然后,在“my_mail_handler”中,它可以是任何语言的脚本,但假设是一个 ruby​​ 脚本:

#!/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

当然,您可以探索、使用和修改 @event 变量来创建您的主题和正文。

于 2016-06-28T15:42:35.663 回答