Skip to content

Commit

Permalink
add external command to add log entries
Browse files Browse the repository at this point in the history
This generic LOG command can be used to add entries to the main logfile. It is
useful ex.: from a global notification handler to log the actual notified contacts.
  • Loading branch information
sni committed Sep 13, 2024
1 parent ec00e45 commit 3674648
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/naemon/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,10 @@ static int global_command_handler(const struct external_command *ext_command, ti
/* disabled */
return ERROR;

case CMD_LOG:
nm_log(NSLOG_EXT_CUSTOM, "%s", ext_command->raw_arguments);
return OK;

default:
nm_log(NSLOG_RUNTIME_ERROR, "Unknown global command ID %d", ext_command->id);
return ERROR;
Expand Down Expand Up @@ -3293,6 +3297,10 @@ void register_core_commands(void)
core_command = command_create("CHANGE_RETRY_HOST_CHECK_INTERVAL", host_command_handler,
"Changes the retry check interval for a particular host.", "host=host_name;timestamp=check_interval");
command_register(core_command, CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL);

core_command = command_create("LOG", global_command_handler,
"Adds custom entry to the default log file.", NULL);
command_register(core_command, CMD_LOG);
}

/******************************************************************/
Expand Down Expand Up @@ -3434,6 +3442,8 @@ int process_external_command(char *cmd, int mode, GError **error)
/* passive checks are logged in checks.c as well, as some my bypass external commands by getting dropped in checkresults dir */
if (log_passive_checks == TRUE)
nm_log(NSLOG_PASSIVE_CHECK, "%s", temp_buffer);
} else if (id == CMD_LOG) {
/* skip loging same message twice */
} else if (log_external_commands == TRUE) {
nm_log(NSLOG_EXTERNAL_COMMAND, "%s", temp_buffer);
}
Expand Down
2 changes: 2 additions & 0 deletions src/naemon/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ NAGIOS_END_DECL
#define CMD_ACKNOWLEDGE_HOST_PROBLEM_EXPIRE 173
#define CMD_ACKNOWLEDGE_SVC_PROBLEM_EXPIRE 174

#define CMD_LOG 175

/* custom command introduced in Nagios 3.x */
#define CMD_CUSTOM_COMMAND 999

Expand Down
1 change: 1 addition & 0 deletions src/naemon/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#define NSLOG_HOST_NOTIFICATION 524288
#define NSLOG_SERVICE_NOTIFICATION 1048576
#define NSLOG_EXT_CUSTOM 2097152

/***************** DEBUGGING LEVELS *******************/

Expand Down
4 changes: 2 additions & 2 deletions src/naemon/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,9 @@ int reset_variables(void)
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;
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 | NSLOG_EXT_CUSTOM;

syslog_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;
syslog_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 | NSLOG_EXT_CUSTOM;

service_check_timeout = DEFAULT_SERVICE_CHECK_TIMEOUT;
host_check_timeout = DEFAULT_HOST_CHECK_TIMEOUT;
Expand Down

0 comments on commit 3674648

Please sign in to comment.