Module: check_mk
Branch: master
Commit: 142b2054eb5a43d7de296368f7271a189738e7bf
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=142b2054eb5a43…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue May 31 16:47:52 2016 +0200
3585 Implemented API for exporting the full host inventory
The HW/SW inventory data can now be exported using a webservice. This webservice
outputs the raw structured inventory data of a host.
The URL to this webservice is <tt>http://[MONITORING-SERVER]/[SITE]/check_mk/host_inv_api.py?host=[HOST]&outp…</tt>.
You choose one of these output formats: <tt>json</tt>, <tt>xml</tt>, <tt>python</tt>.
The data provided by this webservice looks as follows:
C+:
{
"result": {
"hardware": {
"memory": {
"total_ram_usable": 16697331712,
"total_swap": 17049841664,
"total_vmalloc": 35184372087808
}
},
"networking": {
"hostname": "Klappspaten"
}
},
"result_code": 0
}
C-:
The data below the key <tt>result</tt> is the HW/SW inventory data.
In case an error occurs during processing of the request, for example a host can not be found,
the <tt>result_code</tt> is set to 1 and the result contains the error message:
C+:
{"result": "Found no inventory data for this host.", "result_code": 1}
C+:
---
.werks/3585 | 44 ++++++++++++++++++++++++++
ChangeLog | 1 +
web/htdocs/htmllib.py | 3 ++
web/htdocs/inventory.py | 70 +++++++++++++++++++++++++++++++++++++++++-
web/htdocs/webapi.py | 2 --
web/plugins/pages/shipped.py | 2 ++
6 files changed, 119 insertions(+), 3 deletions(-)
diff --git a/.werks/3585 b/.werks/3585
new file mode 100644
index 0000000..ccdacac
--- /dev/null
+++ b/.werks/3585
@@ -0,0 +1,44 @@
+Title: Implemented API for exporting the full host inventory
+Level: 2
+Component: inv
+Class: feature
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1464704941
+
+The HW/SW inventory data can now be exported using a webservice. This webservice
+outputs the raw structured inventory data of a host.
+
+The URL to this webservice is <tt>http://[MONITORING-SERVER]/[SITE]/check_mk/host_inv_api.py?host=[HOST]&outp…</tt>.
+
+You choose one of these output formats: <tt>json</tt>, <tt>xml</tt>, <tt>python</tt>.
+
+The data provided by this webservice looks as follows:
+
+C+:
+{
+ "result": {
+ "hardware": {
+ "memory": {
+ "total_ram_usable": 16697331712,
+ "total_swap": 17049841664,
+ "total_vmalloc": 35184372087808
+ }
+ },
+ "networking": {
+ "hostname": "Klappspaten"
+ }
+ },
+ "result_code": 0
+}
+C-:
+
+The data below the key <tt>result</tt> is the HW/SW inventory data.
+
+In case an error occurs during processing of the request, for example a host can not be found,
+the <tt>result_code</tt> is set to 1 and the result contains the error message:
+
+C+:
+{"result": "Found no inventory data for this host.", "result_code": 1}
+C+:
diff --git a/ChangeLog b/ChangeLog
index e13d1f1..6bf595a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -473,6 +473,7 @@
* 3028 statgrab_mem, solaris_mem: updated inventory plugins for solaris systems...
* 3447 mssql_versions: Added inventory plugin for MSSQL instances
* 3581 mssql_versions: Added product name to inventory information
+ * 3585 Implemented API for exporting the full host inventory...
* 3219 FIX: lnx_distro: Now detecting Oracle VM Server correctly
* 3229 FIX: lnx_distro: SLES based systems have now an OS name inventorized\
* 3265 FIX: mk_inventory.solaris: fix problem on Solaris 10, do prtdiag and prtpicl only in global zone
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index a42ffbb..bea4704 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -192,6 +192,9 @@ class html(GUITester):
elif f == "html":
content_type = "text/html; charset=UTF-8"
+ elif f == "xml":
+ content_type = "text/xml; charset=UTF-8"
+
elif f == "pdf":
content_type = "application/pdf"
diff --git a/web/htdocs/inventory.py b/web/htdocs/inventory.py
index 595ff5a..3758dfc 100644
--- a/web/htdocs/inventory.py
+++ b/web/htdocs/inventory.py
@@ -25,7 +25,16 @@
# Boston, MA 02110-1301 USA.
import defaults, re, os
-from lib import MKGeneralException
+
+try:
+ import simplejson as json
+except ImportError:
+ import json
+
+
+import config
+import sites
+from lib import MKException, MKGeneralException, lqencode
# Load data of a host, cache it in the current HTTP request
def host(hostname):
@@ -286,3 +295,62 @@ def count_items(tree):
return sum(map(count_items, tree))
else:
return 1
+
+
+# The response is always a top level dict with two elements:
+# a) result_code - This is 0 for expected processing and 1 for an error
+# b) result - In case of an error this is the error message, a UTF-8 encoded string.
+# In case of success this is a dictionary containing the host inventory.
+def page_host_inv_api():
+ try:
+ host_name = html.var("host")
+ if not may_see(host_name):
+ raise MKAuthException(_("Sorry, you are not allowed to access this host."))
+
+ host_inv = host(host_name)
+
+ if not host_inv and not has_inventory(host_name):
+ raise MKGeneralException(_("Found no inventory data for this host."))
+
+ response = { "result_code": 0, "result": host_inv }
+
+ except MKException, e:
+ response = { "result_code": 1, "result": "%s" % e }
+
+ except Exception, e:
+ if config.debug:
+ raise
+ response = { "result_code": 1, "result": "%s" % e }
+
+ if html.output_format == "json":
+ write_json(response)
+ elif html.output_format == "xml":
+ write_xml(response)
+ else:
+ write_python(response)
+
+
+def may_see(host_name):
+ if config.may("general.see_all"):
+ return True
+
+ return sites.live().query_value("GET hosts\nStats: state >= 0\nFilter: name = %s\n" % lqencode(host_name)) > 0
+
+
+def write_xml(response):
+ try:
+ import dicttoxml
+ except ImportError:
+ raise MKGeneralException(_("You need to have the \"dicttoxml\" python module installed to "
+ "be able to use the XML format."))
+
+ html.write(dicttoxml.dicttoxml(response))
+
+
+def write_json(response):
+ html.write(json.dumps(response,
+ sort_keys=True, indent=4, separators=(',', ': ')))
+
+
+def write_python(response):
+ html.write(repr(response))
diff --git a/web/htdocs/webapi.py b/web/htdocs/webapi.py
index 5b09b20..200c110 100644
--- a/web/htdocs/webapi.py
+++ b/web/htdocs/webapi.py
@@ -101,5 +101,3 @@ def page_api():
else:
html.set_output_format("python")
html.write(repr(response))
-
-
diff --git a/web/plugins/pages/shipped.py b/web/plugins/pages/shipped.py
index 80f5fd5..1f26d67 100644
--- a/web/plugins/pages/shipped.py
+++ b/web/plugins/pages/shipped.py
@@ -44,6 +44,7 @@ import visuals
import crash_reporting
import metrics
import werks
+import inventory
# map URLs to page rendering functions
@@ -61,6 +62,7 @@ pagehandlers.update({
"ajax_set_viewoption" : views.ajax_set_viewoption,
"view" : views.page_view,
"ajax_inv_render_tree" : views.ajax_inv_render_tree,
+ "host_inv_api" : inventory.page_host_inv_api,
"host_service_graph_popup" : metrics.page_host_service_graph_popup,
"graph_dashlet" : metrics.page_graph_dashlet,
"ajax_set_rowselection" : weblib.ajax_set_rowselection,
Module: check_mk
Branch: master
Commit: f747dcc2f300cfe0b64fc35c25455e92a7ad1fe0
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f747dcc2f300cf…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue May 31 15:43:31 2016 +0200
3632 oracle_performance: new check which displays some statistics of ORACLE DBs
To make this check work you have to install <tt>mk_oracle</tt> plugin.
These statistics include physical IO, DB time, buffer pool and library cache
statistics, buffer and library cache hit ratio.
---
.werks/3632 | 11 +++
ChangeLog | 1 +
checkman/oracle_performance | 16 +++++
checks/oracle_performance | 143 +++++++++++++++++++++++++++++++++++++++
web/plugins/metrics/check_mk.py | 78 +++++++++++++++++++++
5 files changed, 249 insertions(+)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=f747dcc2f3…
Module: check_mk
Branch: master
Commit: b843b998f5b978258119f093897e12e612f4f33b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b843b998f5b978…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue May 31 13:44:06 2016 +0200
3631 cisco_fru_powerusage: new check which monitors the current and power of Cisco Core Switches which support the CISCO-ENTITY-FRU-CONTROL MIB
---
.werks/3631 | 9 ++++
ChangeLog | 1 +
checkman/cisco_fru_powerusage | 21 ++++++++
checks/cisco_fru_powerusage | 106 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 137 insertions(+)
diff --git a/.werks/3631 b/.werks/3631
new file mode 100644
index 0000000..4a04d7f
--- /dev/null
+++ b/.werks/3631
@@ -0,0 +1,9 @@
+Title: cisco_fru_powerusage: new check which monitors the current and power of Cisco Core Switches which support the CISCO-ENTITY-FRU-CONTROL MIB
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.9i1
+Date: 1464695005
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 8cdf0c0..dbafec2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -94,6 +94,7 @@
* 3138 jolokia_metrics.cache_hits, jolokia_metrics.in_memory, jolokia_metrics.off_heap, jolokia_metrics.on_disk, jolokia_metrics.writer: added checks for monitoring of ehcache metrics through jolokia...
* 3628 emcvnx_mirrorview: new check which monitors the mirrorviews of EMC VNX storage system...
* 3629 gude_relayport: new check which monitors the ON/OFF state of a GUDE Power Control device
+ * 3631 cisco_fru_powerusage: new check which monitors the current and power of Cisco Core Switches which support the CISCO-ENTITY-FRU-CONTROL MIB
* 3073 FIX: windows agent: relative paths to mrpe scripts are now treated as relative to the agent installation directory...
* 3061 FIX: mk_jolokia: Fixed debugging of the agent plugin
* 3074 FIX: windows agent: fixed incorrect values for 32-bit performance counters
diff --git a/checkman/cisco_fru_powerusage b/checkman/cisco_fru_powerusage
new file mode 100644
index 0000000..6c1c575
--- /dev/null
+++ b/checkman/cisco_fru_powerusage
@@ -0,0 +1,21 @@
+title: Cisco Core Switches: Power usage
+agents: snmp
+catalog: hw/network/cisco
+license: GPL
+distribution: check_mk
+description:
+ This check monitors the voltage, current and power usage
+ of Cisco Core Switches which support the
+ CISCO-ENTITY-FRU-CONTROL MIB.
+
+ There are no default levels set. Lower levels for voltage,
+ and upper levels for current and power can be configured.
+
+ Please note: voltage is shown as an information, it's determine
+ by the device itself: cefcPowerUnits from above MIB.
+
+item:
+ Can be system total or drawn or inline total or drawn.
+
+inventory:
+ One service per phase is created.
diff --git a/checks/cisco_fru_powerusage b/checks/cisco_fru_powerusage
new file mode 100644
index 0000000..96118d5
--- /dev/null
+++ b/checks/cisco_fru_powerusage
@@ -0,0 +1,106 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2016 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.
+
+
+# .1.3.6.1.4.1.9.9.117.1.1.1.1.2.16 "centiAmpsAt12V"
+# some more examples (but we dont know all):
+# milliAmps12v
+# centiAmpsAt12V
+# Amps @ 12V
+# CentiAmps @ 12V
+# Amps @ 50
+# => calculate power = factor * amps * volt
+
+# .1.3.6.1.4.1.9.9.117.1.1.4.1.1.16 11333
+# .1.3.6.1.4.1.9.9.117.1.1.4.1.2.16 9666
+# .1.3.6.1.4.1.9.9.117.1.1.4.1.3.16 6000
+# .1.3.6.1.4.1.9.9.117.1.1.4.1.4.16 122
+
+# .1.3.6.1.4.1.9.9.117.1.1.4.1.1.13 11333
+# .1.3.6.1.4.1.9.9.117.1.1.4.1.2.13 5583
+# .1.3.6.1.4.1.9.9.117.1.1.4.1.3.13 6980
+# .1.3.6.1.4.1.9.9.117.1.1.4.1.4.13 0 <= exclude
+
+
+def parse_cisco_fru_powerusage(info):
+ powerunit, powervals = info
+ oidend, powerunit_str = powerunit[0]
+ factor_str, voltage_str = powerunit_str.lower().split("amps")
+
+ if "milli" in factor_str.lower():
+ factor = 0.001
+ elif "centi" in factor_str.lower():
+ factor = 0.01
+ else:
+ factor = 1.0
+
+ voltage = float(voltage_str.lower().replace("at", "").\
+ replace("@", "").replace("v", "").strip())
+
+ parsed = {}
+ if oidend == powervals[0][0]:
+ system_total, system_drawn, inline_total, inline_drawn = map(float, powervals[0][1:])
+ for what, val in [
+ ("system total", system_total), # Gesamtstrom
+ ("system drawn", system_drawn), # aufgenommene Gesamtstromstaerke
+ ("inline total", inline_total),
+ ("inline drawn", inline_drawn)]:
+ parsed.setdefault(what, {
+ "power" : factor * val * voltage,
+ "current" : factor * val,
+ "voltage" : voltage,
+ })
+
+ return parsed
+
+
+def inventory_cisco_fru_powerusage(parsed):
+ for what, data in parsed.items():
+ if data["current"] > 0:
+ yield what, {}
+
+
+check_info['cisco_fru_powerusage'] = {
+ 'parse_function' : parse_cisco_fru_powerusage,
+ 'inventory_function' : inventory_cisco_fru_powerusage,
+ 'check_function' : check_elphase,
+ 'service_description' : 'FRU power usage %s',
+ 'has_perfdata' : True,
+ 'snmp_info' : [(".1.3.6.1.4.1.9.9.117.1.1.1.1.2", [
+ OID_END,
+ "", # CISCO-ENTITY-FRU-CONTROL-MIB::cefcPowerUnits
+ ]),
+ (".1.3.6.1.4.1.9.9.117.1.1.4.1", [
+ OID_END,
+ "1", # CISCO-ENTITY-FRU-CONTROL-MIB::cefcFRUTotalSystemCurrent
+ "2", # CISCO-ENTITY-FRU-CONTROL-MIB::cefcFRUDrawnSystemCurrent
+ "3", # CISCO-ENTITY-FRU-CONTROL-MIB::cefcFRUTotalInlineCurrent
+ "4", # CISCO-ENTITY-FRU-CONTROL-MIB::cefcFRUDrawnInlineCurrent
+ ])],
+ 'snmp_scan_function' : lambda oid: "cisco" in oid(".1.3.6.1.2.1.1.1.0").lower(),
+ 'includes' : [ "elphase.include" ],
+ 'group' : 'el_inphase'
+}
errors in web.log caused by "Events" checks
Message-ID: <574d7607.g1Vmue6ZWkbhBKzm%lm(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 86e7ac489e07fe58e83b555bc949f7e415ba705d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=86e7ac489e07fe…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue May 31 13:31:14 2016 +0200
3584 FIX check_mkevents: Fixed "failed to parse perfdata" errors in web.log caused by "Events" checks
When the last worst event found in the Event Console contained a pipe character the remaining
output was treated as performance data string and resulted in "failed to parse perfdata" errors
in web.log e.g. when opening the service detail page of such an Events service.
---
.werks/3584 | 12 ++++++++++++
ChangeLog | 1 +
doc/treasures/active_checks/check_mkevents.cc | 17 +++++++++++++++--
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/.werks/3584 b/.werks/3584
new file mode 100644
index 0000000..c784ac4
--- /dev/null
+++ b/.werks/3584
@@ -0,0 +1,12 @@
+Title: check_mkevents: Fixed "failed to parse perfdata" errors in web.log caused by "Events" checks
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1464694172
+
+When the last worst event found in the Event Console contained a pipe character the remaining
+output was treated as performance data string and resulted in "failed to parse perfdata" errors
+in web.log e.g. when opening the service detail page of such an Events service.
diff --git a/ChangeLog b/ChangeLog
index a6b5856..8cdf0c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -249,6 +249,7 @@
* 3626 FIX: dell_eql_storage: fixed scan function if sysDescr is empty
* 3582 FIX: check_mail: Fixed issue with processing multipart mails...
* 3630 FIX: docsis_channels_upstream: fixed channel discovery
+ * 3584 FIX: check_mkevents: Fixed "failed to parse perfdata" errors in web.log caused by "Events" checks...
Multisite:
* 3187 notification view: new filter for log command via regex
diff --git a/doc/treasures/active_checks/check_mkevents.cc b/doc/treasures/active_checks/check_mkevents.cc
index d7ac3ec..f5f309f 100644
--- a/doc/treasures/active_checks/check_mkevents.cc
+++ b/doc/treasures/active_checks/check_mkevents.cc
@@ -309,6 +309,19 @@ int main(int argc, char** argv)
unhandled++;
}
+ // make sure that plugin output does not contain a vertical bar. If that is the
+ // case then replace it with a Uniocode "Light vertical bar". Same as in Check_MK.
+ string text;
+ text.reserve(worst_row_event_text.size());
+ for (size_t i = 0; i < worst_row_event_text.size(); i++) {
+ if (worst_row_event_text[i] == '|') {
+ text += "\xe2\x94\x82"; // \u2758 (utf-8 encoded light vertical bar)
+ }
+ else {
+ text += worst_row_event_text[i];
+ }
+ }
+
if (count == 0 && application)
printf("OK - no events for %s on host %s\n", application, host);
else if (count == 0)
@@ -316,8 +329,8 @@ int main(int argc, char** argv)
else {
const char* state_text = worst_state == 0 ? "OK" : worst_state == 1 ? "WARN" : worst_state == 2 ? "CRIT" : "UNKNOWN";
printf("%s - %d events (%d unacknowledged)", state_text, count, unhandled);
- if (worst_row_event_text.length() > 0)
- printf(", worst state is %s (Last line: %s)", state_text, worst_row_event_text.c_str());
+ if (text.length() > 0)
+ printf(", worst state is %s (Last line: %s)", state_text, text.c_str());
printf("\n");
}
return worst_state;