[Nagios-checkins] ndoutils/src db.c, 1.2, 1.3 dbhandlers.c, 1.6, 1.7 file2sock.c, 1.7, 1.8 log2ndo.
Nagios network monitoring software is enterprise server monitoring
Brought to you by:
egalstad,
sawolf-nagios
From: Ethan G. <ega...@us...> - 2007-10-31 18:17:07
|
Update of /cvsroot/nagios/ndoutils/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30767/src Modified Files: db.c dbhandlers.c file2sock.c log2ndo.c ndo2db.c ndomod.c sockdebug.c utils.c Log Message: Fix for duplicate log entry segfault, prep for new release Index: dbhandlers.c =================================================================== RCS file: /cvsroot/nagios/ndoutils/src/dbhandlers.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dbhandlers.c 3 Oct 2007 01:07:12 -0000 1.6 --- dbhandlers.c 31 Oct 2007 18:17:05 -0000 1.7 *************** *** 4,8 **** * Copyright (c) 2005-2007 Ethan Galstad * ! * Last Modified: 10-02-2007 * **************************************************************/ --- 4,8 ---- * Copyright (c) 2005-2007 Ethan Galstad * ! * Last Modified: 10-31-2007 * **************************************************************/ *************** *** 553,557 **** /*if(duplicate_record==NDO_TRUE && idi->last_logentry_time!=etime){*/ ! if(duplicate_record==NDO_TRUE && strcmp((es[0]==NULL)?"":es[0],idi->dbinfo.last_logentry_data)){ #ifdef NDO2DB_DEBUG printf("IGNORING DUPLICATE LOG RECORD!\n"); --- 553,558 ---- /*if(duplicate_record==NDO_TRUE && idi->last_logentry_time!=etime){*/ ! /*if(duplicate_record==NDO_TRUE && strcmp((es[0]==NULL)?"":es[0],idi->dbinfo.last_logentry_data)){*/ ! if(duplicate_record==NDO_TRUE){ #ifdef NDO2DB_DEBUG printf("IGNORING DUPLICATE LOG RECORD!\n"); *************** *** 3083,3086 **** --- 3084,3089 ---- ndo2db_mbuf mbuf; + ndo2db_log_debug_info(NDO2DB_DEBUGL_SQL,0,"HANDLE_CONFIGFILEVARS [1]\n"); + if(idi==NULL) return NDO_ERROR; *************** *** 3089,3096 **** --- 3092,3104 ---- result=ndo2db_convert_standard_data_elements(idi,&type,&flags,&attr,&tstamp); + ndo2db_log_debug_info(NDO2DB_DEBUGL_SQL,0,"HANDLE_CONFIGFILEVARS [2]\n"); + ndo2db_log_debug_info(NDO2DB_DEBUGL_SQL,0,"TSTAMP: %lu LATEST: %lu\n",tstamp.tv_sec,idi->dbinfo.latest_realtime_data_time); + /* don't store old data */ if(tstamp.tv_sec<idi->dbinfo.latest_realtime_data_time) return NDO_OK; + ndo2db_log_debug_info(NDO2DB_DEBUGL_SQL,0,"HANDLE_CONFIGFILEVARS [3]\n"); + es[0]=ndo2db_db_escape_string(idi,idi->buffered_input[NDO_DATA_CONFIGFILENAME]); *************** *** 3148,3151 **** --- 3156,3165 ---- buf=NULL; + if(asprintf(&buf1,"INSERT INTO %s SET %s" + ,ndo2db_db_tablenames[NDO2DB_DBTABLE_CONFIGFILEVARIABLES] + ,buf + )==-1) + buf1=NULL; + #ifdef REMOVED_10182007 if(asprintf(&buf1,"INSERT INTO %s SET %s ON DUPLICATE KEY UPDATE %s" ,ndo2db_db_tablenames[NDO2DB_DBTABLE_CONFIGFILEVARIABLES] *************** *** 3154,3157 **** --- 3168,3172 ---- )==-1) buf1=NULL; + #endif result=ndo2db_db_query(idi,buf1); Index: log2ndo.c =================================================================== RCS file: /cvsroot/nagios/ndoutils/src/log2ndo.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** log2ndo.c 27 Sep 2007 16:47:47 -0000 1.7 --- log2ndo.c 31 Oct 2007 18:17:05 -0000 1.8 *************** *** 4,8 **** * Copyright (c) 2005-2007 Ethan Galstad * ! * Last Modified: 09-27-2007 * **************************************************************/ --- 4,8 ---- * Copyright (c) 2005-2007 Ethan Galstad * ! * Last Modified: 10-31-2007 * **************************************************************/ *************** *** 13,19 **** #include "../include/protoapi.h" ! #define LOG2NDO_VERSION "1.4b6" #define LOG2NDO_NAME "LOG2NDO" ! #define LOG2NDO_DATE "09-27-2007" --- 13,19 ---- #include "../include/protoapi.h" ! #define LOG2NDO_VERSION "1.4b7" #define LOG2NDO_NAME "LOG2NDO" ! #define LOG2NDO_DATE "10-31-2007" Index: db.c =================================================================== RCS file: /cvsroot/nagios/ndoutils/src/db.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** db.c 29 Aug 2007 15:20:48 -0000 1.2 --- db.c 31 Oct 2007 18:17:05 -0000 1.3 *************** *** 2,8 **** * DB.C - Datatabase routines for NDO2DB daemon * ! * Copyright (c) 2005-2006 Ethan Galstad * ! * Last Modified: 02-15-2006 * **************************************************************/ --- 2,8 ---- * DB.C - Datatabase routines for NDO2DB daemon * ! * Copyright (c) 2005-2007 Ethan Galstad * ! * Last Modified: 10-18-2007 * **************************************************************/ *************** *** 285,288 **** --- 285,289 ---- int result=NDO_OK; int have_instance=NDO_FALSE; + time_t current_time; /* make sure we have an instance name */ *************** *** 382,385 **** --- 383,392 ---- idi->dbinfo.latest_realtime_data_time=idi->dbinfo.latest_queued_event_time; + /* get current time */ + /* make sure latest time stamp isn't in the future - this will cause problems if a backwards system time change occurs */ + time(¤t_time); + if(idi->dbinfo.latest_realtime_data_time>current_time) + idi->dbinfo.latest_realtime_data_time=current_time; + /* set flags to clean event queue, etc. */ idi->dbinfo.clean_event_queue=NDO_TRUE; *************** *** 549,552 **** --- 556,561 ---- #endif + ndo2db_log_debug_info(NDO2DB_DEBUGL_SQL,0,"%s\n",buf); + switch(idi->dbinfo.server_type){ case NDO2DB_DBSERVER_MYSQL: Index: utils.c =================================================================== RCS file: /cvsroot/nagios/ndoutils/src/utils.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** utils.c 8 Jan 2007 00:35:54 -0000 1.1.1.1 --- utils.c 31 Oct 2007 18:17:05 -0000 1.2 *************** *** 2,7 **** * UTILS.C - NDO Utils * ! * Copyright (c) 2005 Ethan Galstad ! * First Written: 05-19-2005 * * --- 2,7 ---- * UTILS.C - NDO Utils * ! * Copyright (c) 2005-2007 Ethan Galstad ! * First Written: 10-29-2007 * * *************** *** 13,16 **** --- 13,18 ---- + + /****************************************************************************/ /* DYNAMIC BUFFER FUNCTIONS */ *************** *** 89,90 **** --- 91,154 ---- return NDO_OK; } + + + + /******************************************************************/ + /************************* FILE FUNCTIONS *************************/ + /******************************************************************/ + + /* renames a file - works across filesystems (Mike Wiacek) */ + int my_rename(char *source, char *dest){ + char buffer[1024]={0}; + int rename_result=0; + int source_fd=-1; + int dest_fd=-1; + int bytes_read=0; + + + /* make sure we have something */ + if(source==NULL || dest==NULL) + return -1; + + /* first see if we can rename file with standard function */ + rename_result=rename(source,dest); + + /* handle any errors... */ + if(rename_result==-1){ + + /* an error occurred because the source and dest files are on different filesystems */ + if(errno==EXDEV){ + + /* open destination file for writing */ + if((dest_fd=open(dest,O_WRONLY|O_TRUNC|O_CREAT|O_APPEND,0644))>0){ + + /* open source file for reading */ + if((source_fd=open(source,O_RDONLY,0644))>0){ + + while((bytes_read=read(source_fd,buffer,sizeof(buffer)))>0) + write(dest_fd,buffer,bytes_read); + + close(source_fd); + close(dest_fd); + + /* delete the original file */ + unlink(source); + + /* reset result since we successfully copied file */ + rename_result=0; + } + + else{ + close(dest_fd); + return rename_result; + } + } + } + + else{ + return rename_result; + } + } + + return rename_result; + } Index: ndomod.c =================================================================== RCS file: /cvsroot/nagios/ndoutils/src/ndomod.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ndomod.c 27 Sep 2007 16:47:48 -0000 1.8 --- ndomod.c 31 Oct 2007 18:17:05 -0000 1.9 *************** *** 6,10 **** * * First Written: 05-19-2005 ! * Last Modified: 09-27-2007 * *****************************************************************************/ --- 6,10 ---- * * First Written: 05-19-2005 ! * Last Modified: 10-31-2007 * *****************************************************************************/ *************** *** 50,56 **** ! #define NDOMOD_VERSION "1.4b6" #define NDOMOD_NAME "NDOMOD" ! #define NDOMOD_DATE "09-27-2007" --- 50,56 ---- ! #define NDOMOD_VERSION "1.4b7" #define NDOMOD_NAME "NDOMOD" ! #define NDOMOD_DATE "10-31-2007" *************** *** 218,222 **** --- 218,226 ---- else{ time(¤t_time); + #ifdef BUILD_NAGIOS_2X schedule_new_event(EVENT_USER_FUNCTION,TRUE,current_time+ndomod_sink_rotation_interval,TRUE,ndomod_sink_rotation_interval,NULL,TRUE,(void *)ndomod_rotate_sink_file,NULL); + #else + schedule_new_event(EVENT_USER_FUNCTION,TRUE,current_time+ndomod_sink_rotation_interval,TRUE,ndomod_sink_rotation_interval,NULL,TRUE,(void *)ndomod_rotate_sink_file,NULL,0); + #endif } *************** *** 1151,1154 **** --- 1155,1160 ---- #endif double retry_interval=0.0; + int last_state=-1; + int last_hard_state=-1; #ifdef BUILD_NAGIOS_3X customvariablesmember *temp_customvar=NULL; *************** *** 2861,2864 **** --- 2867,2906 ---- schangedata=(nebstruct_statechange_data *)data; + #ifdef BUILD_NAGIOS_2X + /* find host/service and get last state info */ + if(schangedata->service_description==NULL){ + if((temp_host=find_host(schangedata->host_name))==NULL){ + ndo_dbuf_free(&dbuf); + return 0; + } + } + else{ + if((temp_service=find_service(schangedata->host_name,schangedata->service_description))==NULL){ + ndo_dbuf_free(&dbuf); + return 0; + } + last_state=temp_service->last_state; + last_hard_state=temp_service->last_hard_state; + } + #else + /* get the last state info */ + if(schangedata->service_description==NULL){ + if((temp_host=(host *)schangedata->object_ptr)==NULL){ + ndo_dbuf_free(&dbuf); + return 0; + } + last_state=temp_host->last_state; + last_state=temp_host->last_hard_state; + } + else{ + if((temp_service=(service *)schangedata->object_ptr)==NULL){ + ndo_dbuf_free(&dbuf); + return 0; + } + last_state=temp_service->last_state; + last_hard_state=temp_service->last_hard_state; + } + #endif + es[0]=ndo_escape_buffer(schangedata->host_name); es[1]=ndo_escape_buffer(schangedata->service_description); *************** *** 2894,2900 **** ,schangedata->max_attempts ,NDO_DATA_LASTSTATE ! ,-1 ,NDO_DATA_LASTHARDSTATE ! ,-1 ,NDO_DATA_OUTPUT ,es[2] --- 2936,2942 ---- ,schangedata->max_attempts ,NDO_DATA_LASTSTATE ! ,last_state ,NDO_DATA_LASTHARDSTATE ! ,last_hard_state ,NDO_DATA_OUTPUT ,es[2] Index: ndo2db.c =================================================================== RCS file: /cvsroot/nagios/ndoutils/src/ndo2db.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ndo2db.c 27 Sep 2007 16:47:47 -0000 1.7 --- ndo2db.c 31 Oct 2007 18:17:05 -0000 1.8 *************** *** 5,9 **** * * First Written: 05-19-2005 ! * Last Modified: 09-27-2007 * **************************************************************/ --- 5,9 ---- * * First Written: 05-19-2005 ! * Last Modified: 10-31-2007 * **************************************************************/ *************** *** 25,31 **** #include "../include/dbhandlers.h" ! #define NDO2DB_VERSION "1.4b6" #define NDO2DB_NAME "NDO2DB" ! #define NDO2DB_DATE "09-27-2007" --- 25,31 ---- #include "../include/dbhandlers.h" ! #define NDO2DB_VERSION "1.4b7" #define NDO2DB_NAME "NDO2DB" ! #define NDO2DB_DATE "10-31-2007" *************** *** 47,55 **** time_t ndo2db_db_last_checkin_time=0L; extern char *ndo2db_db_tablenames[NDO2DB_MAX_DBTABLES]; ! /*#define DEBUG_NDO2DB 1*/ /* don't daemonize */ /*#define DEBUG_NDO2DB_EXIT_AFTER_CONNECTION 1*/ /* exit after first client disconnects */ /*#define DEBUG_NDO2DB2 1*/ --- 47,61 ---- time_t ndo2db_db_last_checkin_time=0L; + char *ndo2db_debug_file=NULL; + int ndo2db_debug_level=NDO2DB_DEBUGL_NONE; + int ndo2db_debug_verbosity=NDO2DB_DEBUGV_BASIC; + FILE *ndo2db_debug_file_fp=NULL; + unsigned long ndo2db_max_debug_file_size=0L; + extern char *ndo2db_db_tablenames[NDO2DB_MAX_DBTABLES]; ! /*#define DEBUG_NDO2DB 1*/ /* don't daemonize */ /*#define DEBUG_NDO2DB_EXIT_AFTER_CONNECTION 1*/ /* exit after first client disconnects */ /*#define DEBUG_NDO2DB2 1*/ *************** *** 103,106 **** --- 109,115 ---- exit(1); } + + /* open debug log */ + ndo2db_open_debug_log(); /* make sure we're good to go */ *************** *** 157,160 **** --- 166,172 ---- } + /* close debug log */ + ndo2db_close_debug_log(); + /* free memory */ ndo2db_free_program_memory(); *************** *** 353,356 **** --- 365,379 ---- ndo2db_group=strdup(val); + else if(!strcmp(var,"debug_file")){ + if((ndo2db_debug_file=strdup(val))==NULL) + return NDO_ERROR; + } + else if(!strcmp(var,"debug_level")) + ndo2db_debug_level=atoi(val); + else if(!strcmp(var,"debug_verbosity")) + ndo2db_debug_verbosity=atoi(val); + else if(!strcmp(var,"max_debug_file_size")) + ndo2db_max_debug_file_size=strtoul(val,NULL,0); + return NDO_OK; } *************** *** 421,424 **** --- 444,451 ---- ndo2db_db_settings.dbprefix=NULL; } + if(ndo2db_debug_file){ + free(ndo2db_debug_file); + ndo2db_debug_file=NULL; + } return NDO_OK; *************** *** 765,768 **** --- 792,799 ---- /*openlog("ndo2db",0,LOG_DAEMON);*/ + /* re-open debug log */ + ndo2db_close_debug_log(); + ndo2db_open_debug_log(); + /* reset signal handling */ signal(SIGQUIT,ndo2db_child_sighandler); *************** *** 1799,1803 **** --- 1830,1839 ---- return NDO_ERROR; + #ifdef HAVE_STRTOF *f=strtof(buf,&endptr); + #else + /* Solaris 8 doesn't have strtof() */ + *f=(float)strtod(buf,&endptr); + #endif if(*f==0 && (endptr==buf || errno==ERANGE)) *************** *** 1889,1890 **** --- 1925,2012 ---- } + + + /****************************************************************************/ + /* LOGGING ROUTINES */ + /****************************************************************************/ + + /* opens the debug log for writing */ + int ndo2db_open_debug_log(void){ + + /* don't do anything if we're not debugging */ + if(ndo2db_debug_level==NDO2DB_DEBUGL_NONE) + return NDO_OK; + + if((ndo2db_debug_file_fp=fopen(ndo2db_debug_file,"a+"))==NULL) + return NDO_ERROR; + + return NDO_OK; + } + + + /* closes the debug log */ + int ndo2db_close_debug_log(void){ + + if(ndo2db_debug_file_fp!=NULL) + fclose(ndo2db_debug_file_fp); + + ndo2db_debug_file_fp=NULL; + + return NDO_OK; + } + + + /* write to the debug log */ + int ndo2db_log_debug_info(int level, int verbosity, const char *fmt, ...){ + va_list ap; + char *temp_path=NULL; + struct timeval current_time; + + if(!(ndo2db_debug_level==NDO2DB_DEBUGL_ALL || (level & ndo2db_debug_level))) + return NDO_OK; + + if(verbosity>ndo2db_debug_verbosity) + return NDO_OK; + + if(ndo2db_debug_file_fp==NULL) + return NDO_ERROR; + + /* write the timestamp */ + gettimeofday(¤t_time,NULL); + fprintf(ndo2db_debug_file_fp,"[%lu.%06lu] [%03d.%d] [pid=%lu] ",current_time.tv_sec,current_time.tv_usec,level,verbosity,(unsigned long)getpid()); + + /* write the data */ + va_start(ap,fmt); + vfprintf(ndo2db_debug_file_fp,fmt,ap); + va_end(ap); + + /* flush, so we don't have problems tailing or when fork()ing */ + fflush(ndo2db_debug_file_fp); + + /* if file has grown beyond max, rotate it */ + if((unsigned long)ftell(ndo2db_debug_file_fp)>ndo2db_max_debug_file_size && ndo2db_max_debug_file_size>0L){ + + /* close the file */ + ndo2db_close_debug_log(); + + /* rotate the log file */ + asprintf(&temp_path,"%s.old",ndo2db_debug_file); + if(temp_path){ + + /* unlink the old debug file */ + unlink(temp_path); + + /* rotate the debug file */ + my_rename(ndo2db_debug_file,temp_path); + + /* free memory */ + my_free(temp_path); + } + + /* open a new file */ + ndo2db_open_debug_log(); + } + + return NDO_OK; + } + Index: sockdebug.c =================================================================== RCS file: /cvsroot/nagios/ndoutils/src/sockdebug.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** sockdebug.c 27 Sep 2007 16:47:48 -0000 1.7 --- sockdebug.c 31 Oct 2007 18:17:05 -0000 1.8 *************** *** 5,9 **** * * First Written: 05-13-2005 ! * Last Modified: 09-27-2007 * **************************************************************/ --- 5,9 ---- * * First Written: 05-13-2005 ! * Last Modified: 10-31-2007 * **************************************************************/ *************** *** 11,17 **** #include "../include/config.h" ! #define SOCKDEBUG_VERSION "1.4b6" #define SOCKDEBUG_NAME "SOCKDEBUG" ! #define SOCKDEBUG_DATE "09-27-2007" --- 11,17 ---- #include "../include/config.h" ! #define SOCKDEBUG_VERSION "1.4b7" #define SOCKDEBUG_NAME "SOCKDEBUG" ! #define SOCKDEBUG_DATE "10-31-2007" Index: file2sock.c =================================================================== RCS file: /cvsroot/nagios/ndoutils/src/file2sock.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** file2sock.c 27 Sep 2007 16:47:47 -0000 1.7 --- file2sock.c 31 Oct 2007 18:17:05 -0000 1.8 *************** *** 6,10 **** * * First Written: 05-13-2005 ! * Last Modified: 09-27-2007 * **************************************************************/ --- 6,10 ---- * * First Written: 05-13-2005 ! * Last Modified: 10-31-2007 * **************************************************************/ *************** *** 14,20 **** #include "../include/io.h" ! #define FILE2SOCK_VERSION "1.4b6" #define FILE2SOCK_NAME "FILE2SOCK" ! #define FILE2SOCK_DATE "09-27-2007" --- 14,20 ---- #include "../include/io.h" ! #define FILE2SOCK_VERSION "1.4b7" #define FILE2SOCK_NAME "FILE2SOCK" ! #define FILE2SOCK_DATE "10-31-2007" |