阅读570 返回首页    go 微软 go Office


nagios整合飞信机器人实现短信报警监控服务器

1.下载安装包

apache2.2安装包

https://www.xuningbo.com/wp-content/uploads/2011/12/httpd-2.2.21.tar.gz

fetion机器人程序:(这个是我整理过的,包含libACE程序在内,2011-12-9测试可用)

https://www.xuningbo.com/wp-content/uploads/2011/12/fx.zip

nagios主程序:(用的3.23中文版的,有技术水平的可以到官网下3.3英文版的)

https://www.xuningbo.com/wp-content/uploads/2011/12/nagios-cn-3.2.3.tar.bz2

nagios插件程序:

https://www.xuningbo.com/wp-content/uploads/2011/12/nagios-plugins-1.4.15.tar.gz

php程序:

https://www.xuningbo.com/wp-content/uploads/2011/12/php-5.3.8.tar.gz

 

2、软件的安装

首先安装支持:

[root@localhost httpd-2.2.21]# yum -yinstall gcc gd*

 

 

(1) apache的安装 [root@localhost httpd-2.2.21]# ./configure –prefix=/usr/local/apache –enable-so
[root@localhost httpd-2.2.21]# make && make install

 grep -v “#” /usr/local/apache-2.2.15/bin/apachectl  > /etc/init.d/apache
   用vi编辑Apache服务控制脚本/etc/init.d/apache:
    vi /etc/init.d/apache
   在文件最前面插入下面的行,使其支持chkconfig命令:
    #!/bin/sh
              # chkconfig: 2345 85 15
              # description: Apache is a World Wide Web server.
   保存后退出vi编辑器,执行下面的命令增加Apache服务控制脚本执行权限:
    chmod  +x  /etc/init.d/apache
   执行下面的命令将Apache服务加入到系统服务:
    chkconfig –add apache
   执行下面的命令检查Apache服务是否已经生效:
    chkconfig –list apache
              命令输出类似下面的结果:
              apache          0:off 1:off 2:on 3:on 4:on 5:on 6:off
       表明apache服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制Apache的启动和停止。
(2) php的安装

支持:yum -y install libxml*

[root@localhost php-5.2.10]# ./configure –prefix=/usr/local/php    \
>   –with-apxs2=/usr/local/apache/bin/apxs
[root@localhost php-5.2.10]# make && make install
[root@localhost php-5.2.10]# cp php.ini-dist /usr/local/lib/php.ini
[root@localhost php-5.2.10]# vi /usr/local/apache/conf/httpd.conf

为了配置文件的工整,在配置文件的相关地方加入如下配置:

LoadModule php5_module modules/libphp5.so(如果有,不用加)
AddType application/x-httpd-php .php .html
找到DirectoryIndex index.html
改为:DirectoryIndex index.php index.html
在最后加入nagios的访问目录:
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory “/usr/local/nagios/sbin”> 
AuthType Basic 
Options ExecCGI 
AllowOverride None 
Order allow,deny 
Allow from all
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory “/usr/local/nagios/share”> 
AuthType Basic 
Options None 
AllowOverride None 
Order allow,deny 
Allow from all
</Directory>

 

如果重新启动apache报如下错误:

httpd: Syntax error on line 53 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

原因:是Linux有一个SELinux保护模式引起的。

解决办法:

关闭SELINUX的方法:

vi /etc/selinux/config 将SELINUX=enforcing 改成SELINUX=disabled 需要重启

(3) nagios的安装      为了支持Nagios安装完后status map,trend等完全显示,需要gd库的支持,之前我已经提了,没装的装下 [root@localhost nagios-cn-3.2.3]#useradd nagios 
[root@localhost nagios-cn-3.2.3]# ./configure –prefix=/usr/local/nagios \
> –with-gd-lib=/usr/lib –with-gd-inc=/usr/include –with-nagios-user=nagios \
> –with-nagios-group=nagios 
[root@localhost nagios-cn-3.2.3]# make all 
[root@localhost nagios-cn-3.2.3]# make install 
[root@localhost nagios-cn-3.2.3]# make install-init 
[root@localhost nagios-cn-3.2.3]# make install-commandmode
[root@localhost nagios-cn-3.2.3]#make install-config
(4) nagios-plugin的安装 [root@localhost nagios-plugins-1.4.15]# ./configure –prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.15]# make && make install (5) 飞信机器人的安装 [root@localhost fx]# cd fx [root@localhost fx]# mv libACE* libcrypto.so.* libssl.so.*  /usr/lib [root@localhost fx]# cd .. [root@localhost xuningbo]# mv fx /usr/local/fetion [root@localhost xuningbo]# chmod -R 755 /usr/local/fetion [root@localhost xuningbo]# chown -R nagios:nagios /usr/local/fetion 测试飞信能否成功发送短信(发送对象需自己或者飞信好友): [root@localhost xuningbo]# /usr/local/fetion/fetion –mobile=159******  –pwd=*****  –to=159**** –msg-utf8=”test” 注意:第一次使用提示: 锲惧舰楠岃瘉镰佸凡缁忕敓鎴愶纴鏂囦欢钖崭负:159****.jpg璇疯瘑鍒悗杈揿叆锲惧舰楠岃瘉镰? 解决方式:将图片下载到本地,打开 输入图中验证码即可,以后就不需要了 镇ㄨ緭鍏ョ殑璇嗗埆镰佹槸:hyxh
SIP-C/4.0 280 Send SMS OK
T: sip:338172353@fetion.com.cn;p=6142
I: 2
Q: 1 M
L: 115
D: Fri, 09 Dec 2011 07:05:13 GMT
XI: 2D50732F57C792E4616756574DD0F131    即发送成功。
  3、nagios的配置 我只用了一台监控与一台被监控,所以设置非常简单 [root@localhost xuningbo]# cd /usr/local/nagios/etc/objects/ [root@localhost objects]# vi hosts.cfg define host{
                host_name                             test
                alias                                   testhost02
                max_check_attempts                 5
                contact_groups                    admins
                address                             61.164.*.*
                }  
