nagios強大的報警功能是其被很多企業選用的一個重要原因,比較常見的報警方式有E-mail、sms和自由腳本,本文主要介紹通過中國特色的飛信實現nagios報警的配置方法。(注:本文是前面兩篇文章(nagios安裝與基本配置)的後繼文章)
一、所用軟件
要實現飛信報警就要用支持Linux版本的飛信機器人,現在最新版本爲20101205002,可以在http://bbs.it-adv.net/viewthread.php?tid=1081下載,但這只是飛信主程序,其安裝包還是2009版的,可以在http://bbs.it-adv.net/viewthread.php?tid=916&extra=page%3D1下載,安裝完2009版之後用上面2010版的飛信主程序fetion覆蓋2009版的就可以了。在安裝飛信機器人之前還要安裝libACE程序,因爲飛信機器人要運行在libACE庫文件之上,下載地址爲http://www.it-adv.net/fetion/downng/library_linux.tar.gz
二、飛信機器人安裝與配置
tar -zxvf library_linux.tar.gz
tar -zxvf fetion20091117-linux.tar.gz
將libACE-5.6.8.so,libACE_SSL-5.6.8.so,libcrypto.so.0.9.8,libssl.so.0.9.8四個文件移動到飛信主目錄fx下
mkdir /usr/local/fx
將上面的fx文件夾移動到/usr/local/目錄下
chmod -R 755 /usr/local/fx
chown -R nagios:nagios /usr/local/fx
vi /etc/ld.so.conf
在最後加上一行:/usr/local/fx保存退出
ldconfig
現在就可以發一條飛信試驗下了,例如執行下面的語句:
/usr/local/fx/fetion --mobile=1300138000 --pwd=123456 --to=13800138000 --msg-utf8=testing
很快13800138000就會收到內容爲“testing”的飛信消息。
三、修改nagios配置文件實現飛信報警
1.在contacts.cfg文件中加入紅色部分內容:
define contact{
contact_name nagiosadmin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email,service-notify-by-fx
host_notification_commands host-notify-by-email,host-notify-by-fx
email [email protected]
pager 13800138000
}
2.在commands.cfg文件中加入如下內容:
# 'notify-host-by-fx' command definition
define command {
command_name host-notify-by-fx ; command_line /usr/local/fx/fetion --mobile=13800138000 --pwd=123456 --to=$CONTACTPAGER$ --msg-utf8="Host $HOSTSTATE$ alert for $HOSTNAME$! on '$LONGDATETIME$'" $CONTACTPAGER$ }
# 'notify-service-by-fx' command definition
define command {
command_name service-notify-by-fx command_line /usr/local/fx/fetion --mobile=13800138000 --pwd=123456 --to=$CONTACTPAGER$ --msg-utf8="$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$" $CONTACTPAGER$
}
好了大功告成,重啓nagios服務之後就可以實現飛信報警了。