服务器监控:Nagios和NRPE配置

来源:互联网 发布:香港智能电视直播软件 编辑:程序博客网 时间:2024/06/07 09:27

 


1        Nagios介绍

Nagios是一款用于系统和网络监控的应用程序。它可以在你设定的条件下对主机和服务进行监控,在状态变差和变好的时候给出告警信息。

Nagios最初被设计为在Linux 系统之上运行,然而它同样可以在类Unix的系统之上运行。

Nagios更进一步的特征包括:

  1. 监控网络服务(SMTP、POP3、HTTP、NNTP、PING等);
  2. 监控主机资源(处理器负荷、磁盘利用率等);
  3. 简单地插件设计使得用户可以方便地扩展自己服务的检测方法;
  4. 并行服务检查机制;
  5. 具备定义网络分层结构的能力,用"parent"主机定义来表达网络主机间的关系,这种关系可被用来发现和明晰主机宕机或不可达状态;
  6. 当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式);
  7. 具备定义事件句柄功能,它可以在主机或服务的事件发生时获取更多问题定位;
  8. 自动的日志回滚;
  9. 可以支持并实现对主机的冗余监控;
  10. 可选的WEB界面用于查看当前的网络状态、通知和故障历史、日志文件等;

2        Nagios安装

2.1       准备软件包

httpd
gcc
glibc glibc-common
gd gd-devel

mysqlmysql-server mysql-devel

gnutls

2.2          创建用户和组

最主要的工作是创建nagios用户及其束组,让nagios的运行用户为nagios而不是root。再把目录/usr/local/nagios的属主设置为nagios,以保证系统的安全。Nagios可以以root用户运行,但并不推荐这样做。用下面的步骤 来完成上述过程:

1、 添加系统帐户nagios:useradd nagios

# groupadd nagios

# groupadd nagcmd

# useradd nagios -M -s /sbin/nologin -g nagios

注意:不要给nagios用户设置密码

2、更改目录属组:chown–R nagios.nagios /usr/local/nagios 。请注意,有的unix/linux的版本用户和属组分隔符号不是“.”,可能会是这样的形式 chown –R nagios:nagios /usr/local/nagios 。

 

2.3          安装nagios

2.3.1      下载Nagios和插件程序包

下载并安装:

http://cdnetworks-kr-2.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz

 

wget http://jaist.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz

2.3.2      安装nagios

 # tar –zxvf nagios-3.2.1.tar.gz

# cd nagios-3.2.1

#./configure  --prefix=/usr/local/nagios  --with-command-group=nagcmd--enable-nanosleep --enable-broker

# make all

# make install

# make install-init

# make install-commandmode

# make install-config

 

2.3.3      安装nagios插件

 

nagios-plugins-1.4.15

./configure  --prefix=/usr/local/nagios

make

make install

安装完成后,将在目录/usr/local/nagios生成目录libexec

 

3        安装web服务器apache

Web服务不是nagios所必须的,但是如果nagios没有web,查看监控对象的对象将是非常费事和没有趣味的事情(只有通过查看nagios的日志来判断状态)。

 

3.1          安装Apache HTTP

安装Apache 2.2.3

./configure --prefix=/usr/local/apache2 \

--enable-module=most \

--enable-shared=max

# make

# make install

----------------------------------启动Apache服务----------------------------------

# /usr/local/apache2/bin/apachectl start

----------------------------------关闭Apache服务----------------------------------

# /usr/local/apache2/bin/apachectl stop

----------------------------------重启Apache服务----------------------------------

# /usr/local/apache2/bin/apachectl restart

 

3.2          安装PHP

2. 安装PHP 5.3.6

# ./configure --prefix=/usr/local/php \

--with-apxs2=/usr/local/apache2/bin/apxs

# make

# make install

# cp php.ini-production/usr/local/php/lib/php.ini

 

if has error:  make clean

 

3.3          配置Apache服务的httpd.conf文件

*在LoadModule处添加 LoadModule php5_module module/libphp5.so

*在DirectoryIndex处添加 index.php

*在AddType application处添加

AddType application/x-httpd-php .php .phtml

AddType applicatoin/x-httpd-php-source.phps

 

然后,vi/usr/local/apache2/conf/httpd.conf,添加:

 

   <FilesMatch \.php$>

       SetHandler application/x-httpd-php

   </FilesMatch>

   <FilesMatch "\.ph(p[2-6]?|tml)$">

       SetHandler application/x-httpd-php

   </FilesMatch>

   <FilesMatch "\.phps$">

       SetHandler application/x-httpd-php-source

   </FilesMatch>

     

   LoadModule php5_module modules/libphp5.so

     

   <IfModule dir_module>

       DirectoryIndex index.html index.php

   </IfModules> 

      

 

4        Nagios配置

4.1          配置前的处理

最主要的工作是创建nagios用户及其束组,让nagios的运行用户为nagios而不是root。再把目录/usr/local/nagios的属主设置为nagios,以保证系统的安全。Nagios可以以root用户运行,但并不推荐这样做。用下面的步骤 来完成上述过程:

2、 添加系统帐户nagios:useradd nagios

# groupadd nagios
# useradd nagios -M -s /sbin/nologin -g nagios

注意:不要给nagios用户设置密码

2、更改目录属组:chown–R nagios.nagios /usr/local/nagios 。请注意,有的unix/linux的版本用户和属组分隔符号不是“.”,可能会是这样的形式 chown –R nagios:nagios /usr/local/nagios 。

添加Apache的daemon到nagios用户组

3、sendmail。看看sendmail是否正常运行?我们需要使用sendmail来发送故障报警信息,所以这个包必须能够正常工作。Sendmail分为服务器和客户端两部分,有2种发送报警邮件的方式:
(1)nagios所在的机器通过sendmail客户端程序把邮件发送到专门的邮件服务器,再由邮件服务器把消息发送到用户邮箱。
(2) 邮件客户端和服务器端就用nagios所在系统sendmail。第一种方式用起来非常规范,但更麻烦,例如需要做地址解析、修改邮件服务器的配置;另外 还有一个问题-它还依赖别的系统,增加了故障点和复杂度。第二种方法十分简单,只需启动sendmail服务即可,而且它不再依赖于别的系统和服务。在我工作的实际场景,这两种方法都使用,用专门的邮件服务器会有发送延迟的情况(因为邮件服务器要处理很多其他用户邮件的收发);而直接用sendmail做 服务器和客户端就异常简单和方便了。非常幸运的是,几乎所有的linux/unix发行版都默认安装sendmail,费了这么多笔墨,其实就做一个动作 -把sendmail服务运行起来。

4、手机短信发送工具。我现在的公司是sp,有自己的短信通道,直接把发送短信的客 户端程序sms_send拷贝到目录/usr/local/bin/下。如果没有短信下发的网关通道,那怎么办呢?网络上有很多短信发送的客户端程序,很 有名的就是smsclient,把它下载下来,解包后安装。不要忘记购买手机modem和手机卡,modem只支持SIM卡而不支持cdma。

安装完smsclient软件和硬件modem后,测试一下是否正常。如果没有modem又怎么办?办法还是有的:让你 的手机号可以接受邮件,这需要你去营业厅开通这项功能。短信报警功能是最有用的功能,我们不可能成天盯着监视屏幕,也不可能成天接受电子邮件,但我们的手机却可以24小时在线,只要被监控对象发生故障,马上就可以收到故障报警短信。

 

 

4.2          Apache配置

 

 

我们分两个步骤来完成这个配置。第一步是修改apache的配置文件httpd.conf,这里的文件路径是/usr/local/apache/conf/httpd.conf 。把apache的运行用户[1]和运行组改成nagios,往下把下面的行追加到文件httpd.conf的末尾:

 

 

#setting for nagios
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
     //Cgi文件所在目录
    AuthType Basic
    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthUserFile /usr/local/nagios/etc/htpasswd  //验证文件路径
    Require valid-user
 
Alias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">   
   //nagios页面文件目录
    AuthType Basic
    Options Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "nagios Access"
    AuthUserFile /usr/local/nagios/etc/htpasswd  //验证文件路径
    Require valid-user

</Directory>

 

上述文本块的作用是对nagios的目录进行用户验证,只有合法的授权用户才可以访问nagios的页面文件。

 

第二步是生成用户验证文件:只要执行命令

/usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/htpasswd nagios

就会生成web的合法访问用户nagios;命令交互执行,需要输入2次密码,然后就在文件/usr/local/nagios/etc/htpasswd写入一行-第一个字段是刚生成的用户名,第二个是加密后的密码,如果还要添加更多的用户,执行命令 htpasswd 就不需要选项 “-c”,否则就会覆盖所有已经生成的行。

 

 

配置完成后,执行/usr/local/apache/bin/apachctl –t 检查apache配置文件是否有语法错误,无误后用/usr/local/apache/bin/apachctlstart & 把apache启动,然后从另外的机器的浏览器输入nagios 的访问地址

 

 

4.3          Nagios配置

nagios,其配置文件的目录是/usr/local/nagios/etc

 

Nagios的主配置文件是nagios.cfg,我们就从这个文件开始修改

 

4.3.1      修改主配置文件nagios.cfg

 

 

#cfg_file=/usr/local/nagios/etc/localhost.cfg[2],然后把下面几行的注释去掉:

cfg_file=/usr/local/nagios/etc/contactgroups.cfg  //联系组配置文件路径

cfg_file=/usr/local/nagios/etc/contacts.cfg       //联系人配置文件路径

cfg_file=/usr/local/nagios/etc/hostgroups.cfg     //主机组配置文件路径

cfg_file=/usr/local/nagios/etc/hosts.cfg          //主机配置文件路径

cfg_file=/usr/local/nagios/etc/services.cfg       //服务配置文件路径

cfg_file=/usr/local/nagios/etc/timeperiods.cfg    //监视时段配置文件路径

改check_external_commands=0为check_external_commands=1 这行的作用是允许执行在web界面下重启nagios、停止主机/服务检查等操作。把command_check_interval的值从默认的1改成 command_check_interval=10s(根据自己的情况定这个命令检查时间间隔,不要太长也不要太短)。主配置文件要改的基本上就是这些,通过上面的修改,发现/usr/local/nagios/etc并没有文件hosts.cfg等一干文件,怎么办?稍后手动创建它们。
第二个要修改的配置文件是cgi.cfg,它的作用是控制相关cgi脚本。

先确保use_authentication=1。接下来修改default_user_name=sery ,再后面的修改在下表列出:

authorized_for_system_information=nagiosadmin,nagios

authorized_for_configuration_information=nagiosadmin,nagios

authorized_for_system_commands=nagios  //多个用户之间用逗号隔开

authorized_for_all_services=nagiosadmin,nagios

authorized_for_all_hosts=nagiosadmin,nagios

authorized_for_all_service_commands=nagiosadmin,nagios

authorized_for_all_host_commands=nagiosadmin,nagios

那么上述用户名打那里来的呢?是执行命令 /usr/local/apache/bin/htpasswd –c/usr/local/nagios/etc/htpasswd nagios所生成的.

 

4.3.2      修改cgi配置文件cgi.cfg

#如有多个用户,中间用逗号隔开

   authorized_for_system_information=nagios

  authorized_for_configuration_information=nagios

   authorized_for_system_commands=nagios

   authorized_for_all_services=nagios

   authorized_for_all_hosts=nagiosadmin,nagios

   authorized_for_all_service_commands=nagios

   authorized_for_all_host_commands=nagios

在这里指定的用户”nagios”可以通过浏览器操纵nagios服务的关闭、重启等各种操作

 

 

 

4.3.3      修改commands.cfg配置文件

 

第3个修改的配置文件是misccommands.cfg,这个文件的主要功能是用来发送报警短信和报警邮件,对其的修改如下所示:

#host-notify-by-sms 

define command {

       command_name      host-notify-by-sms

       command_line      /usr/local/bin/sms_send "Host $HOSTSTATE$

alert for $HOSTNAME$! on '$DATETIME$' " $CONTACTPAGER$

       }

 

#service notify by sms 

define command {

       command_name     service-notify-by-sms

       command_line     /usr/local/bin/sms_send "'$HOSTADDRESS$'

$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" $CONTACTPAGER$

       }

主机和服务的邮件报警通知已经在文件中,不须更改。也可以把短信和邮件报警通知这些配置块写到文件commands.cfg中,效果是一样的。

 

4.3.4      增加新的配置文件

先创建简单的配置文件timeperiods.cfg,其内容如下:

define timeperiod{
        timeperiod_name 24x7
        alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
        monday          00:00-24:00
        tuesday         00:00-24:00
        wednesday       00:00-24:00
        thursday        00:00-24:00
        friday          00:00-24:00
        saturday        00:00-24:00
        }

这个文件的定义明晰易懂,不多做说明。另建议7X24小时监控。
第二个手动创建的配置文件是 contacts.cfg,其格式如下:
 

define contact {
        contact_name         sa    //不要有空格
        alias                system administrator
        service_notification_period    24x7
        host_notification_period       24x7
        service_notification_options   w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands  service-notify-by-sms,service-
notify-by-email  //这个命令读配置文件miscommands.cfg
        host_notification_commands     host-notify-by-email,host-noti
fy-by-sms      //这个命令读配置文件miscommands.cfg
        email                          xxx
        pager                          13333333333 //手机号,收报警短信
        }     //不要把这个符号写掉了
 
define contact {
        contact_name         sery
        alias                system administrator
        service_notification_period    24x7
        host_notification_period       24x7
        service_notification_options   w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands  service-notify-by-sms,service-
notify-by-email
        host_notification_commands     host-notify-by-email,host-noti
fy-by-sms
        email                         xxx
        pager                          13312345678
        }

上面的文件定义了2个联系人,如果有更多联系人的话,照这个格式在后面追加即可。服务通知选项 (service_notification_options)与主机通知选项(host_notification_options)的几个选项在这里说明一下:w-warning ,u-unknown,c-critical,r-recovery;d-down,u-unreachable,注意一下,主机报警和服务报警有些差异。

紧接着的第三个手动创建的配置文件是contactgroups.cfg文件,这个文件是依照上一个文件contacts.cfg来的,contactgroups文件相对简单一些,其格式如下:

define contactgroup {
        contactgroup_name    sagroup  //不要用空格
        alias                system administrator group
        members              sa,sery  //本例有2个成员
}

多个成员之间用逗号做分界符,如果有更多的联系组,就依相同的格式在文件中追加余下的组。
关键的角色终于登场,这就是配置文件hosts.cfg。下面是我定义的两个主机的基本样式:
 

#define monitor  host
 
#################################################################
# Wangjing IDC servers                                          #
#################################################################
define host {
       host_name                  nagios-server
       alias                      nagios server
       address                    61.x..x.49
       contact_groups             sagroup //多个联系组用逗号分隔,
数据来源于contactgroups.cfg
       check_command              check-host-alive
       max_check_attempts         5
       notification_interval      10    //值可调,大小什么值合适需自己测定
       notification_period        24x7
       notification_options        d,u,r
       }
 
