Nagios郵件報警配置

一、安裝sendmail組件

首先要確保sendmail相關組件的完整安裝,我們可以使用如下的命令來完成sendmail的安裝:

#?yum?install?-y?sendmail*

然后重新啟動sendmail服務:

#?service?sendmail?restart

二、郵件報警的配置

下面是我的郵件報警的配置過程:

1、開啟系統自帶的sendmail郵件系統

#service?sendmail?start

測試發送郵件:

echo?"test"?|?mail [email protected]*******.cn

我系統在關掉iptables和selinux前提下是正常的

2、配置nagios中報警郵箱

vi?/var/www/html/nagios/etc/objects/contacts.cfg

  1. define?contact{
  2. ????????contact_name????????????????????nagiosadmin?????????????;?Short?name?of?user
  3. ????????use?????????????????????????????generic-contact?????????;?Inherit?default?values?from?generic-contact?template?(defined?above)
  4. ????????alias???????????????????????????Nagios?Admin????????????;?Full?name?of?user
  5. ????????email???????????????????????????[email protected]????????;?<<*****?CHANGE?THIS?TO?YOUR?EMAIL?ADDRESS?******
  6. ????????}

修改[email protected]為接收郵件地址,如果有多個可以用逗號隔開!

3、設置報警方式

#vi?/var/www/html/nagios/etc/objects/templates.cfg

  1. define?contact{
  2. ????????name????????????????????????????generic-contact?????????;?The?name?of?this?contact?template
  3. ????????service_notification_period?????24x7????????????????????;?service?notifications?can?be?sent?anytime
  4. ????????host_notification_period????????24x7????????????????????;?host?notifications?can?be?sent?anytime
  5. ????????service_notification_options????w,u,c,r,f,s?????????????;?send?notifications?for?all?service?states,?flapping?events,?and?scheduled?downtime?events
  6. ????????host_notification_options???????d,u,r,f,s???????????????;?send?notifications?for?all?host?states,?flapping?events,?and?scheduled?downtime?events
  7. ????????service_notification_commands???notify-service-by-email?;?send?service?notifications?via?email
  8. ????????host_notification_commands??????notify-host-by-email????;?send?host?notifications?via?email
  9. ????????register????????????????????????0???????????????????????;?DONT?REGISTER?THIS?DEFINITION?-?ITS?NOT?A?REAL?CONTACT,?JUST?A?TEMPLATE!
  10. ????????}

這兩個 notify-service-by-email?和 notify-host-by-email 是在commands.cfg那里定義的,看看是怎么定義的:

#vi /var/www/html/nagios/etc/objects/commands.cfg

  1. #?'notify-host-by-email'?command?definition
  2. define?command{
  3. ????????command_name????notify-host-by-email
  4. ????????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$
  5. ????????}
  6. #?'notify-service-by-email'?command?definition
  7. define?command{
  8. ????????command_name????notify-service-by-email
  9. ????????command_line????/usr/bin/printf?"%b"?"*****?Nagios?*****\n\nNotification?Type:?$NOTIFICATIONTYPE$\n\nService:?$SERVICEDESC$\nHost:?$HOSTALIAS$\nAddress:?$HOSTADDRESS$\nState:?$SERVICESTATE$\n\nDate/Time:?$LONGDATETIME$\n\nAdditional?Info:\n\n$SERVICEOUTPUT$"?|?/bin/mail?-s?"**?$NOTIFICATIONTYPE$?Service?Alert:?$HOSTALIAS$/$SERVICEDESC$?is?$SERVICESTATE$?**"?$CONTACTEMAIL$
  10. ????????}

這里已經默認配置好,我們不用修改直接調用就是了

4、最后重啟服務

#service?nagios?restart

然后隨便關掉一些服務測試一下效果!

發表評論

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: