Module: check_mk
Branch: master
Commit: 91cd714ad085537329a7b601c451708338530ed3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=91cd714ad08553…
Author: Marcel Schulte <ms(a)mathias-kettner.de>
Date: Tue May 9 16:05:09 2017 +0200
4567 FIX inventory of interfaces: prevent showing negative last_state_change value
On SNMP devices sysUpTime is a 32-bit counter and will roll over after 496 days.
ifLastChange is the timestamp from sysUpTime when the state changed. At
inventory time we got a negative value if sysUpTime was smaller then
ifLastChange (because it rolled over) using the normal formula. If sysUpTime is
smaller than ifLastChange we add 496 days for the rollover now.
When the device reboots all last_state_change values are set to 0 by the device
so those cases are not affected by the fix..
Beware there's no way to get the count of times the sysUpTime counter rolled
over so the last_state_change is not accurate in case it's in real more than 496
days ago. ...but this situation has never been different. This fix just removes
another error in shown values.
Change-Id: I885abb577f888598918067e4396c0af12801a98b
---
.werks/4567 | 23 +++++++++++++++++++++++
inventory/if | 10 ++++++++++
2 files changed, 33 insertions(+)
diff --git a/.werks/4567 b/.werks/4567
new file mode 100644
index 0000000..c4b564c
--- /dev/null
+++ b/.werks/4567
@@ -0,0 +1,23 @@
+Title: inventory of interfaces: prevent showing negative last_state_change value
+Level: 2
+Component: inv
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1494337855
+Class: fix
+
+On SNMP devices sysUpTime is a 32-bit counter and will roll over after 496 days.
+ifLastChange is the timestamp from sysUpTime when the state changed. At
+inventory time we got a negative value if sysUpTime was smaller then
+ifLastChange (because it rolled over) using the normal formula. If sysUpTime is
+smaller than ifLastChange we add 496 days for the rollover now.
+
+When the device reboots all last_state_change values are set to 0 by the device
+so those cases are not affected by the fix..
+
+Beware there's no way to get the count of times the sysUpTime counter rolled
+over so the last_state_change is not accurate in case it's in real more than 496
+days ago. ...but this situation has never been different. This fix just removes
+another error in shown values.
+
diff --git a/inventory/if b/inventory/if
index b24bc6a..dcc44f5 100644
--- a/inventory/if
+++ b/inventory/if
@@ -73,6 +73,16 @@ def inv_if(info, params):
if last_change > 0:
state_age = uptime - last_change
+
+ # Assume counter rollover in case uptime is less than last_change and
+ # add 497 days (counter maximum).
+ # This way no negative chenge times are shown anymore. The state change is
shown
+ # wrong in case it's really 497 days ago when state changed but
there's no way to
+ # get the count of rollovers since change (or since uptime) and it's
better the
+ # wrong negative state change is not shown anymore...
+ if state_age < 0:
+ state_age = 42949672 - last_change + uptime
+
else:
# Assume point of time of boot as last state change.
state_age = uptime