用Escalations限制Nagios警示次數:
Nagios是一款強大的監控工具,特別是他的警示功能,但是如果伺服器出現故障未及時解決,那麼Nagio就不斷得發送訊息。該通過怎麼樣的方式限制Nagios警示次數呢?本文講述的是限制Nagios警示次數技巧(Escalations)。
AD:
巧用escalations限制Nagios警示次數
Nagios是非常強大的一款監控工具,尤其是它的警示功能,現在網上實現的形式多種多樣如結合移動139郵箱、Fetion、MSN等,但是如果伺服器出現故障而未能及時的解決,Nagios就會不斷的發送警示資訊,實在令人頭疼。現在用如下方法可以解決Nagios的警示次數問題。
系統內容:CentOS 5.2
Nagios版本:3.0.6
Nagios安裝路徑:/usr/local/nagios
設定檔內容定義:#基本的配置就不再進行注釋了。
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 //手機郵箱
}
define contactgroup{
contactgroup_name chengnan
alias Nagios Administrators
members chengnan
}
除此之外再定義一個連絡人
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
}
然後建立一個設定檔:
vi escalations.cfg
escalations有自動調整;不斷增加; 逐步上升等意思,本身設定檔的功能是當服務在某一警示次數前沒有恢複,警示頻率周期將會縮短,同時將警示資訊發送至指定連絡人。
其內容為:
define hostescalation{
host_name WWW-Server //被監控主機名稱,與Hosts.cfg中一致
first_notification 4 // 第n條資訊起,改變頻率間隔
last_notification 0 // 第n條資訊起,恢複頻率間隔
notification_interval 30 // 通知間隔(分)
contact_groups ysadmin
}
說明:從第4條警示資訊起至伺服器恢複前,警示資訊發送至sysadmin組下的連絡人,警示間隔為30分鐘1條資訊。
define serviceescalation{
host_name WWW-Server //被監控主機名稱,與Hosts.cfg中一致
service_description Check_HTTP,Check_Jetty //被監控服務名稱,與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
重新啟動nagios服務:
service nagios restart
測試:
伺服器啟動後停掉被監控測試機的相應服務,確認警示資訊是否按照設定發送至不同信箱
總結
escalations這個功能官方給的定義是notification的擴充,使notification變得更加靈活,方便。文中我使用的方法算是耍了個小聰明,將第四條警示資訊後的所有資訊全部發送至我公司郵箱直至伺服器恢複(recovery的資訊還是會發送至手機的),從而實現限制警示資訊發送至手機的條數。這樣,用Escalations限制Nagios警示次數的功能就成功實現了。