This is Part 2 in a series of posts described here: https://kevinholman.com/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://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.
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
Name the folder “Classes”
Step 3: Add the class fragment: Right click “Classes” and choose Add > Existing Item.
Browse to where you extracted my sample fragments, and choose the Class.And.Discovery.Registry.KeyExists.mpx.
Select this fragment on the right, which now shows up under the Classes folder 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##, ##UniqueID##
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.
UniqueID is simply something unique for this class/discovery, that allows us to reused this fragment again in the same MP for another application. We can make anything up that makes sense.
I start with replacing ##CompanyID## with “Fab”
Edit > Find and Replace > Quick Replace
There is a “Replace All” button at the red arrow above. After using this, you might get a popup about the replacements, or in the lower left hand corner of Visual Studio you might see:
Now I repeat this for ##AppName##
Then – the ##RegKeyPath##
My Registry Key for this app is HKEY_LOCAL_MACHINE\SOFTWARE\DemoApp
However, in SCOM “HKEY_LOCAL_MACHINE” is already hard coded
So all I need to do is replace ##RegKeyPath## with “SOFTWARE\DemoApp”
Lastly – I need to replace ##UniqueID##. This unique ID will be common across many fragments, with the intent of letting you put in something unique (NO SPACES OR SPECIAL CHARACTERS) that will allow us to reuse a fragment over and over. Perhaps DemoApp has two different roles we want to monitor, we might have two different regkeys… so we could do “WebRole” and “AppRole” here. Its totally up to you.
For this example, I will just replace it with “Server”
Done!
4 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 the XML file as a test.
Open Discovered Inventory in the SCOM console – Change Target type – and find the class you just created
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:
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.
How do you get the State to change to “Monitor” vs “Not Monitor” like your example above?
Any instance of a class will ALWAYS show “no monitored” until there is a monitor created, that rolls up health state to the class instance. Since we only created a class at this point, and have not targeted any monitors at that class – this will show “not monitored” and that’s totally fine. It doesn’t mean something isnt working.
Hi Kevin, nice to meet you… I see all your videos, thank you for your contribution. I have a question, I tried to create a monitor for SQL and SQL agent because i need to change the threshold in 60 seconds, but i when create the monitor class, the discovery in SCOM don’t show me anything. I hope you can help me. TY
Solved!
I search and replace ## UniqueID ## as well, I guess. The XML code does not explain so clearly how to think with the name phrase.
When I try to build, I get the following:
The ‘ID’ attribute is invalid – The value ‘Randy.DemoApp.##UniqueID##.Class’ is invalid according to its datatype ‘ManagementPackUniqueIdentifier’ – The Pattern constraint failed. ManagementPack11 C:\Users\rhall\source\repos\ManagementPack11\ManagementPack11\Classes\Class.And.Discovery.Registry.KeyExists.mpx 30
I have changed the fragments to include UNIQUE ID. The instructions are in the fragment. You need to replace the ##UniqueID## with something “unique”.
Hello Kevin, thank you for all your help over the last years… i just started with this Training and i was not able to get it working… i was able to create the MP (just one warning regarding the “you should not create classes in unsealed MP…) and i see the MP and the Discovery as expected in SCOM after i import it. But as long as i was waiting, i cant see my computer in the “Discovered inventory” when i select the Fab.DemoApp Class…
In the Registry i add a key Called “DemoApp” below HKLM\Software…
When i check in Authoring -> Object Discoverys -> Object Discovery name: Fab DemoApp MyUniqueId Class Discovery i see this:
Object Discovery Details -> Discovered Classes and their attributes:
Fab DemoApp MyUniqueID Class
XML:
$Target/Host/Property[Type=”Windows!Microsoft.Windows.Computer”]/PrincipalName$
–
–
MyUniqueIdRegKeyExists
“SOFTWARE\DemoApp”
0
–
0
–
86400
$MPElement[Name=”Fab.DemoApp.MyUniqueId.Class”]$
–
–
–
$MPElement[Name=”Windows!Microsoft.Windows.Computer”]/PrincipalName$
$Target/Host/Property[Type=”Windows!Microsoft.Windows.Computer”]/PrincipalName$
–
$MPElement[Name=”System!System.Entity”]/DisplayName$
$Target/Host/Property[Type=”Windows!Microsoft.Windows.Computer”]/PrincipalName$
–
–
–
Values/MyUniqueIdRegKeyExists
–
Equal
–
–
true
–
How can i troubleshoot this?
Thank you
Martin
That looks good to me. Send me an email with your MP attached, and a screenshot of your registry.
kevin.holman at live.com
Hi KEvin, thats great. Thank you very much for your Support
Mail is sent.
again – thank you
Martin
Hi
I have same issue. Can you please share the solution
Hello Kevin,
I followed the instructions to the letter, but my devices are not being discovered.
The one thing I wasn’t too certain on was the registry key, which I did manually add on each server I’ve tested so far and supplied the path to that key in the discovery xml.
I am working with an existing SCOM setup with agent managed devices. I uninstalled and reinstalled the agent on my test servers, ran the discovery, and rechecked in the Discovery Inventory for my class. Nothing found.
Since I am working with pre-discovered devices, will your discovery method work after I remove and re-add the machines in SCOM.
I did not do the original SCOM setup so it there anything I should look for in the settings?
Thanks for your time.
Shoot me your XML to kevin.holman@live.com
I sent the XML from my second attempt to you. I have one from my first attempt using a different server group (different project) if you need to see that too.
Kevin, Thanks again for the assistance. You’re a sanity saver!
If somebody else is wondering what the fix was, I entered the wrong registry path. My original path I entered was “\SOFTWARE\” when it should have been “SOFTWARE\”. I removed the leading back-slash and it worked after that.
Hi Kevin,
Thank you for wonderful guide to create the Management Pack. I am working on one of the Management Pack for BMC Tool. I am facing issue as the Discovery is not showing any results under Discovered Inventory. When cross checking came across the registry value containing the space (SOFTWARE\BMCSoftware\), wanted to check if this is the issue due to which the Discovery results are not showing. Thanks in advance for all your inputs.
Hello Kevin, thanks for all these articles, really got me moving on building MPs of which we have many that are needed.
My discovery is not working, no errors, just the discovered class is not populated in SCOM. I have others that are working.
I think what the problem is the path to the registry key has spaces in it, is this allowed or is there a work around?
ITSORegKeyExists
SYSTEM\CurrentControlSet\Services\ITSO Inbound Message Converter
Many thanks
Stuart
Spaces in a key should not be a problem. Can you forward me your management pack via email and I can take a look?
kevin.holman@live.com
Hello Kevin,
Thanks for the article. Here’s the only place I found on how to start creating custom MPs.
But my discovery is not working, there are no errors, but no classes are discovered although my management server and trusted agent both have the registry key I defined. How to Find the error?
Almost always the problem is how people format the reg key. Can you post that line in your xml and compare to the instructions in the frag?
Hello Kevin,
I am wondering how do we deal with situation when we just want to build monitor targeting existing class, such as IIS Application Pool?
I have added IIS management packs as a reference, but still getting an error when try to build
Okay, I think I have found solution myself.
For anyone wanting to extend existing management pack, check part 5, step 5 of Kevin’s guides. In short, when adding references to existing classes, add correct alias in front of that class name.
I want to modify this so that it only discovers the service if it’s set to automatic. I’ve seen you do this with MP Author, but we didn’t get to see the underlying XML there so that we can use it in VSAE.
Sure! Super easy. Instead of using the Registry key exists fragment (Class.And.Discovery.Registry.KeyExists.mpx) instead choose to use Registry Value Expression (Class.And.Discovery.Registry.ValueSimpleExpression.mpx)
Then provide the RegValuePath to the service start registry value like: SYSTEM\CurrentControlSet\Services\CcmExec\Start
Edit the fragment or XML and change the expression value to “2” which is automatic:2
Hi Kevin
I tried it now over 2 hours but I get no data. I tried it with two different Registry entrys but no success.
Is there any problem if the Registry is in another language? I saw that our Registry is in german language.
I will send you my xml in a minute.
I really dont know what is wrong and I really like to do something like that because I am into my thesis witch SCOM.
best regards
Hi guys
I found my problem. I try to use that template for registry entrys on windows 10 clients, not on servers. I dont know if I am able to write all over to get that thing running.
Maybe I just do now some server registry management pack to learn how to and maybe try later on windows 10 clients.
best regards
Hi guys
I just want to post the solution. I got it from Kevin.
If you want to discover the regestry of Windows Clients then just use as target Windows!Microsoft.Windows.Client.OperatingSystem
Its working perfectly.
best regards and thanks to Kevin again