define host {
       host_name                  24-25
       alias                      server 24-25
       address                    202.X.24.25
       contact_groups             sagroup
       check_command             check-host-alive //down机就发报警通知
       max_check_attempts         5
       notification_interval      10
       notification_period        24x7
       notification_options        d,u,r
       }

更多的主机依此格式逐个追加进来。小技巧,如果是连续的ip段,最好自己写个脚本生成hosts.cfg文件

再一个重量级的配置文件是services.cfg,没有这个文件,什么监控也没用。下面给出一个样式文件:

#service definition
 
##############################################################
# servers service for host-live                              #
##############################################################
define service {
        host_name        nagios-server  //来源:hosts.cfg
        service_description   check-host-alive
        check_period          24x7
        max_check_attempts    4
        normal_check_interval 3
        retry_check_interval  2
        contact_groups        sagroup  //来源:contactgroups.cfg
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command           check-host-alive  //检查主机是否存活
        }
define service {
        host_name        74-210
        service_description   check_tcp 80
        check_period          24x7
        max_check_attempts    4
        normal_check_interval 3
        retry_check_interval  2
        contact_groups        sagroup
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command      check_tcp!80 //检查tcp 80端口服务是否正常
        }

书写时要注意的是,check_tcp与要监控的服务端口之间要用”!”做分隔符。如果服务太多,以应该考虑用脚本来生成。
主机组配置文件hostgroups.cfg,这是一个可选的项目,它建立在文件hosts之上,其格式如下:
 

define hostgroup {
         hostgroup_name  sa-servers
         alias           sa servers
         members         nagios-server,24-25,24-26  //用逗号间隔多个主机
         }

多个主机组依上面的格式逐个追加上去。后面给一个主机组的截图。
 

千辛万苦,终于把这些配置给做好保存,现在几乎有点迫不及待了,运行程序/usr/local/nagios –v /usr/local/nagios/etc/nagios.cfg来检查所有配置文件的正确性。如果十分幸运的话,运行完毕将在输出尾部出现:
 

Total Warnings: 0
Total Errors:   0
 
Things look okay - No serious problems were detected during the pre-flight check

这样的情况,大功告成

验证通过以后,就可以执行命令/usr/local/nagios–d  /usr/local/nagios/etc/nagios.cfg 把nagios作为守护进程。然后用ps –aux | grep nagios 看进程是否处于运行状态。到这一步,nagios服务基本上算是配置完毕。做hosts.cfg、services.cfg等配置时,可以运用一些小技巧 来减少出错的概率:如先定义少许的主机、服务,待校验无误后再追加。

验收

用浏览器输入nagios所在服务器的ip及目录,如http://xxxx/nagios,再输验证所需的用户名和密码,就可点击页面右边的相关连接来查看各种状态。关掉某个被nagios监控主机的服务或者拔掉某个服务器的网线,等几分钟,点击超连接“ServiceDetail”观察页面状态看是否有红色的醒目的报警出现。

 一会儿,就会收到报警短信和报警邮件,然后在把测试所有的服务开启或把拔下来的网线查上去,片刻后,网页里的红色报警表格消失,手机短信或邮件通知故障恢复。如果你的情况也这样,那么真正大功告成。

 

Nagios 的功能十分强大,在我的项目里,因为我的需求不同而尽可能的简化了nagios而没有使用代理、多更多插件等功能,在一个不超过1000个服务器的网络规模里,它工作得很好。如果有更多的服务器,建议使用mysql数据来管理监控对象。


 

5        Nagios Addons

 

 

5.1          NRPE

NRPE is an addon that allows you to executeplugins onremote Linux/Unix hosts. This is useful if you need to monitor localresources/attributes like disk usage, CPU load, memory usage, etc. on a remotehost. Similiar functionality can be accomplished by using the check_by_sshplugin, although it can impose a higher CPU load on the monitoring machine -especially if you are monitoring hundreds or thousands of hosts.

 

 

NRPE

 

 

5.1.1       被监控主机安装

