Module: check_mk
Branch: master
Commit: 01e2953517da870de1bd226af4cc18323b5bc8cf
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=01e2953517da87…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Jun 27 08:27:42 2011 +0200
Neues Dashlet für PNP-Graphen
---
web/htdocs/dashboard.py | 24 ++++++++++++++++++++++++
web/htdocs/lib.py | 6 ++++++
web/plugins/pages/shipped.py | 1 +
web/plugins/views/painters.py | 7 -------
4 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 857afab..f858ee2 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -123,6 +123,11 @@ def render_dashboard(name):
refresh_dashlets = [] # Dashlets with automatic refresh, for Javascript
for nr, dashlet in enumerate(board["dashlets"]):
+ # dashlets using the 'urlfunc' method will dynamically compute
+ # an url (using HTML context variables at their wish).
+ if "urlfunc" in dashlet:
+ dashlet["url"] = dashlet["urlfunc"]()
+
# dashlets using the 'url' method will be refreshed by us. Those
# dashlets using static content (such as an iframe) will not be
# refreshed by us but need to do that themselves.
@@ -513,3 +518,22 @@ context =
document.getElementById("%(what)s_stats").getContext('2d');
html.javascript('chart_pie(%f, %f, %r);' % (r, r + perc, color))
r += perc
+def dashlet_pnpgraph():
+ render_pnpgraph(html.var("site"), html.var("host"),
html.var("service"), int(html.var("source", 0)))
+
+def render_pnpgraph(site, host, service=None, source=0):
+ if not host:
+ html.message("Invalid URL to this dashlet. Missing
<tt>host</tt>")
+ return;
+ if not service:
+ service = "_HOST_"
+
+ if not site:
+ base_url = defaults.url_prefix + "/pnp4nagios/index.php/"
+ else:
+ base_url = html.site_status[site]["site"]["url_prefix"]
+
+ img_url = base_url +
"image?host=%s&srv=%s&view=0&source=%d&theme=multisite" % \
+ (pnp_cleanup(host), pnp_cleanup(service), source)
+ html.write('<img src="%s">' % img_url)
+
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 4353a10..88992ad 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -117,3 +117,9 @@ def load_web_plugins(forwhat, globalvars):
if fn.endswith(".py"):
execfile(local_plugins_path + "/" + fn, globalvars)
+def pnp_cleanup(s):
+ return s \
+ .replace(' ', '_') \
+ .replace(':', '_') \
+ .replace('/', '_') \
+ .replace('\\', '_')
diff --git a/web/plugins/pages/shipped.py b/web/plugins/pages/shipped.py
index b865dd4..e6fcf44 100644
--- a/web/plugins/pages/shipped.py
+++ b/web/plugins/pages/shipped.py
@@ -65,5 +65,6 @@ pagehandlers.update({
"dashlet_overview" : dashboard.dashlet_overview,
"dashlet_hoststats" : dashboard.dashlet_hoststats,
"dashlet_servicestats" : dashboard.dashlet_servicestats,
+ "dashlet_pnpgraph" : dashboard.dashlet_pnpgraph,
})
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index cc5a51e..ff227ae 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -115,13 +115,6 @@ icon_columns = [ "acknowledged",
"scheduled_downtime_depth", "downtimes_with_inf
icon_service_columns = [ "service_description" ]
# Intelligent Links to PNP4Nagios 0.6.X
-def pnp_cleanup(s):
- return s \
- .replace(' ', '_') \
- .replace(':', '_') \
- .replace('/', '_') \
- .replace('\\', '_')
-
def pnp_url(row, what, how = 'graph'):
sitename = row["site"]
host = pnp_cleanup(row["host_name"])