溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

nagios使用sendEmail郵件報警

發布時間:2020-07-13 23:11:16 來源:網絡 閱讀:626 作者:z597011036 欄目:移動開發

1.下載安裝sendEmail工具

[root@db02 ~]# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
[root@db02 ~]# tar xvf sendEmail-v1.56.tar.gz
[root@db02 ~]# mv sendEmail-v1.56/sendEmail /usr/local/bin/sendEmail2
[root@db02 ~]# chmod  755 /usr/local/bin/sendEmail2
[root@db02 ~]# /usr/local/bin/sendEmail2 -f z597011036@126.com -t dick@tingyun.tech -s smtp.126.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu z597011036@126.com -xp z597011036zzz -m test
Jun 01 16:59:03 db02 sendEmail2[27006]: Email was sent successfully!  #測試郵件發送成功
[root@db02 ~]#


2.在nagios中定義聯系人和聯系組

[root@db02 ~]# cd /usr/local/nagios-4.1.1/etc/objects/
[root@db02 objects]# vim contacts.cfg
define contact{
  contact_name       dick    #聯系人姓名
  use      generic-contact      #使用聯系人模板
  alias     dick           #別名
  email   dick@tingyun.tech  #聯系人郵箱
        }
define contact{
   contact_name  rayc          
   use   generic-contact   
   alias  rayc      
   email   rayc@tingyun.tech   
        }
define contact{
   contact_name    tong       
   use        generic-contact   
   alias       tong         
   email     z597011036@qq.com    
        }
define contactgroup{
   contactgroup_name   tingyun   #定義聯系人組
   alias    tingyun
    members    dick,rayc     #組中的成員
   }


3.報警時間,級別設置

[root@db02 objects]# vim templates.cfg    #報警參數設置
define contact{
   name    generic-contact         #定義報警聯系人模板
   service_notification_period     24x7 #服務報警的時間(24小時,7天) 
   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  #服務報警的命令(在command.cfg文件中)

   host_notification_commands     notify-host-by-email 
   register      0      #是否可以繼承               
        }
define host{
   name   generic-host  
   notifications_enabled      1    #是否啟用主機報警
   event_handler_enabled    1    #啟用主機事件程序
   flap_detection_enabled    1  
   process_perf_data            1     #性能數據
   retain_status_information   1     #程序啟動保留狀態信息  
   retain_nonstatus_information    1     #程序啟動保留非狀態信息  

   notification_period             24x7    #報警時間
   register    0      #是否繼承
    }
define host{
   name     linux-server    #自定義模板     
   use     generic-host     #繼承哪個模板
   check_period   24x7     #被選中的時鐘
   check_interval    5         #主機每5分鐘檢查一次
   retry_interval      1         #每隔1分鐘重試檢查一次
    max_check_attempts    10    #檢查每個主機10次
    check_command       check-host-alive   #默認命令檢查主機
    notification_period    workhours   #只通知白天
    notification_interval    120     #每兩個小時發送通知
    notification_options    d,u,r   #只發送特定主機的通知
    contact_groups     tingyun    #發送哪個組
    register    0    #是否被繼承         
     }
define service{
    name   generic-service      #定義模板
    active_checks_enabled   1   #啟動服務檢查
    passive_checks_enabled   1    #啟動被動檢查
    parallelize_check   1        #主動服務檢查(禁用會出現嚴重問題)
    obsess_over_service  1    
    check_freshness      0     #不檢查服務新鮮度   
    notifications_enabled   1    #啟動服務通知
    event_handler_enabled   1    #啟用服務事件
    flap_detection_enabled   1 
    process_perf_data            1    
    retain_status_information     1 
    retain_nonstatus_information    1 
    is_volatile     0    #服務不穩定
    check_period    24x7      #檢查服務時間
    max_check_attempts   3        #重新檢查服務3次
    normal_check_interval  10     #每10分鐘檢查一個服務
    retry_check_interval   2          #每2分鐘再檢查一次
    contact_groups    tingyun      #郵件通知聯系組
    notification_options    w,u,c,r      #發送報警級別
    notification_interval    1               #每1小時重新通知服務
    notification_period        24x7         #通知時間
     register     0     #是否繼承
        }
define service{
    name    local-service       #定義模板 
    use    generic-service      #繼承模板
    max_check_attempts    4    #最多檢查服務4次
    normal_check_interval  5    #正常情況下每5分鐘檢查一下服務
    retry_check_interval     1     #重新檢查該服務需要1分鐘
    register      0      #這只是個模板
    notifications_enabled   1     #啟用報警
    contact_groups     tingyun   #發送聯系組
   }


4.報警腳本編寫

[root@db02 objects]# vim commands.cfg
define command {
     command_name notify-service1-by-email
     command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" | /usr/local/bin/sendEmail2 -f t 發件人郵箱 -t $CONTACTEMAIL$ -s smtp.139.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu 發件人郵箱用戶名 -xp 發件郵箱密碼
}
define command {
     command_name notify-host1-by-email
     command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" | /usr/local/bin/sendEmail2 -f 發件人郵箱 -t $CONTACTEMAIL$ -s smtp.139.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu 發件人郵箱用戶名 -xp 發件郵箱密碼

}

[root@db02 objects]# /etc/init.d/nagios restart
Running configuration check...
Stopping nagios:. done.
Starting nagios: done.
[root@db02 objects]#
nagios使用sendEmail郵件報警

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女