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, url
|
5 |
|
from tg import exceptions
|
|
4 |
import time
|
|
5 |
import urllib
|
|
6 |
import urllib2
|
|
7 |
import csv
|
|
8 |
import logging
|
|
9 |
|
|
10 |
from pylons.i18n import ugettext as _
|
|
11 |
from tg import expose, response, request, redirect, config, url, exceptions
|
|
12 |
from sqlalchemy.orm import aliased
|
6 |
13 |
|
7 |
14 |
from vigigraph.lib.base import BaseController
|
8 |
15 |
|
... | ... | |
17 |
24 |
from vigilo.models.tables.secondary_tables import HOST_GROUP_TABLE
|
18 |
25 |
from vigilo.models.tables.secondary_tables import GRAPH_GROUP_TABLE
|
19 |
26 |
from vigilo.models.tables.secondary_tables import GRAPH_PERFDATASOURCE_TABLE
|
20 |
|
|
21 |
27 |
from vigilo.models.functions import sql_escape_like
|
22 |
|
|
23 |
|
from sqlalchemy.orm import aliased
|
24 |
28 |
|
25 |
29 |
from vigilo.turbogears.rrdproxy import RRDProxy
|
26 |
|
from nagiosproxy import NagiosProxy
|
27 |
|
|
28 |
|
from pylons.i18n import ugettext as _
|
29 |
|
|
30 |
|
import time
|
31 |
|
import random
|
32 |
|
import urllib
|
33 |
|
import urllib2
|
34 |
|
import csv
|
35 |
|
import logging
|
36 |
30 |
|
|
31 |
from nagiosproxy import NagiosProxy
|
37 |
32 |
from searchhostform import SearchHostForm
|
38 |
33 |
from vigigraph.lib import graphs
|
39 |
34 |
|
... | ... | |
42 |
37 |
|
43 |
38 |
__all__ = ['RpcController']
|
44 |
39 |
|
45 |
|
|
|
40 |
# pylint: disable-msg=R0201
|
46 |
41 |
class RpcController(BaseController):
|
47 |
42 |
"""
|
48 |
43 |
Class Controleur TurboGears
|
... | ... | |
349 |
344 |
|
350 |
345 |
# valeurs particulieres
|
351 |
346 |
direct = 1
|
352 |
|
fakeIncr = random.randint(0, 9999999999)
|
353 |
|
|
354 |
347 |
rrdserver = self.getRRDServer(host)
|
|
348 |
|
355 |
349 |
if rrdserver is not None:
|
356 |
350 |
# url
|
357 |
351 |
url_web_path = config.get('rrd_web_path')
|
... | ... | |
362 |
356 |
try:
|
363 |
357 |
result = rrdproxy.get_img_name_with_params(host, graph, \
|
364 |
358 |
direct, duration, start, int(details))
|
365 |
|
except urllib2.URLError, e:
|
|
359 |
except urllib2.URLError:
|
366 |
360 |
txt = _("Can't get RRD graph \"%s\" on host \"%s\"") \
|
367 |
361 |
% (graph, host)
|
368 |
362 |
LOGGER.error(txt)
|
... | ... | |
400 |
394 |
|
401 |
395 |
# valeurs particulieres
|
402 |
396 |
direct = 1
|
403 |
|
fakeIncr = random.randint(0, 9999999999)
|
404 |
|
|
405 |
397 |
rrdserver = self.getRRDServer(host)
|
406 |
398 |
|
407 |
399 |
if rrdserver is not None:
|
... | ... | |
414 |
406 |
try:
|
415 |
407 |
result = rrdproxy.get_img_with_params(host, graph, direct, \
|
416 |
408 |
duration, start, int(details))
|
417 |
|
except urllib2.URLError, e:
|
|
409 |
except urllib2.URLError:
|
418 |
410 |
txt = _("Can't get RRD graph \"%s\" on host \"%s\"") \
|
419 |
411 |
% (graph, host)
|
420 |
412 |
LOGGER.error(txt)
|
... | ... | |
451 |
443 |
"""
|
452 |
444 |
|
453 |
445 |
result = None
|
454 |
|
|
455 |
446 |
getstarttime = 1
|
456 |
|
fakeincr = random.randint(0, 9999999999)
|
457 |
|
|
458 |
447 |
rrdserver = self.getRRDServer(host)
|
|
448 |
|
459 |
449 |
if rrdserver is not None:
|
460 |
450 |
# url
|
461 |
451 |
url_web_path = config.get('rrd_web_path')
|
... | ... | |
465 |
455 |
rrdproxy = RRDProxy(url_l)
|
466 |
456 |
try:
|
467 |
457 |
result = rrdproxy.get_starttime(host, getstarttime)
|
468 |
|
except urllib2.URLError, e:
|
|
458 |
except urllib2.URLError:
|
469 |
459 |
txt = _("Can't get RRD data on host \"%s\"") \
|
470 |
460 |
% (host)
|
471 |
461 |
LOGGER.error(txt)
|
... | ... | |
497 |
487 |
nagiosproxy = NagiosProxy(url_l)
|
498 |
488 |
try:
|
499 |
489 |
result = nagiosproxy.get_status(host)
|
500 |
|
except urllib2.URLError, e:
|
|
490 |
except urllib2.URLError:
|
501 |
491 |
txt = _("Can't get Nagios data on host \"%s\"") \
|
502 |
492 |
% (host)
|
503 |
493 |
LOGGER.error(txt)
|
... | ... | |
532 |
522 |
nagiosproxy = NagiosProxy(url_l)
|
533 |
523 |
try:
|
534 |
524 |
result = nagiosproxy.get_extinfo(host, service)
|
535 |
|
except urllib2.URLError, e:
|
|
525 |
except urllib2.URLError:
|
536 |
526 |
txt = _("Can't get Nagios data on host \"%s\" service \"%s\"")\
|
537 |
527 |
% (host, service)
|
538 |
528 |
LOGGER.error(txt)
|
... | ... | |
567 |
557 |
rrdproxy = RRDProxy(url_l)
|
568 |
558 |
try:
|
569 |
559 |
result = rrdproxy.get_hostC(host)
|
570 |
|
except urllib2.URLError, e:
|
|
560 |
except urllib2.URLError:
|
571 |
561 |
txt = _("Can't get RRD data on host \"%s\"") \
|
572 |
562 |
% (host)
|
573 |
563 |
LOGGER.error(txt)
|
... | ... | |
727 |
717 |
rrdproxy = RRDProxy(url_l)
|
728 |
718 |
try:
|
729 |
719 |
result = rrdproxy.exportCSV(server=host, graph=graph, \
|
730 |
|
indicator=indicator, start=start, end=end)
|
731 |
|
except urllib2.URLError, e:
|
|
720 |
indicator=indicator, start=start, end=end)
|
|
721 |
except urllib2.URLError:
|
732 |
722 |
b_export = False
|
733 |
723 |
|
734 |
724 |
txt = _("Can't get RRD data on host \"%s\" \
|
735 |
|
graph \"%s\" indicator \"%s\" ") \
|
|
725 |
graph \"%s\" indicator \"%s\" ") \
|
736 |
726 |
% (host, graph, indicator)
|
737 |
727 |
LOGGER.error(txt)
|
738 |
728 |
|
... | ... | |
755 |
745 |
|
756 |
746 |
# fichier
|
757 |
747 |
f = open(filename, 'wt')
|
758 |
|
fn = 'attachment;filename='+filename
|
|
748 |
fn = 'attachment;filename=' + filename
|
759 |
749 |
response.headerlist.append \
|
760 |
750 |
(('Content-Disposition', fn))
|
761 |
751 |
try:
|