Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / plugins / priority.py @ 011743be

History | View | Annotate | Download (4.06 KB)

1 15b98053 Francois POIROTTE
# -*- coding: utf-8 -*-
2 a77de887 Francois POIROTTE
# vim:set expandtab tabstop=4 shiftwidth=4:
3 011743be Francois POIROTTE
# Copyright (C) 2007-2020 CS GROUP - France
4 9b8d9497 Francois POIROTTE
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
5 a77de887 Francois POIROTTE
6 15b98053 Francois POIROTTE
"""
7 4febadf0 Francois POIROTTE
Un plugin pour VigiBoard qui ajoute une colonne avec la priorité
8
ITIL de l'événement corrélé.
9 15b98053 Francois POIROTTE
"""
10 27140946 Francois POIROTTE
import tw.forms as twf
11 02c4a1e7 Francois POIROTTE
from tg.i18n import lazy_ugettext as l_
12 27140946 Francois POIROTTE
13 a2fa6a5b Francois POIROTTE
from vigilo.models.tables import CorrEvent, StateName
14 86662bc9 Francois POIROTTE
from vigiboard.controllers.plugins import VigiboardRequestPlugin, ITEMS
15 15b98053 Francois POIROTTE
16 27140946 Francois POIROTTE
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 15b98053 Francois POIROTTE
class PluginPriority(VigiboardRequestPlugin):
48 4febadf0 Francois POIROTTE
    """
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 27140946 Francois POIROTTE
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 86662bc9 Francois POIROTTE
    def handle_search_fields(self, query, search, state, subqueries):
96
        if (not search.get('priority')) or state != ITEMS:
97 27140946 Francois POIROTTE
            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 a2fa6a5b Francois POIROTTE
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 5a845c93 Vincent QUEMENER
126
    def get_sort_criterion(self, query, column):
127
        if column == 'priority':
128
            return CorrEvent.priority
129
        return None