There are times when an application installs a Windows Service that uses inconsistent naming. There might be a scenario where the Computer Name is inserted into the service name, or where random characters get generated in the service name.
I wrote about this previously here: https://kevinholman.com/2011/01/20/how-to-monitor-a-service-with-unique-names-across-multiple-computers-using-a-wildcard/
Now, I have a Visual Studio fragment to make this even easier. This fragment will use a WMI based discovery that supports a partial name match with a wildcard, to discover instances of your service name as a property. Then it includes a monitor which uses this class property and monitors the discovered service name.
You can download the fragment library here: https://github.com/thekevinholman/FragmentLibrary
You can see fragments in action here: https://kevinholman.com/2019/07/15/advanced-mp-authoring-mpu-may-2019/
In this scenario, I am going to use a built in service that uses random data in the service name.
You can use Silect MP Author or Visual Studio with VSAE for fragments. I’ll be using Visual Studio in this example.
Create a new MP:
Add an existing item, and choose my new fragment “Combo.Class.Discovery.ServiceMonitor.Wildcard.WMIQuery.mpx”
In this fragment, we will need to replace the following items:
CompanyID and AppName are standard across all fragments.
##ServiceNameWildcard## is what will go into the WMI query, that supports the operator for wildcards “%”.
In this example, since I want to discover and monitor any services that start with “UserDataSvc_”. Therefore I will replace ServiceNameWildcard with “UserDataSvc_%”
For the UniqueID, this just needs to be something to keep this workflow unique, in case we want to reuse the fragment multiple times in the same MP. Since this is my User Data Svc service monitor, I will just use that. (NO SPACES OR SPECIAL CHARACTERS ALLOWED)
That’s it! Save it and Build it, and we are ready to deploy this MP.
If you look at Discovered Inventory, change target type to our new Demo App class view, you will begin to see new instances showing up:
Note the ServiceName property, with different names in each. Also note they are monitored – because the built in service monitor in the fragment is enabled.
And we are generating good quality alerts: