Quantcast
Viewing all articles
Browse latest Browse all 158

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 may be NSFW.
Clik here to view.
image

 

Name the folder “Classes”

Image may be NSFW.
Clik here to view.
image

 

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

 

Image may be NSFW.
Clik here to view.
image

 

Browse to where you extracted my sample fragments, and choose the Generic.Class.And.Discovery.Registry.KeyExists.Fragment.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 cam 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 to replace ##CompanyID##, ##AppName##, ##RegistryKey##

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”

RegistryKey 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 may be NSFW.
Clik here to view.
image

 

Image may be NSFW.
Clik here to view.
image

 

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

 

Image may be NSFW.
Clik here to view.
image

 

Now I repeat this for ##AppName##

Image may be NSFW.
Clik here to view.
image

 

And lastly – the ##RegistryKey””##.

 

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

Image may be NSFW.
Clik here to view.
image

However, in SCOM “HKEY_LOCAL_MACHINE” is already hard coded in the code, and if you look at the sample XML – SOFTWARE is already present:

 

              <Path>SOFTWARE\##RegistryKey##</Path>

 

So all I need to do is replace ##RegistryKey## with “DemoApp”

 

Image may be NSFW.
Clik here to view.
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 discovery all machines with the registry key.

 

 

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 may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
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.


Viewing all articles
Browse latest Browse all 158

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>