Revision 9a31cbd1
Diverses améliorations/corrections dans VigiGraph.
Les points restants à traiter sont indiqués par des "@TODO" ou "@XXX" dans le code.
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2782 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigigraph/controllers/rpc.py | ||
---|---|---|
27 | 27 |
from vigilo.models.tables.secondary_tables import GRAPH_GROUP_TABLE |
28 | 28 |
from vigilo.models.tables.secondary_tables import GRAPH_PERFDATASOURCE_TABLE |
29 | 29 |
from vigilo.models.functions import sql_escape_like |
30 |
|
|
30 |
|
|
31 | 31 |
from vigilo.turbogears.helpers import get_current_user |
32 | 32 |
|
33 | 33 |
from vigigraph.widgets.searchhostform import SearchHostForm |
... | ... | |
466 | 466 |
# """ |
467 | 467 |
# result = None |
468 | 468 |
|
469 |
@expose('graphslist.html', content_type='text/html')
|
|
469 |
@expose('graphslist.html') |
|
470 | 470 |
def graphsList(self, nocache=None, **kwargs): |
471 | 471 |
""" |
472 | 472 |
Generation document avec url des graphes affiches |
... | ... | |
534 | 534 |
if start is None: |
535 | 535 |
start = int(time.time()) - int(duration) |
536 | 536 |
|
537 |
# graphes pour hote |
|
538 |
hgs = DBSession.query(Graph.name).distinct() \ |
|
539 |
.join((GRAPH_PERFDATASOURCE_TABLE, \ |
|
540 |
GRAPH_PERFDATASOURCE_TABLE.c.idgraph == Graph.idgraph)) \ |
|
541 |
.join((PerfDataSource, \ |
|
542 |
GRAPH_PERFDATASOURCE_TABLE.c.idperfdatasource == \ |
|
543 |
PerfDataSource.idperfdatasource)) \ |
|
544 |
.join((LowLevelService, \ |
|
545 |
PerfDataSource.idservice == LowLevelService.idservice)) \ |
|
546 |
.join((Host, \ |
|
547 |
LowLevelService.idhost == Host.idhost)) \ |
|
548 |
.filter(Host.name == host) \ |
|
549 |
.all() |
|
537 |
# @TODO définir des validateurs sur les paramètres |
|
538 |
start = int(start) |
|
539 |
duration = int(duration) |
|
550 | 540 |
|
551 |
# dictionnaire -> {0 : [hote, graph_0], ..., n: [hote, graph_n] } |
|
552 |
i = 0 |
|
553 |
dhgs = {} |
|
554 |
for hg in hgs: |
|
555 |
elt = [host, hg] |
|
556 |
dhgs[i] = elt |
|
557 |
i += 1 |
|
541 |
user = get_current_user() |
|
542 |
if user is None: |
|
543 |
return dict(host=host, start=start, duration=duration, |
|
544 |
presets=self.presets, graphs=[]) |
|
545 |
supitemgroups = user.supitemgroups() |
|
558 | 546 |
|
559 |
return dict(host=host, start=start, duration=duration, \ |
|
560 |
presets=self.presets, dhgs=dhgs) |
|
547 |
# Récupération de la liste des noms des graphes, |
|
548 |
# avec vérification des permissions de l'utilisateur. |
|
549 |
graphs = DBSession.query( |
|
550 |
Graph.name |
|
551 |
).distinct( |
|
552 |
).join( |
|
553 |
(GRAPH_PERFDATASOURCE_TABLE, |
|
554 |
GRAPH_PERFDATASOURCE_TABLE.c.idgraph == Graph.idgraph), |
|
555 |
(PerfDataSource, PerfDataSource.idperfdatasource == |
|
556 |
GRAPH_PERFDATASOURCE_TABLE.c.idperfdatasource), |
|
557 |
(LowLevelService, LowLevelService.idservice == |
|
558 |
PerfDataSource.idservice), |
|
559 |
).outerjoin( |
|
560 |
(Host, Host.idhost == LowLevelService.idhost), |
|
561 |
).join( |
|
562 |
(SUPITEM_GROUP_TABLE, or_( |
|
563 |
SUPITEM_GROUP_TABLE.c.idsupitem == |
|
564 |
LowLevelService.idservice, |
|
565 |
SUPITEM_GROUP_TABLE.c.idsupitem == Host.idhost, |
|
566 |
)) |
|
567 |
).filter(SUPITEM_GROUP_TABLE.c.idgroup.in_(supitemgroups) |
|
568 |
).all() |
|
569 |
|
|
570 |
return dict(host=host, start=start, duration=duration, |
|
571 |
presets=self.presets, graphs=graphs) |
|
561 | 572 |
|
562 | 573 |
@expose('singlegraph.html') |
563 | 574 |
def singleGraph(self, host, graph, start=None, duration=86400): |
... | ... | |
584 | 595 |
if start is None: |
585 | 596 |
start = int(time.time()) - int(duration) |
586 | 597 |
|
598 |
# @TODO définir des validateurs sur les paramètres |
|
599 |
start = int(start) |
|
600 |
duration = int(duration) |
|
601 |
|
|
587 | 602 |
return dict(host=host, graph=graph, start=start, duration=duration, \ |
588 | 603 |
presets=self.presets) |
589 | 604 |
|
... | ... | |
603 | 618 |
@expose('searchhost.html') |
604 | 619 |
def searchHost(self, query=None): |
605 | 620 |
""" |
606 |
Affichage page pour hotes repondant au critere de recherche |
|
607 |
* dans cette page, lien sur pages de metrologie et de supervision |
|
621 |
Affiche les résultats de la recherche par nom d'hôte. |
|
622 |
La requête de recherche (L{query}) correspond à un préfixe |
|
623 |
qui sera recherché dans le nom d'hôte. Ce préfixe peut |
|
624 |
contenir les caractères '*' et '?' qui agissent comme des |
|
625 |
"jokers". |
|
608 | 626 |
|
609 |
@param query : prefixe de recherche sur les hotes |
|
610 |
@type query : C{str} |
|
611 |
|
|
612 |
@return: page |
|
613 |
@rtype: page html |
|
627 |
@param query: Prefixe de recherche sur les noms d'hôtes |
|
628 |
@type query: C{unicode} |
|
614 | 629 |
""" |
615 | 630 |
|
616 |
hosts = [] |
|
631 |
if not query: |
|
632 |
redirect("searchHostForm") |
|
617 | 633 |
|
618 |
if query: |
|
619 |
r = urllib.unquote_plus(query.strip()) |
|
620 |
rl = r.split(',') |
|
634 |
query = sql_escape_like(query.strip()) |
|
635 |
user = get_current_user() |
|
636 |
if user is None: |
|
637 |
return dict(items=[]) |
|
638 |
supitemgroups = user.supitemgroups() |
|
621 | 639 |
|
622 |
# hotes |
|
623 |
for part in rl: |
|
624 |
hosts += DBSession.query(Host.name) \ |
|
625 |
.filter(Host.name.like(part.strip() + '%')) \ |
|
626 |
.all() |
|
627 |
return dict(hosts=hosts) |
|
628 |
else: |
|
629 |
redirect("searchHostForm") |
|
640 |
# Récupère les hôtes auxquels l'utilisateur a réellement accès. |
|
641 |
hosts = DBSession.query( |
|
642 |
Host.name, |
|
643 |
).distinct( |
|
644 |
).outerjoin( |
|
645 |
(LowLevelService, LowLevelService.idhost == Host.idhost), |
|
646 |
).join( |
|
647 |
(SUPITEM_GROUP_TABLE, or_( |
|
648 |
SUPITEM_GROUP_TABLE.c.idsupitem == Host.idhost, |
|
649 |
SUPITEM_GROUP_TABLE.c.idsupitem == |
|
650 |
LowLevelService.idservice, |
|
651 |
)), |
|
652 |
).filter(SUPITEM_GROUP_TABLE.c.idgroup.in_(supitemgroups) |
|
653 |
).filter(Host.name.like(query+'%') |
|
654 |
).order_by( |
|
655 |
Host.name.asc(), |
|
656 |
).all() |
|
657 |
return dict(hosts=hosts) |
|
630 | 658 |
|
631 | 659 |
# VIGILO_EXIG_VIGILO_PERF_0030:Moteur de recherche des graphes |
632 | 660 |
@expose('getopensearch.xml', content_type='text/xml') |
vigigraph/lib/graphs.py | ||
---|---|---|
5 | 5 |
|
6 | 6 |
import urllib |
7 | 7 |
import urllib2 |
8 |
from pylons.i18n import lazy_ugettext as l_
|
|
8 |
from pylons.i18n import ugettext as _
|
|
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 |
# TRANSLATORS: Format Python de date avec heure.
|
|
25 |
format = l_("%d-%m-%Y %H:%M")
|
|
24 |
# TRANSLATORS: Format Python de date/heure, lisible par un humain.
|
|
25 |
format = _("%a, %d %b %Y %H:%M:%S")
|
|
26 | 26 |
for key in kwargs: |
27 | 27 |
# titre |
28 |
title = l_("Unknown")
|
|
28 |
title = _("Unknown") |
|
29 | 29 |
graph = "" |
30 | 30 |
server = "" |
31 | 31 |
# recherche arguments (apres ?) -> cle1=valeur1&cle2=valeur2&... |
Also available in: Unified diff