Project

General

Profile

Revision 2c334d8b

ID2c334d8b927458857da32024d1e4c7e316dfba6c
Parent 2d587502
Child 81db2abe

Added by Francis LAHEUGUERE over 14 years ago

Mise a jour documentation sur methodes
Ajout signature methodes
Deport traitements dans lib/graphs.py
Deport gestion erreurs nagios et rrd dans controller error

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

View differences:

vigigraph/controllers/rpc.py
1 1
# -*- coding: utf-8 -*-
2 2
"""RPC controller for the combobox of vigigraph"""
3 3

  
4
from tg import expose, response, request, redirect, config
4
from tg import expose, response, request, redirect, config, url
5 5
from tg import exceptions
6 6

  
7 7
from vigigraph.lib.base import BaseController
......
11 11
from vigilo.models import Service, ServiceGroup, LowLevelService
12 12
from vigilo.models import PerfDataSource
13 13
from vigilo.models import Graph
14
from vigilo.models import Ventilation, VigiloServer, Application
14 15

  
15 16
from vigilo.models.secondary_tables import SERVICE_GROUP_TABLE
16 17
from vigilo.models.secondary_tables import HOST_GROUP_TABLE
......
31 32
import logging
32 33
import string
33 34

  
34
from time import gmtime, strftime
35
from datetime import datetime
36

  
37 35
from searchhostform import SearchHostForm
36
from vigigraph.lib import graphs
37

  
38 38

  
39 39
LOGGER = logging.getLogger(__name__)
40 40

  
......
43 43

  
44 44
class RpcController(BaseController):
45 45
    """
46
    Class Gérant la lecture des différents champs des combobox de vigigraph.
46
    Class Controleur TurboGears
47 47
    """
48 48
    def _get_host(self, hostname):
49
        """ Return Host object from hostname, None if not available"""
49
        """
50
        Return Host object from hostname, None if not available
51
        """
50 52
        return DBSession.query(Host) \
51 53
                .filter(Host.name == hostname) \
52 54
                .first()
53 55

  
54 56
    @expose('json')
55 57
    def maingroups(self, nocache=None):
56
        """Render the JSON document for the combobox Main Group"""
58
        """
59
        Render the JSON document for the combobox Main Group
60

  
61
        @return : groupes principaux
62
        @rtype: dict (sous forme json)
63
        """
57 64
        topgroups = DBSession.query(HostGroup.name, HostGroup.idgroup) \
58 65
                .filter(HostGroup.parent == None) \
59 66
                .order_by(HostGroup.name) \
......
65 72

  
66 73
    @expose('json')
67 74
    def hostgroups(self, maingroupid, nocache=None):
68
        """Render the JSON document for the combobox Other Group"""
75
        """
76
        Render the JSON document for the combobox Other Group
77

  
78
        @param maingroupid : identificateur d un groupe principal
79
        @type maingroupid : int
80

  
81
        @return : groupes
82
        @rtype: dict (sous forme json)
83
        """
69 84
        hostgroups = DBSession.query(HostGroup.name, HostGroup.idgroup)\
70 85
                     .filter(HostGroup.idparent == maingroupid) \
71 86
                     .all()
......
76 91

  
77 92
    @expose('json')
78 93
    def hosts(self, othergroupid, nocache=None):
79
        """Render the JSON document for the combobox Host Name"""
94
        """
95
        Render the JSON document for the combobox Host Name
96

  
97
        @param othergroupid : identificateur d un groupe
98
        @type othergroupid : int
99

  
100
        @return : hotes
101
        @rtype: dict (sous forme json)
102
        """
80 103
        hostgroup = DBSession.query(HostGroup) \
81 104
                .filter(HostGroup.idgroup == othergroupid) \
82 105
                .first()
......
89 112

  
90 113
    @expose('json')
91 114
    def servicegroups(self, idhost, nocache=None):
92
        """Render the JSON document for the combobox Graph Group"""
115
        """
116
        Render the JSON document for the combobox Graph Group
117

  
118
        @param idhost : identificateur d un hote
119
        @type idhost : int
120

  
121
        @return : groupes de service
122
        @rtype: dict (sous forme json)
123
        """
93 124
        # passage par une table intermédiaire à cause de l'héritage
94 125
        servicegroups = DBSession.query \
95 126
            (ServiceGroup.name, LowLevelService.idservice) \
......
107 138

  
108 139
    @expose('json')
