| Author |
Message |
Geoff C
Guest
|
Posted:
Wed Nov 09, 2005 9:51 pm Post subject:
Ping a down server |
|
|
Okay, what I'm trying to do is create an escalation scenario.
Something native to the product would be preferred, but I'll be happy
to try and script it. What is really irritating is that VBScript that
works on my desktop has no bearing on the MOM-ified VBScript.
Where I'm at is that I have a task I'm using to execute my VBScript and
see the results before I try to even pull the parameters through from
an event. I set the task to run against either the MOM Agent role or
the Computer role, and don't like the result either way.
It seems the 'Computer' parameter or the 'Instance' parameter are sent
along with the DOMAIN\ (or in Instance DOMAIN\COMPUTER\) as a prefix.
So the ping fails.
Can somebody look at this and tell me what I'm missing? It's been 3
days since the WScript version worked with no progress.
------------------------------------------------------------------------------------------
Dim objParams
Dim objMOMEvent
strTargetPC = ScriptContext.Parameters.Get("Computer")
strComputer = "."
' Going to have the script sleep a while and then check.
' I don't want to know unless the server doesn't come back.
ScriptContext.Sleep 600
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery _
("Select * from Win32_PingStatus Where Address = '" & strTargetPC &
"'")
For Each objComputer in colPingedComputers
If objComputer.StatusCode = 0 Then
Set objMOMEvent = ScriptContext.CreateEvent()
objMOMEvent.EventSource = "MOM Ping Monitor Tool"
objMOMEvent.EventNumber = 10002
objMOMEvent.EventType = 1
objMOMEvent.Message = "Ping Test to " & strTargetPC & " failed.
Please investigate."
'-- Submit Created Error Event to MOM data stream
ScriptContext.Submit(objMOMEvent)
ScriptContext.Echo "Ping Test to " & strTargetPC & " failed.
Please investigate."
Else
'-- Create information event and submit to MOM data stream for
tracking purposes
Set objMOMEvent = ScriptContext.CreateEvent()
objMOMEvent.EventSource = "MOM Ping Monitor Tool"
objMOMEvent.EventNumber = 10001
objMOMEvent.EventType = 4
objMOMEvent.Message = "Ping Test to " & strTargetPC & "
succeeded. No action necessary."
'-- Submit Created Error Event to MOM data stream
ScriptContext.Submit(objMOMEvent)
ScriptContext.Echo "Ping Test to " & strTargetPC & " succeeded.
No action necessary."
End If
Next
' -- Reset all variables
Set objMOMEvent = Nothing |
|
| Back to top |
|
 |
Rune Norberg
Guest
|
Posted:
Wed Nov 09, 2005 9:51 pm Post subject:
Re: Ping a down server |
|
|
One problem seems to be that you are interprenting the statuscode property
of the win32_pingstatus class wrong. Statuscode = 0 is returned when the
ping is successfull, but you are generating an failure event in your script?
For more information see take a look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_pingstatus.asp
/Rune
"Geoff C" <geoff.crego@gmail.com> wrote in message
news:1131564934.775187.123050@g14g2000cwa.googlegroups.com...
| Quote: | Okay, what I'm trying to do is create an escalation scenario.
Something native to the product would be preferred, but I'll be happy
to try and script it. What is really irritating is that VBScript that
works on my desktop has no bearing on the MOM-ified VBScript.
Where I'm at is that I have a task I'm using to execute my VBScript and
see the results before I try to even pull the parameters through from
an event. I set the task to run against either the MOM Agent role or
the Computer role, and don't like the result either way.
It seems the 'Computer' parameter or the 'Instance' parameter are sent
along with the DOMAIN\ (or in Instance DOMAIN\COMPUTER\) as a prefix.
So the ping fails.
Can somebody look at this and tell me what I'm missing? It's been 3
days since the WScript version worked with no progress.
------------------------------------------------------------------------------------------
Dim objParams
Dim objMOMEvent
strTargetPC = ScriptContext.Parameters.Get("Computer")
strComputer = "."
' Going to have the script sleep a while and then check.
' I don't want to know unless the server doesn't come back.
ScriptContext.Sleep 600
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery _
("Select * from Win32_PingStatus Where Address = '" & strTargetPC &
"'")
For Each objComputer in colPingedComputers
If objComputer.StatusCode = 0 Then
Set objMOMEvent = ScriptContext.CreateEvent()
objMOMEvent.EventSource = "MOM Ping Monitor Tool"
objMOMEvent.EventNumber = 10002
objMOMEvent.EventType = 1
objMOMEvent.Message = "Ping Test to " & strTargetPC & " failed.
Please investigate."
'-- Submit Created Error Event to MOM data stream
ScriptContext.Submit(objMOMEvent)
ScriptContext.Echo "Ping Test to " & strTargetPC & " failed.
Please investigate."
Else
'-- Create information event and submit to MOM data stream for
tracking purposes
Set objMOMEvent = ScriptContext.CreateEvent()
objMOMEvent.EventSource = "MOM Ping Monitor Tool"
objMOMEvent.EventNumber = 10001
objMOMEvent.EventType = 4
objMOMEvent.Message = "Ping Test to " & strTargetPC & "
succeeded. No action necessary."
'-- Submit Created Error Event to MOM data stream
ScriptContext.Submit(objMOMEvent)
ScriptContext.Echo "Ping Test to " & strTargetPC & " succeeded.
No action necessary."
End If
Next
' -- Reset all variables
Set objMOMEvent = Nothing
|
|
|
| Back to top |
|
 |
