Monitorowanie stanu hostów#

   Podobnie jak poprzedni ten skrypt słuzy do monitorowania stanu hostów. W tym celu próbuję pingnąć hosta docelowego po ICMP wykorzystując mechanizm WMI, oraz pingnąć hosta zródłowego po ICMP korzystając z zdalnego wywołania procedury po WMI. Jako wynik dostajemy 1 jeśli ping się powiódł , i 0 jeśli zawiódł. Oczywiście jeśli ping nie doszedł, skrypt jeszcze raz próbuje się dostać do hosta, a jesli i ta próba zakończy się niepowodzeniem, wysyła emaila do administratora.

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objArgs = WScript.Arguments

if objArgs.count > 0 then
    addr=objArgs(0)
else
    addr = "localhost"
end if

strComputer="localhost"
pingstatus=0
wmistatus=0

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT StatusCode FROM Win32_PingStatus where address = '"&addr&"'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
if IsNull(objItem.StatusCode) then
pingstatus=0
else
pingstatus=1
end if
Next
Set objWMIServiceR = GetObject("winmgmts:\\" & addr & "\root\CIMV2")
Set colItemsR = objWMIServiceR.ExecQuery("SELECT StatusCode FROM Win32_PingStatus where address = '"&strComputer&"'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItemsR
if IsNull(objItem.StatusCode) then
wmistatus=0
else
wmistatus=1
end if
Next

if (wmistatus=0 or pingstatus=0) then
wmistatus=0
pingstatus=0
WScript.Sleep 10000
Set objWMIServiceN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItemsN = objWMIServiceN.ExecQuery("SELECT StatusCode FROM Win32_PingStatus where address = '"&addr&"'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItemsN
if IsNull(objItem.StatusCode) then
pingstatus=0
else
pingstatus=1
end if
Next
Set objWMIServiceNR = GetObject("winmgmts:\\" & addr & "\root\CIMV2")
Set colItemsNR = objWMIServiceNR.ExecQuery("SELECT StatusCode FROM Win32_PingStatus where address = '"&strComputer&"'", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItemsNR
if IsNull(objItem.StatusCode) then
wmistatus=0
else
wmistatus=1
end if
Next
if (wmistatus=0 or pingstatus=0) then
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Brak odpowiedzi z serwera " & addr
objMessage.From = """RRdTooL Server Watch"" <pkrzysz@pjwstk.edu.pl>"
objMessage.To = "pkrzysz@pjwstk.edu.pl;kfaz@pjwstk.edu.pl"
objMessage.TextBody = "Serwer " & addr &"nie odpowiada na Pingi "&vbCRLF&_
"Trzeba sprawdzic http://peki.pjwstk.edu.pl/rrdtool "&vbCRLF&_
         "zobaczyć co się dzieje i ewentualnie zrestartować."

'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "dfs2"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send
end if
end if

wscript.echo wmistatus
wscript.echo pingstatus

wscript.echo Date() & " " & Time()

wscript.echo "WMI ping"
wscript.echo "ICMP Ping"
Wscript.echo cmpName

   Skrypcik oczywiście chodzi w Schedulerze co 10min, i jest podpiety do MRTG/rrdtool generujacego statystyki - http://peki.pjwstk.edu.pl/rrdtool

Monday, November 14, 2005 7:27:15 PM (Central European Standard Time, UTC+01:00) #    Comments [1]  |  Trackback

 

Wednesday, May 17, 2006 5:26:28 PM (Central European Standard Time, UTC+01:00)
Super site ! Bravo au webmaster qui a su rendre le site tres interressant.Continue comme ca ;)
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview
All content © 2010, Krzysztof Pietrzak
On this page
This site
Calendar
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Archives
Sitemap
Blogroll OPML
  Tokyo by night
blog WiTa
  W-Files
blog n€x¤Ra
 .:fotoblog:.
blog Kfaza
 \\archon\blog$
blog archona
 Czasowstrzymywacz
Blog Fookyego
 Jog Pstryka
Jog Pstryka
 Mac OS X vs. Active Directory
techniczny blog kfaza

Maps
Locations of visitors to this page