Module: check_mk
Branch: master
Commit: 9bade4d20bd1ac84ffc9862dd1365594f5d9dac1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9bade4d20bd1ac…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Apr 15 16:44:39 2013 +0200
New check for uptime of ESX host
---
agents/special/agent_vsphere | 7 +++++-
checkman/esx_vsphere_counters.if | 2 +-
checkman/esx_vsphere_counters.uptime | 15 ++++++++++++
checks/esx_vsphere_counters | 44 ++++++++++++++++++++++++++++++++++
checks/uptime | 14 +++--------
checks/uptime.include | 37 ++++++++++++++++++++++++++++
web/plugins/perfometer/check_mk.py | 3 ++-
7 files changed, 108 insertions(+), 14 deletions(-)
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index fa1de68..2b9b8f8 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -238,7 +238,12 @@ def output_hostsystem_counters():
# a couple of seconds...
# counterids = pm.get_entity_counters(mor)
# needed_ids = counterids.keys() # retrieve all ids....
- needed_ids = [196616, 196621, 196617, 196625, 196619, 196623, 196609, 196614,
196620, 196624, 196615, 196622, 196618, 196612, 196613, 196626]
+ needed_ids = [ \
+ # net.*
+ 196616, 196621, 196617, 196625, 196619, 196623, 196609, 196614, 196620,
196624, 196615, 196622, 196618, 196612, 196613, 196626,
+ # uptime
+ 262144,
+ ]
counters = pm.get_entity_statistic(mor, needed_ids)
lines = []
for counter in counters:
diff --git a/checkman/esx_vsphere_counters.if b/checkman/esx_vsphere_counters.if
index 83a8b8c..abe3414 100644
--- a/checkman/esx_vsphere_counters.if
+++ b/checkman/esx_vsphere_counters.if
@@ -1,5 +1,5 @@
title: Physical network interfaces on VMWare ESX host
-agents: esx
+agents: vsphere
author: Mathias Kettner <mk(a)mathias-kettner.de>
license: GPL
distribution: check_mk
diff --git a/checkman/esx_vsphere_counters.uptime b/checkman/esx_vsphere_counters.uptime
new file mode 100644
index 0000000..5ca8ed8
--- /dev/null
+++ b/checkman/esx_vsphere_counters.uptime
@@ -0,0 +1,15 @@
+title: Uptime of ESX host system
+agents: vsphere
+author: Mathias Kettner <mk(a)mathias-kettner.de>
+license: GPL
+distribution: check_mk
+description:
+ This check is always OK and simply outputs the uptime of an ESX host
+ system.
+
+perfdata:
+ The uptime in seconds.
+
+inventory:
+ One check per system is created if the agent has a section
{<<<uptime>>>}.
+
diff --git a/checks/esx_vsphere_counters b/checks/esx_vsphere_counters
index ba0883f..4ff8599 100644
--- a/checks/esx_vsphere_counters
+++ b/checks/esx_vsphere_counters
@@ -47,6 +47,18 @@
# net.droppedRx||0|number
# net.droppedTx|vmnic0|0|number
# net.droppedTx|vmnic1|0|number
+# ...
+# sys.uptime||630664|second
+
+
+# .--Interfaces----------------------------------------------------------.
+# | ___ _ __ |
+# | |_ _|_ __ | |_ ___ _ __ / _| __ _ ___ ___ ___ |
+# | | || '_ \| __/ _ \ '__| |_ / _` |/ __/ _ \/ __| |
+# | | || | | | || __/ | | _| (_| | (_| __/\__ \ |
+# | |___|_| |_|\__\___|_| |_| \__,_|\___\___||___/ |
+# | |
+# '----------------------------------------------------------------------'
# The bad thing here: ESX does not send *counters* but *rates*. This might
# seem user friendly on the first look, but is really bad at the second. The
@@ -176,3 +188,35 @@ check_info['esx_vsphere_counters.if'] = {
'default_levels_variable' : 'if_default_levels',
'includes' : [ 'if.include' ],
}
+
+#.
+# .--Uptime--------------------------------------------------------------.
+# | _ _ _ _ |
+# | | | | |_ __ | |_(_)_ __ ___ ___ |
+# | | | | | '_ \| __| | '_ ` _ \ / _ \ |
+# | | |_| | |_) | |_| | | | | | | __/ |
+# | \___/| .__/ \__|_|_| |_| |_|\___| |
+# | |_| |
+# '----------------------------------------------------------------------'
+
+def inventory_esx_vsphere_counters_uptime(info):
+ for name, instance, counter, unit in info:
+ if name == "sys.uptime":
+ return [ (None, None) ]
+
+def check_esx_vsphere_counters_uptime(_no_item, params, info):
+ for name, instance, counter, unit in info:
+ if name == "sys.uptime":
+ return check_uptime_seconds(params, int(counter))
+ return 3, "No uptime information found in agent output"
+
+
+check_info['esx_vsphere_counters.uptime'] = {
+ 'inventory_function' : inventory_esx_vsphere_counters_uptime,
+ 'check_function' : check_esx_vsphere_counters_uptime,
+ 'service_description': 'Uptime',
+ 'has_perfdata': True,
+ 'includes': ['uptime.include'],
+ 'group': 'uptime',
+}
+
diff --git a/checks/uptime b/checks/uptime
index 589c7b7..4cb63c6 100644
--- a/checks/uptime
+++ b/checks/uptime
@@ -28,17 +28,8 @@ def inventory_uptime(info):
if len(info) >= 1 and len(info[0]) >= 1:
return [ (None, None) ]
-def check_uptime(_no_item, _no_params, info):
- uptime = int(float(info[0][0]))
- seconds = uptime % 60
- rem = uptime / 60
- minutes = rem % 60
- hours = (rem % 1440) / 60
- 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) ])
-
+def check_uptime(_no_item, params, info):
+ return check_uptime_seconds(params, float(info[0][0]))
check_info["uptime"] = {
@@ -46,5 +37,6 @@ check_info["uptime"] = {
'inventory_function': inventory_uptime,
'service_description': 'Uptime',
'has_perfdata': True,
+ 'includes': [ 'uptime.include' ],
'group': 'uptime',
}
diff --git a/checks/uptime.include b/checks/uptime.include
new file mode 100644
index 0000000..91a0e59
--- /dev/null
+++ b/checks/uptime.include
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 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 check_uptime_seconds(params, uptime):
+ seconds = uptime % 60
+ rem = uptime / 60
+ minutes = rem % 60
+ hours = (rem % 1440) / 60
+ 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) ])
+
diff --git a/web/plugins/perfometer/check_mk.py b/web/plugins/perfometer/check_mk.py
index 7329f54..560e654 100644
--- a/web/plugins/perfometer/check_mk.py
+++ b/web/plugins/perfometer/check_mk.py
@@ -386,7 +386,7 @@ perfometers["check_mk-hpux_snmp_cs.cpu"] =
perfometer_hpux_snmp_cs_cpu
def perfometer_check_mk_uptime(row, check_command, perf_data):
- days, rest = divmod(int(perf_data[0][1]), 60*60*24)
+ days, rest = divmod(int(float(perf_data[0][1])), 60*60*24)
hours, rest = divmod(rest, 60*60)
minutes, seconds = divmod(rest, 60)
@@ -394,6 +394,7 @@ def perfometer_check_mk_uptime(row, check_command, perf_data):
perfometers["check_mk-uptime"] = perfometer_check_mk_uptime
perfometers["check_mk-snmp_uptime"] = perfometer_check_mk_uptime
+perfometers["check_mk-esx_vsphere_counters.uptime"] =
perfometer_check_mk_uptime
def perfometer_check_mk_diskstat(row, check_command, perf_data):