private PartialMonitoringObject GetSBWSHostComputer(string sbwsHostComputerName)
        {
            if (base.ManagementGroup == null)
            {
                return(null);
            }
            ManagementPackClass monitoringClass = base.ManagementGroup.EntityTypes.GetClass(SystemMonitoringClass.HealthService);

            if (monitoringClass == null)
            {
                return(null);
            }

            List <PartialMonitoringObject>          partialMonitoringObjects = new List <PartialMonitoringObject>();
            IObjectReader <PartialMonitoringObject> reader =
                ManagementGroup.EntityObjects.GetObjectReader <PartialMonitoringObject>(
                    new MonitoringObjectGenericCriteria(string.Format(CultureInfo.InvariantCulture, "Name = '{0}' OR DisplayName = '{0}'", new object[] { sbwsHostComputerName })), monitoringClass, ObjectQueryOptions.Default);

            partialMonitoringObjects.AddRange(reader);

            if (partialMonitoringObjects.Count == 1)
            {
                return(partialMonitoringObjects[0]);
            }
            return(null);
        }
示例#2
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="dg"></param>
        /// <param name="FullName"></param>
        /// <param name="Description"></param>
        /// <param name="Port"></param>
        /// <param name="MonitorRule"></param>
        public PoolMember(SyncFailoverGroup dg, string PartitionName, string PoolFullName, string FullName, string Description, string Port, string MonitorRule)
        {
            // Get ShortName
            string ShortName = FullName.Substring(FullName.LastIndexOf("/") + 1);
            // Get Partition
            string Partition = FullName.Substring(1, FullName.LastIndexOf("/") - 1);

            // Create Pool Management Pack Class
            ManagementPackClass mpc_PoolMember = SCOM.GetManagementPackClass("AP.F5.LTM.PoolMember");

            // Create New NetworkInterface Object
            SCOM_Object = new CreatableEnterpriseManagementObject(SCOM.m_managementGroup, mpc_PoolMember);

            // Create Root Entity Class & Key Property
            ManagementPackClass    mpc_Entity            = SCOM.GetManagementPackClass("System.Entity");
            ManagementPackProperty mpp_EntityDisplayName = mpc_Entity.PropertyCollection["DisplayName"];

            SCOM_Object[mpp_EntityDisplayName].Value = ShortName;

            // Create SyncFailoverGroup Management Pack Class & Key Property
            ManagementPackClass    mpc_SyncFailoverGroup    = SCOM.GetManagementPackClass("AP.F5.LTM.SyncFailoverGroup");
            ManagementPackProperty mpp_SyncFailoverGroupKey = mpc_SyncFailoverGroup.PropertyCollection["Key"];

            SCOM_Object[mpp_SyncFailoverGroupKey].Value = dg.Key;

            // Create Partition Management Pack Class & Key Property
            ManagementPackClass    mpc_Partition     = SCOM.GetManagementPackClass("AP.F5.LTM.Partition");
            ManagementPackProperty mpp_PartitionName = mpc_Partition.PropertyCollection["Name"];

            SCOM_Object[mpp_PartitionName].Value = PartitionName;

            // Create Pool Management Pack Class
            ManagementPackClass    mpc_Pool    = SCOM.GetManagementPackClass("AP.F5.LTM.Pool");
            ManagementPackProperty mpp_PoolKey = mpc_Pool.PropertyCollection["FullName"];

            SCOM_Object[mpp_PoolKey].Value = PoolFullName;

            // Create PoolMember Management Pack Class & Properties
            ManagementPackProperty mpp_PoolMemberFullName = mpc_PoolMember.PropertyCollection["FullName"];

            SCOM_Object[mpp_PoolMemberFullName].Value = FullName;
            ManagementPackProperty mpp_PoolMemberName = mpc_PoolMember.PropertyCollection["Name"];

            SCOM_Object[mpp_PoolMemberName].Value = ShortName;
            ManagementPackProperty mpp_PoolMemberPartition = mpc_PoolMember.PropertyCollection["Partition"];

            SCOM_Object[mpp_PoolMemberPartition].Value = Partition;
            ManagementPackProperty mpp_PoolMemberPort = mpc_PoolMember.PropertyCollection["Port"];

            SCOM_Object[mpp_PoolMemberPort].Value = Port;
            ManagementPackProperty mpp_PoolMemberDescription = mpc_PoolMember.PropertyCollection["Description"];

            SCOM_Object[mpp_PoolMemberDescription].Value = Description;
            ManagementPackProperty mpp_PoolMemberMonitorRule = mpc_PoolMember.PropertyCollection["MonitorRule"];

            SCOM_Object[mpp_PoolMemberMonitorRule].Value = MonitorRule;
            ManagementPackProperty mpp_PoolMemberPoolName = mpc_PoolMember.PropertyCollection["PoolName"];

            SCOM_Object[mpp_PoolMemberPoolName].Value = PoolFullName;
        }
示例#3
0
        public static string GetDataWarehouseConnectionString(this ManagementGroup mg, bool integratedSecurity = true, string extraOptions = null)
        {
            ManagementPackClass        DWClass    = mg.EntityTypes.GetClass(SystemCenterId.DataWarehouseClassId); // GetClass(mg, "Microsoft.SystemCenter.DataWarehouse");
            EnterpriseManagementObject DWInstance = mg.EntityObjects.GetObjectReader <EnterpriseManagementObject>(DWClass, ObjectQueryOptions.Default).FirstOrDefault();

            if (DWInstance != null)
            {
                string DWSQLServerName = DWInstance[SystemCenterId.DataWarehouseClassProperties.MainDatabaseServerNamePropertyId].Value.ToString();
                string DWDataBaseName  = DWInstance[SystemCenterId.DataWarehouseClassProperties.MainDatabaseNamePropertyId].Value.ToString();
                string result          = "Server=" + DWSQLServerName + ";Database=" + DWDataBaseName;
                if (integratedSecurity)
                {
                    result += ";Integrated Security=True";
                }
                else
                {
                    result += ";Integrated Security=False";
                }
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    if (extraOptions[0] != ';')
                    {
                        extraOptions = ";" + extraOptions;
                    }
                    result += extraOptions;
                }
                return(result);
            }
            else
            {
                throw new ObjectNotFoundException("Cannot find Data Warehouse instance. Entire SCOM must be broken.");
            }
        }
