Share via


Discover Services to monitor dynamically

In the past I had some customer requirements to monitor many Windows Services  in an easy way. The other option is to define a Windows Service Monitor which only is run on server which has the service installed.

If you define a monitor and bind that to a server where the service isn’t installed you can get an error and at the detailed description you can see the following.

image

The Option “State” 8 means, that the service wasn’t found.

Here is a list of State types

0 = MOM_SERVICE_UNKNOWN_STATE
1 = MOM_SERVICE_STOPPED
2 = MOM_SERVICE_START_PENDING
3 = MOM_SERVICE_STOP_PENDING
4 = MOM_SERVICE_RUNNING
5 = MOM_SERVICE_CONTINUE_PENDING
6 = MOM_SERVICE_PAUSE_PENDING
7 = MOM_SERVICE_PAUSED
8 = MOM_SERVICE_NOT_FOUND
9 = MOM_SERVER_NOT_FOUND

 

On the one hand the customer want a monitor which knows that the service was installed on that server and the other hand to define many services to monitor easily.

For that solution I create a custom management pack to handle that requirements.

Here are the entries of that management pack

Management Pack files:

image

I guess the name of the management pack is clear enough.

 

Classes:

image

The Class “Class.DynamicServices” is the main class where the monitor and the dynamic service discovery are defind.

The Class “Class.Monitor.DynamicServices.on.Host” is a sample class where you can define servers on which the services will be searched. I will show the sample solution later on.

Discoveries:

image

 

DynamicServiceDiscovery (Default= Disabled:True)

The discovery “DynamicServiceDiscovery” is the main discovery where you can define a search expression for your custom service expression which you want to monitor.

The discovery is a powershell script discovery!

There are some override able parameters defined which are described here:

image

CheckStartupState (Default=True)

If true, then only services with Startup Type “Automatic” will be monitored. If false, booth Startup Types (“Automatic and Manual") will be monitored.

Debug (Default=False)

If the debug mode is set to true, a detailed debug event will be written into the Operations Manager log on each discovered server.

 

Sample:

image

I’ve defined a warning, error and success event which has the default values.

  • Success: 850
  • Warning: 851
  • Error: 852

You can change those EventID’s by the override parameters.

DebugSuccessEvent

DebugWarningEvent

DebugErrorEvent

SearchExpression (Default=samplesvc1;*samplesvc2*)

Here you can define the service names which you want to discover. You can write the full service name or a service name with a wildcard. If you want to discover more than one service the separator is “;”

 

DynamicServiceDiscovery.on.Host

This discovery is a sample registry discovery where you also can define a search expression (with or without wildcard). The Discovers DynamicServiceDiscovery is per default disabled but there is an override which enables that discovery for the class where that discovery was bind.

The discovery has only one custom override able parameter.

SearchExpression (Default=scom*)

You can define  a search expression to find one ore more computer objects in you SCOM environment here.

 

Monitors:

I’ve define only one Monitor which is bind to the Class “Class.DynamicServices” and the name is “Dynamic Service Discovery Monitor”.

image

That monitor will check each service which you have defined in your search expression. The only not perfect thing is that the monitor name isn’t dynamic. You find a description for that reason on the following link, written by a colleague of mine.  Link.

 

Recoveries (Optional):

I also create a recovery for that monitor which can be enabled if needed.

image

 

Views:

I create one view where the discovered services and their states are shown.

 

Sample Configuration:

In that section I will show you a sample configuration.

Scenario:

    1. Get the services “DNS Client, DHCP Client” on all Windows computers in your SCOM environment.
    2. Enable the Debug mode on all discovered services on all Windows servers.
    3. Monitor on all Domain Controller only the “Active Directory Certificate Services” service
    4. Disable the Debug mode on all Domain Controller

View Result:

image

 

How does it work:

First I define an override for the Class “Windows Server” with the following parameters.

image

Then I define an override for the Class “Windows Domain Controller” with this parameters.

image

 

Important!! In my test case I change the parameter “IntervalSeconds” to 60. Don’t do this in your production environment!

You can see that all your servers discovered the service “DHCP*;DNS*”except your Domain Controllers. On your Domain Controller only searches for the Service “CertSvc”.

You can check this in your “Dynamic Service Discovered Objects” View:

image

 

Hope that management is useful and it will make me happy if i get a feedback. Please let me know if you have any other things which I can add to that MP.

 

 

 

 

 

DiscoverServicestoMonitorDynamic.zip