Automating OpsMgr Part 16: Creating Windows Service Monitors

OpsMgrExntededIntroduction

This is the 16th instalment of the Automating OpsMgr series. Previously on this series:

I will dedicate this post and the next post to creating monitoring solutions for Windows services. In this post, I will demonstrate how to create a basic Windows service monitor using the New-OMServiceMonitor function from the OpsMgrExtended module.

You can access the help document for this function using the Get-Help cmdlet:

Get-Help New-OMServiceMonitor –Full

SNAGHTMLb42d9c

Sample Runbook: New-ServiceMonitor

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:

  • ClassName – The name of the target monitoring class (i.e.Microsoft.Windows.Server.OperatingSystem)
  • UnhealthyState– The unhealthy state of the monitor (either warning or error).
  • ServiceName–The name of the Windows service (i.e. w32time)
  • IgnoreStartupType– Set this Boolean parameter to True if you want the monitor to become unhealthy and generate alerts even when the service startup type is not set to “Automatic”. More details about this parameter can be found from Kevin Holman’s blog post Monitoring Windows Services – Automatic, Manual, and Disabled, using CheckStartupType
  • UnhealthyWhenRunning – Set this Boolean parameter to True when you want the monitor to become unhealthy and generate alert when the service is running (instead of stopped)
  • MonitorDisabled– Boolean, whether the event monitor should be disabled by default
  • MonitorDisplayName– Display name of the unit monitor
  • MonitorName – The name of the unit monitor
  • ParentMonitor – The parent dependency monitor for the event unit monitor

Runbook Execution Result:

image

Monitor Properties from OpsMgr Console:

image

image

image

image

Conclusion

In this post, I have shown how to create a basic windows service monitor using a simple SMA / Azure Automation runbook with New-OMServiceMonitor function in the OpsMgrExtended module. In the next post, I will show you how to create an instance of the Windows Service management pack template using the OpsMgrExtended module.

Leave a Reply

%d bloggers like this: