標籤:nagios 郵件 警示
目前nagios只能在瀏覽器上查看各個機器各個服務的狀態,當某個機器宕掉或者某個服務宕掉時,我們是不知道的,因為我們不可能時時盯著服務看。這時,就需要用到警示系統了,讓它自動化,當發現問題時及時通知我們。下面配置使用發郵件的方式來實現警示。
在服務端操作!
首先定義郵件接受者。
[[email protected] ~]# vim /etc/nagios/objects/contacts.cfgdefine contact{ contact_name test1 use generic-contact alias email1 email [email protected]}define contact{ contact_name test2 use generic-contact alias email2 email [email protected]}define contactgroup{ contactgroup_name common alias common members test1,test2}
說明:contact.cfg 裡面既可以定義user也可以定義group,先定義兩個user test1和test2,然後把這兩個user加入到common組裡面。發郵件時就發給common組就可以了,這時[email protected]和[email protected]都會收到郵件。
然後在需要警示的服務裡加上contactgroup
[[email protected] ~]# vim /etc/nagios/conf.d/192.168.56.128.cfg
針對check_load服務增加警示配置
define service{ use generic-service host_name 192.168.56.128 service_description check_load check_command check_nrpe!check_load max_check_attempts 5 normal_check_interval 1 contact_groups common notifications_enabled 1 notification_period 24x7 notification_options w,u,c,r}
說明:notifications_enabled 1 表示是否開啟提醒功能。1 為開啟,0 為禁用。一般,這個選項會在主設定檔(nagios.cfg)中定義,效果相同。notification_period 24x7 表示發送提醒的時間段。如果不在定義的時間段內,無論什麼問題都不會發送提醒。notification_options:w,u,c,r 表示service的狀態。w 為 warning,u 為unknown,c 為critical,r 為recovery。類似的還有一個host對應的狀態:d,u,r,f,n。 d 狀態表示DOWN,u 為UNREACHABLE,r 狀態恢複為 OK,f 為flapping,n 為不發送提醒。需要加入到 host 的定義配置裡生效。
編輯完設定檔後,重啟nagios服務
[[email protected] ~]# service nagios restartRunning configuration check...done.Stopping nagios: done.Starting nagios: done.
本文出自 “散宜生的學習筆記” 部落格,請務必保留此出處http://sanyisheng.blog.51cto.com/11154168/1795726
2.3 nagios 配置郵件警示