Wednesday, April 5, 2017

MP Authoring – Quick & Dirty – 02 – Authoring The Template MP XML Code


Advice to the reader
This posting is part of a series of articles. In order to get a full grasp of it, I strongly advise you to start at the beginning of it. 

Other postings in the same series:
00 – Introduction
01 – Overview
03 - Example Using The Template MP XML Code
04 - Testing The Example MP
05 – Q&A


In this posting I’ll write about how to author your own template MP XML code by using MP Author, available for free. For the ease of it all I presume you’ve already downloaded and installed this tool. Also I will not describe every detail but try to highlight the most important parts of it. As it turned out when ready, this posting has become quite big and detailed…

And last but not least, I also presume you’ve downloaded a tool like Notepad++ since the XML code generated by MP Author has to be scrubbed because MP Author adds these nagging flags of itself to the XML code which I totally dislike…

There is much to tell, so let’s start.

Creating the template MP XML code with MP Author
Since creating the template MP XML code consists out of many steps, I’ve broken it into five sections.

01 - Creating the MP Manifest and basic XML structure

  1. Start MP Author and create a new MP. MP Creation Wizard will start now. Use this input for the Manifest section:
    - Unique identifiable name: Custom.Application (mind the DOT!!!)
    - Friendly name: Custom Application (mind the space!!!)
    - Description: Remove the MP Author crap and replace it with This MP monitors Custom Application.
    Now you’ve got something like this:
    image

  2. In the section Template Selection, select the first option Empty Management Pack. IMHO the other templates add way too much noise, resulting in anything but clean XML code.
    image

  3. Follow the wizard to the end. Save the MP. Based on your previous choices and input MP Author will create the basic XML code for the Custom Application MP. When ready you’ll be shown a screen like this one:
    image
    There is still much to do, since you’re going to add a Class with a Discovery (the Reverse Discovery as previously discussed), a Group (also a ‘dirty’ trick is going to be used here, much about that later on), a Folder and two Views (Alert and State)). In the next section you’re going to create the Class and Reverse Discovery.

02 - Creating the Class and Reverse Discovery

  1. In MP Author go to Targets > New > Create New Registry Target. The Management Pack Registry Target Wizard starts now. By default it selects the server/computer where MP Author runs to read registry data from. This is fine for this MP so leave this selection as it is.

  2. In the section Discovery and you must define the registry key used for the Discovery for the Class you’re about to create. So hit the Browse button under the Discovery – required header:
    image
    The registry of the system where MP Author runs is opened. Please follow the next steps exactly because otherwise the Add button in the Select Registry Keys screen won’t light up…

  3. On the LEFT part of the Select Registry Keys screen, you’ll see the HKLM registry hive. Select this key: HKLM\SOFTWARE\Microsoft\Windows. Ascertain that Windows is selected in the left part of the screen, like this:
    image
    Please note that the Add button is still greyed out. Now in the middle pane of the screen, select the sub key CurrentVersion, like this:
    image
    Now the Add button is activated, so click it.
    The selected registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion will be shown now in the section Selected Registry Keys:
    image
    Click OK > Next.

  4. Now you’re in the Identify Target section of the Management Pack Registry Target Wizard. The names you’re about to enter here are crucial since they’ll be used as a template. So follow these steps exactly as well.
    - Name: Custom.Application.Class (mind the DOT!!!)
    - Display name: Custom Application Class (mind the spaces!!!)
    - Description: Remove the text and replace it with This Class represents ‘Custom Application’
    image
    > Next

  5. In the next step you’ve to select a Base Class, AKA the Class on which the new Class you’re authoring, refers to. Meaning, without the presence of the Base Class, the new Class you’re authoring won’t exist. As such it’s best to select Microsoft.Windows.LocalApplication as Base Class.
    image
    > Next

  6. Now you’re about to create the Discovery for the Class you previously defined. Because it’s a REVERSE Discovery DON’T FORGET to DISABLE it!!! This is simply done by deselecting the Enabled option. The names you’re about to enter here are crucial since they’ll be used as a template. So follow these steps exactly as well.
    - Name: Custom.Application.Discovery (mind the DOTS!!!)
    - Display name: Custom Application Discovery (mind the spaces!!!)
    - Description: Remove the text and replace it with Discovers the ‘Custom Application’ Class.
    image
    > Next

  7. Now you have to select the Target where the previously defined Discovery will run. Now you select here Microsoft.Windows.Server.OperatingSystem:
    image
    > Next

  8. Now you need to define the expression for the Discovery. Leave the default selection to Check for existence of registry values. Change the pre-defined Attribute Name to CustomApplication (mind the LACKING space!!!)
    image
    > Next

  9. Accept the default Schedule for the Discovery to run (once per day) > Next
    image
    A summary of your previous choices and input will be shown > Finish. Save the MP. MP Author will run some checks now in order to see everything is adhering to the MP XML schema and when okay, will create the code and show you the MP Author screen again. In the next section you’re going to double check that the Discovery is disabled, create a Folder and two Views (Alert and State).

