Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / plugins / hostname.py @ 25892058

History | View | Annotate | Download (1.9 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4:
3
################################################################################
4
#
5
# Copyright (C) 2007-2013 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
Un plugin pour VigiBoard qui ajoute une colonne avec le nom de l'hôte
22
sur lequel porte l'événement corrélé.
23
"""
24
import tw.forms as twf
25
from pylons.i18n import lazy_ugettext as l_
26

    
27
from vigilo.models.functions import sql_escape_like
28
from vigiboard.controllers.plugins import VigiboardRequestPlugin, ITEMS
29

    
30
class PluginHostname(VigiboardRequestPlugin):
31
    """
32
    Ajoute une colonne avec le nom de l'hôte impacté par un événement corrélé.
33
    """
34
    def get_search_fields(self):
35
        return [
36
            twf.TextField(
37
                'host',
38
                label_text=l_('Host'),
39
                validator=twf.validators.String(if_missing=None),
40
            )
41
        ]
42

    
43
    def handle_search_fields(self, query, search, state, subqueries):
44
        if state != ITEMS:
45
            return
46

    
47
        if search.get('host'):
48
            host = sql_escape_like(search['host'])
49
            query.add_filter(query.items.c.hostname.ilike(host))
50

    
51
    def get_data(self, event):
52
        return {
53
            'hostname': event.hostname,
54
        }