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