Project

General

Profile

Revision 2ed2fd99

ID2ed2fd99a59430588be49ed2e1671f287eedc5ba
Parent 075487bf
Child c02aff6b

Added by Francois POIROTTE about 14 years ago

Mise à jour de vigigraph pour utiliser le proxy RRDgraph de vigilo.turbogears.controllers.proxy.
Nettoyage des contrôleurs.
Mise à jour du code qooxdoo.
Ajout de variables de configuration dans le development.ini pour gérer la communication via le proxy.
Ajout d'un patch pour qooxdoo afin d'éviter l'utilisation de la méthode getBoxObjectFor() (retirée dans Firefox 3.6.x).

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

View differences:

development.ini
29 29
use_kerberos=False
30 30
app.vigicore = /
31 31

  
32
# web_path
33
rrd_web_path = /rrdgraph
34
nagios_web_path = /nagios/cgi-bin
32
; Emplacement des applications (rrdgraph, Nagios, ...)
33
; sur les serveurs distants.
34
app_path.rrdgraph = /vigilo/rrdgraph/
35
app_path.nagios = /nagios/
36

  
37
; Schéma ("protocol") à utiliser pour se connecter
38
; à l'application. En général : http ou https.
39
; Par défaut : http
40
app_scheme.rrdgraph = http
41
app_scheme.nagios = http
42

  
43
; Port de connexion au serveur distant hébergeant
44
; l'application.
45
; Par défaut : 80
46
app_port.rrdgraph = 80
47
app_port.nagios = 80
35 48

  
36 49
# Vigigraph - refresh for graphs (en millisecondes)
37 50
delay_refresh = 30000
javascript/source/class/vigigraph/Application.js
47 47
    "selectHostAndGraph": "/rpc/selectHostAndGraph",
48 48
    "searchHostAndGraph": "/rpc/searchHostAndGraph",
49 49
    "supPage": "/nagios/",
50
    "getImage": "/rpc/getImage",
51
    "getStartTime": "/rpc/getStartTime",
50
    "getImage": "/rrdgraph/",
51
    "getStartTime": "/rrdgraph/",
52 52
    "graphsList": "/rpc/graphsList",
53 53
    "tempoDelayRefresh": "/rpc/tempoDelayRefresh",
54 54
    "getIndicators": "/rpc/getIndicators",
55
    "exportCSV": "/rpc/exportCSV"
55
    "exportCSV": "/rrdgraph/"
