Skip to content

Commit

Permalink
Add host_down_disable_service_checks config option
Browse files Browse the repository at this point in the history
Add option to *not* check services if their host is down.

references:
      - NagiosEnterprises/nagioscore@05e1dda
  • Loading branch information
sni committed Dec 10, 2018
1 parent 27e64c9 commit f021ca9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sample-config/naemon.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,16 @@ allow_empty_hostgroup_assignment=0

#check_workers=3


# DISABLE SERVICE CHECKS WHEN HOST DOWN
# This option will disable all service checks if the host is not in an UP state
#
# While desirable in some environments, enabling this value can distort report
# values as the expected quantity of checks will not have been performed

#host_down_disable_service_checks=0


# CIRCULAR DEPENDENCIES (EXPERIMENTAL)
# Allow for circular dependencies in naemon's host graph.
# Enabaling this will cause propagation the following to stop working:
Expand Down
13 changes: 13 additions & 0 deletions src/naemon/checks_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ static void handle_service_check_event(struct nm_event_execution_properties *evp
struct timeval tv;
struct timeval event_runtime;
int options = temp_service->check_options;
host *temp_host = NULL;

log_debug_info(DEBUGL_CHECKS, 0, "Service '%s' on host '%s' handle_service_check_event()...\n", temp_service->description, temp_service->host_name);

Expand Down Expand Up @@ -200,6 +201,18 @@ static void handle_service_check_event(struct nm_event_execution_properties *evp
return;
}

/* check if host is up - if not, do not perform check */
if(host_down_disable_service_checks) {
if((temp_host = temp_service->host_ptr) == NULL) {
log_debug_info(DEBUGL_CHECKS, 2, "Host pointer NULL in handle_service_check_event().\n");
return;
} else {
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");
return;
}
}
}
}

/* Otherwise, run the event */
Expand Down
2 changes: 2 additions & 0 deletions src/naemon/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ read_config_file(const char *main_config_file, nagios_macros *mac)
allow_empty_hostgroup_assignment = (atoi(value) > 0) ? TRUE : FALSE;
} else if (!strcmp(variable, "allow_circular_dependencies")) {
allow_circular_dependencies=atoi(value);
} else if(!strcmp(variable,"host_down_disable_service_checks")) {
host_down_disable_service_checks = strtoul(value, NULL, 0);
}
/* skip external data directives */
else if (strstr(input, "x") == input)
Expand Down
1 change: 1 addition & 0 deletions src/naemon/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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_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: 1 addition & 0 deletions src/naemon/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ extern unsigned long max_debug_file_size;

extern int allow_empty_hostgroup_assignment;
extern int allow_circular_dependencies;
extern int host_down_disable_service_checks;

extern time_t last_program_stop;
extern time_t event_start;
Expand Down
1 change: 1 addition & 0 deletions src/naemon/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ 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;

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

Expand Down

0 comments on commit f021ca9

Please sign in to comment.