Overview of Managed Code Responses

What are Managed Code Responses?

Managed code responses are a response type that allows you to create rules that call a method within a .NET Framework assembly.

In the rule response properties, you must specify the name of the assembly, the name of the type (class or structure), and the name of the specific method that should be called. You must also specify whether the method is a static method or an instance method. For instance methods, the response must create an instance of the type before calling the method. You can also specify parameters when calling a method in the assembly.

The managed code response can run on an agent-managed computer or the management server computer. The assembly, however, must be manually deployed to all computers running the response. Unlike scripts, MOM does not automatically deploy the assembly to agent computers.

Advantages of using Managed Code Responses

The assembly used by a managed code response can perform custom actions and take advantage of the classes in the .NET Framework base class library. The following namespaces will be especially useful for monitoring and managing server applications:

  • System namespace: Information about the operating system.
  • System.Diagnostics namespace: Access to the Windows NT event logs, performance counters, and processes.
  • System.Management namespace: WMI-related classes.

Security for Managed Code Responses

A managed code response runs its assembly using the MOM action account. The .NET Framework's security model, including strongly named assemblies, code access security, and policy settings should be used to restrict the use of the assembly and to guarantee its identity.

Interacting with MOM in a Managed Code Response

By creating 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 method will have access to features similar to those available to unmanaged script responses through the ScriptContext object.

Your MOM-aware assembly can examine details about the current event or alert that triggered the response. Your assembly can create and submit new MOM alerts as well.

Note that the assembly used in a managed code response does not need to be MOM-aware. For example, a managed code response can be configured to directly call a method in an assembly belonging to the product you are monitoring.

Loading and Executing the Assembly

When a rule with a managed code response is triggered, the MOM runtime will dynamically load the assembly and call the specified method. If the assembly accepts a Context object in one of its parameters, the Context object will allow the code in the assembly to interact with MOM, and submit data back to MOM. The MOM runtime is also responsible for unloading the assembly, either after the method has returned, or after the method call times out.

Error Handling Model

.NET Framework exceptions should be used to communicate errors in a managed code response. A MOM event is automatically created to record unhandled exceptions raised from managed code responses. The details of the exception will be included in the properties of the MOM event.

See Also

Microsoft.EnterpriseManagement.Mom.Runtime Namespace | Developing Managed Code Response Assemblies