Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
core: merge xdata/xdddefault back into common/downtime
Browse files Browse the repository at this point in the history
refs #4815
  • Loading branch information
Michael Friedrich committed Nov 4, 2013
1 parent cfdadbe commit 117c315
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 410 deletions.
16 changes: 2 additions & 14 deletions base/Makefile.in
Expand Up @@ -76,8 +76,6 @@ XODC=@XODC@
XODH=@XODH@
XPDC=@XPDC@
XPDH=@XPDH@
XDDC=@XDDC@
XDDH=@XDDH@

# Extra base code
BASEEXTRALIBS=@BASEEXTRALIBS@
Expand Down Expand Up @@ -122,16 +120,9 @@ PDATALIBS=perfdata-base.o xperfdata-base.o
PDATAHDRS=
PDATADEPS=$(PDATALIBS)

# Downtime data
#DDATALIBS=$(SRC_COMMON)/downtime.c $(SRC_XDATA)/$(XDDC)
#DDATAHDRS=$(SRC_INCLUDE)/downtime.h $(SRC_XDATA)/$(XDDH)
DDATALIBS=downtime-base.o xdowntime-base.o
DDATAHDRS=
DDATADEPS=$(DDATALIBS)


OBJS=$(BROKER_O) $(SRC_COMMON)/shared.o checks.o config.o commands.o events.o flapping.o logging.o macros-base.o netutils.o notifications.o sehandlers.o skiplist.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O) $(PERLXSI_O)
OBJDEPS=$(ODATADEPS) $(ODATADEPS) $(RDATADEPS) $(CDATADEPS) $(SDATADEPS) $(PDATADEPS) $(DDATADEPS) $(BROKER_H)
OBJS=$(BROKER_O) $(SRC_COMMON)/shared.o $(SRC_COMMON)/downtime.o checks.o config.o commands.o events.o flapping.o logging.o macros-base.o netutils.o notifications.o sehandlers.o skiplist.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O) $(PERLXSI_O)
OBJDEPS=$(ODATADEPS) $(ODATADEPS) $(RDATADEPS) $(CDATADEPS) $(SDATADEPS) $(PDATADEPS) $(BROKER_H)

all: icinga icingastats

Expand Down Expand Up @@ -165,9 +156,6 @@ xcomments-base.o: $(SRC_XDATA)/$(XCDC) $(SRC_XDATA)/$(XCDH)
downtime-base.o: $(SRC_COMMON)/downtime.c $(SRC_INCLUDE)/downtime.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/downtime.c

xdowntime-base.o: $(SRC_XDATA)/$(XDDC) $(SRC_XDATA)/$(XDDH)
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XDDC)

perfdata-base.o: perfdata.c $(SRC_INCLUDE)/perfdata.h
$(CC) $(CFLAGS) -c -o $@ perfdata.c

Expand Down
7 changes: 0 additions & 7 deletions base/config.c
Expand Up @@ -1497,13 +1497,6 @@ int read_main_config_file(char *main_config_file) {
auth_file = (char *)strdup(value);
}

/* warn about old variables */
else if (!strcmp(variable, "comment_file") || !strcmp(variable, "xcddefault_comment_file")) {
logit(NSLOG_CONFIG_WARNING, TRUE, "Warning: comment_file variable ignored. Comments are now stored in the status and retention files.");
} else if (!strcmp(variable, "downtime_file") || !strcmp(variable, "xdddefault_downtime_file")) {
logit(NSLOG_CONFIG_WARNING, TRUE, "Warning: downtime_file variable ignored. Downtime entries are now stored in the status and retention files.");
}

/* skip external data directives */
else if (strstr(input, "x") == input)
continue;
Expand Down
5 changes: 0 additions & 5 deletions cgi/Makefile.in
Expand Up @@ -63,8 +63,6 @@ XCDC=@XCDC@
XCDH=@XCDH@
XODC=@XODC@
XODH=@XODH@
XDDC=@XDDC@
XDDH=@XDDH@

# Generated automatically from configure script
SNPRINTF_O=@SNPRINTF_O@
Expand Down Expand Up @@ -133,9 +131,6 @@ xcomments-cgi.o: $(SRC_XDATA)/$(XCDC) $(SRC_XDATA)/$(XCDH)
downtime-cgi.o: $(SRC_COMMON)/downtime.c $(SRC_INCLUDE)/downtime.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/downtime.c

xdowntime-cgi.o: $(SRC_XDATA)/$(XDDC) $(SRC_XDATA)/$(XDDH)
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XDDC)

$(SRC_COMMON)/shared.o: $(SRC_COMMON)/shared.c
$(CC) $(CFLAGS) -c -o $@ $<

Expand Down
157 changes: 108 additions & 49 deletions common/downtime.c
Expand Up @@ -32,10 +32,6 @@

/***** IMPLEMENTATION-SPECIFIC INCLUDES *****/

#ifdef USE_XDDDEFAULT
#include "../xdata/xdddefault.h"
#endif

