Module: check_mk
Branch: master
Commit: 4c4933dea31970f05d9c55d0bf3045a2c9bd63ac
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4c4933dea31970…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Mon Feb 23 17:12:33 2015 +0100
cisco_temperature: New check to replace cisco_temp_perf and cisco_temp_sensor. Will not
yet inventorize.
---
checks/cisco_temperature | 165 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 165 insertions(+)
diff --git a/checks/cisco_temperature b/checks/cisco_temperature
new file mode 100644
index 0000000..a2d838d
--- /dev/null
+++ b/checks/cisco_temperature
@@ -0,0 +1,165 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2015 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+def parse_cisco_temp_temperature(info):
+ description_info, state_info, levels_info, perfstuff = info
+
+ # Parse OIDs described by CISCO-ENTITY-SENSOR-MIB
+ entity_parsed = {}
+
+ # Create dict of sensor descriptions
+ descriptions = dict(description_info)
+
+ # Create dict with thresholds
+ thresholds = {}
+ for sensor_id, sensortype, scalecode, magnitude, value, sensorstate in state_info:
+ thresholds.setdefault(sensor_id, [])
+
+ for endoid, level in levels_info:
+ level = float(level) / (10 ** int(magnitude))
+ # endoid is e.g. 21549.9 or 21459.10
+ sensor_id, subid = endoid.split('.')
+ thresholds.setdefault(sensor_id, []).append(level)
+
+ for sensor_id, sensortype, scalecode, magnitude, value, sensorstate in state_info:
+ descr = descriptions[sensor_id]
+ if descr and sensortype == '8':
+ entity_parsed[descr] = {}
+ scale = 10**int(magnitude)
+ if scalecode == '8':
+ scale *= 1000
+ entity_parsed[descr]['temp'] = float(value) / scale
+
+ if len(thresholds[sensor_id]) in [ 2, 4 ]:
+ warnraw, critraw = thresholds[sensor_id][0:2]
+ dev_levels = (float(warnraw)/scale, float(critraw)/scale)
+ else:
+ dev_levels = None
+ entity_parsed[descr]['dev_levels'] = dev_levels
+
+ if sensorstate == '2':
+ entity_parsed[descr]['unknown'] = (3, "Data from sensor
currently not available")
+ elif sensorstate == '3':
+ entity_parsed[descr]['unknown'] = (3, "Sensor is
broken")
+ entity_parsed[descr]['dev_status'] = None
+
+ # Now parse OIDs described by CISCO-ENVMON-MIB
+ envmon_states = {
+ '1': "normal",
+ '2': "warning",
+ '3': "critical",
+ '4': "shutdown",
+ '5': "not present",
+ '6': "not functioning"
+ }
+
+ parsed = {}
+ for statustext, temp, max_temp, state, oid_end in perfstuff:
+ item = cisco_sensor_item(statustext, oid_end)
+ parsed[item] = {}
+ parsed[item]['temp'] = int(temp)
+ if state in ['5', '6']:
+ parsed[item]['unknown'] = (3, "Sensor %s" %
envmon_states[state])
+ elif max_temp and int(max_temp):
+ parsed[item]['dev_status'] = None
+ parsed[item]['dev_levels'] = (int(max_temp), int(max_temp))
+ else:
+ parsed[item]['dev_levels'] = None
+ if state == '1':
+ parsed[item]['dev_status'] = 0
+ elif state == '2':
+ parsed[item]['dev_status'] = 1
+ elif state in '34':
+ parsed[item]['dev_status'] = 2
+ else:
+ parsed[item]['unknown'] = (3, "Sensor reports unknown status
code")
+
+ # Merge the two dicts, preferring keys generated from ENTITY data
+ parsed.update(entity_parsed)
+
+ return parsed
+
+
+def inventory_cisco_temp_temperature(parsed):
+ for item in parsed.keys():
+ yield item, None
+
+
+def check_cisco_temp_temperature(item, params, parsed):
+ if item in parsed:
+ if parsed[item].get('unknown', None):
+ return parsed[item]['unknown']
+ else:
+ return check_temperature(parsed[item]['temp'], params,
+ dev_levels = parsed[item]['dev_levels'],
+ dev_status = parsed[item]['dev_status'])
+
+
+check_info['cisco_temp_temperature'] = {
+ "parse_function" : parse_cisco_temp_temperature,
+ "inventory_function" : inventory_cisco_temp_temperature,
+ "check_function" : check_cisco_temp_temperature,
+ "service_description": "Temperature %s",
+ "group" : "temperature",
+ "has_perfdata" : True,
+ "snmp_scan_function" : lambda oid: False,
+# "snmp_scan_function" : lambda oid: True, #lambda oid: "cisco" in
oid(".1.3.6.1.2.1.1.1.0").lower() and \
+# # ( oid(".1.3.6.1.4.1.9.9.91.1.1.1.1.*") !=
None or
+# # oid(".1.3.6.1.4.1.9.9.13.1.3.1.3.*") !=
None ),
+ "snmp_info" : [
+ # cisco_temp_sensor data
+ ( ".1.3.6.1.2.1.47.1.1.1.1", [
+ OID_END,
+ 2, # Description of the sensor
+ ]),
+
+ # Type and current state
+ ( ".1.3.6.1.4.1.9.9.91.1.1.1.1", [
+ OID_END,
+ 1, # Type (see above), 8 = Celsius, 12 = truth value
+ 2, # scalecode, 8 == milli
+ 3, # Precision
+ 4, # Most recent measurement
+ 5, # Status of the sensor 1 == ok, 2 == cannot report, 3
== broken
+ ]),
+
+ # Threshold
+ ( ".1.3.6.1.4.1.9.9.91.1.2.1.1", [
+ OID_END,
+ 4, # Thresholds
+ ]),
+
+ # cisco_temp_perf data
+ ( ".1.3.6.1.4.1.9.9.13.1.3.1", [ # CISCO-SMI
+ 2, #
ciscoEnvMonTemperatureStatusDescr
+ 3, #
ciscoEnvMonTemperatureStatusValue
+ 4, #
ciscoEnvMonTemperatureThreshold
+ 6, #
ciscoEnvMonTemperatureState
+ OID_END
+ ]),
+ ],
+ "includes" : [ "temperature.include",
'cisco_sensor_item.include' ],
+}