Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.67 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 liens vers les
23
entrées d'historiques liées à l'événement, ainsi que les liens vers les
24
applications externes.
25
"""
26

    
27
import urllib
28

    
29
from tg.exceptions import HTTPForbidden
30
from tg import config, url
31

    
32
from vigiboard.controllers.vigiboardrequest import VigiboardRequest
33
from vigiboard.controllers.plugins import VigiboardRequestPlugin
34
from vigilo.models.tables import CorrEvent, Event, StateName
35
from vigilo.turbogears.helpers import get_current_user
36

    
37
class PluginDetails(VigiboardRequestPlugin):
38
    """
39
    Plugin qui ajoute des liens vers les historiques et les applications
40
    externes.
41
    """
42

    
43
    def get_json_data(self, idcorrevent, *args, **kwargs):
44
        """
45
        Renvoie les éléments pour l'affichage de la fenêtre de dialogue
46
        contenant des détails sur un événement corrélé.
47

48
        @param idcorrevent: identifiant de l'événement corrélé.
49
        @type idcorrevent: C{int}
50
        """
51

    
52
        # Obtention de données sur l'événement et sur son historique
53
        user = get_current_user()
54
        if user is None:
55
            return None
56

    
57
        events = VigiboardRequest(user, False)
58
        events.add_table(
59
            Event,
60
            events.items.c.hostname,
61
            events.items.c.servicename,
62
        )
63
        events.add_join((CorrEvent, CorrEvent.idcause == Event.idevent))
64
        events.add_join((events.items,
65
            Event.idsupitem == events.items.c.idsupitem))
66
        events.add_filter(CorrEvent.idcorrevent == idcorrevent)
67

    
68
        # Vérification que au moins un des identifiants existe et est éditable
69
        if events.num_rows() != 1:
70
            raise HTTPForbidden()
71

    
72
        event = events.req[0]
73
        eventdetails = {}
74
        for edname, edlink in enumerate(config['vigiboard_links.eventdetails']):
75

    
76
            if event.servicename:
77
                service = urllib.quote(event.servicename)
78
            else:
79
                service = None
80

    
81
            eventdetails[unicode(edname)] = url(edlink[1]) % {
82
                'idcorrevent': idcorrevent,
83
                'host': urllib.quote(event.hostname),
84
                'service': service,
85
                'message': urllib.quote(event[0].message),
86
            }
87

    
88
        return dict(
89
                current_state = StateName.value_to_statename(
90
                                    event[0].current_state),
91
                initial_state = StateName.value_to_statename(
92
                                    event[0].initial_state),
93
                peak_state = StateName.value_to_statename(
94
                                    event[0].peak_state),
95
                idcorrevent = idcorrevent,
96
                host = event.hostname,
97
                service = event.servicename,
98
                eventdetails = eventdetails,
99
                idcause = event[0].idevent,
100
            )