| Author |
Message |
Eric Smith
Guest
|
Posted:
Mon Nov 14, 2005 5:50 pm Post subject:
Problems with MOM scripts just not working... |
|
|
I have the following script:
strComputer = ScriptContext.TargetComputer
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address = '" & strComputer & "'")
For Each objItem in colItems
if objItem.StatusCode = 0 then
strTitle = "Ping Status GOOD!"
strMsg = "Return Status code = " & objItem.StatusCode
MsgBox strMsg,, strTitle
else
strTitle = "Ping Status FAILURE!"
strMsg = "Return Status code = " & objItem.StatusCode
MsgBox strMsg,, strTitle
end if
Next
That is scheduled to run every 2 minutes using a timed provider that I
setup. The problem is I get no message boxes and nothing in the event logs.
I have degugging enabled for all scripts and I don't even get the error that
I used to get, "No script debugger is installed. Please install a script
debugger." What's happening with my script? Is there something I can look
at that if nothing else says, "Your script is retarded please try again"?
TIA
Eric Smith |
|
| Back to top |
|
 |
Geoff C
Guest
|
Posted:
Mon Nov 14, 2005 5:50 pm Post subject:
Re: Problems with MOM scripts just not working... |
|
|
I got started with scripting MOM here:
http://www.microsoft.com/technet/scriptcenter/hubs/mom.mspx
The response should really be submitted into the MOM data stream as an
event. The first two articles deal with that pretty effectively. I
return responses with scriptcontext.echo, and they come up in the
event.
My Ping Script hobbled together with the help of this resource and many
others:
Dim objParams
Dim objMOMEvent
strTargetPC = ScriptContext.Parameters.Get("Computer")
strComputer = "."
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
'-- 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."
Else
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."
End If
Next
' -- Reset all variables
Set objMOMEvent = Nothing |
|
| Back to top |
|
 |
Eric Smith
Guest
|
Posted:
Mon Nov 14, 2005 5:50 pm Post subject:
Re: Problems with MOM scripts just not working... |
|
|
Ideally you would want to use a VarSet object to track ping responses for
each computer in the group that you have the rule applied to and only alert
if successive attempts to ping a machine don't respond (to avoid the reboot
scenario). Outside of that, where's the rule that says I can't generate a
messagebox? This is something simple (I have no problems changing it to a
log file) that will allow a script tester to determine if their script is
working or not; but then that's what I'm really getting at; how can I tell if
my script is even working? How do I test it for errors if there's no way to
test out of context? |
|
| Back to top |
|
 |
|
|
|
|