Part 2: Use VSAE fragments to dynamically discover an application based on the existence of a registry key or value


 

This is Part 2 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/

 

Now we will start with our first example fragment – discovering an app and creating a class for it.

 

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.

We want to keep things organized – so we want to create folders to organize our solution as we go.  This wont affect anything in the MP XML, it just keeps the solution organized.

Right click “Fab.DemoApp” and choose Add > New Folder

 

image

 

Name the folder “Classes”

image

 

Step 3:  Add the class fragment:  Right click “Classes” and choose Add > Existing Item.

 

image

 

Browse to where you extracted my sample fragments, and choose the Class.And.Discovery.Registry.KeyExists.mpx.

Select this fragment which now shows up under classes in solution explorer, and you should see the XML pop up in Visual Studio.

 

Step 4:  Find and Replace!

This is the area where I tried to make using Visual Studio and VSAE MUCH easier.  I came up with a standard item list that you will need to commonly replace in your XML, and enclosed each item with “##” to make them easy to find.  I also included notes at the top of each fragment, explaining what the fragment does, and what you need to replace.

This allows you to create LOTS of monitoring ins SECONDS, simply using Find and Replace.

For this example, we need to replace ##CompanyID##, ##AppName##, ##RegKeyPath##

CompanyID is easy – for my demo’s that’s my company abbreviation, or “Fab”.

AppName in this case, is a fake application I called “DemoApp”

RegKeyPath is simply going to be the path in the registry which designates that “DemoApp” is installed.

 

I start with replacing ##CompanyID## with “Fab”

Edit > Find and Replace > Quick Replace

image

 

image

 

There is a “Replace All” button at the red arrow above.

 

image

 

Now I repeat this for ##AppName##

image

 

And lastly – the ##RegKeyPath##

 

My Registry Key for this app is HKEY_LOCAL_MACHINE\SOFTWARE\DemoApp

image

However, in SCOM “HKEY_LOCAL_MACHINE” is already hard coded

So all I need to do is replace ##RegKeyPath## with “SOFTWARE\DemoApp”

 

image

 

Done!

Three quick find/replace actions, and we have a working class definition, with a registry discovery.  Look through the XML to familiarize yourself with all that you just created.  There is a TypeDefinitions section with your Class definition, along with a Discovery to discover all machines with the registry key.

**Note – if your reg key is not present in “SOFTWARE” but you want to use something in “SYSTEM” such as a service in SYSTEM\CurrentControlSet\Services\, you could simply change the path in the fragment. 

 

 

Step 5:  Build the MP.  Then import it as a test.

Open Discovered Inventory in the SCOM console – Change Target type – and find the class you just created

image

 

After a few minutes, the agents should download this MP, run the discovery, and any agents with that registry key will show up as an instance of our new class:

 

image

 

 

 

Congrats!  You have dynamically discovered all computers with the “DemoApp” application in your company.  Start to finish, about 1 minute.  5 minutes tops if you are learning VSAE for the first time.