示例#4
0
        private void AddToCatalogWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                emg = GetSession();
                if (emg == null)
                {
                    emg = new EnterpriseManagementGroup("SM");
                }

                //mpAssetCore = emg.ManagementPacks.GetManagementPack("SMCenter.AssetManagement.Core", "75b45bd6835084b1", new Version());

                mpSoftLibrary = emg.ManagementPacks.GetManagementPack("SMCenter.SoftwareAssetManagement.Library", "75b45bd6835084b1", new Version());
                //mpSystemSoftwareLibrary = emg.ManagementPacks.GetManagementPack("System.Software.Library", "31bf3856ad364e35", new Version());
                //classSoftwareItem = emg.EntityTypes.GetClass("System.SoftwareItem", mpSystemSoftwareLibrary);
                classSoftwareTitle   = emg.EntityTypes.GetClass("SMCenter.SoftwareTitle", mpSoftLibrary);
                classSoftwareVersion = emg.EntityTypes.GetClass("SMCenter.SoftwareVersion", mpSoftLibrary);
                //classPublisher = emg.EntityTypes.GetClass("SMCenter.Company", mpAssetCore);
                //SMCenter.PublisherHasSoftwareTitle
                //SMCenter.SoftwareTitleHasSoftwareVersion
                //SMCenter.SoftwareVersionReferencesDiscoveredSoftwareItem
                relSoftwareTitleHasSoftwareVersion = emg.EntityTypes.GetRelationshipClass("SMCenter.SoftwareTitleHasSoftwareVersion", mpSoftLibrary);
                //relExcludedSoftwareItemGroup = emg.EntityTypes.GetRelationshipClass("SMCenter.ExcludedSoftwareItemGroupContainsEntities", mpSoftLibrary);

                //TemplateSoftwareTitle.PathString = "SotwareTitle";
                //TemplateSoftwareTitle.mpClass = classSoftwareTitle;
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Initialize procedure error : " + ex.Message, "Service Manager", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }
示例#5
0
        /// <summary>
        /// Gets the history alarm datas.
        /// </summary>
        /// <param name="mpClass">The mp class.</param>
        /// <param name="eSightIp">The eSight Ip.</param>
        /// <returns>List&lt;AlarmData&gt;.</returns>
        public List <AlarmData> GetExistAlarmDatas(ManagementPackClass mpClass, string eSightIp)
        {
            var existEvents = GetExistEvents(mpClass, eSightIp);

            // HWLogger.Service.Info($"ExistEvents :[{ JsonUtil.SerializeObject(existEvents)}]");
            return(existEvents.Where(x => x.EventData.Contains("<AlarmData>")).Select(x => x.GetAlarmData()).ToList());
        }
示例#6
0
        /// <summary>
        /// Inserts the device change event.
        /// </summary>
        /// <param name="mpClass">The mp class.</param>
        /// <param name="eventData">The event data.</param>
        /// <param name="eSightIp">The e sight ip.</param>
        public void InsertDeviceChangeEvent(ManagementPackClass mpClass, DeviceChangeEventData eventData, string eSightIp)
        {
            try
            {
                var logger = HWLogger.GetESightSdkLogger(eventData.ESightIp);
                HWLogger.GetESightSdkLogger(eSightIp).Info($"Start Insert DeviceChangeEvent.[{JsonUtil.SerializeObject(eventData)}]");
                MGroup.Instance.CheckConnection();
                var obj = GetObjectByDeviceId(mpClass, eventData.DeviceId);

                if (obj == null)
                {
                    logger.Warn($"InsertDeviceChangeEvent:Can not find the MonitoringObject:{eventData.DeviceId}");
                    return;
                }
                var isReady = CheckAndWaitHealthStateReady(mpClass, obj, eventData.DeviceId, eSightIp);
                if (!isReady)
                {
                    logger.Warn($"InsertDeviceChangeEvent:The MonitoringObject state is uninitialized.Drop the event.");
                    return;
                }
                obj?.InsertCustomMonitoringEvent(eventData.ToCustomMonitoringEvent());
            }
            catch (Exception ex)
            {
                HWLogger.GetESightSdkLogger(eSightIp).Error(ex, "Insert DeviceChangeEvent Error");
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Type in the Work Item ID (e.g. 'AC1234'). Or just press enter to grab the first found Timer Activity. Tot test settings type 'settings'");
            string strID = Console.ReadLine();



            EnterpriseManagementGroup emg = new EnterpriseManagementGroup("localhost");


            ManagementPackClass mpcTimerActivity = Common.GetManagementPackClassByName("Cireson.Timer.Activity", emg);
            ManagementPackClass mpcWorkItem      = Common.GetManagementPackClassByName("System.WorkItem", emg);


            EnterpriseManagementObject emoActivity = null;
            Window defaultWindow = null;

            if (String.IsNullOrEmpty(strID))
            {
                var emoReader = emg.EntityObjects.GetObjectReader <EnterpriseManagementObject>(mpcTimerActivity, ObjectQueryOptions.Default);

                if (emoReader.Count == 0)
                {
                    throw new Exception("Found zero objects of class " + mpcTimerActivity.Name);
                }
                emoActivity = emoReader.First();
            }
            else if (strID == "settings")
            {
                defaultWindow = new TimerActivitySettingsWindow();

                defaultWindow.Width  = 400;
                defaultWindow.Height = 300;
            }
            else
            {
                EnterpriseManagementObjectGenericCriteria cmogc = new EnterpriseManagementObjectGenericCriteria("Name = '" + strID + "'");
                var emoReader = emg.EntityObjects.GetObjectReader <EnterpriseManagementObject>(cmogc, ObjectQueryOptions.Default);

                if (emoReader.Count == 0)
                {
                    throw new Exception("Found zero objects with id '" + strID + "'");
                }
                emoActivity = emoReader.First();
                var taUserControl = new CiresonTimerActivityUserControl(); //This manually triggers the user control dataContext changed event

                defaultWindow = new Window();


                defaultWindow.Width       = 800;
                defaultWindow.Height      = 1000;
                defaultWindow.Content     = taUserControl;
                taUserControl.DataContext = emoActivity; //This simulates when SCSM sets the datacontext as an idataitem on Window initialization.
            }



            defaultWindow.ShowDialog(); //Make it modal, because we can. Also prevents the window from closing instantly.
            //defaultWindow.Show();
        }
示例#8
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //try
            //{
            GetSession();

            mpCore = emg.GetManagementPack("SMCenter.AssetManagement.Core", "75b45bd6835084b1", new Version());
            mpNA   = emg.GetManagementPack("SMCenter.NetworkAssetManagement.Library", "75b45bd6835084b1", new Version());


            classLocation = emg.EntityTypes.GetClass("SMCenter.Location", mpCore);
            //classNetworkMap = emg.EntityTypes.GetClass("SMCenter.NetworkMap", mpNA);

            relLoctoLoc = emg.EntityTypes.GetRelationshipClass("SMCenter.LocationContainsChildLocation", mpCore);

            //Fill Templates

            this.TemplateLocationItem.emg                 = emg;
            this.TemplateLocationItem.PathString          = "LinkedLocation";
            this.TemplateLocationItem.mpClass             = classLocation;
            this.TemplateLocationItem.mpRelationshipClass = relLoctoLoc;
            this.TemplateLocationItem.criteria            = new EnterpriseManagementObjectCriteria("LocationType = '0A607435-3D34-23D1-B38E-B89DDE0A558D'", classLocation);


            //////Handlers
            this.AddHandler(FormEvents.SubmittedEvent, new EventHandler <FormCommandExecutedEventArgs>(this.OnSubmitted));
            this.AddHandler(FormEvents.PreviewSubmitEvent, new EventHandler <PreviewFormCommandEventArgs>(this.OnPreviewSubmit));
            //}
            //catch (Exception ex)
            //{
            //    System.Windows.MessageBox.Show(DateTime.Now + " : " + "UserControl_Loaded Error : " + ex.Message);
            //}
        }
