Exemple #1
0
        internal string RunTestTask(string connectionString, string query)
        {
            ManagementPackClass AllManagementServersPoolClass =
                GetManagementPackClass("Microsoft.SystemCenter.Library", "Microsoft.SystemCenter.AllManagementServersPool");

            IObjectReader <MonitoringObject> Targets = managementGroup.EntityObjects.GetObjectReader <MonitoringObject>(AllManagementServersPoolClass, ObjectQueryOptions.Default);
            EnterpriseManagementObject       Target  = Targets.First();
            // Get the task.
            string TaskQuery = "Name = 'QueryOleDbMonitorTemplate.OLEDBMontiorTESTTask'";
            ManagementPackTaskCriteria taskCriteria = new ManagementPackTaskCriteria(TaskQuery);

            IList <ManagementPackTask> tasks = managementGroup.TaskConfiguration.GetTasks(taskCriteria);
            ManagementPackTask         task  = null;

            if (tasks.Count == 1)
            {
                task = tasks[0];
            }
            else
            {
                throw new InvalidOperationException(
                          "Error! Expected one task with: " + query);
            }

            // Use the default task configuration.
            Microsoft.EnterpriseManagement.Runtime.TaskConfiguration config =
                new Microsoft.EnterpriseManagement.Runtime.TaskConfiguration();

            //Get OleDbTriggerProbe module to override paramters
            ManagementPackModuleType OleDbTriggerProbeMoudule =
                managementGroup.Monitoring.GetModuleType("System.OleDbTriggerProbe", managementGroup.ManagementPacks.GetManagementPack(SystemManagementPack.System));

            ManagementPackOverrideableParameter overrideConnecionStringParam = OleDbTriggerProbeMoudule.OverrideableParameterCollection["ConnectionString"];
            ManagementPackOverrideableParameter overrideQueryParam           = OleDbTriggerProbeMoudule.OverrideableParameterCollection["Query"];


            config.Overrides.Add(new Pair <ManagementPackOverrideableParameter, string>(overrideConnecionStringParam,
                                                                                        connectionString
                                                                                        ));
            config.Overrides.Add(new Pair <ManagementPackOverrideableParameter, string>(overrideQueryParam,
                                                                                        query
                                                                                        ));

            //execute task

            IList <Microsoft.EnterpriseManagement.Runtime.TaskResult> result = managementGroup.TaskRuntime.ExecuteTask(Target, task, config);
            XmlDocument xd = new XmlDocument();

            xd.LoadXml(result[0].Output);
            TestReportFactory reportTestFactory = new TestReportFactory();

            return(GetTestResult(xd, reportTestFactory).UiText());
        }
        private void PerformRelationshipCleanup(ManagementPackClass mySeedClass, CreatableEnterpriseManagementObject newSeedInstance, MonitoringObject monitoringObject)
        {
            // it's so complex, because the new instance may not exist
            EnterpriseManagementObject realSeedInstance;
            string criteriaString = "";

            foreach (ManagementPackProperty property in newSeedInstance.GetProperties())
            {
                if (property.Key)
                {
                    if (criteriaString == "")
                    {
                        criteriaString = property.Name + "='" + newSeedInstance[property] + "'";
                    }
                    else
                    {
                        criteriaString += " AND " + property.Name + "='" + newSeedInstance[property] + "'";
                    }
                }
            }
            EnterpriseManagementObjectCriteria         searchQuery          = new EnterpriseManagementObjectCriteria(criteriaString, mySeedClass);
            IObjectReader <EnterpriseManagementObject> realSeedInstanceList = myMG.EntityObjects.GetObjectReader <EnterpriseManagementObject>(searchQuery, ObjectQueryOptions.Default);

            if (realSeedInstanceList.Count == 0)
            {
                return;
            }
            else
            {
                realSeedInstance = realSeedInstanceList.First();
            }

            IncrementalDiscoveryData RemovalDiscovery = new IncrementalDiscoveryData();
            // Management Point
            bool commitOverwrite = false;
            IEnumerable <EnterpriseManagementRelationshipObject <EnterpriseManagementObject> > allMAPRelations = myMG.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(realSeedInstance.Id, relToClearMAP, DerivedClassTraversalDepth.Recursive, TraversalDepth.OneLevel, ObjectQueryOptions.Default).Where(x => !x.IsDeleted);
            IEnumerable <EnterpriseManagementRelationshipObject <EnterpriseManagementObject> > allHSRelations  = myMG.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(realSeedInstance.Id, relToClearHS, DerivedClassTraversalDepth.Recursive, TraversalDepth.OneLevel, ObjectQueryOptions.Default).Where(x => !x.IsDeleted);

            foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> rel in allMAPRelations)
            {
                if (rel.SourceObject.Id != monitoringObject.Id)
                {
                    // remove this relationship
                    RemovalDiscovery.Remove(rel);
                    commitOverwrite = true;
                }
            }
            foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> rel in allHSRelations)
            {
                if (rel.SourceObject.Id != monitoringObject.Id)
                {
                    // remove this relationship
                    RemovalDiscovery.Remove(rel);
                    commitOverwrite = true;
                }
            }
            if (commitOverwrite)
            {
                RemovalDiscovery.Overwrite(myConnector);
            }
        }
        static void Main(string[] args)
        {
            string strServerName                 = args[0];
            string strWorkItemTypeToCreate       = args[1];
            int    intIncidnetsPerDay            = Int32.Parse(args[2]);
            int    intIncidnetsToCreate          = Int32.Parse(args[3]);
            int    intChangeRequestsPerDay       = Int32.Parse(args[4]);
            int    intChangeRequestsToCreate     = Int32.Parse(args[5]);
            int    intServiceRequestsPerDay      = Int32.Parse(args[6]);
            int    intServiceRequestsToCreate    = Int32.Parse(args[7]);
            int    intProblemsPerDay             = Int32.Parse(args[8]);
            int    intProblemsToCreate           = Int32.Parse(args[9]);
            int    intReleasesPerDay             = Int32.Parse(args[10]);
            int    intReleasesToCreate           = Int32.Parse(args[11]);
            int    intNumberOfWorkingHoursPerDay = Int32.Parse(args[12]);

            intRateOfWorkItemQueryAndUpdates = Int32.Parse(args[13]);
            intDoWorkPause            = Int32.Parse(args[14]);
            intNumberOfWorkItemsToGet = Int32.Parse(args[15]);

            DateTime dtCreatingManagementGroupStart = DateTime.Now;

            emg = new EnterpriseManagementGroup(strServerName);
            DateTime dtCreatingManagementGroupEnd = DateTime.Now;
            TimeSpan tsCreatingManagementGroup    = dtCreatingManagementGroupEnd - dtCreatingManagementGroupStart;

            pcManagementGroupCreate.RawValue = (long)tsCreatingManagementGroup.TotalSeconds;
            Console.WriteLine(String.Format("Process user: {0}\\{1}", Environment.UserDomainName, Environment.UserName));
            Console.WriteLine("Creating Management Group (seconds): " + tsCreatingManagementGroup.TotalSeconds);

            //For debugging so you can catch the process and put it in the debugger
            //Console.WriteLine("Sleeping for 10 seconds");
            //Thread.Sleep(10000);

            DateTime dtCachingStart = DateTime.Now;

            //Get the current user and the user's associated group enum
            strUserName       = Environment.UserName;
            strUserDomainName = Environment.UserDomainName;
            mpcUser           = Helper.GetClassByName("System.Domain.User", emg);
            EnterpriseManagementObjectCriteria         emocUser = new EnterpriseManagementObjectCriteria(String.Format("UserName = '******' AND Domain ='{1}'", strUserName, strUserDomainName), mpcUser);
            IObjectReader <EnterpriseManagementObject> orUser   = emg.EntityObjects.GetObjectReader <EnterpriseManagementObject>(emocUser, ObjectQueryOptions.Default);

            if (orUser.Count > 0)
            {
                emoUser = orUser.First <EnterpriseManagementObject>();
            }
            else
            {
                Console.WriteLine(String.Format("Logged in user: {0}\\{1} doesnt exist in the SCSM database.", strUserDomainName, strUserName));
            }

            //Classes
            mpcIncident                = Helper.GetClassByName("System.WorkItem.Incident", emg);
            mpcAnalystComment          = Helper.GetClassByName("System.WorkItem.TroubleTicket.AnalystCommentLog", emg);
            mpcChangeRequest           = Helper.GetClassByName("System.WorkItem.ChangeRequest", emg);
            mpcServiceRequest          = Helper.GetClassByName("System.WorkItem.ServiceRequest", emg);
            mpcProblem                 = Helper.GetClassByName("System.WorkItem.Problem", emg);
            mpcComputer                = Helper.GetClassByName("Microsoft.Windows.Computer", emg);
            mpcChangeRequestExtension  = Helper.GetClassByName(Constants.CLASS_CHANGEREQUEST_EXTENSION, emg);
            mpcProblemExtension        = Helper.GetClassByName(Constants.CLASS_PROBLEM_EXTENSION, emg);
            mpcServiceRequestExtension = Helper.GetClassByName(Constants.CLASS_SERVICEREQUEST_EXTENSION, emg);

            //Type Projections
            mptpIncidentView       = Helper.GetTypeProjectionByName("System.WorkItem.Incident.View.ProjectionType", emg);
            mptpIncidentFull       = Helper.GetTypeProjectionByName("System.WorkItem.Incident.ProjectionType", emg);
            mptpChangeRequestView  = Helper.GetTypeProjectionByName("System.WorkItem.ChangeRequestViewProjection", emg);
            mptpChangeRequestFull  = Helper.GetTypeProjectionByName("System.WorkItem.ChangeRequestProjection", emg);
            mptpServiceRequestView = Helper.GetTypeProjectionByName("System.WorkItem.ServiceRequestViewProjection", emg);
            mptpServiceRequestFull = Helper.GetTypeProjectionByName("System.WorkItem.ServiceRequestProjection", emg);
            mptpProblemView        = Helper.GetTypeProjectionByName("System.WorkItem.ProblemViewProjection", emg);
            mptpProblemFull        = Helper.GetTypeProjectionByName("System.WorkItem.Problem.ProjectionType", emg);

            //Relationships
            mprAnalystComment         = Helper.GetRelationshipByName("System.WorkItem.TroubleTicketHasAnalystComment", emg);
            mprWorkItemAssignedToUser = Helper.GetRelationshipByName("System.WorkItemAssignedToUser", emg);
            mprAffectedCI             = Helper.GetRelationshipByName("System.WorkItemAboutConfigItem", emg);
            mprRelatedCI = Helper.GetRelationshipByName("System.WorkItemRelatesToConfigItem", emg);

            //Management Packs
            mpSystemWorkItemLibrary = Helper.GetManagementPackByName("System.WorkItem.Library", emg);
            mpIncidentLibrary       = Helper.GetManagementPackByName("System.WorkItem.Incident.Library", emg);
            mpServiceRequestLibrary = Helper.GetManagementPackByName("System.WorkItem.ServiceRequest.Library", emg);
            mpChangeRequestLibrary  = Helper.GetManagementPackByName("System.WorkItem.ChangeRequest.Library", emg);
            mpProblemLibrary        = Helper.GetManagementPackByName("System.WorkItem.Problem.Library", emg);

            //Properties
            mppIncidentClassification = Helper.GetManagementPackClassPropertyByName("System.WorkItem.Incident", "Classification", emg);
            mppServiceRequestArea     = Helper.GetManagementPackClassPropertyByName("System.WorkItem.ServiceRequest", "Area", emg);
            mppChangeRequestArea      = Helper.GetManagementPackClassPropertyByName("System.WorkItem.ChangeRequest", "Area", emg);
            mppProblemClassification  = Helper.GetManagementPackClassPropertyByName("System.WorkItem.Problem", "Classification", emg);

            ManagementPackEnumeration mpeSRAreaBase = Helper.GetEnumerationByName("ServiceRequestAreaEnum", emg);
            ManagementPackEnumeration mpeCRAreaBase = Helper.GetEnumerationByName("ChangeAreaEnum", emg);
            ManagementPackEnumeration mpeProblemClassificationBase  = Helper.GetEnumerationByName("ProblemClassificationEnum", emg);
            ManagementPackEnumeration mpeIncidentClassificationBase = Helper.GetEnumerationByName("IncidentClassificationEnum", emg);

            listSRAreaEnums = emg.EntityTypes.GetChildEnumerations(mpeSRAreaBase.Id, TraversalDepth.Recursive);
            listCRAreaEnums = emg.EntityTypes.GetChildEnumerations(mpeCRAreaBase.Id, TraversalDepth.Recursive);
            listProblemClassificationEnums  = emg.EntityTypes.GetChildEnumerations(mpeProblemClassificationBase.Id, TraversalDepth.Recursive);
            listIncidentClassificationEnums = emg.EntityTypes.GetChildEnumerations(mpeIncidentClassificationBase.Id, TraversalDepth.Recursive);

            DateTime dtCachingEnd = DateTime.Now;
            TimeSpan tsCaching    = dtCachingEnd - dtCachingStart;

            pcCaching.RawValue = (long)tsCaching.TotalSeconds;
            Console.WriteLine("Caching (seconds): " + tsCaching.TotalSeconds);

            Console.WriteLine("Worker work item class to create: " + strWorkItemTypeToCreate);
            switch (strWorkItemTypeToCreate)
            {
            case "Incident":
                CreateIncidents(intIncidnetsToCreate, intIncidnetsPerDay, intNumberOfWorkingHoursPerDay);
                break;

            case "ChangeRequest":
                CreateChangeRequests(intChangeRequestsToCreate, intChangeRequestsPerDay, intNumberOfWorkingHoursPerDay);
                break;

            case "ServiceRequest":
                CreateServiceRequests(intServiceRequestsToCreate, intServiceRequestsPerDay, intNumberOfWorkingHoursPerDay);
                break;

            case "Problem":
                CreateProblems(intProblemsToCreate, intProblemsPerDay, intNumberOfWorkingHoursPerDay);
                break;

            case "Release":
                CreateReleases(intReleasesToCreate, intReleasesPerDay, intNumberOfWorkingHoursPerDay);
                break;

            default:
                break;
            }

            System.Timers.Timer timerWorkItemQueryUpdate = new System.Timers.Timer((double)intRateOfWorkItemQueryAndUpdates);
            timerWorkItemQueryUpdate.Elapsed += new ElapsedEventHandler(WorkItemQueryUpdate);
            timerWorkItemQueryUpdate.Enabled  = true;

            while (Console.Read() != 'q')
            {
                ;
            }
        }