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.