This is Part 3 in a series of posts described here: https://kevinholman.com/2016/06/04/authoring-management-packs-the-fast-and-easy-way-using-visual-studio/
In our next example fragment – we will monitor a service by creating a monitor that targets our custom class.
Step 1: Download and extract the sample MP fragments. These are available here: https://github.com/thekevinholman/FragmentLibrary
I will update these often as I enhance and add new ones, so check back often for new versions.
Step 2: Open your newly created MP solution, and open Solution Explorer. This solution was created in Part 1, and the class was created in Part 2.
Step 3: Create a folder and add the fragment to it.
Create a folder called “Monitors” in your MP:
Right click Monitors, and Add > Existing item.
Find the fragment named “Monitor.Service.WithAlert.mpx” and add it.
Select Monitor.Service.WithAlert.mpx in solution explorer to display the XML.
Step 4: Find and Replace
Replace ##CompanyID## with our company ID which is “Fab”
Replace ##AppName## with our App ID, which is “DemoApp”
Replace ##ClassID## with the custom class we created in Step 2. This was “Fab.DemoApp.Server.Class” from our previous class fragment.
Replace ##ServiceName## with the short name of any service. For this Demo, since “DemoApp” is a made up application example, we will just use the Print Spooler service. So replace with “spooler”
Replace ##UniqueID## with something that represents what this monitor does. For a service monitor, I like to use the short name of the service, with NO SPACES OR SPECIAL CHARACTERS. In this example, I will choose “Spooler”
That took all of 2 minutes. Take another few minutes to review the XML we have in this fragment. It is a simple monitor definition, that will generate an alert and change state when the spooler service isn’t running. There are also display strings which can be modified for the monitor display name, alert name, and alert description.
Step 5: Save, then Build the MP. BUILD > Build Solution.
Step 6: Import or Deploy the management pack.
When enough time passes, the agent will get the new MP, and will load the new monitor. In our discovered inventory view – we should be able to see the state change from “Unmonitored” to “Healthy” because our custom class now gets health rollup from the monitor we just created.
Step 7: Test the MP.
Stop the Print Spooler service. Verify we see a state change and the alert we expect:
Nice! And easy.
It’s very useful, but what happen if I want to monitor all services in Windows?
You really shouldn’t. Lots of services start and stop as a normal operation, and this usually leads to noise and people ignoring things that should be monitored. However, if you DO want to monitor all services, then you should write a script for that, that accepts ignored services as an overridable parameter, and ignores specific known services that you never want to monitor.
Hi Kevin ji,
First!! Thanks a lot for your blog, precious materials.
How to create another monitor for another service for the same class.
You should be able to reuse these over and over – as there is a unique ID you can change to make them unique and target the same class. What fragment are you using?
Thanks for the clarification.
I am going to use Monitor.Service.WithAlert.mpx for service monitoring.
Hi Kevin
In the fragment you have added the value “UniqueID”
for what is added to the XML?
Thnaks
Descriptions of each required input are documented in the instructions in each fragment. UniqueID can be anything you want…. it just makes that workflow unique so it can be reused multiple times in the same MP.
Hello Kevin
Thanks for all.
I can’t use uniqueid for use more Monitor.Service.WithAlert.mpx in the same ManagmentPack.
I have change attribute UnidiqueID in all fragment and compilated the solution but this dont work.
Sorry for my english
Kevin, thanks for the amazing library.
I’ve been using Brian Wren’s way to use Wildcards in Service Monitoring https://blogs.technet.microsoft.com/brianwren/2008/03/08/using-wildcards-with-the-windows-service-template/ . Is it possible to build a fragment which would do this?
Hi Kevin, many thanks for all this it’s very useful. Is there an easy way to generate an alert if the service doesn’t exist on our custom class, not just the service state?
If you use my service fragments, I have one that will alert if the service does not exist. Alternatively – I have examples of a registry monitor – where you can monitor for a missing registry key – the service.
Hi, I’ve been using your fragments to build out some advanced management packs and have a question around targeting a custom class, I am using the MP fragment Class.And.Discovery.MultiRoleHostedByParentClass_Example to define a parent and a couple role classes which work without issue, However, when I add the fragment CPM.Monitor.Service.WithAlert.FreqAndSamples.IgnoreDisabled.PSRecovery and attempt to target one of the role classes, I get a compilation error:
Host reference error in expression: $Target/Host/Property[Type=”Windows!Microsoft.Windows.Computer”]/NetworkName$
The specified ClassType was ‘Microsoft.Windows.Computer’ and the resolved ClassType (evaluating the /Host references) was ‘##CompanyID##.##AppName##.Class’.
Check the number of ‘/Host’ references in this expression.
Any idea what I’m doing wrong? I’ve specified the role class in the Rule ID but not sure where it’s going wrong.
You arent doing anything wrong. This is expected when you target a child class of a parent, you must edit the hosting from something like $Target/Host/Property[Type=”Windows!Microsoft.Windows.Computer”]/NetworkName$ to $Target/Host/Host/Property[Type=”Windows!Microsoft.Windows.Computer”]/NetworkName$
Hi Kevin,
https://github.com/thekevinholman/FragmentLibrary/blob/1c2ea6c53cafcec5e9085ce971c0436c4efac234/Combo.Class.Discovery.ServiceMonitor.Wildcard.WMIQuery.PSRecovery.mpx#L336
If multiple services are discovered (with wildcard) on an individual server, and let’s say the recovery runs and fails, the failed recovery rule (linked above) generates an alert for each service discovered, not just the particular service with the issue. Is this a targeting issue with the rule? If so how to target to host vs custom service class?
Hi Kevin,
When I try to add this custom class into Ditributed Component the search can´t find it. But SCOM create a component with computers FQDN related to the class. In this case is it possible to add the whole class with discovery objects or I need to add every component related to the new class? For exemple I have 1 service on 3 computers but a I need to add this monitoring into a Distrubuted application but the class won´t show up and I have only 3 objects related to the new class.
sorry, I mean is a “Ditributed Application”
Hi Kevin,
Is It possible to add the custom class into a distributed application ? I can´t find the custom class when I try to add in Component group but I can find the server related with the custom class.