Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / plugins / hls.py @ cf3c2494

History | View | Annotate | Download (4.06 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4:
3
################################################################################
4
#
5
# Copyright (C) 2007-2011 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 les services de haut
23
niveau (L{HighLevelService}) impactés par un événement.
24
"""
25

    
26
from vigiboard.controllers.plugins import VigiboardRequestPlugin
27
from vigilo.models.session import DBSession
28
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

    
33
class PluginHLS(VigiboardRequestPlugin):
34
    """
35
    Plugin qui permet de voir les services de haut niveau impactés par
36
    les événements affichés sur la page principale de VigiBoard.
37
    """
38

    
39
    def get_bulk_data(self, events_ids):
40
        """
41
        Renvoie le nom des services de haut niveau impactés
42
        par chacun des événements du tableau de VigiBoard.
43

44
        @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
        """
51

    
52
        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

    
80
        # 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
            HighLevelService.servicename.asc()
92
        ).all()
93

    
94
        # 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
103