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