Module: check_mk
Branch: master
Commit: c28509a3b7e8776d4f0d89c90ad8cc0e39c9d69b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c28509a3b7e877…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu May 24 14:45:54 2018 +0200
Add HW/SW inventory function and make parse function available.
Change-Id: I9d2ccb9cffd16f8ecc9c5632016ac9dd238e1759
---
checks/allnet_ip_sensoric | 74 +++++++++++++++++++++-----------------------
inventory/allnet_ip_sensoric | 38 +++++++++++++++++++++++
2 files changed, 73 insertions(+), 39 deletions(-)
diff --git a/checks/allnet_ip_sensoric b/checks/allnet_ip_sensoric
index 70b48af..91889d2 100644
--- a/checks/allnet_ip_sensoric
+++ b/checks/allnet_ip_sensoric
@@ -26,8 +26,6 @@
# Example output from agent:
-# <<<check_mk>>>
-# AgentOS:;ALL5000
# <<<allnet_ip_sensoric:sep(59)>>>
# sensor0.alarm0;0
# sensor0.all4000_typ;0
@@ -70,28 +68,28 @@
# system.sys;114854
# system.time;16:08:48
-# parses agent output in a structure like:
-# {'sensor0': {'alarm0': '0',
-# 'all4000_typ': '0',
-# 'function': '1',
-# 'limit_high': '50.00',
-# 'limit_low': '10.00',
-# 'maximum': '28.56',
-# 'minimum': '27.43',
-# 'name': 'Temperatur intern',
-# 'value_float': '27.50',
-# 'value_int': '2750',
-# 'value_string': '27.50'},
-# [...]
-# 'system': {'alarmcount': '4',
-# 'date': '30.06.2014',
-# 'devicename': 'all5000',
-# 'devicetype': 'ALL5000',
-# 'sys': '116240',
-# 'time': '16:57:50'}}
-
-def allnet_ip_sensoric_parse(info):
+def parse_allnet_ip_sensoric(info):
+ '''parses agent output in a structure like:
+ {'sensor0': {'alarm0': '0',
+ 'all4000_typ': '0',
+ 'function': '1',
+ 'limit_high': '50.00',
+ 'limit_low': '10.00',
+ 'maximum': '28.56',
+ 'minimum': '27.43',
+ 'name': 'Temperatur intern',
+ 'value_float': '27.50',
+ 'value_int': '2750',
+ 'value_string': '27.50'},
+ [...]
+ 'system': {'alarmcount': '4',
+ 'date': '30.06.2014',
+ 'devicename': 'all5000',
+ 'devicetype': 'ALL5000',
+ 'sys': '116240',
+ 'time': '16:57:50'}}
+ '''
parsed = {}
for key, value in info:
match = re.search('(\w+)\.(\w+)', key)
@@ -103,6 +101,7 @@ def allnet_ip_sensoric_parse(info):
return parsed
+
def allnet_ip_sensoric_compose_item(sensor_id, sensor):
sensor_id = re.sub("sensor", "", sensor_id)
if "name" in sensor.keys():
@@ -120,8 +119,7 @@ def allnet_ip_sensoric_compose_item(sensor_id, sensor):
# | |
# '----------------------------------------------------------------------'
-def inventory_allnet_ip_sensoric_tension(info):
- parsed = allnet_ip_sensoric_parse(info)
+def inventory_allnet_ip_sensoric_tension(parsed):
inventory = []
for sensor in parsed.keys():
if "function" in parsed[sensor].keys() and
parsed[sensor]["function"] == "12":
@@ -129,8 +127,7 @@ def inventory_allnet_ip_sensoric_tension(info):
inventory.append( (item, None) )
return inventory
-def check_allnet_ip_sensoric_tension(item, _no_params, info):
- parsed = allnet_ip_sensoric_parse(info)
+def check_allnet_ip_sensoric_tension(item, _no_params, parsed):
sensor_id = "sensor" + re.sub(".+Sensor ", "", item)
if sensor_id not in parsed.keys():
@@ -167,16 +164,14 @@ factory_settings["allnet_ip_sensoric_temp_default_levels"]
= {
"levels" : (35, 40)
}
-def inventory_allnet_ip_sensoric_temp(info):
- parsed = allnet_ip_sensoric_parse(info)
+def inventory_allnet_ip_sensoric_temp(parsed):
for sensor in parsed.keys():
if (parsed[sensor].get('function') and
parsed[sensor]["function"] == "1") \
or (parsed[sensor].get('unit') and parsed[sensor]['unit'] ==
u'°C'):
item = allnet_ip_sensoric_compose_item(sensor, parsed[sensor])
yield item, {}
-def check_allnet_ip_sensoric_temp(item, params, info):
- parsed = allnet_ip_sensoric_parse(info)
+def check_allnet_ip_sensoric_temp(item, params, parsed):
sensor_id = "sensor" + re.sub(".+Sensor ", "", item)
if sensor_id not in parsed.keys():
@@ -208,8 +203,7 @@ check_info["allnet_ip_sensoric.temp"] = {
allnet_ip_sensoric_humidity_default_levels = ( 35, 40, 60, 65 )
-def inventory_allnet_ip_sensoric_humidity(info):
- parsed = allnet_ip_sensoric_parse(info)
+def inventory_allnet_ip_sensoric_humidity(parsed):
inventory = []
for sensor in parsed.keys():
if "function" in parsed[sensor].keys() and
parsed[sensor]["function"] == "2":
@@ -217,8 +211,7 @@ def inventory_allnet_ip_sensoric_humidity(info):
inventory.append( (item,
"allnet_ip_sensoric_humidity_default_levels") )
return inventory
-def check_allnet_ip_sensoric_humidity(item, params, info):
- parsed = allnet_ip_sensoric_parse(info)
+def check_allnet_ip_sensoric_humidity(item, params, parsed):
sensor_id = "sensor" + re.sub(".+Sensor ", "", item)
if sensor_id not in parsed.keys():
return 3, "%s not found in agent output" % item
@@ -244,8 +237,7 @@ check_info["allnet_ip_sensoric.humidity"] = {
# | |_| |
# '----------------------------------------------------------------------'
-def inventory_allnet_ip_sensoric_pressure(info):
- parsed = allnet_ip_sensoric_parse(info)
+def inventory_allnet_ip_sensoric_pressure(parsed):
inventory = []
for sensor in parsed.keys():
if "function" in parsed[sensor].keys() and
parsed[sensor]["function"] == "16":
@@ -253,8 +245,7 @@ def inventory_allnet_ip_sensoric_pressure(info):
inventory.append( (item, None) )
return inventory
-def check_allnet_ip_sensoric_pressure(item, _no_params, info):
- parsed = allnet_ip_sensoric_parse(info)
+def check_allnet_ip_sensoric_pressure(item, _no_params, parsed):
sensor_id = "sensor" + re.sub(".+Sensor ", "", item)
if sensor_id not in parsed.keys():
@@ -274,3 +265,8 @@ check_info["allnet_ip_sensoric.pressure"] = {
}
#.
+
+check_info["allnet_ip_sensoric"] = {
+ "parse_function": parse_allnet_ip_sensoric,
+}
+
diff --git a/inventory/allnet_ip_sensoric b/inventory/allnet_ip_sensoric
new file mode 100644
index 0000000..2caac6d
--- /dev/null
+++ b/inventory/allnet_ip_sensoric
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2018 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-
+# tails. 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 inv_allnet_ip_sensoric(parsed, inventory_tree):
+
+ model = parsed.get("system", {}).get("devicetype")
+ if model:
+ node = inventory_tree.get_dict("hardware.system.")
+ node["model"] = model
+
+
+inv_info['allnet_ip_sensoric'] = {
+ 'inv_function' : inv_allnet_ip_sensoric,
+}