编译
#./configure--enable-command-args
#make all        

安装NRPE插件、Deamon和Deamon配置文件示例
#make install-plugin
#make install-daemon
#make install-daemon-config

安装NRPE Deamon为xinetd下的一个服务
#make install-xinetd

编辑/etc/xinetd.d/nrpe,在only_from参数里加入nagios服务器的IP地址
only_from = 127.0.0.1  <nagios server IP>

在/etc/services中添加NRPE Deamon
nrpe   5666/tcp   #NRPE

重启xinetd服务
#service xinetd restart

 

检查NRPE Deamon是否运行
#netstat -at | grep nrpe
tcp    0     0 *:nrpe     *:*     LISTEN

检查NRPE Deamon是否工作正常
#/usr/local/nagios/libexec/check_nrpe -H  localhost
NRPE v2.12

 

 

5.1.2      nagios服务器上安装设置

 

编译
#./configure
#make all        

安装NRPE插件
#make install-plugin

 

 

定制配置
如果想使用nrpe监视远程主机上的新服务,需要做两件事:
     1.在远程主机的nrpe.cfg文件里加上新命令。
     2.对该主机的Nagios配置里添加新服务定义。

 

 

 

5.2          NSCA

 

NSCA is an addon that allows you to send passive checkresults from remote Linux/Unix hosts to the Nagios daemon running on themonitoring server. This is very useful indistributedandredundant/failovermonitoring setups.

 

 

http://prdownloads.sourceforge.net/sourceforge/nagios/nsca-2.7.2.tar.gz

 

 

 

 

5.3          NDOUtils

 

NDOUtils is an addon that allows you to store all statusinformation from Nagios in a MySQL database. Multiple instances of Nagios canall store their information in a central database for centralized reporting.This will likely serve as the basis for a new PHP-based web interface forNagios in the future.

The NDOUtils addon and documentation can be found at http://www.nagios.org/.

 

 

6        在 Oracle 所在服务器上安装 NRPE

安装过程参考 Nagios NRPE 文档。

注意点:
1.由于 nagios 脚本需要读取 oracle 相关文件。所以运行 nagios 的用户需要定义为 oracle 服务用户。并且修改 /etc/xinted.d/nrpe 中的配置。

service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = oracle  //(注意这里一定要用oracle用户)
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 192.168.100.62
}

