Revision e307e626
Suppression du !BaseController spécifique de l'application (utilisation de celui dans vigilo.turbogears.controllers).
Utilisation de schémas de validation !FormEncode dans le contrôleur principal (en remplacement des validateurs individuels, plus limités).
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2808 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigiboard/controllers/root.py | ||
---|---|---|
15 | 15 |
from sqlalchemy import asc |
16 | 16 |
from sqlalchemy.sql import func |
17 | 17 |
from repoze.what.predicates import Any, not_anonymous |
18 |
from formencode import validators, schema |
|
18 | 19 |
|
19 | 20 |
from vigilo.models.session import DBSession |
20 | 21 |
from vigilo.models.tables import Event, EventHistory, CorrEvent, Host, \ |
... | ... | |
22 | 23 |
from vigilo.models.functions import sql_escape_like |
23 | 24 |
from vigilo.models.tables.secondary_tables import EVENTSAGGREGATE_TABLE |
24 | 25 |
|
25 |
from vigilo.turbogears.controllers.autocomplete \ |
|
26 |
import make_autocomplete_controller |
|
26 |
from vigilo.turbogears.controllers.autocomplete import AutoCompleteController |
|
27 | 27 |
from vigilo.turbogears.helpers import get_current_user |
28 | 28 |
|
29 | 29 |
from vigiboard.controllers.vigiboardrequest import VigiboardRequest |
30 | 30 |
from vigiboard.controllers.vigiboard_controller import VigiboardRootController |
31 | 31 |
from vigiboard.widgets.edit_event import edit_event_status_options |
32 |
from vigiboard.lib.base import BaseController |
|
33 | 32 |
|
34 | 33 |
__all__ = ('RootController', 'get_last_modification_timestamp', |
35 | 34 |
'date_to_timestamp') |
... | ... | |
39 | 38 |
""" |
40 | 39 |
Le controller général de vigiboard |
41 | 40 |
""" |
42 |
autocomplete = make_autocomplete_controller(BaseController)
|
|
41 |
autocomplete = AutoCompleteController()
|
|
43 | 42 |
|
44 | 43 |
def process_form_errors(self, *argv, **kwargv): |
45 | 44 |
""" |
... | ... | |
50 | 49 |
flash("'%s': %s" % (k, tmpl_context.form_errors[k]), 'error') |
51 | 50 |
redirect(request.environ.get('HTTP_REFERER', '/')) |
52 | 51 |
|
53 |
@validate(validators={ |
|
54 |
'page': validators.Int(min=1), |
|
55 |
}, error_handler = process_form_errors) |
|
52 |
|
|
53 |
class DefaultSchema(schema.Schema): |
|
54 |
page = validators.Int(min=1, if_missing=1, if_invalid=1) |
|
55 |
supitemgroup = validators.String(if_missing=None) |
|
56 |
host = validators.String(if_missing=None) |
|
57 |
service = validators.String(if_missing=None) |
|
58 |
output = validators.String(if_missing=None) |
|
59 |
trouble_ticket = validators.String(if_missing=None) |
|
60 |
from_date = validators.String(if_missing=None) |
|
61 |
to_date = validators.String(if_missing=None) |
|
62 |
|
|
63 |
@validate( |
|
64 |
validators=DefaultSchema(), |
|
65 |
error_handler = process_form_errors) |
|
56 | 66 |
@expose('events_table.html') |
57 | 67 |
@require(Any(not_anonymous(), msg=l_("You need to be authenticated"))) |
58 |
def default(self, page=1, supitemgroup=None, |
|
59 |
host=None, service=None, output=None, trouble_ticket=None, |
|
60 |
from_date=None, to_date=None, *argv, **krgv): |
|
68 |
def default(self, page, supitemgroup, host, service, |
|
69 |
output, trouble_ticket, from_date, to_date): |
|
61 | 70 |
""" |
62 | 71 |
Page d'accueil de Vigiboard. Elle affiche, suivant la page demandée |
63 | 72 |
(page 1 par defaut), la liste des événements, rangés par ordre de prise |
... | ... | |
77 | 86 |
- VIGILO_EXIG_VIGILO_BAC_0070, |
78 | 87 |
- VIGILO_EXIG_VIGILO_BAC_0100, |
79 | 88 |
""" |
80 |
if not page: |
|
81 |
page = 1 |
|
82 |
|
|
83 | 89 |
user = get_current_user() |
84 | 90 |
aggregates = VigiboardRequest(user) |
85 | 91 |
aggregates.add_table( |
... | ... | |
196 | 202 |
refresh_times = config['vigiboard_refresh_times'], |
197 | 203 |
) |
198 | 204 |
|
199 |
@validate(validators={ |
|
200 |
'idcorrevent': validators.Int(not_empty=True), |
|
201 |
'page': validators.Int(min=1), |
|
202 |
}, error_handler = process_form_errors) |
|
205 |
|
|
206 |
class MaskedEventsSchema(schema.Schema): |
|
207 |
idcorrevent = validators.Int(not_empty=True) |
|
208 |
page = validators.Int(min=1, if_missing=1, if_invalid=1) |
|
209 |
|
|
210 |
@validate( |
|
211 |
validators=MaskedEventsSchema(), |
|
212 |
error_handler = process_form_errors) |
|
203 | 213 |
@expose('raw_events_table.html') |
204 | 214 |
@require(Any(not_anonymous(), msg=l_("You need to be authenticated"))) |
205 |
def masked_events(self, idcorrevent, page=1):
|
|
215 |
def masked_events(self, idcorrevent, page): |
|
206 | 216 |
""" |
207 | 217 |
Affichage de la liste des événements bruts masqués dans un |
208 | 218 |
événement corrélé (agrégés). |
209 | 219 |
|
210 | 220 |
@param idevent: identifiant de l'événement souhaité |
211 | 221 |
""" |
212 |
if not page: |
|
213 |
page = 1 |
|
214 |
|
|
215 | 222 |
user = get_current_user() |
216 | 223 |
|
217 | 224 |
# Récupère la liste des événements masqués de l'événement |
... | ... | |
301 | 308 |
refresh_times=config['vigiboard_refresh_times'], |
302 | 309 |
) |
303 | 310 |
|
304 |
@validate(validators={ |
|
305 |
'idevent': validators.Int(not_empty=True), |
|
306 |
'page': validators.Int(min=1), |
|
307 |
}, error_handler = process_form_errors) |
|
311 |
|
|
312 |
class EventSchema(schema.Schema): |
|
313 |
idevent = validators.Int(not_empty=True) |
|
314 |
page = validators.Int(min=1, if_missing=1, if_invalid=1) |
|
315 |
|
|
316 |
@validate( |
|
317 |
validators=EventSchema(), |
|
318 |
error_handler = process_form_errors) |
|
308 | 319 |
@expose('history_table.html') |
309 | 320 |
@require(Any(not_anonymous(), msg=l_("You need to be authenticated"))) |
310 |
def event(self, idevent, page=1):
|
|
321 |
def event(self, idevent, page): |
|
311 | 322 |
""" |
312 | 323 |
Affichage de l'historique d'un événement brut. |
313 | 324 |
Pour accéder à cette page, l'utilisateur doit être authentifié. |
... | ... | |
385 | 396 |
refresh_times=config['vigiboard_refresh_times'], |
386 | 397 |
) |
387 | 398 |
|
399 |
|
|
400 |
class ItemSchema(schema.Schema): |
|
401 |
page = validators.Int(min=1, if_missing=1, if_invalid=1) |
|
402 |
host = validators.String(not_empty=True) |
|
403 |
service = validators.String(if_missing=None) |
|
404 |
|
|
388 | 405 |
@validate( |
389 |
validators={ |
|
390 |
'host': validators.NotEmpty(), |
|
391 |
# 'service': validators.NotEmpty(), |
|
392 |
'page': validators.Int(min=1), |
|
393 |
}, |
|
406 |
validators=ItemSchema(), |
|
394 | 407 |
error_handler = process_form_errors) |
395 | 408 |
@expose('events_table.html') |
396 | 409 |
@require(Any(not_anonymous(), msg=l_("You need to be authenticated"))) |
397 |
def item(self, page, host, service=None):
|
|
410 |
def item(self, page, host, service): |
|
398 | 411 |
""" |
399 | 412 |
Affichage de l'historique de l'ensemble des événements corrélés |
400 | 413 |
jamais ouverts sur l'hôte / service demandé. |
... | ... | |
465 | 478 |
refresh_times=config['vigiboard_refresh_times'], |
466 | 479 |
) |
467 | 480 |
|
468 |
@validate(validators={ |
|
469 |
"id": validators.Regex(r'^[0-9]+(,[0-9]+)*,?$'), |
|
470 |
"last_modification": validators.Number(not_empty=True), |
|
471 |
"trouble_ticket": validators.String(if_missing=''), |
|
472 |
"ack": validators.OneOf([ |
|
481 |
|
|
482 |
class UpdateSchema(schema.Schema): |
|
483 |
id = validators.Regex(r'^[0-9]+(,[0-9]+)*,?$') |
|
484 |
last_modification = validators.Number(not_empty=True) |
|
485 |
trouble_ticket = validators.String(if_missing='') |
|
486 |
ack = validators.OneOf([ |
|
473 | 487 |
u'NoChange', |
474 | 488 |
u'None', |
475 | 489 |
u'Acknowledged', |
476 | 490 |
u'AAClosed' |
477 |
], not_empty=True)}, error_handler = process_form_errors) |
|
491 |
], not_empty=True) |
|
492 |
|
|
493 |
@validate( |
|
494 |
validators=UpdateSchema(), |
|
495 |
error_handler = process_form_errors) |
|
478 | 496 |
@require(Any(not_anonymous(), msg=l_("You need to be authenticated"))) |
479 | 497 |
@expose() |
480 | 498 |
def update(self, id, last_modification, trouble_ticket, ack): |
... | ... | |
573 | 591 |
flash(_('Updated successfully')) |
574 | 592 |
redirect(request.environ.get('HTTP_REFERER', '/')) |
575 | 593 |
|
576 |
@validate(validators={ |
|
577 |
"plugin_name": validators.OneOf([i[0] for i \ |
|
578 |
in config.get('vigiboard_plugins', [])]), |
|
579 |
'idcorrevent': validators.Int(not_empty=True), |
|
580 |
}, error_handler=process_form_errors) |
|
594 |
|
|
595 |
class GetPluginValueSchema(schema.Schema): |
|
596 |
idcorrevent = validators.Int(not_empty=True) |
|
597 |
plugin_name = validators.OneOf( |
|
598 |
i[0] for i in config.get('vigiboard_plugins', [])) |
|
599 |
# Permet de passer des paramètres supplémentaires au plugin. |
|
600 |
allow_extra_fields = True |
|
601 |
|
|
602 |
@validate( |
|
603 |
validators=GetPluginValueSchema(), |
|
604 |
error_handler = process_form_errors) |
|
581 | 605 |
@expose('json') |
582 | 606 |
@require(Any(not_anonymous(), msg=l_("You need to be authenticated"))) |
583 | 607 |
def get_plugin_value(self, idcorrevent, plugin_name, *arg, **krgv): |
Also available in: Unified diff