Esempio n. 1
0
 public void CheckHealthStateAndRespond(HttpContext httpContext)
 {
     if (!HealthCheckResponder.HealthCheckResponderEnabled.Value)
     {
         this.RespondSuccess(httpContext);
     }
     else
     {
         ServerComponentEnum serverComponent = ServerComponentEnum.None;
         if (!HealthCheckResponder.ProtocolServerComponentMap.TryGetValue(HttpProxyGlobals.ProtocolType, out serverComponent))
         {
             throw new InvalidOperationException("Unknown protocol type " + HttpProxyGlobals.ProtocolType);
         }
         if (HealthCheckResponder.HealthCheckResponderServerComponentOverride.Value != ServerComponentEnum.None)
         {
             serverComponent = HealthCheckResponder.HealthCheckResponderServerComponentOverride.Value;
         }
         DateTime utcNow = DateTime.UtcNow;
         if (this.componentStateNextLookupTime <= utcNow)
         {
             this.isComponentOnline            = ServerComponentStateManager.IsOnline(serverComponent);
             this.componentStateNextLookupTime = utcNow.AddSeconds(15.0);
         }
         if (!this.isComponentOnline)
         {
             this.RespondFailure(httpContext);
         }
         else
         {
             this.RespondSuccess(httpContext);
         }
     }
     httpContext.ApplicationInstance.CompleteRequest();
 }
Esempio n. 2
0
        protected override void InternalValidate()
        {
            base.InternalValidate();
            if (base.ProvisioningHandlers != null)
            {
                foreach (ProvisioningHandler provisioningHandler in base.ProvisioningHandlers)
                {
                    provisioningHandler.Validate(this.serverObject);
                }
            }
            if (!ServerComponentStateManager.IsValidComponent(this.Component))
            {
                base.WriteError(new ArgumentException(Strings.ServerComponentStateInvalidComponentName(this.Component)), ErrorCategory.InvalidArgument, null);
            }
            if (this.LocalOnly)
            {
                ServerComponentEnum serverComponentEnum;
                Enum.TryParse <ServerComponentEnum>(this.Component, true, out serverComponentEnum);
                if (serverComponentEnum == ServerComponentEnum.Monitoring || serverComponentEnum == ServerComponentEnum.RecoveryActionsEnabled)
                {
                    base.WriteError(new ArgumentException(Strings.ServerComponentStateNoLocalOnly(this.Component)), ErrorCategory.InvalidArgument, null);
                }
            }
            ServerComponentRequest serverComponentRequest;

            if (!Enum.TryParse <ServerComponentRequest>(this.Requester, true, out serverComponentRequest))
            {
                string allowedRequesters = string.Join(",", Enum.GetNames(typeof(ServerComponentRequest)));
                base.WriteError(new ArgumentException(Strings.ServerComponentStateInvalidRequester(this.Requester, allowedRequesters)), ErrorCategory.InvalidArgument, null);
            }
            if (this.LocalOnly && this.RemoteOnly)
            {
                base.WriteError(new ArgumentException(Strings.SetServerComponentStateInvalidLocalRemoteSwitch), ErrorCategory.InvalidArgument, null);
            }
        }
 protected override void InternalValidate()
 {
     base.InternalValidate();
     if (this.Component != null && !ServerComponentStateManager.IsValidComponent(this.Component))
     {
         base.WriteError(new ArgumentException(Strings.ServerComponentStateInvalidComponentName(this.Component)), ErrorCategory.InvalidArgument, null);
     }
 }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter(new object[]
            {
                this.serverId,
                this.Component
            });
            ADComputer adcomputer = null;
            ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(this.DomainController, true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 98, "InternalProcessRecord", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\ComponentStates\\GetServerComponentState.cs");
            string text  = (!string.IsNullOrWhiteSpace(this.serverId.Fqdn)) ? this.serverId.Fqdn : this.serverId.ToString();
            string text2 = text;
            int    num   = text.IndexOf('.');

            if (num > 0)
            {
                text2 = text.Substring(0, num);
            }
            Server server = topologyConfigurationSession.FindServerByName(text2);

            if (server == null)
            {
                topologyConfigurationSession.UseConfigNC      = false;
                topologyConfigurationSession.UseGlobalCatalog = true;
                adcomputer = topologyConfigurationSession.FindComputerByHostName(text2);
                if (adcomputer == null)
                {
                    base.WriteError(new ADServerNotFoundException(text), ErrorCategory.InvalidArgument, null);
                }
            }
            if (string.IsNullOrEmpty(this.Component))
            {
                using (IEnumerator enumerator = Enum.GetValues(typeof(ServerComponentEnum)).GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        object obj = enumerator.Current;
                        ServerComponentEnum serverComponent = (ServerComponentEnum)obj;
                        if (ServerComponentStateManager.IsValidComponent(serverComponent))
                        {
                            base.WriteObject(new ServerComponentStatePresentationObject((server != null) ? server.Id : adcomputer.Id, (server != null) ? server.Fqdn : adcomputer.DnsHostName, ServerComponentStateManager.GetComponentId(serverComponent), (server != null) ? server.ComponentStates : adcomputer.ComponentStates));
                        }
                    }
                    goto IL_1B2;
                }
            }
            base.WriteObject(new ServerComponentStatePresentationObject((server != null) ? server.Id : adcomputer.Id, (server != null) ? server.Fqdn : adcomputer.DnsHostName, this.Component, (server != null) ? server.ComponentStates : adcomputer.ComponentStates));