109 140
    def graphs(self, idservice, nocache=None):
110
        """Render the JSON document for the combobox Graph Name"""
141
        """
142
        Render the JSON document for the combobox Graph Name
143

  
144
        @param idservice : identificateur d un service
145
        @type idservice : int
146

  
147
        @return : graphes
148
        @rtype: dict (sous forme json)
149
        """
111 150
        graphs_l = DBSession.query(Graph.name, Graph.idgraph) \
112 151
            .join((GRAPH_PERFDATASOURCE_TABLE, \
113 152
            GRAPH_PERFDATASOURCE_TABLE.c.idgraph == Graph.idgraph)) \
......
124 163

  
125 164
    @expose('json')
126 165
    def searchHostAndService(self, **kwargs):
127
        """Render the JSON document for the Host and Service"""
166
        """
167
        Render the JSON document for the Host and Service
128 168

  
169
        @param **kwargs : arguments nommes
170
        @type **kwargs : dict
171

  
172
        @return : couples hote-service
173
        @rtype: dict (sous forme json)
174
        """
129 175
        host = kwargs.get('host')
130 176
        service = kwargs.get('service')
131 177

  
......
162 208

  
163 209
    @expose('json')
164 210
    def selectHostAndService(self, **kwargs):
165
        """Render the JSON document for the Host and Service"""
166
        
211
        """
212
        Render the JSON document for the Host and Service
213

  
214
        @param **kwargs : arguments nommes
215
        @type **kwargs : dict
216

  
217
        @return : groupes
218
        @rtype: dict (sous forme json)
219
        """
167 220
        host = kwargs.get('host')
168 221
        #service = kwargs.get('service')
169 222
        service = None
......
216 269
    @expose(content_type='text/plain')
217 270
    def getImage(self, host, start=None, duration=86400, graph=None, \
218 271
    details=1, nocache=0):
219
        '''Image - as Text'''
272
        """
273
        Determination de l url d un graphe
274
        (via proxy)
275

  
276
        @param host : hôte
277
        @type host : C{str}
278
        @param start : date-heure de debut des donnees
279
        @type start : C{str}
280
        @param duration : plage de temps des données
281
        @type duration : C{str}
282
                         (parametre optionnel, initialise à 86400 = plage de 1 jour)
283
        @param details :
284
        @type details :
285
        @param nocache :
286
        @type nocache :
287

  
288
        @return : url du graphe
289
        @rtype: C{str}
290
        """
291

  
220 292
        result = None
221 293

  
222 294
        if start is None:
......
226 298
        direct = 1
227 299
        fakeIncr = random.randint(0, 9999999999)
228 300

  
229
        # url
230
        url_l = config.get('rrd_url')
231
        if url_l is not None:
301
        rrdserver = self.getRRDServer(host)
302
        if rrdserver is not None:
303
            # url
304
            url_web_path = config.get('rrd_web_path')
305
            url_l = '%s%s' % (rrdserver, url_web_path)
306

  
232 307
            # proxy
233 308
            rrdproxy = RRDProxy(url_l)
234 309
            try:
......
246 321
    @expose(content_type='image/png')
247 322
    def getImage_png(self, host, start=None, duration=86400, graph=None, \
248 323
    details=1):
249
        '''Image - as png'''
324
        """
325
        Affichage de l image d un graphe
326
        (via proxy)
327

  
328
        @param host : hôte
329
        @type host : C{str}
330
        @param start : date-heure de debut des donnees
331
        @type start : C{str}
332
        @param duration : plage de temps des données
333
        @type duration : C{str}
334
                      (parametre optionnel, initialise à 86400 = plage de 1 jour)
335
        @param graph :
336
        @type graph : C{str}
337
        @param details :
338
        @type details :
339

  
340
        @return : page avec l image du graphe
341
        @rtype: page
342
        """
250 343
        result = None
251 344

  
252 345
        if start is None:
......
256 349
        direct = 1
257 350
        fakeIncr = random.randint(0, 9999999999)
258 351

  
259
        # url
260
        url_l = config.get('rrd_url')
261
        if url_l is not None:
352
        rrdserver = self.getRRDServer(host)
353
        
354
        if rrdserver is not None:
355
            # url
356
            url_web_path = config.get('rrd_web_path')
357
            url_l = '%s%s' % (rrdserver, url_web_path)
358

  
262 359
            # proxy
