check_graylog: option to ignore update notifications

This commit is contained in:
Cyberes 2023-07-25 10:22:55 -06:00
parent 452266481c
commit 3a5b765634
1 changed files with 17 additions and 8 deletions

View File

@ -40,6 +40,7 @@ def main():
parser.add_argument('--crit-mem', type=int, default=100, help='Percentage of JVM memory used for critical')
parser.add_argument('--insecure', action='store_false', help="Don't verify SSL")
parser.add_argument('--crit-notif', action='store_true', help='Return critical when there are notifications')
parser.add_argument('--ignore-update-notif', action='store_true', help='Ignore any update notifications')
parser.add_argument('--html', action='store_true', help='Print HTML')
parser.add_argument('--cluster-metrics', action='store_true',
help='Also gather cluster metrics and check for notifications')
@ -225,15 +226,23 @@ def main():
# Check for notifications
if args.cluster_metrics:
notifications = fetch_with_retry(f'{base_url}/api/system/notifications', headers=headers,
notifications_query = fetch_with_retry(f'{base_url}/api/system/notifications', headers=headers,
auth=(args.token, 'token'), verify=args.insecure).json()
if notifications['total'] > 0:
notif = "notifications" if notifications["total"] > 1 else "notification"
are = "are" if notifications["total"] > 1 else "is"
notifications = []
for notif in notifications_query['notifications']:
if notif['type'] == 'outdated_version' and not args.ignore_update_notif:
notifications.append(notif)
elif notif['type'] != 'outdated_version':
notifications.append(notif)
if len(notifications):
notif = "notifications" if len(notifications) else "notification"
are = "are" if len(notifications) else "is"
if args.html:
notif_str = f'<a href="{base_url}/system/overview" target="_blank">There {are} {notifications["total"]} {notif}.</a>'
notif_str = f'<a href="{base_url}/system/overview" target="_blank">There {are} {len(notifications)} {notif}.</a>'
else:
notif_str = f'There {are} {notifications["total"]} {notif}.'
notif_str = f'There {are} {len(notifications)} {notif}.'
else:
notif_str = 'No notifications'
@ -266,8 +275,8 @@ def main():
exit_code = max(nagios.STATE_OK, jvm_mem_usage_state, elasticsearch_exit_code, indexer_failures_exit)
if notifications['total'] > 0:
text_result += f' There {are} {notifications["total"]} {notif}!'
if len(notifications):
text_result += f' There {are} {len(notifications)} {notif}!'
if args.crit_notif:
exit_code = nagios.STATE_CRIT # force crit