Skip to content

Commit

Permalink
add hint to plugin output if skip check applies
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Feb 17, 2020
1 parent 156a619 commit 6c76754
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
7 changes: 3 additions & 4 deletions sample-config/naemon.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -1048,9 +1048,9 @@ allow_empty_hostgroup_assignment=0

# SET SERVICE/HOST STATUS WHEN SERVICE CHECK SKIPPED
# These options will allow you to set the status of a service when its
# service check is skipped due to one of three reasons:
# 1) failed dependency check; 2) parent's status; 3) host not up
# Number 3 can only happen if 'host_down_disable_service_checks' above
# service check is skipped due to one of two reasons:
# 1) failed dependency check; 2) host not up
# Number 2 can only happen if 'host_down_disable_service_checks' above
# is set to 1.
# Valid values for the service* options are:
# -1 Do not change the service status (default)
Expand All @@ -1059,7 +1059,6 @@ allow_empty_hostgroup_assignment=0
# 2 Set the service status to STATE_CRITICAL
# 3 Set the service status to STATE_UNKNOWN
#service_skip_check_dependency_status=-1
#service_skip_check_parent_status=-1
#service_skip_check_host_down_status=-1

# The host_dependency_skip_check_status option will allow you to set the
Expand Down
10 changes: 8 additions & 2 deletions src/naemon/checks_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,14 @@ static int run_async_host_check(host *hst, int check_options, double latency)
/* check host dependencies for execution */
log_debug_info(DEBUGL_CHECKS, 0, "Host '%s' checking dependencies...\n", hst->name);
if (check_host_dependencies(hst, EXECUTION_DEPENDENCY) == DEPENDENCIES_FAILED) {
if (service_skip_check_dependency_status >= 0) {
hst->current_state = service_skip_check_dependency_status;
if (host_skip_check_dependency_status >= 0) {
hst->current_state = host_skip_check_dependency_status;
if(strstr(hst->plugin_output, "(host dependency check failed)") == NULL) {
char *old_output = nm_strdup(hst->plugin_output);
nm_free(hst->plugin_output);
nm_asprintf(&hst->plugin_output, "(host dependency check failed) was: %s", old_output);
nm_free(old_output);
}
}

log_debug_info(DEBUGL_CHECKS, 0, "Host '%s' failed dependency check. Aborting check\n", hst->name);
Expand Down
18 changes: 15 additions & 3 deletions src/naemon/checks_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,14 @@ static void handle_service_check_event(struct nm_event_execution_properties *evp
/* check service dependencies for execution */
log_debug_info(DEBUGL_CHECKS, 0, "Service '%s' on host '%s' checking dependencies...\n", temp_service->description, temp_service->host_name);
if (check_service_dependencies(temp_service, EXECUTION_DEPENDENCY) == DEPENDENCIES_FAILED) {
if (service_skip_check_parent_status >= 0) {
temp_service->current_state = service_skip_check_parent_status;
if (service_skip_check_dependency_status >= 0) {
temp_service->current_state = service_skip_check_dependency_status;
if(strstr(temp_service->plugin_output, "(service dependency check failed)") == NULL) {
char *old_output = nm_strdup(temp_service->plugin_output);
nm_free(temp_service->plugin_output);
nm_asprintf(&temp_service->plugin_output, "(service dependency check failed) was: %s", old_output);
nm_free(old_output);
}
}
log_debug_info(DEBUGL_CHECKS, 0, "Service '%s' on host '%s' failed dependency check. Aborting check\n", temp_service->description, temp_service->host_name);
return;
Expand All @@ -217,7 +223,13 @@ static void handle_service_check_event(struct nm_event_execution_properties *evp
if(temp_host->current_state != STATE_UP) {
log_debug_info(DEBUGL_CHECKS, 2, "Host state not UP, so service check will not be performed - will be rescheduled as normal.\n");
if (service_skip_check_host_down_status >= 0) {
temp_host->current_state = service_skip_check_host_down_status;
temp_service->current_state = service_skip_check_host_down_status;
if(strstr(temp_service->plugin_output, "(host is down)") == NULL) {
char *old_output = nm_strdup(temp_service->plugin_output);
nm_free(temp_service->plugin_output);
nm_asprintf(&temp_service->plugin_output, "(host is down) was: %s", old_output);
nm_free(old_output);
}
}
return;
}
Expand Down
7 changes: 0 additions & 7 deletions src/naemon/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,13 +1077,6 @@ read_config_file(const char *main_config_file, nagios_macros *mac)
error = TRUE;
break;
}
} else if(!strcmp(variable,"service_skip_check_parent_status")) {
service_skip_check_parent_status = atoi(value);
if (service_skip_check_parent_status < -1 || service_skip_check_parent_status > 3) {
nm_asprintf(&error_message, "Illegal value for service_skip_check_parent_status");
error = TRUE;
break;
}
} else if (!strcmp(variable,"service_skip_check_host_down_status")) {
service_skip_check_host_down_status = atoi(value);
if (service_skip_check_host_down_status < -1 || service_skip_check_host_down_status > 3) {
Expand Down
1 change: 1 addition & 0 deletions src/naemon/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#define DEFAULT_ALLOW_EMPTY_HOSTGROUP_ASSIGNMENT 2 /* Allow assigning to empty hostgroups by default, but warn about it */
#define DEFAULT_ALLOW_CIRCULAR_DEPENDENCIES 0 /* Allow circular depdendencies */
#define DEFAULT_HOST_DOWN_DISABLE_SERVICE_CHECKS 0 /* run service checks if the host is down */
#define DEFAULT_SKIP_CHECK_STATUS -1 /* do not change status by default */

#define DEFAULT_HOST_PERFDATA_FILE_TEMPLATE "[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$"
#define DEFAULT_SERVICE_PERFDATA_FILE_TEMPLATE "[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$"
Expand Down
1 change: 0 additions & 1 deletion src/naemon/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ extern int allow_empty_hostgroup_assignment;
extern int allow_circular_dependencies;
extern int host_down_disable_service_checks;
extern int service_skip_check_dependency_status;
extern int service_skip_check_parent_status;
extern int service_skip_check_host_down_status;
extern int host_skip_check_dependency_status;

Expand Down
7 changes: 3 additions & 4 deletions src/naemon/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ char *use_timezone = NULL;
int allow_empty_hostgroup_assignment = DEFAULT_ALLOW_EMPTY_HOSTGROUP_ASSIGNMENT;
int allow_circular_dependencies = DEFAULT_ALLOW_CIRCULAR_DEPENDENCIES;
int host_down_disable_service_checks = DEFAULT_HOST_DOWN_DISABLE_SERVICE_CHECKS;
int service_skip_check_dependency_status = -1;
int service_skip_check_parent_status = -1;
int service_skip_check_host_down_status = -1;
int host_skip_check_dependency_status = -1;
int service_skip_check_dependency_status = DEFAULT_SKIP_CHECK_STATUS;
int service_skip_check_host_down_status = DEFAULT_SKIP_CHECK_STATUS;
int host_skip_check_dependency_status = DEFAULT_SKIP_CHECK_STATUS;

static long long check_file_size(char *, unsigned long, struct rlimit);

Expand Down

0 comments on commit 6c76754

Please sign in to comment.