前面提到nagios用邮件来发邮件报警,如果能将报警信息发到手机上来不是更好。其实手机上也可以使用邮箱的。邮箱和手机绑定一下就行了。下面说一下,centos6.0 64位的系统下,用飞信来发报警信息。
一,安装所要的软件
总下载地址:http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1
wget http://www.it-adv.net/fetion/cenos54X64_20101113.rar
wget http://www.it-adv.net/fetion/linuxso_20101113.rar
//下面的这个连接是下载飞信的可执行文件fetion,要注册回复后才能看到,有点恶
http://bbs.it-adv.net/attachment.php?aid=43&k=954fb0d183808bfb706d8c4a35308874&t=1335168710
//下面的这个连接是下载rar的解压缩软件文件的软件
wget http://www.rarlab.com/rar/rarlinux-3.9.2.tar.gz
二,解压下载的软件
1,安装rar的解压缩软件
- tar zxvf rarlinux-3.9.2.tar.gz
- cd rar
- make && make install
make时如果报以下
rar: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
解决方法:
- [root@localhost download]# yum install libstdc++.so.6
2,解压cenos54X64_20101113.rar,linuxso_20101113.rar
- [root@localhost download]# rar x cenos54X64_20101113.rar
- [root@localhost download]# cp cenos54X64_20101113/lib/* /usr/local/lib //我的/usr/local/lib下面是没有东西的,避免根系统自带的冲突了。
- [root@localhost download]# rar x linuxso_20101113.rar //解压后的文件在当前文件夹,总共4个文件
- [root@localhost download]# cp ./lib* /usr/local/lib //也cp过去,在这里根cenos54X64有部分冲突直接覆盖掉。
- [root@localhost download]# cp fetion /usr/local/bin //将fetion主程序,拷贝到/usr/local/bin下面。
- [root@localhost download]# chown nagios:nagios /usr/local/bin/fetion //给nagios权限
- [root@localhost download]# chmod +x /usr/local/bin/fetion //命令行下,别的用户也可以用
- [root@localhost download]# chmod +x /usr/local/lib/* //给/usr/local/lib/下面的.so文件加可执行权限
别忘了下面这一步,很重要
- [root@localhost download]# ldconfig /usr/local/lib/
三,测试发短信,以及遇到的问题
1,
[root@localhost lib64]# fetion --mobile=1582170xxxx --pwd=**** --to=1582170xxxx --msg-utf8=测试
如果报以下错误:
-bash: fetion: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
解决方法
[root@localhost download]# yum install /lib/ld-linux.so.2
2,
[root@localhost local]# fetion --mobile=1582170xxxx --pwd=****** --to=1582170xxxx --msg-utf8=测试
如果报以下错误:
fetion: error while loading shared libraries: libgssapi_krb5.so.2: cannot open shared object file: No such file or directory
解决方法:
[root@localhost local]# yum install libgssapi_krb5.so.2
如果还报错,libgssapi_krb5.so.2 i686 conflicts with file libgssapi_krb5.so.2 x86冲突了。由于急着解决报错,错误没有记下来,系统有了libgssapi_krb5.so.2,但是是64位的。我在网上查了一下,说把有libgssapi_krb5.so.2卸载掉,在重新装,问题就能解决,说实话不敢卸载,因为libgssapi_krb5.so.2这个东西我没有装过,估计是系统自带,卸载掉,怕系统崩掉。
解决办法:
[root@localhost local]# yum install krb5-libs //先安装rb5-libs
[root@localhost local]# yum install libgssapi_krb5.so.2 //安装libgssapi_krb5.so.2
这样就搞定了。
3,
[root@localhost lib]# fetion --mobile=1582170xxxx --pwd=******* --to=1582170xxxx --msg-utf8=测试
如果报以下错误
fetion: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
解决办法:
[root@localhost lib]# yum install libz.so.1
查看一下fetion加载情况:
- [root@localhost lib]# ldd fetion
- linux-gate.so.1 => (0x0078c000)
- libACE-5.7.2.so => /usr/local/lib/libACE-5.7.2.so (0x00110000)
- libACE_SSL-5.7.2.so => /usr/local/lib/libACE_SSL-5.7.2.so (0x00b9d000)
- libssl.so.4 => /usr/local/lib/libssl.so.4 (0x0069d000)
- libstdc++.so.6 => /usr/local/lib/libstdc++.so.6 (0x004f8000)
- libm.so.6 => /lib/libm.so.6 (0x00a04000)
- libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x007e4000)
- libc.so.6 => /lib/libc.so.6 (0x002af000)
- libcrypto.so.4 => /usr/local/lib/libcrypto.so.4 (0x03e4a000)
- librt.so.1 => /lib/librt.so.1 (0x00b26000)
- libdl.so.2 => /lib/libdl.so.2 (0x0043f000)
- libgssapi_krb5.so.2 => /lib/libgssapi_krb5.so.2 (0x0065b000)
- libkrb5.so.3 => /lib/libkrb5.so.3 (0x00802000)
- libcom_err.so.2 => /usr/local/lib/libcom_err.so.2 (0x00444000)
- libk5crypto.so.3 => /lib/libk5crypto.so.3 (0x00ae1000)
- libresolv.so.2 => /lib/libresolv.so.2 (0x00447000)
- libz.so.1 => /lib/libz.so.1 (0x00461000)
- /lib/ld-linux.so.2 (0x00bd4000)
- libpthread.so.0 => /lib/libpthread.so.0 (0x00475000)
- libkrb5support.so.0 => /lib/libkrb5support.so.0 (0x00cb4000)
- libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x00b3b000)
- libselinux.so.1 => /lib/libselinux.so.1 (0x00490000)
如果有提示not found是不能发短信的。
fetion发消息测试
四,配置nagios
1,建一个发飞信的脚本,当然你也可以直接在nagios配置中写命令
查看复制打印?
- [root@localhost objects]# vim /usr/lib64/nagios/plugins/fetion.sh
- fetion --mobile=1582170xxxx --pwd=***** --to="$1" --msg-utf8="$2" //添加
- [root@localhost nagios]# chmod 777 /usr/lib64/nagios/plugins/fetion.sh
- [root@localhost nagios]# chown nagios:nagios /etc/nagios/fetion.sh
- [root@localhost nagios]# /usr/lib64/nagios/plugins/fetion.sh 1582170xxxx 'fasdfasdf'
- SIP-C/4.0 280 Send SMS OK
- T: sip:[email protected];p=7118
- I: 2
- Q: 1 M
- L: 115
- D: Tue, 24 Apr 2012 03:25:05 GMT
- XI: EC6F4C81FB87A69DF75FAEBB840DD928
如果不想显示发送成功的信息,fetion.sh文件中,在--msg-utf8="$2" 后面加上 > /dev/null
2,修改模板配置文件templates.cfg
查看复制打印?
- [root@localhost objects]# vim /etc/nagios/objects/templates.cfg //找到以下内容
- define contact{
- name generic-contact
- 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,notify-service-by-fetion //添加飞信发送模块
- host_notification_commands notify-host-by-email,notify-host-by-fetion //添加飞信发送模块
- register 0
- }
这样的话,邮件和短信都能收到通知。
3,修改命令配置文件commands.cfg
查看复制打印?
- [root@localhost objects]# vim /etc/nagios/objects/commands.cfg //添加以下内容
- # 'notify-host-by-fetion' command definition
- define command{
- command_name notify-host-by-fetion
- command_line $USER1$/fetion.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$"
- }
- # 'notify-service-by-fetion' command definition
- define command{
- command_name notify-service-by-fetion
- command_line $USER1$/fetion.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"
- }
4,修改联系人配置文件contacgs.cfg
查看复制打印?
- [root@localhost objects]# vim /etc/nagios/objects/contacts.cfg
- define contact{
- contact_name nagiosadmin ; Short name of user
- use generic-contact ; Inherit default values from generic-contact template (defined above)
- alias Nagios Admin ; Full name of user
- email [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
- pager 1582170xxxx //添加这一行,这个pager不是自定义的。
- }
到这儿就配置好了,最后别忘了重一下nagios,/etc/init.d/nagios restart。看一下效果图:
nagios用飞信发消息报警成功