#ifdef NSCORE
#include "../include/icinga.h"
#include "../include/broker.h"
Expand All @@ -62,6 +58,7 @@ int defer_downtime_sorting = 0;
extern timed_event *event_list_high;
extern timed_event *event_list_high_tail;
pthread_mutex_t icinga_downtime_lock = PTHREAD_MUTEX_INITIALIZER;
extern unsigned long next_downtime_id;
#endif

#ifdef NSCORE
Expand All @@ -75,28 +72,88 @@ pthread_mutex_t icinga_downtime_lock = PTHREAD_MUTEX_INITIALIZER;
int initialize_downtime_data(char *config_file) {
int result = OK;

/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_initialize_downtime_data(config_file);
#endif
scheduled_downtime *temp_downtime = NULL;

/* clean up the old downtime data */
validate_downtime_data();

/* find the new starting index for downtime id if its missing*/
if (next_downtime_id == 0L) {
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (temp_downtime->downtime_id >= next_downtime_id)
next_downtime_id = temp_downtime->downtime_id + 1;
}
}

/* initialize next downtime id if necessary */
if (next_downtime_id == 0L)
next_downtime_id = 1;

return result;
}


/* removes invalid and old downtime entries from the downtime file */
int validate_downtime_data(void) {
scheduled_downtime *temp_downtime;
scheduled_downtime *next_downtime;
int save = TRUE;

/* remove stale downtimes */
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) {

next_downtime = temp_downtime->next;
save = TRUE;

/* delete downtimes with invalid host names */
if (find_host(temp_downtime->host_name) == NULL)
save = FALSE;

/* delete downtimes with invalid service descriptions */
if (temp_downtime->type == SERVICE_DOWNTIME && find_service(temp_downtime->host_name, temp_downtime->service_description) == NULL)
save = FALSE;

/* delete downtimes that have expired */
if (temp_downtime->end_time < time(NULL))
save = FALSE;

/* delete the downtime */
if (save == FALSE) {
delete_downtime(temp_downtime->type, temp_downtime->downtime_id);
}
}

/* remove triggered downtimes without valid parents */
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = next_downtime) {

next_downtime = temp_downtime->next;
save = TRUE;

if (temp_downtime->triggered_by == 0)
continue;

if (find_host_downtime(temp_downtime->triggered_by) == NULL && find_service_downtime(temp_downtime->triggered_by) == NULL)
save = FALSE;

/* delete the downtime */
if (save == FALSE) {
delete_downtime(temp_downtime->type, temp_downtime->downtime_id);
}
}

/* update downtime file - done in aggregated dumps */

return OK;
}


/* cleans up scheduled downtime data */
int cleanup_downtime_data(char *config_file) {
int result = OK;

/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_cleanup_downtime_data(config_file);
#endif

/* free memory allocated to downtime data */
free_downtime_data();

return result;
return OK;
}


