Module: check_mk
Branch: master
Commit: 27552f55f25eafe2daab7bea214ef58fb5087f0b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=27552f55f25eaf…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Sep 2 13:00:10 2013 +0200
snmp: Added timestamp parsing
---
modules/check_mk.py | 11 +----------
modules/snmp.py | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index f022468..96723a3 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -3901,16 +3901,7 @@ def do_snmpwalk_on(hostname, filename):
sys.stdout.flush()
results = snmpwalk_on_suboid(hostname, oid, strip_values = False)
for oid, value in results:
- # FIXME: Need to parse some datatypes to have a compatible data format
- # with older versions:
- # .1.3.6.1.2.1.1.3.0 0:1:43:32.82
- # ->
- # .1.3.6.1.2.1.1.3.0 620972
- #
- # .1.3.6.1.2.1.1.8.0 0:0:00:00.00
- # ->
- # .1.3.6.1.2.1.1.8.0 0
- out.write("%s %s\n" % (oid, value.strip()))
+ out.write("%s %s\n" % (oid, value))
if opt_verbose:
sys.stdout.write("%d variables.\n" % len(results))
diff --git a/modules/snmp.py b/modules/snmp.py
index 638b4f5..7f982c5 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -30,6 +30,14 @@ OID_END = 0
OID_STRING = -1
OID_BIN = -2
+# 0:2:01:20.13 -> seconds
+def parse_snmp_ticks(value):
+ days, hours, minutes, seconds = map(float, value.split(':'))
+ seconds += days * 8640000
+ seconds += hours * 360000
+ seconds += minutes * 6000
+ return seconds
+
def strip_snmp_value(value):
v = value.strip()
if v.startswith('"'):
@@ -148,8 +156,13 @@ def snmpwalk_on_suboid(hostname, oid, strip_values = True):
continue
this_oid = var.tag + '.' + var.iid
- if strip_values:
+
+ if var.type == 'TICKS':
+ value = parse_snmp_ticks(var.val)
+
+ elif strip_values:
value = strip_snmp_value(var.val)
+
else:
value = var.val