263 360
            rrdproxy = RRDProxy(url_l)
264 361
            try:
......
270 367
                LOGGER.error(txt)
271 368
                exceptions.HTTPNotFound(comment=txt)
272 369

  
273
        print ''
274
        print result
275
        print ''
276

  
277 370
        return result
278 371

  
279 372
    @expose('')
373
    def imagePage(self, server, graphtemplate):
374
        """
375
        Affichage de l image d un graphe
376

  
377
        @param server : hôte
378
        @type server : C{str}
379
        @param graphtemplate : graphe
380
        @type graphtemplate : C{str}
381

  
382
        @return : page avec l image du graphe (redirection sur getImage_png)
383
        @rtype: page
384
        """
385
        redirect('getImage_png?host=%s&graph=%s' % (server, graphtemplate))
386

  
387
    @expose('')
280 388
    def getStartTime(self, host, nocache=None):
281
        '''StartTime RRD'''
389
        """
390
        Determination de la date-heure de debut des donnees RRD d un hote
391
        (via proxy)
392

  
393
        @param host : hôte
394
        @type host : C{str}
395

  
396
        @return : date-heure de debut des donnees RRD
397
        @rtype: 
398
        """
399

  
282 400
        result = None
283 401

  
284 402
        getstarttime = 1
285 403
        fakeincr = random.randint(0, 9999999999)
286 404

  
287
        # url
288
        url_l = config.get('rrd_url')
289
        if url_l is not None:
405
        rrdserver = self.getRRDServer(host)
406
        if rrdserver is not None:
407
            # url
408
            url_web_path = config.get('rrd_web_path')
409
            url_l = '%s%s' % (rrdserver, url_web_path)
410
    
290 411
            # proxy
291 412
            rrdproxy = RRDProxy(url_l)
292 413
            try:
293
                #result=rrdproxy.get_getstarttime(host, getstarttime, fakeincr)
294 414
                result = rrdproxy.get_starttime(host, getstarttime)
295 415
            except urllib2.URLError, e:
296 416
                txt = _("Can't get RRD data on host \"%s\"") \
......
302 422

  
303 423
    @expose('')
304 424
    def supPage(self, host):
305
        '''supPage'''
425
        """
426
        Affichage page supervision Nagios pour un hote
427
        (via proxy)
428

  
429
        @param host : hôte
430
        @type host : C{str}
431

  
432
        @return : page de supervision Nagios
433
        @rtype : page
434
        """
306 435
        result = None
307 436

  
308
        # url
309
        url_l = config.get('nagios_url')
310
        if url_l is not None:
437
        nagiosserver = self.getNagiosServer(host)
438
        if nagiosserver is not None:
439
            # url
440
            url_web_path = config.get('nagios_web_path')
441
            url_l = '%s%s' % (nagiosserver, url_web_path)
442

  
311 443
            # proxy
312 444
            nagiosproxy = NagiosProxy(url_l)
313 445
            try:
......
316 448
                txt = _("Can't get Nagios data on host \"%s\"") \
317 449
                    % (host)
318 450
                LOGGER.error(txt)
319
                redirect('nagios_host_error?host=%s' % host)
451
                error_url = '../error/nagios_host_error?host=%s'
452
                redirect(error_url % host)
320 453

  
321 454
        return result
322 455

  
323 456
    @expose('')
324 457
    def servicePage(self, host, service=None):
325
        '''servicePage'''
458
        """
459
        Affichage page supervision Nagios pour un hote
460
        (via proxy)
461

  
462
        @param host : hôte
463
        @type host : C{str}
464
        @param service : service
465
        @type service : C{str}
466

  
467
        @return : page de supervision Nagios
468
        @rtype : page
469
        """
326 470
        result = None
327 471

  
328
        # url
329
        url_l = config.get('nagios_url')
330
        if url_l is not None:
472
        nagiosserver = self.getNagiosServer(host)
473
        if nagiosserver is not None:
474
            # url
475
            url_web_path = config.get('nagios_web_path')
476
            url_l = '%s%s' % (nagiosserver, url_web_path)
477

  
331 478
            # proxy
332 479
            nagiosproxy = NagiosProxy(url_l)
333 480
            try:
......
336 483
                txt = _("Can't get Nagios data on host \"%s\" service \"%s\"")\
337 484
                    % (host, service)
338 485
                LOGGER.error(txt)
339
                redirect('nagios_host_service_error?host=%s&service=%s' \
340
                % (host, service))
486

  
487
                error_url = '../error'
488
                error_url += '/nagios_host_service_error?host=%s&service=%s'
489
                redirect(error_url % (host, service))
341 490

  
342 491
        return result
343 492

  
344 493
    @expose('')
345 494
    def metroPage(self, host):
346
        '''metroPage'''
495
        """
496
        Affichage page metrologie pour un hote
497
        (via proxy)
498

  
499
        @param host : hôte
500
        @type host : C{str}
501

  
502
        @return : page de metrologie
503
        @rtype : page
504
        """
347 505
        result = None
348 506

  
349
        # url
350
        url_l = config.get('rrd_url')
351
        if url_l is not None:
507
        rrdserver = self.getRRDServer(host)
508
        if rrdserver is not None:
509
            # url
510
            url_web_path = config.get('rrd_web_path')
511
            url_l = '%s%s' % (rrdserver, url_web_path)
512

  
352 513
            # proxy
353 514
            rrdproxy = RRDProxy(url_l)
354 515
            try:
......
357 518
                txt = _("Can't get RRD data on host \"%s\"") \
358 519
                    % (host)
359 520
                LOGGER.error(txt)
360
                redirect('rrd_error?host=%s' % host)
521
                error_url = '../error/rrd_error?host=%s'
522
                redirect(error_url % host)
361 523

  
362 524
        return result
363 525

  
364
    @expose('')
365
    def imagePage(self, server, graphtemplate):
366
        '''metroPage'''
367
        redirect('getImage_png?host=%s&graph=%s' % (server, graphtemplate))
368

  
369 526
    @expose('graphslist.html', content_type='text/html')
370 527
    def graphsList(self, nocache=None, **kwargs):
371
        '''graphsList'''
372
        graphslist = []
373
        format = "%d-%m-%Y %H:%M"
374
        for key in kwargs:
375
            # titre
376
            title = "Inconnu"
377
            graph = ""
378
            server = ""
379
            lca = kwargs[key].split("?")
380
            if len(lca) == 2:
381
                largs = lca[1].split("&")
382
                for arg in largs:
383
                    larg = arg.split("=")
384
                    if len(larg) == 2:
385
                        if larg[0] == "server":
386
                            server = larg[1]
387
                        elif larg[0] == "graphtemplate":
388
                            graph = larg[1]
389
                        elif larg[0] == "start":
390
                            start = larg[1]
391
                        elif larg[0] == "duration":
392
                            duration = larg[1]
393
            if graph != "" or server != "":
394
                title = "'%s' Graph for host %s" % \
395
                  (urllib.unquote_plus(graph), server)
396
            graph = {}
397
            graph['title'] = title
398
            v = int(start)
399
            graph['sts'] = _(strftime(format, gmtime(v)))
400
            v = int(start) + int(duration)
401
            graph['ets'] = _(strftime(format, gmtime(v)))
402
            graph['src'] = urllib2.unquote(kwargs[key])
403
            graphslist.append(graph)
528
        """
529
        Liste de graphes
530
        
531
        @param **kwargs : arguments nommes
532
        @type **kwargs  : dict
533

  
534
        @return : dictionnaire applique sur un template -> graphslist.html
535
        @rtype: dict
536
        """
537
        graphslist = graphs.graphsList(**kwargs)
404 538
        return dict(graphslist=graphslist)
405 539

  
406 540
    @expose(content_type='text/plain')
407 541
    def tempoDelayRefresh(self, nocache=None):
408
        '''tempo pour rafraichissement'''
409

  
410
        delay = config.get('delay_refresh')
411
        delay = string.strip(delay)
412

  
413
        b_evaluate = False
414
        if delay == '':
415
            b_evaluate = True
416
        else:
417
            if delay.isalnum():
418
                delay_l = int(delay)
419
                b_evaluate = (delay_l <= 0)
420
            else:
421
                b_evaluate = True
542
        """
543
        Lecture de la temporisation pour le rafraichissement automatique
422 544

  
423
        if b_evaluate:
424
            delay = '30000'
545
        @return : valeur de temporisation
546
        @return : C{str}
547
        """
425 548

  
549
        delay = graphs.tempoDelayRefresh()
426 550
        return delay
427 551

  
428 552
    @expose('json')
429 553
    def getIndicators(self, nocache=None, graph=None):
