Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (1.34 KB)

1 15b98053 Francois POIROTTE
# -*- coding: utf-8 -*-
2 4febadf0 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
6 15b98053 Francois POIROTTE
"""
7 4febadf0 Francois POIROTTE
Un plugin pour VigiBoard qui ajoute une colonne avec le nom de l'hôte
8
sur lequel porte 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
from vigilo.models.functions import sql_escape_like
14 86662bc9 Francois POIROTTE
from vigiboard.controllers.plugins import VigiboardRequestPlugin, ITEMS
15 15b98053 Francois POIROTTE
16
class PluginHostname(VigiboardRequestPlugin):
17 4febadf0 Francois POIROTTE
    """
18
    Ajoute une colonne avec le nom de l'hôte impacté par un événement corrélé.
19
    """
20 27140946 Francois POIROTTE
    def get_search_fields(self):
21
        return [
22
            twf.TextField(
23
                'host',
24
                label_text=l_('Host'),
25
                validator=twf.validators.String(if_missing=None),
26
            )
27
        ]
28
29 86662bc9 Francois POIROTTE
    def handle_search_fields(self, query, search, state, subqueries):
30
        if state != ITEMS:
31
            return
32
33 27140946 Francois POIROTTE
        if search.get('host'):
34
            host = sql_escape_like(search['host'])
35
            query.add_filter(query.items.c.hostname.ilike(host))
36 a2fa6a5b Francois POIROTTE
37
    def get_data(self, event):
38
        return {
39
            'hostname': event.hostname,
40
        }
41 5a845c93 Vincent QUEMENER
42
    def get_sort_criterion(self, query, column):
43
        if column == 'hostname':
44
            return query.items.c.hostname
45
        return None