示例#9
0
        public SMHandler()
        {
            String strSMServerName = null;

            try
            {
                strSMServerName = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString();
            }
            catch
            {
                Console.WriteLine("Cannot read the name of the SM Server from Registry.");
                Environment.Exit(2);
            }

            try
            {
                mg = new EnterpriseManagementGroup(strSMServerName);
            }
            catch
            {
                Console.WriteLine("Cannot connect to SM Server {0}", strSMServerName);
                Environment.Exit(2);
            }

            ManagementPack systemWorkitemMP = GetManagementPackByName("System.WorkItem.Library", this.mg);

            wiClass = systemWorkitemMP.GetClass(WIType);
        }
示例#10
0
        /// <summary>
        /// 插入历史告警-插入前请先排重
        /// </summary>
        /// <param name="mpClass">The mp class.</param>
        /// <param name="eventDatas">The event datas.</param>
        public void InsertHistoryEvent(ManagementPackClass mpClass, List <EventData> eventDatas)
        {
            // 获取到历史的事件记录
            // var eventHistory = obj.GetMonitoringEvents();
            // 过滤掉已经存在的事件-如果已存在,则不再重复添加
            // var filterEventList = eventDatas.Where(y => eventHistory.All(x => x.Parameters[5] != y.AlarmSn.ToString())).ToList();
            var deviceId = eventDatas[0].DeviceId;
            var obj      = this.GetReadyObject(mpClass, deviceId);

            HWLogger.SERVICE.Debug($"{deviceId}:Start insert event.");
            var alertHistory = obj.GetMonitoringAlerts();
            // 过滤掉已经存在的告警
            var filterAlertList = eventDatas.Where(y => alertHistory.All(x => x.CustomField6 != y.AlarmSn.ToString())).ToList();

            HWLogger.SERVICE.Info($"InsertHistoryEvent : [Event Count:{eventDatas.Count}] [New Alert Count:{filterAlertList.Count}]");
            if (!filterAlertList.Any())
            {
                return;
            }
            foreach (var eventData in filterAlertList)
            {
                try
                {
                    obj.InsertCustomMonitoringEvent(eventData.ToCustomMonitoringEvent());
                }
                catch (Exception ex)
                {
                    HWLogger.SERVICE.Error($"InsertHistoryEvent Error.AlarmSn: {eventData.AlarmSn}", ex);
                }
            }
        }
示例#11
0
 /// <summary>
 /// 删除Server以及父级的Computer
 /// </summary>
 /// <param name="mpClass">The class.</param>
 public void RemoverServers(ManagementPackClass mpClass)
 {
     try
     {
         MGroup.Instance.CheckConnection();
         var blades =
             MGroup.Instance.EntityObjects.GetObjectReader <PartialMonitoringObject>(
                 mpClass,
                 ObjectQueryOptions.Default);
         var deviceIds = blades.ToList().Select(x => x.Path).ToList();
         var discovery = new IncrementalDiscoveryData();
         deviceIds.ForEach(
             deviceId =>
         {
             var existingObject = this.GetComputerByDeviceId(deviceId);
             if (existingObject != null)
             {
                 discovery.Remove(existingObject);
             }
         });
         discovery.Commit(this.MontioringConnector);
     }
     catch (Exception ex)
     {
         HWLogger.SERVICE.Error("RemoverServers", ex);
         throw;
     }
 }
