{"id":189,"date":"2007-06-26T22:40:58","date_gmt":"2007-06-26T20:40:58","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=189"},"modified":"2007-07-02T10:30:52","modified_gmt":"2007-07-02T08:30:52","slug":"ping-script-in-ops-mgr-2007","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=189","title":{"rendered":"Ping Script in Ops Mgr 2007"},"content":{"rendered":"<p>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.<\/p>\n<ol>\n<li>Start the console, click Authoring and then expand Management Pack Objects, right-click Rules and choose Create a new rule&#8230;<\/li>\n<li>Create Rule Wizard &#8211; Rule Type: Choose Timed Command\/Execute a script, choose management pack and click Next<\/li>\n<li>Create Rule Wizard &#8211; 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<\/li>\n<li>Create Rule Wizard &#8211; Schedule: Choose how often the script should be executed, click Next<\/li>\n<li>Create Rule Wizard &#8211; 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.<\/li>\n<\/ol>\n<p><code>Hosts = \"CODC99,ping.sunet.se\"aMachines = Split(Hosts, \",\")<br \/>\nstrLog = \"1\"<br \/>\nFor Each machine in aMachines<br \/>\nSet objPing = GetObject(\"winmgmts:{impersonationLevel=impersonate}\")._<br \/>\nExecQuery(\"select * from Win32_PingStatus where address = '\"_<br \/>\n& machine & \"'\")<br \/>\nFor Each objStatus in objPing<br \/>\nIf IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Const EVENT_WARNING = 2<br \/>\n\u00c2\u00a0Set objShell = CreateObject(\"Wscript.Shell\")<br \/>\n\u00c2\u00a0objShell.LogEvent EVENT_WARNING, _<br \/>\n\u00c2\u00a0\"Computer \" & machine & \" is not reachable (\" & strLog & \")\"<br \/>\nELSE<br \/>\n\u00c2\u00a0IF strLog = 1 Then<br \/>\n\u00c2\u00a0\u00c2\u00a0Const EVENT_SUCCESS = 0<br \/>\n\u00c2\u00a0\u00c2\u00a0Set objShell = CreateObject(\"Wscript.Shell\")<br \/>\n\u00c2\u00a0\u00c2\u00a0objShell.LogEvent EVENT_SUCCESS, _<br \/>\n\u00c2\u00a0\u00c2\u00a0\"Computer \" & machine & \" is reachable\"<br \/>\n\u00c2\u00a0End If<br \/>\nEnd If<br \/>\nNext<br \/>\nNext<\/code><\/p>\n<p>If you set strLog = &#8220;1&#8221; 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.\u00c2\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. Start the console, click Authoring and then expand Management Pack Objects, right-click Rules and choose Create a new rule&#8230; Create Rule Wizard &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=189\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[19],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/189"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=189"}],"version-history":[{"count":0,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}