public static MRSHealthCheckOutcome VerifyServiceIsUp(string serverName, string fqdn, TestMRSHealth testMRSCmdlet = null) { MRSHealthCheckOutcome result; try { using (ManagementObject serviceObject = WmiWrapper.GetServiceObject(fqdn, "MSExchangeMailboxReplication")) { if (serviceObject == null) { if (testMRSCmdlet != null) { testMRSCmdlet.MonitoringData.Events.Add(new MonitoringEvent("MSExchange Monitoring MRSHealth", 1001, EventTypeEnumeration.Error, Strings.MailboxReplicationServiceNotInstalled)); } result = new MRSHealthCheckOutcome(serverName, MRSHealthCheckId.ServiceCheck, false, Strings.MailboxReplicationServiceNotInstalled); } else if (!StringComparer.InvariantCultureIgnoreCase.Equals(serviceObject["State"] as string, "Running")) { if (testMRSCmdlet != null) { testMRSCmdlet.MonitoringData.Events.Add(new MonitoringEvent("MSExchange Monitoring MRSHealth", 1001, EventTypeEnumeration.Error, Strings.MailboxReplicationServiceNotRunning)); } result = new MRSHealthCheckOutcome(serverName, MRSHealthCheckId.ServiceCheck, false, Strings.MailboxReplicationServiceNotRunning); } else { result = new MRSHealthCheckOutcome(serverName, MRSHealthCheckId.ServiceCheck, true, Strings.MailboxReplicationServiceIsRunning); } } } catch (WmiException ex) { ServiceHealthWmiFailureException ex2 = new ServiceHealthWmiFailureException(ex.Message, ex); if (testMRSCmdlet != null) { testMRSCmdlet.WriteErrorAndMonitoringEvent(ex2, ErrorCategory.ReadError, 1001); } result = new MRSHealthCheckOutcome(serverName, MRSHealthCheckId.ServiceCheck, false, CommonUtils.FullExceptionMessage(ex2, true)); } return(result); }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); try { Dictionary <ServerRole, List <string> > dictionary = new Dictionary <ServerRole, List <string> >(); Dictionary <ServerRole, List <string> > dictionary2 = new Dictionary <ServerRole, List <string> >(); foreach (TestServiceHealth.MonitoredService monitoredService in this.monitoredServicesArray) { if ((monitoredService.Roles & this.serverRolesBitfield) != ServerRole.None) { try { using (ManagementObject serviceObject = WmiWrapper.GetServiceObject(this.serverName, monitoredService.Name)) { if (serviceObject != null) { string strA = serviceObject["State"] as string; if (string.Compare(strA, "Running", true, CultureInfo.InvariantCulture) == 0) { using (List <ServerRole> .Enumerator enumerator = this.serverRolesList.GetEnumerator()) { while (enumerator.MoveNext()) { ServerRole serverRole = enumerator.Current; if ((monitoredService.Roles & serverRole) != ServerRole.None) { List <string> list = null; if (!dictionary2.TryGetValue(serverRole, out list)) { list = new List <string>(); dictionary2[serverRole] = list; } list.Add(monitoredService.Name); } } goto IL_18C; } } string strA2 = serviceObject["StartMode"] as string; if (string.Compare(strA2, "Auto", true, CultureInfo.InvariantCulture) == 0 || monitoredService.IsRequired) { foreach (ServerRole serverRole2 in this.serverRolesList) { if ((serverRole2 & monitoredService.Roles) != ServerRole.None) { List <string> list2 = null; if (!dictionary.TryGetValue(serverRole2, out list2)) { list2 = new List <string>(); dictionary[serverRole2] = list2; } list2.Add(monitoredService.Name); } } } IL_18C :; } } } catch (WmiException ex) { ServiceHealthWmiFailureException exception = new ServiceHealthWmiFailureException(ex.Message, ex); base.WriteError(exception, ErrorCategory.ReadError, null); } } } foreach (ServerRole serverRole3 in this.serverRolesList) { List <string> list3 = null; List <string> list4 = null; string[] servicesRunning; if (dictionary2.TryGetValue(serverRole3, out list3)) { servicesRunning = list3.ToArray(); } else { servicesRunning = new string[0]; } ExchangeServicesStatus sendToPipeline; if (dictionary.TryGetValue(serverRole3, out list4)) { string[] array2 = list4.ToArray(); this.monitoringData.Events.Add(new MonitoringEvent("MSExchange Monitoring ServiceHealth", (int)(11000 + serverRole3), EventTypeEnumeration.Error, Strings.SomeEssentialServicesForTheRoleNotRunning(MpServerRoles.DisplayRoleName(serverRole3), string.Join("\n", array2)))); sendToPipeline = new ExchangeServicesStatus(serverRole3, false, array2, servicesRunning); } else { this.monitoringData.Events.Add(new MonitoringEvent("MSExchange Monitoring ServiceHealth", (int)(12000 + serverRole3), EventTypeEnumeration.Information, Strings.AllEssentialServicesForTheRoleRunning(MpServerRoles.DisplayRoleName(serverRole3)))); sendToPipeline = new ExchangeServicesStatus(serverRole3, true, new string[0], servicesRunning); } base.WriteObject(sendToPipeline); } this.monitoringData.Events.Add(new MonitoringEvent("MSExchange Monitoring ServiceHealth", 10000, EventTypeEnumeration.Information, Strings.NoMonitoringErrorsInTestServiceHealthTask)); } finally { if (this.MonitoringContext) { base.WriteObject(this.monitoringData); } TaskLogger.LogExit(); } }