protected override void Run() { host.Status = HostStatus.compiling; string hostname = Helpers.GetName(host.Host); hostname = ZipStatusReportAction.SanitizeTarPathMember(hostname); // Workaround for excessively long filenames: trim the hostname we use if (hostname.Length > 20) { hostname = hostname.Truncate(20); } string filename = string.Format("{1}\\{2}-bugtool-{0}.tar", hostname, filepath, timestring); string entries_string = String.Join(",", entries); log.DebugFormat("Getting system status for {0} on {1}", entries_string, hostname); try { host.Status = HostStatus.compiling; if (Session == null) { throw new Exception(Messages.CONNECTION_IO_EXCEPTION); } HTTPHelper.Get(this, false, dataRxDelegate, filename, host.Host.address, (HTTP_actions.get_ssss)HTTP_actions.get_system_status, Session.opaque_ref, entries_string, "tar"); log.DebugFormat("Getting system status from {0} successful", hostname); host.Status = HostStatus.succeeded; base.PercentComplete = 100; } catch (CancelledException ce) { log.Info("Getting system status cancelled"); Description = Messages.ACTION_SYSTEM_STATUS_CANCELLED; host.Status = HostStatus.failed; host.error = ce; throw; } catch (Exception e) { log.Warn(string.Format("Getting system status from {0} failed", hostname), e); host.Status = HostStatus.failed; host.error = e; Description = Win32.GetHResult(e) == Win32.ERROR_DISK_FULL ? Messages.ACTION_SYSTEM_STATUS_DISK_FULL : Messages.ACTION_SYSTEM_STATUS_FAILED; } }
public void RunBugtool(IXenConnection connection, Session session) { if (connection == null || session == null) return; // Ensure downloaded filenames are unique even for hosts with the same hostname: append a counter to the timestring string filepath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); if (Directory.Exists(filepath)) Directory.Delete(filepath); Directory.CreateDirectory(filepath); string timestring = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); // Collect all master/slave information to output as a separate text file with the report List<string> mastersInfo = new List<string>(); int i = 0; Pool p = Helpers.GetPool(connection); foreach (Host host in connection.Cache.Hosts) { // master/slave information if (p == null) { mastersInfo.Add(string.Format("Server '{0}' is a stand alone server", host.Name)); } else { mastersInfo.Add(string.Format("Server '{0}' is a {1} of pool '{2}'", host.Name, p.master.opaque_ref == host.opaque_ref ? "master" : "slave", p.Name)); } HostWithStatus hostWithStatus = new HostWithStatus(host, 0); SingleHostStatusAction statAction = new SingleHostStatusAction(hostWithStatus, bugtoolParam, filepath, timestring + "-" + ++i); statAction.RunExternal(session); } string mastersDestination = string.Format("{0}\\{1}-Masters.txt", filepath, timestring); if (File.Exists(mastersDestination)) File.Delete(mastersDestination); StreamWriter sw = null; try { sw = new StreamWriter(mastersDestination); foreach (string s in mastersInfo) sw.WriteLine(s); sw.Flush(); } catch (Exception e) { log.ErrorFormat("Exception while writing masters file: {0}", e); } finally { if (sw != null) sw.Close(); } // Finish the collection of logs with bugtool. // Start to zip the files. ZipStatusReportAction zipAction = new ZipStatusReportAction(filepath, outputFile); zipAction.RunExternal(session); log.InfoFormat("Server Status Report is collected: {0}", outputFile); }
public void RunBugtool(IXenConnection connection, Session session) { if (connection == null || session == null) return; // Fetch the common capabilities of all hosts. Dictionary<Host, List<string>> hostCapabilities = new Dictionary<Host, List<string>>(); foreach (Host host in connection.Cache.Hosts) { GetSystemStatusCapabilities action = new GetSystemStatusCapabilities(host); action.RunExternal(session); if (!action.Succeeded) return; List<string> keys = new List<string>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(action.Result); foreach (XmlNode node in doc.GetElementsByTagName("capability")) { foreach (XmlAttribute a in node.Attributes) { if (a.Name == "key") keys.Add(a.Value); } } hostCapabilities[host] = keys; } List<string> combination = null; foreach (List<string> capabilities in hostCapabilities.Values) { if (capabilities == null) continue; if (combination == null) { combination = capabilities; continue; } combination = Helpers.ListsCommonItems<string>(combination, capabilities); } if (combination == null || combination.Count <= 0) return; // The list of the reports which are required in Health Check Report. List<string> reportIncluded = combination.Except(reportExcluded).ToList(); // Verbosity works for xen-bugtool since Dundee. if (Helpers.DundeeOrGreater(connection)) { List<string> verbReport = new List<string>(reportWithVerbosity.Keys); int idx = -1; for (int x = 0; x < verbReport.Count; x++) { idx = reportIncluded.IndexOf(verbReport[x]); if (idx >= 0) { reportIncluded[idx] = reportIncluded[idx] + ":" + reportWithVerbosity[verbReport[x]].ToString(); } } } // Ensure downloaded filenames are unique even for hosts with the same hostname: append a counter to the timestring string filepath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); if (Directory.Exists(filepath)) Directory.Delete(filepath); Directory.CreateDirectory(filepath); string timestring = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); // Collect all master/slave information to output as a separate text file with the report List<string> mastersInfo = new List<string>(); int i = 0; Pool p = Helpers.GetPool(connection); foreach (Host host in connection.Cache.Hosts) { // master/slave information if (p == null) { mastersInfo.Add(string.Format("Server '{0}' is a stand alone server", host.Name)); } else { mastersInfo.Add(string.Format("Server '{0}' is a {1} of pool '{2}'", host.Name, p.master.opaque_ref == host.opaque_ref ? "master" : "slave", p.Name)); } HostWithStatus hostWithStatus = new HostWithStatus(host, 0); SingleHostStatusAction statAction = new SingleHostStatusAction(hostWithStatus, reportIncluded, filepath, timestring + "-" + ++i); statAction.RunExternal(session); } string mastersDestination = string.Format("{0}\\{1}-Masters.txt", filepath, timestring); if (File.Exists(mastersDestination)) File.Delete(mastersDestination); StreamWriter sw = null; try { sw = new StreamWriter(mastersDestination); foreach (string s in mastersInfo) sw.WriteLine(s); sw.Flush(); } catch (Exception e) { log.ErrorFormat("Exception while writing masters file: {0}", e); } finally { if (sw != null) sw.Close(); } // Finish the collection of logs with bugtool. // Start to zip the files. ZipStatusReportAction zipAction = new ZipStatusReportAction(filepath, outputFile); zipAction.RunExternal(session); log.InfoFormat("Server Status Report is collected: {0}", outputFile); }
protected override void Run() { Status = ReportStatus.compiling; string hostname = Helpers.GetName(host); hostname = ZipStatusReportAction.SanitizeTarPathMember(hostname); if (hostname.Length > 20) { hostname = hostname.Truncate(20); } string filename = string.Format("{1}\\{2}-bugtool-{0}.tar", hostname, filePath, timeString); string entries_string = string.Join(",", capabilityKeys); log.DebugFormat("Getting system status for {0} on {1}", entries_string, hostname); try { if (Session == null) { throw new Exception(Messages.CONNECTION_IO_EXCEPTION); } HTTPHelper.Get(this, false, dataRxDelegate, filename, host.address, (HTTP_actions.get_ssss)HTTP_actions.get_system_status, Session.opaque_ref, entries_string, "tar"); log.DebugFormat("Getting system status from {0} successful", hostname); Status = ReportStatus.succeeded; Description = Messages.COMPLETED; PercentComplete = 100; } catch (HTTP.CancelledException) { throw new CancelledException(); } catch (CancelledException ce) { log.Info("Getting system status cancelled"); Status = ReportStatus.cancelled; Error = ce; Description = Messages.ACTION_SYSTEM_STATUS_CANCELLED; throw; } catch (Exception e) { log.Error(string.Format("Getting system status from {0} failed", hostname), e); Status = ReportStatus.failed; Error = e; if (Win32.GetHResult(e) == Win32.ERROR_DISK_FULL) { Description = Messages.ACTION_SYSTEM_STATUS_DISK_FULL; return; } if (!string.IsNullOrEmpty(Error.Message) && RBAC_FAIL_STRINGS.All(s => Error.Message.Contains(s))) { var roles = Host.Connection.Session.Roles; roles.Sort(); Description = string.Format(Messages.BUGTOOL_RBAC_FAILURE, roles[0].FriendlyName()); return; } Description = Messages.BUGTOOL_REPORTSTATUS_FAILED; } }