Skip to content
Snippets Groups Projects
Commit ceac16a7 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Test vhost IP in Nginx test (refs #20060).

parent f43ce37c
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' '''
Check the response status code of all enabled vhosts. This script checks for all enabled vhosts in Nginx conf that:
Allowed status code are: 403 and 200. * The response status code is 200 or 403.
Also check Wowza response for all mediaserver vhosts. * The host is resolved as 127.0.0.1.
* The Wowza response is correct on /streaming/ (only for mediaserver vhosts).
''' '''
import os import os
import re import re
import requests import requests
import socket
import sys import sys
...@@ -48,34 +50,39 @@ for name in os.listdir(nginx_dir): ...@@ -48,34 +50,39 @@ for name in os.listdir(nginx_dir):
found = True found = True
url = '%s://%s' % ('https' if https else 'http', domain) url = '%s://%s' % ('https' if https else 'http', domain)
sys.stdout.write('Testing url "%s": ' % url) sys.stdout.write('Testing url "%s": ' % url)
try: ip = socket.gethostbyname(domain)
req = requests.get(url, verify=False, proxies={'http': '', 'https': ''}, timeout=10) if ip != '127.0.0.1':
except Exception as e: sys.stdout.write('\033[91mKO (domain is not resolved with 127.0.0.1)\033[0m')
code = str(e)
else:
code = req.status_code
if code not in (200, 403):
sys.stdout.write('\033[91mKO (%s)\033[0m' % code)
errors += 1 errors += 1
else: else:
sys.stdout.write('\033[92mOK (%s)\033[0m' % code) try:
if 'mediaserver' in name and wowza_dir: req = requests.get(url, verify=False, proxies={'http': '', 'https': ''}, timeout=10)
# test /streaming url except Exception as e:
sys.stdout.write(', streaming: ') code = str(e)
try: else:
req = requests.get(url + '/streaming/', verify=False, proxies={'http': '', 'https': ''}, timeout=10) code = req.status_code
except Exception as e: if code not in (200, 403):
code = str(e) sys.stdout.write('\033[91mKO (%s)\033[0m' % code)
else: errors += 1
code = req.status_code else:
if code != 200: sys.stdout.write('\033[92mOK (%s)\033[0m' % code)
sys.stdout.write('\033[91mKO (%s)\033[0m' % code) if 'mediaserver' in name and wowza_dir:
errors += 1 # test /streaming url
elif 'Wowza Streaming Engine' not in req.text: sys.stdout.write(', streaming: ')
sys.stdout.write('\033[91mKO (%s, %s)\033[0m' % (code, req.text.replace('\n', ' ')[:200])) try:
errors += 1 req = requests.get(url + '/streaming/', verify=False, proxies={'http': '', 'https': ''}, timeout=10)
else: except Exception as e:
sys.stdout.write('\033[92mOK (%s)\033[0m' % code) code = str(e)
else:
code = req.status_code
if code != 200:
sys.stdout.write('\033[91mKO (%s)\033[0m' % code)
errors += 1
elif 'Wowza Streaming Engine' not in req.text:
sys.stdout.write('\033[91mKO (%s, %s)\033[0m' % (code, req.text.replace('\n', ' ')[:200]))
errors += 1
else:
sys.stdout.write('\033[92mOK (%s)\033[0m' % code)
sys.stdout.write('.\n') sys.stdout.write('.\n')
if errors: if errors:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment