用Escalations限制Nagios警示次數

來源:互聯網
上載者:User

 

用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警示次數的功能就成功實現了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.