华硕老毛子固件padavan路由器server酱单个设备上线下线快速响应。

待解决问题
由于padavan固件对设备下线的反应会有十几分钟的延迟,而server酱在设备上下线的判断是读取系统内的信息的,所以会在设备下线了很久才给推送,时效性差。

方法及原理
针对单一用户的上下线的判断条件进行修改,使得消息推送在上下线一分钟左右即可推送。原理是通过ping来判断该用户是否在线来决定是否推送,而脚本每分钟运行一次,因此可以保证在一分钟左右得到反馈。

具体步骤
首先要打开微信推送,获取到SCKEY后填入,并且打开设备上、下线提醒按钮

然后点开点这里自定义serverchan_script脚本,找到以下代码段:

if [ "$serverchan_notify_4" = "1" ] ; then
# 设备上、下线提醒
# 获取接入设备名称
touch /tmp/var/newhostname.txt
echo "接入设备名称" > /tmp/var/newhostname.txt
#cat /tmp/syslog.log | grep 'Found new hostname' | awk '{print $7" "$8}' >> /tmp/var/newhostname.txt
cat /tmp/static_ip.inf | grep -v "^$" | awk -F "," '{ if ( $6 == 0 ) print "【内网IP:"$1",MAC:"$2",名称:"$3"】 "}' >> /tmp/var/newhostname.txt
# 读取以往上线设备名称
touch /etc/storage/hostname_上线.txt
[ ! -s /etc/storage/hostname_上线.txt ] && echo "接入设备名称" > /etc/storage/hostname_上线.txt
# 上线
awk 'NR==FNR{a[$0]++} NR>FNR&&a[$0]' /etc/storage/hostname_上线.txt /tmp/var/newhostname.txt > /tmp/var/newhostname相同行_上线.txt
awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname相同行_上线.txt /tmp/var/newhostname.txt > /tmp/var/newhostname不重复_上线.txt
find /tmp/var/ -name "newhostname不重复_上线.txt" |xargs grep "192.168.121.23"
if [ $? == 0 ]; then
if [ -s "/tmp/var/newhostname不重复_上线.txt" ] ; then
content=`cat /tmp/var/newhostname不重复_上线.txt | grep -v "^$"`
curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【PDCN_"`nvram get computer_name`"】设备【上线】Online" -d "&desp=${content}" &
logger -t "【微信推送】" "PDCN设备【上线】:${content}"
cat /tmp/var/newhostname不重复_上线.txt | grep -v "^$" >> /etc/storage/hostname_上线.txt
fi
fi
# 下线
awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname.txt /etc/storage/hostname_上线.txt > /tmp/var/newhostname不重复_下线.txt
find /tmp/var/ -name "newhostname不重复_下线.txt" |xargs grep "192.168.121.23"
if [ $? == 0 ]; then
if [ -s "/tmp/var/newhostname不重复_下线.txt" ] ; then
content=`cat /tmp/var/newhostname不重复_下线.txt | grep -v "^$"`
curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【PDCN_"`nvram get computer_name`"】设备【下线】offline" -d "&desp=${content}" &
logger -t "【微信推送】" "PDCN设备【下线】:${content}"
cat /tmp/var/newhostname.txt | grep -v "^$" > /etc/storage/hostname_上线.txt
fi
fi
fi

替换成以下内容:

if [ "$serverchan_notify_4" = "1" ] ; then
ping -c 1 -W 2 192.168.121.201
a=$?
echo $a >> /tmp/var/new.txt
b=$(cat /tmp/var/last.txt)
if [ $a -ne $b ]; then
if [ $a == 0 ]; then
curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【该】设备【已上线】Online" &
logger -t "通知" "该设备已上线"
else
curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【该】设备【已下线】offline" &
logger -t "通知" "该设备已下线"
fi
fi
cp /tmp/var/new.txt /tmp/var/last.txt
rm /tmp/var/new.txt
fi

应用本页面设置即可

点赞

发表回复

您的电子邮箱地址不会被公开。