vigiboard / vigiboard / controllers / plugins / hostname.py @ 8c198622
History | View | Annotate | Download (1.33 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4:
|
3 |
# Copyright (C) 2007-2019 CS-SI
|
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 le nom de l'hôte
|
8 |
sur lequel porte 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.functions import sql_escape_like |
14 |
from vigiboard.controllers.plugins import VigiboardRequestPlugin, ITEMS |
15 |
|
16 |
class PluginHostname(VigiboardRequestPlugin): |
17 |
"""
|
18 |
Ajoute une colonne avec le nom de l'hôte impacté par un événement corrélé.
|
19 |
"""
|
20 |
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 |
def handle_search_fields(self, query, search, state, subqueries): |
30 |
if state != ITEMS:
|
31 |
return
|
32 |
|
33 |
if search.get('host'): |
34 |
host = sql_escape_like(search['host'])
|
35 |
query.add_filter(query.items.c.hostname.ilike(host)) |
36 |
|
37 |
def get_data(self, event): |
38 |
return {
|
39 |
'hostname': event.hostname,
|
40 |
} |
41 |
|
42 |
def get_sort_criterion(self, query, column): |
43 |
if column == 'hostname': |
44 |
return query.items.c.hostname
|
45 |
return None |
46 |
|