Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / plugins / status.py @ a2744508

History | View | Annotate | Download (3.44 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4:
3
################################################################################
4
#
5
# Copyright (C) 2007-2012 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 3 colonnes au tableau des événements :
23
    -   la première colonne contient l'état d'acquittement de l'événement.
24
    -   la seconde colonne contient un lien permettant d'éditer certaines
25
        propriétés associées à l'événement corrélé.
26
    -   la dernière colonne permet de (dé)sélectionner l'événement pour
27
        effectuer un traitement par lot.
28
"""
29
import tw.forms as twf
30
from pylons.i18n import lazy_ugettext as l_
31

    
32
from vigilo.models.tables import CorrEvent
33
from vigilo.models.functions import sql_escape_like
34
from vigiboard.controllers.plugins import VigiboardRequestPlugin, ITEMS
35

    
36
class PluginStatus(VigiboardRequestPlugin):
37
    """
38
    Ajoute des colonnes permettant de voir le statut d'acquittement
39
    d'un événement corrélé et de modifier certaines de ses propriétés.
40
    """
41

    
42
    def get_generated_columns_count(self):
43
        """
44
        Renvoie le nombre de colonnes que ce plugin ajoute.
45
        Ce plugin en ajoute 4, au lieu de 1 comme la plupart des plugins.
46
        """
47
        return 4
48

    
49
    def get_search_fields(self):
50
        options = [
51
            ('', l_('All alerts')),
52
            # On doit passer un type basestring pour les options.
53
            # Donc, on convertit les constantes (entiers) en type str.
54
            (str(CorrEvent.ACK_NONE),   l_('New alerts')),
55
            (str(CorrEvent.ACK_KNOWN),  l_('Alerts marked as Acknowledged')),
56
            (str(CorrEvent.ACK_CLOSED), l_('Alerts marked as Closed')),
57
        ]
58

    
59
        return [
60
            twf.TextField(
61
                'trouble_ticket',
62
                label_text=l_('Trouble Ticket'),
63
                validator=twf.validators.String(if_missing=None),
64
            ),
65
            twf.SingleSelectField(
66
                'ack',
67
                label_text=l_('Acknowledgement Status'),
68
                options=options,
69
                validator=twf.validators.OneOf(
70
                    dict(options).keys(),
71
                    if_invalid=None,
72
                    if_missing=None,
73
                ),
74
            ),
75
        ]
76

    
77
    def handle_search_fields(self, query, search, state, subqueries):
78
        if state != ITEMS:
79
            return
80

    
81
        if search.get('trouble_ticket'):
82
            tt = sql_escape_like(search['trouble_ticket'])
83
            query.add_filter(CorrEvent.trouble_ticket.ilike(tt))
84

    
85
        if search.get('ack'):
86
            try:
87
                query.add_filter(CorrEvent.ack == int(search['ack']))
88
            except (ValueError, TypeError):
89
                # On ignore silencieusement le critère de recherche erroné.
90
                pass