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

Merge branch 't34153-detect-status-vhost-port' into 'master'

See merge request mediaserver/envsetup!68
parents fb15c4b8 9564a384
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""
'''
Criticality: Normal
Checks that the webserver is running.
"""
'''
from pathlib import Path
import re
import requests
import sys
......@@ -16,29 +17,39 @@ from utilities import logging as lg # noqa: E402
def main():
lg.log("Checking nginx status:")
lg.log('Checking nginx status:')
if not Path("/etc/nginx").exists():
lg.info("nginx dir does not exists, skip test")
exit(2)
stats_file = Path('/etc/nginx/sites-enabled/stats.conf')
if not stats_file.exists():
lg.info('The Nginx status vhost does not exist, skipping test.')
return 2
with open(stats_file, 'r') as fo:
content = fo.read()
listen_s = re.search(r'listen (\d+);', content)
if not listen_s:
lg.info('The Nginx status vhost has no listen directive, skipping test.')
return 2
port = int(listen_s.group(1))
try:
req = requests.get(
"http://127.0.0.1:1080/nginx_status",
proxies={"http": "", "https": ""},
'http://127.0.0.1:%s/nginx_status' % port,
proxies={'http': '', 'https': ''},
timeout=5,
)
if req.status_code != 200:
raise Exception("status code: {}".format(req.status_code))
if "Active connections" not in req.text:
raise Exception("invalid response from nginx status url")
raise Exception('Status code: %s.' % req.status_code)
if 'Active connections' not in req.text:
raise Exception('invalid response from nginx status url.')
except Exception as e:
lg.error(str(e))
exit(1)
return 1
lg.success("status code: {}".format(req.status_code))
exit(0)
lg.success('Status code: %s.' % req.status_code)
return 0
if __name__ == "__main__":
main()
if __name__ == '__main__':
rc = main()
sys.exit(rc)
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