1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-26 02:57:04 +00:00

simplify the munin_cgi wrapper / add changelog entry

This commit is contained in:
Joshua Tauberer 2016-03-23 16:07:34 -04:00
parent 6b408ef824
commit bd86d44c8b
2 changed files with 9 additions and 18 deletions

View File

@ -1,6 +1,8 @@
CHANGELOG CHANGELOG
========= =========
* Munin system monitoring graphs are now zoomable.
In Development In Development
-------------- --------------

View File

@ -507,12 +507,9 @@ def munin(filename=""):
if filename == "": filename = "index.html" if filename == "": filename = "index.html"
return send_from_directory("/var/cache/munin/www", filename) return send_from_directory("/var/cache/munin/www", filename)
# MUNIN CGI-GRAPH
@app.route('/munin/cgi-graph/')
@app.route('/munin/cgi-graph/<path:filename>') @app.route('/munin/cgi-graph/<path:filename>')
@authorized_personnel_only @authorized_personnel_only
def munin_cgi(filename=""): def munin_cgi(filename):
""" Relay munin cgi dynazoom requests """ Relay munin cgi dynazoom requests
/usr/lib/munin/cgi/munin-cgi-graph is a perl cgi script in the munin package /usr/lib/munin/cgi/munin-cgi-graph is a perl cgi script in the munin package
that is responsible for generating binary png images _and_ associated HTTP that is responsible for generating binary png images _and_ associated HTTP
@ -541,8 +538,6 @@ def munin_cgi(filename=""):
return ("a path must be specified", 404) return ("a path must be specified", 404)
query_str = request.query_string.decode("utf-8", 'ignore') query_str = request.query_string.decode("utf-8", 'ignore')
query_str = query_str[1:] if query_str.startswith('&') else query_str[1:]
# I don't know if this is strictly necessary
env = {'PATH_INFO': '/%s/' % filename, 'QUERY_STRING': query_str} env = {'PATH_INFO': '/%s/' % filename, 'QUERY_STRING': query_str}
cmd = COMMAND % query_str cmd = COMMAND % query_str
@ -560,18 +555,12 @@ def munin_cgi(filename=""):
return ("error processing graph image", 500) return ("error processing graph image", 500)
# /usr/lib/munin/cgi/munin-cgi-graph returns both headers and binary png when successful. # /usr/lib/munin/cgi/munin-cgi-graph returns both headers and binary png when successful.
# Per http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html PNG files always start # A double-Windows-style-newline always indicates the end of HTTP headers.
# with the same 8 bytes (137 80 78 71 13 10 26 10) or b'\x89PNG\r\n\x1a\n' So we split headers, image_bytes = binout.split(b'\r\n\r\n', 1)
# the output of munin-cgi-graph where the PNG begins response = make_response(image_bytes)
bin_start = binout.find(b'\x89PNG\r\n\x1a\n') for line in headers.splitlines():
str_headers = binout[:bin_start].decode("utf-8") name, value = line.decode("utf8").split(':', 1)
# decode the byte str containing response headers response.headers[name] = value
bin_image = binout[bin_start:]
response = make_response(bin_image)
for line in str_headers.splitlines():
if line:
name, value = line.split(':',1)
response.headers[name] = value
if 'Status' in response.headers and '404' in response.headers['Status']: if 'Status' in response.headers and '404' in response.headers['Status']:
app.logger.warning("munin_cgi: munin-cgi-graph returned 404 status code. PATH_INFO=%s", env['PATH_INFO']) app.logger.warning("munin_cgi: munin-cgi-graph returned 404 status code. PATH_INFO=%s", env['PATH_INFO'])
return response return response