Partager via


How to Get Information About an Override

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

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.

The following procedure describes how to get information about overrides.

  1. Retrieve overrides using the GetMonitoringOverrides 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 listed below.

  3. If one you casted the override object as one of the abstract classes listed in step 2, then you must cast the object again to access the override value. This is 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 you 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");
            ReadOnlyCollection<ManagementPackOverride> overrides = mg.GetMonitoringOverrides();

            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.GetMonitoringRule(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.GetMonitoringRecovery(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.GetMonitoringDiscovery(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.GetMonitoringDiagnostic(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.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);
            }
        }
    }
}
' Gathers information about overrides. 
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Text
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Common

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

            Dim mg As ManagementGroup = New ManagementGroup("localhost")
            Dim mpOverrides As ReadOnlyCollection(Of ManagementPackOverride) = mg.GetMonitoringOverrides()

            For Each mpOverride As ManagementPackOverride In mpOverrides

                ' MangementPackOverride is an abstract base class, so you need
                ' to find out the type of the override.
                If (TypeOf mpOverride Is ManagementPackCategoryOverride) Then

                    PrintCategoryOverrideDetails(mpOverride, mg)

                ElseIf (TypeOf mpOverride Is ManagementPackDiagnosticOverride) Then

                    PrintDiagnosticOverrideDetails(mpOverride, mg)

                ElseIf (TypeOf mpOverride Is ManagementPackDiscoveryOverride) Then

                    PrintDiscoveryOverrideDetails(mpOverride, mg)

                ElseIf (TypeOf mpOverride Is ManagementPackMonitorOverride) Then

                    PrintMonitorOverrideDetails(mpOverride, mg)

                ElseIf (TypeOf mpOverride Is ManagementPackRecoveryOverride) Then

                    PrintRecoveryOverrideDetails(mpOverride, mg)

                ElseIf (TypeOf mpOverride Is ManagementPackRuleOverride) Then

                    PrintRuleOverrideDetails(mpOverride, mg)
                End If

            Next
        End Function

        ' --------------------------------------------------------------------------------------------------
        Private Shared Sub PrintRuleOverrideDetails(ByVal mpOverride As ManagementPackOverride, _
                                                    ByVal mg As ManagementGroup)

            Console.WriteLine("--- Rule Override Details: ")

            Dim ruleOverride As ManagementPackRuleOverride
            Dim rule As ManagementPackRule

            ruleOverride = CType(mpOverride, ManagementPackRuleOverride)

            Try
                rule = mg.GetMonitoringRule(ruleOverride.Rule.Id)
                Console.WriteLine("    Rule name: " & rule.Name)

            Catch e As ObjectNotFoundException

                Console.WriteLine("    Rule name: Not Found")
            End Try

            If (TypeOf mpOverride Is ManagementPackRuleConfigurationOverride) Then

                Dim configOverride As ManagementPackRuleConfigurationOverride = _
                    CType(mpOverride, ManagementPackRuleConfigurationOverride)
                Console.WriteLine("      Parameter: " & configOverride.Parameter)
                Console.WriteLine("      Value: " & configOverride.Value)

            ElseIf (TypeOf mpOverride Is ManagementPackRulePropertyOverride) Then

                Dim propertyOverride As ManagementPackRulePropertyOverride = _
                    CType(mpOverride, ManagementPackRulePropertyOverride)
                Console.WriteLine("      Property: " & propertyOverride.Property)
                Console.WriteLine("      Value: " & propertyOverride.Value)
            End If
        End Sub

        ' --------------------------------------------------------------------------------------------------
        Private Shared Sub PrintRecoveryOverrideDetails(ByVal mpOverride As ManagementPackOverride, _
                                                        ByVal mg As ManagementGroup)

            Console.WriteLine("--- Recovery Override Details: ")

            Dim recoveryOverride As ManagementPackRecoveryOverride
            Dim recovery As ManagementPackRecovery

            recoveryOverride = CType(mpOverride, ManagementPackRecoveryOverride)

            Try

                recovery = mg.GetMonitoringRecovery(recoveryOverride.Recovery.Id)
                Console.WriteLine("    Recovery name: " & recovery.Name)

            Catch e As ObjectNotFoundException

                Console.WriteLine("    Recovery name: Not Found")
            End Try

            If (TypeOf mpOverride Is ManagementPackRecoveryConfigurationOverride) Then

                Dim configOverride As ManagementPackRecoveryConfigurationOverride = _
                    CType(mpOverride, ManagementPackRecoveryConfigurationOverride)
                Console.WriteLine("      Parameter: " & configOverride.Parameter)
                Console.WriteLine("      Value: " & configOverride.Value)

            ElseIf (TypeOf mpOverride Is ManagementPackRecoveryPropertyOverride) Then

                Dim propertyOverride As ManagementPackRecoveryPropertyOverride = _
                    CType(mpOverride, ManagementPackRecoveryPropertyOverride)
                Console.WriteLine("      Property: " & propertyOverride.Property)
                Console.WriteLine("      Value: " & propertyOverride.Value)
            End If
        End Sub

        ' --------------------------------------------------------------------------------------------------
        Private Shared Sub PrintDiscoveryOverrideDetails(ByVal mpOverride As ManagementPackOverride, _
                                                         ByVal mg As ManagementGroup)

            Console.WriteLine("--- Discovery Override Details: ")

            Dim discoveryOverride As ManagementPackDiscoveryOverride
            Dim discovery As ManagementPackDiscovery

            discoveryOverride = CType(mpOverride, ManagementPackDiscoveryOverride)

            Try

                discovery = mg.GetMonitoringDiscovery(discoveryOverride.Discovery.Id)
                Console.WriteLine("    Discovery name: " & discovery.Name)

            Catch e As ObjectNotFoundException

                Console.WriteLine("    Discovery name: Not Found")
            End Try

            If (TypeOf mpOverride Is ManagementPackDiscoveryConfigurationOverride) Then

                Dim configOverride As ManagementPackDiscoveryConfigurationOverride = _
                    CType(mpOverride, ManagementPackDiscoveryConfigurationOverride)
                Console.WriteLine("      Parameter: " & configOverride.Parameter)
                Console.WriteLine("      Value: " & configOverride.Value)

            ElseIf (TypeOf mpOverride Is ManagementPackDiscoveryPropertyOverride) Then

                Dim propertyOverride As ManagementPackDiscoveryPropertyOverride = _
                    CType(mpOverride, ManagementPackDiscoveryPropertyOverride)
                Console.WriteLine("      Property: " & propertyOverride.Property)
                Console.WriteLine("      Value: " & propertyOverride.Value)
            End If
        End Sub

        ' --------------------------------------------------------------------------------------------------
        Private Shared Sub PrintDiagnosticOverrideDetails(ByVal mpOverride As ManagementPackOverride, _
                                                          ByVal mg As ManagementGroup)

            Console.WriteLine("--- Diagnostic Override Details: ")

            Dim diagnosticOverride As ManagementPackDiagnosticOverride
            Dim diagnostic As ManagementPackDiagnostic

            diagnosticOverride = CType(mpOverride, ManagementPackDiagnosticOverride)

            Try

                diagnostic = mg.GetMonitoringDiagnostic(diagnosticOverride.Diagnostic.Id)
                Console.WriteLine("    Diagnostic name: " & diagnostic.Name)

            Catch e As ObjectNotFoundException

                Console.WriteLine("    Diagnostic name: Not Found")
            End Try

            If (TypeOf mpOverride Is ManagementPackDiagnosticConfigurationOverride) Then

                Dim configOverride As ManagementPackDiagnosticConfigurationOverride = _
                    CType(mpOverride, ManagementPackDiagnosticConfigurationOverride)
                Console.WriteLine("      Parameter: " & configOverride.Parameter)
                Console.WriteLine("      Value: " & configOverride.Value)

            ElseIf (TypeOf mpOverride Is ManagementPackDiagnosticPropertyOverride) Then

                Dim propertyOverride As ManagementPackDiagnosticPropertyOverride = _
                    CType(mpOverride, ManagementPackDiagnosticPropertyOverride)
                Console.WriteLine("      Property: " & propertyOverride.Property)
                Console.WriteLine("      Value: " & propertyOverride.Value)
            End If
        End Sub

        ' --------------------------------------------------------------------------------------------------
        Private Shared Sub PrintCategoryOverrideDetails(ByVal mpOverride As ManagementPackOverride, _
                                                        ByVal mg As ManagementGroup)

            Console.WriteLine("--- Category Override Details: ")

            Dim categoryOverride As ManagementPackCategoryOverride = _
                CType(mpOverride, ManagementPackCategoryOverride)

            Console.WriteLine("      Category: " & categoryOverride.Category)
            Console.WriteLine("      Value: " & categoryOverride.Value)

        End Sub

        ' --------------------------------------------------------------------------------------------------
        Private Shared Sub PrintMonitorOverrideDetails(ByVal mpOverride As ManagementPackOverride, _
                                                       ByVal mg As ManagementGroup)

            Console.WriteLine("--- Monitor Override Details: ")

            Dim monitorOverride As ManagementPackMonitorOverride
            Dim monitor As ManagementPackMonitor

            monitorOverride = CType(mpOverride, ManagementPackMonitorOverride)

            Try

                monitor = mg.GetMonitor(monitorOverride.Monitor.Id)
                Console.WriteLine("    Monitor name: " & monitor.Name)

            Catch e As ObjectNotFoundException

                Console.WriteLine("    Monitor name: Not Found")
            End Try

            If (TypeOf mpOverride Is ManagementPackMonitorConfigurationOverride) Then

                Dim configOverride As ManagementPackMonitorConfigurationOverride = _
                    CType(mpOverride, ManagementPackMonitorConfigurationOverride)
                Console.WriteLine("      Parameter: " & configOverride.Parameter)
                Console.WriteLine("      Value: " & configOverride.Value)

            ElseIf (TypeOf mpOverride Is ManagementPackMonitorPropertyOverride) Then

                Dim propertyOverride As ManagementPackMonitorPropertyOverride = _
                    CType(mpOverride, ManagementPackMonitorPropertyOverride)
                Console.WriteLine("      Property: " & propertyOverride.Property)
                Console.WriteLine("      Value: " & propertyOverride.Value)
            End If
        End Sub
    End Class
End Namespace