public bool Post(string sessionId) { try { SessionController sessionController = new SessionController(); Session session = sessionController.GetSessionWithId(new SessionId(sessionId)).Result; sessionController.Analyze(session); return(true); } catch { return(false); } }
public bool Post(string sessionId, string detailed) { try { if (detailed == "downloadreports") { SessionController sessionController = new SessionController(); Session session = sessionController.GetSessionWithId(new SessionId(sessionId)); foreach (DiagnoserSession diagSession in session.GetDiagnoserSessions()) { diagSession.DownloadReportsToWebsite(); } } else if (detailed == "startanalysis") { SessionController sessionController = new SessionController(); Session session = sessionController.GetSessionWithId(new SessionId(sessionId)); sessionController.Analyze(session); } else if (detailed == "cancel") { SessionController sessionController = new SessionController(); Session session = sessionController.GetSessionWithId(new SessionId(sessionId)); sessionController.Cancel(session); } else { return(false); } return(true); } catch { return(false); } }
private static void CollectLogsAndTakeActions(Options options, string[] args, ref int argNum) { try { var diagnosersToRun = GetDiagnosersToRun(args, ref argNum); TimeSpan timeToRunFor = GetTimeSpanFromArg(args, ref argNum); string blobSasUri = GetBlobSasUriFromArg(args, ref argNum); bool runOnAllInstances = GetRunAllInstancesFromArg(args, ref argNum); var currentInstance = Instance.GetCurrentInstance(); List <Instance> Instances = new List <Instance>(); if (!runOnAllInstances) { Instances.Add(currentInstance); Console.WriteLine($"Running Diagnosers on {currentInstance.Name} instance only"); } else { // An empty diagnoser list means runs DaaS on all instances. Console.WriteLine("Running Diagnosers on all instances"); } Console.WriteLine($"BlobSaUri for the session is '{blobSasUri}'"); if (!string.IsNullOrWhiteSpace(blobSasUri)) { var message = DaaS.Storage.BlobController.ValidateBlobSasUri(blobSasUri); if (!string.IsNullOrWhiteSpace(message)) { throw new ApplicationException($"BlobSasUri specified is invalid. Failed with error - {message}"); } } var details = new { Diagnoser = string.Join(",", diagnosersToRun.Select(x => x.Name)), TimeSpanToRunFor = timeToRunFor.TotalSeconds.ToString("0"), HasBlobSasUri = !string.IsNullOrWhiteSpace(blobSasUri), AllInstances = runOnAllInstances, InstancesSelected = string.Join(",", Instances.Select(x => x.Name)), Options = options.ToString() }; var detailsString = JsonConvert.SerializeObject(details); Logger.LogDaasConsoleEvent("DaasConsole started a new Session", detailsString); EventLog.WriteEntry("Application", $"DaasConsole started with {detailsString} ", EventLogEntryType.Information); // Collect the logs for just the current instance Console.WriteLine("Starting data collection"); Session session = null; if (options == Options.CollectKillAnalyze || options == Options.CollectLogs) { session = SessionController.CollectLiveDataLogs( timeToRunFor, diagnosersToRun, true, Instances, null, blobSasUri); } else if (options == Options.Troubleshoot) { session = SessionController.TroubleshootLiveData( timeToRunFor, diagnosersToRun, true, Instances, null, blobSasUri); } Console.WriteLine("Waiting for collection to complete..."); Console.WriteLine($"Going to sleep for {timeToRunFor} seconds"); Thread.Sleep(timeToRunFor); Console.WriteLine("done sleeping"); do { Thread.Sleep(TimeSpan.FromSeconds(10)); Console.Write("."); session = SessionController.GetSessionWithId(session.SessionId); } while (session.Status == SessionStatus.Active); Console.WriteLine("Completed"); if (options == Options.CollectKillAnalyze) { Console.WriteLine("Analyzing collected logs"); // Say we want the logs analyzed SessionController.Analyze(session); // Kill the regular site's w3wp process. The logs can be analyzed by another instance or by this same instance when it is in a healtheir state Process mainSiteW3wpProcess = GetMainSiteW3wpProcess(); Console.WriteLine("Killing process {0} with pid {1}", mainSiteW3wpProcess.ProcessName, mainSiteW3wpProcess.Id); mainSiteW3wpProcess.Kill(); string sessionId = session != null?session.SessionId.ToString() : string.Empty; Logger.LogSessionVerboseEvent($"DaasConsole killed process {mainSiteW3wpProcess.ProcessName} with pid {mainSiteW3wpProcess.Id}", sessionId); } } catch (Exception ex) { string logMessage = $"Unhandled exception in DaasConsole.exe - {ex.GetType().ToString()}:{ex.Message}"; EventLog.WriteEntry("Application", logMessage, EventLogEntryType.Information); Console.WriteLine(logMessage); Logger.LogErrorEvent("Unhandled exception in DaasConsole.exe while collecting logs and taking actions", ex); } }