[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Naparuba
naparuba at gmail.com
Tue Feb 28 22:16:37 UTC 2012
The following commit has been merged in the debian/master branch:
commit f7977a425073ed2d75e0cee9f80c048299a907d3
Author: Naparuba <naparuba at gmail.com>
Date: Fri Jan 27 14:09:19 2012 +0100
*Add : is_admin property for contacts
*Add : if contact is not is_admin, then the /problems view only show its related elements (if he is a contact of the elemetn, of an impact or a source problems one).
diff --git a/etc/contacts.cfg b/etc/contacts.cfg
index 68707a1..21aef6d 100644
--- a/etc/contacts.cfg
+++ b/etc/contacts.cfg
@@ -6,6 +6,6 @@ define contact{
email shinken at localhost
pager 0600000000 ; contact phone number
password admin
+ is_admin 1
}
-
diff --git a/shinken/misc/filter.py b/shinken/misc/filter.py
new file mode 100644
index 0000000..0a9595f
--- /dev/null
+++ b/shinken/misc/filter.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# Copyright (C) 2009-2010 :
+# Gabes Jean, naparuba at gmail.com
+# Gerhard Lausser, Gerhard.Lausser at consol.de
+# Gregory Starck, g.starck at gmail.com
+# Hartmut Goebel, h.goebel at goebel-consult.de
+#
+# This file is part of Shinken.
+#
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""
+Helper functions for some filtering, like for user based
+"""
+
+# Get only user relevant items for the user
+def only_related_to(lst, user):
+ # if the user is an admin, show all
+ if user.is_admin:
+ return lst
+
+ # Ok the user is a simple user, we should filter
+ r = []
+ for i in lst:
+ # Maybe the user is a direct contact
+ if user in i.contacts:
+ r.append(i)
+ continue
+ # TODO : add a notified_contact pass
+
+ # Maybe it's a contact of a linked elements (source problems or impacts)
+ is_find = False
+ for s in i.source_problems:
+ if user in s.contacts:
+ r.append(i)
+ is_find = True
+ # Ok skeep this object now
+ if is_find:
+ continue
+ # Now impacts related maybe?
+ for imp in i.impacts:
+ if user in imp.contacts:
+ r.append(i)
+
+ return r
+
diff --git a/shinken/objects/contact.py b/shinken/objects/contact.py
index 88f7248..b0f0837 100644
--- a/shinken/objects/contact.py
+++ b/shinken/objects/contact.py
@@ -66,6 +66,7 @@ class Contact(Item):
'address5': StringProp(default='none', fill_brok=['full_status']),
'address6': StringProp(default='none', fill_brok=['full_status']),
'can_submit_commands': BoolProp(default='0', fill_brok=['full_status']),
+ 'is_admin': BoolProp(default='0', fill_brok=['full_status']),
'retain_status_information': BoolProp(default='1', fill_brok=['full_status']),
'notificationways': StringProp(default='', fill_brok=['full_status']),
'password' : StringProp(default='NOPASSWORDSET', fill_brok=['full_status']),
diff --git a/shinken/webui/plugins/problems/problems.py b/shinken/webui/plugins/problems/problems.py
index b39ca83..10d9da2 100644
--- a/shinken/webui/plugins/problems/problems.py
+++ b/shinken/webui/plugins/problems/problems.py
@@ -22,6 +22,7 @@
#along with Shinken. If not, see <http://www.gnu.org/licenses/>.
from shinken.webui.bottle import redirect
+from shinken.misc.filter import only_related_to
### Will be populated by the UI with it's own value
app = None
@@ -49,6 +50,9 @@ def get_page():
search = app.request.GET.get('search', '')
pbs = app.datamgr.get_all_problems()
+
+ # Filter with the user interests
+ pbs = only_related_to(pbs, user)
# Ok, if need, appli the search filter
if search:
@@ -104,6 +108,9 @@ def get_all():
all = app.datamgr.get_all_hosts_and_services()
+ # Filter or not filter? That is the question....
+ #all = only_related_to(all, user)
+
# Ok, if need, appli the search filter
if search:
print "SEARCHING FOR", search
diff --git a/shinken/webui/plugins/problems/views/problems.tpl b/shinken/webui/plugins/problems/views/problems.tpl
index 205d964..22b56c6 100644
--- a/shinken/webui/plugins/problems/views/problems.tpl
+++ b/shinken/webui/plugins/problems/views/problems.tpl
@@ -4,10 +4,12 @@
%helper = app.helper
%datamgr = app.datamgr
+%title = {'problems' : 'All problems', 'all' : 'All elements'}.get(page, 'Unknown page')
+
%top_right_banner_state = datamgr.get_overall_state()
-%rebase layout title='All problems', top_right_banner_state=top_right_banner_state, js=['problems/js/img_hovering.js', 'problems/js/accordion.js'], css=['problems/css/accordion.css', 'problems/css/pagenavi.css', 'problems/css/perfometer.css', 'problems/css/img_hovering.css'], refresh=True, menu_part='/'+page, user=user
+%rebase layout title=title, top_right_banner_state=top_right_banner_state, js=['problems/js/img_hovering.js', 'problems/js/accordion.js'], css=['problems/css/accordion.css', 'problems/css/pagenavi.css', 'problems/css/perfometer.css', 'problems/css/img_hovering.css'], refresh=True, menu_part='/'+page, user=user
%# " If the auth got problem, we bail out"
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list