vigiboard / vigiboard / controllers / plugins / priority.py @ 0f0e32ed
History | View | Annotate | Download (4.46 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 la priorité
|
23 |
ITIL de l'événement corrélé.
|
24 |
"""
|
25 |
import tw.forms as twf |
26 |
from pylons.i18n import lazy_ugettext as l_ |
27 |
from formencode import schema, validators |
28 |
|
29 |
from vigilo.models.tables import CorrEvent |
30 |
from vigiboard.controllers.plugins import VigiboardRequestPlugin |
31 |
|
32 |
from tw.forms.fields import ContainerMixin, FormField |
33 |
from tw.core.base import WidgetsList |
34 |
|
35 |
class HorizontalBox(ContainerMixin, FormField): |
36 |
"""
|
37 |
Container de widgets, qui se contente de les placer
|
38 |
côte-à-côte horizontalement.
|
39 |
"""
|
40 |
|
41 |
template = """<div
|
42 |
xmlns="http://www.w3.org/1999/xhtml"
|
43 |
xmlns:py="http://genshi.edgewall.org/"
|
44 |
id="${id}"
|
45 |
name="${name}"
|
46 |
class="${css_class}"
|
47 |
py:attrs="attrs">
|
48 |
<py:for each="field in fields">
|
49 |
${field.display(value_for(field), **args_for(field))}
|
50 |
</py:for>
|
51 |
</div>
|
52 |
"""
|
53 |
|
54 |
def generate_schema(self): |
55 |
"""
|
56 |
Fait en sorte que l'absence de saisie dans les sous-champs
|
57 |
du container ne génère pas une erreur (Valeur manquante)
|
58 |
sur le container lui-même.
|
59 |
"""
|
60 |
super(HorizontalBox, self).generate_schema() |
61 |
self.validator.if_missing = None |
62 |
|
63 |
|
64 |
class PluginPriority(VigiboardRequestPlugin): |
65 |
"""
|
66 |
Ce plugin affiche la priorité ITIL des événements corrélés.
|
67 |
La priorité est un nombre entier et permet de classer les événements
|
68 |
corrélés dans l'ordre qui semble le plus approprié pour que les
|
69 |
problèmes les plus urgents soient traités en premier.
|
70 |
|
71 |
La priorité des événements peut être croissante (plus le nombre est
|
72 |
élevé, plus il est urgent de traiter le problème) ou décroissante
|
73 |
(ordre opposé). L'ordre utilisé par VigiBoard pour le tri est
|
74 |
défini dans la variable de configuration C{vigiboard_priority_order}.
|
75 |
"""
|
76 |
|
77 |
def get_search_fields(self): |
78 |
options = [ |
79 |
('eq', u'='), |
80 |
('neq', u'≠'), |
81 |
('gt', u'>'), |
82 |
('gte', u'≥'), |
83 |
('lt', u'<'), |
84 |
('lte', u'≤'), |
85 |
] |
86 |
|
87 |
return [
|
88 |
HorizontalBox( |
89 |
'priority',
|
90 |
label_text=l_('Priority'),
|
91 |
fields=[ |
92 |
twf.SingleSelectField( |
93 |
'op',
|
94 |
options=options, |
95 |
validator=twf.validators.OneOf( |
96 |
dict(options).keys(),
|
97 |
if_invalid=None,
|
98 |
if_missing=None,
|
99 |
), |
100 |
), |
101 |
twf.TextField( |
102 |
'value',
|
103 |
validator=twf.validators.Int( |
104 |
if_invalid=None,
|
105 |
if_missing=None,
|
106 |
), |
107 |
), |
108 |
], |
109 |
) |
110 |
] |
111 |
|
112 |
def handle_search_fields(self, query, search, subqueries): |
113 |
if (not search.get('priority')): |
114 |
return
|
115 |
|
116 |
op = search['priority']['op'] |
117 |
value = search['priority']['value'] |
118 |
|
119 |
if (not op) or (not value): |
120 |
search['priority'] = None |
121 |
return
|
122 |
|
123 |
if op == 'eq': |
124 |
query.add_filter(CorrEvent.priority == value) |
125 |
elif op == 'neq': |
126 |
query.add_filter(CorrEvent.priority != value) |
127 |
elif op == 'gt': |
128 |
query.add_filter(CorrEvent.priority > value) |
129 |
elif op == 'gte': |
130 |
query.add_filter(CorrEvent.priority >= value) |
131 |
elif op == 'lt': |
132 |
query.add_filter(CorrEvent.priority < value) |
133 |
elif op == 'lte': |
134 |
query.add_filter(CorrEvent.priority <= value) |