vigiboard / vigiboard / controllers / plugins / hls.py @ cf3c2494
History | View | Annotate | Download (4.06 KB)
1 | 15b98053 | Francois POIROTTE | # -*- coding: utf-8 -*-
|
---|---|---|---|
2 | 4febadf0 | Francois POIROTTE | # vim:set expandtab tabstop=4 shiftwidth=4:
|
3 | a77de887 | Francois POIROTTE | ################################################################################
|
4 | #
|
||
5 | 3b537383 | Francois POIROTTE | # Copyright (C) 2007-2011 CS-SI
|
6 | a77de887 | Francois POIROTTE | #
|
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 | 15b98053 | Francois POIROTTE | """
|
22 | 4febadf0 | Francois POIROTTE | Un plugin pour VigiBoard qui ajoute une colonne avec les services de haut
|
23 | niveau (L{HighLevelService}) impactés par un événement.
|
||
24 | 15b98053 | Francois POIROTTE | """
|
25 | |||
26 | 94f31908 | Francois POIROTTE | from vigiboard.controllers.plugins import VigiboardRequestPlugin |
27 | e7e3d45e | Francois POIROTTE | from vigilo.models.session import DBSession |
28 | cf3c2494 | Vincent QUEMENER | from vigilo.models.tables import HighLevelService, CorrEvent, Event, SupItem, \ |
29 | ImpactedHLS, ImpactedPath |
||
30 | from sqlalchemy.orm import aliased |
||
31 | from sqlalchemy.sql import functions |
||
32 | 15b98053 | Francois POIROTTE | |
33 | class PluginHLS(VigiboardRequestPlugin): |
||
34 | """
|
||
35 | 4febadf0 | Francois POIROTTE | Plugin qui permet de voir les services de haut niveau impactés par
|
36 | cf3c2494 | Vincent QUEMENER | les événements affichés sur la page principale de VigiBoard.
|
37 | 15b98053 | Francois POIROTTE | """
|
38 | cf3c2494 | Vincent QUEMENER | |
39 | def get_bulk_data(self, events_ids): |
||
40 | 4febadf0 | Francois POIROTTE | """
|
41 | cf3c2494 | Vincent QUEMENER | Renvoie le nom des services de haut niveau impactés
|
42 | par chacun des événements du tableau de VigiBoard.
|
||
43 | 4febadf0 | Francois POIROTTE |
|
44 | cf3c2494 | Vincent QUEMENER | @param events_ids: Liste des identifiants des événements corrélés
|
45 | à afficher.
|
||
46 | @type events_ids: C{int}
|
||
47 | @return: Un dictionnaire associant à chaque identifiant d'évènement
|
||
48 | la liste des noms des HLS de plus haut niveau qu'il impacte.
|
||
49 | @rtype: C{dict}
|
||
50 | 4febadf0 | Francois POIROTTE | """
|
51 | 15b98053 | Francois POIROTTE | |
52 | cf3c2494 | Vincent QUEMENER | imp_hls1 = aliased(ImpactedHLS) |
53 | imp_hls2 = aliased(ImpactedHLS) |
||
54 | |||
55 | # Sous-requête récupérant les identifiants des supitems
|
||
56 | # impactés par les évènements passés en paramètre.
|
||
57 | subquery = DBSession.query( |
||
58 | SupItem.idsupitem, |
||
59 | CorrEvent.idcorrevent |
||
60 | ).join( |
||
61 | (Event, Event.idsupitem == SupItem.idsupitem), |
||
62 | (CorrEvent, CorrEvent.idcause == Event.idevent), |
||
63 | ).filter(CorrEvent.idcorrevent.in_(events_ids) |
||
64 | ).subquery() |
||
65 | |||
66 | # Sous-requête récupérant les identifiants des SHN de plus
|
||
67 | # haut niveau impactés par les évènements passés en paramètre.
|
||
68 | # Fait appel à la sous-requête précédente (subquery).
|
||
69 | subquery2 = DBSession.query( |
||
70 | functions.max(imp_hls1.distance).label('distance'),
|
||
71 | imp_hls1.idpath, |
||
72 | subquery.c.idcorrevent |
||
73 | ).join( |
||
74 | (ImpactedPath, ImpactedPath.idpath == imp_hls1.idpath) |
||
75 | ).join( |
||
76 | (subquery, ImpactedPath.idsupitem == subquery.c.idsupitem) |
||
77 | ).group_by(imp_hls1.idpath, subquery.c.idcorrevent |
||
78 | ).subquery() |
||
79 | 15b98053 | Francois POIROTTE | |
80 | cf3c2494 | Vincent QUEMENER | # Requête récupérant les noms des SHN de plus haut niveau
|
81 | # impactés par chacun des évènements passés en paramètre.
|
||
82 | # Fait appel à la sous-requête précédente (subquery2).
|
||
83 | services = DBSession.query( |
||
84 | HighLevelService.servicename, |
||
85 | subquery2.c.idcorrevent |
||
86 | ).join( |
||
87 | (imp_hls2, HighLevelService.idservice == imp_hls2.idhls), |
||
88 | (subquery2, subquery2.c.idpath == imp_hls2.idpath), |
||
89 | ).filter(imp_hls2.distance == subquery2.c.distance |
||
90 | ).order_by( |
||
91 | 15b98053 | Francois POIROTTE | HighLevelService.servicename.asc() |
92 | ).all() |
||
93 | |||
94 | cf3c2494 | Vincent QUEMENER | # Construction d'un dictionnaire associant à chaque évènement
|
95 | # le nom des SHN de plus haut niveau qu'il impacte.
|
||
96 | hls = {} |
||
97 | for event_id in events_ids: |
||
98 | hls[event_id] = [] |
||
99 | for service in services: |
||
100 | hls[service.idcorrevent].append(service.servicename) |
||
101 | |||
102 | return hls
|