5分钟配置实现Nagios微信、短信和移动APP提醒

通过度娘查询了一堆的Nagios提醒,无非是短信猫,139邮箱,还有飞信等。这些都可能存在:

1. 机房短信猫信号差问题

2. 通过邮箱延迟大问题

其实小编挺烦短信的,为什么?如果监控系统的告警策略设置不到位,或者是告警的关联控制不好,会造成大批量的短信提醒,而且短信是不能拒绝的(如今天不值班),这点Nagios是做不到的。

今天推荐一款免费利器“110云告警”,这款工具的Nagios插件五分钟即可配置实现微信、移动APP、短信、邮件提醒,而且支持多人值班模式。直接上效果图:


注意!下文中默认以“nagios”用户登录到nagios服务器中进行操作


1. 注册110云告警账号

猛戳这里 http://www.110monitor.com


2. 创建一个Nagios应用

创建Nagios应用,并获取appkey,见下图3adac4c9-3a82-76af-7b33-0a0bdf16334d

注意!建议告警关闭时间大于Nagios告警提醒间隔,如90分钟,超过90分钟如果告警不再重复发生会自动关闭。



3. 下载Agent

请在nagios服务器中,使用nagios用户下载软件,下文中默认使用nagios用户操作。下载agent

wget http://cdn.110monitor.com/open/download/alert-agent-4.0.1-RC1.tar.gz

4. 安装Agent

注意!下文以nagios默认安装路径/usr/local/nagios/为例,如果你的Nagios服务器不是安装在该目录,请自行替换。

tar xvf alert-agent-4.0.1-RC1.tar.gz
cp -R alert-agent /usr/local/nagios/libexec/
cp alert-agent/plugin/nagios-plugin/nagios /usr/local/nagios/libexec/
chmod +x /usr/local/nagios/libexec/nagios
cp alert-agent/plugin/nagios-plugin/110monitor.cfg /usr/local/nagios/etc/objects/


5. 修改配置

修改/usr/local/nagios/etc/objects/110monitor.cfg,设置pager为上面应用的appkey: 3adac4c9-3a82-76af-7b33-0a0bdf16334d

vi /usr/local/nagios/etc/objects/110monitor.cfg

<span style="color:#333333;">define contact{
        contact_name                    110monitor                 ; The name of this contact template
        alias                           110monitor                 ;
        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-110monitor ; send service notifications via email
        host_notification_commands      notify-host-by-110monitor    ; send host notifications via email
        pager                           </span><span style="color:#ff0000;">3adac4c9-3a82-76af-7b33-0a0bdf16334d</span><span style="color:#333333;"> ; your nagios app key
        }</span>

修改/usr/local/nagios/etc/objects/contacts.cfg,新增110monitor到默认联系组

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

<span style="color:#333333;">define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin,</span><span style="color:#ff0000;">110monitor</span><span style="color:#333333;">
        }	</span>
修改/usr/local/nagios/etc/nagios.cfg,将110monitor.cfg新增到nagios.cfg中

vi /usr/local/nagios/etc/nagios.cfg
<span style="color:#ff0000;">cfg_file=/usr/local/nagios/etc/objects/110monitor.cfg</span>
可选为了让告警信息显示更友好,建议修改nagios.cfg由原先us更改为iso8601

<span style="color:#333333;">date_format=</span><span style="color:#ff0000;">iso8601</span>


5. 重启nagios

请使用root账号重启Nagios

service nagios restart

6. 验证测试

登录Nagios页面控制台发送通知

注意!请确认对应服务的notifications_enabled为1。

<span style="color:#333333;">define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Tomcat18080
        check_command                   check_http18080
        notifications_enabled           </span><span style="color:#ff0000;">1</span><span style="color:#333333;">
        }</span>

查看agent日志,出现sucess字样代表成功,如果发送的告警通知,则会同步发送微信、移动app、短信、邮件

tail -f /usr/local/nagios/libexec/alert-agent/log/agent.log

正常返回success即表示成功

10-05-2015 15:48:53,056 CST INFO  [main] [com.upyoo.agent.NagiosClient@45] start to call alert ...
10-05-2015 15:48:53,063 CST INFO  [main] [com.upyoo.agent.CommandClient@82] alarmName:PROBLEM Service Alert: 127.0.0.1/Tomcat18080 is CRITICAL
10-05-2015 15:48:53,064 CST INFO  [main] [com.upyoo.agent.CommandClient@82] alarmContent:localhost/127.0.0.1/Tomcat18080 connect to address 127.0.0.1 and port 18080: Connection refused Date/Time: 2015-05-10 15:48:52
10-05-2015 15:48:53,064 CST INFO  [main] [com.upyoo.agent.CommandClient@82] entityName:127.0.0.1/Tomcat18080
10-05-2015 15:48:53,066 CST INFO  [main] [com.upyoo.agent.CommandClient@82] priority:CRITICAL
10-05-2015 15:48:53,066 CST INFO  [main] [com.upyoo.agent.CommandClient@82] app:9c4bc722-6677-9fc9-fbdc-003d8977d17e
10-05-2015 15:48:53,067 CST INFO  [main] [com.upyoo.agent.CommandClient@82]
10-05-2015 15:48:53,068 CST INFO  [main] [com.upyoo.agent.CommandClient@82]
10-05-2015 15:48:53,068 CST INFO  [main] [com.upyoo.agent.CommandClient@82]
10-05-2015 15:48:53,069 CST INFO  [main] [com.upyoo.agent.CommandClient@82]
10-05-2015 15:48:53,105 CST INFO  [main] [com.upyoo.agent.CommandClient@58] start to post url:http://api.110monitor.com/alert/api/event
10-05-2015 15:48:53,180 CST INFO  [main] [com.upyoo.agent.CommandClient@65] body:{"app":"9c4bc722-6677-9fc9-fbdc-003d8977d17e","alarmContent":"localhost/127.0.0.1/Tomcat18080 connect to address 127.0.0.1 and port 18080: Connection refused Date/Time: 2015-05-10 15:48:52","eventId":"8G8OGOYUCOOLOENYOGGENOOOOONYNOLU","priority":"3","alarmName":"PROBLEM Service Alert: 127.0.0.1/Tomcat18080 is CRITICAL","eventType":"trigger","entityName":"127.0.0.1/Tomcat18080"}
10-05-2015 15:48:53,775 CST INFO  [main] [com.upyoo.agent.CommandClient@68] result:{"result":"success","message":null,"data":"3516","totalCount":0,"code":"200"}
		

7.完成

恭喜你 完成Nagios集成配置,微信即可接收告警提醒,并通过”我的告警“查询所有未处理告警哦。

注意!注册完毕后默认仅发送邮件提醒,请关注微信号alert110,或者到”用户“->“具体用户”下配置短信提醒规则。

现在公测阶段短信100条/月,微信和移动APP提醒无限量,高级功能如排班免费用










阅读更多

没有更多推荐了,返回首页