SCOM 2012 SDK Override

Hi guys,

I need write C# code for scom. I use SDK and I have question.

This is code from

https://msdn.microsoft.com/en-us/library/bb960482.aspx

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

Why I can use monitoring class for create override? I founded managementpack without classes and i get error with this sample of code. Can I make override without classes if I can how?

Thanks

September 2nd, 2015 1:02am

Hi,

No, you can not create a override without a class instance, to create a override you need either group or class or instance of object mandatory.

you need to load dependent mp where class is defined in to library and get class instance from the monitoring target and create a instance of it.

 Regards

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 2:58am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics