[Nagios-checkins] CVS: nagios/base broker.c,NONE,1.1 broker.h,NONE,1.1 events.c,NONE,1.1 Makefile.in
Nagios network monitoring software is enterprise server monitoring
Brought to you by:
egalstad,
sawolf-nagios
From: Ethan G. <ega...@us...> - 2002-12-17 03:30:00
|
Update of /cvsroot/nagios/nagios/base In directory sc8-pr-cvs1:/tmp/cvs-serv1029/base Modified Files: Makefile.in checks.c commands.c config.c logging.c nagios.c nagios.h.in sehandlers.c sretention.c utils.c Added Files: broker.c broker.h events.c Log Message: Start of event broker code, misc changes --- NEW FILE --- /***************************************************************************** * * BROKER.C - Event broker routines for Nagios * * Copyright (c) 2002 Ethan Galstad (na...@na...) * Last Modified: 12-15-2002 * * License: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *****************************************************************************/ #include "../common/config.h" #include "../common/common.h" #include "nagios.h" #include "broker.h" extern circular_buffer event_broker_buffer; extern char *event_broker_file; extern int event_broker_options; int event_broker_fd=-1; int broker_file_open; /******************************************************************/ /************************* EVENT FUNCTIONS ************************/ /******************************************************************/ /* sends data to the event broker worker thread */ int send_event_data_to_broker(char *data){ if(event_broker_options==BROKER_NOTHING) return OK; /* bail if we weren't given data */ if(data==NULL) return ERROR; /* bail if the buffer is unallocated */ if(event_broker_buffer.buffer==NULL) return ERROR; /* obtain a lock for writing to the buffer */ pthread_mutex_lock(&event_broker_buffer.buffer_lock); /* save the data to the buffer - older data is overwritten if the buffer is full */ ((char **)event_broker_buffer.buffer)[event_broker_buffer.tail]=strdup(data); /* increment the index counters and number of items */ event_broker_buffer.tail=(event_broker_buffer.tail + 1) % EVENT_BUFFER_SLOTS; if(event_broker_buffer.items<EVENT_BUFFER_SLOTS) event_broker_buffer.items++; else event_broker_buffer.head=(event_broker_buffer.head + 1) % EVENT_BUFFER_SLOTS; /* unlock the buffer */ pthread_mutex_unlock(&event_broker_buffer.buffer_lock); return OK; } /* sends program data (starts, restarts, stops, etc.) to broker */ void broker_program_state(int type, int flags, int attr, struct timeb *timestamp){ char temp_buffer[MAX_INPUT_BUFFER]; struct timeb tb; if(!(event_broker_options & BROKER_PROGRAM_STATE)) return; if(timestamp==NULL) ftime(&tb); else tb=*timestamp; snprintf(temp_buffer,sizeof(temp_buffer)-1,"[%lu.%d] %d;%d;%d;%d\n",(unsigned long)tb.time,tb.millitm,type,flags,attr,(int)getpid()); temp_buffer[sizeof(temp_buffer)-1]='\x0'; send_event_data_to_broker(temp_buffer); return; } /* send timed event data to broker */ void broker_timed_event(int type, int flags, int attr, timed_event *event, void *data, struct timeb *timestamp){ char temp_buffer[MAX_INPUT_BUFFER]; struct timeb tb; service *temp_service; if(!(event_broker_options & BROKER_TIMED_EVENTS)) return; if(timestamp==NULL) ftime(&tb); else tb=*timestamp; switch(type){ case NEBTYPE_TIMEDEVENT_SLEEP: snprintf(temp_buffer,sizeof(temp_buffer)-1,"[%lu.%d] %d;%d;%d;%lf\n",(unsigned long)tb.time,tb.millitm,type,flags,attr,*((double *)data)); break; default: if(event==NULL) snprintf(temp_buffer,sizeof(temp_buffer)-1,"[%lu.%d] %d;%d;%d;\n",(unsigned long)tb.time,tb.millitm,type,flags,attr); else if(event->event_type==EVENT_SERVICE_CHECK){ temp_service=(service *)event->event_data; snprintf(temp_buffer,sizeof(temp_buffer)-1,"[%lu.%d] %d;%d;%d;%d;%lu;%s;%s;\n",(unsigned long)tb.time,tb.millitm,type,flags,attr,event->event_type,event->run_time,temp_service->host_name,temp_service->description); } else snprintf(temp_buffer,sizeof(temp_buffer)-1,"[%lu.%d] %d;%d;%d;%d;%lu;\n",(unsigned long)tb.time,tb.millitm,type,flags,attr,event->event_type,event->run_time); break; } temp_buffer[sizeof(temp_buffer)-1]='\x0'; send_event_data_to_broker(temp_buffer); return; } /* send log data to broker */ void broker_logged_data(int type, int flags, int attr, char *data, unsigned long data_type, struct timeb *timestamp){ char temp_buffer[MAX_INPUT_BUFFER]; struct timeb tb; service *temp_service; if(!(event_broker_options & BROKER_LOGGED_DATA)) return; if(timestamp==NULL) ftime(&tb); else tb=*timestamp; strip(data); snprintf(temp_buffer,sizeof(temp_buffer)-1,"[%lu.%d] %d;%d;%d;%lu;%s\n",(unsigned long)tb.time,tb.millitm,type,flags,attr,data_type,data); temp_buffer[sizeof(temp_buffer)-1]='\x0'; send_event_data_to_broker(temp_buffer); return; } /******************************************************************/ /************************ THREAD FUNCTIONS ************************/ /******************************************************************/ /* event broker thread - passed event data to external daemon */ void * event_broker_worker_thread(void *arg){ char temp_buffer[MAX_INPUT_BUFFER]; struct timeval tv; struct timeb tb; sigset_t newmask; int write_result; int x; /* this thread should block all signals */ sigfillset(&newmask); pthread_sigmask(SIG_BLOCK,&newmask,NULL); /* specify cleanup routine */ pthread_cleanup_push(cleanup_event_broker_worker_thread,NULL); /* set cancellation info */ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL); broker_file_open=FALSE; event_broker_fd=-1; while(1){ /* open the event broker file for writing (non-blocked) */ if(event_broker_fd<0){ event_broker_fd=open(event_broker_file,O_WRONLY | O_NONBLOCK | O_APPEND,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /*event_broker_fd=open(event_broker_file,O_WRONLY | O_NONBLOCK | O_CREAT,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);*/ /* wait a while if we couldn't open the file */ if(event_broker_fd<0){ for(x=0;x<10;x++){ /* should we shutdown? */ pthread_testcancel(); /* wait a bit */ tv.tv_sec=0; tv.tv_usec=500000; select(0,NULL,NULL,NULL,&tv); } continue; } } /* should we shutdown? */ pthread_testcancel(); /* wait a bit */ tv.tv_sec=0; tv.tv_usec=500000; select(0,NULL,NULL,NULL,&tv); /* should we shutdown? */ pthread_testcancel(); /* broker file was just opened - say hello... */ if(broker_file_open==FALSE){ ftime(&tb); snprintf(temp_buffer,sizeof(temp_buffer)-1,"[%lu.%d] %d;%d;%d;%s\n",(unsigned long)tb.time,tb.millitm,NEBTYPE_HELLO,NEBFLAG_NONE,NEBATTR_NONE,PROGRAM_VERSION); temp_buffer[sizeof(temp_buffer)-1]='\x0'; write(event_broker_fd,temp_buffer,strlen(temp_buffer)); broker_file_open=TRUE; } /* obtain a lock for reading from the buffer */ pthread_mutex_lock(&event_broker_buffer.buffer_lock); /* process all data in the buffer */ if(event_broker_buffer.items>0){ /* write the data to the event broker file */ while(1){ write_result=write(event_broker_fd,((char **)event_broker_buffer.buffer)[event_broker_buffer.head],strlen(((char **)event_broker_buffer.buffer)[event_broker_buffer.head])); if(write_result==-1){ if(errno!=EINTR && errno!=EAGAIN) break; } else break; /* should we shutdown? */ pthread_testcancel(); } /* free buffer data */ free(((char **)event_broker_buffer.buffer)[event_broker_buffer.head]); /* update the head counter and items */ event_broker_buffer.head=(event_broker_buffer.head + 1) % EVENT_BUFFER_SLOTS; event_broker_buffer.items--; /* should we shutdown? */ pthread_testcancel(); } /* release lock on buffer */ pthread_mutex_unlock(&event_broker_buffer.buffer_lock); } /* removes cleanup handler */ pthread_cleanup_pop(0); return NULL; } /* clean up resources used by event broker worker thread */ void * cleanup_event_broker_worker_thread(void *arg){ char temp_buffer[MAX_INPUT_BUFFER]; struct timeb tb; int x; /* lock the buffer */ pthread_mutex_lock(&event_broker_buffer.buffer_lock); /* flush remaining data in the buffer */ while(event_broker_buffer.items>0){ write(event_broker_fd,((char **)event_broker_buffer.buffer)[event_broker_buffer.head],strlen(((char **)event_broker_buffer.buffer)[event_broker_buffer.head])); /* free buffer data */ free(((char **)event_broker_buffer.buffer)[event_broker_buffer.head]); /* update the head counter and items */ event_broker_buffer.head=(event_broker_buffer.head + 1) % EVENT_BUFFER_SLOTS; event_broker_buffer.items--; } /* release memory allocated to circular buffer */ for(x=event_broker_buffer.head;x!=event_broker_buffer.tail;x=(x+1) % EVENT_BUFFER_SLOTS) free(((char **)event_broker_buffer.buffer)[x]); free(event_broker_buffer.buffer); event_broker_buffer.buffer=NULL; /* release lock on buffer */ pthread_mutex_unlock(&event_broker_buffer.buffer_lock); /* say goodbye */ ftime(&tb); snprintf(temp_buffer,sizeof(temp_buffer)-1,"[%lu.%d] %d;%d;%d;%s\n",(unsigned long)tb.time,tb.millitm,NEBTYPE_GOODBYE,NEBFLAG_NONE,NEBATTR_NONE,PROGRAM_VERSION); temp_buffer[sizeof(temp_buffer)-1]='\x0'; write(event_broker_fd,temp_buffer,strlen(temp_buffer)); /* close file */ fsync(event_broker_fd); close(event_broker_fd); return NULL; } --- NEW FILE --- /***************************************************************************** * * BROKER.H - Event broker includes for Nagios * * Copyright (c) 2002 Ethan Galstad (na...@na...) * Last Modified: 12-15-2002 * * License: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *****************************************************************************/ #ifndef _BROKER_H #define _BROKER_H /****** EVENT TYPES ************************/ #define NEBTYPE_HELLO 1 #define NEBTYPE_GOODBYE 2 #define NEBTYPE_PROCESS_START 3 #define NEBTYPE_PROCESS_DAEMON 4 #define NEBTYPE_PROCESS_RESTART 5 #define NEBTYPE_PROCESS_SHUTDOWN 6 #define NEBTYPE_TIMEDEVENT_ADD 7 #define NEBTYPE_TIMEDEVENT_REMOVE 8 #define NEBTYPE_TIMEDEVENT_EXECUTE 9 #define NEBTYPE_TIMEDEVENT_DELAY 10 #define NEBTYPE_TIMEDEVENT_SKIP 11 #define NEBTYPE_TIMEDEVENT_SLEEP 12 #define NEBTYPE_LOGDATA 13 #define NEBTYPE_NOTIFICATION_HOST 14 #define NEBTYPE_NOTIFICATION_SERVICE 15 #define NEBTYPE_NOTIFICATION_HOST_CONTACT 16 #define NEBTYPE_NOTIFICATION_SERVICE_CONTACT 17 /****** EVENT FLAGS ************************/ #define NEBFLAG_NONE 0 #define NEBFLAG_PROCESS_INITIATED 1 /* event was initiated by Nagios process */ #define NEBFLAG_USER_INITIATED 2 /* event was initiated by a user request */ /****** EVENT ATTRIBUTES *******************/ #define NEBATTR_NONE 0 #define NEBATTR_SHUTDOWN_NORMAL 1 #define NEBATTR_SHUTDOWN_ABNORMAL 2 #define NEBATTR_RESTART_NORMAL 3 #define NEBATTR_RESTART_ABNORMAL 4 #endif --- NEW FILE --- /***************************************************************************** * * EVENTS.C - Timed event functions for Nagios * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) * Last Modified: 12-15-2002 * * License: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * [...1089 lines suppressed...] /* we can't precede the UNIX epoch */ if(time_difference>(unsigned long)program_start) program_start=(time_t)0; else program_start=(time_t)(program_start-(time_t)time_difference); } /* we moved into the future... */ else program_start=(time_t)(program_start+(time_t)time_difference); /* update status data */ update_program_status(FALSE); #ifdef DEBUG0 printf("compensate_for_system_time_change() end\n"); #endif return; } Index: Makefile.in =================================================================== RCS file: /cvsroot/nagios/nagios/base/Makefile.in,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** Makefile.in 9 Dec 2002 05:15:33 -0000 1.6 --- Makefile.in 17 Dec 2002 03:29:57 -0000 1.7 *************** *** 2,6 **** # Makefile for Nagios # ! # Last Modified: 12-07-2002 ############################ --- 2,6 ---- # Makefile for Nagios # ! # Last Modified: 12-13-2002 ############################ *************** *** 87,91 **** ! OBJS=checks.o config.o commands.o flapping.o logging.o notifications.o sehandlers.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O) nagios: nagios.c $(OBJS) nagios.h $(SRC_COMMON)/locations.h --- 87,91 ---- ! OBJS=broker.o checks.o config.o commands.o events.o flapping.o logging.o notifications.o sehandlers.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O) nagios: nagios.c $(OBJS) nagios.h $(SRC_COMMON)/locations.h Index: checks.c =================================================================== RCS file: /cvsroot/nagios/nagios/base/checks.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -r1.18 -r1.19 *** checks.c 11 Dec 2002 00:32:34 -0000 1.18 --- checks.c 17 Dec 2002 03:29:57 -0000 1.19 *************** *** 4,8 **** * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 12-09-2002 * * License: --- 4,8 ---- * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 12-13-2002 * * License: *************** *** 843,849 **** temp_service->state_type=HARD_STATE; - /* update service state times and last state change time */ - update_service_state_times(temp_service); - /* log the service recovery */ log_service_event(temp_service,HARD_STATE); --- 843,846 ---- *************** *** 863,869 **** temp_service->state_type=SOFT_STATE; - /* update service state times and last state change time */ - update_service_state_times(temp_service); - /* log the soft recovery */ log_service_event(temp_service,SOFT_STATE); --- 860,863 ---- *************** *** 955,962 **** hard_state_change=TRUE; - /* update service state times if necessary and last state change time */ - if(hard_state_change==TRUE) - update_service_state_times(temp_service); - /* put service into a hard state without attempting check retries and don't send out notifications about it */ temp_service->host_problem_at_last_check=TRUE; --- 949,952 ---- *************** *** 1024,1031 **** temp_service->state_type=SOFT_STATE; - /* update service state times if necessary and last state change time */ - if(state_change==TRUE) - update_service_state_times(temp_service); - /* log the service check retry */ log_service_event(temp_service,SOFT_STATE); --- 1014,1017 ---- *************** *** 1060,1066 **** /* if we've hard a hard state change... */ if(hard_state_change==TRUE){ - - /* update service state times and last state change time */ - update_service_state_times(temp_service); /* log the service problem (even if host is not up, which is new in 0.0.5) */ --- 1046,1049 ---- Index: commands.c =================================================================== RCS file: /cvsroot/nagios/nagios/base/commands.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** commands.c 11 Dec 2002 00:32:35 -0000 1.11 --- commands.c 17 Dec 2002 03:29:57 -0000 1.12 *************** *** 1040,1046 **** int cmd_enable_disable_notifications(int cmd, char *args){ - timed_event *new_event=NULL; - time_t scheduled_time; - char *temp_ptr; #ifdef DEBUG0 --- 1040,1043 ---- *************** *** 1048,1080 **** #endif ! /* get the time to schedule the event */ ! temp_ptr=my_strtok(args,"\n"); ! if(temp_ptr==NULL) ! scheduled_time=0L; ! else ! scheduled_time=strtoul(temp_ptr,NULL,10); ! ! /* no need to schedule a future change, just do it now */ ! if(scheduled_time==0L){ ! if(cmd==CMD_ENABLE_NOTIFICATIONS) ! enable_all_notifications(); ! else ! disable_all_notifications(); ! } ! /* else add a scheduled notification change */ ! else{ ! ! new_event=malloc(sizeof(timed_event)); ! if(new_event!=NULL){ ! new_event->event_type=(cmd==CMD_ENABLE_NOTIFICATIONS)?EVENT_ENABLE_NOTIFICATIONS:EVENT_DISABLE_NOTIFICATIONS; ! new_event->event_data=(void *)NULL; ! new_event->run_time=scheduled_time; ! new_event->recurring=FALSE; ! schedule_event(new_event,&event_list_high); ! } ! else ! return ERROR; ! } #ifdef DEBUG0 --- 1045,1054 ---- #endif ! /* scheduled time is now ignored... */ ! if(cmd==CMD_ENABLE_NOTIFICATIONS) ! enable_all_notifications(); ! else ! disable_all_notifications(); #ifdef DEBUG0 Index: config.c =================================================================== RCS file: /cvsroot/nagios/nagios/base/config.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** config.c 11 Dec 2002 05:30:10 -0000 1.13 --- config.c 17 Dec 2002 03:29:57 -0000 1.14 *************** *** 4,8 **** * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 12-10-2002 * * License: --- 4,8 ---- * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 12-15-2002 * * License: *************** *** 37,40 **** --- 37,41 ---- extern char *auth_file; extern char *p1_file; + extern char *event_broker_file; extern char *nagios_user; *************** *** 73,77 **** extern int test_scheduling; ! extern int sleep_time; extern int interval_length; extern int inter_check_delay_method; --- 74,78 ---- extern int test_scheduling; ! extern double sleep_time; extern int interval_length; extern int inter_check_delay_method; *************** *** 116,119 **** --- 117,122 ---- extern int time_change_threshold; + extern int event_broker_options; + extern int process_performance_data; *************** *** 841,853 **** else if(!strcmp(variable,"sleep_time")){ strip(value); ! sleep_time=atoi(value); ! if(sleep_time<1){ strcpy(error_message,"Illegal value for sleep_time"); error=TRUE; break; } - #ifdef DEBUG1 ! printf("\t\tsleep_time set to %d\n",sleep_time); #endif } --- 844,855 ---- else if(!strcmp(variable,"sleep_time")){ strip(value); ! sleep_time=atof(value); ! if(sleep_time<=0.0){ strcpy(error_message,"Illegal value for sleep_time"); error=TRUE; break; } #ifdef DEBUG1 ! printf("\t\tsleep_time set to %f\n",sleep_time); #endif } *************** *** 1078,1081 **** --- 1080,1108 ---- #endif } + else if(!strcmp(variable,"event_broker_file")){ + if(strlen(value)>MAX_FILENAME_LENGTH-1){ + strcpy(error_message,"Event broker file is too long"); + error=TRUE; + break; + } + + if(event_broker_file!=NULL) + free(event_broker_file); + event_broker_file=(char *)strdup(value); + strip(event_broker_file); + + #ifdef DEBUG1 + printf("\t\tevent_broker_file set to '%s'\n",event_broker_file); + #endif + } + else if(!strcmp(variable,"event_broker_options")){ + strip(value); + event_broker_options=atoi(value); + if(event_broker_options<0) + event_broker_options=BROKER_EVERYTHING; + #ifdef DEBUG1 + printf("\t\tevent_broker_options set to %d\n",event_broker_options); + #endif + } else if(!strcmp(variable,"illegal_object_name_chars")){ illegal_object_chars=strdup(value); Index: logging.c =================================================================== RCS file: /cvsroot/nagios/nagios/base/logging.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** logging.c 7 Dec 2002 01:08:11 -0000 1.4 --- logging.c 17 Dec 2002 03:29:57 -0000 1.5 *************** *** 4,8 **** * * Copyright (c) 1999-2001 Ethan Galstad (na...@na...) ! * Last Modified: 12-06-2001 * * License: --- 4,8 ---- * * Copyright (c) 1999-2001 Ethan Galstad (na...@na...) ! * Last Modified: 12-16-2001 * * License: *************** *** 28,31 **** --- 28,32 ---- #include "../common/statusdata.h" #include "nagios.h" + #include "broker.h" extern char *log_file; *************** *** 116,119 **** --- 117,122 ---- fclose(fp); + + broker_logged_data(NEBTYPE_LOGDATA,NEBFLAG_NONE,NEBATTR_NONE,buffer,data_type,NULL); #ifdef DEBUG0 Index: nagios.c =================================================================== RCS file: /cvsroot/nagios/nagios/base/nagios.c,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -r1.30 -r1.31 *** nagios.c 11 Dec 2002 00:32:35 -0000 1.30 --- nagios.c 17 Dec 2002 03:29:57 -0000 1.31 *************** *** 9,13 **** * * First Written: 01-28-1999 (start of development) ! * Last Modified: 12-09-2002 * * Description: --- 9,13 ---- * * First Written: 01-28-1999 (start of development) ! * Last Modified: 12-15-2002 * [...1496 lines suppressed...] - else - program_start=(time_t)(program_start-(time_t)time_difference); - } - - /* we moved into the future... */ - else - program_start=(time_t)(program_start+(time_t)time_difference); - - /* update status data */ - update_program_status(FALSE); - - #ifdef DEBUG0 - printf("compensate_for_system_time_change() end\n"); - #endif - - return; - } --- 713,716 ---- Index: nagios.h.in =================================================================== RCS file: /cvsroot/nagios/nagios/base/nagios.h.in,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** nagios.h.in 11 Dec 2002 00:32:36 -0000 1.13 --- nagios.h.in 17 Dec 2002 03:29:57 -0000 1.14 *************** *** 3,7 **** * Nagios Main Header File * Written By: Ethan Galstad (na...@na...) ! * Last Modified: 12-09-2002 * * This program is free software; you can redistribute it and/or modify --- 3,7 ---- * Nagios Main Header File * Written By: Ethan Galstad (na...@na...) ! * Last Modified: 12-13-2002 * * This program is free software; you can redistribute it and/or modify *************** *** 93,97 **** #define DEFAULT_INTER_CHECK_DELAY 5.0 /* seconds between initial service check scheduling */ #define DEFAULT_INTERLEAVE_FACTOR 1 /* default interleave to use when scheduling checks */ ! #define DEFAULT_SLEEP_TIME 1 /* seconds between event run checks */ #define DEFAULT_INTERVAL_LENGTH 60 /* seconds per interval unit for check scheduling */ #define DEFAULT_RETRY_INTERVAL 30 /* services are retried in 30 seconds if they're not OK */ --- 93,97 ---- #define DEFAULT_INTER_CHECK_DELAY 5.0 /* seconds between initial service check scheduling */ #define DEFAULT_INTERLEAVE_FACTOR 1 /* default interleave to use when scheduling checks */ ! #define DEFAULT_SLEEP_TIME 0.5 /* seconds between event run checks */ #define DEFAULT_INTERVAL_LENGTH 60 /* seconds per interval unit for check scheduling */ #define DEFAULT_RETRY_INTERVAL 30 /* services are retried in 30 seconds if they're not OK */ *************** *** 203,215 **** #define EVENT_PROGRAM_SHUTDOWN 3 /* program shutdown */ #define EVENT_PROGRAM_RESTART 4 /* program restart */ ! #define EVENT_ENABLE_NOTIFICATIONS 5 /* enable notifications */ ! #define EVENT_DISABLE_NOTIFICATIONS 6 /* disable notifications */ ! #define EVENT_SERVICE_REAPER 7 /* reaps results from service checks */ ! #define EVENT_ORPHAN_CHECK 8 /* checks for orphaned service checks */ ! #define EVENT_RETENTION_SAVE 9 /* save (dump) retention data */ ! #define EVENT_STATUS_SAVE 10 /* save (dump) status data */ ! #define EVENT_SCHEDULED_DOWNTIME 11 /* scheduled host or service downtime */ ! #define EVENT_FRESHNESS_CHECK 12 /* checks service result "freshness" */ ! #define EVENT_EXPIRE_DOWNTIME 13 /* checks for (and removes) expired scheduled downtime */ --- 203,237 ---- #define EVENT_PROGRAM_SHUTDOWN 3 /* program shutdown */ #define EVENT_PROGRAM_RESTART 4 /* program restart */ ! #define EVENT_SERVICE_REAPER 5 /* reaps results from service checks */ ! #define EVENT_ORPHAN_CHECK 6 /* checks for orphaned service checks */ ! #define EVENT_RETENTION_SAVE 7 /* save (dump) retention data */ ! #define EVENT_STATUS_SAVE 8 /* save (dump) status data */ ! #define EVENT_SCHEDULED_DOWNTIME 9 /* scheduled host or service downtime */ ! #define EVENT_FRESHNESS_CHECK 10 /* checks service result "freshness" */ ! #define EVENT_EXPIRE_DOWNTIME 11 /* checks for (and removes) expired scheduled downtime */ ! ! ! ! /*************** EVENT BROKER OPTIONS *****************/ ! ! #define BROKER_NOTHING 0 ! #define BROKER_EVERYTHING 32767 ! ! #define BROKER_PROGRAM_STATE 1 ! #define BROKER_TIMED_EVENTS 2 ! #define BROKER_SERVICE_CHECKS 4 ! #define BROKER_HOST_CHECKS 8 ! #define BROKER_SERVICE_NOTIFICATIONS 16 ! #define BROKER_HOST_NOTIFICATIONS 32 ! #define BROKER_SERVICE_EVENT_HANDLERS 64 ! #define BROKER_HOST_EVENT_HANDLERS 128 ! #define BROKER_LOGGED_DATA 256 ! #define BROKER_SERVICE_FLAPPING 512 ! #define BROKER_HOST_FLAPPING 1024 ! #define BROKER_SERVICE_COMMENTS 2048 ! #define BROKER_HOST_COMMENTS 4096 ! #define BROKER_SERVICE_DOWNTIME 8192 ! #define BROKER_HOST_DOWNTIME 16384 ! *************** *** 332,335 **** --- 354,358 ---- #define COMMAND_BUFFER_SLOTS 512 #define SERVICE_BUFFER_SLOTS 512 + #define EVENT_BUFFER_SLOTS 1536 /* worker threads */ *************** *** 338,342 **** #define COMMAND_WORKER_THREAD 0 #define SERVICE_WORKER_THREAD 1 ! #define BROKER_WORKER_THREAD 2 --- 361,365 ---- #define COMMAND_WORKER_THREAD 0 #define SERVICE_WORKER_THREAD 1 ! #define EVENT_WORKER_THREAD 2 *************** *** 359,363 **** int drop_privileges(char *,char *); /* drops priveleges before startup */ void display_scheduling_info(void); /* displays service check scheduling information */ - void display_xdata_modules(void); /* displays which external data modules are compiled in */ --- 382,385 ---- *************** *** 414,419 **** int run_host_event_handler(host *,int,int); /* runs the event handler for a specific host */ int run_global_host_event_handler(host *,int,int); /* runs the global host event handler */ - void update_service_state_times(service *); /* updates service state times */ - void update_host_state_times(host *); /* updates host state times */ --- 436,439 ---- *************** *** 571,582 **** void disable_passive_host_checks(host *); /* disables passive host checks for a particular host */ ! int init_worker_threads(void); ! int cleanup_worker_threads(void); void * service_result_worker_thread(void *); void * cleanup_service_result_worker_thread(void *); int init_command_file_worker_thread(void); void * command_file_worker_thread(void *); void * cleanup_command_file_worker_thread(void *); #endif --- 591,616 ---- void disable_passive_host_checks(host *); /* disables passive host checks for a particular host */ ! int init_service_result_worker_thread(void); ! int init_event_broker_worker_thread(void); ! int shutdown_service_result_worker_thread(void); ! int shutdown_event_broker_worker_thread(void); void * service_result_worker_thread(void *); void * cleanup_service_result_worker_thread(void *); + void * cleanup_event_broker_worker_thread(void *); int init_command_file_worker_thread(void); + int shutdown_command_file_worker_thread(void); void * command_file_worker_thread(void *); void * cleanup_command_file_worker_thread(void *); + + + /**** Event Broker Functions ****/ + int send_event_data_to_broker(char *); + void * event_broker_worker_thread(void *); + + void broker_program_state(int,int,int,struct timeb *); + void broker_timed_event(int,int,int,timed_event *event,void *,struct timeb *); + void broker_logged_data(int,int,int,char *,unsigned long,struct timeb*); + #endif Index: sehandlers.c =================================================================== RCS file: /cvsroot/nagios/nagios/base/sehandlers.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** sehandlers.c 7 Dec 2002 01:08:11 -0000 1.6 --- sehandlers.c 17 Dec 2002 03:29:57 -0000 1.7 *************** *** 4,8 **** * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 12-06-2002 * * License: --- 4,8 ---- * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 12-13-2002 * * License: *************** *** 493,550 **** /******************************************************************/ - /**************** SERVICE STATE HANDLER FUNCTIONS *****************/ - /******************************************************************/ - - - /* updates service state times */ - void update_service_state_times(service *svc){ - unsigned long time_difference; - time_t current_time; - - #ifdef DEBUG0 - printf("update_service_state_times() start\n"); - #endif - - /* calculate the time since the last service state change */ - time(¤t_time); - - /* if this is NOT the first time we've had a service check/state change.. */ - if(svc->has_been_checked==TRUE){ - - if(svc->last_state_change<program_start) - time_difference=(unsigned long)current_time-program_start; - else - time_difference=(unsigned long)current_time-svc->last_state_change; - - /* use last hard state... */ - if(svc->last_hard_state==STATE_UNKNOWN) - svc->time_unknown+=time_difference; - else if(svc->last_hard_state==STATE_WARNING) - svc->time_warning+=time_difference; - else if(svc->last_hard_state==STATE_CRITICAL) - svc->time_critical+=time_difference; - else - svc->time_ok+=time_difference; - } - - - /* update the last service state change time */ - svc->last_state_change=current_time; - - /* update status log with service information */ - update_service_status(svc,FALSE); - - - #ifdef DEBUG0 - printf("update_service_state_times() end\n"); - #endif - - return; - } - - - - - /******************************************************************/ /****************** HOST STATE HANDLER FUNCTIONS ******************/ /******************************************************************/ --- 493,496 ---- *************** *** 582,589 **** } - /* update the host state times */ - if(state_type==HARD_STATE) - update_host_state_times(hst); - /* the host just recovered, so reset the current host attempt number */ if(state==HOST_UP) --- 528,531 ---- *************** *** 644,690 **** } - - - - /* updates host state times */ - void update_host_state_times(host *hst){ - unsigned long time_difference; - time_t current_time; - - #ifdef DEBUG0 - printf("update_host_state_times() start\n"); - #endif - - /* get the current time */ - time(¤t_time); - - /* if this is NOT the first time we've had a host check/state change... */ - if(hst->has_been_checked==TRUE){ - - if(hst->last_state_change<program_start) - time_difference=(unsigned long)current_time-program_start; - else - time_difference=(unsigned long)current_time-hst->last_state_change; - - if(hst->status==HOST_DOWN) - hst->time_down+=time_difference; - else if(hst->status==HOST_UNREACHABLE) - hst->time_unreachable+=time_difference; - else - hst->time_up+=time_difference; - } - - /* update the last host state change time */ - hst->last_state_change=current_time; - - /* update status log with host information */ - update_host_status(hst,FALSE); - - - #ifdef DEBUG0 - printf("update_host_state_times() end\n"); - #endif - - return; - } --- 586,588 ---- Index: sretention.c =================================================================== RCS file: /cvsroot/nagios/nagios/base/sretention.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** sretention.c 2 Dec 2002 04:30:01 -0000 1.4 --- sretention.c 17 Dec 2002 03:29:57 -0000 1.5 *************** *** 263,271 **** temp_service->no_recovery_notification=FALSE; - temp_service->time_ok=time_ok; - temp_service->time_warning=time_warning; - temp_service->time_unknown=time_unknown; - temp_service->time_critical=time_critical; - if(temp_service->current_state==STATE_OK) temp_service->last_notification=(time_t)0; --- 263,266 ---- *************** *** 376,383 **** temp_host->current_attempt=temp_host->max_attempts; - temp_host->time_up=time_up; - temp_host->time_down=time_down; - temp_host->time_unreachable=time_unreachable; - temp_host->last_state_change=(time_t)last_state_change; temp_host->last_check=(time_t)last_check; --- 371,374 ---- *************** *** 508,515 **** time(¤t_time); ! t_ok=temp_service->time_ok; ! t_warning=temp_service->time_warning; ! t_unknown=temp_service->time_unknown; ! t_critical=temp_service->time_critical; if(temp_service->state_type==SOFT_STATE){ --- 499,506 ---- time(¤t_time); ! t_ok=0; ! t_warning=0; ! t_unknown=0; ! t_critical=0; if(temp_service->state_type==SOFT_STATE){ *************** *** 612,618 **** time(¤t_time); ! t_up=temp_host->time_up; ! t_down=temp_host->time_down; ! t_unreachable=temp_host->time_unreachable; /* if this is NOT the first time we've had a host check/state change... */ --- 603,609 ---- time(¤t_time); ! t_up=0; ! t_down=0; ! t_unreachable=0; /* if this is NOT the first time we've had a host check/state change... */ Index: utils.c =================================================================== RCS file: /cvsroot/nagios/nagios/base/utils.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -r1.24 -r1.25 *** utils.c 13 Dec 2002 23:42:00 -0000 1.24 --- utils.c 17 Dec 2002 03:29:57 -0000 1.25 *************** *** 4,8 **** * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 12-09-2002 * * License: --- 4,8 ---- * * Copyright (c) 1999-2002 Ethan Galstad (na...@na...) ! * Last Modified: 12-15-2002 * * License: *************** *** 29,32 **** --- 29,35 ---- #include "../common/statusdata.h" + #include "nagios.h" + #include "broker.h" + #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> *************** *** 40,45 **** #include <grp.h> #endif - - #include "nagios.h" #ifdef EMBEDDEDPERL --- 43,46 ---- *************** *** 64,67 **** --- 65,69 ---- extern char *auth_file; extern char *p1_file; + extern char *event_broker_file; extern char *nagios_user; *************** *** 104,108 **** extern int log_initial_states; ! extern int sleep_time; extern int interval_length; extern int inter_check_delay_method; --- 106,110 ---- extern int log_initial_states; ! extern double sleep_time; extern int interval_length; extern int inter_check_delay_method; *************** *** 153,156 **** --- 155,160 ---- extern int time_change_threshold; + extern int event_broker_options; + extern int process_performance_data; *************** *** 194,197 **** --- 198,202 ---- extern circular_buffer external_command_buffer; extern circular_buffer service_result_buffer; + extern circular_buffer event_broker_buffer; extern int errno; *************** *** 1901,1904 **** --- 1906,1911 ---- open("/dev/null",O_WRONLY); + broker_program_state(NEBTYPE_PROCESS_DAEMON,NEBFLAG_NONE,NEBATTR_NONE,time(NULL)); + return OK; } *************** *** 2195,2203 **** command_file_created=FALSE; ! /* tell the worker thread to exit */ ! pthread_cancel(worker_threads[COMMAND_WORKER_THREAD]); ! ! /* wait for the worker thread to exit */ ! pthread_join(worker_threads[COMMAND_WORKER_THREAD],NULL); /* close the command file */ --- 2202,2207 ---- command_file_created=FALSE; ! /* shutdown the worker thread */ ! shutdown_command_file_worker_thread(); /* close the command file */ *************** *** 2551,2563 **** /******************************************************************/ ! /* initializes worker threads */ ! int init_worker_threads(void){ int result; - #ifdef DOESNT_WORK - sigset_t newmask, oldmask; - #endif - - - /**** SERVICE CHECK WORKER THREAD ****/ /* initialize circular buffer */ --- 2555,2561 ---- /******************************************************************/ ! /* initializes service result worker thread */ ! int init_service_result_worker_thread(void){ int result; /* initialize circular buffer */ *************** *** 2572,2581 **** pthread_mutex_init(&service_result_buffer.buffer_lock,NULL); - #ifdef DOESNT_WORK - /* worker thread should ignore signals */ - sigfillset(&newmask); - pthread_sigmask(SIG_BLOCK,&newmask,&oldmask); - #endif - /* create worker thread */ result=pthread_create(&worker_threads[SERVICE_WORKER_THREAD],NULL,service_result_worker_thread,NULL); --- 2570,2573 ---- *************** *** 2585,2591 **** #endif ! #ifdef DOESNT_WORK ! /* restore signal catching in main thread */ ! pthread_sigmask(SIG_UNBLOCK,&oldmask,NULL); #endif --- 2577,2610 ---- #endif ! if(result) ! return ERROR; ! ! return OK; ! } ! ! ! /* initializes event broker worker thread */ ! int init_event_broker_worker_thread(void){ ! int result; ! ! if(event_broker_options==BROKER_NOTHING) ! return OK; ! ! /* initialize circular buffer */ ! event_broker_buffer.head=0; ! event_broker_buffer.tail=0; ! event_broker_buffer.items=0; ! event_broker_buffer.buffer=(void **)malloc(EVENT_BUFFER_SLOTS*sizeof(char **)); ! if(event_broker_buffer.buffer==NULL) ! return ERROR; ! ! /* initialize mutex */ ! pthread_mutex_init(&event_broker_buffer.buffer_lock,NULL); ! ! /* create worker thread */ ! result=pthread_create(&worker_threads[EVENT_WORKER_THREAD],NULL,event_broker_worker_thread,NULL); ! ! #ifdef DEBUG1 ! printf("EVENT BROKER THREAD: %lu\n",(unsigned long)worker_threads[EVENT_WORKER_THREAD]); #endif *************** *** 2593,2609 **** return ERROR; - /**** EVENT BROKER WORKER THREAD */ - return OK; } ! /* cleans up worker threads */ ! int cleanup_worker_threads(void){ ! /* tell the worker threads to exit */ pthread_cancel(worker_threads[SERVICE_WORKER_THREAD]); ! /* wait for the worker threads to exit */ pthread_join(worker_threads[SERVICE_WORKER_THREAD],NULL); --- 2612,2626 ---- return ERROR; return OK; } ! /* shutdown the service result worker thread */ ! int shutdown_service_result_worker_thread(void){ ! /* tell the worker thread to exit */ pthread_cancel(worker_threads[SERVICE_WORKER_THREAD]); ! /* wait for the worker thread to exit */ pthread_join(worker_threads[SERVICE_WORKER_THREAD],NULL); *************** *** 2612,2615 **** --- 2629,2648 ---- + /* shutdown event broker worker thread */ + int shutdown_event_broker_worker_thread(void){ + + if(event_broker_options==BROKER_NOTHING) + return OK; + + /* tell the worker thread to exit */ + pthread_cancel(worker_threads[EVENT_WORKER_THREAD]); + + /* wait for the worker thread to exit */ + pthread_join(worker_threads[EVENT_WORKER_THREAD],NULL); + + return OK; + } + + /* clean up resources used by service result worker thread */ void * cleanup_service_result_worker_thread(void *arg){ *************** *** 2628,2634 **** int init_command_file_worker_thread(void){ int result; - #ifdef DOESNT_WORK - sigset_t newmask, oldmask; - #endif /* initialize circular buffer */ --- 2661,2664 ---- *************** *** 2643,2652 **** pthread_mutex_init(&external_command_buffer.buffer_lock,NULL); - #ifdef DOESNT_WORK - /* worker thread should ignore signals */ - sigfillset(&newmask); - pthread_sigmask(SIG_BLOCK,&newmask,&oldmask); - #endif - /* create worker thread */ result=pthread_create(&worker_threads[COMMAND_WORKER_THREAD],NULL,command_file_worker_thread,NULL); --- 2673,2676 ---- *************** *** 2656,2664 **** #endif - #ifdef DOESNT_WORK - /* restore signal catching in main thread */ - pthread_sigmask(SIG_UNBLOCK,&oldmask,NULL); - #endif - if(result) return ERROR; --- 2680,2683 ---- *************** *** 2668,2671 **** --- 2687,2703 ---- + /* shutdown command file worker thread */ + int shutdown_command_file_worker_thread(void){ + + /* tell the worker thread to exit */ + pthread_cancel(worker_threads[COMMAND_WORKER_THREAD]); + + /* wait for the worker thread to exit */ + pthread_join(worker_threads[COMMAND_WORKER_THREAD],NULL); + + return OK; + } + + /* clean up resources used by command file worker thread */ void * cleanup_command_file_worker_thread(void *arg){ *************** *** 3117,3120 **** --- 3149,3153 ---- p1_file=(char *)strdup(DEFAULT_P1_FILE); log_archive_path=(char *)strdup(DEFAULT_LOG_ARCHIVE_PATH); + event_broker_file=(char *)strdup(DEFAULT_EVENT_BROKER_FILE); nagios_user=(char *)strdup(DEFAULT_NAGIOS_USER); *************** *** 3181,3184 **** --- 3214,3219 ---- aggregate_status_updates=TRUE; status_update_interval=DEFAULT_STATUS_UPDATE_INTERVAL; + + event_broker_options=BROKER_NOTHING; time_change_threshold=DEFAULT_TIME_CHANGE_THRESHOLD; |