Revision 62c4c6f5
Corrections pour faciliter les traductions dans VigiGraph.
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2655 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigigraph/controllers/rpc.py | ||
---|---|---|
6 | 6 |
import urllib2 |
7 | 7 |
import logging |
8 | 8 |
|
9 |
from pylons.i18n import ugettext as _ |
|
9 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_
|
|
10 | 10 |
from tg import expose, response, request, redirect, config, url, exceptions |
11 | 11 |
from sqlalchemy.orm import aliased |
12 |
from repoze.what.predicates import not_anonymous |
|
12 | 13 |
|
13 | 14 |
from vigigraph.lib.base import BaseController |
14 | 15 |
|
... | ... | |
41 | 42 |
Class Controleur TurboGears |
42 | 43 |
""" |
43 | 44 |
|
45 |
# L'accès à ce contrôleur nécessite d'être identifié. |
|
46 |
allow_only = not_anonymous(l_("You need to be authenticated")) |
|
47 |
|
|
44 | 48 |
presets = [ |
45 | 49 |
{"caption" : _("Last %d hours") % 12, "duration" : 43200}, |
46 | 50 |
{"caption" : _("Last %d hours") % 24, "duration" : 86400}, |
... | ... | |
57 | 61 |
""" |
58 | 62 |
Determination des groupes principaux (sans parent) |
59 | 63 |
|
60 |
@return: groupes principaux |
|
61 |
@rtype: document json (sous forme de dict) |
|
64 |
@return: Dictionnaire dont la clé "items" contient une liste |
|
65 |
de tuples contenant le nom et l'ID des groupes d'éléments |
|
66 |
au sommet de la hiérarchie et auquels l'utilisateur a accès. |
|
67 |
@rtype: C{dict} |
|
68 |
@note: L'ID des groupes est converti en chaîne de caractères |
|
69 |
dans le résultat. |
|
62 | 70 |
""" |
63 | 71 |
topgroups = [(tpg.name, str(tpg.idgroup)) \ |
64 | 72 |
for tpg in SupItemGroup.get_top_groups()] |
... | ... | |
70 | 78 |
Determination des groupes associes au groupe parent |
71 | 79 |
dont identificateur = argument |
72 | 80 |
|
73 |
@param maingroupid : identificateur d un groupe principal
|
|
74 |
@type maingroupid : int
|
|
81 |
@param maingroupid: identificateur d un groupe principal |
|
82 |
@type maingroupid: C{int}
|
|
75 | 83 |
|
76 |
@return: groupes |
|
77 |
@rtype: document json (sous forme de dict) |
|
84 |
@return: Dictionnaire dont la clé "items" contient une liste |
|
85 |
de tuples avec le nom et l'ID des groupes d'éléments |
|
86 |
auxquels l'utilisateur a accès. |
|
87 |
@rtype: C{dict} |
|
88 |
@note: L'ID des groupes est converti en chaîne de caractères |
|
89 |
dans le résultat. |
|
78 | 90 |
""" |
79 | 91 |
hostgroups = DBSession.query( |
80 | 92 |
SupItemGroup.name, |
... | ... | |
398 | 410 |
result = rrdproxy.get_img_name_with_params(host, graph, \ |
399 | 411 |
direct, duration, start, int(details)) |
400 | 412 |
except urllib2.URLError: |
401 |
txt = _("Can't get RRD graph \"%s\" on host \"%s\"") \ |
|
402 |
% (graph, host) |
|
413 |
txt = _("Can't get RRD graph \"%(graph)\" on " |
|
414 |
"host \"%(host)s\"") % { |
|
415 |
'graph': graph, |
|
416 |
'host': host, |
|
417 |
} |
|
403 | 418 |
LOGGER.error(txt) |
404 | 419 |
exceptions.HTTPNotFound(comment=txt) |
405 | 420 |
|
... | ... | |
448 | 463 |
result = rrdproxy.get_img_with_params(host, graph, direct, \ |
449 | 464 |
duration, start, int(details)) |
450 | 465 |
except urllib2.URLError: |
451 |
txt = _("Can't get RRD graph \"%s\" on host \"%s\"") \ |
|
452 |
% (graph, host) |
|
466 |
txt = _("Can't get RRD graph \"%(graph)\" on " |
|
467 |
"host \"%(host)s\"") % { |
|
468 |
'graph': graph, |
|
469 |
'host': host, |
|
470 |
} |
|
453 | 471 |
LOGGER.error(txt) |
454 | 472 |
exceptions.HTTPNotFound(comment=txt) |
455 | 473 |
|
... | ... | |
497 | 515 |
try: |
498 | 516 |
result = rrdproxy.get_starttime(host, getstarttime) |
499 | 517 |
except urllib2.URLError: |
500 |
txt = _("Can't get RRD data on host \"%s\"") \ |
|
501 |
% (host) |
|
518 |
txt = _("Can't get RRD data on host \"%s\"") % host |
|
502 | 519 |
LOGGER.error(txt) |
503 | 520 |
exceptions.HTTPNotFound(comment=txt) |
504 | 521 |
|
... | ... | |
529 | 546 |
try: |
530 | 547 |
result = nagiosproxy.get_status(host) |
531 | 548 |
except urllib2.URLError: |
532 |
txt = _("Can't get Nagios data on host \"%s\"") \ |
|
533 |
% (host) |
|
549 |
txt = _("Can't get Nagios data on host \"%s\"") % host |
|
534 | 550 |
LOGGER.error(txt) |
535 |
error_url = '../error/nagios_host_error?host=%s' |
|
536 |
redirect(error_url % host)
|
|
551 |
error_url = '../error/nagios_host_error?host=%s' % host
|
|
552 |
redirect(error_url) |
|
537 | 553 |
else: |
538 | 554 |
txt = _("No server has been configured to monitor \"%s\"") % host |
539 | 555 |
LOGGER.error(txt) |
... | ... | |
570 | 586 |
try: |
571 | 587 |
result = nagiosproxy.get_extinfo(host, service) |
572 | 588 |
except urllib2.URLError: |
573 |
txt = _("Can't get Nagios data on host \"%s\" service \"%s\"")\ |
|
574 |
% (host, service) |
|
589 |
txt = _("Can't get Nagios data on host \"%(host)s\" " |
|
590 |
"and service \"%(service)s\"") % { |
|
591 |
'host': host, |
|
592 |
'service': service, |
|
593 |
} |
|
575 | 594 |
LOGGER.error(txt) |
576 | 595 |
|
577 |
error_url = '../error'
|
|
578 |
error_url += '/nagios_host_service_error?host=%s&service=%s'
|
|
579 |
redirect(error_url % (host, service))
|
|
596 |
error_url = '../error/nagios_host_service_error' \
|
|
597 |
'?host=%s&service=%s' % (host, service)
|
|
598 |
redirect(error_url) |
|
580 | 599 |
|
581 | 600 |
return result |
582 | 601 |
|
... | ... | |
605 | 624 |
try: |
606 | 625 |
result = rrdproxy.get_hostC(host) |
607 | 626 |
except urllib2.URLError: |
608 |
txt = _("Can't get RRD data on host \"%s\"") \ |
|
609 |
% (host) |
|
627 |
txt = _("Can't get RRD data on host \"%s\"") % host |
|
610 | 628 |
LOGGER.error(txt) |
611 |
error_url = '../error/rrd_error?host=%s' |
|
612 |
redirect(error_url % host)
|
|
629 |
error_url = '../error/rrd_error?host=%s' % host
|
|
630 |
redirect(error_url) |
|
613 | 631 |
|
614 | 632 |
return result |
615 | 633 |
|
... | ... | |
735 | 753 |
result = rrdproxy.exportCSV(server=host, graph=graph, \ |
736 | 754 |
indicator=indicator, start=start, end=end) |
737 | 755 |
except urllib2.URLError: |
738 |
# @TODO utiliser des dicos pour faciliter la traduction. |
|
739 |
txt = _("Can't get RRD data on host \"%s\" " |
|
740 |
"graph \"%s\" indicator \"%s\" ") % (host, graph, indicator) |
|
756 |
txt = _("Can't get RRD data on host \"%(host)s\", " |
|
757 |
"graph \"%(graph)s\" and indicator \"%(indicator)s\"") % { |
|
758 |
'host': host, |
|
759 |
'graph': graph, |
|
760 |
'indicator': indicator, |
|
761 |
} |
|
741 | 762 |
LOGGER.error(txt) |
742 | 763 |
|
743 | 764 |
error_url = '../error' |
744 | 765 |
error_url += '/rrd_exportCSV_error' |
745 |
error_url += '?host=%s&graph=%s&indicator=%s' |
|
746 |
redirect(error_url % (host, graph, indicator)) |
|
766 |
error_url += '?host=%s&graph=%s&indicator=%s' % \ |
|
767 |
(host, graph, indicator) |
|
768 |
redirect(error_url) |
|
747 | 769 |
else: |
748 | 770 |
response.headerlist.append(('Content-Disposition', |
749 | 771 |
'attachment;filename=%s' % filename)) |
... | ... | |
898 | 920 |
@rtype: C{str} |
899 | 921 |
""" |
900 | 922 |
|
901 |
result = DBSession.query \ |
|
902 |
(VigiloServer.name) \ |
|
903 |
.filter(VigiloServer.idvigiloserver == Ventilation.idvigiloserver) \ |
|
904 |
.filter(Ventilation.idhost == Host.idhost) \ |
|
905 |
.filter(Ventilation.idapp == Application.idapp) \ |
|
906 |
.filter(Host.name == host) \ |
|
907 |
.filter(Application.name == 'rrdgraph') \ |
|
908 |
.scalar() |
|
923 |
result = DBSession.query( |
|
924 |
VigiloServer.name |
|
925 |
).filter(VigiloServer.idvigiloserver == \ |
|
926 |
Ventilation.idvigiloserver |
|
927 |
).filter(Ventilation.idhost == Host.idhost |
|
928 |
).filter(Ventilation.idapp == Application.idapp |
|
929 |
).filter(Host.name == host |
|
930 |
).filter(Application.name == 'rrdgraph' |
|
931 |
).scalar() |
|
909 | 932 |
return result |
910 | 933 |
|
911 | 934 |
def getNagiosServer(self, host=None): |
... | ... | |
920 | 943 |
@rtype: C{str} |
921 | 944 |
""" |
922 | 945 |
|
923 |
result = DBSession.query \ |
|
924 |
(VigiloServer.name) \ |
|
925 |
.filter(VigiloServer.idvigiloserver == Ventilation.idvigiloserver) \ |
|
926 |
.filter(Ventilation.idhost == Host.idhost) \ |
|
927 |
.filter(Ventilation.idapp == Application.idapp) \ |
|
928 |
.filter(Host.name == host) \ |
|
929 |
.filter(Application.name == 'nagios') \ |
|
930 |
.scalar() |
|
946 |
result = DBSession.query( |
|
947 |
VigiloServer.name |
|
948 |
).filter(VigiloServer.idvigiloserver == \ |
|
949 |
Ventilation.idvigiloserver |
|
950 |
).filter(Ventilation.idhost == Host.idhost |
|
951 |
).filter(Ventilation.idapp == Application.idapp |
|
952 |
).filter(Host.name == host |
|
953 |
).filter(Application.name == 'nagios' |
|
954 |
).scalar() |
|
931 | 955 |
return result |
956 |
|
Also available in: Unified diff