This commit is contained in:
Cyberes 2023-11-14 14:59:28 -07:00
parent 91f7dcbdd1
commit eb19567573
1 changed files with 6 additions and 5 deletions

View File

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