Module: check_mk
Branch: master
Commit: 84e7c1998e0895e90a7bfce11114c9395eb14d88
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=84e7c1998e0895…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jul 6 12:45:16 2016 +0200
Fixed implementation of "see unrelated" permission checking in GUI
---
web/htdocs/views.py | 21 ++++++++++++++++++---
web/plugins/views/mkeventd.py | 21 +++++++++++++++++++--
2 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index ad955ee..c5d70ca 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1126,9 +1126,15 @@ def show_view(view, show_heading = False, show_buttons = True,
# tablename may be a function instead of a livestatus tablename
# In that case that function is used to compute the result.
+ # It may also be a tuple. In this case the first element is a function and the
second element
+ # is a list of argument to hand over to the function together with all other
arguments that
+ # are passed to query_data().
if type(tablename) == type(lambda x:None):
rows = tablename(columns, query, only_sites, limit, all_active_filters)
+ elif type(tablename) == tuple:
+ func, args = tablename
+ rows = func(datasource, columns, add_columns, query, only_sites, limit,
*args)
else:
rows = query_data(datasource, columns, add_columns, query, only_sites,
limit)
@@ -1664,8 +1670,10 @@ def ajax_count_button():
# add_headers: additional livestatus headers to add
# only_sites: list of sites the query is limited to
# limit: maximum number of data rows to query
-def query_data(datasource, columns, add_columns, add_headers, only_sites = [], limit =
None):
- tablename = datasource["table"]
+def query_data(datasource, columns, add_columns, add_headers, only_sites = [], limit =
None, tablename=None):
+ if tablename == None:
+ tablename = datasource["table"]
+
add_headers += datasource.get("add_headers", "")
merge_column = datasource.get("merge_by")
if merge_column:
@@ -1691,9 +1699,16 @@ def query_data(datasource, columns, add_columns, add_headers,
only_sites = [], l
# Remove columns which are implicitely added by the datasource
columns = [ c for c in columns if c not in add_columns ]
query = "GET %s\n" % tablename
- return do_query_data(query, columns, add_columns, merge_column,
+ rows = do_query_data(query, columns, add_columns, merge_column,
add_headers, only_sites, limit, auth_domain)
+ # Datasource may have optional post processing function to filter out rows
+ post_process_func = datasource.get("post_process")
+ if post_process_func:
+ return post_process_func(rows)
+ else:
+ return rows
+
def do_query_data(query, columns, add_columns, merge_column,
add_headers, only_sites, limit, auth_domain):
diff --git a/web/plugins/views/mkeventd.py b/web/plugins/views/mkeventd.py
index c54f9b9..ffc2944 100644
--- a/web/plugins/views/mkeventd.py
+++ b/web/plugins/views/mkeventd.py
@@ -42,6 +42,23 @@ except:
# | |
# '----------------------------------------------------------------------'
+
+def query_ec_table(datasource, columns, add_columns, query, only_sites, limit,
tablename):
+ if "event_contact_groups" not in columns:
+ columns.append("event_contact_groups")
+ if "host_contact_groups" not in columns:
+ columns.append("host_contact_groups")
+
+ rows = query_data(datasource, columns, add_columns, query, only_sites, limit,
+ tablename=tablename)
+
+ if config.may("mkeventd.seeunrelated"):
+ return rows # user is allowed to see all events returned by the core
+
+ return [ r for r in rows if r["event_contact_groups"] != [] or
r["host_name"] != "" ]
+
+
+
# Declare datasource only if the event console is activated. We do
# not want to irritate users that do not know anything about the EC.
if mkeventd_enabled:
@@ -60,7 +77,7 @@ if mkeventd_enabled:
multisite_datasources["mkeventd_events"] = {
"title" : _("Event Console: Current Events"),
- "table" : "eventconsoleevents",
+ "table" : (query_ec_table, ["eventconsoleevents"]),
"auth_domain" : "ec",
"infos" : [ "event", "host" ],
"keys" : [],
@@ -70,7 +87,7 @@ if mkeventd_enabled:
multisite_datasources["mkeventd_history"] = {
"title" : _("Event Console: Event History"),
- "table" : "eventconsolehistory",
+ "table" : (query_ec_table, ["eventconsolehistory"]),
"auth_domain" : "ec",
"infos" : [ "history", "event",
"host" ],
"keys" : [],