Geoff C
Guest
|
Posted:
Wed Nov 09, 2005 9:51 pm Post subject:
Re: Ping a down server |
|
|
Rune,
Thank you. For some reason the one I ran from cscript worked exactly
backwards of that.
It seems the more I dive into VB Script that as soon as people learn
what objects are available, those objects get tossed aside for the
latest new cool way of doing the same thing with 10 more lines of code
than before. I was tring to understand how to use OpScrUtil, but now
everybody seems to have moved on. :P
Now to make it smart enough to run in response to the heartbeat
failure.....
Rune Norberg wrote:
| Quote: | One problem seems to be that you are interprenting the statuscode property
of the win32_pingstatus class wrong. Statuscode = 0 is returned when the
ping is successfull, but you are generating an failure event in your script?
For more information see take a look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_pingstatus.asp
/Rune
"Geoff C" <geoff.crego@gmail.com> wrote in message
news:1131564934.775187.123050@g14g2000cwa.googlegroups.com...
Okay, what I'm trying to do is create an escalation scenario.
Something native to the product would be preferred, but I'll be happy
to try and script it. What is really irritating is that VBScript that
works on my desktop has no bearing on the MOM-ified VBScript.
Where I'm at is that I have a task I'm using to execute my VBScript and
see the results before I try to even pull the parameters through from
an event. I set the task to run against either the MOM Agent role or
the Computer role, and don't like the result either way.
It seems the 'Computer' parameter or the 'Instance' parameter are sent
along with the DOMAIN\ (or in Instance DOMAIN\COMPUTER\) as a prefix.
So the ping fails.
Can somebody look at this and tell me what I'm missing? It's been 3
days since the WScript version worked with no progress.
------------------------------------------------------------------------------------------
Dim objParams
Dim objMOMEvent
strTargetPC = ScriptContext.Parameters.Get("Computer")
strComputer = "."
' Going to have the script sleep a while and then check.
' I don't want to know unless the server doesn't come back.
ScriptContext.Sleep 600
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery _
("Select * from Win32_PingStatus Where Address = '" & strTargetPC &
"'")
For Each objComputer in colPingedComputers
If objComputer.StatusCode = 0 Then
Set objMOMEvent = ScriptContext.CreateEvent()
objMOMEvent.EventSource = "MOM Ping Monitor Tool"
objMOMEvent.EventNumber = 10002
objMOMEvent.EventType = 1
objMOMEvent.Message = "Ping Test to " & strTargetPC & " failed.
Please investigate."
'-- Submit Created Error Event to MOM data stream
ScriptContext.Submit(objMOMEvent)
ScriptContext.Echo "Ping Test to " & strTargetPC & " failed.
Please investigate."
Else
'-- Create information event and submit to MOM data stream for
tracking purposes
Set objMOMEvent = ScriptContext.CreateEvent()
objMOMEvent.EventSource = "MOM Ping Monitor Tool"
objMOMEvent.EventNumber = 10001
objMOMEvent.EventType = 4
objMOMEvent.Message = "Ping Test to " & strTargetPC & "
succeeded. No action necessary."
'-- Submit Created Error Event to MOM data stream
ScriptContext.Submit(objMOMEvent)
ScriptContext.Echo "Ping Test to " & strTargetPC & " succeeded.
No action necessary."
End If
Next
' -- Reset all variables
Set objMOMEvent = Nothing
|
|
|
| Back to top |
|
 |
|
|
|
|