2.给 oracle 用户在 ORACLE_HOME 目录下执行权限。
chmod –Rf 740 $ ORACLE_HOME/*

3.修改 check_oracle 脚本。将 $ORACLE_HOME 以及 $PATH 手动加入,避免出现问题。

ORACLE_HOME=/u01/oracle/product/10.2.0/db_1
PATH=$PATH: /u01/oracle/product/10.2.0/db_1/bin

二、 配置 nrpe 服务

修改 /usr/local/nagios/etc/nrpe.cfg 文件。加入以下内容:

#Check Oracle
command[check_oracle_tns]=/usr/local/nagios/libexec/check_oracle –tns orcl
command[check_oracle_db]=/usr/local/nagios/libexec/check_oracle –db orcl
command[check_oracle_login]=/usr/local/nagios/libexec/check_oracle –login orcl
command[check_oracle_cache]=/usr/local/nagios/libexec/check_oracle –cache orclsystem lkjsdf 80 90
command[check_oracle_tablespace]=/usr/local/nagios/libexec/check_oracle–tablespace orcl system lkjsdf tab 90 80

具体参数写法请参考 check_oracle –help。

配置完成后,重启 xinetd 服务。

三、配置 Nagios 服务端

1.安装 nrpe 脚本支持。—参考官方文档。
2.添加 nrpe 命令配置。修改 nagios/etc/objects/command.cfg 文件:

define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

3.在 nagios/etc/objects 添加oracle 主机配置文件。oracle.cfg 。

define host {
use linux-server
host_name oracle
alias Oracle 10g
address 192.168.100.63
}

define service {
use generic-service
host_name oracle
service_de.ion TNS Check
check_command check_nrpe!check_oracle_tns
}
define service {
use generic-service
host_name oracle
service_de.ion DB Check
check_command check_nrpe!check_oracle_db
}
define service {
use generic-service
host_name oracle
service_de.ion Login Check
check_command check_nrpe!check_oracle_login
}
define service {
use generic-service
host_name oracle
service_de.ion Cache Check
check_command check_nrpe!check_oracle_cache
}
define service {
use generic-service
host_name oracle
service_de.ion Tablespace Check
check_command check_nrpe!check_oracle_tablespace
}

 

7        邮件和短信告警

7.1          飞信

 

下载软件

主软件:wget http://www.it-adv.net/fetion/downng/fetion20091117-linux.tar.gz

主程序:wget http://bbs.it-adv.net/attachment.php?aid=43&k=b1e8997336d66ec8610adc2b790376a2&t=1299230237

库文件:wget http://www.it-adv.net/fetion/linuxso_20101113.rar

安装飞信:

tar zxvffetion20091117-linux.tar.gz -C /usr/local

将下载的主程序fetion覆盖掉/usr/local/fx/下的fetion

在windows中解压linuxso_20101113.rar并将里面的库文件上传至 /usr/local/fx/

cd /usr/local/fx

cp lib* /usr/lib

vim /etc/ld.so.conf

增加以下内容

/usr/local/fx/fetion

然后执行命令  ldconfig

cp fetion /usr/bin

 

 

第三个是修改配置文件commands.cfg 这个文件是用来发送报警飞信的

#vim/usr/local/nagios/etc/objects/commands.cfg

增加以下内容:

define command {

command_name   notify-service-by-fetion

command_line   /usr/local/fx/fetion –mobile=1589******* –pwd=********** –to=1589********–msg-utf8=”$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on$LONGDATETIME$” –hide

}

这里说明一下fetion的格式:

–mobile=飞信机器人号码

–pwd=密码

–to=目标手机号码      //该号码必须是飞信机器人的飞信好友

–msg-utf8=”信息内容”

–[hide|debug]隐藏/显示发送信息的过程

 

 

/usr/local/fx/fetion--mobile=xxxxx--pwd=xxx --to=1352294xx --msg-utf8="$HOSTADDRESS$$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"

 

7.1.1      Note

第一次运行时需要输入验证码,验证码是个图片文件,以手机号码命名,在命令行输入这个验证码,下次就不需要了。

 

7.2          发送邮件

# 'notify-host-by-email' command definition
define command{
        command_name   notify-host-by-email
        command_line   /usr/bin/printf "%b" "Host: $HOSTNAME$<br>Notification:$HOSTNOTIFICATIONNUMBER$<br>Command:$HOSTCHECKCOMMAND$<br>Datetime: $LONGDATETIME$<br><br>Info:$HOSTOUTPUT$<br>$LONGHOSTOUTPUT$" | /usr/local/bin/sendEmail -fdba@lk.com -t $CONTACTEMAIL$ -s 28.4.15.18 -u "Host $HOSTSTATE$:$HOSTADDRESS$" -o message-content-type=html -o message-charset=utf8
}
# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line   /usr/bin/printf "%b" "Host: $HOSTALIAS$<br>NotifyTimes:$SERVICENOTIFICATIONNUMBER$<br>Command:$SERVICECHECKCOMMAND$<br>Datetime: $LONGDATETIME$<br><br>AdditionalInfo:<br>$SERVICEOUTPUT$<br>$LONGSERVICEOUTPUT$" |/usr/local/bin/sendEmail -f dba@lk.com -t $CONTACTEMAIL$ -s 28.4.15.18 -u"Service $SERVICESTATE$: $HOSTADDRESS$ | $SERVICEDESC$" -omessage-content-type=html -o message-charset=utf8
}