Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / vigiboard_plugin / shn.py @ 53fda08d

History | View | Annotate | Download (2.72 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4: 
3
"""
4
Plugin SHN : High level service
5
"""
6

    
7
from pylons.i18n import gettext as _
8
from tg import url
9
from sqlalchemy.sql import functions
10

    
11
from vigiboard.controllers.vigiboard_plugin import \
12
        VigiboardRequestPlugin
13
from vigiboard.model import DBSession, HighLevelService, \
14
                            CorrEvent, Event, \
15
                            ImpactedHLS, ImpactedPath
16
from vigilo.models.supitem import SupItem
17
from vigilo.models.secondary_tables import EVENTSAGGREGATE_TABLE
18

    
19
class PluginSHN(VigiboardRequestPlugin):
20

    
21
    """
22
    Plugin permettant de rajouter le nombre de SHNs impactés à
23
    l'affichage et d'obtenir une liste détaillée de ces SHNs.
24
    """
25

    
26
    def __init__(self):
27
        super(PluginSHN, self).__init__(
28
            name = _(u'Impacted HLS'),
29
            style = {'title': _(u'Impacted High-Level Services'),
30
                'style': 'text-align:center'},
31
            object_name = "shn"
32
        )
33
    
34
    def show(self, aggregate):
35
        """Fonction d'affichage"""
36
        supitem = DBSession.query(SupItem).join(
37
            (Event, Event.idsupitem == SupItem.idsupitem),
38
            (CorrEvent, CorrEvent.idcause == Event.idevent),
39
        ).filter(CorrEvent.idcorrevent == aggregate.idcorrevent).first()
40

    
41
        if not supitem:
42
            count = 0
43
        else:
44
            count = supitem.impacted_hls(
45
                HighLevelService.idservice
46
            ).count()
47

    
48
        dico = {
49
            'baseurl': url('/'),
50
            'idcorrevent': aggregate.idcorrevent,
51
            'count': count,
52
        }
53

    
54
        # XXX Il faudrait échapper l'URL contenue dans baseurl
55
        # pour éviter des attaques de type XSS.
56
        res = ('<a href="javascript:vigiboard_hls_dialog(this,' + \
57
                '\'%(baseurl)s\',%(idcorrevent)d)" ' + \
58
                'class="hls_link">%(count)d</a>') % dico
59
        return res
60

    
61
    def context(self, context):
62
        """Fonction de context"""
63
        context.append([None, self.object_name])
64

    
65
    def controller(self, *argv, **krgv):
66
        """Ajout de fonctionnalités au contrôleur"""
67
        idcorrevent = krgv['idcorrevent']
68
        supitem = DBSession.query(SupItem).join(
69
            (Event, Event.idsupitem == SupItem.idsupitem),
70
            (CorrEvent, CorrEvent.idcause == Event.idevent),
71
        ).filter(CorrEvent.idcorrevent == idcorrevent).first()
72

    
73
        if not supitem:
74
            # XXX On devrait afficher une erreur (avec tg.flash()).
75
            return []
76

    
77
        services = supitem.impacted_hls(
78
            HighLevelService.servicename
79
        ).order_by(
80
            HighLevelService.servicename.asc()
81
        ).all()
82

    
83
        return dict(services=[service.servicename for service in services])
84