fix
This commit is contained in:
parent
91f7dcbdd1
commit
eb19567573
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
from ipaddress import ip_network
|
||||
|
||||
|
@ -80,12 +81,12 @@ def main():
|
|||
# Fetch the data
|
||||
traffic_data = []
|
||||
for _ in range(args.duration):
|
||||
# start_time = time.time()
|
||||
start_time = time.time()
|
||||
response = fetch_with_retry(f'https://{args.opnsense}/api/diagnostics/traffic/top/{interface}',
|
||||
headers={'Accept': 'application/json'}, auth=(args.key, args.secret), verify=False,
|
||||
timeout=args.timeout)
|
||||
# end_time = time.time()
|
||||
# api_request_time = end_time - start_time
|
||||
end_time = time.time()
|
||||
api_request_time = end_time - start_time
|
||||
|
||||
if isinstance(response.json(), list):
|
||||
print_icinga2_check_status(f'OPNsense returned wrong datatype:\n{response.text}', nagios.STATE_UNKNOWN)
|
||||
|
@ -95,8 +96,8 @@ def main():
|
|||
if item['address'] == args.host:
|
||||
traffic_data.append(item)
|
||||
|
||||
# adjusted_sleep_duration = max(1 - api_request_time, 0)
|
||||
# time.sleep(adjusted_sleep_duration)
|
||||
adjusted_sleep_duration = max(1 - api_request_time, 0)
|
||||
time.sleep(adjusted_sleep_duration)
|
||||
|
||||
if not len(traffic_data) and args.fail_empty:
|
||||
print_icinga2_check_status(f'interface or host not found in OPNsense API response. Raw response:\n{traffic_data}', nagios.STATE_UNKNOWN)
|
||||
|
|
Loading…
Reference in New Issue