Automating OpsMgr Part 17: Creating Windows Service Management Pack Template Instance

OpsMgrExntededThis is the 17th instalment of the Automating OpsMgr series. Previously on this series:

Now that I have demonstrated how to create basic Windows service monitors using New-OMServiceMonitor, in this post, I’ll demonstrate how to use the OpsMgrExtended module to create an instance of the “Windows Service” management pack template:

image

The OpsMgrExtedned module comes with a function called New-OMWindowsServiceTemplateInstance. Same as all other functions in this module, it is fully documented, you can access the help document using Get-Help cmdlet:

Get-Help New-OMWindowsServiceTemplateInstance –Full

SNAGHTML2e5dc32

Sample Runbook New-WindowsServiceTemplateInstance

I have hardcoded the following parameters in the runbook:

  • SMA OpsMgr connection object name (which you will need to change to suit your environment)
  • (Unsealed) MP (where the rule  is going to be saved to) – “TYANG.Test.Windows.Monitoring”

Additionally, this runbook will firstly try to retrieve the management pack from the management group, if the MP deosn’t exist, it will create it first.

This runbook takes the following input parameters:

  • InstanceDisplayName– The Display name of the template instance.
  • InstanceDescription– This is an optional parameter. The description of the template instance.
  • TargetGroupName– The name of the target group
  • ServiceName–The name of the Windows service (i.e. w32time)
  • LocaleId– The 3-letter MP language pack locale ID. This is an optional parameter, if not specified, it will be set to “ENU”.
  • CheckStartupType– Set this Boolean parameter to True if you only want to monitor automatic service. More details about this parameter can be found from Kevin Holman’s blog post Monitoring Windows Services – Automatic, Manual, and Disabled, using CheckStartupType
  • CPUPercent– Specify the threshold for CPU Usage Percentage. This is an optional parameter, if not specifiied, the CPU Usage will not be monitored or collected.
  • MemoryUsageMB– Specify the threshold for Memory Usage (MB). This is an optional parameter, if not specifiied, the Memory Usage will not be monitored or collected.
  • ConsecutiveSampleCount– Specify the the number of (consecutive) samples for the CPU and Memory counters, This is an optional parameter. if not specified, the value is set to 2 (which is the default value when using the wizard in the OpsMgr console).
  • PollingIntervalInSeconds- Specify sample polling interval (in seconds). This is an optional parameter, if not specifiied, the value is set to 300 (which is the default value when using the wizard in the OpsMgr console).

To help you visualise what are these parameters mean, I’ve mapped them to the fields in the GUI wizard:

image

image

image

Runbook Execution Result:

image

A Known Issue

When I was writing the sample runbook, I found a small bug in the OpsMgrExtended module. You may noticed from the screenshots above, that the description field is not populated. I have found the cause of this issue and fixed it in my lab. This fix will be shipped with the next release. So please just be aware of this issue, I don’t think it’s too critical.

Conclusion

In this post, I have demonstrated how to create Windows Service MP template instances using the OpsMgrExtended module. This concludes the topics of monitoring Windows services. In the next module, I will demonstrate how to create any types of generic rules by specifying the configuration of each member module (Data Source, Condition Detection and Write Action) using the New-OMRule function. Until next time, happy automating!

Leave a Reply

%d bloggers like this: