How to Create an Override for a Recovery

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007

You can create an override for a property or configuration parameter for a recovery. A property override changes the default value of a recovery property, and a configuration override changes the default value of a custom configuration setting for the recovery. If you want to create an override for a recovery, use the ManagementPackRecoveryPropertyOverride or ManagementPackRecoveryConfigurationOverride class. These classes are derived from the ManagementPackRecoveryOverride class.

Only the Enabled property can be overridden for recoveries. To figure out which parameters can be overridden, you must look at the definition of the recovery in the Management Pack that defines the recovery. All the parameters that can be overridden are defined in the OverrideableParameters element of the recovery. You can also call the GetOverrideableParameters method to get the list of parameters programmatically.

The following example creates an override for the Enabled property of a recovery.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Administration;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Monitoring;

namespace SDKSamples
{
    class Program
    {
        //---------------------------------------------------------------------
        static void Main(string[] args)
        {
            ManagementGroup                             mg;
            ManagementPack                              mp;
            MonitoringClassCriteria                     monitoringClassCriteria;
            MonitoringClass                             monitoringClass;
            MonitoringRecoveryCriteria                  recoveryCriteria;
            MonitoringRecovery                          recovery;
            ManagementPackRecoveryPropertyOverride      recoveryOverride;

            mg = new ManagementGroup("localhost");

            mp = mg.GetManagementPacks("OverrideTestMP")[0];

            monitoringClassCriteria = new MonitoringClassCriteria("Name='Microsoft.SystemCenter.HealthServiceWatcher'");

            monitoringClass = mg.GetMonitoringClasses(monitoringClassCriteria)[0];

            recoveryCriteria = new MonitoringRecoveryCriteria("Name='Microsoft.SystemCenter.HealthService.Recovery.AutoReinstallAgent'");

            recovery = mg.GetMonitoringRecoveries(recoveryCriteria)[0];

            recoveryOverride = new ManagementPackRecoveryPropertyOverride(mp, "SampleRecoveryOverride");

            recoveryOverride.Recovery     = recovery;
            recoveryOverride.Property     = ManagementPackWorkflowProperty.Enabled;
            recoveryOverride.Value        = "false";
            recoveryOverride.Context      = monitoringClass;
            recoveryOverride.DisplayName  = "SampleRecoveryOverride";

            mp.Verify();
            
            //Save the changes into the management pack.
            mp.AcceptChanges();
        }        
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Administration
Imports Microsoft.EnterpriseManagement.Common
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Monitoring


Namespace SDKSamples
    Class Program
        Public Overloads Shared Function Main(ByVal args() As String) As Integer

            Dim mg As ManagementGroup
            Dim mp As ManagementPack
            Dim monitoringClass As MonitoringClass
            Dim classCriteria As MonitoringClassCriteria
            Dim recoveryCriteria As MonitoringRecoveryCriteria
            Dim recovery As MonitoringRecovery
            Dim recoveryOverride As ManagementPackRecoveryPropertyOverride

            mg = New ManagementGroup("localhost")

            mp = mg.GetManagementPacks("OverrideTestMP")(0)

            classCriteria = New MonitoringClassCriteria("Name='Microsoft.SystemCenter.HealthServiceWatcher'")

            monitoringClass = mg.GetMonitoringClasses(classCriteria)(0)

            recoveryCriteria = New MonitoringRecoveryCriteria( _
                "Name='Microsoft.SystemCenter.HealthService.Recovery.AutoReinstallAgent'")

            recovery = mg.GetMonitoringRecoveries(recoveryCriteria)(0)

            recoveryOverride = New ManagementPackRecoveryPropertyOverride(mp, "SampleRecoveryOverride")

            recoveryOverride.Recovery = recovery
            recoveryOverride.Property = ManagementPackWorkflowProperty.Enabled
            recoveryOverride.Value = "false"
            recoveryOverride.Context = monitoringClass
            recoveryOverride.DisplayName = "SampleRecoveryOverride"

            mp.Verify()

            ' Save the changes into the management pack.
            mp.AcceptChanges()

        End Function
    End Class
End Namespace