Scripting in 2007
For scripting in MOM 2005 Brian Wren’s excellent articles (http://www.microsoft.com/technet/scriptcenter/hubs/mom.mspx) on how to take all those scripts out there and “MOMifiy” them was essential reading. So there is good news and bad news on scripting in OpsMgr 2007.
The good news is that you do not need all that “stuff” around the scripts (ScriptObject) to make them work in 2007. Nor do you need a special tool (like ResponseTest.exe in MOM 2005 RKit) to test them out outside of OpsMgr. In fact the test is to run the script as a vbs (or js) file using cscript. That is why when you are creating script rules it asks you to give it a name which initially confused me. Although 2007 embeds the script in the XML of the management pack when it is at the agent the script is created using that file name in a directory structure. In 2005 you could see all the scripts. In 2007 that is harder with sealed MPs. (Clive Eastwood has just released a tool to do that here – http://blogs.technet.com/cliveeastwood/archive/2007/05/25/tool-to-dump-all-mp-s-as-xml-unsealed-to-a-folder-of-your-choice.aspx)
You can, however, see all the scripts that are assigned to that agent and look at how the scripts are written for some help. They are on each agent under Program Files, System Center Operations Manager 2007, Health State Service with a directory called Monitoring Host Temporary Files x where x is a number that changes. You will see a directory with a number for each script so it does not seem to matter if you give the script the same name but it would be better if it was unique. If you search on that directory for vbs or js files you will then see them all. Also note that in the wizard if you do not give the script an extension the next button is greyed out. It does not tell you why (very frustrating) but now you know.
The bad news is that there is not much in the way of documentation and examples. The best around at the moment is the SDK. There is a section called “Using OpsMgr Runtime Scripts” at http://msdn2.microsoft.com/en-us/library/bb437498.aspx and another section on the scripting objects at http://msdn2.microsoft.com/en-us/library/bb437498.aspx. Additionally Daniele has a nice screen shot step by step post on creating a script based unit monitor at http://www.muscetta.com/2007/05/10/create-a-script-based-unit-monitor-in-opsmgr2007-via-the-gui/. Note that if you cut and paste the example script you need to change the apostrophes (“) as that causes the script to fail when run. There are also examples of using a script for discovery at www.authormps.com.
What you will need to get used to, is using “MOM.ScriptAPI” in order to use the script and MOMScriptAPI.CreatePropertyBag Method to store information until you need to assign it to OpsMgr calling the Return method. Programmers among you will recognise the Property Bag concept. Unfortunately not many infrastructure people are programmers – including me.
What I have not found is how to then turn information gathered directly into an alert. Neale (from SystemCenterForum) also mentioned that in one of the news groups and suggested using the MOMScriptAPI.LogScriptEvent Method which allows you to put an event into an event log so that you can create a rule to alert on it. I did think about that but the documentation does say that its use was for checking that scripts are working properly. And in some of the AD scripts they use CreateEvent with a corresponding rule. There must be a better way. If only we had some documentation.
As the script is embedded in the MP it is not obvious how top create one script and use that with multiple rules using parameters like 2005. The documentation hints at being able to do it using “data source module type” but I have not found out how. And unsurprisingly no documentation on it. There is a parameter section which is confusing in itself as it is just a blank window but you can pass context parameters at runtime but you need to know them. Fortunately they are listed in the SDK. Try remembering $Target/Property[Type=’Windows!Microsoft.Windows.Computer’]/PrincipalName$ from the top of your head!
The bottom line is that we need more documentation and examples with clear explanations of what is being used and why. But once we get that then it looks like scripts will be a lot more powerful in 2007 as they run natively as cscript scripts.
- Posted in: System Center Operations Manager 2007