56 56
};
57 57

  
58 58
/**
......
684 684

  
685 685
      function setUrl(start,duration)
686 686
      {
687
        url= urls.getImage+"?host="+encodeURIComponent(host)+"&start="+start+"&duration="+duration+"&graph="+encodeURIComponent(graph);
687
        url= urls.getImage+"/"+encodeURIComponent(host)+"/rrdgraph.py?start="+start+"&duration="+duration+"&graphtemplate="+encodeURIComponent(graph)+"&direct=1";
688 688
        qx.log.Logger.ROOT_LOGGER.debug(url);
689 689
      }
690 690
      function loadImage(myUrl,o)
691 691
      {
692 692
        o.removeAll();
693
        var i=new qx.io.remote.Request(url,"GET","text/plain");
694
        i.addEventListener("completed", function(e) { 
695
          img = e.getContent();
696
          if (img)
697
          {
698
            o.add(new qx.ui.basic.Image(e.getContent()));
699
          }
700
        });
701
        i.send();
693
        o.add(new qx.ui.basic.Image(myUrl));
702 694
      }
703 695
      function getTime() // we use a function because the window can be opened a long time without reloading
704 696
      {
......
707 699
      }
708 700
      function updateGraphOnStartTime()
709 701
      {
710
        var url= urls.getStartTime+"?host="+encodeURIComponent(host);
702
        var url= urls.getStartTime+"/"+encodeURIComponent(host)+"/rrdgraph.py?getstarttime=1";
711 703
        var g=new qx.io.remote.Request(url,"GET","text/plain");
712 704
        g.addEventListener("completed", function(e) { 
713 705
          start = parseInt(e.getContent());
......
1006 998
        if (indicator != "")
1007 999
        {
1008 1000
          var end = start + duration;
1009
          var url= urls.exportCSV+"?host="+encodeURIComponent(host)+"&graph="+graph+"&indicator="+indicator+"&start="+start+"&end="+end;
1001
          var url= urls.exportCSV+"/"+encodeURIComponent(host)+"/rrdgraph.py/exportCSV?graphtemplate="+graph+"&ds="+indicator+"&start="+start+"&end="+end;
1010 1002
          w4 = window.open(url);
1011 1003
          w4.onload = function(){
1012 1004
          }
javascript/source/translation/C.po
7 7
msgstr ""
8 8
"Project-Id-Version: SupNavigator 1.x\n"
9 9
"Report-Msgid-Bugs-To: \n"
10
"POT-Creation-Date: 2010-04-16 16:43+0200\n"
10
"POT-Creation-Date: 2010-04-20 14:42+0200\n"
11 11
"PO-Revision-Date: 2007-12-06 16:03+0100\n"
12 12
"Last-Translator: Automatically generated\n"
13 13
"Language-Team: none\n"
......
16 16
"Content-Transfer-Encoding: 8bit\n"
17 17

  
18 18
#: source/class/vigigraph/Application.js:87
19
#: source/class/vigigraph/Application.js:1047
20
#: source/class/vigigraph/Application.js:1076
21
#: source/class/vigigraph/Application.js:1105
19
#: source/class/vigigraph/Application.js:1039
20
#: source/class/vigigraph/Application.js:1068
21
#: source/class/vigigraph/Application.js:1097
22 22
msgid "Vigilo Graphic"
23 23
msgstr "Vigilo Graphic"
24 24

  
......
171 171
#: source/class/vigigraph/Application.js:678
172 172
msgid "Export CSV"
173 173
msgstr "Export CSV"
174

  
javascript/source/translation/fr.po
7 7
msgstr ""
8 8
"Project-Id-Version: SupNavigator 1.x\n"
9 9
"Report-Msgid-Bugs-To: \n"
10
"POT-Creation-Date: 2010-04-16 16:43+0200\n"
10
"POT-Creation-Date: 2010-04-20 14:42+0200\n"
11 11
"PO-Revision-Date: 2007-12-06 16:03+0100\n"
12 12
"Last-Translator: Automatically generated\n"
13 13
"Language-Team: none\n"
......
17 17
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
18 18

  
19 19
#: source/class/vigigraph/Application.js:87
20
#: source/class/vigigraph/Application.js:1047
21
#: source/class/vigigraph/Application.js:1076
22
#: source/class/vigigraph/Application.js:1105
20
#: source/class/vigigraph/Application.js:1039
21
#: source/class/vigigraph/Application.js:1068
22
#: source/class/vigigraph/Application.js:1097
23 23
msgid "Vigilo Graphic"
24 24
msgstr ""
25 25

  
......
172 172
#: source/class/vigigraph/Application.js:678
173 173
msgid "Export CSV"
174 174
msgstr "Export CSV"
175

  
javascript/source/translation/messages.pot
8 8
msgstr ""
9 9
"Project-Id-Version: PACKAGE VERSION\n"
10 10
"Report-Msgid-Bugs-To: \n"
11
"POT-Creation-Date: 2010-04-16 16:43+0200\n"
11
"POT-Creation-Date: 2010-04-20 14:58+0200\n"
12 12
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13 13
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14 14
"Language-Team: LANGUAGE <LL@li.org>\n"
......
17 17
"Content-Transfer-Encoding: 8bit\n"
18 18

  
19 19
#: source/class/vigigraph/Application.js:87
20
#: source/class/vigigraph/Application.js:1047
21
#: source/class/vigigraph/Application.js:1076
22
#: source/class/vigigraph/Application.js:1105
20
#: source/class/vigigraph/Application.js:1039
21
#: source/class/vigigraph/Application.js:1068
22
#: source/class/vigigraph/Application.js:1097
23 23
msgid "Vigilo Graphic"
24 24
msgstr ""
25 25

  
patches/001_qooxdoo_getBoxObjectFor.diff
1
--- javascript/qooxdoo-0.7.3-sdk/frontend/framework/source/class/qx/html/Location.js.old	2010-04-20 14:18:32.000000000 +0200
2
+++ javascript/qooxdoo-0.7.3-sdk/frontend/framework/source/class/qx/html/Location.js	2010-04-20 14:42:14.000000000 +0200
3
@@ -419,7 +419,7 @@
4
     getPageAreaLeft : qx.core.Variant.select("qx.client",
5
     {
6
       "gecko" : function(el) {
7
-        return el.ownerDocument.getBoxObjectFor(el).x;
8
+        return el.getBoundingClientRect().left;
9
       },
10
 
11
       "default" : function(el) {
12
@@ -439,7 +439,7 @@
13
     getPageAreaTop : qx.core.Variant.select("qx.client",
14
     {
15
       "gecko" : function(el) {
16
-        return el.ownerDocument.getBoxObjectFor(el).y;
17
+        return el.getBoundingClientRect().top;
18
       },
19
 
20
       "default" : function(el) {
vigigraph/controllers/root.py
10 10
from vigigraph.lib.base import BaseController
11 11
from vigigraph.controllers.error import ErrorController
12 12
from vigigraph.controllers.rpc import RpcController
13
from vigilo.turbogears.controllers.nagiosproxy \
14
    import make_nagios_proxy_controller
13
from vigilo.turbogears.controllers.proxy import make_proxy_controller
15 14

  
16 15
__all__ = ['RootController']
17 16

  
......
21 20
class RootController(BaseController):
22 21
    """
23 22
    The root controller for the vigigraph application.
24
    
25
    All the other controllers and WSGI applications should be mounted on this
26
    controller. For example::
27
    
28
        panel = ControlPanelController()
29
        another_app = AnotherWSGIApplication()
30
    
31
    Keep in mind that WSGI applications shouldn't be mounted directly: They
32
    must be wrapped around with :class:`tg.controllers.WSGIAppController`.
33
    
34 23
    """
35 24
    error = ErrorController()
36 25
    rpc = RpcController()
37
    nagios = make_nagios_proxy_controller(BaseController, '/nagios/')
26
    nagios = make_proxy_controller(BaseController, 'nagios', '/nagios/')
27
    rrdgraph = make_proxy_controller(BaseController, 'rrdgraph', '/rrdgraph/')
38 28

  
39 29
    @expose('index.html')
40 30
    @require(Any(not_anonymous(), msg=_("You need to be authenticated")))
vigigraph/controllers/rpc.py
442 442
        graphgroups = [gg.name for gg in selected_graphgroups]
443 443
        return dict(items=[hostgroups, graphgroups])        
444 444

  
445
    @expose(content_type='text/plain')
446
    def getImage(self, host, start=None, duration=86400, graph=None, \
447
    details=1, nocache=0):
448
        """
449
        Determination de l url d un graphe
450
        (via proxy RRD)
451

  
452
        @param host : hôte
453
        @type host : C{str}
454
        @param start : date-heure de debut des donnees
455
        @type start : C{str}
456
        @param duration : plage de temps des données
457
        @type duration : C{str}
458
                         (parametre optionnel, initialise a 86400 = plage de 1 jour)
459
        @param details : indicateur affichage details dans graphe (legende)
460
        @type details : int
461
        @param graph : graphe
462
        @type graph : C{str}
463

  
464
        @return: url du graphe
465
        @rtype: C{str}
466
        """
467

  
468
        result = None
469

  
470
        if start is None:
471
            start = int(time.time()) - 24*3600
472

  
473
        # valeurs particulieres
474
        direct = 1
475
        rrdserver = self.getRRDServer(host)
476

  
477
        if rrdserver is not None:
478
            # url
479
            url_web_path = config.get('rrd_web_path')
480
            url_l = '%s%s' % (rrdserver, url_web_path)
481

  
482
            # proxy
483
            rrdproxy = RRDProxy(url_l)
484
            try:
485
                result = rrdproxy.get_img_name_with_params(host, graph, \
486
                direct, duration, start, int(details))
487
            except urllib2.URLError:
488
                txt = _("Can't get RRD graph \"%(graph)s\" on "
489
                        "host \"%(host)s\"") % {
490
                    'graph': graph,
491
                    'host': host,
492
                }
493
                LOGGER.error(txt)
494
                exceptions.HTTPNotFound(comment=txt)
495

  
496
        return result
497

  
498
    # VIGILO_EXIG_VIGILO_PERF_0020:Visualisation unitaire des graphes
499
    @expose(content_type='image/png')
500
    def getImage_png(self, host, start=None, duration=86400, graph=None, \
501
    details=1):
502
        """
503
        Affichage de l image d un graphe
504
        (via proxy RRD)
505

  
506
        @param host : hôte
507
        @type host : C{str}
508
        @param start : date-heure de debut des donnees
509
        @type start : C{str}
510
        @param duration : plage de temps des données
511
        @type duration : C{str}
512
                      (parametre optionnel, initialise a 86400 = plage de 1 jour)
513
        @param graph : graphe
514
        @type graph : C{str}
515
        @param details : indicateur affichage details dans graphe (legende)
516
        @type details : int
517

  
518
        @return: image du graphe
519
        @rtype: image png
520
        """
521
        result = None
522

  
523
        if start is None:
524
            start = int(time.time()) - 24*3600
525

  
526
        # valeurs particulieres
527
        direct = 1
528
        rrdserver = self.getRRDServer(host)
529
        
530
        if rrdserver is not None:
531
            # url
532
            url_web_path = config.get('rrd_web_path')
533
            url_l = '%s%s' % (rrdserver, url_web_path)
534

  
535
            # proxy
536
            rrdproxy = RRDProxy(url_l)
537
            try:
538
                result = rrdproxy.get_img_with_params(host, graph, direct, \
539
                duration, start, int(details))
540
            except urllib2.URLError:
541
                txt = _("Can't get RRD graph \"%(graph)s\" on "
542
                        "host \"%(host)s\"") % {
543
                    'graph': graph,
544
                    'host': host,
545
                }
546
                LOGGER.error(txt)
547
                exceptions.HTTPNotFound(comment=txt)
548

  
549
        return result
550

  
551
    @expose()
552
    def imagePage(self, server, graphtemplate):
553
        """
554
        Affichage de l image d un graphe
555

  
556
        @param server : hôte
557
        @type server : C{str}
558
        @param graphtemplate : graphe
559
        @type graphtemplate : C{str}
560

  
561
        @return: page avec l image du graphe (redirection sur getImage_png)
562
        @rtype: page
563
        """
564
        redirect('getImage_png?host=%s&graph=%s' % (server, graphtemplate))
565

  
566
    @expose()
567
    def getStartTime(self, host, nocache=None):
568
        """
569
        Determination de la date-heure de debut des donnees RRD d un hote
570
        (via proxy RRD)
571

  
572
        @param host : hôte
573
        @type host : C{str}
574

  
575
        @return: date-heure de debut des donnees RRD
576
        @rtype: C{str}
577
        """
578

  
579
        result = None
580
        getstarttime = 1
581
        rrdserver = self.getRRDServer(host)
582

  
583
        if rrdserver is not None:
584
            # url
585
            url_web_path = config.get('rrd_web_path')
586
            url_l = '%s%s' % (rrdserver, url_web_path)
587
    
588
            # proxy
589
            rrdproxy = RRDProxy(url_l)
590
            try:
591
                result = rrdproxy.get_starttime(host, getstarttime)
592
            except urllib2.URLError:
593
                txt = _("Can't get RRD data on host \"%s\"") % host
594
                LOGGER.error(txt)
595
                exceptions.HTTPNotFound(comment=txt)
596

  
597
        return result
598

  
599
    @expose()
600
    def metroPage(self, host):
601
        """
602
        Affichage page metrologie pour un hote
603
        (via proxy RRD)
604

  
605
        @param host : hôte
606
        @type host : C{str}
607

  
608
        @return: page de metrologie
609
        @rtype: page
610
        """
611
        result = None
612

  
613
        rrdserver = self.getRRDServer(host)
614
        if rrdserver is not None:
615
            # url
616
            url_web_path = config.get('rrd_web_path')
617
            url_l = '%s%s' % (rrdserver, url_web_path)
618

  
619
            # proxy
620
            rrdproxy = RRDProxy(url_l)
621
            try:
622
                result = rrdproxy.get_hostC(host)
623
            except urllib2.URLError:
624
                txt = _("Can't get RRD data on host \"%s\"") % host
625
                LOGGER.error(txt)
626
                error_url = '../error/rrd_error?host=%s' % host
627
                redirect(error_url)
628

  
629
        return result
445
#    # VIGILO_EXIG_VIGILO_PERF_0020:Visualisation unitaire des graphes
446
#    @expose(content_type='image/png')
447
#    def getImage_png(self, host, start=None, duration=86400, graph=None, \
448
#    details=1):
449
#        """
450
#        Affichage de l image d un graphe
451
#        (via proxy RRD)
452

  
453
#        @param host : hôte
454
#        @type host : C{str}
455
#        @param start : date-heure de debut des donnees
456
#        @type start : C{str}
457
#        @param duration : plage de temps des données
458
#        @type duration : C{str}
459
#                      (parametre optionnel, initialise a 86400 = plage de 1 jour)
460
#        @param graph : graphe
461
#        @type graph : C{str}
462
#        @param details : indicateur affichage details dans graphe (legende)
463
#        @type details : int
464

  
465
#        @return: image du graphe
466
#        @rtype: image png
467
#        """
468
#        result = None
630 469

  
631 470
    @expose('graphslist.html', content_type='text/html')
632 471
    def graphsList(self, nocache=None, **kwargs):
......
672 511
        indicators = [(ind.name, ind.idperfdatasource) for ind in indicators]
673 512
        return dict(items=indicators)
674 513

  
675
    def getListIndicators(self, graph=None):
676
        """
677
        Liste d indicateurs associes a un graphe
678

  
679
        @param graph : graphe
680
        @type graph  : C{str}
681

  
682
        @return: liste d indicateurs
683
        @rtype  : list
684
        """
685

  
686
        indicators = []
687
        if graph is not None:
688
            indicators = DBSession.query \
689
              (PerfDataSource.name, PerfDataSource.idperfdatasource) \
690
              .join((GRAPH_PERFDATASOURCE_TABLE, \
691
              GRAPH_PERFDATASOURCE_TABLE.c.idperfdatasource == \
692
              PerfDataSource.idperfdatasource)) \
693
              .join((Graph, \
694
              Graph.idgraph == GRAPH_PERFDATASOURCE_TABLE.c.idgraph)) \
695
              .filter(Graph.name == graph) \
696
              .all()
697
        return indicators
698

  
699
    # VIGILO_EXIG_VIGILO_PERF_0040:Export des donnees d'un graphe au format CSV
700
    @expose(content_type='text/csv')
701
    def exportCSV(self, nocache=None, host=None, graph=None, indicator=None, \
702
    start=None, end=None):
703
        """
704
        Export CSV sous forme de fichier
705
        pour un hote et un graphe et pour l'indicateur suivant
706
        * soit un des indicateurs associes au graphe
707
        * soit l ensemble des indicateurs -> valeur argument = All
708

  
709
        @param host : hôte
710
        @type host : C{str}
711
        @param graph : graphe
712
        @type graph : C{str}
713
        @param indicator : indicateur graphe
714
        @type indicator : C{str}
715
        @param start : date-heure de debut des donnees
716
        @type start : C{str}
717

  
718
        @return: fichier genere avec les donnees RRD repondant aux criteres
719
        @rtype  : fichier CSV
720
        """
721

  
722
        result = None
723
        filename = None
724

  
725
        # indicateurs
726
        if indicator is None:
727
            raise ValueError
728

  
729
        rrdserver = self.getRRDServer(host)
730
        if not rrdserver:
731
            raise ValueError, host
732

  
733
        indicators = [ind[0] for ind in self.getListIndicators(graph)]
734
        if indicator != "All":
735
            if indicator not in indicators:
736
                raise ValueError, indicator
737
            indicators = [indicator]
738
            filename = graphs.getExportFileName(host, indicator, start, end)
739

  
740
        else:
741
            filename = graphs.getExportFileName(host, graph, start, end)
742

  
743
        indicators.insert(0, "Timestamp")
744

  
745
        url_web_path = config.get('rrd_web_path', '')
746
        url = '%s%s' % (rrdserver, url_web_path)
747
        rrdproxy = RRDProxy(url)
748

  
749
        try:
750
            result = rrdproxy.exportCSV(server=host, graph=graph, \
751
                indicator=indicator, start=start, end=end)
752
        except urllib2.URLError:
753
            txt = _("Can't get RRD data on host \"%(host)s\", "
754
                    "graph \"%(graph)s\" and indicator \"%(indicator)s\"") % {
755
                        'host': host,
756
                        'graph': graph,
757
                        'indicator': indicator,
758
                    }
759
            LOGGER.error(txt)
760

  
761
            error_url = '../error'
762
            error_url += '/rrd_exportCSV_error'
763
            error_url += '?host=%s&graph=%s&indicator=%s' % \
764
                (host, graph, indicator)
765
            redirect(error_url)
766
        else:
767
            response.headerlist.append(('Content-Disposition',
768
                'attachment;filename=%s' % filename))
769
            return result
770

  
771

  
772 514
    # VIGILO_EXIG_VIGILO_PERF_0010:Visualisation globale des graphes
773 515
    @expose('fullhostpage.html')
774 516
    def fullHostPage(self, host, start=None, duration=86400):
......
897 639
        @rtype: document xml
898 640
        """
899 641

  
642
        # @TODO: une URL relative ne suffit-elle pas
643
        # ex: /public
900 644
        here = "http://"
901 645
        here += request.host
902 646
        dir_l = url('/public')
......
905 649

  
906 650
        return result
907 651

  
908
    def getRRDServer(self, host=None):
652
    def getListIndicators(self, graph=None):
909 653
        """
910
        Determination Serveur RRD pour l hote courant
911
        (Serveur RRD -> nom de l application associee = rrdgraph)
654
        Liste d indicateurs associes a un graphe
912 655

  
913
        @param host : hôte
914
        @type host : C{str}
656
        @param graph : graphe
657
        @type graph  : C{str}
915 658

  
916
        @return: serveur RRD
917
        @rtype: C{str}
659
        @return: liste d indicateurs
660
        @rtype  : list
918 661
        """
919 662

  
920
        result = DBSession.query(
921
                    VigiloServer.name
922
                ).filter(VigiloServer.idvigiloserver == \
923
                    Ventilation.idvigiloserver
924
                ).filter(Ventilation.idhost == Host.idhost
925
                ).filter(Ventilation.idapp == Application.idapp
926
                ).filter(Host.name == host
927
                ).filter(Application.name == 'rrdgraph'
928
                ).scalar()
929
        return result
663
        indicators = []
664
        if graph is not None:
665
            indicators = DBSession.query \
666
              (PerfDataSource.name, PerfDataSource.idperfdatasource) \
667
              .join((GRAPH_PERFDATASOURCE_TABLE, \
668
              GRAPH_PERFDATASOURCE_TABLE.c.idperfdatasource == \
669
              PerfDataSource.idperfdatasource)) \
670
              .join((Graph, \
671
              Graph.idgraph == GRAPH_PERFDATASOURCE_TABLE.c.idgraph)) \
672
              .filter(Graph.name == graph) \
673
              .all()
674
        return indicators
930 675

  
vigigraph/lib/graphs.py
5 5

  
6 6
import urllib
7 7
import urllib2
8
from pylons.i18n import ugettext as _
8
from pylons.i18n import lazy_ugettext as l_
9 9

  
10 10
from time import gmtime, strftime
11 11
from datetime import datetime
......
21 21
    graphslist = []
22 22
    
23 23
    if kwargs is not None:
24
        format = "%d-%m-%Y %H:%M"
24
        # TRANSLATORS: Format Python de date avec heure.
25
        format = l_("%d-%m-%Y %H:%M")
25 26
        for key in kwargs:
26 27
            # titre
27
            title = "Inconnu"
28
            title = l_("Unknown")
28 29
            graph = ""
29 30
            server = ""
30 31
            # recherche arguments (apres ?) -> cle1=valeur1&cle2=valeur2&...
......
49 50
            graph = {}
50 51
            graph['title'] = title
51 52
            v = int(start)
52
            graph['sts'] = _(strftime(format, gmtime(v)))
53
            graph['sts'] = strftime(format, gmtime(v))
53 54
            v = int(start) + int(duration)
54
            graph['ets'] = _(strftime(format, gmtime(v)))
55
            graph['ets'] = strftime(format, gmtime(v))
55 56
            graph['src'] = urllib2.unquote(kwargs[key])
56 57
            graphslist.append(graph)
57 58

  
......
85 86

  
86 87
    return delay
87 88

  
88
def getExportFileName(host, indicator_f, start, end):
89
    """
90
    Determination nom fichier pour export
91
    -> <hote>_<indicator_f>_<date_heure_debut>_<date_heure_fin>
92
    avec format <date_heure_...> = AAMMJJ-hhmmss
93

  
94
    @param host : hôte
95
    @type host : C{str}
96
    @param indicator_f : indicateur graphe ( nom du graphe ou d un des indicateurs)
97
    @type indicator_f : C{str}
98
    @param start : date-heure de debut des donnees
99
    @type start : C{str}
100
    @param end : duree des donnees
101
    @type end : C{str}
102

  
103
    @return: nom du fichier
104
    @rtype: C{str}
105
    """
106

  
107
    # plage temps sous forme texte
108
    format = '%Y%m%d-%H%M%S'
109

  
110
    dt = datetime.utcfromtimestamp(int(start))
111
    str_start = dt.strftime(format)
112

  
113
    dt = datetime.utcfromtimestamp(int(end))
114
    str_end = dt.strftime(format)
115

  
116
    # nom fichier
117
    filename = '%s_%s_%s_%s' % (host, indicator_f, str_start, str_end)
118

  
119
    # remplacement caracteres particuliers
120
    lc = [' ', '|', '/', '\\', ':', '?', '*', '<', '>', '"']
121
    for c in lc:
122
        filename = filename.replace(c, "_")
123

  
124
    # extension
125
    filename += ".csv"
126

  
127
    return filename
128

  
129
def setExportFile(writer, dict_values, dict_indicators, sep_value):
130
    """
131
    Ecriture des donnees sous forme texte dans le fichier d export
132
    (les donnees se rapportent aux indicateurs passes en parametre)
133

  
134
    @param writer : gestion csv pour lecture/ecriture
135
    @type writer : csv.DictWriter (voir Python)
136
    @param dict_values : valeurs
137
    @type dict_values : dict
138
    @param dict_indicators : indicateurs
139
    @type dict_indicators : dict
140
    @param sep_value : separateur partie entiere - partie decimale
141
    @type sep_value : C{str}
142

  
143
    @return: resultat generation (pas de valeurs -> false, sinon true)
144
    @rtype: booleen
145
    """
146

  
147
    # format pour valeur temps
148
    format = '%Y/%m/%d %H:%M:%S'
149

  
150
    result = (writer is not None)
151
    result &= (dict_values is not None or dict_values != "{}")
152
    if result:
153
        # parcours valeurs
154
        for key_tv in dict_values:
155
            tv = dict_values[key_tv]
156

  
157
            # generation ligne
158
            dict_data = {}
159
            for key_i in dict_indicators:
160
                iv = dict_indicators[key_i]
161
                v = str(tv[key_i])
162

  
163
                # temps sous forme texte
164
                if iv == 'TimeStamp':
165
                    dt = datetime.utcfromtimestamp(int(v))
166
                    v = dt.strftime(format)
167

  
168
                # separateur dans valeur -> remplacement . par ,
169
                v = v.replace(".", sep_value)
170

  
171
                dict_data[iv] = v
172

  
173
            writer.writerow(dict_data)
174

  
175
    return result

Also available in: Unified diff