nagios发邮件-sendmail

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

# echo "Hello World" | mail abc@abc.com(这里qq邮箱不行)

2、配置nagios中报警邮箱

vi /usr/local/nagios/etc/objects/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                           lihuipeng007@163.com   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }

在email那里加上自己的邮箱,如果有多个可以用逗号隔开

3、设置报警方式:

 vi /usr/local/nagios/etc/objects/templates.cfg

 define contact{
        name                            generic-contact         ; The name of this contact template
        service_notification_period     24x7                    ; service notifications can be sent anytime
        host_notification_period        24x7                    ; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands   notify-service-by-email ; send service notifications via email
        host_notification_commands      notify-host-by-email    ; send host notifications via email
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        }
这两个 notify-service-by-email     notify-host-by-email     是在command.cfg那里定义的,看看是怎么定义的:

# '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$
        }

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        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$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

这里已经默认配置好,我们不用修改直接调用就是了

最后重启服务:

 service nagios retart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装Nagios客户端,您可以按照以下步骤进行操作: 1. 在要安装Nagios客户端的目标计算机上,打开终端或命令提示符。 2. 在终端或命令提示符中,使用适合您的操作系统的包管理工具来安装Nagios客户端软件包。例如,对于基于Debian/Ubuntu的系统,可以使用以下命令安装: ``` sudo apt-get install nagios-nrpe-server ``` 对于基于Red Hat/CentOS的系统,可以使用以下命令安装: ``` sudo yum install nrpe ``` 3. 安装完成后,需编辑Nagios客户端配置文件以指定监控项和允许监控的Nagios服务器。请在终端或命令提示符中使用文本编辑器打开配置文件。例如,在基于Debian/Ubuntu的系统上,可以运行以下命令: ``` sudo nano /etc/nagios/nrpe.cfg ``` 4. 在配置文件中,您可以添加或修改监控项,例如检查远程主机的CPU使用率、内存使用率等。您还需要指定允许连接的Nagios服务器的IP地址。保存并关闭配置文件。 5. 重新启动Nagios客户端服务以应用更改。例如,在基于Debian/Ubuntu的系统上,可以使用以下命令: ``` sudo systemctl restart nagios-nrpe-server ``` 在基于Red Hat/CentOS的系统上,可以使用以下命令: ``` sudo systemctl restart nrpe ``` 6. 完成后,您的Nagios客户端将准备好接受Nagios服务器的监控请求并提供相关信息。 请注意,这只是一个简单的安装指南。根据您的操作系统和配置需求,可能需要进行其他设置和调整。建议您参考Nagios官方文档或其他相关资源以获得更详细的安装说明和配置指导。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值