コード例 #1
0
        public override async Task <int> ExecuteAsync(CommandContext context, CheckProcessSettings settings)
        {
            AnsiConsole.WriteLine("Running checks on process " + settings.Pid);

            var process = ProcessInfo.GetProcessInfo(settings.Pid);

            if (process == null)
            {
                Utils.WriteError("Could not fetch information about target process. Make sure to run the command from an elevated prompt, and check that the pid is correct.");
                return(1);
            }

            var mainModule = process.MainModule != null?Path.GetFileName(process.MainModule) : null;

            if (mainModule == "w3wp.exe" || mainModule == "iisexpress.exe")
            {
                if (process.EnvironmentVariables.ContainsKey("APP_POOL_ID"))
                {
                    Utils.WriteWarning(IisProcess);
                }
            }

            var foundIssue = !ProcessBasicCheck.Run(process);

            if (foundIssue)
            {
                return(1);
            }

            foundIssue = !await AgentConnectivityCheck.RunAsync(process).ConfigureAwait(false);

            if (foundIssue)
            {
                return(1);
            }

            Utils.WriteSuccess("No issue found with the target process.");

            return(0);
        }
コード例 #2
0
        public override async Task <int> ExecuteAsync(CommandContext context, CheckAgentSettings settings)
        {
            ExporterSettings configuration;

            if (settings.Url == null)
            {
                // Try to autodetect the agent settings
                configuration = new ExporterSettings(new EnvironmentConfigurationSource());

                AnsiConsole.WriteLine("No Agent URL provided, using environment variables");
            }
            else
            {
                configuration = new ExporterSettings {
                    AgentUri = new Uri(settings.Url)
                };

                // TODO: Remove when the logic has been moved to the ImmutableExporterSettings constructor
                if (settings.Url.StartsWith("unix://"))
                {
                    configuration.TracesTransport            = TracesTransportType.UnixDomainSocket;
                    configuration.TracesUnixDomainSocketPath = configuration.AgentUri.PathAndQuery;
                }
            }

            var result = await AgentConnectivityCheck.RunAsync(new ImmutableExporterSettings(configuration)).ConfigureAwait(false);

            if (!result)
            {
                return(1);
            }

            Utils.WriteSuccess("Connected successfully to the Agent.");

            return(0);
        }
コード例 #3
0
        internal static async Task <int> ExecuteAsync(CheckIisSettings settings, string applicationHostConfigurationPath, int?pid, IRegistryService registryService = null)
        {
            var values = settings.SiteName.Split('/');

            var siteName        = values[0];
            var applicationName = values.Length > 1 ? $"/{values[1]}" : "/";

            AnsiConsole.WriteLine(FetchingApplication(siteName, applicationName));

            var serverManager = new ServerManager(readOnly: true, applicationHostConfigurationPath);

            var site = serverManager.Sites[siteName];

            if (site == null)
            {
                Utils.WriteError(CouldNotFindSite(siteName, serverManager.Sites.Select(s => s.Name)));

                return(1);
            }

            var application = site.Applications[applicationName];

            if (application == null)
            {
                Utils.WriteError(CouldNotFindApplication(siteName, applicationName, site.Applications.Select(a => a.Path)));

                return(1);
            }

            var pool = serverManager.ApplicationPools[application.ApplicationPoolName];

            // The WorkerProcess part of ServerManager doesn't seem to be compatible with IISExpress
            // so we skip this bit when launched from the tests
            if (pid == null)
            {
                var workerProcesses = pool.WorkerProcesses;

                if (workerProcesses.Count > 0)
                {
                    // If there are multiple worker processes, we just take the first one
                    // In theory, all worker processes have the same configuration
                    pid = workerProcesses[0].ProcessId;
                }
            }

            if (pid == null)
            {
                Utils.WriteWarning(NoWorkerProcess);
            }
            else
            {
                AnsiConsole.WriteLine(InspectingWorkerProcess(pid.Value));

                var rootDirectory = application.VirtualDirectories.FirstOrDefault(d => d.Path == "/")?.PhysicalPath;

                IConfigurationSource appSettingsConfigurationSource = null;

                try
                {
                    var config      = application.GetWebConfiguration();
                    var appSettings = config.GetSection("appSettings");
                    var collection  = appSettings.GetCollection();

                    appSettingsConfigurationSource = new DictionaryConfigurationSource(
                        collection.ToDictionary(c => (string)c.Attributes["key"].Value, c => (string)c.Attributes["value"].Value));
                }
                catch (Exception ex)
                {
                    Utils.WriteWarning(ErrorExtractingConfiguration(ex.Message));
                }

                var process = ProcessInfo.GetProcessInfo(pid.Value, rootDirectory, appSettingsConfigurationSource);

                if (process == null)
                {
                    Utils.WriteError(GetProcessError);
                    return(1);
                }

                if (process.DotnetRuntime.HasFlag(ProcessInfo.Runtime.NetCore) && !string.IsNullOrEmpty(pool.ManagedRuntimeVersion))
                {
                    Utils.WriteWarning(IisMixedRuntimes);
                }

                if (process.Modules.Any(m => Path.GetFileName(m).Equals("aspnetcorev2_outofprocess.dll", StringComparison.OrdinalIgnoreCase)))
                {
                    // IIS site is hosting aspnetcore in out-of-process mode
                    // Trying to locate the actual application process
                    AnsiConsole.WriteLine(OutOfProcess);

                    var childProcesses = process.GetChildProcesses();

                    // Get either the first process that is dotnet, or the first that is not conhost
                    int?dotnetPid   = null;
                    int?fallbackPid = null;

                    foreach (var childPid in childProcesses)
                    {
                        using var childProcess = Process.GetProcessById(childPid);

                        if (childProcess.ProcessName.Equals("dotnet", StringComparison.OrdinalIgnoreCase))
                        {
                            dotnetPid = childPid;
                            break;
                        }

                        if (!childProcess.ProcessName.Equals("conhost", StringComparison.OrdinalIgnoreCase))
                        {
                            fallbackPid = childPid;
                        }
                    }

                    var aspnetCorePid = dotnetPid ?? fallbackPid;

                    if (aspnetCorePid == null)
                    {
                        Utils.WriteError(AspNetCoreProcessNotFound);
                        return(1);
                    }

                    AnsiConsole.WriteLine(AspNetCoreProcessFound(aspnetCorePid.Value));

                    process = ProcessInfo.GetProcessInfo(aspnetCorePid.Value);

                    if (process == null)
                    {
                        Utils.WriteError(GetProcessError);
                        return(1);
                    }
                }

                if (!ProcessBasicCheck.Run(process, registryService))
                {
                    return(1);
                }

                if (!await AgentConnectivityCheck.RunAsync(process).ConfigureAwait(false))
                {
                    return(1);
                }
            }

            if (!GacCheck.Run())
            {
                return(1);
            }

            Utils.WriteSuccess(IisNoIssue);

            return(0);
        }