IL_1B2:
            TaskLogger.LogExit();
        }
        public ServerComponentStatePresentationObject(ADObjectId serverId, string serverFqdn, string componentName, MultiValuedProperty <string> componentStates) : base(new SimpleProviderPropertyBag())
        {
            this[SimpleProviderObjectSchema.Identity] = serverId;
            this.ServerFqdn = serverFqdn;
            this.Component  = componentName;
            bool serverWideOfflineIsOffline;
            List <ServerComponentStates.ItemEntry> list;
            List <ServerComponentStates.ItemEntry> list2;

            this.State = ServerComponentStates.ReadEffectiveComponentState(this.ServerFqdn, componentStates, ServerComponentStateSources.All, this.Component, ServerComponentStateManager.GetDefaultState(this.Component), out serverWideOfflineIsOffline, out list, out list2);
            this.ServerWideOfflineIsOffline = serverWideOfflineIsOffline;
            if (list != null)
            {
                this.localStates = new List <ServerComponentStatePresentationObject.RequesterDetails>(list.Count);
                foreach (ServerComponentStates.ItemEntry info in list)
                {
                    this.localStates.Add(new ServerComponentStatePresentationObject.RequesterDetails(info));
                }
            }
            if (list2 != null)
            {
                this.remoteStates = new List <ServerComponentStatePresentationObject.RequesterDetails>(list2.Count);
                foreach (ServerComponentStates.ItemEntry info2 in list2)
                {
                    this.remoteStates.Add(new ServerComponentStatePresentationObject.RequesterDetails(info2));
                }
            }
        }
        // Token: 0x06000010 RID: 16 RVA: 0x000024E8 File Offset: 0x000006E8
        private void Run(string[] args)
        {
            bool   flag  = false;
            bool   flag2 = false;
            bool   flag3 = false;
            bool   flag4 = false;
            string text  = null;
            string name  = null;
            string name2 = null;
            string s     = null;

            foreach (string text2 in args)
            {
                if (text2.StartsWith("-?", StringComparison.OrdinalIgnoreCase))
                {
                    MonitoringWorker.PrintUsageAndExit();
                }
                else if (text2.StartsWith("-console", StringComparison.OrdinalIgnoreCase))
                {
                    flag3 = true;
                }
                else if (text2.StartsWith("-stopkey:", StringComparison.OrdinalIgnoreCase))
                {
                    text = text2.Remove(0, "-stopkey:".Length);
                }
                else if (text2.StartsWith("-hangkey:", StringComparison.OrdinalIgnoreCase))
                {
                    name = text2.Remove(0, "-hangkey:".Length);
                }
                else if (text2.StartsWith("-resetkey:", StringComparison.OrdinalIgnoreCase))
                {
                    text2.Remove(0, "-resetkey:".Length);
                }
                else if (text2.StartsWith("-readykey:", StringComparison.OrdinalIgnoreCase))
                {
                    name2 = text2.Remove(0, "-readykey:".Length);
                }
                else if (text2.StartsWith("-pipe:", StringComparison.OrdinalIgnoreCase))
                {
                    s = text2.Remove(0, "-pipe:".Length);
                }
                else if (text2.StartsWith("-paused", StringComparison.OrdinalIgnoreCase))
                {
                    flag = true;
                }
                else if (text2.StartsWith("-passive", StringComparison.OrdinalIgnoreCase))
                {
                    flag2 = true;
                }
                else if (text2.StartsWith("-wait", StringComparison.OrdinalIgnoreCase))
                {
                    flag4 = true;
                }
            }
            this.serviceControlled = !string.IsNullOrEmpty(text);
            if (!this.serviceControlled)
            {
                if (!flag3)
                {
                    MonitoringWorker.PrintUsageAndExit();
                }
                Console.WriteLine("Starting {0}, running in console mode.", Assembly.GetExecutingAssembly().GetName().Name);
                if (flag4)
                {
                    Console.WriteLine("Press ENTER to continue.");
                    Console.ReadLine();
                }
            }
            this.stopHandle  = MonitoringWorker.OpenSemaphore(text, "stop");
            this.hangHandle  = MonitoringWorker.OpenSemaphore(name, "hang");
            this.readyHandle = MonitoringWorker.OpenSemaphore(name2, "ready");
            if (this.hangHandle != null)
            {
                new Thread(new ThreadStart(this.WaitForHangSignal))
                {
                    IsBackground = true
                }.Start();
            }
            if (CriticalDependencyAlertEscalator.RunningInMicrosoftDatacenter())
            {
                bool   flag5 = true;
                string name3 = "SOFTWARE\\Microsoft\\ExchangeServer\\v15\\ActiveMonitoring\\CriticalDependencyVerification\\";
                using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(name3))
                {
                    if (registryKey != null)
                    {
                        object value = registryKey.GetValue("Enabled");
                        if (value != null && value is int && (int)value == 0)
                        {
                            flag5 = false;
                        }
                    }
                }
                if (flag5)
                {
                    WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Attempting to verify critical dependencies before continuing with initialization.", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 543);
                    CriticalDependencyVerification criticalDependencyVerification = new CriticalDependencyVerification(ExTraceGlobals.CommonComponentsTracer, TracingContext.Default);
                    if (!criticalDependencyVerification.VerifyDependencies())
                    {
                        WTFLogger.Instance.LogError(WTFLog.Core, TracingContext.Default, "Failed to verify one or more critical dependencies. We will try to continue running, but may hang, crash, or exit unexpectedly.", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 551);
                    }
                    else
                    {
                        WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Successfully verified all critical dependencies. Continuing with initialization.", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 555);
                    }
                }
            }
            if (!ServiceTopologyProvider.IsAdTopologyServiceInstalled())
            {
                ADSession.SetAdminTopologyMode();
            }
            Globals.InitializeMultiPerfCounterInstance("ExHMWorker");
            LocalEndpointManager.UseMaintenanceWorkItem = true;
            WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Initializing global override lists", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 573);
            try
            {
                DirectoryAccessor.Instance.LoadGlobalOverrides();
            }
            catch (Exception arg)
            {
                ExTraceGlobals.WorkerTracer.TraceError <Exception>(0L, "Initializing global override lists failed with exception {0}", arg);
            }
            WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Initializing local override lists", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 586);
            LocalOverrideManager.LoadLocalOverrides();
            Settings.RemoveAllOverrides();
            if (MaintenanceDefinition.GlobalOverrides != null)
            {
                foreach (WorkDefinitionOverride o in MaintenanceDefinition.GlobalOverrides)
                {
                    this.ApplyConfigurationOverrideIfNecessary(o);
                }
            }
            if (MaintenanceDefinition.LocalOverrides != null)
            {
                foreach (WorkDefinitionOverride o2 in MaintenanceDefinition.LocalOverrides)
                {
                    this.ApplyConfigurationOverrideIfNecessary(o2);
                }
            }
            Assembly assembly = typeof(LocalEndpointManager).Assembly;

            WorkItemFactory.DefaultAssemblies["Microsoft.Exchange.Monitoring.ActiveMonitoring.Local.Components.dll"] = assembly;
            WorkItemFactory.DefaultAssemblies[assembly.Location] = assembly;
            WorkItemFactory factory = new WorkItemFactory();
            bool            flag6   = true;
            bool            flag7   = true;

            try
            {
                flag6 = ServerComponentStateManager.IsOnline(ServerComponentEnum.Monitoring);
            }
            catch (Exception ex)
            {
                MonitoringWorker.eventLogger.LogEvent(MSExchangeHMEventLogConstants.Tuple_FailedToGetIsOnlineState, null, new object[]
                {
                    MonitoringWorker.processId,
                    ServerComponentEnum.Monitoring.ToString(),
                    flag6.ToString(),
                    ex.ToString()
                });
            }
            try
            {
                flag7 = ServerComponentStateManager.IsOnline(ServerComponentEnum.RecoveryActionsEnabled);
            }
            catch (Exception ex2)
            {
                MonitoringWorker.eventLogger.LogEvent(MSExchangeHMEventLogConstants.Tuple_FailedToGetIsOnlineState, null, new object[]
                {
                    MonitoringWorker.processId,
                    ServerComponentEnum.RecoveryActionsEnabled.ToString(),
                    flag7.ToString(),
                    ex2.ToString()
                });
            }
            if (flag6 && flag7)
            {
                this.activeMonitoringWorker = new Worker(new WorkBroker[]
                {
                    new ProbeWorkBroker <LocalDataAccess>(factory),
                    new MonitorWorkBroker <LocalDataAccess>(factory),
                    new ResponderWorkBroker <LocalDataAccess>(factory),
                    new MaintenanceWorkBroker <LocalDataAccess>(factory)
                }, new Action(this.OnExitCallback), true);
                MonitoringWorker.eventLogger.LogEvent(MSExchangeHMEventLogConstants.Tuple_HealthManagerWorkerStarted, null, new object[]
                {
                    MonitoringWorker.processId,
                    Strings.StartedWithAllWorkBrokers(flag6, flag7)
                });
            }
            else if (flag6 && !flag7)
            {
                this.activeMonitoringWorker = new Worker(new WorkBroker[]
                {
                    new ProbeWorkBroker <LocalDataAccess>(factory),
                    new MonitorWorkBroker <LocalDataAccess>(factory),
                    new MaintenanceWorkBroker <LocalDataAccess>(factory)
                }, new Action(this.OnExitCallback), true);
                MonitoringWorker.eventLogger.LogEvent(MSExchangeHMEventLogConstants.Tuple_HealthManagerWorkerStarted, null, new object[]
                {
                    MonitoringWorker.processId,
                    Strings.StartedWithAllWorkBrokersExceptResponder(flag6, flag7)
                });
            }
            else
            {
                this.activeMonitoringWorker = new Worker(new WorkBroker[]
                {
                    new MaintenanceWorkBroker <LocalDataAccess>(factory)
                }, new Action(this.OnExitCallback), true);
                MonitoringWorker.eventLogger.LogEvent(MSExchangeHMEventLogConstants.Tuple_HealthManagerWorkerStarted, null, new object[]
                {
                    MonitoringWorker.processId,
                    Strings.StartedWithMaintenanceWorkBrokerOnly(flag6, flag7)
                });
            }
            try
            {
                if (this.serviceControlled)
                {
                    SafeFileHandle handle = new SafeFileHandle(new IntPtr(long.Parse(s)), true);
                    this.listenPipeStream = new PipeStream(handle, FileAccess.Read, true);
                    this.controlObject    = new ControlObject(this.listenPipeStream, this);
                    if (this.controlObject.Initialize())
                    {
                        if (this.readyHandle != null)
                        {
                            WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Signal the process is ready", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 726);
                            this.readyHandle.Release();
                            this.readyHandle.Close();
                            this.readyHandle = null;
                        }
                        if (!flag && !flag2)
                        {
                            WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Start processing work items", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 736);
                            this.Activate();
                        }
                        WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Waiting for shutdown signal to exit.", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 742);
                        this.stopHandle.WaitOne();
                    }
                }
                else
                {
                    if (!flag)
                    {
                        Console.WriteLine("Start processing work items");
                        this.Activate();
                    }
                    Console.WriteLine("Press ENTER to exit ");
                    bool flag8 = false;
                    while (!flag8)
                    {
                        string text3 = Console.ReadLine();
                        if (string.IsNullOrEmpty(text3))
                        {
                            Console.WriteLine("Exiting.");
                            flag8 = true;
                        }
                        else if (text3.Equals("p"))
                        {
                            Console.WriteLine("Pause.");
                            this.Pause();
                        }
                        else if (text3.Equals("c"))
                        {
                            Console.WriteLine("Continue.");
                            this.Continue();
                        }
                        else if (text3.Equals("s"))
                        {
                            Console.WriteLine("Stop.");
                            this.Stop();
                        }
                        else
                        {
                            Console.WriteLine("Unknown command.");
                        }
                    }
                }
            }
            catch (Exception ex3)
            {
                MonitoringWorker.eventLogger.LogEvent(MSExchangeHMEventLogConstants.Tuple_WorkerRestartOnUnknown, null, new object[]
                {
                    MonitoringWorker.processId,
                    ex3.ToString()
                });
                if (!this.serviceControlled && ((ex3 is Win32Exception && ((Win32Exception)ex3).NativeErrorCode == 5) || ex3 is UnauthorizedAccessException || ex3 is SecurityAccessDeniedException))
                {
                    Console.WriteLine("You must run the worker process with elevated privileges");
                }
            }
            WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Received a signal to shut down.  Closing control pipe.", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 814);
            this.DoCleanUp();
            this.SavePersistentState();
            WTFLogger.Instance.LogDebug(WTFLog.Core, TracingContext.Default, "Monitoring worker process stopped.", "Run", "f:\\15.00.1497\\sources\\dev\\monitoring\\src\\ActiveMonitoring\\Local\\WorkerProcess\\Program.cs", 820);
            WTFLogger.Instance.Flush();
            MonitoringWorker.eventLogger.LogEvent(MSExchangeHMEventLogConstants.Tuple_HealthManagerWorkerStopped, null, new object[]
            {
                MonitoringWorker.processId
            });
        }