Part 3: Use VSAE fragments to monitor a service


 

This is Part 3 in a series of posts described here:  https://blogs.technet.microsoft.com/kevinholman/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://gallery.technet.microsoft.com/SCOM-Management-Pack-VSAE-2c506737

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:

 

image

 

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.Class” from our previous class fragment.

Replace ##ServiceName## with the short name of any service.  For this Demo, since “DemoApp” is a made up example, we will just use the spooler service.  So replace with “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:  Build the MP.   BUILD > Build Solution.

image

 

 

Step 6:  Import or Deploy the management pack.

image

 

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.

 

image

 

Step 7:  Test the MP.

Stop the Print Spooler service.  Verify we see a state change and the alert we expect:

image

 

image

 

 

Nice!   And easy.

image


Comments (13)

  1. Steffen Frank says:

    Hi Kevin,
    many thanks for this great Post.
    I will monitor a service for example like this”IBH CommService MachineMonitor02″. The Servicename have blanks. I get an error in Visual Studio. Do you know how can i monitor a Servicename with blanks?

    regards Steffen

    1. Phil Aitman says:

      It’s fine for the Service name to have spaces eg K2 Blackpearl Server
      However. the ID’s and other parameters can’t. Remove the spaces for everything but the ServiceName Tag
      <UnitMonitor ID="MyCo.Myapp.K2 Black pearl Server.Monitor" would become
      <UnitMonitor ID="MyCo.Myapp.K2BlackpearlServer.Monitor"

      This is one instance where you need to do a bit of editing after finding and replacing.

  2. Gerald Versluis says:

    Hi Kevin,

    Lifesaving stuff, this. Absolutely brilliant. I did find a minor improvement tho: in the Generic.Monitor.Service.WithRecovery.WithAlertRules.Fragment.mpx, the end tag for the AlertOnEvent.3754.Rule.AlertMessage display string is missing.

    Regards, Gerald

  3. Gerald Versluis says:

    Hi Kevin,

    In addition to my earlier comment, fot the same MPX:
    – The alert rule IDs do not include the service name. This becomes an issue as soon as the MPX is used more than once.
    – The rules and monitor use the service name as part of the ID, but the service name can contain a dollar sign (Navision, MSSQL Server) which is not allowed in MP ID’s.
    I tried fixing this, will try and send you my version by mail.

    Regards, Gerald

  4. Excellent Article Kelvin for VSAE explanations. Good Job.

  5. Ehrnst says:

    Hi Kevin,

    I tried using Your timed ps script fragment in an already created MP. I see that the monitor is targeted at the correct class, but the Object is still “not monitored” any ideas on what i have done wrong?

  6. Amar says:

    Hi Kevin,
    Thanks for putting up this entire series! Makes it lot easier for someone without dev background to use VSAE for SCOM authoring.
    I need to create a service monitor which will skip specified number of service failures within a specified timeframe. I read about the suppression settings available and would like to use them in my custom service and script based monitors. If you could provide an mp fragment for that, it would be great!
    https://msdn.microsoft.com/en-us/library/jj129836.aspx

  7. Hi Kevin,

    I am authoring a MP using the service monitor with recovery and alert fragment, but I cannot get the alert rules to fire. From the looks of it everything seems fine and the correct 3759 event is logged by recovery. Is there something I am missing?

    1. Kevin Holman says:

      Martin – I had a bug in the alert rules. Change Param 1 to Param 2.

      The param is looking for the service name and Logscriptevent puts this in param 2.

      I will be publishing updated fragments later today which will include this and some other fixes.

      1. Thank you Kevin. I was looking in to that, but assumed that we started from Param0. making param1 effectively #2 in the event log.

  8. HectorMarcia says:

    The work done with the Fragment library is simply awesome.. Thanks so much Kevin.

    I wouldn’t mind a semi-complex MP tutorial. Some relationships, a report and why not a dashboard? 🙂

  9. Hi Kevin,

    That’s awesome series, thanks a lot for the efforts, is there a way to integrate wild card service monitoring, without using the old way of using the console Service Monitoring template.

    I am looking to create a clean management pack to monitor services using wildcard because each service of the application have different instanceID attached to the service name.

    Thanks
    Ahmed Atef

Skip to main content