计划任务 主动ping服务器是否宕机的vbs脚本


' ********************************************************************************
' * Ping utility: internalPing.vbs
' ********************************************************************************
on error resume next


Set PingTool=WScript.CreateObject("WebTool.Ping")


'------------------Server Admin List----------------------
PingServer "10.**.**.*1","H.B","X.X"
PingServer "10.**.**.*2","H.B","X.X"
'---------------------------------------------------------


Set PingTool=nothing


'---------------------------------------------------------------------------------
'PingServer
Sub PingServer(serverName, adminAccount, ccAccount)
intTimeOut=5000
intPacketSize=32
intInterval=100
intPacketCount=3


pingResult=PingTool.Ping(serverName,intTimeOut,intPacketSize,intInterval,intPacketCount,"P")
WScript.Sleep 1000 'Sleep
'WScript.Echo pingResult

if pingResult=11010 then
'Down
siteStatus=4
Call SendSMS(serverName, adminAccount, ccAccount) 'Send SMS
elseif PingTool.Average>1000 or PingTool.PacketsReceived<=2 then
'Very slow
siteStatus=3
elseif PingTool.Average>=500 then
'Slow
siteStatus=2
else
'OK
siteStatus=1
end if

WScript.Sleep 1000 'Sleep
End Sub


'Send SMS
Sub SendSMS(serverName, adminAccount, ccAccount)
strMessage="Notify ["+serverName+"] Down @ "+cstr(now)


Set conSMS=CreateObject("ADODB.Connection")
conSMS.open "Provider=SQLOLEDB.1;Server=****;Database=***;Uid=***;Pwd=***;"

'SMS
conSMS.execute "exec sms.dbo.AddMessage_NetDetecter '"+adminAccount+"','PingServer','"+strMessage+"'"
conSMS.execute "exec sms.dbo.AddMessage_NetDetecter '"+ccAccount+"','PingServer','"+strMessage+"'"

'Mail
adminMailAddress=replace(replace(trim(adminAccount)," ","."),"..",".")+"@corp.com"
ccMailAddress=replace(replace(trim(ccAccount)," ","."),"..",".")+"@corp.com"
conSMS.execute "exec SP_MS_MAIL_ADD 'PingServer','Mail','','"+adminMailAddress+"','"+ccMailAddress+"','','["+serverName+"] PingServer Notify','"+strMessage+"'"

conSMS.close
Set conSMS=nothing
End Sub

你可能感兴趣的:(计划任务 主动ping服务器是否宕机的vbs脚本)