nagios報警通知

 1.下載郵件客戶端,測試郵件發送是否正常

# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
# tar -zxvf  sendEmail-v1.56.tar.gz
# cp sendEmail /usr/local/bin
# chmod  0755 /usr/local/bin/sendEmail
# /usr/local/bin/sendEmail  -f [email protected] -t [email protected] -s mail.xxxx.com -u "test"  -m  "error" ;此郵箱發郵件無需添加smtp身份驗證,139郵箱需要
 
 
-f 表示發送者的郵箱
-t 表示接收者的郵箱
-s 表示SMTP服務器的域名或者ip
-u 表示郵件的主題
-xu 表示SMTP驗證的用戶名
-xp 表示SMTP驗證的密碼(注意,這個密碼貌似有限制,例如我用d!5neyland就不能被正確識別)
-m 表示郵件的內容
-cc 表示抄送
-bcc 表示暗抄送
 
 
--------------------------------------------------------------------------
2. 修改commands.cfg, 替換掉原來發送郵件的兩個命令
默認的輸出宏$HOSTOUTPUT$和$SERVICEOUTPUT$只會輸出第一行信息, 我們使用$LONGHOSTOUTPUT$和$LONGSERVICEOUTPUT$輸出完整信息.
注意: 爲了能接受到格式化良好, 且中文無亂碼的超文本郵件, 可以對sendEmail設置 "-o message-content-type=html -o message-charset=utf8" 選項.
# vi  /usr/local/nagios/etc/objects/commands.cfg    
 
define command{
        command_name    notify-host-by-email
        command_line    /usr/local/bin/sendEmail -f 手機號@139.com -t $CONTACTEMAIL$ -s smtp.139.com:25  -u "** Host Alert:$HOSTALIAS$ **" -m "$HOSTNAME$($HOSTALIAS$)的狀>態異常,請及時處理!" -o message-content-type=html -o message-charset=utf8 -xu 手機號@139.com -xp 郵箱密碼
              }
  
# 'notify-service-by-email' command definition
 
define command{
        command_name    notify-service-by-email
        command_line  /usr/local/bin/sendEmail -f 手機號@139.com -t $CONTACTEMAIL$ -s smtp.139.com:25  -u "** Service Alert:$HOSTALIAS$ **" -m "$HOSTNAME$($HOSTALIAS$)的監控項 $SERVICEDESC$ 狀態爲$SERVICESTATE$,請及時處理!" -o message-content-type=html -o message-charset=utf8  -xu 手機號@139.com  -xp 郵箱密碼
              }
 
 
-------------------------------------------------------------------
3.配置接收nagios告警的郵件地址
# vi /usr/local/nagios/etc/objects/contacts.cfg
 
define contact{
        contact_name                     聯繫人名稱
        use                              generic-contact
        alias                            聯繫人別名
        service_notification_period      24x7
        host_notification_period         24x7
        service_notification_options     w,u,c,r,f,s
        host_notification_options        d,u,r,f,s
        service_notification_commands    notify-service-by-email
        host_notification_commands       notify-host-by-email
        email                            手機號@139.com
             }
 
 
define contact{
        contact_name                     聯繫人名稱
        use                              generic-contact
        alias                            聯繫人別名
        service_notification_period      24x7
        host_notification_period         24x7
        service_notification_options     w,u,c,r,f,s
        host_notification_options        d,u,r,f,s
        service_notification_commands    notify-service-by-email
        host_notification_commands       notify-host-by-email
        email                            手機號@139.com
             }
 
 
define contactgroup{
        contactgroup_name              system
        alias                          system
        members                        聯繫人1,聯繫人2
                   }
 
-------------------------------------------------------------------------
 
4.自定義需要監控的主機和相關服務
檢測主機是否宕機
例如:
define host{
        use             windows-server  ; Inherit default values from a template
        host_name       XX服務器      ; The name we're giving to this host
        alias           192.168.12.216  ; A longer name associated with the host
        address         192.168.12.216  ; IP address of the host
添加如下語句
        check_command   check-host-alive
        max_check_attempts  1  ;最大重複檢測失敗次數
        contact_groups  system   ;通知發送組
        normal_check_interval  2   ;正常命令檢測頻率 2分鐘
        notification_interval  0   ;警報發送頻率,0爲只發送一次,10爲每隔10分鐘發送一次
        }
 
檢測相關服務
例如:
define service{
        use                     generic-service
        host_name               XX服務器
        service_description     XX進程
        check_command           check_nt!PROCSTATE!-d SHOWALL -l  OAAdmin.exe
        contact_groups          system  ;選擇需要發送警告的聯繫組
        notification_interval    0     ;選擇重複發送警告的頻率,0爲發送一次,10爲10分鐘發送一次!
}
-----------------------------------------------------------------------------
5. 修改完主配置文件後, 都需要重啓Nagios服務, 重啓前先驗證配置文件是否有誤
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# service nagios reload
如果有問題則查詢Nagios運行日誌, 進行進一步診斷:
#tail -50f /usr/local/nagios/var/nagios.log
 
------------------------------------------------------------------------------
6.短信通知
本文主要通過139郵箱免費的短信提示實現,只用於移動手機
參考:http://storysky.blog.51cto.com/628458/274416
 
 
 
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章