check db null warn

This commit is contained in:
Cyberes 2023-04-21 23:54:17 -06:00
parent bafcf422b9
commit e5e4bba051
4 changed files with 28 additions and 11 deletions

View File

@ -104,15 +104,15 @@ def main():
print(traceback.format_exc())
sys.exit(nagios.UNKNOWN)
elif args.type == 'db-lag':
# in seconds
db_lag_MAX = 0.01 if not args.crit else args.crit
db_lag_MAX = 0.01 if not args.crit else args.crit # in seconds
try:
db_lag = get_waiting_for_db(args.grafana_api_key, args.interval, args.range, args.grafana_server)
db_lag, null_present = get_waiting_for_db(args.grafana_api_key, args.interval, args.range, args.grafana_server)
null_warn = 'Null data was present for this timeseries.' if null_present else ''
if db_lag > db_lag_MAX:
print(f"CRITICAL: DB lag is {db_lag} sec. |'db-lag'={db_lag}s;;;")
print(f"CRITICAL: DB lag is {db_lag} sec. {null_warn} |'db-lag'={db_lag}s;;;")
sys.exit(nagios.CRITICAL)
else:
print(f"OK: DB lag is {db_lag} sec. |'db-lag'={db_lag}s;;;")
print(f"OK: DB lag is {db_lag} sec. {null_warn} |'db-lag'={db_lag}s;;;")
sys.exit(nagios.OK)
except Exception as e:
print(f'UNKNOWN: failed to check DB lag "{e}"')

View File

@ -139,8 +139,8 @@ async def main() -> None:
# convert mxc:// to http://
target_file_url = await client.mxc_to_http(image_event.url)
# Check the headers. Ignore the non-async thing here, it doesn't
# matter in this situation.
# Check the file. Ignore the non-async thing here, it doesn't matter in this situation.
# Remember: Cloudflare does not cache non-GET requests.
r = requests.head(target_file_url, allow_redirects=False)
prints = []

View File

@ -1,5 +1,3 @@
import json
import numpy as np
import requests
from urllib3.exceptions import InsecureRequestWarning
@ -312,7 +310,13 @@ def get_waiting_for_db(api_key, interval, data_range, endpoint):
'to': 'now',
}
response = requests.post(f'{endpoint}/api/ds/query', headers={'Authorization': f'Bearer {api_key}'}, json=json_data, verify=False).json()
return np.round(np.average(response['results']['A']['frames'][0]['data']['values'][1]), 5)
data = response['results']['A']['frames'][0]['data']['values'][1]
null_present = False
for i in range(data):
if data[i] is None:
data[i] = -1
null_present = True
return np.round(np.average(data), 5), null_present
def get_stateres_worst_case(api_key, interval, data_range, endpoint):
@ -374,5 +378,4 @@ def get_stateres_worst_case(api_key, interval, data_range, endpoint):
}
response = requests.post(f'{endpoint}/api/ds/query', headers={'Authorization': f'Bearer {api_key}'}, json=json_data, verify=False).json()
# AVerage CPU time per block

14
icinga2kuma.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=Icinga to Kuma converter.
After=network.target
[Service]
User=flask
Environment="ICINGA2KUMA_ICINGA2_PW=[your icinga2 API password]"
WorkingDirectory=/opt/icinga2-checks
ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8081 -w 4 icinga2kuma:app
Restart=always
[Install]
WantedBy=multi-user.target