Nagios安装包部署方式

1.添加应用

创建Nagios应用,并获取appkey,见下图e8aac304-ae83-81f2-14c0-d6621ef0ed23

2.下载Agent软件包

请在nagios服务器中,使用root或nagios用户下载软件。

wget http://cdn.onealert.com/open/download/4.1.3.1/alert-agent-4.1.3.1-linux-x64.tar.gz

3.安装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/

4.修改配置

修改/usr/local/nagios/etc/objects/110monitor.cfg,设置pager为上面应用的appkey: e8aac304-ae83-81f2-14c0-d6621ef0ed23

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

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                           3adac4c9-3a82-76af-7b33-0a0bdf16334d ; your nagios app key
    }

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

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

define contactgroup{
    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 nagiosadmin,110monitor
    }       

修改/usr/local/nagios/etc/nagios.cfg,将110monitor.cfg新增到nagios.cfg中

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

cfg_file=/usr/local/nagios/etc/objects/110monitor.cfg

可选为了让告警信息显示更友好,建议修改nagios.cfg由原先us更改为iso8601

date_format=iso8601

5.重启nagios

重启前检查下配置是不是正确.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

请使用root账号重启Nagios

service nagios restart

6.测试验证

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

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

define service{
    use                             local-service         ; Name of service template to use
    host_name                       localhost
    service_description             Tomcat18080
    check_command                   check_http18080
    notifications_enabled           1
    }

查看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.onealert.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"}

完成

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

注意!注册完毕后默认仅发送邮件提醒

亲,到现在可以抛弃老的139邮箱、飞信、短信猫、qq邮箱等间接短信配置提醒方式。


相关链接:

若在nagios新触发测试告警后,onealert平台无法看到告警,请点击所有告警,确认是否有告警?:

  1. 若有,则说明告警已成功发送到onealert平台,需要您在配置->分派策略那添加分派策略;
  2. 若无,则说明告警未成功发送到onealert平台,点击查看安装排错文档

如果您对 OneAlert 感兴趣,可以选择使用我们的产品,只需要点击下面的按钮免费注册即可。


注册,永久免费使用 OneAlert