public static void RunCommand(string command, bool isHidden = true) { try { Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); if (isHidden) { startInfo.WindowStyle = ProcessWindowStyle.Hidden; } startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C " + command; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.StandardOutputEncoding = Encoding.UTF8; startInfo.WindowStyle = ProcessWindowStyle.Minimized; startInfo.CreateNoWindow = true; //FileLogger.TraceLog("Cmd: " + command); process.StartInfo = startInfo; process.Start(); //FileLogger.TraceLog(process.StandardOutput.ReadToEnd()); process.WaitForExit(); process.Close(); } catch (Exception e) { FileLogger.LogError("Error retrieving memory dumps. Cmd: " + command, e.Message + e.StackTrace); } }
public static void GetPlatformAndServerFiles() { // Process Platform and Server Configuration files FileLogger.TraceLog("Copying Platform and Server configuration files... "); Directory.CreateDirectory(_osPlatFilesDest); Platform.PlatformFilesHelper.CopyPlatformAndServerConfFiles(_osInstallationFolder, _iisApplicationHostPath, _iisWebConfigPath, _machineConfigPath, _osPlatFilesDest); // Export Registry information // Create directory for Registry information Directory.CreateDirectory(Path.Combine(_tempFolderPath, "RegistryInformation")); string registryInformationPath = Path.Combine(_tempFolderPath, "RegistryInformation"); // Fetch Registry key values and subkeys values try { FileLogger.TraceLog("Exporting Registry information..."); RegistryClass.RegistryCopy(_sslProtocolsRegistryPath, Path.Combine(registryInformationPath, "SSLProtocols.txt"), true); RegistryClass.RegistryCopy(_netFrameworkRegistryPath, Path.Combine(registryInformationPath, "NetFramework.txt"), true); RegistryClass.RegistryCopy(_iisRegistryPath, Path.Combine(registryInformationPath, "IIS.txt"), true); RegistryClass.RegistryCopy(_outSystemsPlatformRegistryPath, Path.Combine(registryInformationPath, "OutSystemsPlatform.txt"), true); RegistryClass.RegistryCopy(_rabbitMQRegistryPath, Path.Combine(registryInformationPath, "RabbitMQ.txt"), true); } catch (Exception e) { FileLogger.LogError("Failed to export Registry:", e.Message + e.StackTrace); } }
private void LoadServerAPIAndIdentityLogPath(string _filepath) { try { var xml = XDocument.Load(_filepath); XNamespace ns = xml.Root.GetDefaultNamespace(); foreach (XElement el in xml.Descendants(ns + "targets").Elements(ns + "target")) { _logServerFilePath = el.Attribute("fileName").Value.ToString(); break; } } catch (Exception e) { FileLogger.LogError("Failed to parse Server API / Identity xml ", e.Message + e.StackTrace); } }
public static void DatabaseTroubleshootProgram(OSDiagToolConf.ConfModel.strConfModel configurations, DBConnector.SQLConnStringModel sqlConnString = null, DBConnector.OracleConnStringModel orclConnString = null) { Directory.CreateDirectory(_osDatabaseTroubleshootDest); try { FileLogger.TraceLog(string.Format("Performing {0} Database Troubleshoot...", dbEngine.ToUpper())); if (dbEngine.Equals("sqlserver")) { Database.DatabaseQueries.DatabaseTroubleshoot.DatabaseTroubleshooting(dbEngine, configurations, _osDatabaseTroubleshootDest, sqlConnString, null); } else if (dbEngine.Equals("oracle")) { Database.DatabaseQueries.DatabaseTroubleshoot.DatabaseTroubleshooting(dbEngine, configurations, _osDatabaseTroubleshootDest, null, orclConnString); } } catch (Exception e) { FileLogger.LogError("Failed to perform Database Troubleshoot", e.Message + e.StackTrace); } }
// Loads all the required information from the OS service conf file private void LoadConfFileInfo() { if (_isFileLoaded) { return; } try { XElement confXml = XElement.Load(_filepath); LoadLogFilePathFromConfRoot(confXml); LoadLogLevelFromConfRoot(confXml); _isFileLoaded = true; } catch (Exception e) { FileLogger.LogError("Attempted to load OS Configuration file but failed:", e.Message + e.StackTrace); } }
public static void GetIISAccessLogs(string iisapplicationHostPath, string tempFolderPath, FileSystemHelper fsHelper, int daysToFetch) { //Retrieving IIS access logs try { FileLogger.TraceLog("Retrieving IIS Access logs... "); // Loading Xml text from the file. Note: 32 bit processes will redirect \System32 to \SysWOW64: http://www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm if (Environment.Is64BitOperatingSystem == false) { iisapplicationHostPath = iisapplicationHostPath.Replace("system32", "Sysnative"); } var xmlString = XDocument.Load(iisapplicationHostPath); // Querying the data and finding the Access logs path var query = from p in xmlString.Descendants("siteDefaults") select new { LogsFilePath = p.Element("logFile").Attribute("directory").Value, }; string iisAccessLogsPath = query.First().LogsFilePath.ToLower(); if (iisAccessLogsPath.Contains("%systemdrive%")) { iisAccessLogsPath = iisAccessLogsPath.Replace("%systemdrive%\\", Path.GetPathRoot(Environment.SystemDirectory)); if ((Environment.Is64BitOperatingSystem == false) && iisAccessLogsPath.Contains("system32")) { iisAccessLogsPath = iisAccessLogsPath.Replace("system32", "Sysnative"); } } //Copies all the contents from the path iisAcessLogsPath, including contents in subfolder fsHelper.DirectoryCopy(iisAccessLogsPath, Path.Combine(tempFolderPath, "IISLogs"), true, true, daysToFetch); } catch (Exception e) { FileLogger.LogError("Attempted to retrieve IIS Access logs but failed...", e.Message + e.StackTrace); } }
public static void CollectMemoryDumps(bool iisMemDumps, bool osMemDumps) { List <string> processList = new List <string>(); if (iisMemDumps && osMemDumps) { processList.AddRange(new List <string>() { "w3wp", "deployment_controller", "deployment_service", "scheduler", "log_service" }); } else if (!iisMemDumps && osMemDumps) { processList.AddRange(new List <string>() { "deployment_controller", "deployment_service", "scheduler", "log_service" }); } else if (iisMemDumps && !osMemDumps) { processList.AddRange(new List <string>() { "w3wp" }); } else { return; } string memoryDumpsPath = Path.Combine(_tempFolderPath, "MemoryDumps"); Directory.CreateDirectory(memoryDumpsPath); CmdLineCommand command; ThreadDumpCollector dc = new ThreadDumpCollector(5000); Dictionary <string, string> processDict = new Dictionary <string, string> { { "log_service", "LogServer.exe" }, { "deployment_service", "DeployService.exe" }, { "deployment_controller", "CompilerService.exe" }, { "scheduler", "Scheduler.exe" }, { "w3wp", "w3wp.exe" } }; try { foreach (string processTag in processList) { FileLogger.TraceLog("Collecting " + processTag + " memory dumps... "); string processName = processDict[processTag]; List <int> pids = dc.GetProcessIdsByName(processName); foreach (int pid in dc.GetProcessIdsByFilename(processName)) { string pidSuf = pids.Count > 1 ? "_" + pid : ""; string filename = "memdump_" + processTag + pidSuf + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".dmp"; FileLogger.TraceLog(" - PID " + pid + " - "); command = new CmdLineCommand("procdump64.exe -ma " + pid + " /accepteula " + "\"" + Path.Combine(memoryDumpsPath, filename) + "\""); command.Execute(); } } } catch (Exception e) { FileLogger.LogError("Failed to get memory dump: ", e.Message + e.StackTrace); } }
private static void CollectThreadDumps(bool iisThreads, bool osThreads) { List <string> processList = new List <string>(); if (iisThreads && osThreads) { processList.AddRange(new List <string>() { "w3wp", "deployment_controller", "deployment_service", "scheduler", "log_service" }); } else if (!iisThreads && osThreads) { processList.AddRange(new List <string>() { "deployment_controller", "deployment_service", "scheduler", "log_service" }); } else if (iisThreads && !osThreads) { processList.AddRange(new List <string>() { "w3wp" }); } else { return; } string threadDumpsPath = Path.Combine(_tempFolderPath, "ThreadDumps"); Directory.CreateDirectory(threadDumpsPath); ThreadDumpCollector dc = new ThreadDumpCollector(5000); Dictionary <string, string> processDict = new Dictionary <string, string> { { "log_service", "LogServer.exe" }, { "deployment_service", "DeployService.exe" }, { "deployment_controller", "CompilerService.exe" }, { "scheduler", "Scheduler.exe" }, { "w3wp", "w3wp.exe" } }; try { foreach (string processTag in processList) { FileLogger.TraceLog("Collecting " + processTag + " thread dumps... "); string processName = processDict[processTag]; List <int> pids = dc.GetProcessIdsByName(processName); foreach (int pid in dc.GetProcessIdsByFilename(processName)) { string pidSuf = pids.Count > 1 ? "_" + pid : ""; string filename = "threads_" + processTag + pidSuf + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".log"; using (TextWriter writer = new StreamWriter(File.Create(Path.Combine(threadDumpsPath, filename)))) { writer.WriteLine(DateTime.Now.ToString()); writer.WriteLine(dc.GetThreadDump(pid)); } } } } catch (Exception e) { FileLogger.LogError("Failed to get thread dump: ", e.Message + e.StackTrace); } }