Вход:
./http_check www.xxx.com
Выход:
0 – Ок
1 – Warning
2 – Critical
#!/usr/bin/env python3 import urllib.request, urllib.error import sys url = sys.argv[1] try: conn = urllib.request.urlopen(url) except urllib.error.HTTPError as e: # Return code error (e.g. 404, 501, ...) # ... print('HTTPError: {}'.format(e.code)) exit(1) except urllib.error.URLError as e: # Not an HTTP-specific error (e.g. connection refused) # ... print('URLError: {}'.format(e.reason)) exit(2) else: # 200 # ... exit(0) |