一、软件环境(centos 5为例)
这里向大家推荐的是飞信机器人的软件,支持linux、命令行下的飞信、完全免费(目前为止);
官网地址:[url]http://www.it-adv.net/[/url]
支持库安装:
需要Glibc2.4以上的版本;centos5默认安装的Glibc2.5,所不需要额外升级;
目前网上的安装文档只有ubuntu的,至于redhat、fedora、centos都没有相关安装文档,我在安装的过程中遇到很多库的问题,所以在这里一并给大家进行介绍;
二、安装过程
下载包地址 LINUX X86/32(REDHAT ES4X32): 支持库 最新程序fetion20080522004-linrh4.tar.gz
其中支持库和安装包内容如下:
# tar zxvf libraryrh4x32.tar.gz
libACE-5.6.5.so
libACE_SSL-5.6.5.so
libcrypto.so.0.9.7a
libssl.so.0.9.7a

# tar zxvf fetion20080522004-linrh4.tar.gz
./install/
./install/www/
./install/www/index.html
./install/www/css/
./install/www/css/scheme.css
./install/www/css/main.css
./install/www/css/print.css
./install/www/css/main-msie.css
./install/www/p_w_picpaths/
./install/www/js/
./install/www/js/jquery.js
./install/socket_interface/
./install/socket_interface/socket_demo.php
./install/Readme.txt
./install/sound/
./install/sound/smile8.wav
./install/sound/message.wav
./install/sound/smile1.wav
./install/sound/login.wav
./install/sound/openchatwin.wav
./install/sound/closechatwin.wav
./install/fetion
./install/plugins/
./install/plugins/plugin_contact_update
./install/plugins/plugin_buddy_application
./install/plugins/plugin_message
./install/plugins/plugin_invite
./install/plugins/plugin_timer
./install/conf/
把支持库复制到/usr/lib/目录下,并作软链接如下:
cp lib*so* /usr/lib/
ln -s /usr/lib/libcrypto.so.0.9.7a /usr/lib/libcrypto.so.4
ln -s /usr/lib/libssl.so.0.9.7a /usr/lib/libssl.so.4
设定lib库配置文件
#vi /etc/ld.so.conf
#增加一条
/usr/lib/
#保存退出后,执行
#ldconfig
fetion的目录结构:
.\Readme.txt: 本说明文件
.\fetion:主程序
.\sound\*.wav:各种音效文件,您可以用自己喜欢的文件替换
.\plugins\plugin_*: 插件程序,您可以修改插件以达到自己的各性化需求
我在安装中遇到缺少krb5的库问题,这里写一下解决方法:
错误如下:
./fetion: error while loading shared libraries: libgssapi_krb5.so.2: cannot open shared object file: No such file or directory
安装一下krb5-libs包就可以解决啦:
yum install krb5-libs
完成之后测试,安装是否成功;执行
#cd install
# ./fetion -h
 Usage:
    fetion -h
        -h: help
    fetion -u mobile -p pwd [-b batchfile] [-EN] [-d]
    fetion -u mobile -p pwd [-b batchfile] [-EN] [-d]
        -u: Fetion user account(only supports mobile phone No.)
        -p: Account password
        -b: Batch file name
        -d: Debug on and write logs to [mobile]-debug.log
        -EN: English
三、实际测试
登录飞信默认是中文utf8的,如果linux系统不支持utf8会出现乱码:我使用english的方式来登录啦。
测试帐号:13713718888
密码:123456 (如果密码中含有特殊字符,请使用单引号)
./fetion -u 13713718888 -p 123456 -EN
登录后输入?获得帮助
****************************************************************
指令                    指令说明
list                     好友列表: list
sms                    发送短信: sms 飞信号/手机号/编号 短信内容(换行请用\n代替)
chat                   在线消息: chat 飞信号/手机号/编号 短信内容(换行请用\n代替)
status                 在线状态: status online/busy/away/hidden [个性化信息]
add                    添加好友: add 飞信号/手机号 申请信息 本地呢称
del                     删除好友: del 飞信号/手机号/编号
invite                 邀请好友: invite 手机号 您的姓名(邀请好友开通飞信)
autoaccept         自动接受: autoaccept on/off/status 自动接受加为好友申请
myinfo                修改资料: myinfo nickname/impresa 内容(呢称/心情)
help                   帮助菜单: help/?
exit                   退出系统: quit/exit
****************************************************************

sms 137******** "this is test message" # 这个就是我们需要的发送短信的指令啦!
脚本测试:
可以使用fetion的-b参数来实现p处理;
举例如下:

# vi p.sh
sms 13712312311 “msyqlserver is down”
sms 13712312312 “db1 is not running”
sms 13712312313 “warning db2 disk3 is full”
保存后执行:
./fetion -u 13713718888 -p 123456 -b p.sh
就是一次给3个admin发出报警信息。
还有许多插件的功能,我会在下次实际应用中写出日志和大家一起研究;
在初步接触中,发现可以实现一些交互信息的查询,比如直接向短信机器人发指令得到某台服务器的运行状态等。
 
附带飞信2009-nagios报警配置
nagios 可以发送报警信息
修改/usr/local/nagios/etc/objects/commands.cfg,在文件开始部分添加如下几行:
# 'host-notify-by-sms' command definition
define command {
             command_name            host-notify-by-sms
             command_line            /usr/local/nagios/share/im/install/fetion --mobile=13570855555 --pwd=111111 --to=$CONTACTPAGER$ --msg-utf8="Host $HOSTSTATE$ alert for $HOSTNAME$! on '$LONGDATETIME$'" $CONTACTPAGER$
             }
 
# 'service-notify-by-sms' command definition
define command {
             command_name         service-notify-by-sms
             command_line         /usr/local/nagios/share/im/install/fetion --mobile=13570855555 --pwd=111111 --to=$CONTACTPAGER$ --msg-utf8="$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$" $CONTACTPAGER$
             }
修改templates.cfg 红色字体部分或者修改contacts.cfg
define contact{
        name                            generic-contact         ; The name of this contact template
        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-fetion        ; send service notifications via email
        host_notification_commands      notify-host-by-fetion   ; send host notifications via email
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        }
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
        host_notifications_enabled 1
        service_notifications_enabled 1
        service_notification_options u,c
        host_notification_options d,u
        service_notification_commands notify-service-by-fetion
        host_notification_commands notify-host-by-fetion
        can_submit_commands 1
         email                                ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
另外,我们不知道这个版本的飞信机器人哪天会突然出问题(我就遇到过这样的问题),所以写
个每天定时使用飞信机器人发送nagios 进程号的信息。
vi /usr/local/nagios/fetion/test_everyD
#!/bin/bash
msg=`service nagios status`
/usr/local/nagios/fetion/fetion --mobile=15812345678 --pwd=FetionPWD --msgutf8="*$
msg \n$(date +%D\ %H:%M)*" --msg-type=1 --to=15812345678,15
912345678
chown nagios.nagios /usr/local/nagios/fetion/fetion
chmod 644 /usr/local/nagios/fetion/fetion
echo '00 21 * * * nagios /usr/local/nagios/fetion/test_everyD' >>/etc/crontab
至此我们就可以在各被监控机的配置文件里定义报警阀值,由nagios 监控机监测并发出报警信
息。
 
新版本飞信机器人下载