Module: check_mk
Branch: master
Commit: 5a42cbea2effea7e4b0c3a450b66aba98baebbe5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5a42cbea2effea…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri May 3 11:35:18 2013 +0200
uptime, snmp_uptime, esx_vsphere_counters.uptime: allow to set lower and upper levels
---
ChangeLog | 1 +
checkman/esx_vsphere_counters.uptime | 8 +++++++
checkman/snmp_uptime | 9 +++++++
checkman/uptime | 8 +++++++
checks/esx_vsphere_counters | 2 +-
checks/snmp_uptime | 44 +++++++++++++---------------------
checks/uptime | 2 +-
checks/uptime.include | 29 +++++++++++++++++++++-
web/plugins/wato/check_parameters.py | 28 ++++++++++++++++++++++
9 files changed, 101 insertions(+), 30 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 56818d9..1b801f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -87,6 +87,7 @@
* Check_MK check: enable extended performance data per default now
* viprinet checks: New checks for firmware version/update, memory usage, power supply
status,
router mode, serialnumber and temperature sensors
+ * uptime, snmp_uptime, esx_vsphere_counters.uptime: allow to set lower and upper
levels
Notifications:
* notify.py: unique spoolfiles name no longer created with uuid
diff --git a/checkman/esx_vsphere_counters.uptime b/checkman/esx_vsphere_counters.uptime
index 5ca8ed8..e0e8d80 100644
--- a/checkman/esx_vsphere_counters.uptime
+++ b/checkman/esx_vsphere_counters.uptime
@@ -13,3 +13,11 @@ perfdata:
inventory:
One check per system is created if the agent has a section
{<<<uptime>>>}.
+[parameters]
+parameters (dict): A dictionary with the following optional keys:
+
+ {"min"}: Pair of integers of warn and crit: the minimum required uptime
+ uptime in seconds.
+
+ {"max"}: Pair of integers of warn and crit: the maximum allowed uptime
+ uptime in seconds.
diff --git a/checkman/snmp_uptime b/checkman/snmp_uptime
index c6c64ca..dfad92c 100644
--- a/checkman/snmp_uptime
+++ b/checkman/snmp_uptime
@@ -15,3 +15,12 @@ perfdata:
inventory:
One check per system is created if the host provides that information.
+
+[parameters]
+parameters (dict): A dictionary with the following optional keys:
+
+ {"min"}: Pair of integers of warn and crit: the minimum required uptime
+ uptime in seconds.
+
+ {"max"}: Pair of integers of warn and crit: the maximum allowed uptime
+ uptime in seconds.
diff --git a/checkman/uptime b/checkman/uptime
index 2fa4d95..8961cb0 100644
--- a/checkman/uptime
+++ b/checkman/uptime
@@ -14,3 +14,11 @@ perfdata:
inventory:
One check per system is created if the agent has a section
{<<<uptime>>>}.
+[parameters]
+parameters (dict): A dictionary with the following optional keys:
+
+ {"min"}: Pair of integers of warn and crit: the minimum required uptime
+ uptime in seconds.
+
+ {"max"}: Pair of integers of warn and crit: the maximum allowed uptime
+ uptime in seconds.
diff --git a/checks/esx_vsphere_counters b/checks/esx_vsphere_counters
index 9d05388..c76f3af 100644
--- a/checks/esx_vsphere_counters
+++ b/checks/esx_vsphere_counters
@@ -254,7 +254,7 @@ check_info['esx_vsphere_counters.if'] = {
def inventory_esx_vsphere_counters_uptime(info):
for name, instance, counter, unit in info:
if name == "sys.uptime":
- return [ (None, None) ]
+ return [ (None, {}) ]
def check_esx_vsphere_counters_uptime(_no_item, params, info):
for name, instance, counter, unit in info:
diff --git a/checks/snmp_uptime b/checks/snmp_uptime
index 4147547..2a0c96d 100644
--- a/checks/snmp_uptime
+++ b/checks/snmp_uptime
@@ -28,36 +28,26 @@
def inventory_snmp_uptime(info):
if len(info) > 0 and len(info[0]) >= 1:
- return [ (None, None) ]
+ return [ (None, {}) ]
-def check_snmp_uptime(checktype, _no_params, info):
- if len(info) > 0 and len(info[0]) >= 1:
- ticks = info[0][0]
- try:
- uptime = int(ticks[:-2])
- except:
- days, h, m, s = ticks.split(":")
- uptime = (int(days) * 86400 ) + (int(h) * 3600) + (int(m) * 60) +
int(float(s))
+def check_snmp_uptime(checktype, params, info):
+ ticks = info[0][0]
+ try:
+ uptime = int(ticks[:-2])
+ except:
+ days, h, m, s = ticks.split(":")
+ uptime = (int(days) * 86400 ) + (int(h) * 3600) + (int(m) * 60) + int(float(s))
- days, rest = divmod(uptime, 60*60*24)
- hours, rest = divmod(rest, 60*60)
- minutes, seconds = divmod(rest, 60)
- now = int(time.time())
- since = time.strftime("%c", time.localtime(now - uptime))
- return (0, "up since %s (%dd %02d:%02d:%02d)" %
- (since, days, hours, minutes, seconds), [ ("uptime", uptime)
])
- else:
- return (3, "No data retrieved")
+ return check_uptime_seconds(params, uptime)
check_info["snmp_uptime"] = {
- 'check_function': check_snmp_uptime,
- 'inventory_function': inventory_snmp_uptime,
- 'service_description': 'Uptime',
- 'has_perfdata': True,
- # DISMAN-EVENT-MIB::sysUpTime
- 'snmp_info': ('.1.3.6.1.2.1.1', ['3.0']),
- # This check works on all SNMP hosts
- 'snmp_scan_function': lambda oid: oid(".1.3.6.1.2.1.1.1.0") !=
None,
- 'group': 'uptime',
+ 'check_function' : check_snmp_uptime,
+ 'inventory_function' : inventory_snmp_uptime,
+ 'service_description' : 'Uptime',
+ 'has_perfdata' : True,
+ 'snmp_info' : ('.1.3.6.1.2.1.1', ['3.0']), #
DISMAN-EVENT-MIB::sysUpTime
+ 'snmp_scan_function' : lambda oid: oid(".1.3.6.1.2.1.1.1.0") !=
None,
+ 'group' : 'uptime',
+ 'includes' : [ 'uptime.include' ],
}
diff --git a/checks/uptime b/checks/uptime
index 4cb63c6..f95ab5c 100644
--- a/checks/uptime
+++ b/checks/uptime
@@ -26,7 +26,7 @@
def inventory_uptime(info):
if len(info) >= 1 and len(info[0]) >= 1:
- return [ (None, None) ]
+ return [ (None, {}) ]
def check_uptime(_no_item, params, info):
return check_uptime_seconds(params, float(info[0][0]))
diff --git a/checks/uptime.include b/checks/uptime.include
index 91a0e59..2f2cd7d 100644
--- a/checks/uptime.include
+++ b/checks/uptime.include
@@ -25,6 +25,12 @@
# Boston, MA 02110-1301 USA.
+# Example for params:
+# {
+# "min" : ( 7200, 3600 ), # Minimum required uptime (warn, crit)
+# "max" : ( 86400 * 7, 86400 * 14), # Maximum required uptime (warn, crit)
+# }
+
def check_uptime_seconds(params, uptime):
seconds = uptime % 60
rem = uptime / 60
@@ -33,5 +39,26 @@ def check_uptime_seconds(params, uptime):
days = rem / 1440
now = int(time.time())
since = time.strftime("%c", time.localtime(now - uptime))
- return (0, "up since %s (%dd %02d:%02d:%02d)" % (since, days, hours,
minutes, seconds), [ ("uptime", uptime) ])
+ state = 0
+ infotext = "up since %s (%dd %02d:%02d:%02d)" % (since, days, hours,
minutes, seconds)
+
+ if "min" in params:
+ warn, crit = params["min"]
+ if uptime < crit:
+ state = 2
+ elif uptime < warn:
+ state = max(state, 1)
+ if state:
+ infotext += ", not up long enough!"
+
+ if "max" in params:
+ warn, crit = params["max"]
+ if uptime > crit:
+ state = 2
+ elif uptime > warn:
+ state = max(state, 1)
+ if uptime > warn:
+ infotext += ", up too long!"
+
+ return (state, infotext, [ ("uptime", uptime) ])
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 5fe61ff..5ba2002 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -659,6 +659,34 @@ register_check_parameters(
register_check_parameters(
subgroup_os,
+ "uptime",
+ _("Uptime (seconds since last reboot)"),
+ Dictionary(
+ elements = [
+ ( "min",
+ Tuple(
+ title = _("Minimum required uptime"),
+ elements = [
+ Age(title = _("Warning if below")),
+ Age(title = _("Critical if below")),
+ ]
+ )),
+ ( "max",
+ Tuple(
+ title = _("Maximum allowed uptime"),
+ elements = [
+ Age(title = _("Warning if above")),
+ Age(title = _("Critical if above")),
+ ]
+ )),
+ ]
+ ),
+ None,
+ "first",
+)
+
+register_check_parameters(
+ subgroup_os,
"systemtime",
_("Windows system time offset"),
Tuple(