Udostępnij za pośrednictwem


How to Get Information About an Override

Applies To: System Center 2012 - Operations Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

You can use overrides to adjust the default settings that are set in management packs so that they are customized for your network. Overrides can adjust property values and configuration settings for rules, monitors, discovery objects, recovery objects, and diagnostic objects.

Do the following to get information about overrides:

  1. Retrieve overrides using the IOverridesManagement.GetOverrides method. This method will return a collection of objects of type ManagementPackOverride, which is the abstract base type that all override classes are derived from.

  2. To be able to gather information from the returned override objects (such as the value of the override), you must cast the ManagementPackOverride object as a specific override type. The types you can use for the cast are as follows:

  3. If you casted the override object as one of the abstract classes in step 2, you must cast the object again to access the override value because you need to classify the override as a property override or a configuration override. A property override changes the default value of a class property, while a configuration override changes the default value of a custom configuration setting for a class.

The following code example shows how to display information for all the overrides for rules, monitors, discovery objects, recovery objects, and diagnostic objects:

//
//Gathers information about overrides. 
//
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement;
using System.Collections.ObjectModel;
using Microsoft.EnterpriseManagement.Common;

namespace SDKSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementGroup mg = new ManagementGroup("localhost");
            IList<ManagementPackOverride> overrides = mg.Overrides.GetOverrides();

            foreach (ManagementPackOverride mpOverride in overrides)
            {
                // MangementPackOverride is an abstract base class, so you need
                // to find out the type of the override.
                if (mpOverride is  ManagementPackCategoryOverride)
                {
                    PrintCategoryOverrideDetails(mpOverride, mg);
                }
                else if (mpOverride is ManagementPackDiagnosticOverride)
                {
                    PrintDiagnosticOverrideDetails(mpOverride, mg);
                }
                else if (mpOverride is ManagementPackDiscoveryOverride)
                {
                    PrintDiscoveryOverrideDetails(mpOverride, mg);
                }
                else if (mpOverride is ManagementPackMonitorOverride)
                {
                    PrintMonitorOverrideDetails(mpOverride, mg);
                }
                else if (mpOverride is ManagementPackRecoveryOverride)
                {
                    PrintRecoveryOverrideDetails(mpOverride, mg);
                }
                else if (mpOverride is ManagementPackRuleOverride)
                {
                    PrintRuleOverrideDetails(mpOverride, mg);
                }
                
            }
        }

        // --------------------------------------------------------------------------------------------------
        private static void PrintRuleOverrideDetails(ManagementPackOverride mpOverride, ManagementGroup mg)
        {
            Console.WriteLine("--- Rule Override Details: ");

            ManagementPackRuleOverride ruleOverride;
            ManagementPackRule rule;

            ruleOverride = (ManagementPackRuleOverride)mpOverride;
            try
            {
                rule = mg.Monitoring.GetRule(ruleOverride.Rule.Id);
                Console.WriteLine("    Rule name: " + rule.Name);
            }
            catch (ObjectNotFoundException)
            {
                Console.WriteLine("    Rule name: Not Found");
            }
            
            if (mpOverride is ManagementPackRuleConfigurationOverride)
            {
                ManagementPackRuleConfigurationOverride configOverride =
                    (ManagementPackRuleConfigurationOverride)mpOverride;
                Console.WriteLine("      Parameter: " + configOverride.Parameter);
                Console.WriteLine("      Value: " + configOverride.Value);
            }
            else if (mpOverride is ManagementPackRulePropertyOverride)
            {
                ManagementPackRulePropertyOverride propertyOverride =
                    (ManagementPackRulePropertyOverride)mpOverride;
                Console.WriteLine("      Property: " + propertyOverride.Property);
                Console.WriteLine("      Value: " + propertyOverride.Value);
            }
        }

        // --------------------------------------------------------------------------------------------------
        private static void PrintRecoveryOverrideDetails(ManagementPackOverride mpOverride, ManagementGroup mg)
        {
            Console.WriteLine("--- Recovery Override Details: ");

            ManagementPackRecoveryOverride recoveryOverride;
            ManagementPackRecovery recovery;

            recoveryOverride = (ManagementPackRecoveryOverride)mpOverride;

            try
            {
                recovery = mg.Monitoring.GetRecovery(recoveryOverride.Recovery.Id);
                Console.WriteLine("    Recovery name: " + recovery.Name);
            }
            catch (ObjectNotFoundException)
            {
                Console.WriteLine("    Recovery name: Not Found");
            }

            if (mpOverride is ManagementPackRecoveryConfigurationOverride)
            {
                ManagementPackRecoveryConfigurationOverride configOverride =
                    (ManagementPackRecoveryConfigurationOverride)mpOverride;
                Console.WriteLine("      Parameter: " + configOverride.Parameter);
                Console.WriteLine("      Value: " + configOverride.Value);
            }
            else if (mpOverride is ManagementPackRecoveryPropertyOverride)
            {
                ManagementPackRecoveryPropertyOverride propertyOverride =
                    (ManagementPackRecoveryPropertyOverride)mpOverride;
                Console.WriteLine("      Property: " + propertyOverride.Property);
                Console.WriteLine("      Value: " + propertyOverride.Value);
            }
        }

        // --------------------------------------------------------------------------------------------------
        private static void PrintDiscoveryOverrideDetails(ManagementPackOverride mpOverride, ManagementGroup mg)
        {
            Console.WriteLine("--- Discovery Override Details: ");

            ManagementPackDiscoveryOverride discoveryOverride;
            ManagementPackDiscovery discovery;

            discoveryOverride = (ManagementPackDiscoveryOverride)mpOverride;

            try
            {
                discovery = mg.Monitoring.GetDiscovery(discoveryOverride.Discovery.Id);
                Console.WriteLine("    Discovery name: " + discovery.Name);
            }
            catch (ObjectNotFoundException)
            {
                Console.WriteLine("    Discovery name: Not Found");
            }

            if (mpOverride is ManagementPackDiscoveryConfigurationOverride)
            {
                ManagementPackDiscoveryConfigurationOverride configOverride =
                    (ManagementPackDiscoveryConfigurationOverride)mpOverride;
                Console.WriteLine("      Parameter: " + configOverride.Parameter);
                Console.WriteLine("      Value: " + configOverride.Value);
            }
            else if (mpOverride is ManagementPackDiscoveryPropertyOverride)
            {
                ManagementPackDiscoveryPropertyOverride propertyOverride =
                    (ManagementPackDiscoveryPropertyOverride)mpOverride;
                Console.WriteLine("      Property: " + propertyOverride.Property);
                Console.WriteLine("      Value: " + propertyOverride.Value);
            }
        }

        // --------------------------------------------------------------------------------------------------
        private static void PrintDiagnosticOverrideDetails(ManagementPackOverride mpOverride, ManagementGroup mg)
        {
            Console.WriteLine("--- Diagnostic Override Details: ");

            ManagementPackDiagnosticOverride diagnosticOverride;
            ManagementPackDiagnostic diagnostic;

            diagnosticOverride = (ManagementPackDiagnosticOverride)mpOverride;

            try
            {
                diagnostic = mg.Monitoring.GetDiagnostic(diagnosticOverride.Diagnostic.Id);
                Console.WriteLine("    Diagnostic name: " + diagnostic.Name);
            }
            catch (ObjectNotFoundException)
            {
                Console.WriteLine("    Diagnostic name: Not Found");
            }

            if (mpOverride is ManagementPackDiagnosticConfigurationOverride)
            {
                ManagementPackDiagnosticConfigurationOverride configOverride =
                    (ManagementPackDiagnosticConfigurationOverride)mpOverride;
                Console.WriteLine("      Parameter: " + configOverride.Parameter);
                Console.WriteLine("      Value: " + configOverride.Value);
            }
            else if (mpOverride is ManagementPackDiagnosticPropertyOverride)
            {
                ManagementPackDiagnosticPropertyOverride propertyOverride =
                    (ManagementPackDiagnosticPropertyOverride)mpOverride;
                Console.WriteLine("      Property: " + propertyOverride.Property);
                Console.WriteLine("      Value: " + propertyOverride.Value);
            }
        }

        // --------------------------------------------------------------------------------------------------
        private static void PrintCategoryOverrideDetails(ManagementPackOverride mpOverride, ManagementGroup mg)
        {
            Console.WriteLine("--- Category Override Details: ");

            ManagementPackCategoryOverride categoryOverride;

            categoryOverride = (ManagementPackCategoryOverride)mpOverride;
            
            Console.WriteLine("      Category: " + categoryOverride.Category);
            Console.WriteLine("      Value: " + categoryOverride.Value);
            
        }

        // --------------------------------------------------------------------------------------------------
        private static void PrintMonitorOverrideDetails(ManagementPackOverride mpOverride, ManagementGroup mg)
        {
            Console.WriteLine("--- Monitor Override Details: ");

            ManagementPackMonitorOverride monitorOverride;
            ManagementPackMonitor monitor;

            monitorOverride = (ManagementPackMonitorOverride)mpOverride;

            try
            {
                monitor = mg.Monitoring.GetMonitor(monitorOverride.Monitor.Id);
                Console.WriteLine("    Monitor name: " + monitor.Name);
            }
            catch (ObjectNotFoundException)
            {
                Console.WriteLine("    Monitor name: Not Found");
            }

            if (mpOverride is ManagementPackMonitorConfigurationOverride)
            {
                ManagementPackMonitorConfigurationOverride configOverride =
                    (ManagementPackMonitorConfigurationOverride)mpOverride;
                Console.WriteLine("      Parameter: " + configOverride.Parameter);
                Console.WriteLine("      Value: " + configOverride.Value);
            }
            else if (mpOverride is ManagementPackMonitorPropertyOverride)
            {
                ManagementPackMonitorPropertyOverride propertyOverride =
                    (ManagementPackMonitorPropertyOverride)mpOverride;
                Console.WriteLine("      Property: " + propertyOverride.Property);
                Console.WriteLine("      Value: " + propertyOverride.Value);
            }
        }
    }
}

See Also

Other Resources

Automating Operations Manager Administration