summaryrefslogtreecommitdiff
path: root/test/nagios
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-04-15 12:51:06 +0200
committerAzul <azul@leap.se>2014-04-17 10:39:59 +0200
commit44d2d031555c889b94e9738cb45740b16a4071ce (patch)
tree8bafaecff89b9c483fc3b019eeb7da0678d7fadf /test/nagios
parenta14f66c2642ff43c2cc497b0597bfb17d19a7139 (diff)
refactor reporting in webapp login nagios test
Diffstat (limited to 'test/nagios')
-rw-r--r--test/nagios/report.py19
-rwxr-xr-xtest/nagios/soledad_sync.py2
-rwxr-xr-xtest/nagios/webapp_login.py35
3 files changed, 32 insertions, 24 deletions
diff --git a/test/nagios/report.py b/test/nagios/report.py
new file mode 100644
index 0000000..d2720a5
--- /dev/null
+++ b/test/nagios/report.py
@@ -0,0 +1,19 @@
+system = 'undefined'
+
+def report(code, message):
+ codes = {0: 'OK', 1: 'WARNING', 2: 'CRITICAL', 3: 'UNKNOWN'}
+ print "%d %s - %s - %s" % \
+ (code, system, codes[code], message)
+ exit(code)
+
+def fail(message):
+ report(2, message)
+
+def warn(message):
+ report(1, message)
+
+def ok(message):
+ report(0, message)
+
+def unknown(message):
+ report(3, message)
diff --git a/test/nagios/soledad_sync.py b/test/nagios/soledad_sync.py
index faf552a..a3c2d5a 100755
--- a/test/nagios/soledad_sync.py
+++ b/test/nagios/soledad_sync.py
@@ -58,7 +58,7 @@ def get_soledad_info(config, tempdir):
# get soledad server url
service_url = 'https://%s:%d/%d/config/soledad-service.json' % \
(api['domain'], api['port'], api['version'])
- soledad_hosts = requests.get(service_url).json['hosts']
+ soledad_hosts = requests.get(service_url).json()['hosts']
host = soledad_hosts.keys()[0]
server_url = 'https://%s:%d/user-%s' % \
(soledad_hosts[host]['hostname'], soledad_hosts[host]['port'],
diff --git a/test/nagios/webapp_login.py b/test/nagios/webapp_login.py
index 86a4045..a7e3473 100755
--- a/test/nagios/webapp_login.py
+++ b/test/nagios/webapp_login.py
@@ -9,20 +9,21 @@ import random
import srp._pysrp as srp
import binascii
import yaml
-
+import report
safe_unhexlify = lambda x: binascii.unhexlify(x) if (
len(x) % 2 == 0) else binascii.unhexlify('0' + x)
+report.system = 'webapp login'
def read_config():
with open("/etc/leap/hiera.yaml", 'r') as stream:
config = yaml.load(stream)
user = config['webapp']['nagios_test_user']
if 'username' not in user:
- fail('nagios test user lacks username')
+ report.fail('nagios test user lacks username')
if 'password' not in user:
- fail('nagios test user lacks password')
+ report.fail('nagios test user lacks password')
api = config['api']
api['version'] = config['webapp']['api_version']
return {'api': api, 'user': user}
@@ -35,9 +36,13 @@ def run_tests(config):
try:
auth = authenticate(api, usr)
except requests.exceptions.ConnectionError:
- fail('no connection to server')
- exit(report(auth, usr))
-
+ report.fail('no connection to server')
+ if ('errors' in auth):
+ report.fail('srp password auth failed')
+ usr.verify_session(safe_unhexlify(auth["M2"]))
+ if usr.authenticated():
+ report.ok('can login to webapp fine')
+ report.warn('failed to verify webapp server')
def authenticate(api, usr):
api_url = "https://{domain}:{port}/{version}".format(**api)
@@ -50,28 +55,12 @@ def authenticate(api, usr):
response = session.post(api_url + '/sessions', data=params, verify=False)
init = response.json()
if ('errors' in init):
- fail('test user not found')
+ report.fail('test user not found')
M = usr.process_challenge(
safe_unhexlify(init['salt']), safe_unhexlify(init['B']))
response = session.put(api_url + '/sessions/' + uname, verify=False,
data={'client_auth': binascii.hexlify(M)})
return response.json()
-
-def report(auth, usr):
- if ('errors' in auth):
- fail('srp password auth failed')
- usr.verify_session(safe_unhexlify(auth["M2"]))
- if usr.authenticated():
- print '0 webapp_login - OK - can login to webapp fine'
- return 0
- print '1 webapp_login - WARNING - failed to verify webapp server'
- return 1
-
-
-def fail(reason):
- print '2 webapp_login - CRITICAL - ' + reason
- exit(2)
-
if __name__ == '__main__':
run_tests(read_config())