shift duplicate service detection from the special agent to the check
Message-ID: <5b15358a.nLPJdnXlCtzUHue5%tb(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: eb4a23e8ff7cd64f17141c489e830721794bb96b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eb4a23e8ff7cd6…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Wed May 30 16:42:35 2018 +0200
6113 FIX winperf_processor, esx_vsphere_hostsystem.cpu_usage: shift duplicate service
detection from the special agent to the check
Previously, duplicate services for winperf_processor and
esx_vsphere_hostsystem.cpu_usage were recognized in the special agent. If
duplicate services would appear the corresponding entries in the special agent
were removed.
With the new option to configure multiple datasources for one host this logic
will not work since there is no possibility for the special agent to inspect
the section winperf_processor of the Check_MK agent. Therefore, the check
esx_vsphere_hostsystem.cpu_usage now recognizes duplicate services using
extra sections.
The transition from the old to the new logic should happen transparently, i.e.
no actions are required by the user.
Change-Id: I3b6a56efcff4c75bbd05a051242e18deaa499d9e
---
.werks/6113 | 22 ++++++++++++++++++++++
agents/special/agent_vsphere | 22 ----------------------
checks/esx_vsphere_hostsystem | 43 +++++++++++++++++++++++++++++++++++++------
3 files changed, 59 insertions(+), 28 deletions(-)
diff --git a/.werks/6113 b/.werks/6113
new file mode 100644
index 0000000..ffbb661
--- /dev/null
+++ b/.werks/6113
@@ -0,0 +1,22 @@
+Title: winperf_processor, esx_vsphere_hostsystem.cpu_usage: shift duplicate service
detection from the special agent to the check
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1528112755
+Class: fix
+
+Previously, duplicate services for winperf_processor and
+esx_vsphere_hostsystem.cpu_usage were recognized in the special agent. If
+duplicate services would appear the corresponding entries in the special agent
+were removed.
+
+With the new option to configure multiple datasources for one host this logic
+will not work since there is no possibility for the special agent to inspect
+the section winperf_processor of the Check_MK agent. Therefore, the check
+esx_vsphere_hostsystem.cpu_usage now recognizes duplicate services using
+extra sections.
+
+The transition from the old to the new logic should happen transparently, i.e.
+no actions are required by the user.
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index 7ceffae..de75964 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -940,17 +940,6 @@ vsphere_output = []
def output(line):
vsphere_output.append(line)
-# This function is used to modify the vsphere output, just before it is written to
stdout
-def check_winperf_processor(line):
- if "<<<winperf_processor>>>" in win_agent_output:
- try:
- vsphere_output.remove(line)
- except ValueError:
- pass
-# A list of tuples: (line, function_pointer)
-# A certain line can register a function pointer
-# The function pointer is called later on with the line as argument
-postprocess_functions = []
socket.setdefaulttimeout(opt_timeout)
def get_agent_info_tcp(hostname):
@@ -1495,12 +1484,6 @@ if not error:
output("<<<esx_vsphere_hostsystem>>>")
for key in sorted(properties.keys()):
- # Special handling. If the windows may report winperf_processor
in the following call
- # remove summary.quickStats.overallCpuUsage from the output. This
would lead to a
- # duplicate "CPU utlization" service
- if opt_direct and opt_agent and key ==
"summary.quickStats.overallCpuUsage":
- postprocess_functions.append(("%s %s" % (key,
" ".join(properties[key])), check_winperf_processor))
-
output("%s %s" % (key, "
".join(properties[key])))
output("<<<esx_vsphere_sensors:sep(59)>>>")
@@ -1731,11 +1714,6 @@ if opt_agent:
sys.stdout.flush()
error_exit = 0
-# May filter some data from the vsphere_output variable
-# Currently only used by winperf_processor special handling
-for line, function in postprocess_functions:
- function(line)
-
print "\n".join(map(make_utf8, vsphere_output))
if tracefile:
diff --git a/checks/esx_vsphere_hostsystem b/checks/esx_vsphere_hostsystem
index 45b36dc..55e3234 100644
--- a/checks/esx_vsphere_hostsystem
+++ b/checks/esx_vsphere_hostsystem
@@ -24,6 +24,23 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+
+# TODO: The extra_sections part is only transitional code to avoid
+# duplicate CPU services.
+# Previously, the duplicate services were handled in the agent_vsphere
+# directly. Starting with 1.5.0 this is problematic since multiple
+# datasources can be defined in Check_MK natively. Therefore we shift
+# the detection of the duplicate services directly to this check.
+# When it is possible to handle duplicate services for different
+# datasources correctly at the cmk_base level this code can be removed.
+# NOTE: By design the extra_sections are passed to EVERY subcheck and
+# therefore have to be removed in every subcheck!
+# Change-Id: I3b6a56efcff4c75bbd05a051242e18deaa499d9e
+check_info['esx_vsphere_hostsystem'] = {
+ 'extra_sections': ["winperf_processor"],
+}
+
+
def esx_vsphere_hostsystem_convert(info):
data = {}
for line in info:
@@ -51,16 +68,20 @@ esx_host_cpu_default_levels = {}
def inventory_esx_vsphere_hostsystem_cpu(info):
- data = esx_vsphere_hostsystem_convert(info).keys()
- if 'summary.quickStats.overallCpuUsage' in data \
- and 'hardware.cpuInfo.hz' in data\
- and 'hardware.cpuInfo.numCpuCores' in data:
+ hostsystem_info, winperf_info = info
+ data = esx_vsphere_hostsystem_convert(hostsystem_info).keys()
+ if (not winperf_info and
+ 'summary.quickStats.overallCpuUsage' in data and
+ 'hardware.cpuInfo.hz' in data and
+ 'hardware.cpuInfo.numCpuCores' in data):
return [(None, {})]
+
def check_esx_vsphere_hostsystem_cpu(item, params, info):
- data = esx_vsphere_hostsystem_convert(info)
+ hostsystem_info, winperf_info = info
+ data = esx_vsphere_hostsystem_convert(hostsystem_info)
- if "summary.quickStats.overallCpuUsage" not in data:
+ if winperf_info or "summary.quickStats.overallCpuUsage" not in data:
return
num_sockets = int(data['hardware.cpuInfo.numCpuPackages'][0])
@@ -108,6 +129,7 @@ check_info['esx_vsphere_hostsystem.cpu_usage'] = {
# +----------------------------------------------------------------------+
def check_esx_vsphere_hostsystem_mem_cluster(item, params, info):
+ info, _ = info
data = {}
for line in info:
if line[0] in ["summary.quickStats.overallMemoryUsage",
"hardware.memorySize", "name"]:
@@ -163,6 +185,7 @@ check_info['esx_vsphere_hostsystem.mem_usage_cluster'] = {
def check_esx_vsphere_hostsystem_cpu_util_cluster(item, params, info):
+ info, _ = info
current_node = {}
def get_node_usage(node):
num_sockets = int(node['hardware.cpuInfo.numCpuPackages'])
@@ -237,11 +260,13 @@ check_info['esx_vsphere_hostsystem.cpu_util_cluster'] = {
esx_host_mem_default_levels = ( 80.0, 90.0 )
def inventory_esx_vsphere_hostsystem_mem(info):
+ info, _ = info
data = esx_vsphere_hostsystem_convert(info).keys()
if 'summary.quickStats.overallMemoryUsage' in data and
'hardware.memorySize' in data:
return [(None, 'esx_host_mem_default_levels')]
def check_esx_vsphere_hostsystem_mem(item, params, info):
+ info, _ = info
data = esx_vsphere_hostsystem_convert(info)
if "summary.quickStats.overallMemoryUsage" not in data:
@@ -288,11 +313,13 @@ check_info['esx_vsphere_hostsystem.mem_usage'] = {
def inventory_esx_vsphere_hostsystem_state(info):
+ info, _ = info
data = esx_vsphere_hostsystem_convert(info).keys()
if 'runtime.inMaintenanceMode' in data:
return [(None, None)]
def check_esx_vsphere_hostsystem_state(_no_item, _no_params, info):
+ info, _ = info
data = esx_vsphere_hostsystem_convert(info)
state = 0
if "overallStatus" not in data:
@@ -331,12 +358,14 @@ check_info['esx_vsphere_hostsystem.state'] = {
# '----------------------------------------------------------------------'
def inventory_esx_vsphere_hostsystem_maintenance(info):
+ info, _ = info
data = esx_vsphere_hostsystem_convert(info)
if 'runtime.inMaintenanceMode' in data:
current_state = str(data['runtime.inMaintenanceMode'][0]).lower()
return [(None, { 'target_state' : current_state })]
def check_esx_vsphere_hostsystem_maintenance(_no_item, params, info):
+ info, _ = info
data = esx_vsphere_hostsystem_convert(info)
target_state = params['target_state']
@@ -425,10 +454,12 @@ def esx_vsphere_multipath_convert(info):
return paths
def inventory_esx_vsphere_hostsystem_multipath(info):
+ info, _ = info
data = esx_vsphere_multipath_convert(info).items()
return [ (x, None) for x, y in data]
def check_esx_vsphere_hostsystem_multipath(item, params, info):
+ info, _ = info
state_infos = {
# alert_state, count, info
"active" : [0, 0, ""],