Module: check_mk
Branch: master
Commit: 5745442d5305e6f2b03d5ab23c7a8904d5bad040
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5745442d5305e6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jun 2 15:46:10 2015 +0200
omd_apache: Added parse function, fixed problem with multiple sites
---
checks/omd_apache | 75 +++++++++++++++++++++++++++++++++--------------------
1 file changed, 47 insertions(+), 28 deletions(-)
diff --git a/checks/omd_apache b/checks/omd_apache
index 15505fe..e35125d 100644
--- a/checks/omd_apache
+++ b/checks/omd_apache
@@ -24,6 +24,16 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+# <<<omd_apache:sep(124)>>>
+# [heute]
+#
/heute/check_mk/view.py?view_name=allhosts&_display_options=htbfcoderuw&_do_actions=&_ajaxid=1433252694|200|5067|13465
+# /heute/check_mk/sidebar_snapin.py?names=tactical_overview,admin|200|4046|8109
+#
/heute/check_mk/index.py?start_url=%2Fheute%2Fcheck_mk%2Fview.py%3Fview_name%3Dallhosts|200|515|7528
+# /heute/check_mk/view.py?view_name=allhosts|200|37656|57298
+# /heute/check_mk/side.py|200|39885|108178
+# /heute/check_mk/js/graphs-2015.06.02.js|200|28895|1823
+# [heute2]
+
omd_apache_patterns = [
# perf keys url matching regex
('cmk_views' , '^check_mk/view\.py'),
@@ -43,12 +53,25 @@ omd_apache_patterns = [
('other' , '.*'),
]
-def inventory_omd_apache(info):
+# Parses the agent data to a dictionary, using the site name as keys
+# which holds
+def parse_omd_apache(info):
+ parsed = {}
+ site = None
for line in info:
if line[0][0] == '[':
- yield line[0][1:-1], None
+ site = line[0][1:-1]
+ parsed[site] = []
+ elif site:
+ parsed[site].append(line)
+ return parsed
+
+
+def inventory_omd_apache(parsed):
+ return [ (k, None) for k in parsed.keys() ]
-def check_omd_apache(item, _no_params, info):
+
+def check_omd_apache(item, _no_params, parsed):
# First initialize all possible values to be able to always report all perf keys
stats = {'requests': {}, 'secs': {}, 'bytes': {}}
for key, pattern in omd_apache_patterns:
@@ -56,34 +79,28 @@ def check_omd_apache(item, _no_params, info):
stats['secs'][key] = 0
stats['bytes'][key] = 0
- active = False
- found = False
- for line in info:
- if line[0] == '[' + item + ']':
- active = True
- elif active and line[0] == '[':
- break
- elif active:
- url, status, size_bytes, microsec = line
- for key, pattern in omd_apache_patterns:
- # make url relative to site directory
- if regex(pattern).search(url[len('/'+item+'/'):]):
- found = True
- stats['requests'].setdefault(key, 0)
- stats['requests'][key] += 1
-
- stats['secs'].setdefault(key, 0)
- stats['secs'][key] += int(microsec) / 1000.0 / 1000.0
-
- stats['bytes'].setdefault(key, 0)
- stats['bytes'][key] += int(size_bytes)
-
- break # don't call a line twice
-
- if not found:
+ if item not in parsed:
+ return
+ elif not parsed[item]:
yield 0, "No activity since last check"
return
+ for url, status, size_bytes, microsec in parsed[item]:
+ for key, pattern in omd_apache_patterns:
+ # make url relative to site directory
+ if regex(pattern).search(url[len('/'+item+'/'):]):
+ found = True
+ stats['requests'].setdefault(key, 0)
+ stats['requests'][key] += 1
+
+ stats['secs'].setdefault(key, 0)
+ stats['secs'][key] += int(microsec) / 1000.0 / 1000.0
+
+ stats['bytes'].setdefault(key, 0)
+ stats['bytes'][key] += int(size_bytes)
+
+ break # don't call a line twice
+
# Now process the result. Break down the gathered values to values per second.
# the output is showing total values, for the graphing we provide detailed data
this_time = time.time()
@@ -99,7 +116,9 @@ def check_omd_apache(item, _no_params, info):
total = ty == 'bytes' and get_bytes_human_readable(total) or
'%.2f' % total
yield 0, '%s %s' % (total, title)
+
check_info['omd_apache'] = {
+ 'parse_function' : parse_omd_apache,
'check_function' : check_omd_apache,
'inventory_function' : inventory_omd_apache,
'service_description' : 'OMD %s apache',