Project

General

Profile

Revision e4b8d982

IDe4b8d982b0e4ee2beb944662f0b947c19e6db0e5
Parent 454df3f9
Child 00456667

Added by Francois POIROTTE over 14 years ago

Nettoyage dans les templates de VigiGraph.
Réintroduction du template classique de Vigilo (master.html) dans VigiGraph,
pour que la présentation de la page de login soit la même partout.
Déplacement de searchhostform vers un dossier spécifique pour les widgets.
Déplacement du proxy Nagios vers vigilo.turbogears (pour le réutiliser ailleurs que dans VigiGraph).

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

View differences:

vigigraph/controllers/nagiosproxy.py
1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4: 
3
"""Gestion Nagios par proxy"""
4

  
5
import urllib
6
import urllib2
7

  
8
class NagiosProxy(object):
9
    '''
10
    Proxy Nagios
11

  
12
    cf http://www.voidspace.org.uk/python/articles/urllib2_francais.shtml
13
    '''
14

  
15
    def __init__(self, url):
16
        '''Constructeur'''
17
        self._url = url
18

  
19
    #def _retrieve_content(self, url, values):
20
    def _retrieve_content(self, *args, **kwargs):
21
        '''
22
        Lecture de donnees Nagios à partir d une url et d un dictionnaire
23
        ce dictionnaire contient les arguments pour l url
24
        '''
25

  
26
        handle = None
27
        result = None
28

  
29
        if kwargs is not None:
30
            url = kwargs.get('url')
31
            values = kwargs.get('values')
32
            if url is not None and values is not None:
33
                data = urllib.urlencode(values)
34
                try:
35
                    handle = urllib2.urlopen(url, data)
36
                    result = handle.read()
37
                except urllib2.URLError:
38
                    raise
39
                finally:
40
                    if handle:
41
                        handle.close()
42

  
43
        return result
44

  
45

  
46
    def get_status(self, host):
47
        '''
48
        lecture status
49
     
50
        @param host : hôte
51
        @type host : C{str}
52
        @return : donnees Nagios
53
        @rtype: 
54
        '''
55

  
56
        values = {'host' : host,
57
                  'style' : 'detail',
58
                  'supNav' : 1}
59

  
60
        url = '%s/%s' % (self._url, 'status.cgi')
61
        return self._retrieve_content(url=url, values=values)
62

  
63

  
64
    def get_extinfo(self, host, service):
65
        '''
66
        lecture informations
67
     
68
        @param host : hôte
69
        @type host : C{str}
70
        @param service : service
71
        @type service : C{str}
72
        @return : donnees Nagios
73
        @rtype: 
74
        '''
75

  
76
        values = {'host' : host,
77
                  'service' : service,
78
                  'type' : 2,
79
                  'supNav' : 1}
80

  
81
        url = '%s/%s' % (self._url, 'extinfo.cgi')
82
        return self._retrieve_content(url=url, values=values)
vigigraph/controllers/rpc.py
4 4
import time
5 5
import urllib
6 6
import urllib2
7
import csv
8 7
import logging
9 8

  
10 9
from pylons.i18n import ugettext as _
......
14 13
from vigigraph.lib.base import BaseController
15 14

  
16 15
from vigilo.models.session import DBSession
17
from vigilo.models.tables import Service, LowLevelService, Host
16
from vigilo.models.tables import LowLevelService, Host
18 17
from vigilo.models.tables import SupItemGroup, GroupHierarchy
19 18
from vigilo.models.tables import PerfDataSource
20 19
from vigilo.models.tables import Graph, GraphGroup
......
26 25
from vigilo.models.functions import sql_escape_like
27 26
        
28 27
from vigilo.turbogears.rrdproxy import RRDProxy
28
from vigilo.turbogears.nagiosproxy import NagiosProxy
29 29

  
30
from nagiosproxy import NagiosProxy
31
from searchhostform import SearchHostForm
30
from vigigraph.widgets.searchhostform import SearchHostForm
32 31
from vigigraph.lib import graphs
33 32

  
34 33

  
......
115 114
                Host.name,
116 115
                Host.idhost,
117 116
            ).join(
118
                (SUPITEM_GROUP_TABLE, SUPITEM_GROUP_TABLE.c.idsupitem == Host.idhost),
119
                (SupItemGroup, SupItemGroup.idgroup == SUPITEM_GROUP_TABLE.c.idgroup),
117
                (SUPITEM_GROUP_TABLE, SUPITEM_GROUP_TABLE.c.idsupitem == \
118
                    Host.idhost),
119
                (SupItemGroup, SupItemGroup.idgroup == \
120
                    SUPITEM_GROUP_TABLE.c.idgroup),
120 121
            ).filter(SupItemGroup.idgroup == othergroupid
121 122
            ).order_by(
122 123
                Host.name.asc(),
......
541 542
                LOGGER.error(txt)
542 543
                error_url = '../error/nagios_host_error?host=%s'
543 544
                redirect(error_url % host)
545
        else:
546
            txt = _("No server has been configured to monitor \"%s\"") % host
547
            LOGGER.error(txt)
548
            error_url = '../error/nagios_host_error?host=%s' % host
549
            redirect(error_url)
550

  
544 551

  
545 552
        return result
546 553

  
......
800 807
        return dict(host=host, start=start, duration=duration, \
801 808
                    presets=self.presets, dhgs=dhgs)
802 809

  
803
    @expose ('singlegraph.html')
810
    @expose('singlegraph.html')
804 811
    def singleGraph(self, host, graph, start=None, duration=86400):
805 812
        """
806 813
        Affichage d un graphe associe a un hote et un graphe
......
841 848

  
842 849
        return dict(searchhostform=searchhostform)
843 850

  
844
    @expose ('searchhost.html')
851
    @expose('searchhost.html')
845 852
    def searchHost(self, query=None):
846 853
        """
847 854
        Affichage page pour hotes repondant au critere de recherche
vigigraph/tests/functional/test_nagiosproxy.py
12 12
from tg import config
13 13
from nose.tools import eq_
14 14

  
15
from vigigraph.controllers.nagiosproxy import NagiosProxy
15
from vigilo.turbogears.nagiosproxy import NagiosProxy
16 16

  
17 17
from vigilo.models.session import DBSession
18 18
from vigilo.models.tables import Host, Ventilation, VigiloServer, Application
vigigraph/widgets/__init__.py
1
# -*- coding: utf-8 -*-
2
"""Formulaires ToscaWidgets pour VigiGraph."""
3

  

Also available in: Unified diff