vigiboard / vigiboard / controllers / plugins / masked_events.py @ 87345eb9
History | View | Annotate | Download (2.28 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4:
|
3 |
################################################################################
|
4 |
#
|
5 |
# Copyright (C) 2007-2015 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 une colonne avec le nombre
|
23 |
d'événements masqués d'un événement corrélé.
|
24 |
"""
|
25 |
from sqlalchemy.sql import functions as func |
26 |
from vigiboard.controllers.plugins import VigiboardRequestPlugin |
27 |
|
28 |
from vigilo.models.session import DBSession |
29 |
from vigilo.models.tables.secondary_tables import EVENTSAGGREGATE_TABLE |
30 |
|
31 |
class PluginMaskedEvents(VigiboardRequestPlugin): |
32 |
"""
|
33 |
Affiche le nombre d'événements masqués par l'événement corrélé.
|
34 |
"""
|
35 |
def get_bulk_data(self, events_ids): |
36 |
"""
|
37 |
Renvoie le nombre d'événements masqués par celui-ci.
|
38 |
|
39 |
@param events_ids: Liste des identifiants des événements corrélés
|
40 |
à afficher.
|
41 |
@type events_ids: C{int}
|
42 |
@return: Un dictionnaire associant à chaque identifiant d'évènement
|
43 |
le nombre d'événements masqués.
|
44 |
@rtype: C{dict}
|
45 |
"""
|
46 |
counts = DBSession.query( |
47 |
func.count().label('masked'),
|
48 |
EVENTSAGGREGATE_TABLE.c.idcorrevent |
49 |
).group_by(EVENTSAGGREGATE_TABLE.c.idcorrevent |
50 |
).filter(EVENTSAGGREGATE_TABLE.c.idcorrevent.in_(events_ids)) |
51 |
|
52 |
res = {} |
53 |
for count in counts: |
54 |
# Il faut retirer la cause du décompte.
|
55 |
res[count.idcorrevent] = count.masked - 1
|
56 |
return res
|
57 |
|
58 |
def get_data(self, event): |
59 |
return {
|
60 |
'id': event[0].idcorrevent, |
61 |
} |