Revision a2fa6a5b
Export CSV alertes de VigiBoard (#954).
Permet l'export des alertes (événements corrélés) affichés à l'écran au
format CSV. L'export tient compte des critères de recherche
éventuellement appliqués.
Refs: #954.
Change-Id: I3c6639dbef9ca53043d45d8a683f5c77619af23a
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/1017
Tested-by: Build system <qa@vigilo-dev.si.c-s.fr>
Reviewed-by: Thomas BURGUIERE <thomas.burguiere@c-s.fr>
vigiboard/controllers/root.py | ||
---|---|---|
27 | 27 |
|
28 | 28 |
from tg.exceptions import HTTPNotFound |
29 | 29 |
from tg import expose, validate, require, flash, url, \ |
30 |
tmpl_context, request, config, session, redirect |
|
30 |
tmpl_context, request, response, config, session, redirect
|
|
31 | 31 |
from webhelpers import paginate |
32 | 32 |
from tw.forms import validators |
33 | 33 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_, get_lang |
... | ... | |
59 | 59 |
from vigiboard.controllers.vigiboardrequest import VigiboardRequest |
60 | 60 |
from vigiboard.controllers.feeds import FeedsController |
61 | 61 |
|
62 |
from vigiboard.lib import export_csv |
|
62 | 63 |
from vigiboard.widgets.edit_event import edit_event_status_options, \ |
63 | 64 |
EditEventForm |
64 | 65 |
from vigiboard.widgets.search_form import create_search_form |
... | ... | |
127 | 128 |
validators=IndexSchema(), |
128 | 129 |
error_handler = process_form_errors) |
129 | 130 |
@expose('events_table.html') |
131 |
@expose('csv', content_type='text/csv') |
|
130 | 132 |
@require(access_restriction) |
131 | 133 |
def index(self, page, **search): |
132 | 134 |
""" |
... | ... | |
201 | 203 |
plugin_data = plugins[plugin].get_bulk_data(ids_correvents) |
202 | 204 |
if plugin_data: |
203 | 205 |
plugins_data[plugin] = plugin_data |
206 |
else: |
|
207 |
plugins_data[plugin] = {} |
|
204 | 208 |
|
205 | 209 |
# Ajout des formulaires et préparation |
206 | 210 |
# des données pour ces formulaires. |
... | ... | |
210 | 214 |
tmpl_context.edit_event_form = EditEventForm("edit_event_form", |
211 | 215 |
submit_text=_('Apply'), action=url('/update')) |
212 | 216 |
|
217 |
if request.response_type == 'text/csv': |
|
218 |
# Sans les 2 en-têtes suivants qui désactivent la mise en cache, |
|
219 |
# Internet Explorer refuse de télécharger le fichier CSV (cf. #961). |
|
220 |
response.headers['Pragma'] = 'public' # Nécessaire pour IE. |
|
221 |
response.headers['Cache-Control'] = 'max-age=0' # Nécessaire pour IE. |
|
222 |
|
|
223 |
response.headers['Content-Disposition'] = \ |
|
224 |
'attachment;filename="alerts.csv"' |
|
225 |
return export_csv.export(page, plugins_data) |
|
226 |
|
|
213 | 227 |
return dict( |
214 | 228 |
hostname = None, |
215 | 229 |
servicename = None, |
... | ... | |
465 | 479 |
tmpl_context.edit_event_form = EditEventForm("edit_event_form", |
466 | 480 |
submit_text=_('Apply'), action=url('/update')) |
467 | 481 |
|
482 |
plugins_data = {} |
|
483 |
for plugin in dict(config['columns_plugins']): |
|
484 |
plugins_data[plugin] = {} |
|
485 |
|
|
468 | 486 |
return dict( |
469 | 487 |
hostname = host, |
470 | 488 |
servicename = service, |
471 |
plugins_data = {},
|
|
489 |
plugins_data = plugins_data,
|
|
472 | 490 |
page = page, |
473 | 491 |
event_edit_status_options = edit_event_status_options, |
474 | 492 |
search_form = create_search_form, |
... | ... | |
721 | 739 |
# l'utilisateur (s'il n'appartient pas au groupe 'managers') |
722 | 740 |
is_manager = in_group('managers').is_met(request.environ) |
723 | 741 |
if not is_manager: |
724 |
|
|
725 | 742 |
user = get_current_user() |
726 | 743 |
|
727 | 744 |
events = events.join( |
Also available in: Unified diff