nagios报警通知

发布时间:2020-07-31 18:13:50 作者:zdw156
来源:网络 阅读:1280

 1.下载邮件客户端,测试邮件发送是否正常

# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
# tar -zxvf  sendEmail-v1.56.tar.gz
# cp sendEmail /usr/local/bin
# chmod  0755 /usr/local/bin/sendEmail
# /usr/local/bin/sendEmail  -f zzz@qq.com -t xxxx@xxxxxx.com -s mail.xxxx.com -u "test"  -m  "error" ;此邮箱发邮件无需添加smtp身份验证,139邮箱需要
 
 
-f 表示发送者的邮箱
-t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容
-cc 表示抄送
-bcc 表示暗抄送
 
 
--------------------------------------------------------------------------
2. 修改commands.cfg, 替换掉原来发送邮件的两个命令
默认的输出宏$HOSTOUTPUT$和$SERVICEOUTPUT$只会输出第一行信息, 我们使用$LONGHOSTOUTPUT$和$LONGSERVICEOUTPUT$输出完整信息.
注意: 为了能接受到格式化良好, 且中文无乱码的超文本邮件, 可以对sendEmail设置 "-o message-content-type=html -o message-charset=utf8" 选项.
# vi  /usr/local/nagios/etc/objects/commands.cfg    
 
define command{
        command_name    notify-host-by-email
        command_line    /usr/local/bin/sendEmail -f 手机号@139.com -t $CONTACTEMAIL$ -s smtp.139.com:25  -u "** Host Alert:$HOSTALIAS$ **" -m "$HOSTNAME$($HOSTALIAS$)的状>态异常,请及时处理!" -o message-content-type=html -o message-charset=utf8 -xu 手机号@139.com -xp 邮箱密码
              }
  
# 'notify-service-by-email' command definition
 
define command{
        command_name    notify-service-by-email
        command_line  /usr/local/bin/sendEmail -f 手机号@139.com -t $CONTACTEMAIL$ -s smtp.139.com:25  -u "** Service Alert:$HOSTALIAS$ **" -m "$HOSTNAME$($HOSTALIAS$)的监控项 $SERVICEDESC$ 状态为$SERVICESTATE$,请及时处理!" -o message-content-type=html -o message-charset=utf8  -xu 手机号@139.com  -xp 邮箱密码
              }
 
 
-------------------------------------------------------------------
3.配置接收nagios告警的邮件地址
# vi /usr/local/nagios/etc/objects/contacts.cfg
 
define contact{
        contact_name                     联系人名称
        use                              generic-contact
        alias                            联系人别名
        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                            手机号@139.com
             }
 
 
define contact{
        contact_name                     联系人名称
        use                              generic-contact
        alias                            联系人别名
        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                            手机号@139.com
             }
 
 
define contactgroup{
        contactgroup_name              system
        alias                          system
        members                        联系人1,联系人2
                   }
 
-------------------------------------------------------------------------
 
4.自定义需要监控的主机和相关服务
检测主机是否宕机
例如:
define host{
        use             windows-server  ; Inherit default values from a template
        host_name       XX服务器      ; The name we're giving to this host
        alias           192.168.12.216  ; A longer name associated with the host
        address         192.168.12.216  ; IP address of the host
添加如下语句
        check_command   check-host-alive
        max_check_attempts  1  ;最大重复检测失败次数
        contact_groups  system   ;通知发送组
        normal_check_interval  2   ;正常命令检测频率 2分钟
        notification_interval  0   ;警报发送频率,0为只发送一次,10为每隔10分钟发送一次
        }
 
检测相关服务
例如:
define service{
        use                     generic-service
        host_name               XX服务器
        service_description     XX进程
        check_command           check_nt!PROCSTATE!-d SHOWALL -l  OAAdmin.exe
        contact_groups          system  ;选择需要发送警告的联系组
        notification_interval    0     ;选择重复发送警告的频率,0为发送一次,10为10分钟发送一次!
}
-----------------------------------------------------------------------------
5. 修改完主配置文件后, 都需要重启Nagios服务, 重启前先验证配置文件是否有误
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# service nagios reload
如果有问题则查询Nagios运行日志, 进行进一步诊断:
#tail -50f /usr/local/nagios/var/nagios.log
 
------------------------------------------------------------------------------
6.短信通知
本文主要通过139邮箱免费的短信提示实现,只用于移动手机
参考:http://storysky.blog.51cto.com/628458/274416
 
 
 
 
 
推荐阅读:
  1. Nagios设置报警间隔
  2. nagios邮件报警配置

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

通知 报警 na

上一篇:Ubuntu 创建开机自启动脚本的方法

下一篇: SHELL DATE 命令详解

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》