OpsMgr: New Sample Wizard to Create PowerShell Monitors in the Ops Console

This is an update to the sample management pack that provides a wizard to create PowerShell script based monitors in the Operations Console in System Center Operations Manager 2007 R2 & 2012. The updated sample management pack can now be downloaded from the TechNet Gallery.

The first version was released about 2 years ago – refer to Using Wizards to create Powershell-based Monitors for more information.

The new features included in this update are:

  • Ability to specify script parameters: The input parameter value can now be accessed in the script by using the $Arguments variable via
    param( $Arguments).
    image

  • Ability to apply an Override to modify the “Arguments” parameter value for the custom PowerShell based monitor created .
    image      

  •  

Importing the management pack will allow the PowerShell script Two State Monitor type to appear under the Scripting\Generic folder in the “Create a unit monitor” wizard.

image

Here is a simple example to test and display the input parameter values used via an alert triggered by a monitor state change for a custom PowerShell script monitor created from this updated wizard:

The PowerShell script used to test is as follows:

#///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

param($Arguments)
$PropertyBagAPI = new-object -comObject "MOM.ScriptAPI"
$PropertyBag = $PropertyBagAPI.CreatePropertyBag()

if($Arguments.length -gt 10){
$PropertyBag.AddValue("State","Critical")
$PropertyBag.AddValue("MessageText",$Arguments)}

else{
$PropertyBag.AddValue("State","Healthy")
$PropertyBag.AddValue("MessageText",$Arguments)}

$PropertyBag

#///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Paste the script in the Script field and click the Parameters button:

Important Note:
The input parameter value can ONLY be accessed in the script by using the $Arguments variable - param($Arguments) :

image

You can use a static string or any target variables accessible via the Target menu in the Parameters field of the pop-up page:

image

Provide the expressions based on the value in the Propertybag and map monitor conditions to health states (If the length of the string value of $Arguments exceeds 10, change monitor state to Critical/Warning, else monitor state is Healthy):

The Expression Builder Pages builds expression that looks for a particular value from the Propertybag that the data source outputs
(Property[@Name='State'] ).

image

image

Specify the name of the value in the Propertybag in the alert context variable: $Data/Context/Property[@Name='Description']$  

 image

Here is an example of the active alert generated and the state change recorded:

image

image

 

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.