Home » System Center Operations Manager 2007 » Ping Script in Ops Mgr 2007

Ping Script in Ops Mgr 2007

A time ago I wrote a simple ping script for MOM 2005. Today I needed a script like that in Ops Mgr 2007, this is how I implemented it in Ops Mgr 2007.

  1. Start the console, click Authoring and then expand Management Pack Objects, right-click Rules and choose Create a new rule…
  2. Create Rule Wizard – Rule Type: Choose Timed Command/Execute a script, choose management pack and click Next
  3. Create Rule Wizard – General: Input a name, description and choose target. In this example I have create a small group of machines that will be the target. Click Next
  4. Create Rule Wizard – Schedule: Choose how often the script should be executed, click Next
  5. Create Rule Wizard – Script: Paste the following script in the script box, input a filename (for example ping_script.vbs) and then click Create. In this example I ping two machines, CODC99 and ping.sunet.se.

Hosts = "CODC99,ping.sunet.se"aMachines = Split(Hosts, ",")
strLog = "1"
For Each machine in aMachines
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& machine & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
        Const EVENT_WARNING = 2
 Set objShell = CreateObject("Wscript.Shell")
 objShell.LogEvent EVENT_WARNING, _
 "Computer " & machine & " is not reachable (" & strLog & ")"
ELSE
 IF strLog = 1 Then
  Const EVENT_SUCCESS = 0
  Set objShell = CreateObject("Wscript.Shell")
  objShell.LogEvent EVENT_SUCCESS, _
  "Computer " & machine & " is reachable"
 End If
End If
Next
Next

If you set strLog = “1” you will get a local event for every sucessfully ping. If a machine is not reachable you will get a local event with event ID 2, type=warning and source=WSH. To get this into your console you will have to create a rule to collect them too. 


1 Comment

Comments are closed.