<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="网卡速率状态变化自动微信通知">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">熊茂祥</a><br />时间:2020-05-07 13:50<br />分类:<a href="index.php?action=list&amp;cid=3&amp;hash=">ROS</a><br />标签:<a href="index.php?action=tags&amp;item=ros&amp;hash=">ros</a>, <a href="index.php?action=tags&amp;item=%E9%80%9A%E7%9F%A5&amp;hash=">通知</a>, <a href="index.php?action=tags&amp;item=%E5%BE%AE%E4%BF%A1&amp;hash=">微信</a>, <a href="index.php?action=tags&amp;item=%E5%91%8A%E8%AD%A6&amp;hash=">告警</a>, <a href="index.php?action=tags&amp;item=%E6%B6%88%E6%81%AF&amp;hash=">消息</a><br />内容:
有的人不知道本站开通的微信通知中心有什么用。那我就举个栗子！


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

点击添加微信通知中心为好友


ROS脚本


    :global oethlink  

    :global oethspeed  

    :global nethname &quot;&quot;  

    :global nethlink &quot;&quot;  

    :global nethspeed &quot;&quot;  

    :global msg &quot;&quot;  

    :global ethlink &quot;&quot;  

    :global ethspeed &quot;&quot;  

    :foreach ceth in=[/interface ethernet find] do={  

    :global ethname [/interface ethernet get $ceth name]  

    /interface ethernet mon $ethname once do={  

    :set ethlink $&quot;status&quot;  

    :set ethspeed $&quot;rate&quot;  

    }  

    :set nethname ($nethname.$ethname.&quot;,&quot;)  

    :set nethlink ($nethlink.$ethlink.&quot;,&quot;)  

    :set nethspeed ($nethspeed.$ethspeed.&quot;,&quot;)  

    }  

    :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].&quot;状态变化为:&quot;.[:pick $nethlink $ceths].&quot;,&quot;)}  

    :if (([:pick $nethspeed $ceths] != [:pick $oethspeed $ceths]) &amp;&amp; ([:pick $nethlink $ceths] = &quot;link-ok&quot;)) do={  

    :set msg ($msg.[:pick $nethname $ceths].&quot;速率变化为:&quot;.[:pick $nethspeed $ceths].&quot;,&quot;)}  

    }  

    :set msg [:pick $msg 0 ([:len $msg] -1)]  

    :set oethlink $nethlink  

    :set oethspeed $nethspeed  

    :if ([:len $msg] &gt;6) do={  

    ###通知语言###  

    :local lang &quot;CN&quot;  

    ###通知微信ID或者群ID###  

    :local wxid &quot;ros6&quot;  

    ###通知节点名###  

    :local nodename [/system identity get name]  

    ###通知信息内容###  

    :local info $msg  

    /tool fetch url=(&quot;http://mail.ros6.com/wx/msg.php\?act=sendmsg&amp;wxid=$wxid&amp;node=$nodename&amp;msg=$info&amp;lang=$lang&quot;) mode=http keep-result=no}  





 
</p><p>
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
