vigiboard / vigiboard / controllers / plugins / details.py @ cf3c2494
History | View | Annotate | Download (3.67 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 liens vers les
|
23 | entrées d'historiques liées à l'événement, ainsi que les liens vers les
|
||
24 | applications externes.
|
||
25 | 15b98053 | Francois POIROTTE | """
|
26 | |||
27 | import urllib |
||
28 | |||
29 | 94f31908 | Francois POIROTTE | from tg.exceptions import HTTPForbidden |
30 | 4c949ec9 | Francois POIROTTE | from tg import config, url |
31 | 15b98053 | Francois POIROTTE | |
32 | from vigiboard.controllers.vigiboardrequest import VigiboardRequest |
||
33 | 94f31908 | Francois POIROTTE | from vigiboard.controllers.plugins import VigiboardRequestPlugin |
34 | df25ac35 | Francois POIROTTE | from vigilo.models.tables import CorrEvent, Event, StateName |
35 | from vigilo.turbogears.helpers import get_current_user |
||
36 | 15b98053 | Francois POIROTTE | |
37 | 94f31908 | Francois POIROTTE | class PluginDetails(VigiboardRequestPlugin): |
38 | 4febadf0 | Francois POIROTTE | """
|
39 | Plugin qui ajoute des liens vers les historiques et les applications
|
||
40 | externes.
|
||
41 | """
|
||
42 | |||
43 | cf3c2494 | Vincent QUEMENER | def get_json_data(self, idcorrevent, *args, **kwargs): |
44 | 15b98053 | Francois POIROTTE | """
|
45 | Renvoie les éléments pour l'affichage de la fenêtre de dialogue
|
||
46 | 94f31908 | Francois POIROTTE | contenant des détails sur un événement corrélé.
|
47 | 15b98053 | Francois POIROTTE |
|
48 | 94f31908 | Francois POIROTTE | @param idcorrevent: identifiant de l'événement corrélé.
|
49 | @type idcorrevent: C{int}
|
||
50 | 15b98053 | Francois POIROTTE | """
|
51 | |||
52 | # Obtention de données sur l'événement et sur son historique
|
||
53 | df25ac35 | Francois POIROTTE | user = get_current_user() |
54 | if user is None: |
||
55 | return None |
||
56 | 15b98053 | Francois POIROTTE | |
57 | df25ac35 | Francois POIROTTE | events = VigiboardRequest(user, False)
|
58 | 15b98053 | Francois POIROTTE | 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 | 65383903 | Francois POIROTTE | events.add_join((events.items, |
65 | 15b98053 | Francois POIROTTE | 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 | 94f31908 | Francois POIROTTE | raise HTTPForbidden()
|
71 | 15b98053 | Francois POIROTTE | |
72 | event = events.req[0]
|
||
73 | eventdetails = {} |
||
74 | 65383903 | Francois POIROTTE | for edname, edlink in enumerate(config['vigiboard_links.eventdetails']): |
75 | 15b98053 | Francois POIROTTE | |
76 | if event.servicename:
|
||
77 | service = urllib.quote(event.servicename) |
||
78 | else:
|
||
79 | service = None
|
||
80 | bcf87133 | Francois POIROTTE | |
81 | 6e76504a | Francois POIROTTE | eventdetails[unicode(edname)] = url(edlink[1]) % { |
82 | 15b98053 | Francois POIROTTE | '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 | bcf87133 | Francois POIROTTE | idcause = event[0].idevent,
|
100 | 15b98053 | Francois POIROTTE | ) |