将飞信拷贝到nagios命令目录
cp fetion /usr/local/nagios/libexec/
chmod +x /usr/local/nagios/libexec/fetion
tar zxf linuxso_20101113.tar.gz -C /lib
chown nagios.nagios /usr/local/nagios/libexec/fetion
su - nagios
中间可能用到的包
yum install /lib/ld-linux.so.2
发送飞信短信
/usr/local/nagios/libexec/fetion --mobile=13679270227 --pwd=Yakexi007 --to=186***** --msg-utf8="hello"
如果想要nagios发送短信需要
cd /usr/local/nagios/libexec/
vim fetion.sh
在里面写入
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$ " }
/usr/local/nagios/libexec/fetion --mobile=186***** --pwd=***** --to="$1" --msg-utf8="$2"
之后修改其他文件
cd /usr/local/nagios/etc/objects/
vim commands.cfg
添加一下内容
# 'notify-host-by-fetion' command definition
//$USER1$/fetion.sh相当于/usr/local/nagios/libexec/fetion.sh
//$CONTACTPAGER$ 是那个命令里面的$1
//"$NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ "是$2
之后修改
vim templates.cfg
service_notification_commands notify-service-by-email,
notify-service-by-fetion
host_notification_commands notify-host-by-email,
notify-host-by-fetion //在34,35行后面添加
vim contacts.cfg
添加
pager 186****** //在36行添加联系人
文件修改部分整体内容如下
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 useremail nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
pager 186****** }
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 做完之后一定要检查语法。并且重启服务