private bool CheckLocalServerRegistryRoles()
        {
            bool result;

            try
            {
                base.WriteVerbose(Strings.ReadingE14ServerRoles(this.m_serverName));
                this.m_serverRolesBitfield = MpServerRoles.GetLocalE12ServerRolesFromRegistry();
                if ((this.m_serverRolesBitfield & ServerRole.Mailbox) != ServerRole.Mailbox)
                {
                    this.WriteErrorAndMonitoringEvent(new NoMailboxRoleInstalledException(this.m_serverName), ErrorCategory.NotInstalled, null, 10002, "MSExchange Monitoring ReplicationHealth");
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                CannotReadRolesFromRegistryException exception = new CannotReadRolesFromRegistryException(ex.Message);
                this.WriteErrorAndMonitoringEvent(exception, ErrorCategory.PermissionDenied, null, 10001, "MSExchange Monitoring ReplicationHealth");
                result = false;
            }
            catch (SecurityException ex2)
            {
                CannotReadRolesFromRegistryException exception2 = new CannotReadRolesFromRegistryException(ex2.Message);
                this.WriteErrorAndMonitoringEvent(exception2, ErrorCategory.PermissionDenied, null, 10001, "MSExchange Monitoring ReplicationHealth");
                result = false;
            }
            return(result);
        }
 internal ExchangeServicesStatus(ServerRole roleBitfiedFlag, bool requiredServicesRunning, string[] servicesNotRunning, string[] servicesRunning) : base(new SimpleProviderPropertyBag())
 {
     if (servicesNotRunning == null)
     {
         throw new ArgumentNullException("servicesNotRunning");
     }
     if (servicesRunning == null)
     {
         throw new ArgumentNullException("servicesRunning");
     }
     this.Role = MpServerRoles.DisplayRoleName(roleBitfiedFlag);
     this.RequiredServicesRunning = requiredServicesRunning;
     this.ServicesNotRunning      = new MultiValuedProperty <string>(servicesNotRunning);
     this.ServicesRunning         = new MultiValuedProperty <string>(servicesRunning);
 }
Ejemplo n.º 3
0
 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();
     }
 }
Ejemplo n.º 4
0
 protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     try
     {
         IEnumerable <TestServiceHealth.MonitoredService> source;
         if (Datacenter.IsMultiTenancyEnabled())
         {
             source = TestServiceHealth.DefaultMonitoredServicesList;
         }
         else
         {
             source = TestServiceHealth.DefaultMonitoredServicesList.Concat(new TestServiceHealth.MonitoredService[]
             {
                 new TestServiceHealth.MonitoredService("MSExchangeEdgeSync", false, true, ServerRole.HubTransport | ServerRole.Edge)
             });
         }
         source = from monitoredService in source
                  orderby monitoredService
                  select monitoredService;
         this.monitoredServicesArray = source.ToArray <TestServiceHealth.MonitoredService>();
         if (this.Server == null)
         {
             this.serverName = NativeHelpers.GetLocalComputerFqdn(false);
             try
             {
                 this.serverRolesBitfield = MpServerRoles.GetLocalE12ServerRolesFromRegistry();
                 goto IL_1AF;
             }
             catch (SecurityException ex)
             {
                 CannotReadRolesFromRegistryException exception = new CannotReadRolesFromRegistryException(ex.Message);
                 this.WriteErrorAndMonitoringEvent(exception, ErrorCategory.PermissionDenied, null, 10003, "MSExchange Monitoring ServiceHealth");
                 return;
             }
         }
         IConfigurationSession configurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(this.DomainController, true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 708, "InternalValidate", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Monitoring\\Tasks\\TestServiceHealth.cs");
         configurationSession.ServerTimeout = new TimeSpan?(TimeSpan.FromSeconds((double)this.ActiveDirectoryTimeout));
         IEnumerable <Server> objects    = this.Server.GetObjects <Server>(null, configurationSession);
         IEnumerator <Server> enumerator = objects.GetEnumerator();
         Server server = null;
         if (enumerator.MoveNext())
         {
             server = enumerator.Current;
         }
         if (server == null || enumerator.MoveNext())
         {
             CannotLocateServerException exception2;
             if (server == null)
             {
                 exception2 = new CannotLocateServerException(Strings.ErrorServerNotFound(this.Server.ToString()));
             }
             else
             {
                 exception2 = new CannotLocateServerException(Strings.ErrorServerNotUnique(this.Server.ToString()));
             }
             this.WriteErrorAndMonitoringEvent(exception2, ErrorCategory.InvalidData, null, 10007, "MSExchange Monitoring ServiceHealth");
             return;
         }
         this.serverName          = server.Fqdn;
         this.serverRolesBitfield = server.CurrentServerRole;
         IL_1AF:
         this.serverRolesList = new List <ServerRole>(MpServerRoles.ValidE12MpRoles.Length);
         foreach (ServerRole serverRole in MpServerRoles.ValidE12MpRoles)
         {
             if ((serverRole & this.serverRolesBitfield) != ServerRole.None)
             {
                 this.serverRolesList.Add(serverRole);
             }
         }
         if (!base.HasErrors && this.serverRolesList.Count < 1)
         {
             NoExchangeRoleInstalledException exception3 = new NoExchangeRoleInstalledException(this.serverName);
             this.WriteErrorAndMonitoringEvent(exception3, ErrorCategory.InvalidArgument, null, 10007, "MSExchange Monitoring ServiceHealth");
         }
     }
     finally
     {
         if (base.HasErrors && this.MonitoringContext)
         {
             base.WriteObject(this.monitoringData);
         }
         TaskLogger.LogExit();
     }
 }