Sensu :希望在同一封电子邮件警报中发送友好的用户警报和原始日志
Sensu : want both friendly user alarm and raw log to be sent in same e-mail alert
我正在实施 Sensu 监控(使用 Graphite + 电子邮件警报).. 一切正常,但只有电子邮件警报部分。我设法让电子邮件系统发出警报,但它的格式如下:
{"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}
但是支持团队和我的队友都希望在电子邮件警报的前半部分具有友好的用户格式,在后半部分具有原始日志或唯一的 "output" 属性。
现在我的 e-mail.json 如下所示:我知道我确实尝试在此处添加 "output" 但仍然不起作用..:(
{
"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"
}
}
}
我找到了一些文章,我发现了一些关于 link 的内容:http://search-devops.com/m/wbRqS5nPvh2WnZfj1&subj=Sensu+alert+in+Html+format
但我仍然坚持如何共同努力..
请帮忙。
提前致谢。
Sumana W 小姐
我建议您使用额外的处理程序来解析输出,使其易于使用,然后通过电子邮件发送。
"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 变量来创建您的主题和正文。
我正在实施 Sensu 监控(使用 Graphite + 电子邮件警报).. 一切正常,但只有电子邮件警报部分。我设法让电子邮件系统发出警报,但它的格式如下: {"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}
但是支持团队和我的队友都希望在电子邮件警报的前半部分具有友好的用户格式,在后半部分具有原始日志或唯一的 "output" 属性。
现在我的 e-mail.json 如下所示:我知道我确实尝试在此处添加 "output" 但仍然不起作用..:(
{
"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"
}
}
}
我找到了一些文章,我发现了一些关于 link 的内容:http://search-devops.com/m/wbRqS5nPvh2WnZfj1&subj=Sensu+alert+in+Html+format
但我仍然坚持如何共同努力..
请帮忙。
提前致谢。
Sumana W 小姐
我建议您使用额外的处理程序来解析输出,使其易于使用,然后通过电子邮件发送。
"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 变量来创建您的主题和正文。