限制Nagios報(bào)警次數(shù)技巧(Escalations)
巧用escalations限制Nagios報(bào)警次數(shù)
Nagios是非常強(qiáng)大的一款監(jiān)控工具,尤其是它的告警功能,現(xiàn)在網(wǎng)上實(shí)現(xiàn)的形式多種多樣如結(jié)合移動(dòng)139郵箱、Fetion、MSN等,但是如果服務(wù)器出現(xiàn)故障而未能及時(shí)的解決,Nagios就會(huì)不斷的發(fā)送告警信息,實(shí)在令人頭疼?,F(xiàn)在用如下方法可以解決Nagios的告警次數(shù)問(wèn)題。
系統(tǒng)環(huán)境:CentOS 5.2
Nagios版本:3.0.6
Nagios安裝路徑:/usr/local/nagios
配置文件內(nèi)容定義:#基本的配置就不再進(jìn)行注釋了。
- hosts.cfg
- define host{
- host_name WWW-Server
- alias WWW-Server
- address 193.1.16.100
- check_command check-host-alive
- max_check_attempts 5
- check_period 24x7
- notification_interval 10
- notification_period 24x7
- notification_options d,u,r
- notifications_enabled 1
- contact_groups chengnan
- }
- Services.cfg
- define service{
- host_name WWW-Server
- service_description Check_HTTP
- check_command check_http
- max_check_attempts 10
- normal_check_interval 3
- retry_check_interval 2
- check_period 24x7
- notification_interval 5
- notification_period 24x7
- notification_options w,u,c,r
- contact_groups admin
- }
- define service{
- host_name WWW-Server
- service_description Check_Jetty
- check_command check_tcp!8080
- max_check_attempts 10
- normal_check_interval 3
- retry_check_interval 2
- check_period 24x7
- notification_interval 5
- notification_period 24x7
- notification_options w,u,c,r
- contact_groups admin
- }
- Contacts.cfg
- define contact{
- contact_name chengnan
- alias chengnan
- service_notification_period 24x7
- host_notification_period 24x7
- service_notification_options w,u,c,r
- host_notification_options d,u,r
- service_notification_commands notify-service-by-email
- host_notification_commands notify-host-by-email
- email chengnan@139.com //手機(jī)郵箱
- }
- define contactgroup{
- contactgroup_name chengnan
- alias Nagios Administrators
- members chengnan
- }
除此之外再定義一個(gè)聯(lián)系人
- define contact{
- contact_name chengnan_cor
- alias chengnan_cor
- service_notification_period 24x7
- host_notification_period 24x7
- service_notification_options w,u,c,r
- host_notification_options d,u,r
- service_notification_commands notify-service-by-email
- host_notification_commands notify-host-by-email
- email chengnan@company.com //公司郵箱
- }
- define contactgroup{
- contactgroup_name sysadmin
- alias sysadmin
- members chengnan_cor
- }
然后創(chuàng)建一個(gè)配置文件:
- vi escalations.cfg
escalations有自動(dòng)調(diào)整;不斷增加; 逐步上升等意思,本身配置文件的功能是當(dāng)服務(wù)在某一告警次數(shù)前沒(méi)有恢復(fù),告警頻率周期將會(huì)縮短,同時(shí)將告警信息發(fā)送至指定聯(lián)系人。
其內(nèi)容為:
- define hostescalation{
- host_name WWW-Server //被監(jiān)控主機(jī)名稱,與Hosts.cfg中一致
- first_notification 4 // 第n條信息起,改變頻率間隔
- last_notification 0 // 第n條信息起,恢復(fù)頻率間隔
- notification_interval 30 // 通知間隔(分)
- contact_groups sysadmin
- }
說(shuō)明:從第4條告警信息起至服務(wù)器恢復(fù)前,告警信息發(fā)送至sysadmin組下的聯(lián)系人,告警間隔為30分鐘1條信息。
- define serviceescalation{
- host_name WWW-Server //被監(jiān)控主機(jī)名稱,與Hosts.cfg中一致
- service_description Check_HTTP,Check_Jetty //被監(jiān)控服務(wù)名稱,與Services.cfg中一致
- first_notification 4
- last_notification 0
- notification_interval 30
- contact_groups sysadmin
- }
保存
修改nagios.cfg
- vi nagios.cfg
添加:
- cfg_file=/usr/local/nagios/etc/objects/escalations.cfg
檢查nagios配置文件是否正確
- /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
重新啟動(dòng)nagios服務(wù):
- service nagios restart
測(cè)試:
服務(wù)器啟動(dòng)后停掉被監(jiān)控測(cè)試機(jī)的相應(yīng)服務(wù),確認(rèn)告警信息是否按照設(shè)置發(fā)送至不同信箱
總結(jié)
escalations這個(gè)功能官方給的定義是notification的擴(kuò)充,使notification變得更加靈活,方便。文中我使用的方法算是耍了個(gè)小聰明,將第四條告警信息后的所有信息全部發(fā)送至我公司郵箱直至服務(wù)器恢復(fù)(recovery的信息還是會(huì)發(fā)送至手機(jī)的),從而實(shí)現(xiàn)限制告警信息發(fā)送至手機(jī)的條數(shù)。這樣,用Escalations限制Nagios報(bào)警次數(shù)的功能就成功實(shí)現(xiàn)了。