Expand Down Expand Up @@ -737,23 +794,29 @@ int add_new_downtime(int type, char *host_name, char *service_description, time_
/* saves a host downtime entry */
int add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, time_t trigger_time) {
int result = OK;
unsigned long new_downtime_id = 0L;

if (host_name == NULL)
return ERROR;

/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_add_new_host_downtime(host_name, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &new_downtime_id, is_in_effect, trigger_time);
#endif
/* find the next valid downtime id */
while (find_host_downtime(next_downtime_id) != NULL)
next_downtime_id++;

/* add downtime to list in memory */
result = add_host_downtime(host_name, entry_time,
author, comment_data, start_time, end_time, fixed, triggered_by,
duration, next_downtime_id, is_in_effect, trigger_time);

/* increment the downtime id */
next_downtime_id++;

/* save downtime id */
if (downtime_id != NULL)
*downtime_id = new_downtime_id;
*downtime_id = next_downtime_id;

#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_downtime_data(NEBTYPE_DOWNTIME_ADD, NEBFLAG_NONE, NEBATTR_NONE, HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, new_downtime_id, NULL, is_in_effect, trigger_time);
broker_downtime_data(NEBTYPE_DOWNTIME_ADD, NEBFLAG_NONE, NEBATTR_NONE, HOST_DOWNTIME, host_name, NULL, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, next_downtime_id, NULL, is_in_effect, trigger_time);
#endif

return result;
Expand All @@ -763,23 +826,29 @@ int add_new_host_downtime(char *host_name, time_t entry_time, char *author, char
/* saves a service downtime entry */
int add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, time_t trigger_time) {
int result = OK;
unsigned long new_downtime_id = 0L;

if (host_name == NULL || service_description == NULL)
return ERROR;

/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_add_new_service_downtime(host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, &new_downtime_id, is_in_effect, trigger_time);
#endif
/* find the next valid downtime id */
while (find_service_downtime(next_downtime_id) != NULL)
next_downtime_id++;

/* add downtime to list in memory */
result = add_service_downtime(host_name, service_description, entry_time,
author, comment_data, start_time, end_time, fixed, triggered_by,
duration, next_downtime_id, is_in_effect, trigger_time);

/* increment the downtime id */
next_downtime_id++;

/* save downtime id */
if (downtime_id != NULL)
*downtime_id = new_downtime_id;
*downtime_id = next_downtime_id;

#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_downtime_data(NEBTYPE_DOWNTIME_ADD, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_DOWNTIME, host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, new_downtime_id, NULL, is_in_effect, trigger_time);
broker_downtime_data(NEBTYPE_DOWNTIME_ADD, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_DOWNTIME, host_name, service_description, entry_time, author, comment_data, start_time, end_time, fixed, triggered_by, duration, next_downtime_id, NULL, is_in_effect, trigger_time);
#endif

return result;
Expand Down Expand Up @@ -854,33 +923,23 @@ int delete_downtime(int type, unsigned long downtime_id) {

/* deletes a scheduled host downtime entry */
int delete_host_downtime(unsigned long downtime_id) {
int result = OK;

/*
* do not update status immediately
* let aggregated dumps take care of it
*/
/* delete the downtime from memory */
delete_downtime(HOST_DOWNTIME, downtime_id);

/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_delete_host_downtime(downtime_id);
#endif

return result;
return delete_downtime(HOST_DOWNTIME, downtime_id);
}


/* deletes a scheduled service downtime entry */
int delete_service_downtime(unsigned long downtime_id) {
int result = OK;

/*
* do not update status immediately
* let aggregated dumps take care of it
*/
/* delete the downtime from memory */
delete_downtime(SERVICE_DOWNTIME, downtime_id);

/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XDDDEFAULT
result = xdddefault_delete_service_downtime(downtime_id);
#endif

return result;
return delete_downtime(SERVICE_DOWNTIME, downtime_id);
}

/*
Expand Down
14 changes: 0 additions & 14 deletions configure
Expand Up @@ -660,8 +660,6 @@ BROKER_LDFLAGS
mainurl
htmurl
cgiurl
XDDH
XDDC
XPDH
XPDC
XODH
Expand Down Expand Up @@ -5822,18 +5820,6 @@ echo "We'll use default routines (in xdata/xpddefault.*) for performance data I/
cat >>confdefs.h <<_ACEOF
#define USE_XDDDEFAULT /**/
_ACEOF
XDDC="xdddefault.c"
XDDH="xdddefault.h"
XDDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O..."
# Check whether --with-gd-lib was given.
if test "${with_gd_lib+set}" = set; then :
Expand Down
9 changes: 0 additions & 9 deletions configure.in
Expand Up @@ -593,15 +593,6 @@ AC_SUBST(XPDC)
AC_SUBST(XPDH)


dnl Downtime data
AC_DEFINE_UNQUOTED(USE_XDDDEFAULT,,[use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O...])
XDDC="xdddefault.c"
XDDH="xdddefault.h"
XDDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O..."
AC_SUBST(XDDC)
AC_SUBST(XDDH)


dnl Optional GD library and include paths
AC_ARG_WITH(gd-lib,AC_HELP_STRING([--with-gd-lib=DIR],[sets location of the gd library]),[
Expand Down
1 change: 0 additions & 1 deletion include/config.h.in
Expand Up @@ -63,7 +63,6 @@
#undef USE_XRDDEFAULT
#undef USE_XODTEMPLATE
#undef USE_XPDDEFAULT
#undef USE_XDDDEFAULT

/***** CGI COMPILE OPTIONS *****/
/* should we compile and use the statusmap CGI? */
Expand Down
1 change: 1 addition & 0 deletions include/downtime.h
Expand Up @@ -64,6 +64,7 @@ typedef struct scheduled_downtime_struct{
#ifdef NSCORE
int initialize_downtime_data(char *); /* initializes scheduled downtime data */
int cleanup_downtime_data(char *); /* cleans up scheduled downtime data */
int validate_downtime_data(void);

int add_new_downtime(int,char *,char *,time_t,char *,char *,time_t,time_t,int,unsigned long,unsigned long,unsigned long *,int,time_t);
int add_new_host_downtime(char *,time_t,char *,char *,time_t,time_t,int,unsigned long,unsigned long,unsigned long *,int,time_t);
Expand Down
2 changes: 0 additions & 2 deletions t-tap/Makefile.in
Expand Up @@ -72,8 +72,6 @@ XODC=@XODC@
XODH=@XODH@
XPDC=@XPDC@
XPDH=@XPDH@
XDDC=@XDDC@
XDDH=@XDDH@

# Extra base code
BASEEXTRALIBS=@BASEEXTRALIBS@
Expand Down
3 changes: 0 additions & 3 deletions t-tap/stub_xddefault.c
@@ -1,8 +1,5 @@
/* Stub file for xdata/xddefault.c */
int xdddefault_add_new_host_downtime(char *host_name, time_t entry_time, char *author, char *comment, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, time_t trigger_time) {} /* icinga changed */
int xdddefault_add_new_service_downtime(char *host_name, char *service_description, time_t entry_time, char *author, char *comment, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *downtime_id, int is_in_effect, time_t trigger_time) {} /* icinga changed */
int xdddefault_cleanup_downtime_data(char *main_config_file) {}
int xdddefault_delete_service_downtime(unsigned long downtime_id) {}
int xdddefault_delete_host_downtime(unsigned long downtime_id) {}
int xdddefault_initialize_downtime_data(char *main_config_file) {}

0 comments on commit 117c315

Please sign in to comment.