Thursday, January 20, 2011

OpsLogix Ping MP Target Host Export Script

Many SCOM environments are using the OpsLogix Ping MP. A nice MP it is since it adds basic and easy to use Ping functionality to SCOM. This MP is build in such a manner that one can easily import many devices based on their IP addresses and friendly names:
image

But wouldn’t it be nice to have an option to export the devices as well? Into the same format (IP address and friendly name) so when the list of devices in the MP gets corrupted or damaged in any kind of way, one is easily back on track again by importing the latest export file?

Yesterday I visited a customer of mine. One of his system engineers bumped into the issue where the list of devices got corrupted so he was forced to add many of the devices by hand since the import list – originally used - wasn’t up to date any more.

Since he is a real script kiddo, he built a PS-script which exports the list of devices present in the OpsLogix Ping MP. This script is managed by Task Scheduler so it runs on a regular basis. That way he has always a backup available in case ‘disaster’ strikes. Some time ago disaster struck again. But now he had this export file, ready to be used. Within a few minutes all the devices were back again!

I asked him whether I am allowed to blog about it and to share his script with the Community. And guess what: he agreed. But he doesn’t want me to mention his name, so let’s call him Mister X. This is his favorite lunch:

All credits go to him. Thank you Mister X! Much appreciated. I owe you a hamburger!

The export functionality comes in two parts:

  1. A batch files which calls the PS-script;
  2. The PS-script which exports the devices present in the OpsLogix Ping MP to a file.

The batch file is managed by the Task Scheduler in order to have it run on a scheduled basis. The entries in red need modification:

  1. The location of the PS-script;
  2. The name of the RMS;
  3. The location of the export file.

Batch File:

@echo off
powershell d:\scripts\opslogix\opslogix.ps1

PS script (opslogix.ps1):

$rootMS="NAME OF RMS"

# ========================================================================================
# Initializing OpsMgr 2007 Powershell provider
# ========================================================================================
     add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin ;
     set-location "OperationsManagerMonitoring::" -ErrorVariable errSnapin ;
     new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin ;
     set-location $rootMS -ErrorVariable errSnapin ;

  del d:\scripts\opslogix\opslogix.log

  $mclass = get-monitoringclass -name "OpsLogix.IMP.Ping.Target"
  $mo = Get-MonitoringObject -monitoringclass:$mclass | ForEach-Object {
    $IP = $_.PathName
    $IP = $IP.Replace("%002d","-")
    $IP = $IP.SubString($IP.IndexOf("%003a")+5)
    write-host $IP
    $regel = $_.DisplayName + ";" + $IP
    Add-Content "d:\scripts\opslogix\opslogix.log" $regel
  }

I am sure many people will appreciate this. Nice!

Of course, before importing the file again, one or more valid Source Hosts must be present.

5 comments:

Kurt Renner said...

I'm looking to integrate our asset management system with the OpsLogix Ping MP using powershell to add target clients automatically based on classification of systems in our asset management system and whether or not they are monitored systems in SCOM. Any insight on how that might be accomplished?

Marnix Wolf said...

Hi Kurt.

What you're looking add is a magnificent example for SCOrch: it connects into your asset management system, makes a cross reference in order to find newly added devices, and when found, start another workflow to add them OpsMgr. This is the overview of course, but SCOrch is certainly the way to go here.

Cheers,
Marnix

Kurt Renner said...

Thanks for your response Marnix.

We do not yet have Orchestrator deployed because of lack of resources at this time. If you have any thoughts on how I might be able to automate this outside of Orchestrator using powershell, I'd love to hear them.

All I need is a simple example of how to add/remove a target to/from the OpsLogix MP via powershell. I can figure out the rest.

Marnix Wolf said...

Hi Kurt.

I am sorry but that kind of information I don't have at hand right now and takes time to get it. And time I don't have at this moment (closing of the year and just a couple of days left before holiday season kicks in :) )

So what you could do instead is to check the PS cmdlets for SCOM/OM and perhaps even contact OpsLogix with your questions. It's their MP and perhaps they can tell you what route to take here.

Cheers,
Marnix

Kurt Renner said...

Understand. Thanks for the discussion.