示例#12
0
        /// <summary>
        /// 插入告警时,等待新增的对象的healthState不再是Not Monitor
        /// </summary>
        /// <param name="mpClass">The mp class.</param>
        /// <param name="deviceId">The device identifier.</param>
        /// <returns>PartialMonitoringObject.</returns>
        private PartialMonitoringObject GetNewReadyObject(ManagementPackClass mpClass, string deviceId)
        {
            MGroup.Instance.CheckConnection();
            var obj = this.GetObjectByDeviceId(mpClass, deviceId);

            if (obj.StateLastModified == null)
            {
                #region 新增对象
                HWLogger.SERVICE.Debug($"New Object:{deviceId}");
                while (true)
                {
                    // 重新查询obj状态
                    obj = this.GetObjectByDeviceId(mpClass, deviceId);
                    if (obj.HealthState != HealthState.Uninitialized)
                    {
                        HWLogger.SERVICE.Debug($"{deviceId} first healthState is {obj.HealthState}.");
                        break;
                    }
                    HWLogger.SERVICE.Debug($"wait {deviceId} first Initialized...");
                    Thread.Sleep(TimeSpan.FromSeconds(5));
                }
                #endregion
            }
            return(obj);
        }
示例#13
0
        private void PopulateGroups()
        {
            IManagementGroupSession managementGroupSession = null;

            if (base.ParentForm != null && base.ParentForm.Site != null)
            {
                managementGroupSession = (base.ParentForm.Site.GetService(typeof(IManagementGroupSession)) as IManagementGroupSession);
            }

            if (managementGroupSession == null || managementGroupSession.ManagementGroup == null)
            {
                return;
            }

            using (ManageQueryOleDBSDKHelper helper = new ManageQueryOleDBSDKHelper(managementGroupSession.ManagementGroup))
            {
                monitoringClass = helper.GetManagementPackClass("QueryOleDbMonitorLibrary", "OleDBQueryMonitoringGroup");
                if (GroupsImage == null)
                {
                    GroupsImage = ComponentMethodLibrary.GetImageFromSharedCache(monitoringClass, base.ParentForm);
                }
                List <EnterpriseManagementObject>          list      = new List <EnterpriseManagementObject>();
                IObjectReader <EnterpriseManagementObject> allGroups = helper.GetEnterpriseManagementObjects(monitoringClass);
                if (allGroups != null)
                {
                    foreach (EnterpriseManagementObject current in allGroups)
                    {
                        list.Add(current);
                    }
                }
                groups = list;
            }
        }
 /// <summary>
 /// 根据eSight删除Server以及父级的Computer
 /// </summary>
 /// <param name="mpClass">
 /// The class.
 /// </param>
 /// <param name="eSightIp">
 /// The eSightIp.
 /// </param>
 public void RemoverServers(ManagementPackClass mpClass, string eSightIp)
 {
     try
     {
         MGroup.Instance.CheckConnection();
         var criteria = new MonitoringObjectCriteria($"eSight = '{eSightIp}'", mpClass);
         var reader   =
             MGroup.Instance.EntityObjects.GetObjectReader <PartialMonitoringObject>(
                 criteria,
                 ObjectQueryOptions.Default);
         var dns       = reader.ToList().Select(x => x.Path).ToList();
         var discovery = new IncrementalDiscoveryData();
         dns.ForEach(
             dn =>
         {
             var existingObject = this.GetComputerByDn(dn);
             if (existingObject != null)
             {
                 discovery.Remove(existingObject);
             }
         });
         discovery.Commit(this.MontioringConnector);
     }
     catch (Exception ex)
     {
         HWLogger.SERVICE.Error("RemoverServers", ex);
     }
 }
