thespot4sap.com independent sap information
 

get SAP Access - pay monthly

  Online SAP Training    SAP Jobs    SAP Tutorials    SAP CBT    Articles    Forums   SAP Resume
  SAP Access    SAP Books    Links     Vendor Directory     Submit Content    Search
Previous posts in SAPscript
Page 1563 of 5660

Creating a unit monitor using the SDK

Blogger : MSDN Blogs
All posts : All posts by MSDN Blogs
Category : SAPscript
Blogged date : 2007 Oct 26

This came up several times so I decided to write a blog post on how you can create a unit monitor using the SDK. I will try post a PS script that does the same thing in the next several days.

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;

            MonitoringClassCriteria       monitoringClassCriteria;

            ManagementPackUnitMonitor     serviceMonitor;

            ManagementPackUnitMonitorType serviceMonitorType;

 

            mg = new ManagementGroup("localhost");

 

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

 

            monitoringClassCriteria = new MonitoringClassCriteria("DisplayName='Windows Server 2003 Operating System'");

 

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

 

            serviceMonitorType = mg.GetUnitMonitorTypes("Microsoft.Windows.CheckNTServiceStateMonitorType")[0];

 

serviceMonitor = new ManagementPackUnitMonitor(mp,                                                           "SampleServiceMonitor",

            ManagementPackAccessibility.Internal);

           

            serviceMonitor.DisplayName = "Sample Service Monitor";

           

            serviceMonitor.TypeID = serviceMonitorType;

            serviceMonitor.Target = monitoringClass;

 

            ConfigureAlertSettings(serviceMonitor,serviceMonitorType,mp);

           

            ConfigureHealthStates(serviceMonitor, serviceMonitorType);

           

            SpecifyMonitorConfiguration(serviceMonitor);

 

            SpecifyParentMonitor(serviceMonitor, mg);

 

            mp.Verify();

           

            //Save the changes into the management pack.

            mp.AcceptChanges();

        }

 

        private static void SpecifyParentMonitor(

            ManagementPackUnitMonitor   serviceMonitor,

            ManagementGroup             mg

            )

        {

            ManagementPackAggregateMonitor  parentMonitor;

            MonitorCriteria                 monitorCriteria;

 

            monitorCriteria = new MonitorCriteria("Name='System.Health.AvailabilityState'");

            parentMonitor = (ManagementPackAggregateMonitor)mg.GetMonitors(monitorCriteria)[0];

            serviceMonitor.ParentMonitorID  = parentMonitor;

        }

 

        //-------------------------------------------------------------------

        private static void SpecifyMonitorConfiguration(

            ManagementPackUnitMonitor serviceMonitor

            )

        {

            string monitorConfig;

 

            monitorConfig = @"<ComputerName>$Target/Host/Property[Type=" "Windows!Microsoft.Windows.Computer" "]/NetworkName$</ComputerName>

                                        <ServiceName>Alerter</ServiceName>";

           

            serviceMonitor.Configuration = monitorConfig;

        }

 

        //-------------------------------------------------------------------

        private static void ConfigureHealthStates(

            ManagementPackUnitMonitor       serviceMonitor,

            ManagementPackUnitMonitorType   serviceMonitorType

            )

        {

            ManagementPackUnitMonitorOperationalState healthyState;

            ManagementPackUnitMonitorOperationalState errorState;

 

            healthyState = new ManagementPackUnitMonitorOperationalState(serviceMonitor, "Success");

            errorState   = new ManagementPackUnitMonitorOperationalState(serviceMonitor, "Error");

 

            healthyState.HealthState        = HealthState.Success;

            healthyState.MonitorTypeStateID = "Running";

           

            errorState.HealthState          = HealthState.Error;

            errorState.MonitorTypeStateID   = "NotRunning";

 

            serviceMonitor.OperationalStateCollection.Add(healthyState);

            serviceMonitor.OperationalStateCollection.Add(errorState);

        }

 

        //-------------------------------------------------------------------

        private static void ConfigureAlertSettings(

            ManagementPackUnitMonitor       serviceMonitor,

            ManagementPackUnitMonitorType   unitMonitorType,

            ManagementPack                  mp

            )

        {  

            serviceMonitor.AlertSettings = new ManagementPackMonitorAlertSettings();

            serviceMonitor.AlertSettings.AlertOnState       = HealthState.Error;

            serviceMonitor.AlertSettings.AutoResolve        = true;

            serviceMonitor.AlertSettings.AlertPriority      = ManagementPackWorkflowPriority.Normal;

            serviceMonitor.AlertSettings.AlertSeverity      = ManagementPackAlertSeverity.Error;

            serviceMonitor.AlertSettings.AlertParameter1    = @"$Target/Host/Property[Type=" "Windows!Microsoft.Windows.Computer" "]/NetworkName$"; //this points to the computer name           

 

            ManagementPackStringResource alertMessage;

           

            alertMessage = new ManagementPackStringResource(mp, "SampleAlertMessage");

 

            alertMessage.DisplayName = "The Alerter service is stopped";

            alertMessage.Description = "The Alerter service is stopped on computer {0}.";

 

            serviceMonitor.AlertSettings.AlertMessage = alertMessage;

        }       

    }

}

 

 

 


Read comments or post a reply to : Creating a unit monitor using the SDK
Page 1563 of 5660

Newest posts
New Page 1

 

 

About Us   Contact Us   Privacy   Disclaimer   Feedback   Email Discussion   Newsletter  

Copyright © - Independent SAP Information
Find a Bed and Breakfast