430
        '''Indicators for graph'''
554
        """
555
        Liste d indicateurs associes a un graphe
556

  
557
        @param graph : graphe
558
        @type graph  : C{str}
559
                       (parametre optionnel, initialise à None)
560

  
561
        @return : dictionnaire applique sur un template json
562
        @return : dict
563
        """
564

  
431 565
        indicators = self.getListIndicators(graph)
432 566
        if indicators is not None and indicators != []:
433 567
            return dict(items=[(ind[0], str(ind[1])) for ind in indicators])
......
435 569
            return dict(items=[])
436 570

  
437 571
    def getListIndicators(self, graph=None):
438
        '''List of Indicators'''
572
        """
573
        Liste d indicateurs associes a un graphe
574

  
575
        @param graph : graphe
576
        @type graph  : C{str}
577
                       (parametre optionnel, initialise à None)
578

  
579
        @return : liste d indicateurs
580
        @rtype  : list
581
        """
582

  
439 583
        indicators = []
440 584
        if graph is not None:
441 585
            indicators = DBSession.query \
......
453 597
    @expose('', content_type='text/csv')
454 598
    def exportCSV(self, nocache=None, host=None, graph=None, indicator=None, \
455 599
    start=None, end=None):
456
        '''export CSV'''
600
        """
601
        Export CSV sous forme de fichier
602
        - pour un hote
603
        - pour un graphe
604
        - pour un indicateur parmi ceux associes au graphe
605
          ou l ensemble des indicateurs
606

  
607
        @param host : hôte
608
        @type host : C{str}
609
        @param graph : graphe
610
        @type graph : C{str}
611
        @param indicator : indicateur graphe
612
        @type indicator : C{str}
613
        @param start : date-heure de debut des donnees
614
        @type start : C{str}
615

  
616
        @return : donnees RRD dans fichier
617
        @rtype  : fichier CSV
618
        """
457 619

  
458 620
        result = None
459 621
        b_export = False
......
494 656
                        break
495 657

  
496 658
            if b_export:
497
                # plage temps sous forme texte
498
                format = '%Y%m%d-%H%M%S'
499

  
500
                dt = datetime.utcfromtimestamp(int(start))
501
                str_start = dt.strftime(format)
502

  
503
                dt = datetime.utcfromtimestamp(int(end))
504
                str_end = dt.strftime(format)
505

  
506 659
                # nom fichier
507
                filename = host
508
                filename += "_"
509
                filename += indicator_f
510
                filename += "_"
511
                filename += str_start
512
                filename += "_"
513
                filename += str_end
514

  
515
                # nom fichier final
516
                lc = [' ', '|', '/', '\\', ':', '?', '*', '<', '>', '"']
517
                for c in lc:
518
                    filename = filename.replace(c, "_")
519
                filename += ".csv"
660
                filename = graphs.getExportFileName(host, indicator_f, \
661
                start, end)
520 662

  
521 663
                idx = 0
522 664
                dict_indicators[idx] = 'TimeStamp'
......
525 667
                    idx += 1
526 668
                    dict_indicators[idx] = indicators_l[i]
527 669

  
528
                # url selon configuration
529
                url_l = config.get('rrd_url')
530
                if url_l is not None:
670
                rrdserver = self.getRRDServer(host)
671
                if rrdserver is not None:
672
                    # url selon configuration
673
                    url_web_path = config.get('rrd_web_path')
674
                    url_l = '%s%s' % (rrdserver, url_web_path)
675

  
531 676
                    # donnees via proxy
532 677
                    rrdproxy = RRDProxy(url_l)
533 678
                    try:
......
541 686
                        % (host, graph, indicator)
542 687
                        LOGGER.error(txt)
543 688

  
544
                        redirect('rrd_exportCSV_error?\
545
                        host=%s&graph=%s&indicator=%s'\
546
                        % (host, graph, indicator))
689
                        error_url = '../error'
690
                        error_url += '/rrd_exportCSV_error'
691
                        error_url += '?host=%s&graph=%s&indicator=%s'
692
                        redirect(error_url % (host, graph, indicator))
547 693
                    finally:
548 694
                        if b_export:
549 695
                            # conversion sous forme de dictionnaire
......
570 716
                                # entête
571 717
                                headers = dict( (n, n) for n in fieldnames )
572 718
                                writer.writerow(headers)