03 - Creating the Folder and Views & double check the disabled Discovery
First of all check whether the Discovery is REALLY disabled. In MP Author go to Discoveries, select the only Discovery present and check in the right panel whether Enabled (under the header State) is set to False. When not, modify it by clicking on the arrow button on the right of Enabled and select false. Save the MP so the changes are set.

  1. Go to Folder > New > Create New Folder > accept the default selection in the introduction section of the Management Pack Folder Wizard screen (Microsoft.SystemCenter.Monitoring.ViewFolder.Root) > Next.

  2. The names you’re about to enter here are crucial since they’ll be used as a template. So follow these steps exactly as well.
    - Name: Custom.Application.ViewFolder.Root (mind the DOTS!!!)
    - Display name: Custom Application (mind the spaces!!!)
    - Description: Remove the text and replace it with This is the root folder for ‘Custom Application’
    image
    > Next > Finish.

  3. Go to Views > New > Create New Alert View. As the folder for the new View, you must select Custom.Application.ViewFolder.Root (the Folder you previously made):
    image
    > Next

  4. In the screen Specify alert view data you must select the target you previously made, or better the Class (Custom.Application.Class). I presume you don’t want to see old (Closed) Alerts, so choose as for Resolution State Unresolved:
    image
    > Next

  5. In the screen Identify state view section Identify, enter the names as required. Again: The names you’re about to enter here are crucial since they’ll be used as a template. So follow these steps exactly as well.
    - Name: Custom.Application.AlertView (mind the DOTS!!!)
    - Display name: Alerts
    - Description: Remove the text and replace it with Alert View for ‘Custom Application’
    image
    > Next > Finish.

  6. Go to Views > New > Create New State View. As the folder for the new View, you must select Custom.Application.ViewFolder.Root (the Folder you previously made):
    image
    > Next

  7. In the screen Specify state view data you must select the target you previously made, or better the Class (Custom.Application.Class). I presume you  want to see all States, so select all of them:
    image
    > Next

  8. In the screen Identify state view section Identify, enter the names as required. Again: The names you’re about to enter here are crucial since they’ll be used as a template. So follow these steps exactly as well.
    - Name: Custom.Application.StateView (mind the DOTS!!!)
    - Display name: State
    - Description: Remove the text and replace it with State View for ‘Custom Application’
    image
    > Next > Finish. Save the MP. So now the Folder and two Views are created. In the next section you’ll create the Group.

04 – Create the Group
In this section you’ll create the Group. Because MP Author wants to help you as much as (im)possible, it doesn’t allow empty Groups to be created, or better Groups without any formula. Therefore you’ll use a ‘workaround’ here by creating a Group which is populated by a formula which results in an empty Group anyway when imported in SCOM.

This Group is going to be used later on in SCOM. All Windows Servers hosting the custom application to be monitored, are added to this Group. Then the Discovery (disabled by default) is enabled through an Override, targeted against the same Group.

  1. Go to Targets > New > Create New Group. The Group Target Wizard is started now. Again: The names you’re about to enter here are crucial since they’ll be used as a template. So follow these steps exactly as well.
    - Name: Custom.Application.Group (mind the DOTS!!!)
    - Display name: Custom Application Group (mind the spaces!!!)
    - Description: Remove the text and replace it with This Group contains all Windows Servers running ‘Custom Application’
    image
    > Next

  2. In the Membership Rules section of the screen, select Windows Computer > Add > Insert > select as Property DNS Name, as Operator Equals, as Value QWERTY.QW resulting in this:
    image
    > OK. Now you’ve got this:
    image
    > Next > Finish.

  3. MP Author has a nagging habit of creating a folder for every Group created. You don’t want/need that. So go to Folders, select the Folder with Name Custom.Application.Group.Folder and select Delete. Confirm it when asked for. Save the MP. Now the template XML MP code is almost ready. As stated before, MP Author adds ‘flags’ about itself to the XML code. I don’t like that so I use Notepad++ to remove those flags/noise. In the next step I’ll tell you how to that.

05 – Scrubbing the XML code
Save the MP so you’re 100% sure the XML code on disk contains all modifications. Go to the folder where the XML code is stored, also shown in MP Author when selecting the MP in the left pane AND in the tab of the MP itself:
image

  1. Close MP Author.

  2. Create a new subfolder in the folder containing the MP XML code, titled Scrubbed. Copy the XML into that folder (so there is always a way back when things go wrong) and open the copy in the Scrubbed folder in Notepad++ (or any other text editor of your choice).

  3. Search for Silect. In my case I found 8(!) entries. Remove ALL Comments, but be careful here, COMMENTS ONLY! Nothing more, since many times after the comment other crucial MP XML code is also placed there. So remove the COMMENT only and keep the rest!

  4. Save the modified XML code. Start MP Author and open the modified XML code. Go to New > Run Best Practices Analyzer in order to see whether the template MP XML code adheres to the MP authoring Best Practices. Please know that Verify will fail since the XML code contains type definitions, which normally should be found in sealed MPs, not unsealed MPs. But the MP should be just fine when you followed everything to the smallest step.

  5. When you want to be 100% sure, just import the template MP into your SCOM test/lab environment. This MP contains only one Class, a DISABLED Discovery, a Group, a Folder and two Views (Alert & State), so theoretically it should do no harm. But always be careful. None the less, it’s VITAL to check the validity of the XML code, since it will serve as a basis for many custom MPs to come. So import it and check for the Class, Discoveries (one for the Class, the other for the Group), Folder with the Views (Alert & State) and the Group which is empty because it looks for a non-existing server (QWERTY.QW). Some screenshots from my test lab:

    Folder and two Views (Alert & State):
    image

    The Class:
    image

    The Discoveries (two, one for the Class, another for the Group (which is also a Class)):
    image

    And yes, the Discovery for the Class is disabled by default:
    image

    And the Group:
    image
    When all is present you can remove this MP and store the XML code to save place since it will be used a template for many custom MPs in the near future.

Recap
So now you’ve authored the template MP XML all by yourself! Wh00t!

In the next posting of this series I’ll show you how to use this template in order to create your own custom MPs yourself! See you all next time!

For the completeness of it all, the scrubbed template MP XML code can be downloaded from here.


Update 5th of April 2017: I got some very valuable feedback on this posting. As such I’ve partially rewritten this posting, and updated the downloadable template MP XML code.

1 comment: