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 #!/usr/bin/env python3
""" '''
Criticality: Normal Criticality: Normal
Checks that the webserver is running. Checks that the webserver is running.
""" '''
from pathlib import Path from pathlib import Path
import re
import requests import requests
import sys import sys
...@@ -16,29 +17,39 @@ from utilities import logging as lg # noqa: E402 ...@@ -16,29 +17,39 @@ from utilities import logging as lg # noqa: E402
def main(): def main():
lg.log("Checking nginx status:") lg.log('Checking nginx status:')
if not Path("/etc/nginx").exists(): stats_file = Path('/etc/nginx/sites-enabled/stats.conf')
lg.info("nginx dir does not exists, skip test") if not stats_file.exists():
exit(2) 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: try:
req = requests.get( req = requests.get(
"http://127.0.0.1:1080/nginx_status", 'http://127.0.0.1:%s/nginx_status' % port,
proxies={"http": "", "https": ""}, proxies={'http': '', 'https': ''},
timeout=5, timeout=5,
) )
if req.status_code != 200: if req.status_code != 200:
raise Exception("status code: {}".format(req.status_code)) raise Exception('Status code: %s.' % req.status_code)
if "Active connections" not in req.text: if 'Active connections' not in req.text:
raise Exception("invalid response from nginx status url") raise Exception('invalid response from nginx status url.')
except Exception as e: except Exception as e:
lg.error(str(e)) lg.error(str(e))
exit(1) return 1
lg.success("status code: {}".format(req.status_code)) lg.success('Status code: %s.' % req.status_code)
exit(0) return 0
if __name__ == "__main__": if __name__ == '__main__':
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