|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +import os, sys, json, time, math |
| 4 | +import requests |
| 5 | + |
| 6 | +# settings |
| 7 | +url = "http://localhost:8080/CombineArchiveWeb/rest/v1/stats" |
| 8 | +secret = "1234" |
| 9 | +timeout = 0.02 |
| 10 | + |
| 11 | +# trying to establish connection |
| 12 | +try: |
| 13 | + req = requests.get(url, params=[("secret", secret)], timeout=timeout) |
| 14 | + stats = req.json() |
| 15 | +except requests.exceptions.ConnectionError as err: |
| 16 | + print( "Connection Error: {0}".format(err) ) |
| 17 | + sys.exit(2) |
| 18 | +except requests.exceptions.HTTPError as err: |
| 19 | + print( "HTTP Error: {0}".format(err) ) |
| 20 | + sys.exit(2) |
| 21 | +except requests.exceptions.Timeout as err: |
| 22 | + print( "Timeout of {1} exceeded: {0}".format(err, timeout) ) |
| 23 | + sys.exit(2) |
| 24 | +except requests.exceptions.TooManyRedirects as err: |
| 25 | + print( "Too many redirects while requesting stats: {0}".format(err) ) |
| 26 | + sys.exit(2) |
| 27 | +except ValueError as err: |
| 28 | + print( "Error decoding json: {0}".format(err) ) |
| 29 | + sys.exit(2) |
| 30 | +except: |
| 31 | + print( "Unknown exception: {0}".format(sys.exc_info()[0]) ) |
| 32 | + sys.exit(2) |
| 33 | + |
| 34 | +if 'maxStatsAge' and 'generated' in stats: |
| 35 | + now = int( time.time() ) * 1000 |
| 36 | + if math.fabs( now - int(stats['generated']) ) >= int(stats['maxStatsAge']) * 1000 : |
| 37 | + print( "Stats are too old. Is System running?" ) |
| 38 | + sys.exit(1) |
| 39 | + |
| 40 | +if 'totalSizeQuota' in stats: |
| 41 | + if stats['totalSizeQuota'] >= 0.90: |
| 42 | + print("Total quoata is about to exceed: {0}%".format(stats['totalSizeQuota']*100) ) |
| 43 | + sys.exit(1) |
| 44 | + elif stats['totalSizeQuota'] >= 0.99: |
| 45 | + print( "Total quota is exceeded: {0}%".format(stats['totalSizeQuota']*100) ) |
| 46 | + sys.exit(2) |
| 47 | + else: |
| 48 | + print("quota is ok: {0}% ".format(stats['totalSizeQuota']*100) ) |
| 49 | + sys.exit(0) |
| 50 | +else: |
| 51 | + sys.exit(0) |
| 52 | + |
| 53 | + |
| 54 | +# no normal ending |
| 55 | +print( "script terminated unexpected" ) |
| 56 | +sys.exit(2) |
0 commit comments