Comments (15)

  1. Hi Kevin. Looking at the first installment mpx in the library, I noticed on lines 51 and 55 some comments:

    "...since the default is boolean, we use "string"..."

    Should not we use type boolean if we are checking a boolean registry attribute definition? If it's of type string, and the registry attribute definition is a boolean, I'm thinking it would always evaluate to true.

    1. Kevin Holman says:

      @ Jonathan -

      As long as AttributeType = 0, then you can use string or Boolean. They will be evaluated the exact same way. If you look at the code spit out by the SCOM 2007 R2 authoring console, it uses a String XpathQuery and Value Type. MPAuthor uses Boolean. When AttributeType=0, the expression "XPathQuery Type="String">Values/##AppName##RegKeyExists</XPathQuery" will resolve to True or False only.

      1. Ok. I remember dealing with this years back, and had some problems when types between the attribute definition and the expression filter did not match (particularly when dealing with boolean and string), but maybe this does work as expected in this case. Do you think it's a good practice to use the same type in the expression filter as what is specified in the attribute definition?

        1. Kevin Holman says:

          As a general rule - absolutely.

          I was also trying to keep as few variables as possible in this ever-growing fragment library, so customers could change the fewest things and still have a working MP. However, the more I work with and try to understand all our native modules and their inputs and outputs, the more I like just using a PowerShell module to do whatever I want.

  2. sepeck says:

    Kevin,

    In the Generic.Class.And.Discovery.Registry.ValueExpression.Fragment on line 29....
    Not sure you want everything before ##RegistryValue##
    SYSTEM\CurrentControlSet\Services\Spooler\Start##RegistryValue##

    1. Kevin Holman says:

      I actually did that on purpose - because that is only a SINGLE location in the XML for the registry value - and this seems like it would help customers to provide an example full path to the registry. The find and replace token for this one is really more of a guide to know you need to do "something" there. If a customers wanted to remove all that with their own customized version of the fragment - they should.

  3. GS says:

    Hi Kevin,
    Excellent set of articles .... great work! Do you have a discovery fragment example to perform a WMI discovery?
    Thanks

  4. Excellent Article Kelvin.

  5. Birdal says:

    Hi Kevin,
    I am very new in SCOM, and am in a very "cold water" in a complex IT infrastructure so that I must understand first SCOM 2012 and SCOM Authoring. I found your authoring article and wanted to "exercise" with it.
    Unfortunately your ZP packet does not incluse "Generic.Class.And.Discovery.Registry.KeyExists.Fragment.mpx". Forgotten? Or am I blind? 🙂
    Best Regards
    Birdal

  6. Kevin Holman says:

    I renamed them to make the names shorter in the latest download.

    Just take off "generic"

  7. Hi Kevin,

    Unfortunately your ZP packet does not incluse “Generic.Class.And.Discovery.Registry.KeyExists.Fragment.mpx”. ? where i get this file?

    In the above line you reply to Mr.Harvansh Singh
    I renamed them to make the names shorter in the latest download.

    Just take off “generic”

    How can i get?

    Regards,
    Arjun walmiki

  8. i am download from the below link

    https://gallery.technet.microsoft.com/SCOM-Management-Pack-VSAE-2c506737

    but not find the file =" Generic.Class.And.Discovery.Registry.KeyExists.Fragment.mpx"

    kindly send me the link if you have some other reference.

    Thanks,
    Arjun Walmiki

  9. yes i have

    old name :- Generic.Class.And.Discovery.Registry.KeyExists.Fragment.mpx.

    new name :- Class.And.Discovery.Registry.KeyExists.

    Regards,
    Arjun Walmiki

  10. Daniel Haddad says:

    Hi Found this like and the parts are excellent learning for a newbie like me. The question i had is , is it possible to add several classes to one project. I.E. if i want to make a MP for RDS infrastructure that includes the RDSBroker, RDSGateway and RDS License server. I have created a new project and added a clase with registry key for rdsbroker that is looking at /System/CurrentControlSet/Services/Tssdis. If i wanted to target multiple registry keys such as the TSGateway and TermServLicensing keys how would i acomplish this. Would i import the Class.AndDiscovery.Registry.KeyExists.MPX a second time and modify it with the relevant info?

    1. Kevin Holman says:

      Yes.

      Or, you could use the registry discovery for a "seed" class which is not used for monitoring, but for lightweight registry discoveries only. Then you could target that class for additional discoveries of specific roles, and use registry wmi, or script based discoveries for each class. The base class for those can be local application still, or use can use more complicated abstract base classes for "RDS Server" or something like that. And you can build relationships between the classes if needed, such as "RDS Server hosts RDS Broker", but again - this would only be for health rollups between classes, and special grouping..... it is not required. It just makes a sexier, more useful looking MP. If you want to get that advanced - look at some of the microsoft MP's for ideas. However, I'd say those are for more experienced MP authors.

Skip to main content