From ec00e45f0b25dd179fe845161480e7657cc08356 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 12 Sep 2024 11:33:20 +0200 Subject: [PATCH] add log_global_notifications the global notification handler adds quite some noise to the log file, so make it possible to disable it. --- sample-config/naemon.cfg.in | 9 +++++++++ src/naemon/configuration.c | 11 +++++++++++ src/naemon/defaults.h | 1 + src/naemon/globals.h | 1 + src/naemon/notifications.c | 4 ++-- src/naemon/utils.c | 2 ++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/sample-config/naemon.cfg.in b/sample-config/naemon.cfg.in index 75d184dd..441a33f7 100644 --- a/sample-config/naemon.cfg.in +++ b/sample-config/naemon.cfg.in @@ -274,6 +274,15 @@ log_passive_checks=1 +# GLOBAL NOTIFICATIONS LOGGING OPTION +# If you don't want Naemon to log global notifications, set +# this value to 0. If they should be logged, set +# this value to 1. + +log_global_notifications=1 + + + # GLOBAL HOST AND SERVICE EVENT HANDLERS # These options allow you to specify a host and service event handler # command that is to be run for every host or service state change. diff --git a/src/naemon/configuration.c b/src/naemon/configuration.c index 8b8d8c61..af96451f 100644 --- a/src/naemon/configuration.c +++ b/src/naemon/configuration.c @@ -375,6 +375,17 @@ read_config_file(const char *main_config_file, nagios_macros *mac) log_current_states = (atoi(value) > 0) ? TRUE : FALSE; } + else if (!strcmp(variable, "log_global_notifications")) { + + if (strlen(value) != 1 || value[0] < '0' || value[0] > '1') { + nm_asprintf(&error_message, "Illegal value for log_global_notifications"); + error = TRUE; + break; + } + + log_global_notifications = (atoi(value) > 0) ? TRUE : FALSE; + } + else if (!strcmp(variable, "retain_state_information")) { if (strlen(value) != 1 || value[0] < '0' || value[0] > '1') { diff --git a/src/naemon/defaults.h b/src/naemon/defaults.h index 2bcb31f0..62dcb04d 100644 --- a/src/naemon/defaults.h +++ b/src/naemon/defaults.h @@ -47,6 +47,7 @@ #define DEFAULT_LOG_CURRENT_STATES 1 /* log current service and host states after rotating log */ #define DEFAULT_LOG_EXTERNAL_COMMANDS 1 /* log external commands */ #define DEFAULT_LOG_PASSIVE_CHECKS 1 /* log passive service checks */ +#define DEFAULT_log_global_notifications 1 /* log global notifications */ #define DEFAULT_DEBUG_LEVEL 0 /* don't log any debugging information */ #define DEFAULT_DEBUG_VERBOSITY 1 diff --git a/src/naemon/globals.h b/src/naemon/globals.h index dd160b0c..1b96e780 100644 --- a/src/naemon/globals.h +++ b/src/naemon/globals.h @@ -64,6 +64,7 @@ extern int log_host_retries; extern int log_event_handlers; extern int log_external_commands; extern int log_passive_checks; +extern int log_global_notifications; extern unsigned long logging_options; extern unsigned long syslog_options; diff --git a/src/naemon/notifications.c b/src/naemon/notifications.c index e00a7d39..cb06c15e 100644 --- a/src/naemon/notifications.c +++ b/src/naemon/notifications.c @@ -2308,7 +2308,7 @@ int run_global_service_notification_handler(nagios_macros *mac, service *svc, in log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Processed notification command: %s\n", processed_command); /* log the notification to program log file */ - if (log_notifications == TRUE) { + if (log_global_notifications == TRUE) { if (type != NOTIFICATION_NORMAL) { nm_asprintf(&temp_buffer, "SERVICE NOTIFICATION: %s;%s;%s;%s ($SERVICESTATE$);%s;$SERVICEOUTPUT$;$NOTIFICATIONAUTHOR$;$NOTIFICATIONCOMMENT$\n", "GLOBAL", svc->host_name, svc->description, notification_reason_name(type), command_name_ptr); } else { @@ -2401,7 +2401,7 @@ int run_global_host_notification_handler(nagios_macros *mac, host *hst, int type log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Processed notification command: %s\n", processed_command); /* log the notification to program log file */ - if (log_notifications == TRUE) { + if (log_global_notifications == TRUE) { if (type != NOTIFICATION_NORMAL) { nm_asprintf(&temp_buffer, "HOST NOTIFICATION: %s;%s;%s ($HOSTSTATE$);%s;$HOSTOUTPUT$;$NOTIFICATIONAUTHOR$;$NOTIFICATIONCOMMENT$\n", "GLOBAL", hst->name, notification_reason_name(type), command_name_ptr); } else { diff --git a/src/naemon/utils.c b/src/naemon/utils.c index dc12895f..3b984561 100644 --- a/src/naemon/utils.c +++ b/src/naemon/utils.c @@ -70,6 +70,7 @@ int log_host_retries = DEFAULT_LOG_HOST_RETRIES; int log_event_handlers = DEFAULT_LOG_EVENT_HANDLERS; int log_external_commands = DEFAULT_LOG_EXTERNAL_COMMANDS; int log_passive_checks = DEFAULT_LOG_PASSIVE_CHECKS; +int log_global_notifications = DEFAULT_log_global_notifications; unsigned long logging_options = 0; unsigned long syslog_options = 0; @@ -1080,6 +1081,7 @@ int reset_variables(void) log_event_handlers = DEFAULT_LOG_EVENT_HANDLERS; log_external_commands = DEFAULT_LOG_EXTERNAL_COMMANDS; log_passive_checks = DEFAULT_LOG_PASSIVE_CHECKS; + log_global_notifications = DEFAULT_log_global_notifications; logging_options = NSLOG_RUNTIME_ERROR | NSLOG_RUNTIME_WARNING | NSLOG_VERIFICATION_ERROR | NSLOG_VERIFICATION_WARNING | NSLOG_CONFIG_ERROR | NSLOG_CONFIG_WARNING | NSLOG_PROCESS_INFO | NSLOG_HOST_NOTIFICATION | NSLOG_SERVICE_NOTIFICATION | NSLOG_EVENT_HANDLER | NSLOG_EXTERNAL_COMMAND | NSLOG_PASSIVE_CHECK | NSLOG_HOST_UP | NSLOG_HOST_DOWN | NSLOG_HOST_UNREACHABLE | NSLOG_SERVICE_OK | NSLOG_SERVICE_WARNING | NSLOG_SERVICE_UNKNOWN | NSLOG_SERVICE_CRITICAL | NSLOG_INFO_MESSAGE;