From 3a5b765634495e950252c2af6dcacfa98a8ecd29 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Tue, 25 Jul 2023 10:22:55 -0600 Subject: [PATCH] check_graylog: option to ignore update notifications --- check_graylog.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/check_graylog.py b/check_graylog.py index 086122f..efe8138 100755 --- a/check_graylog.py +++ b/check_graylog.py @@ -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'There {are} {notifications["total"]} {notif}.' + notif_str = f'There {are} {len(notifications)} {notif}.' 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