Module: check_mk
Branch: master
Commit: d1fec08d64a595c72c26418ceb8d30755d6792e1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d1fec08d64a595…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Oct 9 09:14:49 2014 +0200
More clean check for availability of reporting
---
web/htdocs/config.py | 72 ++++++++++++++++++++++++++++---------
web/htdocs/index.py | 5 ---
web/htdocs/views.py | 14 +-------
web/htdocs/visuals.py | 2 +-
web/plugins/views/availability.py | 5 +--
5 files changed, 59 insertions(+), 39 deletions(-)
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 3bceae3..e329b7b 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -51,6 +51,19 @@ try:
except NameError:
from sets import Set as set
+#.
+# .--Declarations--------------------------------------------------------.
+# | ____ _ _ _ |
+# | | _ \ ___ ___| | __ _ _ __ __ _| |_(_) ___ _ __ ___ |
+# | | | | |/ _ \/ __| |/ _` | '__/ _` | __| |/ _ \| '_ \/ __| |
+# | | |_| | __/ (__| | (_| | | | (_| | |_| | (_) | | | \__ \ |
+# | |____/ \___|\___|_|\__,_|_| \__,_|\__|_|\___/|_| |_|___/ |
+# | |
+# +----------------------------------------------------------------------+
+# | Declarations of global variables and constants |
+# '----------------------------------------------------------------------'
+
+
user = None
user_id = None
builtin_role_ids = [ "user", "admin", "guest" ] # hard
coded in various permissions
@@ -151,15 +164,27 @@ def load_config():
include(p)
+def reporting_available():
+ try:
+ # Check the existance of one arbitrary config variable from the
+ # reporting module
+ reporting_filename
+ return True
+ except:
+ return False
+
+
#.
-# -------------------------------------------------------------------
-# ____ _ _
-# | _ \ ___ _ __ _ __ ___ (_)___ ___(_) ___ _ __ ___
-# | |_) / _ \ '__| '_ ` _ \| / __/ __| |/ _ \| '_ \/ __|
-# | __/ __/ | | | | | | | \__ \__ \ | (_) | | | \__ \
-# |_| \___|_| |_| |_| |_|_|___/___/_|\___/|_| |_|___/
-#
-# -------------------------------------------------------------------
+# .--Permissions---------------------------------------------------------.
+# | ____ _ _ |
+# | | _ \ ___ _ __ _ __ ___ (_)___ ___(_) ___ _ __ ___ |
+# | | |_) / _ \ '__| '_ ` _ \| / __/ __| |/ _ \| '_ \/ __| |
+# | | __/ __/ | | | | | | | \__ \__ \ | (_) | | | \__ \ |
+# | |_| \___|_| |_| |_| |_|_|___/___/_|\___/|_| |_|___/ |
+# | |
+# +----------------------------------------------------------------------+
+# | Handling of users, permissions and roles |
+# '----------------------------------------------------------------------'
def declare_permission(name, title, description, defaults):
perm = { "name" : name, "title" : title, "description"
: description, "defaults" : defaults }
@@ -403,14 +428,16 @@ def save_user_file(name, content, unlock = False):
raise MKConfigError(_("Cannot save %s options for user <b>%s</b>
into <b>%s</b>: %s") % \
(name, user_id, path, e))
-# -------------------------------------------------------------------
-# ____ _ _
-# / ___|(_) |_ ___ ___
-# \___ \| | __/ _ \/ __|
-# ___) | | || __/\__ \
-# |____/|_|\__\___||___/
-#
-# -------------------------------------------------------------------
+# .--Sites---------------------------------------------------------------.
+# | ____ _ _ |
+# | / ___|(_) |_ ___ ___ |
+# | \___ \| | __/ _ \/ __| |
+# | ___) | | || __/\__ \ |
+# | |____/|_|\__\___||___/ |
+# | |
+# +----------------------------------------------------------------------+
+# | The config module provides some helper functions for sites. |
+# '----------------------------------------------------------------------'
sites = { "": {} }
use_siteicons = False
@@ -468,6 +495,19 @@ def read_site_config():
def save_site_config():
save_user_file("siteconfig", user_siteconf)
+#.
+# .--Plugins-------------------------------------------------------------.
+# | ____ _ _ |
+# | | _ \| |_ _ __ _(_)_ __ ___ |
+# | | |_) | | | | |/ _` | | '_ \/ __| |
+# | | __/| | |_| | (_| | | | | \__ \ |
+# | |_| |_|\__,_|\__, |_|_| |_|___/ |
+# | |___/ |
+# +----------------------------------------------------------------------+
+# | Handling of our own plugins. In plugins other software pieces can |
+# | declare defaults for configuration variables. |
+# '----------------------------------------------------------------------'
+
def load_plugins():
load_web_plugins("config", globals())
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index f4c85b0..b43ddb6 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -76,11 +76,6 @@ def load_all_plugins():
else:
module.load_plugins()
- # Load reporting plugins (only available in subscription version)
- try:
- reporting.load_plugins()
- except:
- pass
__builtin__.load_all_plugins = load_all_plugins
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index e7deaa4..960a795 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -713,14 +713,6 @@ def page_view():
html.set_page_context(dict(visuals.get_context_html_vars(view)))
- if config.may("reporting.instant"):
- if html.var("instant_report"):
- import reporting
- reporting.instant_report()
- return
-
- html.add_status_icon("report", _("Export as PDF (instant
report)"), html.makeuri([("instant_report", "1")]))
-
show_view(view, True, True, True)
@@ -1444,12 +1436,8 @@ def show_context_links(thisview, show_filters, display_options,
html.context_button(_("WATO"), url, "wato",
id="wato",
bestof = config.context_buttons_to_show)
- try:
- # FIXME: Berechtigung prüfen
- config.reporting_available
+ if config.reporting_available():
html.context_button(_("Export as PDF"), html.makeuri([],
filename="report_instant.py"), "pdf")
- except:
- pass
links = visuals.collect_context_links(thisview)
for linktitle, uri, icon, buttonid in links:
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 786ecfa..95d6f24 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -899,7 +899,7 @@ def add_context_to_uri_vars(visual, only_infos=None,
only_count=False):
# Now apply the multiple context filters
for info_key in only_infos:
- for filter_name, filter_vars in visual.get('context', {}).items():
+ for filter_name, filter_vars in visual['context'].items():
if type(filter_vars) == dict: # this is a multi-context filter
# We add the filter only if *none* if its HTML variables are present on
the URL
# This important because checkbox variables are not present if the box is
not checked.
diff --git a/web/plugins/views/availability.py b/web/plugins/views/availability.py
index 920809c..8601608 100644
--- a/web/plugins/views/availability.py
+++ b/web/plugins/views/availability.py
@@ -141,11 +141,8 @@ def render_availability(view, datasource, filterheaders,
display_options,
html.begin_context_buttons()
togglebutton("avoptions", html.has_user_errors(),
"painteroptions", _("Configure details of the report"))
html.context_button(_("Status View"), html.makeuri([("mode",
"status")]), "status")
- try:
- config.reporting_available
+ if config.reporting_available():
html.context_button(_("Export as PDF"), html.makeuri([],
filename="report_instant.py"), "pdf")
- except:
- pass
if timeline:
html.context_button(_("Availability"),
html.makeuri([("timeline", "")]), "availability")
history_url = history_url_of(tl_site, tl_host, tl_service, range[0],
range[1])