Creating MOM Responses with Script and Managed CodeBefore we dive into the actual process of creating a MOM response in script or managed code, it's worth discussing when you should choose one approach over the other. Both response types can run on either the MOM management server or an agent-managed computer. One of the most important factors in your decision of response type is deployment. Scripts are much easier to deploy over managed code because they reside in the MOM operations database, while managed assemblies must be manually deployed. But do not discount the managed code response type entirely; managed code has all the benefits of the CLR and access to the ⋅NET Framework. The following table lists features of the MOM SDK.
Creating a MOM Script ResponseMOM script responses allow you to extend the capabilities of rules and provide specialized actions in response to an event, alert, or performance threshold. To create a new script:
Option Explicit Dim objSvc Dim retval Set objSvc = GetObject("WinMgmts::Win32_Service='Messenger'") retval = objSvc.StartService() If (retval <> 0) Then Dim objEvt Set objEvt = ScriptContext.CreateEvent objEvt.Message = "The Messenger service failed to start." objEvt.EventType = 2 ' 2 = EVENTLOG_WARNING_TYPE ScriptContext.Submit(objEvt) Set objEvt = Nothing End If Set objSvc = Nothing Creating a MOM Managed Code ResponseManaged code responses allow you to create rules that call a method within a ⋅NET assembly. Again, one of the burdens if you do choose the managed code response type is that you must manually deploy the assemblies to every machine that needs to call the managed response. The MOM SDK specifically mentions the following namespaces could be very useful for managed code responses:
If you create an assembly method that references the Microsoft.EnterpriseManagement.Mom.Runtime library and accepts an instance of the Microsoft.EnterpriseManagement.Mom.Runtime.Context class as a parameter, your assembly's method will have access to the features similar to those available to unmanaged script responses through the ScriptContext object. You must have the 1.1 ⋅NET Framework or later installed on any machines where MOM could invoke your managed response. When you're building your ⋅NET assembly you can compile it with version 1.0 or later. See the code that follows for a VB.NET example of a managed code response's source code. Imports Microsoft.EnterpriseManagement.Mom Imports Microsoft.EnterpriseManagement.Mom.Runtime Public Class MomAwareMCRs Public Sub MomAwareTest(ByVal oContext As Context) End Sub End Class |