nagios实现邮件、短信警报设置

本文详细介绍了如何配置Nagios实现邮件和短信警报。首先,确保Nagios服务正常运行并能监控客户端,然后安装和配置sendmail邮件服务进行测试。接着,编辑contact.cfg和commands.cfg文件以设置警报通知,包括添加管理员邮箱和创建联系人组。通过示例配置展示了如何为不同服务和主机指定联系人组,以便在出现故障时发送警报。此外,还讨论了如何调整Nagios的检测间隔时间。
摘要由CSDN通过智能技术生成

1. 确保nagios服务能成功启动和访问。并且能够监控客户端。

2.

1)安装sendmail或postfix等邮件服务(这里以sendmail为例)。

1 安装sendmail组件
首先要确保sendmail相关组件的完整安装,我们可以使用如下的命令来完成sendmail的安装:
# yum install -y sendmail*
然后重新启动sendmail服务:
# service sendmail restart
然后发送测试邮件,验证sendmail的可用性:
# echo "Hello World" | mail xxxxxxxx@139.com

# echo "Hello World" | mail xxxxxxxx@163.com

最好是申请两个邮箱做测试。意为两个管理人员。


2) 配置。警报配置只需要在服务器端配置即可。需要编辑的文件有:

1./usr/local/nagios/etc/object下的contact.cfg

2./usr/local/nagios/etc/object下的commands.cfg (经测试,这个文件不用编辑,还没研究透)

如果你不放心,可以加多以下这些代码。其他不用改动。

#define command{
 #       command_name    notify-by-email
  #      command_line    /usr/bin/printf "%b" "***** Nagios 2.9 *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $
HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendmail -f nagios@test.com -t $CONTACTEMAIL$
 -s mail.test.com -u "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu nagios -xp p#3isoda
   #     }

注释掉了还是能成功的,有待研究 ~~  网上说法太不统一了


2) 成功案例配置:

[root@bogon objects]# cat contacts.cfg
define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user
        email                           nagios@localhost        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin
        }





#######################################################################################
#######################################################################################
##############   SYSTEM ADMINISTRATOR MEMBERS
#######################################################################################
#######################################################################################

define contact{
        contact_name                        li1
        use                                        generic-contact
        alias                                       li1
        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                                       15218402325@139.com
        }

define contact{
        contact_name                           li2
        use                                          generic-contact
        alias                                         li2
        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                                          15218402325@163.com
        }




#######################################################################################
#######################################################################################
##############   SYSTEM ADMINISTRATOR GROUP
#######################################################################################
#######################################################################################
define contactgroup{
        contactgroup_name              system
        alias                                     system
        members                              li1,li2
        }
[root@bogon objects]# 


     以上意思是将两个管理员 li1、li2放到一个组system里。有意思了,可以按组来

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值