check_opnsense_traffic_for_host: configurable timeout
check_scrutiny_disks: dont error on no data
This commit is contained in:
parent
9fe6e7586e
commit
b1d78df28c
|
@ -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
|
||||
|
||||
|
|
|
@ -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,13 +94,14 @@ 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():
|
||||
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():
|
||||
|
@ -108,6 +117,13 @@ def main(args):
|
|||
'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 = '<dt>' if args.html else ''
|
||||
dts = '</dt>' if args.html else ''
|
||||
|
@ -172,6 +188,7 @@ if __name__ == "__main__":
|
|||
parser.add_argument('--html', action='store_true', help='Print HTML.')
|
||||
parser.add_argument('--pretty-url', help='The pretty URL to link to when printing HTML.')
|
||||
parser.add_argument('--ignore-non-smart', action='store_true', help="Ignore any non-SMART devices and any devices that error when reading SMART.")
|
||||
parser.add_argument('--dont-warn-no-data', action='store_true', help="Don't warn if there is no data for a disk.")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.html and not args.pretty_url:
|
||||
|
|
Loading…
Reference in New Issue