Project

General

Profile

Revision cc8fe16b

IDcc8fe16b6148fc3767ceb5590950edc073dc7ea9
Parent 2d8c18dc
Child 33c3eea0

Added by Francois POIROTTE about 14 years ago

Ajout d'un proxy Nagios dans vigilo.turbogears.controllers.
Ce proxy est utilisé par VigiGraph pour intégrer les pages de Nagios dans l'interface de Vigilo.

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

View differences:

javascript/source/class/vigigraph/Application.js
46 46
    "graphs": "/rpc/graphs",
47 47
    "selectHostAndGraph": "/rpc/selectHostAndGraph",
48 48
    "searchHostAndGraph": "/rpc/searchHostAndGraph",
49
    "supPage": "/rpc/supPage",
49
    "supPage": "/nagios/",
50 50
    "getImage": "/rpc/getImage",
51 51
    "getStartTime": "/rpc/getStartTime",
52 52
    "graphsList": "/rpc/graphsList",
......
256 256
      }, true);
257 257

  
258 258
      b3.addEventListener("execute",function(e) {
259
        var win = new qx.client.NativeWindow(urls.supPage+"?host="+combo3.getSelected().getLabel());
259
        var win = new qx.client.NativeWindow(urls.supPage+
260
          combo3.getSelected().getLabel()+'/cgi-bin/status.cgi'+
261
          '?style=detail&supNav=1');
260 262
        win.setDimension(800,600);
261 263
        win.setDependent(false);
262 264
        win.open();
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 15

  
14 16
__all__ = ['RootController']
15 17

  
......
32 34
    """
33 35
    error = ErrorController()
34 36
    rpc = RpcController()
37
    nagios = make_nagios_proxy_controller(BaseController, '/nagios/')
35 38

  
36 39
    @expose('index.html')
37 40
    @require(Any(not_anonymous(), msg=_("You need to be authenticated")))
vigigraph/controllers/rpc.py
29 29
from vigilo.models.functions import sql_escape_like
30 30
        
31 31
from vigilo.turbogears.rrdproxy import RRDProxy
32
from vigilo.turbogears.nagiosproxy import NagiosProxy
33 32
from vigilo.turbogears.helpers import get_current_user
34 33

  
35 34
from vigigraph.widgets.searchhostform import SearchHostForm
......
578 577

  
579 578
    @expose()
580 579
    def supPage(self, host):
581
        """
582
        Affichage page supervision Nagios pour un hote
583
        (appel fonction status via proxy Nagios)
584
        
585
        @param host : hôte
586
        @type host : C{str}
580
        proxy = nagiosproxy.NagiosProxy()
581
        values = {
582
            'host' : host,
583
            'style' : 'detail',
584
            'supNav' : 1,
585
        }
587 586

  
588
        @return: page de supervision Nagios
589
        @rtype: page
590
        """
591
        result = None
592

  
593
        nagiosserver = self.getNagiosServer(host)
594
        if nagiosserver is not None:
595
            # url
596
            url_web_path = config.get('nagios_web_path')
597
            url_l = '%s%s' % (nagiosserver, url_web_path)
598

  
599
            # proxy
600
            nagiosproxy = NagiosProxy(url_l)
601
            try:
602
                result = nagiosproxy.get_status(host)
603
            except urllib2.URLError:
604
                txt = _("Can't get Nagios data on host \"%s\"") % host
605
                LOGGER.error(txt)
606
                error_url = '../error/nagios_host_error?host=%s' % host
607
                redirect(error_url)
608
        else:
587
        try:
588
            res = proxy.retrieve(host, 'cgi-bin/status.cgi', values)
589
        except urllib2.URLError:
590
            LOGGER.exception(_("Can't get Nagios data on host \"%s\"") % host)
591
            error_url = '../error/nagios_host_error?host=%s' % host
592
            redirect(error_url)
593
        except nagiosproxy.NoNagiosServerConfigured:
609 594
            txt = _("No server has been configured to monitor \"%s\"") % host
610 595
            LOGGER.error(txt)
611 596
            error_url = '../error/nagios_host_error?host=%s' % host
612 597
            redirect(error_url)
613

  
614

  
615
        return result
598
        return res.read()
616 599

  
617 600
    @expose()
618
    def servicePage(self, host, service=None):
601
    def servicePage(self, host, service):
619 602
        """
620 603
        Affichage page supervision Nagios pour un hote
621 604
        (appel fonction get_extinfo via proxy Nagios)
......
628 611
        @return: page de supervision Nagios
629 612
        @rtype: page
630 613
        """
631
        result = None
614
        proxy = nagiosproxy.NagiosProxy()
615
        values = {
616
            'host' : host,
617
            'service': service,
618
            'type' : 2,
619
            'supNav' : 1,
620
        }
632 621

  
633
        nagiosserver = self.getNagiosServer(host)
634
        if nagiosserver is not None:
635
            # url
636
            url_web_path = config.get('nagios_web_path')
637
            url_l = '%s%s' % (nagiosserver, url_web_path)
638

  
639
            # proxy
640
            nagiosproxy = NagiosProxy(url_l)
641
            try:
642
                result = nagiosproxy.get_extinfo(host, service)
643
            except urllib2.URLError:
622
        try:
623
            res = proxy.retrieve(host, 'cgi-bin/extinfo.cgi', values)
624
        except urllib2.URLError:
644 625
                txt = _("Can't get Nagios data on host \"%(host)s\" "
645 626
                        "and service \"%(service)s\"") % {
646 627
                            'host': host,
647 628
                            'service': service,
648 629
                        }
649 630
                LOGGER.error(txt)
650

  
651 631
                error_url = '../error/nagios_host_service_error' \
652 632
                        '?host=%s&service=%s' % (host, service)
653 633
                redirect(error_url)
654

  
655
        return result
634
        except nagiosproxy.NoNagiosServerConfigured:
635
            txt = _("No server has been configured to monitor \"%s\"") % host
636
            LOGGER.error(txt)
637
            error_url = '../error/nagios_host_error?host=%s' % host
638
            redirect(error_url)
639
        return res.read()
656 640

  
657 641
    @expose()
658 642
    def metroPage(self, host):
......
986 970
                ).scalar()
987 971
        return result
988 972

  
989
    def getNagiosServer(self, host=None):
990
        """
991
        Determination Serveur Nagios pour l hote courant
992
        (Server Nagios -> nom de l application associee = nagios)
993

  
994
        @param host : hôte
995
        @type host : C{str}
996

  
997
        @return: serveur Nagios
998
        @rtype: C{str}
999
        """
1000

  
1001
        result = DBSession.query(
1002
                    VigiloServer.name
1003
                ).filter(VigiloServer.idvigiloserver == \
1004
                    Ventilation.idvigiloserver
1005
                ).filter(Ventilation.idhost == Host.idhost
1006
                ).filter(Ventilation.idapp == Application.idapp
1007
                ).filter(Host.name == host
1008
                ).filter(Application.name == 'nagios'
1009
                ).scalar()
1010
        return result
1011

  

Also available in: Unified diff