nagios設置郵件告警

搭建nagios的目的就是爲了他的報警系統,nagios據我所瞭解可以有三種報警:
一、聲音報警
二、電子郵件報警
三、手機短訊報警
      四、傳真告警
下面是我的郵件報警的配置過程:
1、開啓系統自帶的sendmail郵件系統
service sendmail start
如果沒有安裝,可以yum一下
yum install -y sendmail*
service sendmail restart
測試發送郵件:
echo "test" | mail [email protected]
注:iptables和selinux設置
2、配置nagios中報警郵箱
vi /usr/local/nagios/etc/objects/contacts.cfg
         define contact{
         contact_name                    mail                    ; Short name of user
         alias                           null             ; Full name of user
        service_notification_period     24x7 (和如下時間模版(timeperiod)保持一致)
         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                           [email protected]
         }
在email那裏加上自己的郵箱,如果有多個可以用逗號隔開
3、設置報警方式:
define timeperiod{
        timeperiod_name 24x7
        alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
        monday          00:00-24:00
        tuesday         00:00-24:00
        wednesday       00:00-24:00
        thursday        00:00-24:00
        friday          00:00-24:00
        saturday        00:00-24:00
        }
這兩個notify-service-by-email 和  notify-host-by-email    是在command.cfg那裏定義的,看看是怎麼定義的:# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line      echo " ** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$HOSTADDRESS$ $SERVICEDESC$ is $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$ Additional Info:$SERVICEOUTPUT$ "| formail -I "Subject: $HOSTADDRESS$*$SERVICEOUTPUT$*$LONGDATETIME$"| sendmail -oi $CONTACTEMAIL$
        }

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }
這裏已經默認配置好,我們不用修改直接調用就是了
最後重啓服務:
service nagios retart 
      進行破環性測試!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章