Here is some sample code that I wanted to share for creating overrides using the SDK. In scenarios where you need to automate the creation of overrides, this can become useful:

Creating a Rule Override:

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             classCriteria;

            MonitoringClass                     monitoringClass;

            MonitoringRuleCriteria              ruleCriteria;

            MonitoringRule                      rule;

            ManagementPackRulePropertyOverride  ruleOverride;

 

            mg = new ManagementGroup("localhost");

 

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

 

            classCriteria = new MonitoringClassCriteria("Name='Microsoft.SQLServer.2005.Database'");

 

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

 

            ruleCriteria = new MonitoringRuleCriteria("DisplayName='Collect Database Free Space (%)'");

 

            rule = monitoringClass.GetMonitoringRules(ruleCriteria)[0];

 

            ruleOverride = new ManagementPackRulePropertyOverride(mp, "SampleRuleOverride");

 

            ruleOverride.Rule           = rule;

            ruleOverride.Property       = ManagementPackWorkflowProperty.Enabled;

            ruleOverride.Value          = "false";

            ruleOverride.Context        = monitoringClass;

            ruleOverride.DisplayName    = "SampleRuleOverride";

 

            mp.Verify();

           

            //Save the changes into the management pack.

            mp.AcceptChanges();

        }       

    }

}

 

Creating a Monitor Override:

 

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                 classCriteria;

            MonitoringClass                         monitoringClass;

            MonitorCriteria                         monitorCriteria;

            ManagementPackMonitor                   monitor;

            ManagementPackMonitorPropertyOverride   monitorOverride;

 

            mg = new ManagementGroup("localhost");

 

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

 

            classCriteria = new MonitoringClassCriteria("Name='Microsoft.SQLServer.2005.Database'");

 

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

 

            monitorCriteria = new MonitorCriteria("DisplayName='Database Status'");

 

            monitor = mg.GetMonitors(monitorCriteria)[0];

 

            monitorOverride = new ManagementPackMonitorPropertyOverride(mp, "SampleMonitorOverride");

 

            monitorOverride.Monitor     = monitor;

            monitorOverride.Property    = ManagementPackMonitorProperty.Enabled;

            monitorOverride.Value       = "false";

            monitorOverride.Context     = monitoringClass;

            monitorOverride.DisplayName = "SampleMonitorOverride";

 

            mp.Verify();

           

            //Save the changes into the management pack.

            mp.AcceptChanges();

        }       

    }

}

 

Creating a Discovery Override:

 

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                     classCriteria;

            MonitoringClass                             monitoringClass;

            MonitoringDiscoveryCriteria                 discoveryCriteria;

            MonitoringDiscovery                         discovery;

            ManagementPackDiscoveryPropertyOverride     discoveryOverride;

 

            mg = new ManagementGroup("localhost");

 

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

 

            classCriteria = new MonitoringClassCriteria("Name='Microsoft.SQLServer.2005.DBEngine'");

 

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

 

            discoveryCriteria = new MonitoringDiscoveryCriteria("Name='Microsoft.SQLServer.2005.DatabaseDiscoveryRule'");

 

            discovery = mg.GetMonitoringDiscoveries(discoveryCriteria)[0];

 

            discoveryOverride = new ManagementPackDiscoveryPropertyOverride(mp, "SampleDiscoveryOverride");

 

            discoveryOverride.Discovery     = discovery;

            discoveryOverride.Property      = ManagementPackWorkflowProperty.Enabled;

            discoveryOverride.Value         = "false";

            discoveryOverride.Context       = monitoringClass;

            discoveryOverride.DisplayName   = "SampleDiscoveryOverride";

 

            mp.Verify();

           

            //Save the changes into the management pack.

            mp.AcceptChanges();

        }       

    }

}

 

Creating a Diagnostic Override:

 

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;

            MonitoringClass                             monitoringClass;

            MonitoringDiagnosticCriteria                diagnosticCriteria;

            MonitoringDiagnostic                        diagnostic;

            ManagementPackDiagnosticPropertyOverride    diagnosticOverride;

 

            mg = new ManagementGroup("localhost");

 

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

 

            monitoringClass = mg.GetMonitoringClass(SystemMonitoringClass.WindowsComputer);

 

            diagnosticCriteria = new MonitoringDiagnosticCriteria("Name='Microsoft.SystemCenter.ManagedComputer.Ping.ICMPDiagnostic'");

 

            diagnostic = mg.GetMonitoringDiagnostics(diagnosticCriteria)[0];

 

            diagnosticOverride = new ManagementPackDiagnosticPropertyOverride(mp, "SampleDiagnosticOverride");

 

            diagnosticOverride.Diagnostic   = diagnostic;

            diagnosticOverride.Property     = ManagementPackWorkflowProperty.Enabled;

            diagnosticOverride.Value        = "false";

            diagnosticOverride.Context      = monitoringClass;

            diagnosticOverride.DisplayName  = "SampleDiagnosticOverride";

 

            mp.Verify();

           

            //Save the changes into the management pack.

            mp.AcceptChanges();

        }       

    }

}

 

Creating a recovery override:

 

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();

        }       

    }

}