9939781 发表于 2020-5-7 19:02:07

网卡速率状态变化自动微信通知

有的人不知道本站开通的微信通知中心有什么用。那我就举个栗子!
功能说明:该脚本可以获取设备所有网卡链接状态和速率状态,并在发生改变时微信通知,方便提前处理链路隐患。比如某些情况下网口会从1G变成100M,但是如果在不之情的情况下继续用,会产生网络隐患和性能损失。该脚本定时运行即可完成周期性检测,异常自动微信通知。

点击添加微信通知中心为好友

:global oethlink
:global oethspeed
:global nethname ""
:global nethlink ""
:global nethspeed ""
:global msg ""
:global ethlink ""
:global ethspeed ""
:foreach ceth in= do={
:global ethname
/interface ethernet mon $ethname once do={
:set ethlink $"status"
:set ethspeed $"rate"
}
:set nethname ($nethname.$ethname.",")
:set nethlink ($nethlink.$ethlink.",")
:set nethspeed ($nethspeed.$ethspeed.",")
}
:set nethname [:toarray [:pick $nethname 0 ([:len $nethname] -1)]]
:set nethlink [:toarray [:pick $nethlink 0 ([:len $nethlink] -1)]]
:set nethspeed [:toarray [:pick $nethspeed 0 ([:len $nethspeed] -1)]]
:for ceths from=0 to=([:len $nethname] -1) do={
:if ([:pick $nethlink $ceths] != [:pick $oethlink $ceths]) do={
:set msg ($msg.[:pick $nethname $ceths]."状态变化为:".[:pick $nethlink $ceths].",")}
:if (([:pick $nethspeed $ceths] != [:pick $oethspeed $ceths]) && ([:pick $nethlink $ceths] = "link-ok")) do={
:set msg ($msg.[:pick $nethname $ceths]."速率变化为:".[:pick $nethspeed $ceths].",")}
}
:set msg [:pick $msg 0 ([:len $msg] -1)]
:set oethlink $nethlink
:set oethspeed $nethspeed
:if ([:len $msg] >6) do={
###通知语言###
:local lang "CN"
###通知微信ID或者群ID###
:local wxid "ros6"
###通知节点名###
:local nodename
###通知信息内容###
:local info $msg
/tool fetch url=("http://mail.ros6.com/wx/msg.php\?act=sendmsg&wxid=$wxid&node=$nodename&msg=$info&lang=$lang") mode=http keep-result=no}



57068368 发表于 2020-5-10 16:44:44

这个牛X了。
页: [1]
查看完整版本: 网卡速率状态变化自动微信通知