Skip to content
Snippets Groups Projects
Verified Commit a59ad160 authored by Nicolas KAROLAK's avatar Nicolas KAROLAK
Browse files

update output format

parent fa7723d1
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,11 @@ try:
except ImportError:
requests.packages.urllib3.disable_warnings()
sys.path.append(str(Path(__file__).parents[1].resolve()))
# pylint: disable=wrong-import-position
from envsetup import utils as u # noqa: E402
"""
This script checks for all enabled vhosts in Nginx conf that:
* The response status code is 200, 401 or 403.
......@@ -85,19 +90,14 @@ def test_vhost(
):
errors = 0
warnings = 0
name = nginx_file.stem
name = nginx_file.name
for port, proto in ports_info or [(80, False)]:
for domain in domains or ["localhost"]:
url = "%s://%s:%s" % (proto, domain, port)
sys.stdout.write('Testing url "%s" from %s:\n' % (url, name))
u.info("testing url '%s' from %s" % (url, name))
if name.startswith("mediaserver") and not tested:
if not celerity_conf or not re.search(
r"http[s]{0,1}://%s" % domain, celerity_conf
):
sys.stdout.write(
'\033[93mWarning:\033[0m Url "%s" not found in celerity conf; it should also be set in the MediaWorker.\n'
% url
)
if not re.search(r"https?://%s" % domain, celerity_conf):
u.warning("url '%s' not found in celerity conf" % url)
warnings += 1
# test domain IP
ip_error = None
......@@ -105,27 +105,25 @@ def test_vhost(
try:
ip = socket.gethostbyname(domain)
except Exception as e:
ip_error = "domain is not resolved: %s" % e
ip_error = "domain: not resolved %s" % e
else:
if ip != "127.0.0.1":
ip_warning = "domain is resolved with %s instead of 127.0.0.1" % ip
sys.stdout.write(" IP: ")
ip_warning = "domain: resolve to %s instead of 127.0.0.1" % ip
if ip_error:
if resolution_ignored and domain in resolution_ignored:
sys.stdout.write("\033[94mIgnored (%s)\033[0m" % ip_error)
u.info("%s (ignored)" % ip_error)
ip_error = None
else:
sys.stdout.write("\033[91mKO (%s)\033[0m" % ip_error)
u.error(ip_error)
elif ip_warning:
if resolution_ignored and domain in resolution_ignored:
sys.stdout.write("\033[94mIgnored (%s)\033[0m" % ip_warning)
u.info("%s (ignored)" % ip_warning)
ip_warning = None
else:
sys.stdout.write("\033[93mWarning (%s)\033[0m" % ip_warning)
u.warning(ip_warning)
else:
sys.stdout.write("\033[92mOK (127.0.0.1)\033[0m")
u.success("domain: resolve to 127.0.0.1")
# test url
sys.stdout.write(", status: ")
req_error = False
try:
req = requests.get(
......@@ -143,17 +141,16 @@ def test_vhost(
or domain == "localhost"
and code not in (200, 401, 403, 404)
):
sys.stdout.write("\033[91mKO (%s, %sms)\033[0m" % (code, req_time))
u.error("status: %s, %sms" % (code, req_time))
req_error = True
else:
if req_time > 10000:
sys.stdout.write("\033[93mOK (%s, %sms)\033[0m" % (code, req_time))
u.warning("status: %s, %sms" % (code, req_time))
warnings += 1
else:
sys.stdout.write("\033[92mOK (%s, %sms)\033[0m" % (code, req_time))
u.success("status: %s, %sms" % (code, req_time))
if "mediaserver" in name and wowza_dir:
# test /streaming url
sys.stdout.write(", streaming: ")
try:
req = requests.get(
url + "/streaming/",
......@@ -168,19 +165,13 @@ def test_vhost(
else:
code = req.status_code
if code != 200:
sys.stdout.write(
"\033[91mKO (%s, %sms)\033[0m" % (code, req_time)
)
u.error("streaming: %s, %sms" % (code, req_time))
req_error = True
elif req_time > 10000:
sys.stdout.write(
"\033[93mOK (%s, %sms)\033[0m" % (code, req_time)
)
u.warning("streaming: %s, %sms" % (code, req_time))
warnings += 1
else:
sys.stdout.write(
"\033[92mOK (%s, %sms)\033[0m" % (code, req_time)
)
sys.stdout.write(".\n")
u.success("streaming: %s, %sms" % (code, req_time))
tested += 1
if ip_warning:
......@@ -192,21 +183,20 @@ def test_vhost(
def main():
print("Check that nginx vhosts are well configured:")
# check that Nginx dir exists
nginx_dir = "/etc/nginx/sites-enabled"
if not os.path.exists(nginx_dir):
print('Nginx dir does not exists ("%s").' % nginx_dir)
u.error("nginx dir does not exists ('%s')." % nginx_dir)
sys.exit(2)
# check that Wowza is installed
wowza_dir = "/usr/local/WowzaStreamingEngine"
if not os.path.exists(wowza_dir):
print('Info: Wowza is not installed ("%s" does not exist).' % wowza_dir)
u.info("wowza is not installed ('%s' does not exist)." % wowza_dir)
wowza_dir = None
else:
print(
"Info: Wowza is installed, /streaming/ will be tested on mediaserver vhosts."
)
u.info("wowza is installed, /streaming/ will be tested on mediaserver vhosts.")
# get envsetup conf
conf = dict()
......@@ -246,12 +236,11 @@ def main():
errors += e
if errors:
print("%s url(s) did not correctly respond." % errors)
sys.exit(1)
elif warnings:
sys.exit(3)
if not tested:
print("No url found in Nginx sites-enabled dir.")
u.error("no url found in nginx sites-enabled dir")
sys.exit(1)
......
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