Project

General

Profile

Revision e941ddaf

IDe941ddafb5461fa9e480326c01115b0b1dcf4b69
Parent 5168414c
Child 3ba1cdd2

Added by Francois POIROTTE about 13 years ago

Recherche sur les HLS impactés dans VigiBoard (#726)

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

View differences:

vigiboard/controllers/plugins/hls.py
23 23
niveau (L{HighLevelService}) impactés par un événement.
24 24
"""
25 25

  
26
from vigiboard.controllers.plugins import VigiboardRequestPlugin
26
import tw.forms as twf
27
from pylons.i18n import lazy_ugettext as l_
28

  
29
from vigiboard.controllers.plugins import VigiboardRequestPlugin, INNER
27 30
from vigilo.models.session import DBSession
28
from vigilo.models.tables import HighLevelService, CorrEvent, Event, SupItem, \
29
    ImpactedHLS, ImpactedPath
31
from vigilo.models.functions import sql_escape_like
32
from vigilo.models import tables
30 33
from sqlalchemy.orm import aliased
31 34
from sqlalchemy.sql import functions
32 35

  
......
35 38
    Plugin qui permet de voir les services de haut niveau impactés par
36 39
    les événements affichés sur la page principale de VigiBoard.
37 40
    """
41
    def get_search_fields(self):
42
        return [
43
            twf.TextField(
44
                'hls',
45
                label_text=l_('High-Level Service'),
46
                validator=twf.validators.String(if_missing=None),
47
            )
48
        ]
49

  
50
    def handle_search_fields(self, query, search, state, subqueries):
51
        if state != INNER or not search.get('hls'):
52
            return
53
        hls = sql_escape_like(search['hls'])
54

  
55
        # Il s'agit d'un manager. On applique le filtre
56
        # indépendamment aux 2 sous-requêtes.
57
        if len(subqueries) == 2:
58
            subqueries[0] = subqueries[0].join(
59
                    (tables.ImpactedPath, tables.ImpactedPath.idsupitem == \
60
                        tables.LowLevelService.idservice),
61
                    (tables.ImpactedHLS, tables.ImpactedHLS.idpath == \
62
                        tables.ImpactedPath.idpath),
63
                    (tables.HighLevelService, \
64
                        tables.HighLevelService.idservice == \
65
                        tables.ImpactedHLS.idhls),
66
                ).filter(tables.HighLevelService.servicename.ilike(hls))
67

  
68
            subqueries[1] = subqueries[1].join(
69
                    (tables.ImpactedPath, tables.ImpactedPath.idsupitem == \
70
                        tables.Host.idhost),
71
                    (tables.ImpactedHLS, tables.ImpactedHLS.idpath == \
72
                        tables.ImpactedPath.idpath),
73
                    (tables.HighLevelService,
74
                        tables.HighLevelService.idservice == \
75
                        tables.ImpactedHLS.idhls),
76
                ).filter(tables.HighLevelService.servicename.ilike(hls))
77

  
78
        # Il s'agit d'un utilisateur normal.
79
        else:
80
            subqueries[0] = subqueries[0].join(
81
                    (tables.ImpactedPath, tables.ImpactedPath.idsupitem == \
82
                        tables.UserSupItem.idsupitem),
83
                    (tables.ImpactedHLS, tables.ImpactedHLS.idpath == \
84
                        tables.ImpactedPath.idpath),
85
                    (tables.HighLevelService,
86
                        tables.HighLevelService.idservice == \
87
                        tables.ImpactedHLS.idhls),
88
                ).filter(tables.HighLevelService.servicename.ilike(hls))
38 89

  
39 90
    def get_bulk_data(self, events_ids):
40 91
        """
......
49 100
        @rtype:  C{dict}
50 101
        """
51 102

  
52
        imp_hls1 = aliased(ImpactedHLS)
53
        imp_hls2 = aliased(ImpactedHLS)
103
        imp_hls1 = aliased(tables.ImpactedHLS)
104
        imp_hls2 = aliased(tables.ImpactedHLS)
54 105

  
55 106
        # Sous-requête récupérant les identifiants des supitems
56 107
        # impactés par les évènements passés en paramètre.
57 108
        subquery = DBSession.query(
58
                SupItem.idsupitem,
59
                CorrEvent.idcorrevent
109
                tables.SupItem.idsupitem,
110
                tables.CorrEvent.idcorrevent
60 111
            ).join(
61
                (Event, Event.idsupitem == SupItem.idsupitem),
62
                (CorrEvent, CorrEvent.idcause == Event.idevent),
63
            ).filter(CorrEvent.idcorrevent.in_(events_ids)
112
                (tables.Event, tables.Event.idsupitem == \
113
                    tables.SupItem.idsupitem),
114
                (tables.CorrEvent, tables.CorrEvent.idcause == \
115
                    tables.Event.idevent),
116
            ).filter(tables.CorrEvent.idcorrevent.in_(events_ids)
64 117
            ).subquery()
65 118

  
66 119
        # Sous-requête récupérant les identifiants des SHN de plus
......
71 124
            imp_hls1.idpath,
72 125
            subquery.c.idcorrevent
73 126
        ).join(
74
            (ImpactedPath, ImpactedPath.idpath == imp_hls1.idpath)
127
            (tables.ImpactedPath, tables.ImpactedPath.idpath == imp_hls1.idpath)
75 128
        ).join(
76
            (subquery, ImpactedPath.idsupitem == subquery.c.idsupitem)
129
            (subquery, tables.ImpactedPath.idsupitem == subquery.c.idsupitem)
77 130
        ).group_by(imp_hls1.idpath, subquery.c.idcorrevent
78 131
        ).subquery()
79 132

  
......
81 134
        # impactés par chacun des évènements passés en paramètre.
82 135
        # Fait appel à la sous-requête précédente (subquery2).
83 136
        services = DBSession.query(
84
            HighLevelService.servicename,
137
            tables.HighLevelService.servicename,
85 138
            subquery2.c.idcorrevent
86 139
        ).distinct(
87 140
        ).join(
88
            (imp_hls2, HighLevelService.idservice == imp_hls2.idhls),
141
            (imp_hls2, tables.HighLevelService.idservice == imp_hls2.idhls),
89 142
            (subquery2, subquery2.c.idpath == imp_hls2.idpath),
90 143
        ).filter(imp_hls2.distance == subquery2.c.distance
91 144
        ).order_by(
92
            HighLevelService.servicename.asc()
145
            tables.HighLevelService.servicename.asc()
93 146
        ).all()
94 147

  
95 148
        # Construction d'un dictionnaire associant à chaque évènement

Also available in: Unified diff