From fa618ad4282bbbbd35ee53dcd71fed599fec9e68 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:21:12 +0200 Subject: Adding upstream version 4.1.0. Signed-off-by: Daniel Baumann --- contrib/nrpe_check_control.c | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 contrib/nrpe_check_control.c (limited to 'contrib/nrpe_check_control.c') diff --git a/contrib/nrpe_check_control.c b/contrib/nrpe_check_control.c new file mode 100644 index 0000000..04fa9e0 --- /dev/null +++ b/contrib/nrpe_check_control.c @@ -0,0 +1,121 @@ +#include +#include +#include + +#define MAX_CHARS 1024 +#define SERVICE_COUNT 12 + +#define COMMAND_FILE "/usr/local/nagios/var/rw/nagios.cmd" +#define SERVICES_FILE "/usr/local/nagios/etc/services.cfg" + +int main(int argc, char *argv[]) +{ + char check_name[MAX_CHARS]; + char ent_type[MAX_CHARS]; + char input_buffer[MAX_CHARS]; + char host_name[MAX_CHARS]; + char service_name[MAX_CHARS]; + char state[MAX_CHARS]; + char state_type[MAX_CHARS]; + char temp_input[MAX_CHARS]; + char temp_string[MAX_CHARS]; + char test_host[MAX_CHARS]; + + char *temp_var; + + FILE *command_fp; + FILE *services_fp; + + int attempt; + int i; + + time_t current_time; + + strcpy(state,argv[1]); + strcpy(state_type,argv[2]); + attempt=atoi(argv[3]); + strcpy(host_name,argv[4]); + + if(strcmp(state,"OK") == 0) + { + services_fp=fopen(SERVICES_FILE,"r"); + command_fp=fopen(COMMAND_FILE,"a"); + while((fgets(input_buffer,MAX_CHARS-1,services_fp)) != NULL) + { + if(input_buffer[0]=='#' || input_buffer[0]=='\x0' || input_buffer[0]=='\n' || input_buffer[0]=='\r') + { + continue; + } + else + { + strcpy(temp_input,input_buffer); + strcpy(temp_string,strtok(temp_input,"=")); + strcpy(ent_type,strtok(temp_string,"[")); + if(strcmp(ent_type,"service") == 0) + { + strcpy(test_host,strtok(NULL,"]")); + if(strcmp(test_host,host_name) == 0) + { + temp_var=strtok(input_buffer,"="); + strcpy(service_name,strtok(NULL,";")); + for(i=1;i<=SERVICE_COUNT;i++) + { + temp_var=strtok(NULL,";"); + } + strcpy(check_name,strtok(temp_var,"!")); + if(strcmp(check_name,"check_nrpe") == 0) + { + time(¤t_time); + fprintf(command_fp,"[%lu] ENABLE_SVC_CHECK;%s;%s\n",current_time,host_name,service_name); + } + } + } + } + } + fclose(command_fp); + fclose(services_fp); + } + else if(strcmp(state,"CRITICAL") == 0) + { + if(attempt == 3) + { + services_fp=fopen(SERVICES_FILE,"r"); + command_fp=fopen(COMMAND_FILE,"a"); + while((fgets(input_buffer,MAX_CHARS-1,services_fp)) != NULL) + { + if(input_buffer[0]=='#' || input_buffer[0]=='\x0' || input_buffer[0]=='\n' || input_buffer[0]=='\r') + { + continue; + } + else + { + strcpy(temp_input,input_buffer); + strcpy(temp_string,strtok(temp_input,"=")); + strcpy(ent_type,strtok(temp_string,"[")); + if(strcmp(ent_type,"service") == 0) + { + strcpy(test_host,strtok(NULL,"]")); + if(strcmp(test_host,host_name) == 0) + { + temp_var=strtok(input_buffer,"="); + strcpy(service_name,strtok(NULL,";")); + for(i=1;i<=SERVICE_COUNT;i++) + { + temp_var=strtok(NULL,";"); + } + strcpy(check_name,strtok(temp_var,"!")); + if(strcmp(check_name,"check_nrpe") == 0) + { + time(¤t_time); + fprintf(command_fp,"[%lu] DISABLE_SVC_CHECK;%s;%s\n",current_time,host_name,service_name); + } + } + } + } + } + fclose(command_fp); + fclose(services_fp); + } + } + return 0; +} -- cgit v1.2.3