Revision b13dc642
Tests acces url sur server Nagios par lecture en BD donnees server
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2479 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigigraph/tests/functional/test_nagiosproxy.py | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import unittest |
10 | 10 |
|
11 |
import urllib |
|
12 |
import urllib2 |
|
13 |
import os |
|
14 |
from tg import config |
|
15 |
|
|
11 | 16 |
from vigigraph.controllers.nagiosproxy import NagiosProxy |
12 | 17 |
|
13 |
#from vigilo.common.conf import settings |
|
18 |
from vigilo.models.configure import DBSession |
|
19 |
from vigilo.models import Host, Ventilation, VigiloServer, Application |
|
20 |
|
|
21 |
from vigigraph.tests import TestController |
|
22 |
|
|
23 |
|
|
24 |
def create_Host(name): |
|
25 |
'''Creation Host''' |
|
26 |
h = DBSession.query(Host).filter(Host.name == name).first() |
|
27 |
if not h: |
|
28 |
h = Host(name=name, |
|
29 |
checkhostcmd=u'dummy', |
|
30 |
hosttpl=u'linux', |
|
31 |
mainip=u"127.0.0.1", |
|
32 |
snmpcommunity=u"public", |
|
33 |
snmpport=161, |
|
34 |
weight=0) |
|
35 |
DBSession.add(h) |
|
36 |
DBSession.flush() |
|
37 |
return h |
|
38 |
|
|
39 |
def create_Server(name, description): |
|
40 |
'''Creation Server''' |
|
41 |
s = DBSession.query(VigiloServer).filter(VigiloServer.name == name).first() |
|
42 |
if not s: |
|
43 |
s = VigiloServer(name=name, description=description) |
|
44 |
DBSession.add(s) |
|
45 |
DBSession.flush() |
|
46 |
return s |
|
47 |
|
|
48 |
def create_Application(name): |
|
49 |
'''Creation Application''' |
|
50 |
a = DBSession.query(Application).filter(Application.name == name).first() |
|
51 |
if not a: |
|
52 |
a = Application(name=name) |
|
53 |
DBSession.add(a) |
|
54 |
DBSession.flush() |
|
55 |
return a |
|
56 |
|
|
57 |
def create_Ventilation(host, server, application): |
|
58 |
v = None |
|
59 |
h = DBSession.query(Host).filter(Host.name == host).first() |
|
60 |
s = DBSession.query(VigiloServer).filter(VigiloServer.name == server).first() |
|
61 |
a = DBSession.query(Application).filter(Application.name == application).first() |
|
62 |
if h and s: |
|
63 |
v = Ventilation(idhost=h.idhost, idvigiloserver=s.idvigiloserver, idapp=a.idapp) |
|
64 |
DBSession.add(v) |
|
65 |
DBSession.flush() |
|
66 |
return v |
|
67 |
|
|
68 |
def getServer(host): |
|
69 |
'''Server''' |
|
70 |
|
|
71 |
server = None |
|
72 |
|
|
73 |
result = DBSession.query \ |
|
74 |
(VigiloServer.name) \ |
|
75 |
.filter(VigiloServer.idvigiloserver == Ventilation.idvigiloserver) \ |
|
76 |
.filter(Ventilation.idhost == Host.idhost) \ |
|
77 |
.filter(Ventilation.idapp == Application.idapp) \ |
|
78 |
.filter(Host.name == host) \ |
|
79 |
.filter(Application.name == u'nagios') \ |
|
80 |
.first() |
|
81 |
|
|
82 |
if result is not None: |
|
83 |
server = result[0] |
|
84 |
|
|
85 |
return server |
|
14 | 86 |
|
15 | 87 |
|
16 | 88 |
class NagiosProxy_without_nagios(NagiosProxy): |
... | ... | |
34 | 106 |
def __init__(self, *args, **kwargs): |
35 | 107 |
'''Constructeur''' |
36 | 108 |
super(TestNagiosProxy, self).__init__(*args, **kwargs) |
37 |
#self.url = settings.get('NAGIOS_URL') -> ne marche pas |
|
38 | 109 |
self.url = 'http://localhost/nagios/cgi-bin' |
39 | 110 |
|
40 | 111 |
def test_supPage(self): |
... | ... | |
73 | 144 |
assert(result != None) |
74 | 145 |
|
75 | 146 |
|
147 |
class TestNagiosProxy_bd(TestController): |
|
148 |
""" Test Gestion Valeur Nagios """ |
|
149 |
|
|
150 |
def setup(self): |
|
151 |
'''setup''' |
|
152 |
super(TestNagiosProxy_bd, self).setUp() |
|
153 |
|
|
154 |
# Host |
|
155 |
host = u'par.linux0' |
|
156 |
h = create_Host(host) |
|
157 |
|
|
158 |
# Serveurs Vigilo |
|
159 |
sv1 = create_Server(u'http://localhost', u'RRD+Nagios') |
|
160 |
|
|
161 |
# Applications Vigilo |
|
162 |
ap1 = create_Application(u'rrdgraph') |
|
163 |
ap2 = create_Application(u'nagios') |
|
164 |
|
|
165 |
# Ventilation |
|
166 |
if sv1 is not None and ap1 is not None: |
|
167 |
create_Ventilation(host, sv1.name, ap1.name) |
|
168 |
if sv1 is not None and ap2 is not None: |
|
169 |
create_Ventilation(host, sv1.name, ap2.name) |
|
170 |
|
|
171 |
def test_acces_url(self): |
|
172 |
'''fonction vérification acces url via proxy''' |
|
173 |
|
|
174 |
bresult = True |
|
175 |
|
|
176 |
host = u'par.linux0' |
|
177 |
|
|
178 |
values = {'host' : host, |
|
179 |
'style' : 'detail', |
|
180 |
'supNav' : 1} |
|
181 |
|
|
182 |
#url = 'http://localhost/nagios/cgi-bin' |
|
183 |
server = getServer(host) |
|
184 |
url_web_path = config.get('nagios_web_path') |
|
185 |
url = '%s%s' % (server, url_web_path) |
|
186 |
url = os.path.join(url, 'status.cgi') |
|
187 |
|
|
188 |
if url is not None and values is not None: |
|
189 |
data = urllib.urlencode(values) |
|
190 |
|
|
191 |
handle = urllib2.urlopen(url, data) |
|
192 |
bresult = (handle != None) |
|
193 |
|
|
194 |
if handle: |
|
195 |
handle.close() |
|
196 |
|
|
197 |
assert(bresult) |
|
198 |
|
|
199 |
|
|
76 | 200 |
if __name__ == "__main__": |
201 |
|
|
77 | 202 |
unittest.main() |
Also available in: Unified diff