Project

General

Profile

Revision cf3c2494

IDcf3c2494ece15ab1296aad363b0e84c7bd2a0da0
Parent 832d63c3
Child 699bd24c

Added by Vincent QUEMENER over 13 years ago

Chaque plugin adresse désormais une seule requête à la base de données pour tous les évènements de la page, plutôt qu'une requête par évènement.

git-svn-id: https://vigilo-dev.si.c-s.fr/svn@6291 b22e2e97-25c9-44ff-b637-2e5ceca36478

View differences:

vigiboard/controllers/root.py
32 32
from sqlalchemy import asc
33 33
from sqlalchemy.sql import func
34 34
from sqlalchemy.orm import aliased
35
from sqlalchemy.orm import contains_eager
35 36
from repoze.what.predicates import Any, All, in_group, \
36 37
                                    has_permission, not_anonymous, \
37 38
                                    NotAuthorizedError
......
135 136
        """
136 137
        user = get_current_user()
137 138
        aggregates = VigiboardRequest(user)
139

  
138 140
        aggregates.add_table(
139 141
            CorrEvent,
140 142
            aggregates.items.c.hostname,
141 143
            aggregates.items.c.servicename
142 144
        )
143 145
        aggregates.add_join((Event, CorrEvent.idcause == Event.idevent))
146
        aggregates.add_contains_eager(CorrEvent.cause)
147
        aggregates.add_group_by(Event)
144 148
        aggregates.add_join((aggregates.items,
145 149
            Event.idsupitem == aggregates.items.c.idsupitem))
146 150
        aggregates.add_order_by(asc(aggregates.items.c.hostname))
......
228 232
        else:
229 233
            id_first_row += 1
230 234

  
235
        # Récupération des données des plugins
236
        plugins_data = {}
237
        plugins = dict(config['columns_plugins'])
238
        for plugin in plugins:
239
            plugin_data = plugins[plugin].get_bulk_data(
240
                [event[0].idcorrevent for event in aggregates.events]
241
            )
242
            if plugin_data :
243
                plugins_data[plugin] = plugin_data
244

  
231 245
        return dict(
232 246
            hostname = None,
233 247
            servicename = None,
234 248
            events = aggregates.events,
249
            plugins_data = plugins_data,
235 250
            rows_info = {
236 251
                'id_first_row': id_first_row,
237 252
                'id_last_row': id_last_row,
......
293 308
                SupItem,
294 309
            ).join(
295 310
                (Event, Event.idsupitem == SupItem.idsupitem),
296
                (EVENTSAGGREGATE_TABLE, EVENTSAGGREGATE_TABLE.c.idevent ==
297
                    Event.idevent),
298
                (CorrEvent, CorrEvent.idcorrevent ==
299
                    EVENTSAGGREGATE_TABLE.c.idcorrevent),
311
                (CorrEvent, Event.idevent == CorrEvent.idcause),
300 312
            ).filter(CorrEvent.idcorrevent == idcorrevent
301
            ).filter(Event.idevent == CorrEvent.idcause
302 313
            ).one()
303 314

  
304 315
        if isinstance(cause_supitem, LowLevelService):
......
334 345
            hostname = hostname,
335 346
            servicename = servicename,
336 347
            events = events.events,
348
            plugins_data = {},
337 349
            rows_info = {
338 350
                'id_first_row': id_first_row,
339 351
                'id_last_row': id_last_row,
......
413 425
            idevent = idevent,
414 426
            hostname = event.hostname,
415 427
            servicename = event.servicename,
428
            plugins_data = {},
416 429
            rows_info = {
417 430
                'id_first_row': id_first_row,
418 431
                'id_last_row': id_last_row,
......
492 505
            hostname = host,
493 506
            servicename = service,
494 507
            events = aggregates.events,
508
            plugins_data = {},
495 509
            rows_info = {
496 510
                'id_first_row': id_first_row,
497 511
                'id_last_row': id_last_row,
......
675 689
        error_handler = handle_validation_errors_json)
676 690
    @expose('json')
677 691
    @require(access_restriction)
678
    def get_plugin_value(self, idcorrevent, plugin_name, *arg, **krgv):
692
    def plugin_json(self, idcorrevent, plugin_name, *arg, **krgv):
679 693
        """
680 694
        Permet de récupérer la valeur d'un plugin associée à un CorrEvent
681 695
        donné via JSON.
......
700 714
            raise HTTPNotFound(_('No such incident or insufficient '
701 715
                                'permissions'))
702 716

  
703
        return plugins[plugin_name].get_value(idcorrevent, *arg, **krgv)
717
        return plugins[plugin_name].get_json_data(idcorrevent, *arg, **krgv)
704 718

  
705 719
    @validate(validators={
706 720
        "fontsize": validators.Regex(
......
754 768
        # TODO: Utiliser un schéma de validation
755 769
        parent_id = int(parent_id)
756 770

  
757
        # On vérifie si le groupe parent fait partie des
758
        # groupes auxquel l'utilisateur a accès, et on
759
        # retourne une liste vide dans le cas contraire
771
        # On récupère la liste des groupes de supitems dont
772
        # l'identifiant du parent est passé en paramètre.
773
        supitem_groups = DBSession.query(
774
                SupItemGroup.idgroup,
775
                SupItemGroup.name,
776
            ).join(
777
                (GroupHierarchy,
778
                    GroupHierarchy.idchild == SupItemGroup.idgroup),
779
            ).filter(GroupHierarchy.idparent == parent_id
780
            ).filter(GroupHierarchy.idchild != parent_id)
781

  
782
        # Si l'utilisateur n'appartient pas au groupe 'managers',
783
        # on filtre les résultats en fonction de ses permissions.
760 784
        is_manager = in_group('managers').is_met(request.environ)
761 785
        if not is_manager:
762 786
            user = get_current_user()
763 787
            GroupHierarchy_aliased = aliased(GroupHierarchy,
764 788
                name='GroupHierarchy_aliased')
765
            supitem_groups = DBSession.query(
766
                    SupItemGroup.idgroup,
767
                    SupItemGroup.name,
768
                ).join(
769
                    (GroupHierarchy,
770
                        GroupHierarchy.idchild == SupItemGroup.idgroup),
771
                    (DataPermission,
772
                        DataPermission.idgroup == GroupHierarchy.idparent),
773
                    (USER_GROUP_TABLE, USER_GROUP_TABLE.c.idgroup == \
774
                        DataPermission.idusergroup),
775
                ).join(
776
                    (GroupHierarchy_aliased,
777
                        GroupHierarchy_aliased.idchild == SupItemGroup.idgroup),
778
                ).filter(USER_GROUP_TABLE.c.username == user.user_name
779
                ).filter(GroupHierarchy_aliased.idparent == parent_id
780
                ).filter(GroupHierarchy_aliased.idchild != parent_id
781
                ).distinct().all()
789
            supitem_groups.join(
790
                (GroupHierarchy_aliased,
791
                    GroupHierarchy_aliased.idchild == SupItemGroup.idgroup),
792
                (DataPermission,
793
                    DataPermission.idgroup == GroupHierarchy_aliased.idparent),
794
                (USER_GROUP_TABLE, USER_GROUP_TABLE.c.idgroup == \
795
                    DataPermission.idusergroup),
796
            ).filter(USER_GROUP_TABLE.c.username == user.user_name)
782 797

  
783 798
        groups = []
784
        for group in supitem_groups:
799
        for group in supitem_groups.distinct().all():
785 800
            groups.append({
786 801
                'id'   : group.idgroup,
787 802
                'name' : group.name,

Also available in: Unified diff