573
                                '''
574
                                dict_data = {}
575
                                for key_i in dict_indicators:
576
                                    iv = dict_indicators[key_i]
577
                                    dict_data[iv] = iv
578
                                writer.writerow(dict_data)
579
                                '''
580

  
581
                                # valeurs
582
                                format = '%Y/%m/%d %H:%M:%S'
583
                                if dict_values is not None or \
584
                                dict_values != "{}":
585
                                    for key_tv in dict_values:
586
                                        tv = dict_values[key_tv]
587
                                        dict_data = {}
588
                                        for key_i in dict_indicators:
589
                                            iv = dict_indicators[key_i]
590
                                            v = str(tv[key_i])
591

  
592
                                            # temps sous forme texte
593
                                            if iv == 'TimeStamp':
594
                                                dt = datetime.utcfromtimestamp(int(v))
595
                                                v = dt.strftime(format)
596

  
597
                                            # remplacement . par ,
598
                                            v = v.replace(".", sep_value)
599

  
600
                                            dict_data[iv] = v
601
                                        writer.writerow(dict_data)
719

  
720
                                # generation fichier
721
                                graphs.setExportFile(writer, dict_values, \
722
                                dict_indicators, sep_value)
723
                                
602 724
                            finally:
603 725
                                f.close()
604 726

  
......
611 733
    @expose('fullhostpage.html')
612 734
    def fullHostPage(self, host, start=None, duration=86400):
613 735
        """
614
        fullHostPage
736
        Affichage de l'ensemble des graphes associes a un hote
737
        - d apres les donnees RRD
738
        - avec une date-heure de debut
739
        - pour une plage de temps 
740
        
741
        @param host : hôte
742
        @type host : C{str}
743
        @param start : date-heure de debut des donnees
744
        @type start : C{str}
745
                      (parametre optionnel, initialise à None)
746
        @param duration : plage de temps des données
747
        @type duration : C{str}
748
                         (parametre optionnel, initialise à 86400 = plage de 1 jour)
749

  
750
        @return : dictionnaire applique sur un template -> fullhostpage.html
751
        @rtype: dict
615 752
        """
