Module: check_mk
Branch: master
Commit: 97500168daacd92b92ac0fe42346acfcdc2ee17a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=97500168daacd9…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Jul 6 09:45:21 2015 +0200
#2399 agent_vsphere/esx_vsphere_counters.if: now also reports interface state, bandwidth
and mac address
The agent_vsphere now queries more data from the esx host.
In earlier versions the state was always set to up and the bandwidth and mac address to
unknown.
---
.werks/2399 | 10 ++++++++++
ChangeLog | 1 +
agents/special/agent_vsphere | 33 +++++++++++++++++++++++++++++++++
checks/esx_vsphere_counters | 26 ++++++++++++++++++--------
4 files changed, 62 insertions(+), 8 deletions(-)
diff --git a/.werks/2399 b/.werks/2399
new file mode 100644
index 0000000..3572c3b
--- /dev/null
+++ b/.werks/2399
@@ -0,0 +1,10 @@
+Title: agent_vsphere/esx_vsphere_counters.if: now also reports interface state, bandwidth
and mac address
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i3
+Date: 1436168510
+Class: feature
+
+The agent_vsphere now queries more data from the esx host.
+In earlier versions the state was always set to up and the bandwidth and mac address to
unknown.
diff --git a/ChangeLog b/ChangeLog
index 751f225..45f11fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
* 2371 appdynamics_memory, appdynamics_sessions, appdynamics_web_container: New
checks for AppDynamic...
* 2398 agent_vsphere: now able to opt-out of servers ssl certifcate check...
* 2448 Various Checks for Citrix XenApp 7.x Farms...
+ * 2399 agent_vsphere/esx_vsphere_counters.if: now also reports interface state,
bandwidth and mac address...
* 2315 FIX: windows agent: BOM replacement, fixed incorrect byte offset...
* 2316 FIX: windows agent: fix garbled output of cached agent plugins...
* 2358 FIX: check_mk_agent.solaris: more correct computation of zfs used space...
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index 803a5a8..a02a267 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -157,6 +157,14 @@ telegram_list = {
'<ns1:querySpec><ns1:entity
type="HostSystem">%(esxhost)s</ns1:entity><ns1:maxSample>1</ns1:maxSample>%(counters)s'\
'<ns1:intervalId>20</ns1:intervalId></ns1:querySpec></ns1:QueryPerf>',
+ "networksystem":
+ '<ns1:RetrievePropertiesEx
xsi:type="ns1:RetrievePropertiesExRequestType">'\
+ '<ns1:_this
type="PropertyCollector">%(propertyCollector)s</ns1:_this><ns1:specSet>'\
+
'<ns1:propSet><ns1:type>HostNetworkSystem</ns1:type><all>0</all>'\
+
'<ns1:pathSet>networkInfo</ns1:pathSet></ns1:propSet>'\
+ '<ns1:objectSet><ns1:obj
type="HostNetworkSystem">networkSystem</ns1:obj>'\
+
'</ns1:objectSet></ns1:specSet><ns1:options></ns1:options></ns1:RetrievePropertiesEx>',
+
"esxhostdetails":
'<ns1:RetrievePropertiesEx
xsi:type="ns1:RetrievePropertiesExRequestType">'
'<ns1:_this
type="PropertyCollector">%(propertyCollector)s</ns1:_this><ns1:specSet><ns1:propSet>'\
@@ -778,6 +786,26 @@ if not error:
# Counters
###########################
if "counters" in query_objects:
+ # Get additional interface counter info, this only works when querying ESX
hosts
+ # TODO: get this info from the vcenter
+ net_extra_info = []
+ if opt_direct:
+ reply_code, reply_msg, reply_headers, networksystem_response =
query_server(telegram_list["networksystem"])
+ nic_objects =
get_pattern('<pnic><key>(.*?)</pnic>', networksystem_response)
+ for nic in nic_objects:
+ nic_if =
get_pattern('(.*?)</key><device>(.*?)</device>(.*)<mac>(.*?)</mac>',
nic)
+ try:
+ bandwidth_block = nic_if[0][2]
+ bandwidth =
get_pattern('</driver><linkSpeed><speedMb>(.*?)</speedMb>',
bandwidth_block)
+ net_extra_info.append("net.macaddress|%s|%s|mac" %
(nic_if[0][1], nic_if[0][3]))
+ if bandwidth:
+ net_extra_info.append("net.bandwidth|%s|%s|bytes" %
(nic_if[0][1], int(bandwidth[0]) * 1000000))
+ net_extra_info.append("net.state|%s|1|state" %
nic_if[0][1])
+ else:
+ net_extra_info.append("net.state|%s|2|state" %
nic_if[0][1])
+ except Exception, e:
+ continue
+
# Get counter syntax
counter_syntax_payload = telegram_list["perfcountersyntax"]
needed_ids = get_counters(systeminfo["apiVersion"])
@@ -795,6 +823,7 @@ if not error:
for key, nameInfo, groupInfo, unitInfo in elements:
counters_syntax[key] = { "name": nameInfo, "group":
groupInfo, "unit": unitInfo }
+
# We need to query each ESX host system separately..
hostnames = hostsystems.keys()
counter_data_payload = telegram_list["perfcounterdata"]
@@ -837,6 +866,9 @@ if not error:
value = counters_output[key]
print "%s.%s|%s|%s|%s" % (key + value)
+ for line in net_extra_info:
+ print line
+
if not opt_direct:
print '<<<<>>>>'
@@ -847,6 +879,7 @@ if not error:
hostsystems_properties = {}
hostsystems_sensors = {}
+
# Propsets
reply_code, reply_msg, reply_headers, esxhostdetails_response =
query_server(telegram_list["esxhostdetails"])
hostsystems_objects =
get_pattern('<objects>(.*?)</objects>', esxhostdetails_response)
diff --git a/checks/esx_vsphere_counters b/checks/esx_vsphere_counters
index 753d667..54727da 100644
--- a/checks/esx_vsphere_counters
+++ b/checks/esx_vsphere_counters
@@ -133,7 +133,10 @@ def convert_esx_counters_if(info):
if item and counter.startswith("net."):
name = counter[4:]
by_item.setdefault(item, {})
- by_item[item][name] = int(value)
+ if name != "macaddress":
+ by_item[item][name] = int(value)
+ else:
+ by_item[item][name] = value
# Example of by_item:
# {
@@ -154,6 +157,9 @@ def convert_esx_counters_if(info):
# 'transmitted': 134,
# 'unknownProtos': 0,
# 'usage': 4040,
+ # 'macaddress': 'AA:BB:CC:DD:EE:FF",
+ # 'state': 2,
+ # 'bandwidth': 10000000,
# },
# }
nics = by_item.keys()
@@ -206,13 +212,17 @@ def convert_esx_counters_if(info):
entry = ['0'] * 20
converted.append(entry)
if name: # Skip summary entry without interface name
- entry[0] = (str(index))
- entry[1] = (name)
- entry[2] = ('6') # Ethernet
- entry[3] = ('') # Speed not known
- entry[4] = ('1') # Assume up
- entry[18] = (name) # ifAlias
- entry[19] = ('') # MAC address not known here
+ entry[0] = str(index)
+ entry[1] = name
+ entry[2] = '6' # Ethernet
+ entry[3] = str(by_item[name].get("bandwidth", "")) #
Speed not known
+ entry[4] = str(by_item[name].get("state", "1"))
+ entry[18] = name # ifAlias
+ if by_item[name].get("macaddress"):
+ mac = "".join(map(lambda x: chr(int(x, 16)),
by_item[name]["macaddress"].split(':')))
+ entry[19] = mac
+ else:
+ entry[19] = '' # MAC address not known here
for ctr_name, ti in tableindex.items():
ctr_value = by_item[name].get(ctr_name, 0)
if ctr_name.startswith("bytes"):