Skip to content

Commit

Permalink
add log_global_notifications
Browse files Browse the repository at this point in the history
the global notification handler adds quite some noise to the log file, so
make it possible to disable it.
  • Loading branch information
sni committed Sep 13, 2024
1 parent f285220 commit ec00e45
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions sample-config/naemon.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions src/naemon/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions src/naemon/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/naemon/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/naemon/notifications.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/naemon/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit ec00e45

Please sign in to comment.