vigiboard / vigiboard / controllers / plugins / groups.py @ 032d0f30
History | View | Annotate | Download (4.4 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4:
|
3 |
################################################################################
|
4 |
#
|
5 |
# Copyright (C) 2007-2011 CS-SI
|
6 |
#
|
7 |
# This program is free software; you can redistribute it and/or modify
|
8 |
# it under the terms of the GNU General Public License version 2 as
|
9 |
# published by the Free Software Foundation.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful,
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
# GNU General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 |
################################################################################
|
20 |
|
21 |
"""
|
22 |
Un plugin pour VigiBoard qui ajoute une colonne avec les groupes
|
23 |
d'éléments supervisés auxquels appartient l'objet associé
|
24 |
à l'événement corrélé.
|
25 |
"""
|
26 |
import tw.forms as twf |
27 |
from pylons.i18n import lazy_ugettext as l_ |
28 |
|
29 |
from vigiboard.controllers.plugins import VigiboardRequestPlugin |
30 |
from vigilo.models.session import DBSession |
31 |
from vigilo.models import tables |
32 |
from vigilo.models.tables.group import Group |
33 |
from vigilo.models.tables.grouphierarchy import GroupHierarchy |
34 |
from vigilo.models.tables.secondary_tables import SUPITEM_GROUP_TABLE |
35 |
from sqlalchemy.sql.expression import or_ |
36 |
|
37 |
from repoze.what.predicates import in_group |
38 |
from tg import request |
39 |
|
40 |
class GroupSelector(twf.InputField): |
41 |
params = ["choose_text", "text_value", "clear_text"] |
42 |
choose_text = l_('Choose')
|
43 |
clear_text = l_('Clear')
|
44 |
text_value = ''
|
45 |
|
46 |
template = """
|
47 |
<div xmlns="http://www.w3.org/1999/xhtml"
|
48 |
xmlns:py="http://genshi.edgewall.org/" py:strip="">
|
49 |
<input type="hidden" name="${name}" class="${css_class}"
|
50 |
id="${id}.value" value="${value}" py:attrs="attrs" />
|
51 |
<input type="text" class="${css_class}" id="${id}.ui"
|
52 |
value="${text_value}" readonly="readonly" py:attrs="attrs" />
|
53 |
<input type="button" class="${css_class}" id="${id}"
|
54 |
value="${choose_text}" py:attrs="attrs" />
|
55 |
<input type="button" class="${css_class}" id="${id}.clear"
|
56 |
value="${clear_text}" py:attrs="attrs" />
|
57 |
</div>
|
58 |
"""
|
59 |
|
60 |
def update_params(self, d): |
61 |
super(GroupSelector, self).update_params(d) |
62 |
text_value = DBSession.query(Group.name).filter( |
63 |
Group.idgroup == d.value).scalar() |
64 |
if not text_value: |
65 |
d.value = ''
|
66 |
else:
|
67 |
d.text_value = text_value |
68 |
|
69 |
|
70 |
class PluginGroups(VigiboardRequestPlugin): |
71 |
"""
|
72 |
Affiche les groupes d'éléments supervisés auxquels
|
73 |
appartient l'événement corrélé.
|
74 |
"""
|
75 |
def get_search_fields(self): |
76 |
return [
|
77 |
GroupSelector( |
78 |
'supitemgroup',
|
79 |
label_text=l_('Group'),
|
80 |
validator=twf.validators.Int(if_invalid=None, if_missing=None), |
81 |
) |
82 |
] |
83 |
|
84 |
def handle_search_fields(self, query, search, subqueries): |
85 |
if search.get('supitemgroup') is None: |
86 |
return
|
87 |
|
88 |
# Il s'agit d'un manager. On applique le filtre
|
89 |
# indépendamment aux 2 sous-requêtes.
|
90 |
if len(subqueries) == 2: |
91 |
subqueries[0] = subqueries[0].join( |
92 |
(SUPITEM_GROUP_TABLE, |
93 |
or_( |
94 |
SUPITEM_GROUP_TABLE.c.idsupitem == \ |
95 |
tables.LowLevelService.idhost, |
96 |
SUPITEM_GROUP_TABLE.c.idsupitem == \ |
97 |
tables.LowLevelService.idservice, |
98 |
) |
99 |
), |
100 |
(GroupHierarchy, GroupHierarchy.idchild == |
101 |
SUPITEM_GROUP_TABLE.c.idgroup) |
102 |
).filter( |
103 |
GroupHierarchy.idparent == search['supitemgroup']
|
104 |
) |
105 |
|
106 |
subqueries[1] = subqueries[1].join( |
107 |
(SUPITEM_GROUP_TABLE, |
108 |
SUPITEM_GROUP_TABLE.c.idsupitem == \ |
109 |
tables.Host.idhost, |
110 |
), |
111 |
(GroupHierarchy, GroupHierarchy.idchild == |
112 |
SUPITEM_GROUP_TABLE.c.idgroup) |
113 |
).filter( |
114 |
GroupHierarchy.idparent == search['supitemgroup']
|
115 |
) |
116 |
|
117 |
# Il s'agit d'un utilisateur normal.
|
118 |
else:
|
119 |
subqueries[0] = subqueries[0].filter( |
120 |
tables.UserSupItem.idsupitemgroup == search['supitemgroup']
|
121 |
) |