<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[【他人原创】机房温度监控--SecureCrt的实现]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 07 Oct 2010 03:41:48 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;注：本文系博主原创文章，转载请注明出处。<br/><br/> <br/><br/>===========================================一号分割线========================================<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;思科、华为等多层交换机一般都自带了板卡温度检测功能，对于这些骨干机房，若没有安装温度报警远程监控等设备的，可以使用思科、华为设备的温度自检功能来实现对机房温度的控制。<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;系统的实现的过程是，登陆相应的设备，使用show environment 命令，查询温度，再利用VB脚本功能，提取出相应的关键字，并判断温度。此外再结合计划任务功能，可以实现定时检测报警功能。<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;这边仅以Cisco 7609,4006等设备为例，说明其实现的过程。<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;-----------------------------------分割线------------------------------------------------<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;第一步：SecureCRT脚本编写，代码如下<br/><br/>#$language = &quot;VBScript&quot;<br/>#$interface = &quot;1.0&quot;<br/><br/>&#039;&#124;&#124;=================================&#124;&#124;<br/>&#039;&#124;&#124;Query BackBone Switch Temperature&#124;&#124;<br/>&#039;&#124;&#124;Edit By 王敩&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#124;&#124;<br/>&#039;&#124;&#124;2009-6-26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124;&#124;<br/>&#039;&#124;&#124;Ver 1.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124;&#124;<br/>&#039;&#124;&#124;=================================&#124;&#124;<br/><br/><br/>&#039;===========Start Define Global Parameters=========<br/>Dim FSO<br/>Dim line<br/>Dim SwitchArr(4,3)&nbsp;&nbsp;&#039;设备列表，行数代表设备数量，列用于存放相关数据<br/>Dim SplitKeyW(4,2) &#039;取字符用关键字列表<br/>Dim TempString &#039;临时存放温度相关行<br/>Dim NowRow &#039;存放当前光标所在行号<br/><br/>&#039;常量定义<br/>Const ForReading = 1<br/>Const ForAppending=8<br/>Const ForWriting=2<br/>Const HighTemperatureAlarmFile=&quot;D:&#92;SecureScript&#92;roomtemphigh.wav&quot;<br/>Const HighTemperatureShowFile=&quot;D:&#92;温度过高.txt&quot;<br/>beep = chr(007)<br/><br/>&#039;定义数据库连接<br/>Set conn=CreateObject(&quot;ADODB.Connection&quot;)<br/>conn.Open&quot;driver=&#123;sql server&#125;;server=x.x.x.x;uid=sa;pwd=sa;&quot;&amp;&quot;database=NMC;&quot;<br/><br/>&#039;数组定义<br/>SwitchArr(0,0)=&quot;x.x.x.x&quot;<br/>SwitchArr(0,1)=&quot;19&quot;&nbsp;&nbsp;&#039;代表温度关键字所在的行，用于SecureCRT<br/>SwitchArr(0,2)=&quot;设备一&quot;<br/>SwitchArr(1,0)=&quot;y.y.y.y&quot;<br/>SwitchArr(1,1)=&quot;4&quot;<br/>SwitchArr(1,2)=&quot;设备二&quot;<br/>SwitchArr(2,0)=&quot;z.z.z.z&quot;<br/>SwitchArr(2,1)=&quot;4&quot;<br/>SwitchArr(2,2)=&quot;设备三&quot;<br/>SwitchArr(3,0)=&quot;w.w.w.w&quot;<br/>SwitchArr(3,1)=&quot;4&quot;<br/>SwitchArr(3,2)=&quot;设备四&quot;<br/><br/>SplitKeyW(0,0)=&quot;temperature:&quot;&nbsp;&nbsp;&nbsp;&nbsp;&#039;温度字符前面的字符<br/>SplitKeyW(0,1)=&quot;C&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#039;温度字符后面的字符<br/>SplitKeyW(1,0)=&quot;=&quot;<br/>SplitKeyW(1,1)=&quot;degre&quot;<br/>SplitKeyW(2,0)=&quot;=&quot;<br/>SplitKeyW(2,1)=&quot;degre&quot;<br/>SplitKeyW(3,0)=&quot;=&quot;<br/>SplitKeyW(3,1)=&quot;degre&quot;<br/><br/>&#039;==============================Main Sub=======================================================<br/>Sub main<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;数据库路径及连接参数<br/>&nbsp;&nbsp;&nbsp;&nbsp;pass=&quot;*******&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;登陆设备的密码<br/>&nbsp;&nbsp;&nbsp;&nbsp;username=&quot;*******&quot;&nbsp;&nbsp;&#039;登陆设备的用户名<br/><br/> For i=0 To 3 <br/>&nbsp;&nbsp; &#039;连接设备，通过堡垒主机中转<br/>&nbsp;&nbsp;crt.Screen.WaitForString &quot;2,3]&quot;<br/>&nbsp;&nbsp;crt.Screen.Send &quot;1&quot; &amp; VbCr<br/>&nbsp;&nbsp;crt.Screen.WaitForString &quot;ip address and Enter:&quot;<br/>&nbsp;&nbsp;crt.Screen.Send SwitchArr(i,0) &amp; VbCr<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;&#039;crt.sleep 2000<br/>&nbsp;&nbsp;If (crt.Screen.WaitForString(&quot;Username:&quot;,5))=True Then<br/>&nbsp;&nbsp; crt.Screen.Send username &amp; VbCr<br/>&nbsp;&nbsp; crt.Screen.WaitForString(&quot;Password:&quot;)<br/>&nbsp;&nbsp; crt.Screen.Send pass &amp; VbCr<br/>&nbsp;&nbsp; crt.Screen.WaitForString &quot;&gt;&quot;,5<br/>&nbsp;&nbsp; crt.Screen.Send &quot;show environment temperature&quot; &amp; VbCr<br/>&nbsp;&nbsp; crt.Screen.WaitForString &quot;&gt;&quot;,5<br/>&nbsp;&nbsp; NowRow=crt.Screen.CurrentRow &#039;取得当前光标所在行号<br/>&nbsp;&nbsp; TempString=crt.Screen.Get2 (NowRow-Int(SwitchArr(i,1)),1,NowRow-Int(SwitchArr(i,1)),50)&nbsp;&nbsp;&#039;提取温度所在行<br/><br/>&nbsp;&nbsp; KeyStringStart=InStr(TempString,SplitKeyW(i,0))<br/>&nbsp;&nbsp; KeyStringEnd=InStr(TempString,SplitKeyW(i,1))<br/>&nbsp;&nbsp; If KeyStringStart&lt;&gt;0 And KeyStringEnd&lt;&gt;0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;TemperatureStr=Mid(TempString,KeyStringStart+Len(SplitKeyW(i,0)),KeyStringEnd-(KeyStringStart+Len(SplitKeyW(i,0))))<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;温度大于36度报警，一般36度对应机房温度在23度左右<br/>&nbsp;&nbsp;&nbsp;&nbsp;If Int(TemperatureStr)&gt;36 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; set wshShell = CreateObject(&quot;wscript.Shell&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp; &#039;使用文本文件显示报警，同时播放五次声音<br/>&nbsp;&nbsp;&nbsp;&nbsp; WshShell.Run &quot;cmd /c @echo 时间：&#123;&quot;&amp;Now()&amp;&quot;&#125;机房：&#123;&quot;&amp;SwitchArr(i,2)&amp;&quot;温度过高:&quot;&amp;TemperatureStr&amp;&quot;度&#125;&gt;&quot;&amp;HighTemperatureShowFile<br/>&nbsp;&nbsp;&nbsp;&nbsp; WshShell.Run &quot;notepad.exe &quot;&amp;HighTemperatureShowFile<br/>&nbsp;&nbsp;&nbsp;&nbsp; &#039;WshShell.Run &quot;cmd /c @echo &quot; &amp; beep&amp; beep&amp; beep&amp; beep, 0<br/>&nbsp;&nbsp;&nbsp;&nbsp; WshShell.Run HighTemperatureAlarmFile<br/>&nbsp;&nbsp;&nbsp;&nbsp; crt.sleep 2000<br/>&nbsp;&nbsp;&nbsp;&nbsp; WshShell.Run HighTemperatureAlarmFile<br/>&nbsp;&nbsp;&nbsp;&nbsp; crt.sleep 2000<br/>&nbsp;&nbsp;&nbsp;&nbsp; WshShell.Run HighTemperatureAlarmFile<br/>&nbsp;&nbsp;&nbsp;&nbsp; crt.sleep 2000<br/>&nbsp;&nbsp;&nbsp;&nbsp; WshShell.Run HighTemperatureAlarmFile<br/>&nbsp;&nbsp;&nbsp;&nbsp; crt.sleep 2000<br/>&nbsp;&nbsp;&nbsp;&nbsp;End If <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;准备将温度写入数据库<br/>&nbsp;&nbsp;&nbsp;&nbsp;strSqlInsert=&quot;insert into AutoLog_RoomTemperature (TemperatureTime,Temperature,TemperatureRoom) values (&#039;&quot;&amp;Now()&amp;&quot;&#039;,&#039;&quot;&amp;TemperatureStr&amp;&quot;&#039;,&#039;&quot;&amp;SwitchArr(i,2)&amp;&quot;&#039;)&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;conn.Execute(strSqlInsert)<br/>&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;set wshShell = CreateObject(&quot;wscript.Shell&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;WshShell.Run &quot;cmd /c @echo 时间：&#123;&quot;&amp;Now()&amp;&quot;&#125;机房：&#123;&quot;&amp;SwitchArr(i,2)&amp;&quot;关键字出错,开始字符:&#123;&quot;&amp;KeyStringStart&amp;&quot;&#125;结束字符:&#123;&quot;&amp;KeyStringEnd&amp;&quot;&#125;&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;WshShell.Run &quot;notepad.exe &quot;&amp;HighTemperatureShowFile<br/>&nbsp;&nbsp; End If<br/>&nbsp;&nbsp; crt.Screen.Send &quot;exit&quot; &amp; VbCr<br/>&nbsp;&nbsp;End If<br/> Next<br/> crt.Screen.WaitForString &quot;2,3]&quot;<br/> crt.Screen.Send &quot;3&quot; &amp; VbCr<br/> crt.session.disconnect()<br/> crt.quit<br/>End Sub<br/><br/>---------------------------------------分割线-----------------------------------------------<br/><br/>完了后保存为vbs文件，同时在SecureCrt里创建一会话，名字为checkTemperature，并勾选登陆脚本，选择该脚本。<br/><br/>然后再创建一计划任务，任务运行&quot;C:&#92;Program Files&#92;SecureCRT&#92;SecureCRT.EXE&quot; /S checkTemperature，日程安排 里高级选项中使用重复任务，每20分钟检测一次。<br/><br/>然后就可以测试运行效果了。<br/><br/> <br/><br/>总结：<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;该脚本考虑到实际情况，一般监控中心肯定有人在的，所以没有加入登陆失败的处理代码；登陆出错时，人工操作一下就行了，一般是由于网络时延过大引起的。有需要的朋友可以自己加。<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;华为的设备原理是一样的，只不过关键字可能不一样。大家可以自己根据情况添加。<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;欢迎大家共同讨论与提高<br/>来源：http://blog.sina.com.cn/s/blog_49cd61e70100drhx.html
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 【他人原创】机房温度监控--SecureCrt的实现]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>