Icinga-core 1.4.0
next gen monitoring
base/sretention.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * SRETENTION.C - State retention routines for Icinga
00004  *
00005  * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
00006  * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
00007  * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
00008  *
00009  * License:
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License version 2 as
00013  * published by the Free Software Foundation.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023  *
00024  *****************************************************************************/
00025 
00026 /*********** COMMON HEADER FILES ***********/
00027 
00028 #include "../include/config.h"
00029 #include "../include/common.h"
00030 #include "../include/objects.h"
00031 #include "../include/statusdata.h"
00032 #include "../include/icinga.h"
00033 #include "../include/sretention.h"
00034 #include "../include/broker.h"
00035 
00036 extern int            retain_state_information;
00037 
00038 
00039 
00040 /**** IMPLEMENTATION SPECIFIC HEADER FILES ****/
00041 #ifdef USE_XRDDEFAULT
00042 #include "../xdata/xrddefault.h"                /* default routines */
00043 #endif
00044 
00045 
00046 
00047 
00048 
00049 
00050 /******************************************************************/
00051 /************* TOP-LEVEL STATE INFORMATION FUNCTIONS **************/
00052 /******************************************************************/
00053 
00054 
00055 /* initializes retention data at program start */
00056 int initialize_retention_data(char *config_file){
00057         int result=OK;
00058 
00059         /**** IMPLEMENTATION-SPECIFIC CALLS ****/
00060 #ifdef USE_XRDDEFAULT
00061         result=xrddefault_initialize_retention_data(config_file);
00062 #endif
00063 
00064         return result;
00065         }
00066 
00067 
00068 
00069 /* cleans up retention data before program termination */
00070 int cleanup_retention_data(char *config_file){
00071         int result=OK;
00072 
00073         /**** IMPLEMENTATION-SPECIFIC CALLS ****/
00074 #ifdef USE_XRDDEFAULT
00075         result=xrddefault_cleanup_retention_data(config_file);
00076 #endif
00077 
00078         return result;
00079         }
00080 
00081 
00082 
00083 /* save all host and service state information */
00084 int save_state_information(int autosave){
00085         int result=OK;
00086 
00087         if(retain_state_information==FALSE)
00088                 return OK;
00089 
00090 #ifdef USE_EVENT_BROKER
00091         /* send data to event broker */
00092         broker_retention_data(NEBTYPE_RETENTIONDATA_STARTSAVE,NEBFLAG_NONE,NEBATTR_NONE,NULL);
00093 #endif
00094 
00095         /********* IMPLEMENTATION-SPECIFIC OUTPUT FUNCTION ********/
00096 #ifdef USE_XRDDEFAULT
00097         result=xrddefault_save_state_information();
00098 #endif
00099 
00100 #ifdef USE_EVENT_BROKER
00101         /* send data to event broker */
00102         broker_retention_data(NEBTYPE_RETENTIONDATA_ENDSAVE,NEBFLAG_NONE,NEBATTR_NONE,NULL);
00103 #endif
00104 
00105         if(result==ERROR)
00106                 return ERROR;
00107 
00108         if(autosave==TRUE)
00109                 logit(NSLOG_PROCESS_INFO,FALSE,"Auto-save of retention data completed successfully.\n");
00110 
00111         return OK;
00112         }
00113 
00114 
00115 
00116 
00117 /* reads in initial host and state information */
00118 int read_initial_state_information(void){
00119         int result=OK;
00120 
00121         if(retain_state_information==FALSE)
00122                 return OK;
00123 
00124 #ifdef USE_EVENT_BROKER
00125         /* send data to event broker */
00126         broker_retention_data(NEBTYPE_RETENTIONDATA_STARTLOAD,NEBFLAG_NONE,NEBATTR_NONE,NULL);
00127 #endif
00128 
00129         /********* IMPLEMENTATION-SPECIFIC INPUT FUNCTION ********/
00130 #ifdef USE_XRDDEFAULT
00131         result=xrddefault_read_state_information();
00132 #endif
00133 
00134 #ifdef USE_EVENT_BROKER
00135         /* send data to event broker */
00136         broker_retention_data(NEBTYPE_RETENTIONDATA_ENDLOAD,NEBFLAG_NONE,NEBATTR_NONE,NULL);
00137 #endif
00138 
00139         if(result==ERROR)
00140                 return ERROR;
00141 
00142         return OK;
00143         }
00144 
00145 /* syncs host and state information from sync file */
00146 /* Should this go within read_state_information()? */
00147 int sync_state_information(void){
00148         int result=OK;
00149  
00150         if(retain_state_information==FALSE)
00151                 return OK;
00152  
00153         /********* IMPLEMENTATION-SPECIFIC INPUT FUNCTION ********/
00154 #ifdef USE_XRDDEFAULT
00155         result=xrddefault_sync_state_information();
00156 #endif
00157  
00158         if(result==ERROR)
00159                 return ERROR;
00160 
00161         return OK;
00162         }
00163 
 All Data Structures Files Functions Variables Typedefs Defines