监控--nagios之 邮件报警(三)

 邮件报警
 
 
 1 install
rpm -ivh /tmp/msmtp-1.4.6-1.el5.scopserv.i386.rpm


2 config
cd  /etc/
vim msmtprc


account default
host smtp.163.com
port 25
from jakback@163.com
tls off
auth login
user jakback@163.com
password 123456
logfile /tmp/msmtp.log


3 mutt  添加
vim /etc/Muttrc
set sendmail="/usr/bin/msmtp"
set from="jakback@163.com"  发信人的邮件地址
set realname="baism"   这个定义的就是你收到邮件后 发信人是谁  发信人的名字

4 mutt+msmtp 测试填写的公网邮箱是否能收到信 
echo "hello" |  mutt -s "test" jakback@163.com
 
 5 nagios 设置
 vim commands.cfg   定义如何报警——报警命令  服务宕机了如何报警   机器宕机了如何报警   
 
#notifu-host-by-host command definition    机器宕机了如何报警
define command{
        command_name    notify-host-by-sms
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mutt -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

# 'notify-service-by-email' command definition  服务宕机了如何报警
define command{
        command_name    notify-service-by-sms
        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" | /usr/bin/mutt -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }


 vim contacts.cfg  报警给谁
 
 define contact {
        contact_name  abc
        alias           abc
        host_notification_period        24x7
        host_notification_options       d,u,r
        service_notification_period     24x7
        service_notification_options    w,u,c,r
        service_notification_commands   notify-service-by-sms
        host_notification_commands      notify-host-by-sms
        email   jakback@163.com
}


设置组  如果多个成员用逗号隔开就行
define contactgroup{
        contactgroup_name       vfast
        alias                   Nagios Administrators
        members                 abc
        }

 vim localhost.cfg  定义报警联系人
 
 define host {
        host_name       instructor.example.com
        alias           dell_R510
        address         192.168.18.248
        check_command   check-host-alive
        notification_options    d,u,r
        check_interval  1
        max_check_attempts      2
        contact_groups  vfast             定义监控主机的时候 加上这句  报警联系人
        notification_interval   10
        notification_period     24x7
}
 
 
 注意:nagios报警中如果出现了监控数据抖动  则默认不报警  做实验的时候关了  在localhost.cfg 定义监控服务的时候将其关了就行   如下例子
 define service {
        host_name       instructor.example.com
        service_description     DISK_io
        check_period    24x7
        normal_check_interval   2
        retry_check_interval    1
        max_check_attempts      2
        notification_period     24x7
        notification_options    w,u,c,r
        check_command   check_nrpe!check_disk_io
        flap_detection_enabled          0     #0代表关闭抖动抑制发邮件的设置
}

可以查看nagios.log日志发现是否报警

tail -f /usr/local/nagios/var/nagios.log


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

撸依天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值