forgot to update db lag

This commit is contained in:
Cyberes 2023-09-16 13:22:08 -06:00
parent 9b0a4fc9db
commit 9bd9ba93a7
2 changed files with 7 additions and 0 deletions

View File

@ -120,6 +120,11 @@ def main():
db_lag_MAX = 0.01 if not args.crit else args.crit # in seconds db_lag_MAX = 0.01 if not args.crit else args.crit # in seconds
try: try:
db_lag, null_present, raw_data = get_waiting_for_db(args.grafana_api_key, args.interval, args.range, args.grafana_server) db_lag, null_present, raw_data = get_waiting_for_db(args.grafana_api_key, args.interval, args.range, args.grafana_server)
if db_lag == None:
print(f"UNKNOWN: no data for DB lag")
sys.exit(nagios.UNKNOWN)
null_warn = f'Null data was present for this timeseries, value may be incorrect.\n{raw_data}' if null_present else '' null_warn = f'Null data was present for this timeseries, value may be incorrect.\n{raw_data}' if null_present else ''
if db_lag > db_lag_MAX: if db_lag > db_lag_MAX:
print(f"CRITICAL: DB lag is {db_lag} sec. {null_warn} |'db-lag'={db_lag}s;;;") print(f"CRITICAL: DB lag is {db_lag} sec. {null_warn} |'db-lag'={db_lag}s;;;")

View File

@ -279,6 +279,8 @@ def get_waiting_for_db(api_key, interval, data_range, endpoint):
'to': 'now', 'to': 'now',
} }
response = requests.post(f'{endpoint}/api/ds/query', headers={'Authorization': f'Bearer {api_key}'}, json=json_data, verify=False).json() response = requests.post(f'{endpoint}/api/ds/query', headers={'Authorization': f'Bearer {api_key}'}, json=json_data, verify=False).json()
if not len(response['results']['A']['frames']):
return None, None, None
raw_data = response['results']['A']['frames'][0]['data']['values'][1] raw_data = response['results']['A']['frames'][0]['data']['values'][1]
data = [] data = []
null_present = False null_present = False