define hostgroup{
                hostgroup_name            group
                alias                     testgroup
                members                 test
                }define service{
                host_name            test
                service_description             PING
                is_volatile                             0
                check_period                         24×7
                max_check_attempts                 1
                normal_check_interval             1
                retry_check_interval                 1
                notification_options                 w,u,c,r
                notification_interval             1
                notification_period                 24×7
                check_command   check_ping!100.0,20%!500.0,60%
                   }define service{
                host_name         test
                  service_description             HTTP
                is_volatile                             0
                check_period                         24×7
                max_check_attempts                 1
                normal_check_interval             1
                retry_check_interval                 1
                notification_options                 w,u,c,r
                notification_interval             1
                notification_period                 24×7
                check_command                   check_http
                notifications_enabled                0
                }   

[root@localhost objects]# vi  contacts.cfg

define contact{
        contact_name                    xuningbo                ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user
        service_notification_commands    notify-service-by-email,service-notify-by-fei       
        host_notification_commands        notify-host-by-email,host-notify-by-fei
        pager                                           159****
        email                           xuningbo_0@126.com      ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }

 

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 xuningbo
        }   (3) commands.cfg的编辑      为了支持飞信发短信的功能需要在此文件中添加飞信命令,以促使信息的发送,代码如下:

# ‘notify-host-by-fei’ command definition

define command {
             command_name            host-notify-by-fei ;
             command_line            /usr/local/fetion/fetion –mobile=137*** –pwd=*** –to=$CONTACTPAGER$ –msg-utf8=”Host $HOSTSTATE$ alert for $HOSTNAME$! on ‘$LONGDATETIME$’” $CONTACTPAGER$
             }
 
# ‘notify-service-by-fei’ command definition

define command {
             command_name         service-notify-by-fei
             command_line         /usr/local/fetion/fetion –mobile=137*** –pwd=*** –to=$CONTACTPAGER$ –msg-utf8=”$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$” $CONTACTPAGER$
             }

(4) 编辑nagios.cfg

为了使刚才编辑的文件生效,需加入一行:
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

 

[root@localhost etc]#  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg   

Nagios Core 3.2.3
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 10-03-2010
License: GPL

Website: https://www.nagios.org
Reading configuration data…
   Read main config file okay…
Processing object config file ‘/usr/local/nagios/etc/objects/commands.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/contacts.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/timeperiods.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/templates.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/hosts.cfg’…
   Read object config files okay…

Running pre-flight check on configuration data…

Checking services…
        Checked 2 services.
Checking hosts…
        Checked 1 hosts.
Checking host groups…
        Checked 1 host groups.
Checking service groups…
        Checked 0 service groups.
Checking contacts…
        Checked 1 contacts.
Checking contact groups…
        Checked 1 contact groups.
Checking service escalations…
        Checked 0 service escalations.
Checking service dependencies…
        Checked 0 service dependencies.
Checking host escalations…
        Checked 0 host escalations.
Checking host dependencies…
        Checked 0 host dependencies.
Checking commands…
        Checked 26 commands.
Checking time periods…
        Checked 5 time periods.
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

 

检查没问题就可以测试了!

 

 

设置权限:

apache配置文件中改为

ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”
<Directory “/usr/local/nagios/sbin”>
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios “/usr/local/nagios/share”
<Directory “/usr/local/nagios/share”>
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

添加账户:

 /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users admin

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

authorized_for_system_information=test(你远程登录的账号)



authorized_for_configuration_information=test(你远程登录的账号)


authorized_for_system_commands=test(你远程登录的账号)


authorized_for_all_services=test(你远程登录的账号)


authorized_for_all_hosts=nagiosadmin,test(你远程登录的账号)

authorized_for_all_service_commands=test(你远程登录的账号)


authorized_for_all_host_commands=test(你远程登录的账号)

最后更新:2017-01-04 22:34:35

  上一篇:go TOP 解析
  下一篇:go linux查看内存、cpu参数【原创收集】