示例#15
0
 public override void ExecuteCommand(IList <NavigationModelNodeBase> nodes, NavigationModelNodeTask task, ICollection <string> parameters)
 {
     try
     {
         EnterpriseManagementGroup emg = ConsoleContext.GetConsoleEMG();
         // (Cireson.ProjectAutomation.Library) (Microsoft.SystemCenter.Connector.ProjectServer.Settings) (5a49b80c-4c34-d189-ca94-a591580f1995)
         ManagementPackClass        mpcSettings = emg.EntityTypes.GetClass(new Guid("5a49b80c-4c34-d189-ca94-a591580f1995"));                           //get the settings class.
         EnterpriseManagementObject emoSettings = emg.EntityObjects.GetObject <EnterpriseManagementObject>(mpcSettings.Id, ObjectQueryOptions.Default); //get the settings class instance.
         //somewhere here we will have a container for our class data to feed the consoleWizard obj.
         AdminSettingsData admData       = new AdminSettingsData(emoSettings);
         WizardStory       consoleWizard = new WizardStory();
         consoleWizard.WizardData = admData;
         consoleWizard.AddLast(new WizardStep(ServiceManagerLocalization.GetStringFromManagementPack("strGroomingSettings"), typeof(AdminSettingsGroomingForm), admData));
         consoleWizard.AddLast(new WizardStep(ServiceManagerLocalization.GetStringFromManagementPack("strStatusSettings"), typeof(AdminSettingsStatusForm), admData));
         consoleWizard.AddLast(new WizardStep(ServiceManagerLocalization.GetStringFromManagementPack("strProjectTasksSettings"), typeof(AdminSettingsProjectTasksForm), admData));
         consoleWizard.AddLast(new WizardStep(ServiceManagerLocalization.GetStringFromManagementPack("strProjectLicensingSettings"), typeof(AdminSettingsLicensingForm), admData));
         PropertySheetDialog propertyDialog = new PropertySheetDialog(consoleWizard);
         propertyDialog.Width  = 800;
         propertyDialog.Height = 700;
         propertyDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
         propertyDialog.Title         = ServiceManagerLocalization.GetStringFromManagementPack("strSettings");
         propertyDialog.ShowInTaskbar = true;
         propertyDialog.Icon          = BitmapFrame.Create(System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/Microsoft.EnterpriseManagement.ServiceManager.ProjectServer.ConsoleTasks;component/Icons/Image.Cireson.16x16.ico", UriKind.RelativeOrAbsolute)).Stream);
         propertyDialog.ShowDialog();
     }
     catch (Exception ex)
     {
         ConsoleContextHelper.Instance.ShowErrorDialog(ex, string.Empty, ConsoleJobExceptionSeverity.Error);
     }
 }
        private void UpdateConnectorInstance()
        {
            //Get the server name to connect to and connect
            String strServerName          = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\System Center\\2010\\Service Manager\\Console\\User Settings", "SDKServiceMachine", "localhost").ToString();
            EnterpriseManagementGroup emg = new EnterpriseManagementGroup(strServerName);

            //Get the Connectors MP and AA Connector Class
            ManagementPack      mpConnectors     = emg.GetManagementPack("SCSM.AzureAutomation", "ac1fe0583b6c84af", new Version("1.0.0.0"));
            ManagementPackClass classAAConnector = mpConnectors.GetClass("SCSM.AzureAutomation.Connector");

            //Get the Connector object using the object ID
            EnterpriseManagementObject emoAAConnector = emg.EntityObjects.GetObject <EnterpriseManagementObject>(this.EnterpriseManagementObjectID, ObjectQueryOptions.Default);

            //Set the property values to the new values
            emoAAConnector[classAAConnector, "DisplayName"].Value          = this.DisplayName;
            emoAAConnector[classAAConnector, "AutomationAccount"].Value    = this.AutomationAccount;
            emoAAConnector[classAAConnector, "SubscriptionID"].Value       = this.SubscriptionID;
            emoAAConnector[classAAConnector, "ResourceGroup"].Value        = this.ResourceGroup;
            emoAAConnector[classAAConnector, "RunAsAccountName"].Value     = this.RunAsAccountName;
            emoAAConnector[classAAConnector, "RunAsAccountPassword"].Value = this.RunAsAccountPassword;
            emoAAConnector[classAAConnector, "RefreshIntervalHours"].Value = this.RefreshIntervalHours;



            //Update Connector instance
            emoAAConnector.Commit();

            mpConnectors.AcceptChanges();
        }
        private static void CreateQueue(ManagementPackClass mpc, ManagementPackEnumeration mpe, string strMPAlias, ManagementPackProperty mpp, ref ManagementPack mp, EnterpriseManagementGroup emg)
        {
            string strQueueDisplayName = String.Format("{0}: {1}", mpc.DisplayName, mpe.DisplayName);
            string strCriteria         = ConstructCriteria(strMPAlias, mpc, mpp, mpe);

            Helper.CreateQueue(strQueueDisplayName, Helper.MakeMPElementSafeName(strQueueDisplayName), strCriteria, mpc, ref mp, emg);
        }
示例#18
0
        /// <summary>
        /// Deletes the servers on synchronize.
        /// </summary>
        /// <param name="eSightIp">The e sight ip.</param>
        /// <param name="newDeviceIds">The new device ids.</param>
        /// <param name="mpClass">The mp class.</param>
        public void RemoveServersOnSync(string eSightIp, List <string> newDeviceIds, ManagementPackClass mpClass)
        {
            try
            {
                HWLogger.GetESightSdkLogger(eSightIp).Info($"Check Removed Servers On Polling.[mpClass:{mpClass}][curQueryResult:{string.Join(",", newDeviceIds)}]");
                MGroup.Instance.CheckConnection();
                var criteria     = new MonitoringObjectCriteria($"eSight = '{eSightIp}'", mpClass);
                var exsitDevices = MGroup.Instance.EntityObjects.GetObjectReader <MonitoringObject>(criteria, ObjectQueryOptions.Default).ToList();

                var deleteDevices = exsitDevices.Where(x =>
                                                       newDeviceIds.All(newDeviceId => newDeviceId != x[this.HuaweiServerKey].Value.ToString()))
                                    .ToList();

                var discovery = new IncrementalDiscoveryData();
                deleteDevices.ForEach(deleteDevice =>
                {
                    discovery.Remove(deleteDevice);
                });
                discovery.Commit(this.MontioringConnector);

                if (deleteDevices.Any())
                {
                    HWLogger.GetESightSdkLogger(eSightIp).Info($"RemoveServers OnSync:delete servers[{mpClass.Name}]:{string.Join(",", deleteDevices.Select(x => x[this.HuaweiServerKey].Value.ToString()).Distinct())} ");
                }
            }
            catch (Exception e)
            {
                HWLogger.GetESightSdkLogger(eSightIp).Error($"RemoveServers OnSync.", e);
            }
        }
示例#19
0
        /// <summary>
        /// This constructor is for unhosted objects managed by specific instance of defined Action Point class OR for hosted objects,
        /// which are hosted on defined Action Point class.
        /// </summary>
        /// <param name="managementGroup"></param>
        /// <param name="seedClass"></param>
        /// <param name="actionPointClassName"></param>
        /// <param name="monitoringConnector"></param>
        public ScomClassInstanceEditor(ManagementGroup managementGroup, ManagementPackClass seedClass, ManagementPackClass actionPointClass, MonitoringConnector monitoringConnector = null, ManagementPackRelationship hostingRelationship = null)
            : this(managementGroup, seedClass, monitoringConnector)
        {
            _actionPointClass = actionPointClass ?? throw new ArgumentNullException(nameof(actionPointClass));

            if (seedClass.Hosted)
            {
                _relMapShouldManageEntity = null;
                _relMapManagesEntity      = null;

                _relHosting = hostingRelationship ?? managementGroup.EntityTypes.GetRelationshipClass(SystemRelationship.Hosting);
            }
            else
            {
                if (actionPointClass.IsSubtypeOf(managementGroup.EntityTypes.GetClass(_managementActionPointClassId)) || actionPointClass.Id == _managementActionPointClassId)
                {
                    _relMapShouldManageEntity = managementGroup.EntityTypes.GetRelationshipClass(_managementActionPointShouldManageEntityRelationshipId);
                }
                else if (actionPointClass.IsSubtypeOf(managementGroup.EntityTypes.GetClass(SystemMonitoringClass.HealthService)) || actionPointClass.Id == SystemMonitoringClass.HealthService.Id)
                {
                    _relHsShouldManageEntity = managementGroup.EntityTypes.GetRelationshipClass(SystemMonitoringRelationship.HealthServiceShouldManageEntity);
                }
                else
                {
                    throw new NotSupportedException("For unhosted scenario, action point class should be either Microsoft.SystemCenter.ManagementActionPoint or Microsoft.SystemCenter.HealthService, or inherited from these classes.");
                }

                _relMapManagesEntity = managementGroup.EntityTypes.GetRelationshipClass(_managementActionPointManagesEntityRelationshipId);
            }

            _actionPoints.AddRange(managementGroup.EntityObjects.GetObjectReader <MonitoringObject>(_actionPointClass, ObjectQueryOptions.Default));
        }
 /// <summary>
 /// Inserts the device change event.
 /// </summary>
 /// <param name="mpClass">The mp class.</param>
 /// <param name="deviceChangeEventData">The device change event data.</param>
 public void InsertDeviceChangeEvent(ManagementPackClass mpClass, DeviceChangeEventData deviceChangeEventData)
 {
     try
     {
         MGroup.Instance.CheckConnection();
         var criteria = new MonitoringObjectCriteria($"DN = '{deviceChangeEventData.Dn}'", mpClass);
         var reader   = MGroup.Instance.EntityObjects.GetObjectReader <PartialMonitoringObject>(criteria, ObjectQueryOptions.Default);
         if (reader.Any())
         {
             var obj = reader.First();
             {
                 obj.InsertCustomMonitoringEvent(deviceChangeEventData.ToCustomMonitoringEvent());
             }
         }
         else
         {
             throw new Exception($"cannot find DN '{deviceChangeEventData.Dn}'");
         }
     }
     catch (Exception ex)
     {
         HWLogger.SERVICE.Error(ex);
         throw;
     }
 }
        /// <summary>
        /// Alls the specified entity class name.
        /// </summary>
        /// <param name="entityClass">The entity class.</param>
        /// <returns>IObjectReader&lt;EnterpriseManagementObject&gt;.</returns>
        public IObjectReader <EnterpriseManagementObject> All(ManagementPackClass entityClass)
        {
            IObjectReader <EnterpriseManagementObject> items = this.EntityObjects
                                                               .GetObjectReader <EnterpriseManagementObject>(entityClass, ObjectQueryOptions.Default);

            return(items);
        }
示例#22
0
        private Guid diskSizeStrPropertyId           = Guid.Parse("60c0b971-d523-6564-0be5-e8649e194a25"); // (Get-SCOMClass -id 486adddb-2eb8-819a-fa24-8f6ab3e29543).propertycollection | ft name, displayname, type, id

        public override void OnCacheUpdated(PartialMonitoringObject monitoringObjectContext)
        {
            lvDisks.Items.Clear();
            if (monitoringObjectContext == null)
            {
                ShowStatusMessage("No computer object selected.", false);
                return;
            }
            HideStatusMessage();
            #region Show information related to the currently selected object
            if (logicalDiskClass == null)
            {
                logicalDiskClass = ManagementGroup.EntityTypes.GetClass(Guid.Parse("486adddb-2eb8-819a-fa24-8f6ab3e29543")); // Microsoft.Windows.Server.LogicalDisk
            }
            if (logicalDiskClass == null)
            {
                return;
            }
            IList <EnterpriseManagementRelationshipObject <MonitoringObject> > allDisksLinks = ManagementGroup.EntityObjects.GetRelationshipObjectsWhereSource <MonitoringObject>(monitoringObjectContext.Id, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
            if (allDisksLinks != null && allDisksLinks.Count > 0)
            {
                foreach (MonitoringObject diskMo in allDisksLinks.Where(r => r.TargetObject.IsInstanceOf(logicalDiskClass)).Select(dl => dl.TargetObject).OrderBy(o => o.Name))
                {
                    lvDisks.Items.Add(new ListViewItem(new string[] { diskMo.DisplayName, (Convert.ToDecimal(diskMo[diskSizeStrPropertyId].Value) / 1024 / 1024 / 1024).ToString("N2") })); // KB->MB->GB
                }
            }
            #endregion
        }
示例#23
0
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            DBEngineChooserDialog dialog = new DBEngineChooserDialog(Container);

            dialog.ShowDialog(this);
            if (dialog.DialogResult == DialogResult.OK)
            {
                if (dialog.SelectedItems != null)
                {
                    ChooserControlItem selectedItem = dialog.SelectedItem as ChooserControlItem;
                    if ((selectedItem == null) || (selectedItem.Item == null))
                    {
                    }
                    else
                    {
                        EnterpriseManagementObject item = selectedItem.Item as EnterpriseManagementObject;
                        if (!string.IsNullOrEmpty(item.FullName))
                        {
                            if (item.DisplayName.ToLower() == "MSSQLServer".ToLower() || item.DisplayName.ToLower() == "SQLEXPRESS".ToLower())
                            {
                                txtInstanceName.Text = item.Path;
                            }
                            else
                            {
                                txtInstanceName.Text = item.Path + "\\" + item.DisplayName;
                            }

                            using (ManageQueryOleDBSDKHelper helper = new ManageQueryOleDBSDKHelper(ManagementGroup))
                            {
                                switch (item.GetClasses()[0].Name)
                                {
                                case "Microsoft.SQLServer.DBEngine":
                                    Databases = helper.GetRelatedObjects(item.Id, "Microsoft.SQLServer.Library", "Microsoft.SQLServer.Database");
                                    break;

                                case "Microsoft.SQLServer.2014.DBEngine":
                                    Databases = helper.GetRelatedObjects(item.Id, "Microsoft.SQLServer.2014.Discovery", "Microsoft.SQLServer.2014.Database");
                                    break;

                                case "Microsoft.SQLServer.2016.DBEngine":
                                    Databases = helper.GetRelatedObjects(item.Id, "Microsoft.SQLServer.2016.Discovery", "Microsoft.SQLServer.2016.Database");
                                    break;

                                default:
                                    break;
                                }

                                cmbDatabase.DataSource    = new BindingSource(Databases, null);
                                cmbDatabase.DisplayMember = "DisplayName";
                                cmbDatabase.ValueMember   = "Id";

                                ManagementPackClass winClass = helper.GetManagementPackClass("Microsoft.Windows.Library", "Microsoft.Windows.Computer");

                                principalName = helper.GetObjectsByName(item.Path, winClass).FirstOrDefault().DisplayName;
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Exsitses the specified mp class.
        /// </summary>
        /// <param name="mpClass">The mp class.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool Exsits(ManagementPackClass mpClass, string criteria)
        {
            var c      = new EnterpriseManagementObjectCriteria(criteria, mpClass);
            var reader = this.EntityObjects.GetObjectReader <PartialMonitoringObject>(c, ObjectQueryOptions.Default);

            return(reader.Any());
        }
示例#25
0
        protected override void BeginProcessing()
        {
            // the base.BeginProcesing must come first as it sets up the enterprisemanagementgroup!
            base.BeginProcessing();
            ManagementPackClass clsAnnouncement = SMHelpers.GetManagementPackClass(ClassTypes.System_Announcement_Item, SMHelpers.GetManagementPack(ManagementPacks.System_AdminItem_Library, _mg), _mg);

            // Compare the string case insenstively
            if (_Priority != null)
            {
                if (String.Compare(_Priority, "low", true) == 0)
                {
                    enumPriority = SMHelpers.GetEnum(Enumerations.System_Announcement_PriorityEnum_Low, _mg);
                }
                else if (String.Compare(_Priority, "critical", true) == 0)
                {
                    enumPriority = SMHelpers.GetEnum(Enumerations.System_Announcement_PriorityEnum_Critical, _mg);
                }
                else if (String.Compare(_Priority, "medium", true) == 0)
                {
                    enumPriority = SMHelpers.GetEnum(Enumerations.System_Announcement_PriorityEnum_Medium, _mg);
                }
                else
                {
                    ThrowTerminatingError(new ErrorRecord(new ArgumentException("Priority"), "Priority must be low/medium/critical", ErrorCategory.InvalidOperation, _Priority));
                }
            }
        }
示例#26
0
        //Get property for passed emoUser
        public string GetProperty(
            ref EnterpriseManagementGroup emg,
            EnterpriseManagementObject emoIncident,
            ref ManagementPackClass mpcADUser,
            string sProperty
            )
        {
            try
            {
                //Assigned to user relationship Guid
                Guid rel = new Guid("15e577a3-6bf9-6713-4eac-ba5a5b7c4722");

                EnterpriseManagementObject emoAssignedToUser = null;

                foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> obj in
                         emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(emoIncident.Id, TraversalDepth.OneLevel, ObjectQueryOptions.Default))
                {
                    if (obj.RelationshipId == rel)
                    {
                        emoAssignedToUser = obj.TargetObject;
                    }
                }
                return("" + emoAssignedToUser[mpcADUser, sProperty].Value);
            }
            catch
            {
                return("no-one");
            }
        }
示例#27
0
        private static void CreateUpdateNotificationRule(ManagementPackClass mpc, string strMPAlias, ManagementPackProperty mpp, ref ManagementPack mp, EnterpriseManagementObject emoUser, ManagementPackObjectTemplate mpot, EnterpriseManagementGroup emg)
        {
            string strRuleDisplayName = String.Format("{0}: Update: {1}", mpc.DisplayName, mpp.DisplayName);
            string strCriteria        = ConstructUpdateCriteria(strMPAlias, mpc, mpp);

            Helper.CreateNotificationRule(strRuleDisplayName, Helper.MakeMPElementSafeName(strRuleDisplayName), strCriteria, emoUser, mpc, mpot, ref mp, emg);
        }
示例#28
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="SyncFailoverGroupKey"></param>
        /// <param name="PartitionName"></param>
        public Partition(string SyncFailoverGroupKey, string PartitionName)
        {
            // Create Partition Management Pack Class
            ManagementPackClass mpc_Partition = SCOM.GetManagementPackClass("AP.F5.LTM.Partition");

            // Create New NetworkInterface Object
            SCOM_Object = new CreatableEnterpriseManagementObject(SCOM.m_managementGroup, mpc_Partition);

            // Create Root Entity Class & Key Property
            ManagementPackClass    mpc_Entity            = SCOM.GetManagementPackClass("System.Entity");
            ManagementPackProperty mpp_EntityDisplayName = mpc_Entity.PropertyCollection["DisplayName"];

            SCOM_Object[mpp_EntityDisplayName].Value = PartitionName;

            // Create SyncFailoverGroup Management Pack Class & Key Property
            ManagementPackClass    mpc_SyncFailoverGroup    = SCOM.GetManagementPackClass("AP.F5.LTM.SyncFailoverGroup");
            ManagementPackProperty mpp_SyncFailoverGroupKey = mpc_SyncFailoverGroup.PropertyCollection["Key"];

            SCOM_Object[mpp_SyncFailoverGroupKey].Value = SyncFailoverGroupKey;

            // Create Properties of Partition
            ManagementPackProperty mpp_PartitionName = mpc_Partition.PropertyCollection["Name"];

            SCOM_Object[mpp_PartitionName].Value = PartitionName;
        }
 /// <summary>
 /// This constructor is for unhosted objects managed by specific instance of defined Action Point class OR for hosted objects, which are hosted on defined Action Point class.
 /// </summary>
 /// <param name="managementGroup"></param>
 /// <param name="seedClass"></param>
 /// <param name="actionPointClassName"></param>
 /// <param name="insertConnector"></param>
 public SCOMClassInstanceEditor(ManagementGroup managementGroup, ManagementPackClass seedClass, ManagementPackClass actionPointClass, MonitoringConnector insertConnector, ManagementPackRelationship hostingRelationship = null)
 {
     myActionPointClass = actionPointClass;
     if (seedClass.Hosted)
     {
         relMAPShouldManageEntity = null;
         relMAPManagesEntity      = null;
         relHosting = hostingRelationship ?? managementGroup.EntityTypes.GetRelationshipClass(SystemId.HostingRelationshipId);
     }
     else
     {
         relHosting = null;
         if (actionPointClass.IsSubtypeOf(managementGroup.EntityTypes.GetClass(SystemCenterId.ManagementActionPointClassId)) || actionPointClass.Id == SystemCenterId.ManagementActionPointClassId)
         {
             relMAPShouldManageEntity = managementGroup.EntityTypes.GetRelationshipClass(SystemCenterId.ManagementActionPointShouldManageEntityRelationshipId);
         }
         else if (actionPointClass.IsSubtypeOf(managementGroup.EntityTypes.GetClass(SystemCenterId.HealthServiceClassId)) || actionPointClass.Id == SystemCenterId.HealthServiceClassId)
         {
             relHSShouldManageEntiry = managementGroup.EntityTypes.GetRelationshipClass(SystemCenterId.HealthServiceShouldManageEntityRelationshipId);
         }
         else
         {
             throw new NotSupportedException("For unhosted scenario, action point class should be either Microsoft.SystemCenter.ManagementActionPoint or Microsoft.SystemCenter.HealthService, or inherited from these classes.");
         }
         relMAPManagesEntity = managementGroup.EntityTypes.GetRelationshipClass(SystemCenterId.ManagementActionPointManagesEntityRelationshipId);
     }
     myActionPoints = new List <MonitoringObject>();
     myActionPoints.AddRange(managementGroup.EntityObjects.GetObjectReader <MonitoringObject>(myActionPointClass, ObjectQueryOptions.Default));
     DefaultConstructor(managementGroup, seedClass, insertConnector);
 }
        protected override ICollection <ComputerInstance> DoQuery(string criteria)
        {
            if (ManagementGroup == null || !ManagementGroup.IsConnected)
            {
                Dbg.Log("ComputerInstanceQuery - DoQuery - Management Group is not connected.");
                return(null);
            }

            ManagementPackClass windowsComputerCalss = ManagementGroup.EntityTypes.GetClass(new Guid("ea99500d-8d52-fc52-b5a5-10dcd1e9d2bd")); // Microsoft.Windows.Computer

            if (string.IsNullOrEmpty(criteria))
            {
                Collection <ComputerInstance> result = new Collection <ComputerInstance>();
                foreach (MonitoringObject wc in ManagementGroup.EntityObjects.GetObjectReader <MonitoringObject>(windowsComputerCalss, ObjectQueryOptions.Default))
                {
                    result.Add(new ComputerInstance(wc));
                }
                Dbg.Log($"ComputerInstanceQuery - DoQuery - Returning {result.Count} instances from no criteria search.");
                return(result);
            }
            else
            {
                Collection <ComputerInstance> result = new Collection <ComputerInstance>();
                foreach (MonitoringObject wc in ManagementGroup.EntityObjects.GetObjectReader <MonitoringObject>(new EnterpriseManagementObjectCriteria(criteria, windowsComputerCalss), ObjectQueryOptions.Default))
                {
                    result.Add(new ComputerInstance(wc));
                }
                Dbg.Log($"ComputerInstanceQuery - DoQuery - Returning {result.Count} instances from criteria search.");
                return(result);
            }
        }
        //---------------------------------------------------------------------
        public OverrideTargetEditor(
            ManagementGroup             managementGroup,
            ManagementPackClass         managementPackClass,
            Guid?                       overrideContextInstance
            )
        {
            InitializeComponent();

            m_managementGroup           = managementGroup;
            m_managementPackClass       = managementPackClass;
            m_overrideContextInstance   = overrideContextInstance;
            m_isContextCurrentlyGroup   = false;
        }
示例#32
0
 //---------------------------------------------------------------------
 internal MPClass(ManagementPackClass mpClass)
 {
     m_mpClass           = mpClass;
     m_mpWorkflows       = new Dictionary<Guid, MPWorkflow>();
 }
 public IEnumerable<ManagementPackProperty> GetActivityPropertyDefinitions(ManagementPackClass c)
 {
     if (c.Id != ActivityClass.Id && c.GetBaseTypes().FirstOrDefault(x => x.Id == ActivityClass.Id) == default(ManagementPackType))
         throw new InvalidOperationException("Activity type is not deriven from 'PurgarNET.AAConnector.RunbookActivity'");
     return c.GetProperties();
 }
示例#34
0
        //---------------------------------------------------------------------
        internal void AddOverride(
            ManagementPackClass             mpClass,
            ManagementPackElement           overridenElement,
            ManagementPackOverride          mpOverride
            )
        {
            Debug.Assert(mpClass != null);
            Debug.Assert(overridenElement != null);
            Debug.Assert(mpOverride != null);

            if (!m_classCollection.ContainsKey(mpClass.Id))
            {
                m_classCollection.Add(mpClass.Id, new MPClass(mpClass));
            }

            m_classCollection[mpClass.Id].AddOverride(mpOverride, overridenElement);
        }