php短信报警直到响应,Cacti实现短信报警

一、 软件环境:cacti(需Threshold插件),飞信机器人(fetion)

二、 安装过程:

Cacti的Threshold插件下载及安装配置参见:

飞信机器人(fetion)下载及安装配置参见:系统监控:

三、 配置过程:

1.按照配置并启用thold

2.编辑cacti/plugins/thold/thold-functions.php

在thold–functions.php查找thold_mail($global_alert_address, ”, $subject, $msg, $file_array);行在此行下面加入:

exec("echo $subject >>/var/www/html/cacti/plugins/thold/alter.log");

exec("/var/www/html/cacti/plugins/thold/sendsms.sh");

查找 thold_mail($item["notify_extra"], ”, $subject,

$msg, $file_array);行在此行下面加入:

exec("echo $subject >>/var/www/html/cacti/plugins/thold/alter.log"); #将报警信息记录到alter.log

exec("/var/www/html/cacti/plugins/thold/sendsms.sh"); #执行sendsms.sh

备注:本人的thold安装在/var/www/html/cacti/plugins/thold/目录中,如果注释掉thold_mail,只通过短信发送报警。不注释掉thold_mail,会通过email和短信同时发送报警

thold-functions.php生成的alter.log范例如下:

192.168.1.207 - Used Space - G: Label: [hdd_percent] is still above threshold of 85 with 99

编写脚本sendsms.sh自动调用飞信机器人发送报警

#!/bin/sh

#send sms by fetion

#Write by John.Lv

if [ ! -e "/var/www/html/cacti/plugins/thold/alert.log" ];then #判断alter.log是否存在

echo "Usage:alert.log does not exist"

exit

fi

if [ -n "`cat /var/www/html/cacti/plugins/thold/alert.log`" ]; then #判断alter.log是否有报警信息

admin="135xxxxxxxx"  #短信接收人,需在你飞信的好友列表中

echo "sms $admin "`cat /var/www/html/cacti/plugins/thold/alert.log` >>/var/www/html/cacti/plugins/thold/sms.txt #发送alter.log中的报警信息给admin

echo "exit" >> /var/www/html/cacti/plugins/thold/sms.txt #退出飞信

else

echo "Usage:no alert"

exit

fi

if [ -n "`cat /var/www/html/cacti/plugins/thold/sms.txt`" ] ; then

/var/www/html/cacti/plugins/thold/install/fetion -u 13512345678 -p "123456" -b /var/www/html/cacti/plugins/thold/sms.txt  -EN

#调用fetion发送短信,命令格式和参数说明参见:系统监控:linux命令行-飞信客户端发送免费报警短信

rm -f /var/www/html/cacti/plugins/thold/sms.txt 1>/dev/null 2>&1

rm -f /var/www/html/cacti/plugins/thold/alert.log 1>/dev/null 2>&1

else

echo "Usgae:no message to send"

exit

fi

ok,配置完成了,现在就可以通过短信接收报警信息了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值