service-groups at once
Message-ID: <527269ab.NfUvVhagv6l5vfK1%mk(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 2a57db81fd4ef944904a672668d7048266ef17cd
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2a57db81fd4ef9…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Oct 31 15:30:12 2013 +0100
New filters for selecting several host/service-groups at once
There are two new filters that allow you to select not only one, but
several host- and service groups at once. This filters are added to
the builtin views "Host Search", "Service Search" and "All
hosts".
---
.werks/1 | 10 +++++++++
ChangeLog | 3 +++
web/htdocs/valuespec.py | 5 +++--
web/htdocs/views.css | 9 ++++++++
web/plugins/views/builtin.py | 4 ++++
web/plugins/views/filters.py | 47 ++++++++++++++++++++++++++++++++++++++++--
6 files changed, 74 insertions(+), 4 deletions(-)
diff --git a/.werks/1 b/.werks/1
new file mode 100644
index 0000000..fd9236c
--- /dev/null
+++ b/.werks/1
@@ -0,0 +1,10 @@
+Title: New filters for selecting several host/service-groups at once
+Level: 2
+Component: multisite
+Version: 1.2.3i7
+Date: 1383229744
+Class: feature
+
+There are two new filters that allow you to select not only one, but
+several host- and service groups at once. This filters are added to
+the builtin views "Host Search", "Service Search" and "All
hosts".
diff --git a/ChangeLog b/ChangeLog
index 5554448..4d1fe97 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
1.2.3i7:
+ Multisite:
+ * 0001 : New filters for selecting several host/service-groups at once...
+
1.2.3i6:
Core & Setup:
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 239b87a..00fb846 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1293,6 +1293,7 @@ class MultiSelect(ListChoice):
class DualListChoice(ListChoice):
def __init__(self, **kwargs):
ListChoice.__init__(self, **kwargs)
+ self._autoheight = kwargs.get("autoheight", True)
def render_input(self, varprefix, value):
self.load_elements()
@@ -1310,11 +1311,11 @@ class DualListChoice(ListChoice):
html.write(_('Selected:'))
html.write('</td></tr><tr><td>')
html.sorted_select(varprefix + '_unselected', unselected,
- attrs = {'size': 5, 'style':
'height:auto'},
+ attrs = {'size': 5, 'style': self._autoheight
and 'height:auto' or ''},
onchange = 'vs_duallist_switch(this, \'%s\');'
% varprefix)
html.write('</td><td>')
html.sorted_select(varprefix + '_selected', selected,
- attrs = {'size': 5, 'style':
'height:auto', 'multiple': 'multiple'},
+ attrs = {'size': 5, 'style': self._autoheight
and 'height:auto' or '', 'multiple': 'multiple'},
onchange = 'vs_duallist_switch(this, \'%s\');'
% varprefix)
html.write('</td></tr></table>')
html.hidden_field(varprefix, '|'.join([k for k, v in selected]), id =
varprefix, add_var = True)
diff --git a/web/htdocs/views.css b/web/htdocs/views.css
index 2a1609b..18965f2 100644
--- a/web/htdocs/views.css
+++ b/web/htdocs/views.css
@@ -111,6 +111,15 @@ div.floatfilter .content > select#optservicegroup {
width: 240px;
}
+div.floatfilter .content .multigroup table {
+ margin-top: -6px;
+}
+
+div.floatfilter .content .multigroup select {
+ width: 148px;
+ height: 66px;
+}
+
div.floatfilter .content .filtertime select {
width: 136px;
}
diff --git a/web/plugins/views/builtin.py b/web/plugins/views/builtin.py
index e029d59..639163e 100644
--- a/web/plugins/views/builtin.py
+++ b/web/plugins/views/builtin.py
@@ -56,6 +56,7 @@ multisite_builtin_views.update({
'host_acknowledged',
'hostregex',
'host_notifications_enabled',
+ 'hostgroups',
'opthostgroup',
'host_check_command',
'opthost_contactgroup',
@@ -1029,6 +1030,7 @@ multisite_builtin_views.update({
'siteopt',
'hostregex',
'summary_host',
+ 'hostgroups',
'opthostgroup',
'opthost_contactgroup',
'host_check_command',
@@ -1091,6 +1093,8 @@ multisite_builtin_views.update({
'show_filters': ['service_in_notification_period',
'optservicegroup',
'optservice_contactgroup',
+ 'hostgroups',
+ 'servicegroups',
'service_notifications_enabled',
'host_in_notification_period',
'in_downtime',
diff --git a/web/plugins/views/filters.py b/web/plugins/views/filters.py
index 24b9fd7..b1742cb 100644
--- a/web/plugins/views/filters.py
+++ b/web/plugins/views/filters.py
@@ -120,6 +120,46 @@ def all_groups(what):
groups = dict(html.live.query("GET %sgroups\nCache: reload\nColumns: name
alias\n" % what))
return [ (name, groups[name] or name) for name in groups.keys() ]
+class FilterMultigroup(Filter):
+ def __init__(self, what, title):
+ htmlvars = [ what + "groups" ]
+ Filter.__init__(self, htmlvars[0], # name
+ title,
+ what, # info, e.g. "service"
+ htmlvars,
+ []) # no link info needed
+ self.what = what
+ self.htmlvar = htmlvars[0]
+
+ def double_height(self):
+ return True
+
+ def valuespec(self):
+ return DualListChoice(choices = all_groups(self.what), autoheight=False)
+
+ def selection(self):
+ current = html.var(self.htmlvar, "").strip().split("|")
+ if current == ['']:
+ return []
+ else:
+ return current
+
+ def display(self):
+ html.write('<div class=multigroup>')
+ self.valuespec().render_input(self.htmlvar, self.selection())
+ html.write('</div>')
+
+ def filter(self, infoname):
+ current = self.selection()
+ if len(current) == 0:
+ return "" # No group selected = all groups selected, filter unused
+ filters = ""
+ for group in current:
+ filters += "Filter: %s_groups >= %s\n" % (self.what, group)
+ filters += "Or: %d\n" % len(current)
+ return filters
+
+
class FilterGroupCombo(Filter):
def __init__(self, what, title, enforce):
self.enforce = enforce
@@ -189,10 +229,13 @@ class FilterGroupCombo(Filter):
declare_filter(104, FilterGroupCombo("host",
_("Hostgroup"), False), _("Optional selection of host
group"))
declare_filter(104, FilterGroupCombo("host", _("Hostgroup
(enforced)"), True), _("Dropdown list, selection of host group is
<b>enforced</b>"))
+declare_filter(105, FilterMultigroup("host", _("Several
Hostgroups")), _("Selection of multiple host groups"))
declare_filter(204, FilterGroupCombo("service",
_("Servicegroup"), False), _("Optional selection of service
group"))
declare_filter(205, FilterGroupCombo("service", _("Servicegroup
(enforced)"), True), _("Dropdown list, selection of service group is
<b>enforced</b>"))
-declare_filter(106, FilterGroupCombo("host_contact", _("Host
Contactgroup"), False), _("Optional selection of host contact group
group"))
-declare_filter(206, FilterGroupCombo("service_contact", _("Service
Contactgroup"), False), _("Optional selection of service contact group
group"))
+declare_filter(205, FilterMultigroup("service", _("Several
Servicegroups")), _("Selection of multiple service groups"))
+
+declare_filter(106, FilterGroupCombo("host_contact", _("Host
Contactgroup"), False), _("Optional selection of host contact group"))
+declare_filter(206, FilterGroupCombo("service_contact", _("Service
Contactgroup"), False), _("Optional selection of service contact group"))
declare_filter(107, FilterText("host_ctc", _("Host Contact"),
"host", "host_contacts", "host_ctc", ">="))
declare_filter(207, FilterText("service_ctc", _("Service Contact"),
"service", "service_contacts", "service_ctc",
">="))