vigiboard / vigiboard / controllers / plugins / map.py @ 2bcebf54
History | View | Annotate | Download (3.11 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4:
|
3 |
################################################################################
|
4 |
#
|
5 |
# Copyright (C) 2007-2016 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 |
from sqlalchemy.sql.expression import union_all |
27 |
from sqlalchemy.orm import aliased |
28 |
|
29 |
from vigilo.models.session import DBSession |
30 |
from vigilo.models import tables |
31 |
from vigiboard.controllers.plugins import VigiboardRequestPlugin, INNER |
32 |
|
33 |
class PluginMap(VigiboardRequestPlugin): |
34 |
"""
|
35 |
Ajoute de quoi filtrer sur les cartes.
|
36 |
"""
|
37 |
def get_search_fields(self): |
38 |
return [
|
39 |
twf.HiddenField( |
40 |
'idmap',
|
41 |
validator=twf.validators.Int(if_missing=None),
|
42 |
) |
43 |
] |
44 |
|
45 |
def handle_search_fields(self, query, search, state, subqueries): |
46 |
if state != INNER or not search.get('idmap'): |
47 |
return
|
48 |
idmap = int(search['idmap']) |
49 |
|
50 |
# Il s'agit d'un manager. On applique le filtre
|
51 |
# indépendamment aux 2 sous-requêtes.
|
52 |
if len(subqueries) == 2: |
53 |
mapnodells = DBSession.query( |
54 |
tables.MapNodeLls.idservice |
55 |
).filter(tables.MapNodeLls.idmap == idmap).subquery() |
56 |
|
57 |
mapnodehost = DBSession.query( |
58 |
tables.MapNodeHost.idhost |
59 |
).filter(tables.MapNodeHost.idmap == idmap).subquery() |
60 |
|
61 |
subqueries[0] = subqueries[0].join( |
62 |
(mapnodells, mapnodells.c.idservice == |
63 |
tables.LowLevelService.idservice), |
64 |
) |
65 |
|
66 |
subqueries[1] = subqueries[1].join( |
67 |
(mapnodehost, mapnodehost.c.idhost == |
68 |
tables.Host.idhost), |
69 |
) |
70 |
|
71 |
# Il s'agit d'un utilisateur normal.
|
72 |
else:
|
73 |
mapnodells = DBSession.query( |
74 |
tables.MapNodeLls.idservice.label('idsupitem')
|
75 |
).filter(tables.MapNodeLls.idmap == idmap) |
76 |
|
77 |
mapnodehost = DBSession.query( |
78 |
tables.MapNodeHost.idhost.label('idsupitem')
|
79 |
).filter(tables.MapNodeHost.idmap == idmap) |
80 |
|
81 |
union = union_all(mapnodells, mapnodehost, correlate=False).alias()
|
82 |
subqueries[0] = subqueries[0].join( |
83 |
(union, union.c.idsupitem == tables.UserSupItem.idsupitem), |
84 |
) |
85 |
|