616 753

  
617
        presels = [
754
        presets = [
618 755
            {"caption" : "Last 12h", "duration" : 43200},
619 756
            {"caption" : "Last 24h", "duration" : 86400},
620 757
            {"caption" : "Last 2d",  "duration" : 192800},
......
651 788
            i += 1
652 789

  
653 790
        return dict(host=host, start=start, duration=duration, \
654
        presels=presels, dhgs=dhgs)
791
        presets=presets, dhgs=dhgs)
655 792

  
656 793
    @expose ('singlegraph.html')
657 794
    def singleGraph(self, host, graph, start=None, duration=86400):
658 795
        """
659
        singleGraph
796
        Affichage d un graphe associe a un hote et un graphe
797
        - d apres les donnees RRD
798
        - avec une date-heure de debut
799
        - pour une plage de temps 
800
        
801
        @param host : hôte
802
        @type host : C{str}
803
        @param graph : graphe
804
        @type graph  : C{str}
805
        @param start : date-heure de debut des donnees
806
        @type start : C{str}
807
                      (parametre optionnel, initialise à None)
808
        @param duration : plage de temps des données 
809
        @type duration : C{str}
810
                         (parametre optionnel, initialise à 86400 = plage de 1 jour)
811

  
812
        @return : dictionnaire applique sur un template -> singlegraph.html
813
        @rtype: dict
660 814
        """
661 815

  
662
        presels = [
816
        presets = [
663 817
        {"caption" : "Last 12h", "duration" : 43200},
664 818
        {"caption" : "Last 24h", "duration" : 86400},
665 819
        {"caption" : "Last 2d",  "duration" : 192800},
......
674 828
            start = int(time.time()) - int(duration)
675 829

  
676 830
        return dict(host=host, graph=graph, start=start, duration=duration, \
677
        presels=presels)
831
        presets=presets)
678 832

  
679 833
    @expose('searchhostform.html')
680 834
    def searchHostForm(self):
681
        '''searchhostform'''
835
        """
836
        Formulaire de recherche sur les hotes
837

  
838
        @return : page
839
        @rtype: page (-> dict sur template searchhostform.html)
840
        """
682 841
        searchhostform = SearchHostForm('search_host_form', \
683 842
            submit_text=None)
684 843

  
......
686 845

  
687 846
    @expose ('searchhost.html')
688 847
    def searchHost(self, query=None):
689
        '''
690
        searchHost
691
        '''
848
        """
849
        Recherche d hotes
850

  
851
        @param query : prefixe de recherche sur les hotes
852
        @type query : C{str}
853

  
854
        @return : page
855
        @rtype: page (-> dict sur template searchhost.html)
856
        """
692 857

  
693 858
        hosts = []
694 859

  
......
721 886
    # VIGILO_EXIG_VIGILO_PERF_0030:Moteur de recherche des graphes
722 887
    @expose ('getopensearch.xml', content_type='text/xml')
723 888
    def getOpenSearch(self):
724
        '''
889
        """
725 890
        getOpenSearch
726
        '''
891

  
892
        @return : page
893
        @rtype: page xml (-> dict sur template getopensearch.xml)
894
        """
727 895

  
728 896
        here = "http://"
729 897
        here += request.host
730

  
731
        #dir_l = url('/vigigraph/public')
732
        dir_l = '/vigigraph/public'
898
        dir_l = url('/public')
733 899

  
734 900
        result = dict(here=here, dir=dir_l)
735 901

  
736 902
        return result
737 903

  
738
    @expose('')
739
    def rrd_txt_error(self, **kwargs):
740
        '''rrd_error'''
741
        txt = None
742
        if kwargs is not None:
743
            txt = kwargs.get('txt')
744
        return txt
745

  
746
    @expose('rrd_error.html')
747
    def rrd_error(self, **kwargs):
748
        '''rrd_error'''
749
        host = None
750
        if kwargs is not None:
751
            host = kwargs.get('host')
752
            return dict(host=host)
753
        else:
754
            return None
755

  
756
    @expose('rrd_error.html')
757
    def rrd_exportCSV_error(self, **kwargs):
758
        '''rrd_exportCSV_error'''
759
        host = None
760
        if kwargs is not None:
761
            host = kwargs.get('host')
762
            return dict(host=host)
763
        else:
764
            return None
765

  
766
    @expose('nagios_host_error.html')
767
    def nagios_host_error(self, **kwargs):
768
        '''nagios_host_error'''
769
        host = None
770
        if kwargs is not None:
771
            host = kwargs.get('host')
772
            return dict(host=host)
773
        else:
774
            return None
904
    def getRRDServer(self, host=None):
905
        """
906
        Determination Server RRD pour l hote courant
907
        (Server RRD -> nom de l application associee = rrdgraph)
775 908

  
776
    @expose('nagios_host_service_error.html')
777
    def nagios_host_service_error(self, **kwargs):
778
        '''nagios_host_service_error'''
779
        host = None
780
        service = None
781
        if kwargs is not None:
782
            host = kwargs.get('host')
783
            service = kwargs.get('service')
784
            return dict(host=host, service=service)
785
        else:
786
            return None
909
        @param host : hôte
910
        @type host : C{str}
911

  
912
        @return : server
913
        @rtype: C{str}
914
        """
915

  
916
        server = None
917
        if host is not None:
918
            result = DBSession.query \
919
            (VigiloServer.name) \
920
            .filter(VigiloServer.idvigiloserver == Ventilation.idvigiloserver) \
921
            .filter(Ventilation.idhost == Host.idhost) \
922
            .filter(Ventilation.idapp == Application.idapp) \
923
            .filter(Host.name == host) \
924
            .filter(Application.name == 'rrdgraph') \
925
            .first()
926

  
927
            if result is not None:
928
                server = result[0]
929

  
930
        return server
931

  
932
    def getNagiosServer(self, host=None):
933
        """
934
        Determination Server Nagios pour l hote courant
935
        (Server Nagios -> nom de l application associee = nagios)
936

  
937
        @param host : hôte
938
        @type host : C{str}
939

  
940
        @return : server
941
        @rtype: C{str}
942
        """
943

  
944
        server = None
945
        if host is not None:
946
            # intitulé 
947
            result = DBSession.query \
948
            (VigiloServer.name) \
949
            .filter(VigiloServer.idvigiloserver == Ventilation.idvigiloserver) \
950
            .filter(Ventilation.idhost == Host.idhost) \
951
            .filter(Host.name == host) \
952
            .filter(VigiloServer.description.like('%Nagios%')) \
953
            .first()
954

  
955
            if result is not None:
956
                server = result[0]
957

  
958
        return server

Also available in: Unified diff