This post features a Powershell script that searches for instances of the Savisions Live Maps class that are not in a healthy state (Critical or Warning), in a OpsMgr 2007 R2 management group. Subsequently, the way to create a custom rule from this Powershell script in a management pack is demonstrated. (Download management pack)
* Note that for this Powershell script or management pack to work, Savisions Live Maps will need to be already in place and functioning in the OpsMgr 2007 R2 environment.
The Powershell script takes in the name of the Root Management Server (RMS) as a parameter, loads the OpsMgr Powershell snap-in and connects to the management group via the RMS.
It then collects information for all instances of the Savisions LiveMaps class, identifies instances that are not in a Healthy state and returns a list of URLs of their web version, which is the combination of the Live Maps Web Console URL and the unqiue object ID:
http://<Live Maps Web Console URL>/?moid=<unique ID>
To include the script in a custom rule, the Powershell script was modified to return its output in a propertybag, as highlighted below:
param([string] $RMS) # Load OpsMgr snap-in Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client -ErrorAction SilentlyContinue -ErrorVariable Err # Connect to OpsMgr New-ManagementGroupConnection $RMS -ErrorAction SilentlyContinue -ErrorVariable Err Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin; $API = new-object -comObject "MOM.ScriptAPI" $PropertyBag = $API.CreatePropertyBag() $ScriptName = "QueryObjectHealth.ps1" $newline = "`r`n" $tab = " " + "`t" $LiveMapURL="" $TargetClass = "Savision.LiveMaps.*.InstanceGroup" $LiveMaps = get-monitoringclass | where{$_.name -like $TargetClass} | get-monitoringobject if($LiveMaps) { Foreach($Map in $LiveMaps) { if($Map.HealthState -ne "Success") { # Combination of the Live Maps Web Console URL and the unqiue object ID. # Can be modified for other management groups using different ports or authentication methods. $LiveMapURL = $LiveMapURL + "http://" + $RMS +":52909/Default.aspx?moid="+ $Map.Id + $newline } } } else { $LiveMapURL = "" } if($LiveMapURL -eq "") { $PropertyBag.AddValue("State","GOOD") $PropertyBag.AddValue("Description", "All Live Maps are in Healthy State.") } else { $PropertyBag.AddValue("State","ERROR") $PropertyBag.AddValue("Description", $LiveMapURL) } $PropertyBag
The main logic of the script remains unchanged.
The custom rule that uses the Powershell script above was created in a new management pack: Take-A-Wei Demo LiveMaps HealthState Monitoring Management Pack. Download.

This new management pack references the sealed Take.A.Wei.MP.Demo.Library library pack discussed in an earlier post, and can be downloaded from here.

This is to allow the module, Powershell.PropertyBag.DataSource, in the library pack to be accessible by the custom rule as its data source.
Here is a summary on how this custom rule, LiveMaps Critical Health State Monitoring and Alerting Rule, was created and configured:
- The rule has the following ID and display name (LiveMaps Critical Health State Monitoring and Alerting Rule), and targets the Microsoft.SystemCenter.RootManagementServer class:

- The rule was configured with 1 data source module, 1 condition detection module, and 1 write action module:

- For the data source module, the following parameters were added by editing the XML.
The datasource module will run the Powershell script on schedule, with an interval of 600 seconds and accepting the target's principal name variable as its parameter value. It's output will then be evaluated by the condition detection module.

- The System.ExpressionFilter module was used as the condition detection module with an expression that looks for a particular value from the propertybag that the data source outputs:

- The System.Health.GenerateAlert write action module was selected to generate an alert whenever the condition detection module evaluates to true. The name of the value in the propertybag was specified in the alert description:


Here are some screen shots on the test results in the OpsMgr 2007 R2 Operations Console:
![]() |
| Imported the library and the LiveMaps HealthState Monitoring management packs |
| Alert generated with a list of URLs of Live Maps that are either in Warning or Critical state |
Disclaimer:
All information on this blog is provided on an as-is basis with no warranties and for informational purposes only. Use at your own risk. The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of my employer.
All information on this blog is provided on an as-is basis with no warranties and for informational purposes only. Use at your own risk. The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of my employer.

No comments:
Post a Comment