From 6d2e617af71c2f6f41fb8f024e6adad5a7d1708e Mon Sep 17 00:00:00 2001 From: Hui Zhang Date: Mon, 12 Oct 2015 18:11:10 +0800 Subject: [PATCH] CA-185019: HealthCheckService should retrieve the server capabilities HealthCheckService retrieves system capabilities, filter them with the reports excluded in Health Check. Since Dundee, add verbosity for host status report request. Signed-off-by: Hui Zhang --- .../XenServerHealthCheckBugTool.cs | 114 ++++++++++++------ 1 file changed, 79 insertions(+), 35 deletions(-) diff --git a/XenServerHealthCheck/XenServerHealthCheckBugTool.cs b/XenServerHealthCheck/XenServerHealthCheckBugTool.cs index 9523601a4..b2b70c487 100644 --- a/XenServerHealthCheck/XenServerHealthCheckBugTool.cs +++ b/XenServerHealthCheck/XenServerHealthCheckBugTool.cs @@ -37,7 +37,9 @@ using XenAdmin.Core; using XenAPI; using XenAdmin.Actions; using XenAdmin; +using System.Linq; using System.Globalization; +using System.Xml; namespace XenServerHealthCheck { @@ -45,41 +47,24 @@ namespace XenServerHealthCheck { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - // The logs which are needed by Health Check. - private static readonly List bugtoolParam = - new List + private static readonly List reportExcluded = + new List { - "xen-info:2", - "filesystem_summarise:2", - "xha-liveset:2", - "high-availability:2", - "firstboot:2", - "xenserver-databases:2", - "multipath:2", - "disk-info:2", - "xenserver-logs:2", - "xenserver-install:2", - "process-list:2", - "xapi:2", - "host-crashdump-logs:2", - "xapi-subprocess:2", - "pam:2", - "tapdisk-logs:2", - "kernel-info:2", - "xenserver-config:2", - "xenserver-domains:2", - "device-model:2", - "hardware-info:2", - "xenopsd:2", - "loopback-devices:2", - "system-services:2", - "system-logs:2", - "network-status:2", - "CVSM:2", - "xcp-rrdd-plugins:2", - "yum:2", - "network-config:2", - "boot-loader:2" + "blobs", + "vncterm", + "xapi-debug" + }; + + private static readonly Dictionary reportWithVerbosity = + new Dictionary + { + {"host-crashdump-logs", 2}, + {"system-logs", 2}, + {"tapdisk-logs", 2}, + {"xapi", 2}, + {"xcp-rrdd-plugins", 2}, + {"xenserver-install", 2}, + {"xenserver-logs", 2} }; public readonly string outputFile; @@ -104,6 +89,65 @@ namespace XenServerHealthCheck if (connection == null || session == null) return; + // Fetch the common capabilities of all hosts. + Dictionary> hostCapabilities = new Dictionary>(); + foreach (Host host in connection.Cache.Hosts) + { + GetSystemStatusCapabilities action = new GetSystemStatusCapabilities(host); + action.RunExternal(session); + if (!action.Succeeded) + return; + + List keys = new List(); + 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 combination = null; + foreach (List capabilities in hostCapabilities.Values) + { + if (capabilities == null) + continue; + + if (combination == null) + { + combination = capabilities; + continue; + } + + combination = Helpers.ListsCommonItems(combination, capabilities); + } + + if (combination == null || combination.Count <= 0) + return; + + // The list of the reports which are required in Health Check Report. + List reportIncluded = combination.Except(reportExcluded).ToList(); + + // Verbosity works for xen-bugtool since Dundee. + if (Helpers.DundeeOrGreater(connection)) + { + List verbReport = new List(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)) @@ -134,7 +178,7 @@ namespace XenServerHealthCheck } HostWithStatus hostWithStatus = new HostWithStatus(host, 0); - SingleHostStatusAction statAction = new SingleHostStatusAction(hostWithStatus, bugtoolParam, filepath, timestring + "-" + ++i); + SingleHostStatusAction statAction = new SingleHostStatusAction(hostWithStatus, reportIncluded, filepath, timestring + "-" + ++i); statAction.RunExternal(session); }