diff --git a/check_opnsense_traffic_for_host.py b/check_opnsense_traffic_for_host.py index d67bb30..51f2199 100755 --- a/check_opnsense_traffic_for_host.py +++ b/check_opnsense_traffic_for_host.py @@ -47,6 +47,7 @@ def main(): parser.add_argument('--bandwidth-warn', type=int, default=50, help='Warning if percent of bandwidth usage is greater than or equal to this.') parser.add_argument('--conn-critical', type=int, default=-1, help='Set critical level for number of connections. Default: -1 (disabled).') parser.add_argument('--conn-warn', type=int, default=-1, help='Set warning level for number of connections. Default: -1 (disabled).') + parser.add_argument('--timeout', type=int, default=10, help='Timeout in seconds for the HTTP requests to OPNsense. Default: 10.') args = parser.parse_args() check_result = {} @@ -57,7 +58,7 @@ def main(): # Map interface names to their internal names interfaces_mapping = requests.get(f'https://{args.opnsense}/api/diagnostics/traffic/interface', headers={'Accept': 'application/json'}, auth=(args.key, args.secret), - verify=False, timeout=10) + verify=False, timeout=args.timeout) if interfaces_mapping.status_code != 200: print( f'UNKNOWN: unable to query OPNsense API for interface mappings: {interfaces_mapping.status_code}\n{interfaces_mapping.text}') @@ -80,7 +81,7 @@ def main(): start_time = time.time() response = requests.get(f'https://{args.opnsense}/api/diagnostics/traffic/top/{interface}', headers={'Accept': 'application/json'}, auth=(args.key, args.secret), verify=False, - timeout=10) + timeout=args.timeout) end_time = time.time() api_request_time = end_time - start_time diff --git a/check_scrutiny_disks.py b/check_scrutiny_disks.py index 080f96f..8747bc0 100755 --- a/check_scrutiny_disks.py +++ b/check_scrutiny_disks.py @@ -61,7 +61,7 @@ def main(args): name = f'/dev/{smart_health["data"]["device"]["device_name"]} {wwn_id}' # differentiate disks in RAID arrays - disk_results = { + results[name] = { 'wwn_id': wwn_id, 'failed_attributes': [], } @@ -75,8 +75,16 @@ def main(args): if datetime.utcnow() - timedelta(hours=args.time_delta_limit) > last_updated: metics_out_of_date = True - if smart_health: - for attribute_id, values in smart_health['data']['smart_results'][0]['attrs'].items(): + if smart_health and len(smart_health['data']['smart_results']): + try: + disk_data = smart_health['data']['smart_results'][0]['attrs'] + except Exception as e: + print('UNKNOWN - failed to parse data:', e) + print('Key "data":', smart_health['data'].keys()) + print('Key "smart_results":', len(smart_health['data']['smart_results'])) + print('Key "attrs":', smart_health['data']['smart_results'][0].keys()) + sys.exit(nagios.UNKNOWN) + for attribute_id, values in disk_data.items(): if values['status'] == 0: continue # elif values['status'] == 2 and not args.warn_non_critical: @@ -86,28 +94,36 @@ def main(args): if 'observed_thresholds' in values['metadata'].keys(): del values['metadata']['observed_thresholds'] - disk_results['failed_attributes'].append(values) - - results[name] = disk_results + results[name]['failed_attributes'].append(values) + else: + results[name]['status'] = 'no data' crit_disks = {} warn_disks = {} for disk, values in results.items(): - for item in values['failed_attributes']: - if item['status'] == 2 and args.warn_non_critical: - if disk not in warn_disks.keys(): - warn_disks[disk] = [] - warn_disks[disk].append({ - 'raw_value': item['raw_value'], - 'display_name': item['metadata']['display_name'] - }) - if item['status'] == 4: - if disk not in crit_disks.keys(): - crit_disks[disk] = [] - crit_disks[disk].append({ - 'raw_value': item['raw_value'], - 'display_name': item['metadata']['display_name'] - }) + if values['status'] != 'no data': + for item in values['failed_attributes']: + if item['status'] == 2 and args.warn_non_critical: + if disk not in warn_disks.keys(): + warn_disks[disk] = [] + warn_disks[disk].append({ + 'raw_value': item['raw_value'], + 'display_name': item['metadata']['display_name'] + }) + if item['status'] == 4: + if disk not in crit_disks.keys(): + crit_disks[disk] = [] + crit_disks[disk].append({ + 'raw_value': item['raw_value'], + 'display_name': item['metadata']['display_name'] + }) + else: + if disk not in warn_disks.keys(): + warn_disks[disk] = [] + warn_disks[disk].append({ + 'raw_value': 'no data', + 'display_name': 'no data' + }) dt = '