![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /*************************************************************** 00002 * DB.C - Datatabase routines for IDO2DB daemon 00003 * 00004 * Copyright (c) 2005-2007 Ethan Galstad 00005 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00006 * 00007 **************************************************************/ 00008 00009 /* include our project's header files */ 00010 #include "../../../include/config.h" 00011 #include "../include/common.h" 00012 #include "../include/io.h" 00013 #include "../include/utils.h" 00014 #include "../include/protoapi.h" 00015 #include "../include/ido2db.h" 00016 #include "../include/dbhandlers.h" 00017 #include "../include/db.h" 00018 00019 extern int errno; 00020 00021 extern int ido2db_log_debug_info(int , int , const char *, ...); 00022 00023 int dummy; /* reduce compiler warnings */ 00024 00025 /* point to prepared statements after db initialize */ 00026 #ifdef USE_ORACLE 00027 int ido2db_oci_prepared_statement_objects_insert(ido2db_idi *idi); 00028 int ido2db_oci_prepared_statement_logentries_insert(ido2db_idi *idi); 00029 int ido2db_oci_prepared_statement_timedevents_queue(ido2db_idi *idi); 00030 int ido2db_oci_prepared_statement_timedeventqueue(ido2db_idi *idi); 00031 int ido2db_oci_prepared_statement_timedevents(ido2db_idi *idi); 00032 int ido2db_oci_prepared_statement_hoststatus(ido2db_idi *idi); 00033 int ido2db_oci_prepared_statement_hostchecks(ido2db_idi *idi); 00034 int ido2db_oci_prepared_statement_servicestatus(ido2db_idi *idi); 00035 int ido2db_oci_prepared_statement_servicechecks(ido2db_idi *idi); 00036 int ido2db_oci_prepared_statement_contact_notificationcommands(ido2db_idi *idi); 00037 int ido2db_oci_prepared_statement_programstatus(ido2db_idi *idi); 00038 int ido2db_oci_prepared_statement_systemcommanddata(ido2db_idi *idi); 00039 int ido2db_oci_prepared_statement_eventhandlerdata(ido2db_idi *idi); 00040 int ido2db_oci_prepared_statement_notificationdata(ido2db_idi *idi); 00041 int ido2db_oci_prepared_statement_contactnotificationdata(ido2db_idi *idi); 00042 int ido2db_oci_prepared_statement_contactnotificationmethoddata(ido2db_idi *idi); 00043 int ido2db_oci_prepared_statement_commentdata(ido2db_idi *idi); 00044 int ido2db_oci_prepared_statement_commentdata_history(ido2db_idi *idi); 00045 int ido2db_oci_prepared_statement_downtimedata_scheduled_downtime(ido2db_idi *idi); 00046 int ido2db_oci_prepared_statement_downtimedata_downtime_history(ido2db_idi *idi); 00047 int ido2db_oci_prepared_statement_contactstatusdata(ido2db_idi *idi); 00048 int ido2db_oci_prepared_statement_configfilevariables(ido2db_idi *idi); 00049 int ido2db_oci_prepared_statement_runtimevariables(ido2db_idi *idi); 00050 int ido2db_oci_prepared_statement_hostdefinition_definition(ido2db_idi *idi); 00051 int ido2db_oci_prepared_statement_hostdefinition_parenthosts(ido2db_idi *idi); 00052 int ido2db_oci_prepared_statement_hostdefinition_contactgroups(ido2db_idi *idi); 00053 int ido2db_oci_prepared_statement_hostdefinition_contacts(ido2db_idi *idi); 00054 int ido2db_oci_prepared_statement_hostgroupdefinition_definition(ido2db_idi *idi); 00055 int ido2db_oci_prepared_statement_hostgroupdefinition_hostgroupmembers(ido2db_idi *idi); 00056 int ido2db_oci_prepared_statement_servicedefinition_definition(ido2db_idi *idi); 00057 int ido2db_oci_prepared_statement_servicedefinition_contactgroups(ido2db_idi *idi); 00058 int ido2db_oci_prepared_statement_servicedefinition_contacts(ido2db_idi *idi); 00059 int ido2db_oci_prepared_statement_servicegroupdefinition_definition(ido2db_idi *idi); 00060 int ido2db_oci_prepared_statement_servicegroupdefinition_members(ido2db_idi *idi); 00061 int ido2db_oci_prepared_statement_hostdependencydefinition_definition(ido2db_idi *idi); 00062 int ido2db_oci_prepared_statement_servicedependencydefinition_definition(ido2db_idi *idi); 00063 int ido2db_oci_prepared_statement_hostescalationdefinition_definition(ido2db_idi *idi); 00064 int ido2db_oci_prepared_statement_hostescalationdefinition_contactgroups(ido2db_idi *idi); 00065 int ido2db_oci_prepared_statement_hostescalationdefinition_contacts(ido2db_idi *idi); 00066 int ido2db_oci_prepared_statement_serviceescalationdefinition_definition(ido2db_idi *idi); 00067 int ido2db_oci_prepared_statement_serviceescalationdefinition_contactgroups(ido2db_idi *idi); 00068 int ido2db_oci_prepared_statement_serviceescalationdefinition_contacts(ido2db_idi *idi); 00069 int ido2db_oci_prepared_statement_timeperiodefinition_definition(ido2db_idi *idi); 00070 int ido2db_oci_prepared_statement_timeperiodefinition_timeranges(ido2db_idi *idi); 00071 int ido2db_oci_prepared_statement_contactdefinition_definition(ido2db_idi *idi); 00072 int ido2db_oci_prepared_statement_contactdefinition_addresses(ido2db_idi *idi); 00073 int ido2db_oci_prepared_statement_contactdefinition_servicenotificationcommands(ido2db_idi *idi); 00074 int ido2db_oci_prepared_statement_save_custom_variables_customvariables(ido2db_idi *idi); 00075 int ido2db_oci_prepared_statement_save_custom_variables_customvariablestatus(ido2db_idi *idi); 00076 int ido2db_oci_prepared_statement_contactgroupdefinition_definition(ido2db_idi *idi); 00077 int ido2db_oci_prepared_statement_contactgroupdefinition_contactgroupmembers(ido2db_idi *idi); 00078 int ido2db_oci_prepared_statement_commanddefinition_definition(ido2db_idi *idi); 00079 int ido2db_oci_prepared_statement_process_events(ido2db_idi *idi); 00080 int ido2db_oci_prepared_statement_configfilevariables_insert(ido2db_idi *idi); 00081 int ido2db_oci_prepared_statement_flappinghistory(ido2db_idi *idi); 00082 int ido2db_oci_prepared_statement_external_commands(ido2db_idi *idi); 00083 int ido2db_oci_prepared_statement_acknowledgements(ido2db_idi *idi); 00084 int ido2db_oci_prepared_statement_statehistory(ido2db_idi *idi); 00085 int ido2db_oci_prepared_statement_instances(ido2db_idi *idi); 00086 int ido2db_oci_prepared_statement_conninfo(ido2db_idi *idi); 00087 /* this is screwed but should work ... */ 00088 int ido2db_oci_prepared_statement_objects_select_name1_name2(ido2db_idi *idi); 00089 int ido2db_oci_prepared_statement_objects_select_name1_null_name2(ido2db_idi *idi); 00090 int ido2db_oci_prepared_statement_objects_select_name1_name2_null(ido2db_idi *idi); 00091 int ido2db_oci_prepared_statement_objects_select_name1_null_name2_null(ido2db_idi *idi); 00092 /* select stuff */ 00093 int ido2db_oci_prepared_statement_objects_select_cached(ido2db_idi *idi); 00094 int ido2db_oci_prepared_statement_logentries_select(ido2db_idi *idi); 00095 int ido2db_oci_prepared_statement_instances_select(ido2db_idi *idi); 00096 00097 /* update stuff */ 00098 int ido2db_oci_prepared_statement_objects_update_inactive(ido2db_idi *idi); 00099 int ido2db_oci_prepared_statement_objects_update_active(ido2db_idi *idi); 00100 int ido2db_oci_prepared_statement_programstatus_update(ido2db_idi *idi); 00101 int ido2db_oci_prepared_statement_timedevents_update(ido2db_idi *idi); 00102 int ido2db_oci_prepared_statement_comment_history_update(ido2db_idi *idi); 00103 int ido2db_oci_prepared_statement_downtimehistory_update_start(ido2db_idi *idi); 00104 int ido2db_oci_prepared_statement_downtimehistory_update_stop(ido2db_idi *idi); 00105 int ido2db_oci_prepared_statement_conninfo_update(ido2db_idi *idi); 00106 int ido2db_oci_prepared_statement_conninfo_update_checkin(ido2db_idi *idi); 00107 00108 /* delete stuff */ 00109 int ido2db_oci_prepared_statement_timedeventqueue_delete(ido2db_idi *idi); 00110 int ido2db_oci_prepared_statement_timedeventqueue_delete_more(ido2db_idi *idi); 00111 int ido2db_oci_prepared_statement_comments_delete(ido2db_idi *idi); 00112 int ido2db_oci_prepared_statement_downtime_delete(ido2db_idi *idi); 00113 int ido2db_oci_prepared_statement_instances_delete(ido2db_idi *idi); 00114 int ido2db_oci_prepared_statement_instances_delete_time(ido2db_idi *idi); 00115 00116 /* db version stuff */ 00117 int ido2db_oci_prepared_statement_dbversion_select(ido2db_idi *idi); 00118 00119 #endif 00120 00121 extern ido2db_dbconfig ido2db_db_settings; 00122 extern time_t ido2db_db_last_checkin_time; 00123 00124 char *ido2db_db_rawtablenames[IDO2DB_MAX_DBTABLES]={ 00125 "instances", 00126 "conninfo", 00127 "objects", 00128 "objecttypes", 00129 "logentries", 00130 "systemcommands", 00131 "eventhandlers", 00132 "servicechecks", 00133 "hostchecks", 00134 "programstatus", 00135 "externalcommands", 00136 "servicestatus", 00137 "hoststatus", 00138 "processevents", 00139 "timedevents", 00140 "timedeventqueue", 00141 "flappinghistory", 00142 "commenthistory", 00143 "comments", 00144 "notifications", 00145 "contactnotifications", 00146 "contactnotificationmethods", 00147 "acknowledgements", 00148 "statehistory", 00149 "downtimehistory", 00150 "scheduleddowntime", 00151 "configfiles", 00152 "configfilevariables", 00153 "runtimevariables", 00154 "contactstatus", 00155 "customvariablestatus", 00156 "", 00157 "", 00158 "", 00159 "", 00160 "", 00161 "", 00162 "", 00163 "", 00164 "", 00165 "commands", 00166 "timeperiods", 00167 "timeperiod_timeranges", 00168 "contactgroups", 00169 "contactgroup_members", 00170 "hostgroups", 00171 "hostgroup_members", 00172 "servicegroups", 00173 "servicegroup_members", 00174 "hostescalations", 00175 "hostescalation_contacts", 00176 "serviceescalations", 00177 "serviceescalation_contacts", 00178 "hostdependencies", 00179 "servicedependencies", 00180 "contacts", 00181 "contact_addresses", 00182 "contact_notificationcommands", 00183 "hosts", 00184 "host_parenthosts", 00185 "host_contacts", 00186 "services", 00187 "service_contacts", 00188 "customvariables", 00189 "host_contactgroups", 00190 "service_contactgroups", 00191 "hostescalation_contactgroups", 00192 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00193 "serviceescalationcontactgroups", 00194 #else /* everything else will be libdbi */ 00195 "serviceescalation_contactgroups", 00196 #endif /* Oracle ocilib specific */ 00197 "dbversion" 00198 }; 00199 00200 char *ido2db_db_tablenames[IDO2DB_MAX_DBTABLES]; 00201 00202 /* 00203 #define DEBUG_IDO2DB_QUERIES 1 00204 */ 00205 00206 /****************************************************************************/ 00207 /* CONNECTION FUNCTIONS */ 00208 /****************************************************************************/ 00209 00210 00211 /************************************/ 00212 /* initialize database structures */ 00213 /************************************/ 00214 int ido2db_db_init(ido2db_idi *idi) { 00215 register int x; 00216 00217 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_init() start\n"); 00218 00219 if (idi == NULL) 00220 return IDO_ERROR; 00221 00222 /* initialize db server type */ 00223 idi->dbinfo.server_type = ido2db_db_settings.server_type; 00224 00225 /* initialize table names */ 00226 for (x = 0; x < IDO2DB_MAX_DBTABLES; x++) { 00227 00228 switch (idi->dbinfo.server_type) { 00229 case IDO2DB_DBSERVER_MYSQL: 00230 case IDO2DB_DBSERVER_PGSQL: 00231 case IDO2DB_DBSERVER_DB2: 00232 case IDO2DB_DBSERVER_FIREBIRD: 00233 case IDO2DB_DBSERVER_FREETDS: 00234 case IDO2DB_DBSERVER_INGRES: 00235 case IDO2DB_DBSERVER_MSQL: 00236 if ((ido2db_db_tablenames[x] = (char *) malloc(strlen(ido2db_db_rawtablenames[x]) + ((ido2db_db_settings.dbprefix==NULL) ? 0 : strlen(ido2db_db_settings.dbprefix)) + 1))==NULL) 00237 return IDO_ERROR; 00238 00239 sprintf(ido2db_db_tablenames[x], "%s%s", (ido2db_db_settings.dbprefix==NULL) ? "" : ido2db_db_settings.dbprefix,ido2db_db_rawtablenames[x]); 00240 break; 00241 case IDO2DB_DBSERVER_ORACLE: 00242 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00243 /* don't allow user to set table prefix for oracle */ 00244 if ((ido2db_db_tablenames[x]=strdup(ido2db_db_rawtablenames[x]))==NULL) 00245 return IDO_ERROR; 00246 00247 #endif /* Oracle ocilib specific */ 00248 break; 00249 case IDO2DB_DBSERVER_SQLITE: 00250 case IDO2DB_DBSERVER_SQLITE3: 00251 if ((ido2db_db_tablenames[x] = (char *) malloc(strlen(ido2db_db_rawtablenames[x]) + ((ido2db_db_settings.dbprefix==NULL) ? 0 : strlen(ido2db_db_settings.dbprefix)) + 1))==NULL) 00252 return IDO_ERROR; 00253 00254 sprintf(ido2db_db_tablenames[x], "%s%s", (ido2db_db_settings.dbprefix==NULL) ? "" : ido2db_db_settings.dbprefix,ido2db_db_rawtablenames[x]); 00255 break; 00256 default: 00257 break; 00258 } 00259 } 00260 00261 /* initialize other variables */ 00262 idi->dbinfo.connected = IDO_FALSE; 00263 idi->dbinfo.error = IDO_FALSE; 00264 idi->dbinfo.instance_id = 0L; 00265 idi->dbinfo.conninfo_id = 0L; 00266 idi->dbinfo.latest_program_status_time = (time_t) 0L; 00267 idi->dbinfo.latest_host_status_time = (time_t) 0L; 00268 idi->dbinfo.latest_service_status_time = (time_t) 0L; 00269 idi->dbinfo.latest_queued_event_time = (time_t) 0L; 00270 idi->dbinfo.latest_realtime_data_time = (time_t) 0L; 00271 idi->dbinfo.latest_comment_time = (time_t) 0L; 00272 idi->dbinfo.clean_event_queue = IDO_FALSE; 00273 idi->dbinfo.last_notification_id = 0L; 00274 idi->dbinfo.last_contact_notification_id = 0L; 00275 idi->dbinfo.max_timedevents_age = ido2db_db_settings.max_timedevents_age; 00276 idi->dbinfo.max_systemcommands_age = ido2db_db_settings.max_systemcommands_age; 00277 idi->dbinfo.max_servicechecks_age = ido2db_db_settings.max_servicechecks_age; 00278 idi->dbinfo.max_hostchecks_age = ido2db_db_settings.max_hostchecks_age; 00279 idi->dbinfo.max_eventhandlers_age = ido2db_db_settings.max_eventhandlers_age; 00280 idi->dbinfo.max_externalcommands_age=ido2db_db_settings.max_externalcommands_age; 00281 idi->dbinfo.max_logentries_age=ido2db_db_settings.max_logentries_age; 00282 idi->dbinfo.max_acknowledgements_age=ido2db_db_settings.max_acknowledgements_age; 00283 idi->dbinfo.trim_db_interval=ido2db_db_settings.trim_db_interval; 00284 idi->dbinfo.housekeeping_thread_startup_delay=ido2db_db_settings.housekeeping_thread_startup_delay; 00285 idi->dbinfo.last_table_trim_time = (time_t) 0L; 00286 idi->dbinfo.last_logentry_time = (time_t) 0L; 00287 idi->dbinfo.last_logentry_data = NULL; 00288 idi->dbinfo.object_hashlist = NULL; 00289 00290 /* initialize db structures, etc. */ 00291 #ifdef USE_LIBDBI /* everything else will be libdbi */ 00292 00293 if (dbi_initialize(NULL) == -1) { 00294 syslog(LOG_USER | LOG_INFO, "Error: dbi_initialize() failed\n"); 00295 return IDO_ERROR; 00296 } 00297 #endif 00298 00299 #ifdef USE_PGSQL /* pgsql */ 00300 00301 /* check if config matches */ 00302 if(idi->dbinfo.server_type != IDO2DB_DBSERVER_PGSQL) { 00303 syslog(LOG_USER | LOG_INFO, "Error: ido2db.cfg not correctly configured. Please recheck for PGSQL!\n"); 00304 return IDO_ERROR; 00305 } 00306 00307 idi->dbinfo.pg_conn=NULL; 00308 idi->dbinfo.pg_result=NULL; 00309 00310 #endif 00311 00312 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00313 00314 /* check if config matches */ 00315 if(idi->dbinfo.server_type != IDO2DB_DBSERVER_ORACLE) { 00316 syslog(LOG_USER | LOG_INFO, "Error: ido2db.cfg not correctly configured. Please recheck for Oracle!\n"); 00317 return IDO_ERROR; 00318 } 00319 00320 /* register error handler and init oci */ 00321 if(!OCI_Initialize(ido2db_ocilib_err_handler, NULL, OCI_ENV_CONTEXT)) { 00322 syslog(LOG_USER | LOG_INFO, "Error: OCI_Initialize() failed\n"); 00323 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "OCI_Initialize() failed\n"); 00324 return IDO_ERROR; 00325 } 00326 00327 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "OCI_Initialize() ok\n"); 00328 00329 #endif /* Oracle ocilib specific */ 00330 00331 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_init() end\n"); 00332 return IDO_OK; 00333 } 00334 00335 /************************************/ 00336 /* clean up database structures */ 00337 /************************************/ 00338 int ido2db_db_deinit(ido2db_idi *idi) { 00339 register int x; 00340 00341 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_deinit() start\n"); 00342 00343 if (idi == NULL) 00344 return IDO_ERROR; 00345 00346 /* free table names */ 00347 for (x = 0; x < IDO2DB_MAX_DBTABLES; x++) { 00348 if (ido2db_db_tablenames[x]) 00349 free(ido2db_db_tablenames[x]); 00350 ido2db_db_tablenames[x] = NULL; 00351 } 00352 00353 /* free cached object ids */ 00354 ido2db_free_cached_object_ids(idi); 00355 00356 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_deinit() end\n"); 00357 return IDO_OK; 00358 } 00359 00360 /************************************/ 00361 /* connects to the database server */ 00362 /************************************/ 00363 00364 int ido2db_db_is_connected(ido2db_idi *idi) { 00365 00366 #ifdef USE_LIBDBI 00367 if(!dbi_conn_ping(idi->dbinfo.dbi_conn)) 00368 return IDO_FALSE; 00369 #endif 00370 00371 #ifdef USE_PGSQL 00372 if(PQstatus(idi->dbinfo.pg_conn)!=CONNECTION_OK) 00373 return IDO_FALSE; 00374 #endif 00375 00376 #ifdef USE_ORACLE 00377 if(!OCI_IsConnected(idi->dbinfo.oci_connection)) 00378 return IDO_FALSE; 00379 #endif 00380 00381 return IDO_TRUE; 00382 } 00383 00384 int ido2db_db_reconnect(ido2db_idi *idi) { 00385 00386 /* check connection */ 00387 if(ido2db_db_is_connected(idi)==IDO_FALSE) 00388 idi->dbinfo.connected=IDO_FALSE; 00389 00390 /* try to reconnect... */ 00391 if(idi->dbinfo.connected==IDO_FALSE) { 00392 if(ido2db_db_connect(idi)==IDO_ERROR){ 00393 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_reconnect(): failed.\n"); 00394 syslog(LOG_USER | LOG_INFO, "Error: Could not reconnect to database!"); 00395 return IDO_ERROR; 00396 } 00397 ido2db_db_hello(idi); 00398 } 00399 00400 return IDO_OK; 00401 } 00402 00403 00404 int ido2db_db_connect(ido2db_idi *idi) { 00405 int result = IDO_OK; 00406 #ifdef USE_PGSQL /* pgsql */ 00407 char *temp_port = NULL; 00408 #endif 00409 #ifdef USE_LIBDBI 00410 const char *dbi_error; 00411 #endif 00412 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() start\n"); 00413 00414 if (idi == NULL) 00415 return IDO_ERROR; 00416 00417 /* we're already connected... (and we don't wanna double check with ido2db_db_is_connected) */ 00418 if(idi->dbinfo.connected==IDO_TRUE){ 00419 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "\tido2db_db_connect(): already connected. Dropping out.\n"); 00420 return IDO_OK; 00421 } 00422 00423 #ifdef USE_LIBDBI /* Oracle ocilib specific */ 00424 switch (idi->dbinfo.server_type) { 00425 case IDO2DB_DBSERVER_MYSQL: 00426 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_MYSQL); 00427 break; 00428 case IDO2DB_DBSERVER_PGSQL: 00429 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_PGSQL); 00430 break; 00431 case IDO2DB_DBSERVER_DB2: 00432 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_DB2); 00433 break; 00434 case IDO2DB_DBSERVER_FIREBIRD: 00435 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_FIREBIRD); 00436 break; 00437 case IDO2DB_DBSERVER_FREETDS: 00438 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_FREETDS); 00439 break; 00440 case IDO2DB_DBSERVER_INGRES: 00441 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_INGRES); 00442 break; 00443 case IDO2DB_DBSERVER_MSQL: 00444 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_MSQL); 00445 break; 00446 case IDO2DB_DBSERVER_ORACLE: 00447 break; 00448 case IDO2DB_DBSERVER_SQLITE: 00449 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_SQLITE); 00450 break; 00451 case IDO2DB_DBSERVER_SQLITE3: 00452 idi->dbinfo.dbi_conn = dbi_conn_new(IDO2DB_DBI_DRIVER_SQLITE3); 00453 break; 00454 default: 00455 break; 00456 } 00457 #endif 00458 00459 #ifdef USE_PGSQL /* pgsql */ 00460 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() pgsql start somewhere\n"); 00461 #endif 00462 00463 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00464 00465 /* for ocilib there is no such statement next below */ 00466 00467 #endif /* Oracle ocilib specific */ 00468 00469 00470 #ifdef USE_LIBDBI /* everything else will be libdbi */ 00471 00472 /* Check if the dbi connection was created successful */ 00473 if (idi->dbinfo.dbi_conn == NULL) { 00474 dbi_conn_error(idi->dbinfo.dbi_conn, &dbi_error); 00475 syslog(LOG_USER | LOG_INFO, "Error: Could not dbi_conn_new(): %s", dbi_error); 00476 result = IDO_ERROR; 00477 idi->disconnect_client = IDO_TRUE; 00478 return IDO_ERROR; 00479 } 00480 00481 dbi_conn_set_option(idi->dbinfo.dbi_conn, "host", ido2db_db_settings.host); 00482 dbi_conn_set_option_numeric(idi->dbinfo.dbi_conn, "port", (int)ido2db_db_settings.port); 00483 dbi_conn_set_option(idi->dbinfo.dbi_conn, "username", ido2db_db_settings.username); 00484 dbi_conn_set_option(idi->dbinfo.dbi_conn, "password", ido2db_db_settings.password); 00485 dbi_conn_set_option(idi->dbinfo.dbi_conn, "dbname", ido2db_db_settings.dbname); 00486 dbi_conn_set_option(idi->dbinfo.dbi_conn, "encoding", "auto"); 00487 00488 if(ido2db_db_settings.dbsocket!=NULL){ 00489 /* a local db socket was desired, drop db_port settings in case */ 00490 dbi_conn_clear_option(idi->dbinfo.dbi_conn, "port"); 00491 00492 switch (idi->dbinfo.server_type) { 00493 case IDO2DB_DBSERVER_MYSQL: 00494 dbi_conn_set_option(idi->dbinfo.dbi_conn, "mysql_unix_socket", ido2db_db_settings.dbsocket); 00495 break; 00496 case IDO2DB_DBSERVER_PGSQL: 00497 /* override the port as stated in libdbi-driver docs */ 00498 dbi_conn_set_option(idi->dbinfo.dbi_conn, "port", ido2db_db_settings.dbsocket); 00499 break; 00500 default: 00501 break; 00502 } 00503 } 00504 00505 if (dbi_conn_connect(idi->dbinfo.dbi_conn) != 0) { 00506 dbi_conn_error(idi->dbinfo.dbi_conn, &dbi_error); 00507 syslog(LOG_USER | LOG_INFO, "Error: Could not connect to %s database: %s", ido2db_db_settings.dbserver, dbi_error); 00508 result = IDO_ERROR; 00509 idi->disconnect_client = IDO_TRUE; 00510 } else { 00511 idi->dbinfo.connected = IDO_TRUE; 00512 syslog(LOG_USER | LOG_INFO, "Successfully connected to %s database", ido2db_db_settings.dbserver); 00513 } 00514 #endif 00515 00516 #ifdef USE_PGSQL /* pgsql */ 00517 00518 dummy=asprintf(&temp_port, "%d", ido2db_db_settings.port); 00519 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() pgsql start\n"); 00520 00521 /* check if config matches */ 00522 if(idi->dbinfo.server_type != IDO2DB_DBSERVER_PGSQL) { 00523 syslog(LOG_USER | LOG_INFO, "Error: ido2db.cfg not correctly configured. Please recheck for PGSQL!\n"); 00524 return IDO_ERROR; 00525 } 00526 00527 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() pgsql trying to connect host: %s, port: %s, dbname: %s, user: %s, pass: %s\n", ido2db_db_settings.host, temp_port, ido2db_db_settings.dbname,ido2db_db_settings.username,ido2db_db_settings.password); 00528 00529 /* create db connection instantly */ 00530 idi->dbinfo.pg_conn = PQsetdbLogin(ido2db_db_settings.host, 00531 "",/*temp_port,*/ 00532 "", /* pgoptions */ 00533 "", /* pgtty*/ 00534 ido2db_db_settings.dbname, 00535 ido2db_db_settings.username, 00536 ido2db_db_settings.password); 00537 free(temp_port); 00538 00539 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() pgsql segfault?\n"); 00540 00541 if(PQstatus(idi->dbinfo.pg_conn) != CONNECTION_OK) { 00542 syslog(LOG_USER | LOG_INFO, "Error: Could not connect to pgsql database: %s", PQerrorMessage(idi->dbinfo.pg_conn)); 00543 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "Error: Could not connect to %s database\n", ido2db_db_settings.dbserver); 00544 result = IDO_ERROR; 00545 idi->disconnect_client = IDO_TRUE; 00546 } else { 00547 idi->dbinfo.connected = IDO_TRUE; 00548 syslog(LOG_USER | LOG_INFO, "Successfully connected to pgsql database"); 00549 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "Successfully connected to %s database\n", ido2db_db_settings.dbserver); 00550 } 00551 #endif 00552 00553 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00554 00555 /* check if config matches */ 00556 if(idi->dbinfo.server_type != IDO2DB_DBSERVER_ORACLE) { 00557 syslog(LOG_USER | LOG_INFO, "Error: ido2db.cfg not correctly configured. Please recheck for Oracle!\n"); 00558 return IDO_ERROR; 00559 } 00560 00561 /* create db connection instantly */ 00562 idi->dbinfo.oci_connection = OCI_ConnectionCreate((mtext *)ido2db_db_settings.dbname, (mtext *)ido2db_db_settings.username, (mtext *)ido2db_db_settings.password, OCI_SESSION_DEFAULT); 00563 00564 if(idi->dbinfo.oci_connection == NULL) { 00565 syslog(LOG_USER | LOG_INFO, "Error: Could not connect to oracle database: %s", OCI_ErrorGetString(OCI_GetLastError())); 00566 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "Error: Could not connect to %s database\n", ido2db_db_settings.dbserver); 00567 result = IDO_ERROR; 00568 idi->disconnect_client = IDO_TRUE; 00569 } else { 00570 idi->dbinfo.connected = IDO_TRUE; 00571 syslog(LOG_USER | LOG_INFO, "Successfully connected to oracle database"); 00572 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "Successfully connected to %s database\n", ido2db_db_settings.dbserver); 00573 } 00574 00575 /* initialize prepared statements */ 00576 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() prepare statements start\n"); 00577 00578 /* object inserts */ 00579 if(ido2db_oci_prepared_statement_objects_insert(idi) == IDO_ERROR) { 00580 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_objects_insert() failed\n"); 00581 return IDO_ERROR; 00582 } 00583 00584 /* logentries */ 00585 if(ido2db_oci_prepared_statement_logentries_insert(idi) == IDO_ERROR) { 00586 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_logentries_insert() failed\n"); 00587 return IDO_ERROR; 00588 } 00589 00590 /* timed events */ 00591 if(ido2db_oci_prepared_statement_timedevents_queue(idi) == IDO_ERROR) { 00592 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents_queue() failed\n"); 00593 return IDO_ERROR; 00594 } 00595 00596 if(ido2db_oci_prepared_statement_timedevents(idi) == IDO_ERROR) { 00597 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents() failed\n"); 00598 return IDO_ERROR; 00599 } 00600 00601 if(ido2db_oci_prepared_statement_timedeventqueue(idi) == IDO_ERROR) { 00602 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedeventqueue() failed\n"); 00603 return IDO_ERROR; 00604 } 00605 00606 /* hoststatus/check */ 00607 if(ido2db_oci_prepared_statement_hoststatus(idi) == IDO_ERROR) { 00608 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hoststatus() failed\n"); 00609 return IDO_ERROR; 00610 } 00611 00612 if(ido2db_oci_prepared_statement_hostchecks(idi) == IDO_ERROR) { 00613 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostchecks() failed\n"); 00614 return IDO_ERROR; 00615 } 00616 00617 /* servicestatus/check */ 00618 if(ido2db_oci_prepared_statement_servicestatus(idi) == IDO_ERROR) { 00619 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicestatus() failed\n"); 00620 return IDO_ERROR; 00621 } 00622 00623 if(ido2db_oci_prepared_statement_servicechecks(idi) == IDO_ERROR) { 00624 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicechecks() failed\n"); 00625 return IDO_ERROR; 00626 } 00627 00628 /* contactnotifications */ 00629 if(ido2db_oci_prepared_statement_contact_notificationcommands(idi) == IDO_ERROR) { 00630 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contact_notificationcommands() failed\n"); 00631 return IDO_ERROR; 00632 } 00633 00634 /* programstatus */ 00635 if(ido2db_oci_prepared_statement_programstatus(idi) == IDO_ERROR) { 00636 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_programstatus() failed\n"); 00637 return IDO_ERROR; 00638 } 00639 00640 /* systemcommand */ 00641 if(ido2db_oci_prepared_statement_systemcommanddata(idi) == IDO_ERROR) { 00642 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_systemcommanddata() failed\n"); 00643 return IDO_ERROR; 00644 } 00645 00646 /* commanddefinition_definition */ 00647 if(ido2db_oci_prepared_statement_commanddefinition_definition(idi) == IDO_ERROR) { 00648 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commanddefinition_definition() failed\n"); 00649 return IDO_ERROR; 00650 } 00651 00652 /* eventhandler */ 00653 if(ido2db_oci_prepared_statement_eventhandlerdata(idi) == IDO_ERROR) { 00654 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_eventhandlerdata() failed\n"); 00655 return IDO_ERROR; 00656 } 00657 00658 /* notificationdata */ 00659 if(ido2db_oci_prepared_statement_notificationdata(idi) == IDO_ERROR) { 00660 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_notificationdata() failed\n"); 00661 return IDO_ERROR; 00662 } 00663 00664 /* contactnotificationdata */ 00665 if(ido2db_oci_prepared_statement_contactnotificationdata(idi) == IDO_ERROR) { 00666 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactnotificationdata() failed\n"); 00667 return IDO_ERROR; 00668 } 00669 00670 /* contactnotificationmethoddata */ 00671 if(ido2db_oci_prepared_statement_contactnotificationmethoddata(idi) == IDO_ERROR) { 00672 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactnotificationmethoddata() failed\n"); 00673 return IDO_ERROR; 00674 } 00675 00676 /* commentdata */ 00677 if(ido2db_oci_prepared_statement_commentdata(idi) == IDO_ERROR) { 00678 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commentdata() failed\n"); 00679 return IDO_ERROR; 00680 } 00681 00682 /* commentdata history */ 00683 if(ido2db_oci_prepared_statement_commentdata_history(idi) == IDO_ERROR) { 00684 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commentdata_history() failed\n"); 00685 return IDO_ERROR; 00686 } 00687 00688 /* downtimedata scheduled_downtime */ 00689 if(ido2db_oci_prepared_statement_downtimedata_scheduled_downtime(idi) == IDO_ERROR) { 00690 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_downtimedata_scheduled_downtime() failed\n"); 00691 return IDO_ERROR; 00692 } 00693 00694 /* downtimedata downtime_history */ 00695 if(ido2db_oci_prepared_statement_downtimedata_downtime_history(idi) == IDO_ERROR) { 00696 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_downtimedata_downtime_history() failed\n"); 00697 return IDO_ERROR; 00698 } 00699 00700 /* contactstatusdata */ 00701 if(ido2db_oci_prepared_statement_contactstatusdata(idi) == IDO_ERROR) { 00702 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactstatusdata() failed\n"); 00703 return IDO_ERROR; 00704 } 00705 00706 /* configfilevariables */ 00707 if(ido2db_oci_prepared_statement_configfilevariables(idi) == IDO_ERROR) { 00708 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_configfilevariables() failed\n"); 00709 return IDO_ERROR; 00710 } 00711 00712 if(ido2db_oci_prepared_statement_configfilevariables_insert(idi) == IDO_ERROR) { 00713 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_configfilevariables_insert() failed\n"); 00714 return IDO_ERROR; 00715 } 00716 00717 /* runtimevariables */ 00718 if(ido2db_oci_prepared_statement_runtimevariables(idi) == IDO_ERROR) { 00719 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_runtimevariables() failed\n"); 00720 return IDO_ERROR; 00721 } 00722 00723 /* hostdefinition_definition */ 00724 if(ido2db_oci_prepared_statement_hostdefinition_definition(idi) == IDO_ERROR) { 00725 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostdefinition_definition() failed\n"); 00726 return IDO_ERROR; 00727 } 00728 00729 /* hostdefinition_parenthosts */ 00730 if(ido2db_oci_prepared_statement_hostdefinition_parenthosts(idi) == IDO_ERROR) { 00731 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostdefinition_parenthosts() failed\n"); 00732 return IDO_ERROR; 00733 } 00734 00735 /* hostdefinition_contactgroups */ 00736 if(ido2db_oci_prepared_statement_hostdefinition_contactgroups(idi) == IDO_ERROR) { 00737 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostdefinition_contactgroups() failed\n"); 00738 return IDO_ERROR; 00739 } 00740 00741 /* hostdefinition_contacts */ 00742 if(ido2db_oci_prepared_statement_hostdefinition_contacts(idi) == IDO_ERROR) { 00743 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostdefinition_contacts() failed\n"); 00744 return IDO_ERROR; 00745 } 00746 00747 /* hostgroupdefinition_definition */ 00748 if(ido2db_oci_prepared_statement_hostgroupdefinition_definition(idi) == IDO_ERROR) { 00749 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostgroupdefinition_definition() failed\n"); 00750 return IDO_ERROR; 00751 } 00752 00753 /* hostgroupdefinition_hostgroupmembers */ 00754 if(ido2db_oci_prepared_statement_hostgroupdefinition_hostgroupmembers(idi) == IDO_ERROR) { 00755 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostgroupdefinition_hostgroupmembers() failed\n"); 00756 return IDO_ERROR; 00757 } 00758 00759 /* servicedefinition_definition */ 00760 if(ido2db_oci_prepared_statement_servicedefinition_definition(idi) == IDO_ERROR) { 00761 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicedefinition_definition() failed\n"); 00762 return IDO_ERROR; 00763 } 00764 00765 /* servicedefinition_contactgroups */ 00766 if(ido2db_oci_prepared_statement_servicedefinition_contactgroups(idi) == IDO_ERROR) { 00767 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicedefinition_contactgroups() failed\n"); 00768 return IDO_ERROR; 00769 } 00770 00771 /* servicedefinition_contacts */ 00772 if(ido2db_oci_prepared_statement_servicedefinition_contacts(idi) == IDO_ERROR) { 00773 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicedefinition_contacts() failed\n"); 00774 return IDO_ERROR; 00775 } 00776 00777 /* servicegroupdefinition_definition */ 00778 if(ido2db_oci_prepared_statement_servicegroupdefinition_definition(idi) == IDO_ERROR) { 00779 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicegroupdefinition_definition() failed\n"); 00780 return IDO_ERROR; 00781 } 00782 00783 /* servicegroupdefinition_members */ 00784 if(ido2db_oci_prepared_statement_servicegroupdefinition_members(idi) == IDO_ERROR) { 00785 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicegroupdefinition_members() failed\n"); 00786 return IDO_ERROR; 00787 } 00788 00789 /* hostdependencydefinition_definition */ 00790 if(ido2db_oci_prepared_statement_hostdependencydefinition_definition(idi) == IDO_ERROR) { 00791 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostdependencydefinition_definition() failed\n"); 00792 return IDO_ERROR; 00793 } 00794 00795 /* servicedependencydefinition_definition */ 00796 if(ido2db_oci_prepared_statement_servicedependencydefinition_definition(idi) == IDO_ERROR) { 00797 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicedependencydefinition_definition() failed\n"); 00798 return IDO_ERROR; 00799 } 00800 00801 /* hostescalationdefinition_definition */ 00802 if(ido2db_oci_prepared_statement_hostescalationdefinition_definition(idi) == IDO_ERROR) { 00803 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostescalationdefinition_definition() failed\n"); 00804 return IDO_ERROR; 00805 } 00806 00807 /* hostescalationdefinition_contactgroups */ 00808 if(ido2db_oci_prepared_statement_hostescalationdefinition_contactgroups(idi) == IDO_ERROR) { 00809 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostescalationdefinition_contactgroups() failed\n"); 00810 return IDO_ERROR; 00811 } 00812 00813 /* hostescalationdefinition_contacts */ 00814 if(ido2db_oci_prepared_statement_hostescalationdefinition_contacts(idi) == IDO_ERROR) { 00815 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostescalationdefinition_contacts() failed\n"); 00816 return IDO_ERROR; 00817 } 00818 00819 /* serviceescalationdefinition_definition */ 00820 if(ido2db_oci_prepared_statement_serviceescalationdefinition_definition(idi) == IDO_ERROR) { 00821 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_serviceescalationdefinition_definition() failed\n"); 00822 return IDO_ERROR; 00823 } 00824 00825 /* serviceescalationdefinition_contactgroups */ 00826 if(ido2db_oci_prepared_statement_serviceescalationdefinition_contactgroups(idi) == IDO_ERROR) { 00827 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_serviceescalationdefinition_contactgroups() failed\n"); 00828 return IDO_ERROR; 00829 } 00830 00831 /* serviceescalationdefinition_contacts */ 00832 if(ido2db_oci_prepared_statement_serviceescalationdefinition_contacts(idi) == IDO_ERROR) { 00833 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_serviceescalationdefinition_contacts() failed\n"); 00834 return IDO_ERROR; 00835 } 00836 00837 /* timeperiodefinition_definition */ 00838 if(ido2db_oci_prepared_statement_timeperiodefinition_definition(idi) == IDO_ERROR) { 00839 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timeperiodefinition_definition() failed\n"); 00840 return IDO_ERROR; 00841 } 00842 00843 /* timeperiodefinition_timeranges */ 00844 if(ido2db_oci_prepared_statement_timeperiodefinition_timeranges(idi) == IDO_ERROR) { 00845 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timeperiodefinition_timeranges() failed\n"); 00846 return IDO_ERROR; 00847 } 00848 00849 /* contactdefinition_definition */ 00850 if(ido2db_oci_prepared_statement_contactdefinition_definition(idi) == IDO_ERROR) { 00851 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactdefinition_definition() failed\n"); 00852 return IDO_ERROR; 00853 } 00854 00855 /* contactdefinition_addresses */ 00856 if(ido2db_oci_prepared_statement_contactdefinition_addresses(idi) == IDO_ERROR) { 00857 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactdefinition_addresses() failed\n"); 00858 return IDO_ERROR; 00859 } 00860 00861 /* contactdefinition_servicenotificationcommands */ 00862 if(ido2db_oci_prepared_statement_contactdefinition_servicenotificationcommands(idi) == IDO_ERROR) { 00863 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactdefinition_servicenotificationcommands() failed\n"); 00864 return IDO_ERROR; 00865 } 00866 00867 /* save_custom_variables_customvariables */ 00868 if(ido2db_oci_prepared_statement_save_custom_variables_customvariables(idi) == IDO_ERROR) { 00869 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_save_custom_variables_customvariables() failed\n"); 00870 return IDO_ERROR; 00871 } 00872 00873 /* save_custom_variables_customvariablestatus */ 00874 if(ido2db_oci_prepared_statement_save_custom_variables_customvariablestatus(idi) == IDO_ERROR) { 00875 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_save_custom_variables_customvariablestatus() failed\n"); 00876 return IDO_ERROR; 00877 } 00878 00879 /* contactgroupdefinition_definition */ 00880 if(ido2db_oci_prepared_statement_contactgroupdefinition_definition(idi) == IDO_ERROR) { 00881 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactgroupdefinition_definition() failed\n"); 00882 return IDO_ERROR; 00883 } 00884 00885 /* contactgroupdefinition_contactgroupmembers */ 00886 if(ido2db_oci_prepared_statement_contactgroupdefinition_contactgroupmembers(idi) == IDO_ERROR) { 00887 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactgroupdefinition_contactgroupmembers() failed\n"); 00888 return IDO_ERROR; 00889 } 00890 00891 /* process_events */ 00892 if(ido2db_oci_prepared_statement_process_events(idi) == IDO_ERROR) { 00893 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_process_events() failed\n"); 00894 return IDO_ERROR; 00895 } 00896 00897 /* flapping history */ 00898 if(ido2db_oci_prepared_statement_flappinghistory(idi) == IDO_ERROR) { 00899 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_flappinghistory() failed\n"); 00900 return IDO_ERROR; 00901 } 00902 00903 /* external commands */ 00904 if(ido2db_oci_prepared_statement_external_commands(idi) == IDO_ERROR) { 00905 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_external_commands() failed\n"); 00906 return IDO_ERROR; 00907 } 00908 00909 /* acknowledgements */ 00910 if(ido2db_oci_prepared_statement_acknowledgements(idi) == IDO_ERROR) { 00911 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_acknowledgements() failed\n"); 00912 return IDO_ERROR; 00913 } 00914 00915 /* statehistory */ 00916 if(ido2db_oci_prepared_statement_statehistory(idi) == IDO_ERROR) { 00917 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_statehistory() failed\n"); 00918 return IDO_ERROR; 00919 } 00920 00921 /* instances */ 00922 if(ido2db_oci_prepared_statement_instances(idi) == IDO_ERROR) { 00923 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_instances() failed\n"); 00924 return IDO_ERROR; 00925 } 00926 00927 /* conninfo */ 00928 if(ido2db_oci_prepared_statement_conninfo(idi) == IDO_ERROR) { 00929 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_connfino() failed\n"); 00930 return IDO_ERROR; 00931 } 00932 00933 /* objects select I: name1, name2 II: name1 IS NULL, name2 III: name1, name2 IS NULL IV: name1 IS NULL, name2 IS NULL */ 00934 if(ido2db_oci_prepared_statement_objects_select_name1_name2(idi) == IDO_ERROR) { 00935 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 00936 return IDO_ERROR; 00937 } 00938 00939 /* */ 00940 if(ido2db_oci_prepared_statement_objects_select_name1_null_name2(idi) == IDO_ERROR) { 00941 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 00942 return IDO_ERROR; 00943 } 00944 00945 /* */ 00946 if(ido2db_oci_prepared_statement_objects_select_name1_name2_null(idi) == IDO_ERROR) { 00947 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 00948 return IDO_ERROR; 00949 } 00950 00951 /* */ 00952 if(ido2db_oci_prepared_statement_objects_select_name1_null_name2_null(idi) == IDO_ERROR) { 00953 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 00954 return IDO_ERROR; 00955 } 00956 00957 /* objects select cached */ 00958 if(ido2db_oci_prepared_statement_objects_select_cached(idi) == IDO_ERROR) { 00959 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 00960 return IDO_ERROR; 00961 } 00962 00963 /* objects update inactive */ 00964 if(ido2db_oci_prepared_statement_objects_update_inactive(idi) == IDO_ERROR) { 00965 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_objects_update_inactive() failed\n"); 00966 return IDO_ERROR; 00967 } 00968 00969 /* objects update active */ 00970 if(ido2db_oci_prepared_statement_objects_update_active(idi) == IDO_ERROR) { 00971 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_objects_update_active() failed\n"); 00972 return IDO_ERROR; 00973 } 00974 00975 /* logentries select */ 00976 if(ido2db_oci_prepared_statement_logentries_select(idi) == IDO_ERROR) { 00977 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_logentries_select() failed\n"); 00978 return IDO_ERROR; 00979 } 00980 00981 /* programstatus update */ 00982 if(ido2db_oci_prepared_statement_programstatus_update(idi) == IDO_ERROR) { 00983 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_programstatus_update() failed\n"); 00984 return IDO_ERROR; 00985 } 00986 00987 /* timedevents update */ 00988 if(ido2db_oci_prepared_statement_timedevents_update(idi) == IDO_ERROR) { 00989 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents_update() failed\n"); 00990 return IDO_ERROR; 00991 } 00992 00993 /* timdeventqueue delete */ 00994 if(ido2db_oci_prepared_statement_timedeventqueue_delete(idi) == IDO_ERROR) { 00995 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 00996 return IDO_ERROR; 00997 } 00998 00999 /* timdeventqueue delete more*/ 01000 if(ido2db_oci_prepared_statement_timedeventqueue_delete_more(idi) == IDO_ERROR) { 01001 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01002 return IDO_ERROR; 01003 } 01004 01005 /* comment history update */ 01006 if(ido2db_oci_prepared_statement_comment_history_update(idi) == IDO_ERROR) { 01007 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01008 return IDO_ERROR; 01009 } 01010 01011 /* comments delete */ 01012 if(ido2db_oci_prepared_statement_comments_delete(idi) == IDO_ERROR) { 01013 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01014 return IDO_ERROR; 01015 } 01016 01017 /* downtimehistory_update start */ 01018 if(ido2db_oci_prepared_statement_downtimehistory_update_start(idi) == IDO_ERROR) { 01019 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01020 return IDO_ERROR; 01021 } 01022 01023 /* downtimehistory_update stop */ 01024 if(ido2db_oci_prepared_statement_downtimehistory_update_stop(idi) == IDO_ERROR) { 01025 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01026 return IDO_ERROR; 01027 } 01028 01029 /* downtime delete */ 01030 if(ido2db_oci_prepared_statement_downtime_delete(idi) == IDO_ERROR) { 01031 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01032 return IDO_ERROR; 01033 } 01034 01035 /* instances select */ 01036 if(ido2db_oci_prepared_statement_instances_select(idi) == IDO_ERROR) { 01037 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01038 return IDO_ERROR; 01039 } 01040 01041 /* conninfo update */ 01042 if(ido2db_oci_prepared_statement_conninfo_update(idi) == IDO_ERROR) { 01043 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01044 return IDO_ERROR; 01045 } 01046 01047 /* conninfo update */ 01048 if(ido2db_oci_prepared_statement_conninfo_update_checkin(idi) == IDO_ERROR) { 01049 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() failed\n"); 01050 return IDO_ERROR; 01051 } 01052 01053 /* instances delete */ 01054 if(ido2db_oci_prepared_statement_instances_delete(idi) == IDO_ERROR) { 01055 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_instances_delete() failed\n"); 01056 return IDO_ERROR; 01057 } 01058 01059 /* instances delete time */ 01060 if(ido2db_oci_prepared_statement_instances_delete_time(idi) == IDO_ERROR) { 01061 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_instances_delete_time() failed\n"); 01062 return IDO_ERROR; 01063 } 01064 01065 /* dbversion */ 01066 if(ido2db_oci_prepared_statement_dbversion_select(idi) == IDO_ERROR) { 01067 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_dbversion_select() failed\n"); 01068 return IDO_ERROR; 01069 } 01070 01071 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() prepare statements end\n"); 01072 01073 #endif /* Oracle ocilib specific */ 01074 01075 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect(%d) end\n", result); 01076 return result; 01077 } 01078 01079 /****************************************/ 01080 /* disconnects from the database server */ 01081 /****************************************/ 01082 int ido2db_db_disconnect(ido2db_idi *idi) { 01083 01084 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_disconnect() start\n"); 01085 01086 if (idi == NULL) 01087 return IDO_ERROR; 01088 01089 /* we're not connected... */ 01090 if(ido2db_db_is_connected(idi)==IDO_FALSE) 01091 return IDO_OK; 01092 01093 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01094 dbi_conn_close(idi->dbinfo.dbi_conn); 01095 dbi_shutdown(); 01096 01097 syslog(LOG_USER | LOG_INFO, "Successfully disconnected from %s database", ido2db_db_settings.dbserver); 01098 #endif 01099 01100 #ifdef USE_PGSQL /* pgsql */ 01101 01102 PQfinish(idi->dbinfo.pg_conn); 01103 01104 syslog(LOG_USER | LOG_INFO, "Successfully disconnected from %s database", ido2db_db_settings.dbserver); 01105 01106 #endif 01107 01108 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01109 01110 /* close prepared statements */ 01111 OCI_StatementFree(idi->dbinfo.oci_statement_timedevents); 01112 OCI_StatementFree(idi->dbinfo.oci_statement_timedevents_queue); 01113 OCI_StatementFree(idi->dbinfo.oci_statement_timedeventqueue); 01114 01115 OCI_StatementFree(idi->dbinfo.oci_statement_hostchecks); 01116 OCI_StatementFree(idi->dbinfo.oci_statement_hoststatus); 01117 01118 OCI_StatementFree(idi->dbinfo.oci_statement_servicechecks); 01119 OCI_StatementFree(idi->dbinfo.oci_statement_servicestatus); 01120 01121 OCI_StatementFree(idi->dbinfo.oci_statement_contact_notificationcommands); 01122 OCI_StatementFree(idi->dbinfo.oci_statement_objects_insert); 01123 OCI_StatementFree(idi->dbinfo.oci_statement_logentries_insert); 01124 OCI_StatementFree(idi->dbinfo.oci_statement_programstatus); 01125 OCI_StatementFree(idi->dbinfo.oci_statement_systemcommanddata); 01126 OCI_StatementFree(idi->dbinfo.oci_statement_eventhandlerdata); 01127 OCI_StatementFree(idi->dbinfo.oci_statement_notificationdata); 01128 01129 OCI_StatementFree(idi->dbinfo.oci_statement_contactnotificationdata); 01130 OCI_StatementFree(idi->dbinfo.oci_statement_contactnotificationmethoddata); 01131 01132 OCI_StatementFree(idi->dbinfo.oci_statement_commentdata); 01133 OCI_StatementFree(idi->dbinfo.oci_statement_commentdata_history); 01134 01135 OCI_StatementFree(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime); 01136 OCI_StatementFree(idi->dbinfo.oci_statement_downtimedata_downtime_history); 01137 01138 OCI_StatementFree(idi->dbinfo.oci_statement_contactstatusdata); 01139 01140 OCI_StatementFree(idi->dbinfo.oci_statement_configfilevariables); 01141 OCI_StatementFree(idi->dbinfo.oci_statement_configfilevariables_insert); 01142 01143 OCI_StatementFree(idi->dbinfo.oci_statement_runtimevariables); 01144 01145 OCI_StatementFree(idi->dbinfo.oci_statement_hostdefinition_definition); 01146 OCI_StatementFree(idi->dbinfo.oci_statement_hostdefinition_parenthosts); 01147 OCI_StatementFree(idi->dbinfo.oci_statement_hostdefinition_contactgroups); 01148 OCI_StatementFree(idi->dbinfo.oci_statement_hostdefinition_contacts); 01149 01150 OCI_StatementFree(idi->dbinfo.oci_statement_hostgroupdefinition_definition); 01151 OCI_StatementFree(idi->dbinfo.oci_statement_hostgroupdefinition_hostgroupmembers); 01152 01153 OCI_StatementFree(idi->dbinfo.oci_statement_servicedefinition_definition); 01154 OCI_StatementFree(idi->dbinfo.oci_statement_servicedefinition_contactgroups); 01155 OCI_StatementFree(idi->dbinfo.oci_statement_servicedefinition_contacts); 01156 01157 OCI_StatementFree(idi->dbinfo.oci_statement_servicegroupdefinition_definition); 01158 OCI_StatementFree(idi->dbinfo.oci_statement_servicegroupdefinition_members); 01159 01160 OCI_StatementFree(idi->dbinfo.oci_statement_hostdependencydefinition_definition); 01161 OCI_StatementFree(idi->dbinfo.oci_statement_servicedependencydefinition_definition); 01162 01163 OCI_StatementFree(idi->dbinfo.oci_statement_hostescalationdefinition_definition); 01164 OCI_StatementFree(idi->dbinfo.oci_statement_hostescalationdefinition_contactgroups); 01165 OCI_StatementFree(idi->dbinfo.oci_statement_hostescalationdefinition_contacts); 01166 01167 OCI_StatementFree(idi->dbinfo.oci_statement_serviceescalationdefinition_definition); 01168 OCI_StatementFree(idi->dbinfo.oci_statement_serviceescalationdefinition_contactgroups); 01169 OCI_StatementFree(idi->dbinfo.oci_statement_serviceescalationdefinition_contacts); 01170 01171 OCI_StatementFree(idi->dbinfo.oci_statement_commanddefinition_definition); 01172 01173 OCI_StatementFree(idi->dbinfo.oci_statement_timeperiodefinition_definition); 01174 OCI_StatementFree(idi->dbinfo.oci_statement_timeperiodefinition_timeranges); 01175 01176 OCI_StatementFree(idi->dbinfo.oci_statement_contactdefinition_definition); 01177 OCI_StatementFree(idi->dbinfo.oci_statement_contactdefinition_addresses); 01178 OCI_StatementFree(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands); 01179 01180 OCI_StatementFree(idi->dbinfo.oci_statement_save_custom_variables_customvariables); 01181 OCI_StatementFree(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus); 01182 01183 OCI_StatementFree(idi->dbinfo.oci_statement_contactgroupdefinition_definition); 01184 OCI_StatementFree(idi->dbinfo.oci_statement_contactgroupdefinition_contactgroupmembers); 01185 01186 OCI_StatementFree(idi->dbinfo.oci_statement_process_events); 01187 OCI_StatementFree(idi->dbinfo.oci_statement_flappinghistory); 01188 OCI_StatementFree(idi->dbinfo.oci_statement_external_commands); 01189 OCI_StatementFree(idi->dbinfo.oci_statement_acknowledgements); 01190 OCI_StatementFree(idi->dbinfo.oci_statement_statehistory); 01191 OCI_StatementFree(idi->dbinfo.oci_statement_instances); 01192 OCI_StatementFree(idi->dbinfo.oci_statement_conninfo); 01193 01194 OCI_StatementFree(idi->dbinfo.oci_statement_objects_select_name1_name2); 01195 OCI_StatementFree(idi->dbinfo.oci_statement_objects_select_name1_null_name2); 01196 OCI_StatementFree(idi->dbinfo.oci_statement_objects_select_name1_name2_null); 01197 OCI_StatementFree(idi->dbinfo.oci_statement_objects_select_name1_null_name2_null); 01198 OCI_StatementFree(idi->dbinfo.oci_statement_objects_select_cached); 01199 OCI_StatementFree(idi->dbinfo.oci_statement_objects_update_inactive); 01200 OCI_StatementFree(idi->dbinfo.oci_statement_objects_update_active); 01201 01202 OCI_StatementFree(idi->dbinfo.oci_statement_logentries_select); 01203 OCI_StatementFree(idi->dbinfo.oci_statement_programstatus_update); 01204 01205 OCI_StatementFree(idi->dbinfo.oci_statement_timedevents_update); 01206 OCI_StatementFree(idi->dbinfo.oci_statement_timedeventqueue_delete); 01207 OCI_StatementFree(idi->dbinfo.oci_statement_timedeventqueue_delete_more); 01208 01209 OCI_StatementFree(idi->dbinfo.oci_statement_comment_history_update); 01210 OCI_StatementFree(idi->dbinfo.oci_statement_comments_delete); 01211 01212 OCI_StatementFree(idi->dbinfo.oci_statement_downtimehistory_update_start); 01213 OCI_StatementFree(idi->dbinfo.oci_statement_downtimehistory_update_stop); 01214 OCI_StatementFree(idi->dbinfo.oci_statement_downtime_delete); 01215 01216 OCI_StatementFree(idi->dbinfo.oci_statement_instances_select); 01217 01218 OCI_StatementFree(idi->dbinfo.oci_statement_conninfo_update); 01219 OCI_StatementFree(idi->dbinfo.oci_statement_conninfo_update_checkin); 01220 01221 OCI_StatementFree(idi->dbinfo.oci_statement_instances_delete); 01222 OCI_StatementFree(idi->dbinfo.oci_statement_instances_delete_time); 01223 01224 OCI_StatementFree(idi->dbinfo.oci_statement_dbversion_select); 01225 01226 syslog(LOG_USER | LOG_INFO, "Successfully freed prepared statements"); 01227 01228 /* close db connection */ 01229 OCI_ConnectionFree(idi->dbinfo.oci_connection); 01230 OCI_Cleanup(); 01231 syslog(LOG_USER | LOG_INFO, "Successfully disconnected from oracle database"); 01232 01233 #endif /* Oracle ocilib specific */ 01234 01235 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_disconnect() stop\n"); 01236 return IDO_OK; 01237 } 01238 01239 01240 /************************************/ 01241 /* post-connect routines */ 01242 /************************************/ 01243 01244 int ido2db_db_version_check(ido2db_idi *idi) { 01245 char *buf=NULL; 01246 char *name=NULL; 01247 #ifdef USE_ORACLE 01248 char *dbversion=NULL; 01249 #endif 01250 void *data[1]; 01251 01252 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_version_check () start \n"); 01253 01254 name=strdup("idoutils"); 01255 data[0] = (void *) &name; 01256 01257 #ifdef USE_LIBDBI 01258 01259 if (asprintf(&buf, "SELECT version FROM %s WHERE name='%s'", ido2db_db_tablenames[IDO2DB_DBTABLE_DBVERSION], name) == -1) 01260 buf = NULL; 01261 01262 if ((ido2db_db_query(idi, buf))==IDO_OK) { 01263 01264 if (idi->dbinfo.dbi_result!=NULL) { 01265 if (dbi_result_next_row(idi->dbinfo.dbi_result)) { 01266 idi->dbinfo.dbversion = strdup(dbi_result_get_string(idi->dbinfo.dbi_result, "version")); 01267 } 01268 } 01269 } 01270 01271 free(buf); 01272 #endif 01273 01274 #ifdef USE_ORACLE 01275 01276 01277 if(!OCI_BindString(idi->dbinfo.oci_statement_dbversion_select, MT(":X1"), *(char **) data[0], 0)) { 01278 return IDO_ERROR; 01279 } 01280 01281 /* execute statement */ 01282 if(!OCI_Execute(idi->dbinfo.oci_statement_dbversion_select)) { 01283 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_version_check () \n"); 01284 } 01285 01286 /* commit statement */ 01287 OCI_Commit(idi->dbinfo.oci_connection); 01288 01289 /* do not free statement yet! */ 01290 01291 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_dbversion_select); 01292 01293 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_version_check() query ok\n"); 01294 01295 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 01296 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_version_check() fetchnext ok\n"); 01297 idi->dbinfo.dbversion=strdup(OCI_GetString(idi->dbinfo.oci_resultset, 1)); 01298 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello(version=%s)\n", idi->dbinfo.dbversion); 01299 } else { 01300 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_version_check() fetchnext not ok\n"); 01301 } 01302 01303 01304 #endif 01305 01306 #ifdef USE_PGSQL 01307 01308 //FIXME 01309 #endif 01310 01311 free(name); 01312 01313 /* check dbversion against program version */ 01314 if(idi->dbinfo.dbversion==NULL){ 01315 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_version_check() dbversion is NULL\n"); 01316 syslog(LOG_ERR, "Error: DB Version cannot be retrieved. Please check the upgrade docs and verify the db schema!"); 01317 return IDO_ERROR; 01318 } 01319 if(strcmp(idi->dbinfo.dbversion, IDO2DB_SCHEMA_VERSION)!=0){ 01320 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_version_check() db version %s does not match schema version %s\n", idi->dbinfo.dbversion, IDO2DB_SCHEMA_VERSION); 01321 syslog(LOG_ERR, "Error: DB Version %s does not match needed schema version %s. Please check the upgrade docs!", idi->dbinfo.dbversion, IDO2DB_SCHEMA_VERSION); 01322 return IDO_ERROR; 01323 } 01324 01325 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_version_check () end\n"); 01326 01327 return IDO_OK; 01328 01329 } 01330 01331 int ido2db_db_hello(ido2db_idi *idi) { 01332 #ifdef USE_LIBDBI 01333 char *buf = NULL; 01334 char *buf1 = NULL; 01335 char *ts = NULL; 01336 #endif 01337 int result = IDO_OK; 01338 int have_instance = IDO_FALSE; 01339 time_t current_time; 01340 01341 #ifdef USE_ORACLE 01342 unsigned long n_zero = 0; 01343 void *data[9]; 01344 #endif 01345 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() start\n"); 01346 01347 /* make sure we have an instance name */ 01348 if (idi->instance_name == NULL) 01349 idi->instance_name = strdup("default"); 01350 01351 01352 ido2db_db_version_check(idi); 01353 01354 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01355 01356 /* get existing instance */ 01357 if (asprintf(&buf, "SELECT instance_id FROM %s WHERE instance_name='%s'", 01358 ido2db_db_tablenames[IDO2DB_DBTABLE_INSTANCES], idi->instance_name) 01359 == -1) 01360 buf = NULL; 01361 01362 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 01363 01364 if (idi->dbinfo.dbi_result != NULL) { 01365 if (dbi_result_next_row(idi->dbinfo.dbi_result)) { 01366 idi->dbinfo.instance_id = dbi_result_get_uint(idi->dbinfo.dbi_result, "instance_id"); 01367 have_instance = IDO_TRUE; 01368 } 01369 } 01370 } 01371 else { 01372 /* there was an error with the initial db handshake, bail out */ 01373 /* could be missing database, missing db schema */ 01374 syslog(LOG_USER | LOG_INFO, "Error: Initial %s database query failed! Please check %s database configuration and schema!", ido2db_db_settings.dbserver, ido2db_db_settings.dbserver); 01375 syslog(LOG_USER | LOG_INFO, "Exiting ..."); 01376 01377 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() query against existing instance not possible, cleaning up and exiting\n"); 01378 01379 ido2db_terminate_threads(); 01380 01381 /* disconnect from database */ 01382 ido2db_db_disconnect(idi); 01383 ido2db_db_deinit(idi); 01384 01385 /* free memory */ 01386 ido2db_free_input_memory(idi); 01387 ido2db_free_connection_memory(idi); 01388 01389 /* cleanup the socket */ 01390 ido2db_cleanup_socket(); 01391 01392 /* free memory */ 01393 ido2db_free_program_memory(); 01394 01395 _exit(0); 01396 } 01397 01398 dbi_result_free(idi->dbinfo.dbi_result); 01399 free(buf); 01400 01401 #endif 01402 01403 #ifdef USE_PGSQL /* pgsql */ 01404 //FIXME 01405 01406 syslog(LOG_USER | LOG_INFO, "Error: Initial pgsql database query failed! Please check pgsql database configuration and schema!"); 01407 #endif 01408 01409 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01410 01411 /* get existing instance */ 01412 data[0] = (void *) &idi->instance_name; 01413 01414 if(!OCI_BindString(idi->dbinfo.oci_statement_instances_select, MT(":X1"), *(char **) data[0], 0)) { 01415 return IDO_ERROR; 01416 } 01417 01418 /* execute statement */ 01419 if(!OCI_Execute(idi->dbinfo.oci_statement_instances_select)) { 01420 /* there was an error with the initial db handshake, bail out */ 01421 /* could be missing database, missing db schema */ 01422 syslog(LOG_USER | LOG_INFO, "Error: Initial oracle database query failed! Please check oracle database configuration and schema!"); 01423 syslog(LOG_USER | LOG_INFO, "Exiting ..."); 01424 01425 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() query against existing instance not possible, cleaning up and exiting\n"); 01426 01427 ido2db_terminate_threads(); 01428 01429 /* disconnect from database */ 01430 ido2db_db_disconnect(idi); 01431 ido2db_db_deinit(idi); 01432 01433 /* free memory */ 01434 ido2db_free_input_memory(idi); 01435 ido2db_free_connection_memory(idi); 01436 01437 /* cleanup the socket */ 01438 ido2db_cleanup_socket(); 01439 01440 /* free memory */ 01441 ido2db_free_program_memory(); 01442 01443 _exit(0); 01444 } 01445 01446 /* commit statement */ 01447 OCI_Commit(idi->dbinfo.oci_connection); 01448 01449 /* do not free statement yet! */ 01450 01451 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_instances_select); 01452 01453 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() query ok\n"); 01454 01455 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 01456 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() fetchnext ok\n"); 01457 idi->dbinfo.instance_id = OCI_GetUnsignedInt(idi->dbinfo.oci_resultset, 1); 01458 01459 if(idi->dbinfo.instance_id == 0) { 01460 have_instance = IDO_FALSE; 01461 } else { 01462 have_instance = IDO_TRUE; 01463 } 01464 } else { 01465 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() fetchnext not ok\n"); 01466 } 01467 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello(instance_id=%lu)\n", idi->dbinfo.instance_id); 01468 01469 01470 #endif /* Oracle ocilib specific */ 01471 01472 01473 /* insert new instance if necessary */ 01474 if (have_instance == IDO_FALSE) { 01475 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01476 if (asprintf(&buf, "INSERT INTO %s (instance_name) VALUES ('%s')", ido2db_db_tablenames[IDO2DB_DBTABLE_INSTANCES], idi->instance_name) == -1) 01477 buf = NULL; 01478 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 01479 01480 switch (idi->dbinfo.server_type) { 01481 case IDO2DB_DBSERVER_MYSQL: 01482 /* mysql doesn't use sequences */ 01483 idi->dbinfo.instance_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 01484 break; 01485 case IDO2DB_DBSERVER_PGSQL: 01486 /* depending on tableprefix/tablename a sequence will be used */ 01487 if(asprintf(&buf1, "%s_instance_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_INSTANCES]) == -1) 01488 buf1 = NULL; 01489 01490 idi->dbinfo.instance_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf1); 01491 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello(%s=%lu) instance_id\n", buf1, idi->dbinfo.instance_id); 01492 free(buf1); 01493 break; 01494 case IDO2DB_DBSERVER_DB2: 01495 break; 01496 case IDO2DB_DBSERVER_FIREBIRD: 01497 break; 01498 case IDO2DB_DBSERVER_FREETDS: 01499 break; 01500 case IDO2DB_DBSERVER_INGRES: 01501 break; 01502 case IDO2DB_DBSERVER_MSQL: 01503 break; 01504 case IDO2DB_DBSERVER_ORACLE: 01505 break; 01506 case IDO2DB_DBSERVER_SQLITE: 01507 break; 01508 case IDO2DB_DBSERVER_SQLITE3: 01509 break; 01510 default: 01511 break; 01512 } 01513 } 01514 dbi_result_free(idi->dbinfo.dbi_result); 01515 01516 free(buf); 01517 01518 #endif 01519 01520 #ifdef USE_PGSQL /* pgsql */ 01521 01522 #endif 01523 01524 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01525 01526 data[0] = (void *) &idi->instance_name; 01527 01528 if(!OCI_BindString(idi->dbinfo.oci_statement_instances, MT(":X1"), *(char **) data[0], 0)) { 01529 return IDO_ERROR; 01530 } 01531 01532 /* execute statement */ 01533 if(!OCI_Execute(idi->dbinfo.oci_statement_instances)) { 01534 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_instances() execute error\n"); 01535 return IDO_ERROR; 01536 } 01537 01538 OCI_Commit(idi->dbinfo.oci_connection); 01539 01540 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_instances); 01541 01542 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 01543 idi->dbinfo.instance_id = OCI_GetInt(idi->dbinfo.oci_resultset, 1); 01544 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello(%lu) instance_id\n", idi->dbinfo.instance_id); 01545 } else { 01546 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() instance_id could not be fetched\n"); 01547 } 01548 01549 OCI_Commit(idi->dbinfo.oci_connection); 01550 01551 /* do not free statement yet! */ 01552 01553 #endif /* Oracle ocilib specific */ 01554 01555 } 01556 01557 /* record initial connection information */ 01558 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01559 01560 ts = ido2db_db_timet_to_sql(idi, idi->data_start_time); 01561 01562 if (asprintf(&buf, "INSERT INTO %s (instance_id, connect_time, last_checkin_time, bytes_processed, lines_processed, entries_processed, agent_name, agent_version, disposition, connect_source, connect_type, data_start_time) VALUES ('%lu', NOW(), NOW(), '0', '0', '0', '%s', '%s', '%s', '%s', '%s', NOW())", 01563 ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO], 01564 idi->dbinfo.instance_id, idi->agent_name, idi->agent_version, 01565 idi->disposition, idi->connect_source, idi->connect_type) == -1) 01566 buf = NULL; 01567 01568 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 01569 01570 switch (idi->dbinfo.server_type) { 01571 case IDO2DB_DBSERVER_MYSQL: 01572 /* mysql doesn't use sequences */ 01573 idi->dbinfo.conninfo_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 01574 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello(%lu) conninfo_id\n", idi->dbinfo.conninfo_id); 01575 break; 01576 case IDO2DB_DBSERVER_PGSQL: 01577 /* depending on tableprefix/tablename a sequence will be used */ 01578 if(asprintf(&buf1, "%s_conninfo_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO]) == -1) 01579 buf1 = NULL; 01580 01581 idi->dbinfo.conninfo_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf1); 01582 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello(%s=%lu) conninfo_id\n", buf1, idi->dbinfo.conninfo_id); 01583 free(buf1); 01584 break; 01585 case IDO2DB_DBSERVER_DB2: 01586 break; 01587 case IDO2DB_DBSERVER_FIREBIRD: 01588 break; 01589 case IDO2DB_DBSERVER_FREETDS: 01590 break; 01591 case IDO2DB_DBSERVER_INGRES: 01592 break; 01593 case IDO2DB_DBSERVER_MSQL: 01594 break; 01595 case IDO2DB_DBSERVER_ORACLE: 01596 break; 01597 case IDO2DB_DBSERVER_SQLITE: 01598 break; 01599 case IDO2DB_DBSERVER_SQLITE3: 01600 break; 01601 default: 01602 break; 01603 } 01604 dbi_result_free(idi->dbinfo.dbi_result); 01605 } 01606 01607 free(buf); 01608 free(ts); 01609 #endif 01610 01611 #ifdef USE_PGSQL /* pgsql */ 01612 01613 #endif 01614 01615 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01616 01617 n_zero = 0; 01618 01619 data[0] = (void *) &idi->dbinfo.instance_id; 01620 data[1] = (void *) &n_zero; 01621 data[2] = (void *) &n_zero; 01622 data[3] = (void *) &n_zero; 01623 data[4] = (void *) &idi->agent_name; 01624 data[5] = (void *) &idi->agent_version; 01625 data[6] = (void *) &idi->disposition; 01626 data[7] = (void *) &idi->connect_source; 01627 data[8] = (void *) &idi->connect_type; 01628 01629 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo, MT(":X1"), (big_uint *) data[0])) { 01630 return IDO_ERROR; 01631 } 01632 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo, MT(":X2"), (big_uint *) data[1])) { 01633 return IDO_ERROR; 01634 } 01635 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo, MT(":X3"), (big_uint *) data[2])) { 01636 return IDO_ERROR; 01637 } 01638 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo, MT(":X4"), (big_uint *) data[3])) { 01639 return IDO_ERROR; 01640 } 01641 if(*(char **) data[4]==NULL) { 01642 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X5")==IDO_ERROR) { 01643 return IDO_ERROR; 01644 } 01645 } else { 01646 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X5"), *(char **) data[4], 0)) { 01647 return IDO_ERROR; 01648 } 01649 } 01650 if(*(char **) data[5]==NULL) { 01651 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X6")==IDO_ERROR) { 01652 return IDO_ERROR; 01653 } 01654 } else { 01655 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X6"), *(char **) data[5], 0)) { 01656 return IDO_ERROR; 01657 } 01658 } 01659 if(*(char **) data[6]==NULL) { 01660 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X7")==IDO_ERROR) { 01661 return IDO_ERROR; 01662 } 01663 } else { 01664 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X7"), *(char **) data[6], 0)) { 01665 return IDO_ERROR; 01666 } 01667 } 01668 if(*(char **) data[7]==NULL) { 01669 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X8")==IDO_ERROR) { 01670 return IDO_ERROR; 01671 } 01672 } else { 01673 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X8"), *(char **) data[7], 0)) { 01674 return IDO_ERROR; 01675 } 01676 } 01677 if(*(char **) data[8]==NULL) { 01678 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X9")==IDO_ERROR) { 01679 return IDO_ERROR; 01680 } 01681 } else { 01682 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X9"), *(char **) data[8], 0)) { 01683 return IDO_ERROR; 01684 } 01685 } 01686 01687 /* execute statement */ 01688 if(!OCI_Execute(idi->dbinfo.oci_statement_conninfo)) { 01689 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_conninfo() execute error\n"); 01690 return IDO_ERROR; 01691 } 01692 OCI_Commit(idi->dbinfo.oci_connection); 01693 01694 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_conninfo); 01695 01696 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 01697 idi->dbinfo.conninfo_id = OCI_GetInt(idi->dbinfo.oci_resultset, 1); 01698 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello(%lu) conninfo_id\n", idi->dbinfo.conninfo_id); 01699 } else { 01700 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() conninfo_id could not be fetched\n"); 01701 } 01702 01703 /* do not free statement yet! */ 01704 01705 #endif /* Oracle ocilib specific */ 01706 01707 01708 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() get cached object ids\n"); 01709 /* get cached object ids... */ 01710 ido2db_get_cached_object_ids(idi); 01711 01712 /* get latest times from various tables... */ 01713 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_program_status_time); 01714 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTSTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_host_status_time); 01715 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICESTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_service_status_time); 01716 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTSTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_contact_status_time); 01717 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE], "queued_time", (unsigned long *) &idi->dbinfo.latest_queued_event_time); 01718 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS], "entry_time", (unsigned long *) &idi->dbinfo.latest_comment_time); 01719 01720 /* calculate time of latest realtime data */ 01721 idi->dbinfo.latest_realtime_data_time = (time_t) 0L; 01722 if (idi->dbinfo.latest_program_status_time > idi->dbinfo.latest_realtime_data_time) 01723 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_program_status_time; 01724 if (idi->dbinfo.latest_host_status_time > idi->dbinfo.latest_realtime_data_time) 01725 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_host_status_time; 01726 if (idi->dbinfo.latest_service_status_time > idi->dbinfo.latest_realtime_data_time) 01727 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_service_status_time; 01728 if (idi->dbinfo.latest_contact_status_time > idi->dbinfo.latest_realtime_data_time) 01729 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_contact_status_time; 01730 if (idi->dbinfo.latest_queued_event_time > idi->dbinfo.latest_realtime_data_time) 01731 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_queued_event_time; 01732 01733 /* get current time */ 01734 /* make sure latest time stamp isn't in the future - this will cause problems if a backwards system time change occurs */ 01735 time(¤t_time); 01736 if (idi->dbinfo.latest_realtime_data_time > current_time) 01737 idi->dbinfo.latest_realtime_data_time = current_time; 01738 01739 /* set flags to clean event queue, etc. */ 01740 idi->dbinfo.clean_event_queue = IDO_TRUE; 01741 01742 /* set misc data */ 01743 idi->dbinfo.last_notification_id = 0L; 01744 idi->dbinfo.last_contact_notification_id = 0L; 01745 01746 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() end\n"); 01747 return result; 01748 } 01749 01750 /************************************/ 01751 /* threading post-connect routines */ 01752 /************************************/ 01753 int ido2db_thread_db_hello(ido2db_idi *idi) { 01754 #ifdef USE_LIBDBI 01755 char *buf = NULL; 01756 char *buf1 = NULL; 01757 char *ts = NULL; 01758 #endif 01759 int result = IDO_OK; 01760 int have_instance = IDO_FALSE; 01761 time_t current_time; 01762 01763 #ifdef USE_ORACLE 01764 unsigned long n_zero = 0; 01765 void *data[9]; 01766 #endif 01767 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() start\n"); 01768 01769 /* make sure we have an instance name */ 01770 if (idi->instance_name == NULL) 01771 idi->instance_name = strdup("default"); 01772 01773 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01774 01775 /* get existing instance */ 01776 if (asprintf(&buf, "SELECT instance_id FROM %s WHERE instance_name='%s'", 01777 ido2db_db_tablenames[IDO2DB_DBTABLE_INSTANCES], idi->instance_name) 01778 == -1) 01779 buf = NULL; 01780 01781 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 01782 01783 if (idi->dbinfo.dbi_result != NULL) { 01784 if (dbi_result_next_row(idi->dbinfo.dbi_result)) { 01785 idi->dbinfo.instance_id = dbi_result_get_uint(idi->dbinfo.dbi_result, "instance_id"); 01786 have_instance = IDO_TRUE; 01787 } 01788 } 01789 } 01790 else { 01791 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() query against existing instance not possible, cleaning up and exiting\n"); 01792 01793 ido2db_terminate_threads(); 01794 01795 /* disconnect from database */ 01796 ido2db_db_disconnect(idi); 01797 ido2db_db_deinit(idi); 01798 01799 /* free memory */ 01800 ido2db_free_input_memory(idi); 01801 ido2db_free_connection_memory(idi); 01802 01803 /* cleanup the socket */ 01804 ido2db_cleanup_socket(); 01805 01806 /* free memory */ 01807 ido2db_free_program_memory(); 01808 01809 _exit(0); 01810 } 01811 01812 dbi_result_free(idi->dbinfo.dbi_result); 01813 free(buf); 01814 01815 #endif 01816 01817 #ifdef USE_PGSQL /* pgsql */ 01818 01819 #endif 01820 01821 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01822 01823 /* get existing instance */ 01824 data[0] = (void *) &idi->instance_name; 01825 01826 if(!OCI_BindString(idi->dbinfo.oci_statement_instances_select, MT(":X1"), *(char **) data[0], 0)) { 01827 return IDO_ERROR; 01828 } 01829 01830 /* execute statement */ 01831 if(!OCI_Execute(idi->dbinfo.oci_statement_instances_select)) { 01832 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() query against existing instance not possible, cleaning up and exiting\n"); 01833 01834 ido2db_terminate_threads(); 01835 01836 /* disconnect from database */ 01837 ido2db_db_disconnect(idi); 01838 ido2db_db_deinit(idi); 01839 01840 /* free memory */ 01841 ido2db_free_input_memory(idi); 01842 ido2db_free_connection_memory(idi); 01843 01844 /* cleanup the socket */ 01845 ido2db_cleanup_socket(); 01846 01847 /* free memory */ 01848 ido2db_free_program_memory(); 01849 01850 _exit(0); 01851 } 01852 01853 /* commit statement */ 01854 OCI_Commit(idi->dbinfo.oci_connection); 01855 01856 /* do not free statement yet! */ 01857 01858 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_instances_select); 01859 01860 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() query ok\n"); 01861 01862 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 01863 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() fetchnext ok\n"); 01864 idi->dbinfo.instance_id = OCI_GetUnsignedInt(idi->dbinfo.oci_resultset, 1); 01865 01866 if(idi->dbinfo.instance_id == 0) { 01867 have_instance = IDO_FALSE; 01868 } else { 01869 have_instance = IDO_TRUE; 01870 } 01871 } else { 01872 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() fetchnext not ok\n"); 01873 } 01874 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello(instance_id=%lu)\n", idi->dbinfo.instance_id); 01875 01876 01877 #endif /* Oracle ocilib specific */ 01878 01879 01880 /* check if instance found */ 01881 if(have_instance == IDO_FALSE) { 01882 return IDO_ERROR; 01883 } 01884 01885 /* record initial connection information */ 01886 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01887 01888 ts = ido2db_db_timet_to_sql(idi, idi->data_start_time); 01889 01890 if (asprintf(&buf, "INSERT INTO %s (instance_id, connect_time, last_checkin_time, bytes_processed, lines_processed, entries_processed, agent_name, agent_version, disposition, connect_source, connect_type, data_start_time) VALUES ('%lu', NOW(), NOW(), '0', '0', '0', '%s', '%s', '%s', '%s', '%s', NOW())", 01891 ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO], 01892 idi->dbinfo.instance_id, idi->agent_name, idi->agent_version, 01893 idi->disposition, idi->connect_source, idi->connect_type) == -1) 01894 buf = NULL; 01895 01896 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 01897 01898 switch (idi->dbinfo.server_type) { 01899 case IDO2DB_DBSERVER_MYSQL: 01900 /* mysql doesn't use sequences */ 01901 idi->dbinfo.conninfo_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 01902 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello(%lu) conninfo_id\n", idi->dbinfo.conninfo_id); 01903 break; 01904 case IDO2DB_DBSERVER_PGSQL: 01905 /* depending on tableprefix/tablename a sequence will be used */ 01906 if(asprintf(&buf1, "%s_conninfo_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO]) == -1) 01907 buf1 = NULL; 01908 01909 idi->dbinfo.conninfo_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf1); 01910 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello(%s=%lu) conninfo_id\n", buf1, idi->dbinfo.conninfo_id); 01911 free(buf1); 01912 break; 01913 case IDO2DB_DBSERVER_DB2: 01914 break; 01915 case IDO2DB_DBSERVER_FIREBIRD: 01916 break; 01917 case IDO2DB_DBSERVER_FREETDS: 01918 break; 01919 case IDO2DB_DBSERVER_INGRES: 01920 break; 01921 case IDO2DB_DBSERVER_MSQL: 01922 break; 01923 case IDO2DB_DBSERVER_ORACLE: 01924 break; 01925 case IDO2DB_DBSERVER_SQLITE: 01926 break; 01927 case IDO2DB_DBSERVER_SQLITE3: 01928 break; 01929 default: 01930 break; 01931 } 01932 dbi_result_free(idi->dbinfo.dbi_result); 01933 } 01934 01935 free(buf); 01936 free(ts); 01937 #endif 01938 01939 #ifdef USE_PGSQL /* pgsql */ 01940 01941 #endif 01942 01943 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01944 01945 n_zero = 0; 01946 01947 data[0] = (void *) &idi->dbinfo.instance_id; 01948 data[1] = (void *) &n_zero; 01949 data[2] = (void *) &n_zero; 01950 data[3] = (void *) &n_zero; 01951 data[4] = (void *) &idi->agent_name; 01952 data[5] = (void *) &idi->agent_version; 01953 data[6] = (void *) &idi->disposition; 01954 data[7] = (void *) &idi->connect_source; 01955 data[8] = (void *) &idi->connect_type; 01956 01957 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo, MT(":X1"), (big_uint *) data[0])) { 01958 return IDO_ERROR; 01959 } 01960 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo, MT(":X2"), (big_uint *) data[1])) { 01961 return IDO_ERROR; 01962 } 01963 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo, MT(":X3"), (big_uint *) data[2])) { 01964 return IDO_ERROR; 01965 } 01966 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo, MT(":X4"), (big_uint *) data[3])) { 01967 return IDO_ERROR; 01968 } 01969 if(*(char **) data[4]==NULL) { 01970 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X5")==IDO_ERROR) { 01971 return IDO_ERROR; 01972 } 01973 } else { 01974 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X5"), *(char **) data[4], 0)) { 01975 return IDO_ERROR; 01976 } 01977 } 01978 if(*(char **) data[5]==NULL) { 01979 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X6")==IDO_ERROR) { 01980 return IDO_ERROR; 01981 } 01982 } else { 01983 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X6"), *(char **) data[5], 0)) { 01984 return IDO_ERROR; 01985 } 01986 } 01987 if(*(char **) data[6]==NULL) { 01988 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X7")==IDO_ERROR) { 01989 return IDO_ERROR; 01990 } 01991 } else { 01992 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X7"), *(char **) data[6], 0)) { 01993 return IDO_ERROR; 01994 } 01995 } 01996 if(*(char **) data[7]==NULL) { 01997 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X8")==IDO_ERROR) { 01998 return IDO_ERROR; 01999 } 02000 } else { 02001 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X8"), *(char **) data[7], 0)) { 02002 return IDO_ERROR; 02003 } 02004 } 02005 if(*(char **) data[8]==NULL) { 02006 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_conninfo, ":X9")==IDO_ERROR) { 02007 return IDO_ERROR; 02008 } 02009 } else { 02010 if(!OCI_BindString(idi->dbinfo.oci_statement_conninfo, MT(":X9"), *(char **) data[8], 0)) { 02011 return IDO_ERROR; 02012 } 02013 } 02014 02015 02016 /* execute statement */ 02017 if(!OCI_Execute(idi->dbinfo.oci_statement_conninfo)) { 02018 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_conninfo() execute error\n"); 02019 return IDO_ERROR; 02020 } 02021 OCI_Commit(idi->dbinfo.oci_connection); 02022 02023 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_conninfo); 02024 02025 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 02026 idi->dbinfo.conninfo_id = OCI_GetInt(idi->dbinfo.oci_resultset, 1); 02027 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello(%lu) conninfo_id\n", idi->dbinfo.conninfo_id); 02028 } else { 02029 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() conninfo_id could not be fetched\n"); 02030 } 02031 02032 /* do not free statement yet! */ 02033 02034 #endif /* Oracle ocilib specific */ 02035 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() get cached object ids\n"); 02036 /* get cached object ids... */ 02037 ido2db_get_cached_object_ids(idi); 02038 02039 /* get latest times from various tables... */ 02040 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_program_status_time); 02041 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTSTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_host_status_time); 02042 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICESTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_service_status_time); 02043 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTSTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_contact_status_time); 02044 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE], "queued_time", (unsigned long *) &idi->dbinfo.latest_queued_event_time); 02045 ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS], "entry_time", (unsigned long *) &idi->dbinfo.latest_comment_time); 02046 02047 /* calculate time of latest realtime data */ 02048 idi->dbinfo.latest_realtime_data_time = (time_t) 0L; 02049 if (idi->dbinfo.latest_program_status_time > idi->dbinfo.latest_realtime_data_time) 02050 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_program_status_time; 02051 if (idi->dbinfo.latest_host_status_time > idi->dbinfo.latest_realtime_data_time) 02052 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_host_status_time; 02053 if (idi->dbinfo.latest_service_status_time > idi->dbinfo.latest_realtime_data_time) 02054 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_service_status_time; 02055 if (idi->dbinfo.latest_contact_status_time > idi->dbinfo.latest_realtime_data_time) 02056 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_contact_status_time; 02057 if (idi->dbinfo.latest_queued_event_time > idi->dbinfo.latest_realtime_data_time) 02058 idi->dbinfo.latest_realtime_data_time = idi->dbinfo.latest_queued_event_time; 02059 02060 /* get current time */ 02061 /* make sure latest time stamp isn't in the future - this will cause problems if a backwards system time change occurs */ 02062 time(¤t_time); 02063 if (idi->dbinfo.latest_realtime_data_time > current_time) 02064 idi->dbinfo.latest_realtime_data_time = current_time; 02065 02066 /* set flags to clean event queue, etc. */ 02067 idi->dbinfo.clean_event_queue = IDO_TRUE; 02068 02069 /* set misc data */ 02070 idi->dbinfo.last_notification_id = 0L; 02071 idi->dbinfo.last_contact_notification_id = 0L; 02072 02073 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() end\n"); 02074 return result; 02075 } 02076 02077 02078 02079 02080 /************************************/ 02081 /* pre-disconnect routines */ 02082 /************************************/ 02083 int ido2db_db_goodbye(ido2db_idi *idi) { 02084 int result = IDO_OK; 02085 #ifdef USE_LIBDBI 02086 char *buf = NULL; 02087 char *ts = NULL; 02088 #endif 02089 02090 #ifdef USE_ORACLE 02091 void *data[5]; 02092 #endif 02093 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_goodbye() start\n"); 02094 02095 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02096 ts = ido2db_db_timet_to_sql(idi, idi->data_end_time); 02097 02098 /* record last connection information */ 02099 if (asprintf(&buf, "UPDATE %s SET disconnect_time=NOW(), last_checkin_time=NOW(), data_end_time=%s, bytes_processed='%lu', lines_processed='%lu', entries_processed='%lu' WHERE conninfo_id='%lu'", 02100 ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO], ts, 02101 idi->bytes_processed, idi->lines_processed, idi->entries_processed, 02102 idi->dbinfo.conninfo_id) == -1) 02103 buf = NULL; 02104 02105 result = ido2db_db_query(idi, buf); 02106 02107 dbi_result_free(idi->dbinfo.dbi_result); 02108 02109 free(buf); 02110 free(ts); 02111 02112 #endif 02113 02114 #ifdef USE_PGSQL /* pgsql */ 02115 02116 #endif 02117 02118 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02119 02120 data[0] = (void *) &idi->data_end_time; 02121 data[1] = (void *) &idi->bytes_processed; 02122 data[2] = (void *) &idi->lines_processed; 02123 data[3] = (void *) &idi->entries_processed; 02124 data[4] = (void *) &idi->dbinfo.conninfo_id; 02125 02126 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update, MT(":X1"), (big_uint *) data[0])) { /* unixtimestamp instead of time2sql */ 02127 return IDO_ERROR; 02128 } 02129 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update, MT(":X2"), (big_uint *) data[1])) { 02130 return IDO_ERROR; 02131 } 02132 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update, MT(":X3"), (big_uint *) data[2])) { 02133 return IDO_ERROR; 02134 } 02135 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update, MT(":X4"), (big_uint *) data[3])) { 02136 return IDO_ERROR; 02137 } 02138 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update, MT(":X5"), (big_uint *) data[4])) { 02139 return IDO_ERROR; 02140 } 02141 02142 /* execute statement */ 02143 if(!OCI_Execute(idi->dbinfo.oci_statement_conninfo_update)) { 02144 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_conninfo_update() execute error\n"); 02145 return IDO_ERROR; 02146 } 02147 02148 /* commit statement */ 02149 OCI_Commit(idi->dbinfo.oci_connection); 02150 02151 /* do not free statement yet! */ 02152 02153 #endif /* Oracle ocilib specific */ 02154 02155 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_goodbye() end\n"); 02156 return result; 02157 } 02158 02159 /************************************/ 02160 /* checking routines */ 02161 /************************************/ 02162 int ido2db_db_checkin(ido2db_idi *idi) { 02163 int result = IDO_OK; 02164 #ifdef USE_LIBDBI 02165 char *buf = NULL; 02166 #endif 02167 02168 #ifdef USE_ORACLE 02169 void *data[4]; 02170 #endif 02171 02172 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_checkin() start\n"); 02173 02174 /* record last connection information */ 02175 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02176 if (asprintf(&buf, "UPDATE %s SET last_checkin_time=NOW(), bytes_processed='%lu', lines_processed='%lu', entries_processed='%lu' WHERE conninfo_id='%lu'", 02177 ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO], 02178 idi->bytes_processed, idi->lines_processed, idi->entries_processed, 02179 idi->dbinfo.conninfo_id) == -1) 02180 buf = NULL; 02181 02182 result = ido2db_db_query(idi, buf); 02183 02184 dbi_result_free(idi->dbinfo.dbi_result); 02185 free(buf); 02186 02187 #endif 02188 02189 #ifdef USE_PGSQL /* pgsql */ 02190 02191 #endif 02192 02193 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02194 02195 data[0] = (void *) &idi->bytes_processed; 02196 data[1] = (void *) &idi->lines_processed; 02197 data[2] = (void *) &idi->entries_processed; 02198 data[3] = (void *) &idi->dbinfo.conninfo_id; 02199 02200 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update_checkin, MT(":X1"), (big_uint *) data[0])) { 02201 return IDO_ERROR; 02202 } 02203 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update_checkin, MT(":X2"), (big_uint *) data[1])) { 02204 return IDO_ERROR; 02205 } 02206 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update_checkin, MT(":X3"), (big_uint *) data[2])) { 02207 return IDO_ERROR; 02208 } 02209 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_conninfo_update_checkin, MT(":X4"), (big_uint *) data[3])) { 02210 return IDO_ERROR; 02211 } 02212 02213 /* execute statement */ 02214 if(!OCI_Execute(idi->dbinfo.oci_statement_conninfo_update_checkin)) { 02215 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_conninfo_update_checkin() execute error\n"); 02216 return IDO_ERROR; 02217 } 02218 02219 /* commit statement */ 02220 OCI_Commit(idi->dbinfo.oci_connection); 02221 02222 /* do not free statement yet! */ 02223 02224 #endif /* Oracle ocilib specific */ 02225 02226 02227 time(&ido2db_db_last_checkin_time); 02228 02229 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_checkin() end\n"); 02230 return result; 02231 } 02232 02233 /****************************************************************************/ 02234 /* MISC FUNCTIONS */ 02235 /****************************************************************************/ 02236 02237 /***************************************/ 02238 /* escape a string for a SQL statement */ 02239 /***************************************/ 02240 char *ido2db_db_escape_string(ido2db_idi *idi, char *buf) { 02241 register int x, y, z; 02242 char *newbuf = NULL; 02243 02244 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) start\n", buf); 02245 02246 if (idi == NULL || buf == NULL) 02247 return NULL; 02248 02249 z = strlen(buf); 02250 02251 /* escape characters */ 02252 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02253 /* allocate space for the new string */ 02254 02255 if ((newbuf = (char *) malloc((z * 2) + 1)) == NULL) 02256 return NULL; 02257 02258 for (x = 0, y = 0; x < z; x++) { 02259 02260 if(idi->dbinfo.server_type==IDO2DB_DBSERVER_MYSQL){ 02261 02262 if(buf[x]=='\'' || buf[x]=='\"' || buf[x]=='*' || buf[x]=='\\' || buf[x]=='$' || buf[x]=='?' || buf[x]=='.' || buf[x]=='^' || buf[x]=='+' || buf[x]=='[' || buf[x]==']' || buf[x]=='(' || buf[x]==')') 02263 newbuf[y++]='\\'; 02264 } 02265 else if(idi->dbinfo.server_type==IDO2DB_DBSERVER_PGSQL){ 02266 02267 if (buf[x] == '\'' || buf[x] == '\\' || buf[x] == '\0') 02268 newbuf[y++] = '\\'; 02269 } 02270 else { 02271 02272 if(buf[x]=='\'' ) 02273 newbuf[y++]='\''; 02274 02275 } 02276 02277 newbuf[y++] = buf[x]; 02278 } 02279 02280 /* terminate escape string */ 02281 newbuf[y] = '\0'; 02282 02283 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) end\n", newbuf); 02284 return newbuf; 02285 02286 //size_t res = dbi_conn_quote_string(idi->dbinfo.dbi_conn, &buf); 02287 02288 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) end\n", buf); 02289 //return buf; 02290 02291 #endif 02292 02293 #ifdef USE_PGSQL /* pgsql */ 02294 02295 if ((newbuf = (char *) malloc((z * 2) + 1)) == NULL) 02296 return NULL; 02297 02298 for (x = 0, y = 0; x < z; x++) { 02299 02300 if (buf[x] == '\'' || buf[x] == '[' || buf[x] == ']' || buf[x] == '(' || buf[x] == ')') 02301 newbuf[y++] = '\\'; 02302 02303 newbuf[y++] = buf[x]; 02304 } 02305 02306 /* terminate escape string */ 02307 newbuf[y] = '\0'; 02308 02309 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) end\n", newbuf); 02310 return newbuf; 02311 02312 #endif 02313 02314 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02315 02316 /* allocate space for the new string */ 02317 if ((newbuf = (char *) malloc((z * 2) + 1)) == NULL) 02318 return NULL; 02319 02320 02321 for (x = 0, y = 0; x < z; x++) { 02322 02323 if(buf[x]=='\'' ) 02324 newbuf[y++]='\''; 02325 02326 newbuf[y++] = buf[x]; 02327 } 02328 #endif /* Oracle ocilib specific */ 02329 02330 /* terminate escape string */ 02331 newbuf[y] = '\0'; 02332 02333 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) end\n", newbuf); 02334 return newbuf; 02335 } 02336 02337 /*************************************************************/ 02338 /* SQL query conversion of time_t format to date/time format */ 02339 /*************************************************************/ 02340 char *ido2db_db_timet_to_sql(ido2db_idi *idi, time_t t) { 02341 char *buf = NULL; 02342 02343 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_timet_to_sql(%lu) start\n", (unsigned long)t); 02344 02345 switch (idi->dbinfo.server_type) { 02346 case IDO2DB_DBSERVER_MYSQL: 02347 if(asprintf(&buf, "FROM_UNIXTIME(%lu)", (unsigned long) t)==-1) 02348 buf=NULL; 02349 break; 02350 case IDO2DB_DBSERVER_PGSQL: 02351 /* from_unixtime is a PL/SQL function (defined in db/pgsql.sql) */ 02352 if(asprintf(&buf, "FROM_UNIXTIME(%lu)", (unsigned long) t)==-1) 02353 buf=NULL; 02354 break; 02355 case IDO2DB_DBSERVER_DB2: 02356 break; 02357 case IDO2DB_DBSERVER_FIREBIRD: 02358 break; 02359 case IDO2DB_DBSERVER_FREETDS: 02360 break; 02361 case IDO2DB_DBSERVER_INGRES: 02362 break; 02363 case IDO2DB_DBSERVER_MSQL: 02364 break; 02365 case IDO2DB_DBSERVER_ORACLE: 02366 02367 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02368 /* unixts2date is a PL/SQL function (defined in db/oracle.sql) */ 02369 if(asprintf(&buf,"(SELECT unixts2date(%lu) FROM DUAL)",(unsigned long)t)==-1) 02370 buf=NULL; 02371 #endif /* Oracle ocilib specific */ 02372 02373 break; 02374 case IDO2DB_DBSERVER_SQLITE: 02375 break; 02376 case IDO2DB_DBSERVER_SQLITE3: 02377 break; 02378 default: 02379 break; 02380 } 02381 02382 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_timet_to_sql(%s) end\n", buf); 02383 02384 return buf; 02385 } 02386 02387 /*************************************************************/ 02388 /* SQL query conversion of date/time format to time_t format */ 02389 /*************************************************************/ 02390 char *ido2db_db_sql_to_timet(ido2db_idi *idi, char *field) { 02391 char *buf = NULL; 02392 02393 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_sql_to_timet(%s) start\n", field); 02394 02395 switch (idi->dbinfo.server_type) { 02396 case IDO2DB_DBSERVER_MYSQL: 02397 if(asprintf(&buf,"UNIX_TIMESTAMP(%s)",(field==NULL)?"":field)==-1) 02398 buf=NULL; 02399 break; 02400 case IDO2DB_DBSERVER_PGSQL: 02401 /* unix_timestamp is a PL/SQL function (defined in db/pgsql.sql) */ 02402 if(asprintf(&buf,"UNIX_TIMESTAMP(%s)",(field==NULL)?"":field)==-1) 02403 buf=NULL; 02404 break; 02405 case IDO2DB_DBSERVER_DB2: 02406 break; 02407 case IDO2DB_DBSERVER_FIREBIRD: 02408 break; 02409 case IDO2DB_DBSERVER_FREETDS: 02410 break; 02411 case IDO2DB_DBSERVER_INGRES: 02412 break; 02413 case IDO2DB_DBSERVER_MSQL: 02414 break; 02415 case IDO2DB_DBSERVER_ORACLE: 02416 02417 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02418 if(asprintf(&buf,"((SELECT ((SELECT %s FROM %%s) - TO_DATE('01-01-1970 00:00:00','dd-mm-yyyy hh24:mi:ss')) * 86400) FROM DUAL)",(field==NULL)?"":field)==-1) 02419 buf=NULL; 02420 #endif/* Oracle ocilib specific */ 02421 02422 break; 02423 case IDO2DB_DBSERVER_SQLITE: 02424 break; 02425 case IDO2DB_DBSERVER_SQLITE3: 02426 break; 02427 default: 02428 break; 02429 } 02430 02431 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_sql_to_timet(%s) end\n", buf); 02432 02433 return buf; 02434 } 02435 02436 /************************************/ 02437 /* executes a SQL statement */ 02438 /************************************/ 02439 int ido2db_db_query(ido2db_idi *idi, char *buf) { 02440 int result = IDO_OK; 02441 #ifdef USE_LIBDBI 02442 const char *error_msg; 02443 #endif 02444 02445 #ifdef USE_ORACLE 02446 int oci_res = 0; 02447 #endif 02448 02449 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_query() start\n"); 02450 02451 if (idi == NULL || buf == NULL) 02452 return IDO_ERROR; 02453 02454 /* if we're not connected, try and reconnect... */ 02455 if(ido2db_db_reconnect(idi)==IDO_ERROR) 02456 return IDO_ERROR; 02457 02458 02459 #ifdef DEBUG_IDO2DB_QUERIES 02460 printf("%s\n\n",buf); 02461 #endif 02462 02463 ido2db_log_debug_info(IDO2DB_DEBUGL_SQL, 0, "%s\n", buf); 02464 02465 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02466 02467 /* send query */ 02468 idi->dbinfo.dbi_result = dbi_conn_query(idi->dbinfo.dbi_conn, buf); 02469 02470 if (idi->dbinfo.dbi_result == NULL){ 02471 dbi_conn_error(idi->dbinfo.dbi_conn, &error_msg); 02472 02473 syslog(LOG_USER | LOG_INFO, "Error: database query failed for '%s' - '%s'\n", buf, error_msg); 02474 02475 ido2db_handle_db_error(idi); 02476 result = IDO_ERROR; 02477 } 02478 #endif 02479 02480 #ifdef USE_PGSQL /* pgsql */ 02481 02482 idi->dbinfo.pg_result = PQexec(idi->dbinfo.pg_conn, buf); 02483 02484 if(PQresultStatus(idi->dbinfo.pg_result)!=PGRES_COMMAND_OK) { 02485 syslog(LOG_USER | LOG_INFO, "Error: database query failed for '%s': %s\n", buf, PQerrorMessage(idi->dbinfo.pg_conn)); 02486 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "Error: database query failed for '%s': %s\n", buf, PQerrorMessage(idi->dbinfo.pg_conn)); 02487 02488 ido2db_handle_db_error(idi); 02489 result = IDO_ERROR; 02490 } 02491 #endif 02492 02493 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02494 02495 oci_res = 0; 02496 02497 /* create statement handler */ 02498 idi->dbinfo.oci_statement = OCI_StatementCreate(idi->dbinfo.oci_connection); 02499 02500 /* execute query in one go */ 02501 oci_res = OCI_ExecuteStmt(idi->dbinfo.oci_statement, MT(buf)); 02502 02503 /* get result set */ 02504 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement); 02505 02506 /* check for errors */ 02507 if(!oci_res) { 02508 02509 syslog(LOG_USER | LOG_INFO, "Error: database query failed for '%s'\n", buf); 02510 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "Error: database query failed for: '%s'\n", buf); 02511 02512 ido2db_handle_db_error(idi); 02513 result = IDO_ERROR; 02514 } 02515 02516 /* since we do not want to set auto commit to true, we do it manually */ 02517 OCI_Commit(idi->dbinfo.oci_connection); 02518 02519 #endif /* Oracle ocilib specific */ 02520 02521 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_query(%d) end\n", result); 02522 return result; 02523 } 02524 02525 /****************************************/ 02526 /* frees memory associated with a query */ 02527 /****************************************/ 02528 int ido2db_db_free_query(ido2db_idi *idi) { 02529 02530 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_free_query() start\n"); 02531 02532 if (idi == NULL) 02533 return IDO_ERROR; 02534 02535 /* ToDo: Examine where this function is called 02536 * Not freeing the query may result in memory leaks 02537 **/ 02538 02539 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_free_query() end\n"); 02540 return IDO_OK; 02541 } 02542 02543 /************************************/ 02544 /* handles SQL query errors */ 02545 /************************************/ 02546 int ido2db_handle_db_error(ido2db_idi *idi) { 02547 02548 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_db_error() start\n"); 02549 02550 if (idi == NULL) 02551 return IDO_ERROR; 02552 02553 /* we're not currently connected... */ 02554 if(ido2db_db_is_connected(idi)==IDO_TRUE) 02555 return IDO_OK; 02556 02557 ido2db_db_disconnect(idi); 02558 02559 idi->disconnect_client = IDO_TRUE; 02560 02561 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_db_error() end\n"); 02562 return IDO_OK; 02563 } 02564 02565 /**********************************************************/ 02566 /* clears data from a given table (current instance only) */ 02567 /**********************************************************/ 02568 int ido2db_db_clear_table(ido2db_idi *idi, char *table_name) { 02569 #ifdef USE_LIBDBI 02570 char *buf = NULL; 02571 #endif 02572 int result = IDO_OK; 02573 #ifdef USE_ORACLE 02574 void *data[2]; 02575 #endif 02576 02577 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_clear_table() start\n"); 02578 02579 if (idi == NULL || table_name == NULL) 02580 return IDO_ERROR; 02581 02582 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02583 if (asprintf(&buf, "DELETE FROM %s WHERE instance_id='%lu'", table_name, idi->dbinfo.instance_id) == -1) 02584 buf = NULL; 02585 02586 result = ido2db_db_query(idi, buf); 02587 02588 dbi_result_free(idi->dbinfo.dbi_result); 02589 free(buf); 02590 02591 #endif 02592 02593 #ifdef USE_PGSQL /* pgsql */ 02594 02595 #endif 02596 02597 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02598 02599 /* procedure approach */ 02600 data[0] = (void *) &table_name; 02601 data[1] = (void *) &idi->dbinfo.instance_id; 02602 02603 if(!OCI_BindString(idi->dbinfo.oci_statement_instances_delete, MT(":X1"), *(char **) data[0], 0)) { 02604 return IDO_ERROR; 02605 } 02606 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_instances_delete, MT(":X2"), (big_uint *) data[1])) { 02607 return IDO_ERROR; 02608 } 02609 02610 if(!OCI_Execute(idi->dbinfo.oci_statement_instances_delete)) { 02611 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_instances_delete() execute error\n"); 02612 return IDO_ERROR; 02613 } 02614 02615 OCI_Commit(idi->dbinfo.oci_connection); 02616 02617 #endif /* Oracle ocilib specific */ 02618 02619 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_clear_table() end\n"); 02620 return result; 02621 } 02622 02623 /**************************************************/ 02624 /* gets latest data time value from a given table */ 02625 /**************************************************/ 02626 int ido2db_db_get_latest_data_time(ido2db_idi *idi, char *table_name, char *field_name, unsigned long *t) { 02627 char *buf = NULL; 02628 char *ts[1]; 02629 int result = IDO_OK; 02630 02631 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_get_latest_data_time() start\n"); 02632 02633 if (idi == NULL || table_name == NULL || field_name == NULL || t == NULL) 02634 return IDO_ERROR; 02635 02636 *t = (time_t) 0L; 02637 ts[0] = ido2db_db_sql_to_timet(idi, field_name); 02638 02639 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02640 02641 if (asprintf(&buf,"SELECT %s AS latest_time FROM %s WHERE instance_id='%lu' ORDER BY %s DESC LIMIT 1 OFFSET 0", 02642 field_name, table_name, idi->dbinfo.instance_id, field_name) == -1) 02643 buf = NULL; 02644 02645 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 02646 if (idi->dbinfo.dbi_result != NULL) { 02647 if (dbi_result_next_row(idi->dbinfo.dbi_result)){ 02648 *t = dbi_result_get_datetime(idi->dbinfo.dbi_result, "latest_time"); 02649 } 02650 } 02651 } 02652 02653 #endif 02654 02655 #ifdef USE_PGSQL /* pgsql */ 02656 02657 #endif 02658 02659 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02660 02661 if( asprintf(&buf,"SELECT ( ( ( SELECT * FROM ( SELECT %s FROM %s WHERE instance_id='%lu' ORDER BY %s DESC) WHERE ROWNUM = 1 ) - to_date( '01-01-1970 00:00:00','dd-mm-yyyy hh24:mi:ss' )) * 86400) AS latest_time FROM DUAL" 02662 ,(field_name==NULL)?"":field_name 02663 ,table_name 02664 ,idi->dbinfo.instance_id 02665 ,field_name 02666 )==-1) 02667 buf=NULL; 02668 02669 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 02670 02671 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_get_latest_data_time() query ok\n"); 02672 if (idi->dbinfo.oci_resultset != NULL) { 02673 /* check if next row */ 02674 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 02675 *t = OCI_GetUnsignedInt(idi->dbinfo.oci_resultset, 1); 02676 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_get_latest_data_time(%lu)\n", *t); 02677 } 02678 } 02679 } 02680 02681 #endif /* Oracle ocilib specific */ 02682 02683 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02684 dbi_result_free(idi->dbinfo.dbi_result); 02685 #endif 02686 02687 #ifdef USE_PGSQL /* pgsql */ 02688 02689 #endif 02690 02691 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02692 02693 OCI_StatementFree(idi->dbinfo.oci_statement); 02694 02695 #endif /* Oracle ocilib specific */ 02696 02697 free(buf); 02698 free(ts[0]); 02699 02700 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_get_latest_data_time() end\n"); 02701 return result; 02702 } 02703 02704 /*******************************************/ 02705 /* trim/delete old data from a given table */ 02706 /*******************************************/ 02707 int ido2db_db_trim_data_table(ido2db_idi *idi, char *table_name, char *field_name, unsigned long t) { 02708 char *buf = NULL; 02709 char *ts[1]; 02710 int result = IDO_OK; 02711 02712 #ifdef USE_ORACLE 02713 void *data[4]; 02714 #endif 02715 02716 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_trim_data_table() start, time=%lu\n", t); 02717 02718 if (idi == NULL || table_name == NULL || field_name == NULL) 02719 return IDO_ERROR; 02720 02721 ts[0] = ido2db_db_timet_to_sql(idi, (time_t) t); 02722 02723 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02724 02725 if (asprintf(&buf, "DELETE FROM %s WHERE instance_id='%lu' AND %s<%s", 02726 table_name, idi->dbinfo.instance_id, field_name, ts[0]) == -1) 02727 buf = NULL; 02728 02729 result = ido2db_db_query(idi, buf); 02730 dbi_result_free(idi->dbinfo.dbi_result); 02731 02732 #endif 02733 02734 #ifdef USE_PGSQL /* pgsql */ 02735 02736 #endif 02737 02738 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02739 02740 data[0] = (void *) &table_name; 02741 data[1] = (void *) &idi->dbinfo.instance_id; 02742 data[2] = (void *) &field_name; 02743 data[3] = (void *) &t; 02744 02745 if(!OCI_BindString(idi->dbinfo.oci_statement_instances_delete_time, MT(":X1"), *(char **) data[0], 0)) { 02746 return IDO_ERROR; 02747 } 02748 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_instances_delete_time, MT(":X2"), (big_uint *) data[1])) { 02749 return IDO_ERROR; 02750 } 02751 if(!OCI_BindString(idi->dbinfo.oci_statement_instances_delete_time, MT(":X3"), *(char **) data[2], 0)) { 02752 return IDO_ERROR; 02753 } 02754 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_instances_delete_time, MT(":X4"), (big_uint *) data[3])) { // unixtimestamp instead of time2sql 02755 return IDO_ERROR; 02756 } 02757 02758 if(!OCI_Execute(idi->dbinfo.oci_statement_instances_delete_time)) { 02759 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_instances_delete_time() execute error\n"); 02760 return IDO_ERROR; 02761 } 02762 02763 OCI_Commit(idi->dbinfo.oci_connection); 02764 #endif /* Oracle ocilib specific */ 02765 02766 free(buf); 02767 free(ts[0]); 02768 02769 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_trim_data_table(%s => %s: %lu) end\n", table_name, field_name, t); 02770 return result; 02771 } 02772 02773 /***********************************************/ 02774 /* performs some periodic table maintenance... */ 02775 /***********************************************/ 02776 int ido2db_db_perform_maintenance(ido2db_idi *idi) { 02777 time_t current_time; 02778 02779 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_perform_maintenance() start\n"); 02780 02781 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_perform_maintenance() max_logentries_age=%lu, max_ack_age=%lu\n", idi->dbinfo.max_logentries_age, idi->dbinfo.max_logentries_age); 02782 02783 /* get the current time */ 02784 time(¤t_time); 02785 02786 /* trim tables */ 02787 if (((unsigned long) current_time - idi->dbinfo.trim_db_interval) > (unsigned long) idi->dbinfo.last_table_trim_time) { 02788 if (idi->dbinfo.max_timedevents_age > 0L) 02789 ido2db_db_trim_data_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS], "scheduled_time", (time_t) ((unsigned long) current_time - idi->dbinfo.max_timedevents_age)); 02790 if (idi->dbinfo.max_systemcommands_age > 0L) 02791 ido2db_db_trim_data_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SYSTEMCOMMANDS], "start_time", (time_t) ((unsigned long) current_time - idi->dbinfo.max_systemcommands_age)); 02792 if (idi->dbinfo.max_servicechecks_age > 0L) 02793 ido2db_db_trim_data_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECHECKS], "start_time", (time_t) ((unsigned long) current_time - idi->dbinfo.max_servicechecks_age)); 02794 if (idi->dbinfo.max_hostchecks_age > 0L) 02795 ido2db_db_trim_data_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCHECKS], "start_time", (time_t) ((unsigned long) current_time - idi->dbinfo.max_hostchecks_age)); 02796 if (idi->dbinfo.max_eventhandlers_age > 0L) 02797 ido2db_db_trim_data_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_EVENTHANDLERS], "start_time", (time_t) ((unsigned long) current_time - idi->dbinfo.max_eventhandlers_age)); 02798 if(idi->dbinfo.max_externalcommands_age>0L) 02799 ido2db_db_trim_data_table(idi,ido2db_db_tablenames[IDO2DB_DBTABLE_EXTERNALCOMMANDS],"entry_time",(time_t)((unsigned long)current_time - idi->dbinfo.max_externalcommands_age)); 02800 if(idi->dbinfo.max_logentries_age>0L) 02801 ido2db_db_trim_data_table(idi,ido2db_db_tablenames[IDO2DB_DBTABLE_LOGENTRIES],"logentry_time",(time_t)((unsigned long)current_time - idi->dbinfo.max_logentries_age)); 02802 if(idi->dbinfo.max_acknowledgements_age>0L) 02803 ido2db_db_trim_data_table(idi,ido2db_db_tablenames[IDO2DB_DBTABLE_ACKNOWLEDGEMENTS],"entry_time",(time_t)((unsigned long)current_time - idi->dbinfo.max_acknowledgements_age)); 02804 idi->dbinfo.last_table_trim_time = current_time; 02805 } 02806 02807 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_perform_maintenance() end\n"); 02808 return IDO_OK; 02809 } 02810 02811 /************************************/ 02812 /* check database driver (libdbi) */ 02813 /************************************/ 02814 02815 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02816 02817 int ido2db_check_dbd_driver(void) { 02818 02819 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_check_dbd_driver() start\n"); 02820 dbi_initialize(NULL); 02821 02822 switch (ido2db_db_settings.server_type) { 02823 case IDO2DB_DBSERVER_MYSQL: 02824 if ( (dbi_driver_open(IDO2DB_DBI_DRIVER_MYSQL)) == NULL){ 02825 dbi_shutdown(); 02826 return IDO_FALSE; 02827 } 02828 break; 02829 case IDO2DB_DBSERVER_PGSQL: 02830 if (dbi_driver_open(IDO2DB_DBI_DRIVER_PGSQL) == NULL){ 02831 dbi_shutdown(); 02832 return IDO_FALSE; 02833 } 02834 break; 02835 case IDO2DB_DBSERVER_DB2: 02836 if (dbi_driver_open(IDO2DB_DBI_DRIVER_DB2) == NULL){ 02837 dbi_shutdown(); 02838 return IDO_FALSE; 02839 } 02840 break; 02841 case IDO2DB_DBSERVER_FIREBIRD: 02842 if (dbi_driver_open(IDO2DB_DBI_DRIVER_FIREBIRD) == NULL){ 02843 dbi_shutdown(); 02844 return IDO_FALSE; 02845 } 02846 break; 02847 case IDO2DB_DBSERVER_FREETDS: 02848 if (dbi_driver_open(IDO2DB_DBI_DRIVER_FREETDS) == NULL){ 02849 dbi_shutdown(); 02850 return IDO_FALSE; 02851 } 02852 break; 02853 case IDO2DB_DBSERVER_INGRES: 02854 if (dbi_driver_open(IDO2DB_DBI_DRIVER_INGRES) == NULL){ 02855 dbi_shutdown(); 02856 return IDO_FALSE; 02857 } 02858 break; 02859 case IDO2DB_DBSERVER_MSQL: 02860 if (dbi_driver_open(IDO2DB_DBI_DRIVER_MSQL) == NULL){ 02861 dbi_shutdown(); 02862 return IDO_FALSE; 02863 } 02864 break; 02865 case IDO2DB_DBSERVER_ORACLE: 02866 02867 if (dbi_driver_open(IDO2DB_DBI_DRIVER_ORACLE) == NULL){ 02868 dbi_shutdown(); 02869 return IDO_FALSE; 02870 } 02871 break; 02872 case IDO2DB_DBSERVER_SQLITE: 02873 if (dbi_driver_open(IDO2DB_DBI_DRIVER_SQLITE) == NULL){ 02874 dbi_shutdown(); 02875 return IDO_FALSE; 02876 } 02877 break; 02878 case IDO2DB_DBSERVER_SQLITE3: 02879 if (dbi_driver_open(IDO2DB_DBI_DRIVER_SQLITE3) == NULL){ 02880 dbi_shutdown(); 02881 return IDO_FALSE; 02882 } 02883 break; 02884 default: 02885 dbi_shutdown(); 02886 return IDO_FALSE; 02887 break; 02888 } 02889 02890 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_check_dbd_driver() end\n"); 02891 return IDO_TRUE; 02892 } 02893 #endif 02894 02895 /************************************/ 02896 /* error handler (ocilib) */ 02897 /************************************/ 02898 02899 02900 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02901 02902 void ido2db_ocilib_err_handler(OCI_Error *err) { 02903 02904 if (OCI_ErrorGetType(err) == OCI_ERR_ORACLE) { 02905 const mtext *sql = OCI_GetSql(OCI_ErrorGetStatement(err)); 02906 02907 if (sql != NULL) { 02908 if(ido2db_db_settings.oci_errors_to_syslog==IDO_TRUE) { 02909 syslog(LOG_USER | LOG_INFO, "ERROR: QUERY '%s'\n", sql); 02910 } 02911 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ERROR: QUERY '%s'\n", sql); 02912 } 02913 } 02914 02915 if(ido2db_db_settings.oci_errors_to_syslog==IDO_TRUE) { 02916 syslog(LOG_USER | LOG_INFO, "ERROR: MSG '%s'\n", OCI_ErrorGetString(err)); 02917 } 02918 02919 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ERROR: MSG '%s'\n", OCI_ErrorGetString(err)); 02920 } 02921 02922 /* use defined triggers/sequences to emulate last insert id in oracle */ 02923 unsigned long ido2db_ocilib_insert_id(ido2db_idi *idi, char *seq_name) { 02924 02925 unsigned long insert_id = 0; 02926 char *buf = NULL; 02927 02928 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_ocilib_insert_id(%s) seq_name\n", seq_name); 02929 if(asprintf(&buf, "SELECT %s.CURRVAL FROM DUAL", seq_name) == -1) 02930 buf = NULL; 02931 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_ocilib_insert_id(%s) buf\n", buf); 02932 02933 if(idi->dbinfo.oci_connection) { 02934 02935 idi->dbinfo.oci_statement = OCI_StatementCreate(idi->dbinfo.oci_connection); 02936 02937 OCI_ExecuteStmt(idi->dbinfo.oci_statement, MT(buf)); 02938 OCI_Commit(idi->dbinfo.oci_connection); 02939 02940 /* get result set */ 02941 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement); 02942 02943 if(idi->dbinfo.oci_resultset == NULL) { 02944 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_ocilib_insert_id() nextrow not ok\n"); 02945 } else { 02946 02947 /* check if next row */ 02948 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 02949 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_ocilib_insert_id() nextrow ok\n"); 02950 insert_id = OCI_GetUnsignedInt(idi->dbinfo.oci_resultset, 1); 02951 } 02952 } 02953 02954 /* free statement */ 02955 OCI_StatementFree(idi->dbinfo.oci_statement); 02956 02957 } else { 02958 insert_id = -1; 02959 } 02960 02961 free(buf); 02962 02963 return insert_id; 02964 } 02965 02966 02967 /****************************************************************************/ 02968 /* PREPARED STATEMENTS */ 02969 /****************************************************************************/ 02970 02971 02972 /************************************/ 02973 /* SEQUENCE */ 02974 /************************************/ 02975 02976 /* 02977 int ido2db_oci_prepared_statement_sequence_select(ido2db_idi *idi) { 02978 02979 char *buf = NULL; 02980 02981 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 02982 02983 if(asprintf(&buf, "SELECT :X1.CURRVAL FROM DUAL") == -1) { 02984 buf = NULL; 02985 } 02986 02987 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 02988 02989 if(idi->dbinfo.oci_connection) { 02990 02991 idi->dbinfo.oci_statement_sequence_select = OCI_StatementCreate(idi->dbinfo.oci_connection); 02992 02993 OCI_AllowRebinding(idi->dbinfo.oci_statement_sequence_select, 1); 02994 02995 if(!OCI_Prepare(idi->dbinfo.oci_statement_sequence_select, MT(buf))) { 02996 free(buf); 02997 return IDO_ERROR; 02998 } 02999 } else { 03000 free(buf); 03001 return IDO_ERROR; 03002 } 03003 free(buf); 03004 03005 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03006 03007 return IDO_OK; 03008 } 03009 */ 03010 03011 /************************************/ 03012 /* INSTANCES */ 03013 /************************************/ 03014 03015 03016 int ido2db_oci_prepared_statement_instances(ido2db_idi *idi) { 03017 03018 char *buf = NULL; 03019 03020 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03021 03022 if(asprintf(&buf, "INSERT INTO %s (id, instance_name) VALUES (seq_instances.nextval, :X1) RETURNING id INTO :id", 03023 ido2db_db_tablenames[IDO2DB_DBTABLE_INSTANCES]) == -1) { 03024 buf = NULL; 03025 } 03026 03027 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03028 03029 if(idi->dbinfo.oci_connection) { 03030 03031 idi->dbinfo.oci_statement_instances = OCI_StatementCreate(idi->dbinfo.oci_connection); 03032 03033 /* allow rebinding values */ 03034 OCI_AllowRebinding(idi->dbinfo.oci_statement_instances, 1); 03035 03036 if(!OCI_Prepare(idi->dbinfo.oci_statement_instances, MT(buf))) { 03037 free(buf); 03038 return IDO_ERROR; 03039 } 03040 OCI_RegisterInt(idi->dbinfo.oci_statement_instances, ":id"); 03041 } else { 03042 free(buf); 03043 return IDO_ERROR; 03044 } 03045 free(buf); 03046 03047 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03048 03049 return IDO_OK; 03050 } 03051 03052 int ido2db_oci_prepared_statement_instances_select(ido2db_idi *idi) { 03053 03054 char *buf = NULL; 03055 03056 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03057 03058 if(asprintf(&buf, "SELECT id FROM %s WHERE instance_name=:X1", 03059 ido2db_db_tablenames[IDO2DB_DBTABLE_INSTANCES]) == -1) { 03060 buf = NULL; 03061 } 03062 03063 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03064 03065 if(idi->dbinfo.oci_connection) { 03066 03067 idi->dbinfo.oci_statement_instances_select = OCI_StatementCreate(idi->dbinfo.oci_connection); 03068 03069 /* allow rebinding values */ 03070 OCI_AllowRebinding(idi->dbinfo.oci_statement_instances_select, 1); 03071 03072 if(!OCI_Prepare(idi->dbinfo.oci_statement_instances_select, MT(buf))) { 03073 free(buf); 03074 return IDO_ERROR; 03075 } 03076 } else { 03077 free(buf); 03078 return IDO_ERROR; 03079 } 03080 free(buf); 03081 03082 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03083 03084 return IDO_OK; 03085 } 03086 03087 03088 int ido2db_oci_prepared_statement_dbversion_select(ido2db_idi *idi) { 03089 03090 char *buf = NULL; 03091 03092 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_dbversion_select() start\n"); 03093 03094 if(asprintf(&buf, "SELECT version FROM %s WHERE name=:X1", 03095 ido2db_db_tablenames[IDO2DB_DBTABLE_DBVERSION]) == -1) { 03096 buf = NULL; 03097 } 03098 03099 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_dbversion_select() query: %s\n", buf); 03100 03101 if(idi->dbinfo.oci_connection) { 03102 03103 idi->dbinfo.oci_statement_dbversion_select = OCI_StatementCreate(idi->dbinfo.oci_connection); 03104 03105 /* allow rebinding values */ 03106 OCI_AllowRebinding(idi->dbinfo.oci_statement_dbversion_select, 1); 03107 03108 if(!OCI_Prepare(idi->dbinfo.oci_statement_dbversion_select, MT(buf))) { 03109 free(buf); 03110 return IDO_ERROR; 03111 } 03112 } else { 03113 free(buf); 03114 return IDO_ERROR; 03115 } 03116 free(buf); 03117 03118 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_dbversion_select() end\n"); 03119 03120 return IDO_OK; 03121 } 03122 03123 03124 /************************************/ 03125 /* CONNINFO */ 03126 /************************************/ 03127 03128 03129 int ido2db_oci_prepared_statement_conninfo(ido2db_idi *idi) { 03130 03131 char *buf = NULL; 03132 03133 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03134 03135 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, connect_time, last_checkin_time, bytes_processed, lines_processed, entries_processed, agent_name, agent_version, disposition, connect_source, connect_type, data_start_time) VALUES (seq_conninfo.nextval, :X1, SYSDATE, SYSDATE, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, SYSDATE) RETURNING id INTO :id", 03136 ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO]) == -1) { 03137 buf = NULL; 03138 } 03139 03140 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03141 03142 if(idi->dbinfo.oci_connection) { 03143 03144 idi->dbinfo.oci_statement_conninfo = OCI_StatementCreate(idi->dbinfo.oci_connection); 03145 03146 /* allow rebinding values */ 03147 OCI_AllowRebinding(idi->dbinfo.oci_statement_conninfo, 1); 03148 03149 if(!OCI_Prepare(idi->dbinfo.oci_statement_conninfo, MT(buf))) { 03150 free(buf); 03151 return IDO_ERROR; 03152 } 03153 OCI_RegisterInt(idi->dbinfo.oci_statement_conninfo, ":id"); 03154 } else { 03155 free(buf); 03156 return IDO_ERROR; 03157 } 03158 free(buf); 03159 03160 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03161 03162 return IDO_OK; 03163 } 03164 03165 03166 int ido2db_oci_prepared_statement_conninfo_update(ido2db_idi *idi) { 03167 03168 char *buf = NULL; 03169 03170 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_conninfo_update() start\n"); 03171 03172 if(asprintf(&buf, "UPDATE %s SET disconnect_time=SYSDATE, last_checkin_time=SYSDATE, data_end_time=(SELECT unixts2date(:X1) FROM DUAL), bytes_processed=:X2, lines_processed=:X3, entries_processed=:X4 WHERE id=:X5", 03173 ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO]) == -1) { 03174 buf = NULL; 03175 } 03176 03177 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_conninfo_update() query: %s\n", buf); 03178 03179 if(idi->dbinfo.oci_connection) { 03180 03181 idi->dbinfo.oci_statement_conninfo_update = OCI_StatementCreate(idi->dbinfo.oci_connection); 03182 03183 /* allow rebinding values */ 03184 OCI_AllowRebinding(idi->dbinfo.oci_statement_conninfo_update, 1); 03185 03186 if(!OCI_Prepare(idi->dbinfo.oci_statement_conninfo_update, MT(buf))) { 03187 free(buf); 03188 return IDO_ERROR; 03189 } 03190 } else { 03191 free(buf); 03192 return IDO_ERROR; 03193 } 03194 free(buf); 03195 03196 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03197 03198 return IDO_OK; 03199 } 03200 03201 03202 int ido2db_oci_prepared_statement_conninfo_update_checkin(ido2db_idi *idi) { 03203 03204 char *buf = NULL; 03205 03206 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03207 03208 if(asprintf(&buf, "UPDATE %s SET last_checkin_time=SYSDATE, bytes_processed=:X1, lines_processed=:X2, entries_processed=:X3 WHERE id=:X4", 03209 ido2db_db_tablenames[IDO2DB_DBTABLE_CONNINFO]) == -1) { 03210 buf = NULL; 03211 } 03212 03213 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03214 03215 if(idi->dbinfo.oci_connection) { 03216 03217 idi->dbinfo.oci_statement_conninfo_update_checkin = OCI_StatementCreate(idi->dbinfo.oci_connection); 03218 03219 /* allow rebinding values */ 03220 OCI_AllowRebinding(idi->dbinfo.oci_statement_conninfo_update_checkin, 1); 03221 03222 if(!OCI_Prepare(idi->dbinfo.oci_statement_conninfo_update_checkin, MT(buf))) { 03223 free(buf); 03224 return IDO_ERROR; 03225 } 03226 } else { 03227 free(buf); 03228 return IDO_ERROR; 03229 } 03230 free(buf); 03231 03232 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03233 03234 return IDO_OK; 03235 } 03236 03237 03238 /************************************/ 03239 /* OBJECTS INSERT */ 03240 /************************************/ 03241 03242 int ido2db_oci_prepared_statement_objects_insert(ido2db_idi *idi) { 03243 03244 char *buf = NULL; 03245 03246 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_objects_insert() start\n"); 03247 03248 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, objecttype_id, name1, name2) VALUES (seq_objects.nextval, :X1, :X2, :X3, :X4) RETURNING id INTO :id", 03249 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) { 03250 buf = NULL; 03251 } 03252 03253 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_objects_insert() query: %s\n", buf); 03254 03255 if(idi->dbinfo.oci_connection) { 03256 03257 idi->dbinfo.oci_statement_objects_insert = OCI_StatementCreate(idi->dbinfo.oci_connection); 03258 03259 /* allow rebinding values */ 03260 OCI_AllowRebinding(idi->dbinfo.oci_statement_objects_insert, 1); 03261 03262 if(!OCI_Prepare(idi->dbinfo.oci_statement_objects_insert, MT(buf))) { 03263 free(buf); 03264 return IDO_ERROR; 03265 } 03266 OCI_RegisterInt(idi->dbinfo.oci_statement_objects_insert, ":id"); 03267 } else { 03268 free(buf); 03269 return IDO_ERROR; 03270 } 03271 free(buf); 03272 03273 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_objects_insert() end\n"); 03274 03275 return IDO_OK; 03276 } 03277 03278 03279 /************************************/ 03280 /* OBJECTS SELECT */ 03281 /************************************/ 03282 03283 03284 int ido2db_oci_prepared_statement_objects_select_cached(ido2db_idi *idi) { 03285 03286 03287 char *buf = NULL; 03288 03289 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03290 03291 if(asprintf(&buf, "SELECT id, objecttype_id, name1, name2 FROM %s WHERE instance_id=:X1", 03292 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) { 03293 buf = NULL; 03294 } 03295 03296 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03297 03298 if(idi->dbinfo.oci_connection) { 03299 03300 idi->dbinfo.oci_statement_objects_select_cached = OCI_StatementCreate(idi->dbinfo.oci_connection); 03301 03302 /* allow rebinding values */ 03303 OCI_AllowRebinding(idi->dbinfo.oci_statement_objects_select_cached, 1); 03304 03305 if(!OCI_Prepare(idi->dbinfo.oci_statement_objects_select_cached, MT(buf))) { 03306 free(buf); 03307 return IDO_ERROR; 03308 } 03309 } else { 03310 free(buf); 03311 return IDO_ERROR; 03312 } 03313 free(buf); 03314 03315 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03316 03317 return IDO_OK; 03318 } 03319 03320 int ido2db_oci_prepared_statement_objects_select_name1_name2(ido2db_idi *idi) { 03321 03322 char *buf = NULL; 03323 03324 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03325 03326 if(asprintf(&buf, "SELECT id FROM %s WHERE instance_id=:X1 AND objecttype_id=:X2 AND name1=:X3 AND name2=:X4", 03327 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) { 03328 buf = NULL; 03329 } 03330 03331 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03332 03333 if(idi->dbinfo.oci_connection) { 03334 03335 idi->dbinfo.oci_statement_objects_select_name1_name2 = OCI_StatementCreate(idi->dbinfo.oci_connection); 03336 03337 /* allow rebinding values */ 03338 OCI_AllowRebinding(idi->dbinfo.oci_statement_objects_select_name1_name2, 1); 03339 03340 if(!OCI_Prepare(idi->dbinfo.oci_statement_objects_select_name1_name2, MT(buf))) { 03341 free(buf); 03342 return IDO_ERROR; 03343 } 03344 } else { 03345 free(buf); 03346 return IDO_ERROR; 03347 } 03348 free(buf); 03349 03350 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03351 03352 return IDO_OK; 03353 } 03354 03355 int ido2db_oci_prepared_statement_objects_select_name1_null_name2(ido2db_idi *idi) { 03356 03357 char *buf = NULL; 03358 03359 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03360 03361 if(asprintf(&buf, "SELECT id FROM %s WHERE instance_id=:X1 AND objecttype_id=:X2 AND name1 IS NULL AND name2=:X3", 03362 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) { 03363 buf = NULL; 03364 } 03365 03366 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03367 03368 if(idi->dbinfo.oci_connection) { 03369 03370 idi->dbinfo.oci_statement_objects_select_name1_null_name2 = OCI_StatementCreate(idi->dbinfo.oci_connection); 03371 03372 /* allow rebinding values */ 03373 OCI_AllowRebinding(idi->dbinfo.oci_statement_objects_select_name1_null_name2, 1); 03374 03375 if(!OCI_Prepare(idi->dbinfo.oci_statement_objects_select_name1_null_name2, MT(buf))) { 03376 free(buf); 03377 return IDO_ERROR; 03378 } 03379 } else { 03380 free(buf); 03381 return IDO_ERROR; 03382 } 03383 free(buf); 03384 03385 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03386 03387 return IDO_OK; 03388 } 03389 03390 int ido2db_oci_prepared_statement_objects_select_name1_name2_null(ido2db_idi *idi) { 03391 03392 char *buf = NULL; 03393 03394 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03395 03396 if(asprintf(&buf, "SELECT id FROM %s WHERE instance_id=:X1 AND objecttype_id=:X2 AND name1=:X3 AND name2 IS NULL", 03397 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) { 03398 buf = NULL; 03399 } 03400 03401 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03402 03403 if(idi->dbinfo.oci_connection) { 03404 03405 idi->dbinfo.oci_statement_objects_select_name1_name2_null = OCI_StatementCreate(idi->dbinfo.oci_connection); 03406 03407 /* allow rebinding values */ 03408 OCI_AllowRebinding(idi->dbinfo.oci_statement_objects_select_name1_name2_null, 1); 03409 03410 if(!OCI_Prepare(idi->dbinfo.oci_statement_objects_select_name1_name2_null, MT(buf))) { 03411 free(buf); 03412 return IDO_ERROR; 03413 } 03414 } else { 03415 free(buf); 03416 return IDO_ERROR; 03417 } 03418 free(buf); 03419 03420 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03421 03422 return IDO_OK; 03423 } 03424 03425 int ido2db_oci_prepared_statement_objects_select_name1_null_name2_null(ido2db_idi *idi) { 03426 03427 char *buf = NULL; 03428 03429 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03430 03431 if(asprintf(&buf, "SELECT id FROM %s WHERE instance_id=:X1 AND objecttype_id=:X2 AND name1 IS NULL AND name2 IS NULL", 03432 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) { 03433 buf = NULL; 03434 } 03435 03436 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03437 03438 if(idi->dbinfo.oci_connection) { 03439 03440 idi->dbinfo.oci_statement_objects_select_name1_null_name2_null = OCI_StatementCreate(idi->dbinfo.oci_connection); 03441 03442 /* allow rebinding values */ 03443 OCI_AllowRebinding(idi->dbinfo.oci_statement_objects_select_name1_null_name2_null, 1); 03444 03445 if(!OCI_Prepare(idi->dbinfo.oci_statement_objects_select_name1_null_name2_null, MT(buf))) { 03446 free(buf); 03447 return IDO_ERROR; 03448 } 03449 } else { 03450 free(buf); 03451 return IDO_ERROR; 03452 } 03453 free(buf); 03454 03455 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03456 03457 return IDO_OK; 03458 } 03459 03460 /************************************/ 03461 /* OBJECTS UPDATE */ 03462 /************************************/ 03463 03464 03465 int ido2db_oci_prepared_statement_objects_update_inactive(ido2db_idi *idi) { 03466 03467 char *buf = NULL; 03468 03469 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03470 03471 if(asprintf(&buf, "UPDATE %s SET is_active=:X1 WHERE instance_id=:X2", 03472 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) { 03473 buf = NULL; 03474 } 03475 03476 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03477 03478 if(idi->dbinfo.oci_connection) { 03479 03480 idi->dbinfo.oci_statement_objects_update_inactive = OCI_StatementCreate(idi->dbinfo.oci_connection); 03481 03482 /* allow rebinding values */ 03483 OCI_AllowRebinding(idi->dbinfo.oci_statement_objects_update_inactive, 1); 03484 03485 if(!OCI_Prepare(idi->dbinfo.oci_statement_objects_update_inactive, MT(buf))) { 03486 free(buf); 03487 return IDO_ERROR; 03488 } 03489 } else { 03490 free(buf); 03491 return IDO_ERROR; 03492 } 03493 free(buf); 03494 03495 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03496 03497 return IDO_OK; 03498 } 03499 03500 03501 int ido2db_oci_prepared_statement_objects_update_active(ido2db_idi *idi) { 03502 03503 char *buf = NULL; 03504 03505 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03506 03507 if(asprintf(&buf, "UPDATE %s SET is_active=:X1 WHERE instance_id=:X2 AND objecttype_id=:X3 AND id=:X4", 03508 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) { 03509 buf = NULL; 03510 } 03511 03512 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03513 03514 if(idi->dbinfo.oci_connection) { 03515 03516 idi->dbinfo.oci_statement_objects_update_active = OCI_StatementCreate(idi->dbinfo.oci_connection); 03517 03518 /* allow rebinding values */ 03519 OCI_AllowRebinding(idi->dbinfo.oci_statement_objects_update_active, 1); 03520 03521 if(!OCI_Prepare(idi->dbinfo.oci_statement_objects_update_active, MT(buf))) { 03522 free(buf); 03523 return IDO_ERROR; 03524 } 03525 } else { 03526 free(buf); 03527 return IDO_ERROR; 03528 } 03529 free(buf); 03530 03531 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03532 03533 return IDO_OK; 03534 } 03535 03536 03537 /************************************/ 03538 /* LOGENTRIES */ 03539 /************************************/ 03540 03541 03542 int ido2db_oci_prepared_statement_logentries_insert(ido2db_idi *idi) { 03543 03544 char *buf = NULL; 03545 03546 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_logentries_insert() start\n"); 03547 03548 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, logentry_time, entry_time, entry_time_usec, logentry_type, logentry_data, realtime_data, inferred_data_extracted) VALUES (seq_logentries.nextval, :X1, (SELECT unixts2date(:X2) FROM DUAL), (SELECT unixts2date(:X3) FROM DUAL), :X4, :X5, :X6, :X7, :X8)", 03549 ido2db_db_tablenames[IDO2DB_DBTABLE_LOGENTRIES]) == -1) { 03550 buf = NULL; 03551 } 03552 03553 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_logentries_insert() query: %s\n", buf); 03554 03555 if(idi->dbinfo.oci_connection) { 03556 03557 idi->dbinfo.oci_statement_logentries_insert = OCI_StatementCreate(idi->dbinfo.oci_connection); 03558 03559 /* allow rebinding values */ 03560 OCI_AllowRebinding(idi->dbinfo.oci_statement_logentries_insert, 1); 03561 03562 if(!OCI_Prepare(idi->dbinfo.oci_statement_logentries_insert, MT(buf))) { 03563 free(buf); 03564 return IDO_ERROR; 03565 } 03566 } else { 03567 free(buf); 03568 return IDO_ERROR; 03569 } 03570 free(buf); 03571 03572 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_logentries_insert() end\n"); 03573 03574 return IDO_OK; 03575 } 03576 03577 int ido2db_oci_prepared_statement_logentries_select(ido2db_idi *idi) { 03578 03579 char *buf = NULL; 03580 03581 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03582 03583 if(asprintf(&buf, "SELECT id FROM %s WHERE instance_id=:X1 AND logentry_time=(SELECT unixts2date(:X2) FROM DUAL) AND logentry_data=:X3", 03584 ido2db_db_tablenames[IDO2DB_DBTABLE_LOGENTRIES]) == -1) { 03585 buf = NULL; 03586 } 03587 03588 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03589 03590 if(idi->dbinfo.oci_connection) { 03591 03592 idi->dbinfo.oci_statement_logentries_select = OCI_StatementCreate(idi->dbinfo.oci_connection); 03593 03594 /* allow rebinding values */ 03595 OCI_AllowRebinding(idi->dbinfo.oci_statement_logentries_select, 1); 03596 03597 if(!OCI_Prepare(idi->dbinfo.oci_statement_logentries_select, MT(buf))) { 03598 free(buf); 03599 return IDO_ERROR; 03600 } 03601 } else { 03602 free(buf); 03603 return IDO_ERROR; 03604 } 03605 free(buf); 03606 03607 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03608 03609 return IDO_OK; 03610 } 03611 03612 03613 03614 /************************************/ 03615 /* PROCESSEVENTS */ 03616 /************************************/ 03617 03618 03619 int ido2db_oci_prepared_statement_process_events(ido2db_idi *idi) { 03620 03621 char *buf = NULL; 03622 03623 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03624 03625 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, event_type, event_time, event_time_usec, process_id, program_name, program_version, program_date) VALUES (seq_processevents.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, :X5, :X6, :X7, :X8)", 03626 ido2db_db_tablenames[IDO2DB_DBTABLE_PROCESSEVENTS]) == -1) { 03627 buf = NULL; 03628 } 03629 03630 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03631 03632 if(idi->dbinfo.oci_connection) { 03633 03634 idi->dbinfo.oci_statement_process_events = OCI_StatementCreate(idi->dbinfo.oci_connection); 03635 03636 /* allow rebinding values */ 03637 OCI_AllowRebinding(idi->dbinfo.oci_statement_process_events, 1); 03638 03639 if(!OCI_Prepare(idi->dbinfo.oci_statement_process_events, MT(buf))) { 03640 free(buf); 03641 return IDO_ERROR; 03642 } 03643 } else { 03644 free(buf); 03645 return IDO_ERROR; 03646 } 03647 free(buf); 03648 03649 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03650 03651 return IDO_OK; 03652 } 03653 03654 03655 /************************************/ 03656 /* FLAPPINGHISTORY */ 03657 /************************************/ 03658 03659 03660 int ido2db_oci_prepared_statement_flappinghistory(ido2db_idi *idi) { 03661 03662 char *buf = NULL; 03663 03664 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03665 03666 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, event_time, event_time_usec, event_type, reason_type, flapping_type, object_id, percent_state_change, low_threshold, high_threshold, comment_time, internal_comment_id) VALUES (seq_flappinghistory.nextval, :X1, (SELECT unixts2date(:X2) FROM DUAL), :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, (SELECT unixts2date(:X11) FROM DUAL), :X12)", 03667 ido2db_db_tablenames[IDO2DB_DBTABLE_FLAPPINGHISTORY]) == -1) { 03668 buf = NULL; 03669 } 03670 03671 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03672 03673 if(idi->dbinfo.oci_connection) { 03674 03675 idi->dbinfo.oci_statement_flappinghistory = OCI_StatementCreate(idi->dbinfo.oci_connection); 03676 03677 /* allow rebinding values */ 03678 OCI_AllowRebinding(idi->dbinfo.oci_statement_flappinghistory, 1); 03679 03680 if(!OCI_Prepare(idi->dbinfo.oci_statement_flappinghistory, MT(buf))) { 03681 free(buf); 03682 return IDO_ERROR; 03683 } 03684 } else { 03685 free(buf); 03686 return IDO_ERROR; 03687 } 03688 free(buf); 03689 03690 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03691 03692 return IDO_OK; 03693 } 03694 03695 /************************************/ 03696 /* EXTERNALCOMMANDS */ 03697 /************************************/ 03698 03699 03700 int ido2db_oci_prepared_statement_external_commands(ido2db_idi *idi) { 03701 03702 char *buf = NULL; 03703 03704 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03705 03706 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, command_type, entry_time, command_name, command_args) VALUES (seq_externalcommands.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, :X5)", 03707 ido2db_db_tablenames[IDO2DB_DBTABLE_EXTERNALCOMMANDS]) == -1) { 03708 buf = NULL; 03709 } 03710 03711 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03712 03713 if(idi->dbinfo.oci_connection) { 03714 03715 idi->dbinfo.oci_statement_external_commands = OCI_StatementCreate(idi->dbinfo.oci_connection); 03716 03717 /* allow rebinding values */ 03718 OCI_AllowRebinding(idi->dbinfo.oci_statement_external_commands, 1); 03719 03720 if(!OCI_Prepare(idi->dbinfo.oci_statement_external_commands, MT(buf))) { 03721 free(buf); 03722 return IDO_ERROR; 03723 } 03724 } else { 03725 free(buf); 03726 return IDO_ERROR; 03727 } 03728 free(buf); 03729 03730 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03731 03732 return IDO_OK; 03733 } 03734 03735 /************************************/ 03736 /* ACKNOWLEDGMENTS */ 03737 /************************************/ 03738 03739 03740 int ido2db_oci_prepared_statement_acknowledgements(ido2db_idi *idi) { 03741 03742 char *buf = NULL; 03743 03744 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03745 03746 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, entry_time, entry_time_usec, acknowledgement_type, object_id, state, author_name, comment_data, is_sticky, persistent_comment, notify_contacts) VALUES (seq_acknowledgements.nextval, :X1, (SELECT unixts2date(:X2) FROM DUAL), :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11)", 03747 ido2db_db_tablenames[IDO2DB_DBTABLE_ACKNOWLEDGEMENTS]) == -1) { 03748 buf = NULL; 03749 } 03750 03751 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03752 03753 if(idi->dbinfo.oci_connection) { 03754 03755 idi->dbinfo.oci_statement_acknowledgements = OCI_StatementCreate(idi->dbinfo.oci_connection); 03756 03757 /* allow rebinding values */ 03758 OCI_AllowRebinding(idi->dbinfo.oci_statement_acknowledgements, 1); 03759 03760 if(!OCI_Prepare(idi->dbinfo.oci_statement_acknowledgements, MT(buf))) { 03761 free(buf); 03762 return IDO_ERROR; 03763 } 03764 } else { 03765 free(buf); 03766 return IDO_ERROR; 03767 } 03768 free(buf); 03769 03770 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03771 03772 return IDO_OK; 03773 } 03774 03775 /************************************/ 03776 /* STATEHISTORY */ 03777 /************************************/ 03778 03779 03780 int ido2db_oci_prepared_statement_statehistory(ido2db_idi *idi) { 03781 03782 char *buf = NULL; 03783 03784 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03785 03786 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, state_time, state_time_usec, object_id, state_change, state, state_type, current_check_attempt, max_check_attempts, last_state, last_hard_state, output, long_output) VALUES (seq_statehistory.nextval, :X1, (SELECT unixts2date(:X2) FROM DUAL), :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11, :X12, :X13)", 03787 ido2db_db_tablenames[IDO2DB_DBTABLE_STATEHISTORY]) == -1) { 03788 buf = NULL; 03789 } 03790 03791 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03792 03793 if(idi->dbinfo.oci_connection) { 03794 03795 idi->dbinfo.oci_statement_statehistory = OCI_StatementCreate(idi->dbinfo.oci_connection); 03796 03797 /* allow rebinding values */ 03798 OCI_AllowRebinding(idi->dbinfo.oci_statement_statehistory, 1); 03799 03800 if(!OCI_Prepare(idi->dbinfo.oci_statement_statehistory, MT(buf))) { 03801 free(buf); 03802 return IDO_ERROR; 03803 } 03804 } else { 03805 free(buf); 03806 return IDO_ERROR; 03807 } 03808 free(buf); 03809 03810 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03811 03812 return IDO_OK; 03813 } 03814 03815 03816 03817 /************************************/ 03818 /* TIMED EVENTS */ 03819 /************************************/ 03820 03821 int ido2db_oci_prepared_statement_timedevents_queue(ido2db_idi *idi) { 03822 03823 char *buf = NULL; 03824 03825 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents_queue() start\n"); 03826 03827 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND event_type=:X2 AND scheduled_time=(SELECT unixts2date(:X5) FROM DUAL) AND object_id=:X7) WHEN MATCHED THEN UPDATE SET queued_time=(SELECT unixts2date(:X3) FROM DUAL), queued_time_usec=:X4, recurring_event=:X6 WHEN NOT MATCHED THEN INSERT (id, instance_id, event_type, queued_time, queued_time_usec, scheduled_time, recurring_event, object_id) VALUES (seq_timedevents.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, (SELECT unixts2date(:X5) FROM DUAL), :X6, :X7)", 03828 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS]) == -1) { 03829 buf = NULL; 03830 } 03831 03832 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents_queue() query: %s\n", buf); 03833 03834 if(idi->dbinfo.oci_connection) { 03835 03836 idi->dbinfo.oci_statement_timedevents_queue = OCI_StatementCreate(idi->dbinfo.oci_connection); 03837 03838 /* allow rebinding values */ 03839 OCI_AllowRebinding(idi->dbinfo.oci_statement_timedevents_queue, 1); 03840 03841 if(!OCI_Prepare(idi->dbinfo.oci_statement_timedevents_queue, MT(buf))) { 03842 free(buf); 03843 return IDO_ERROR; 03844 } 03845 } else { 03846 free(buf); 03847 return IDO_ERROR; 03848 } 03849 free(buf); 03850 03851 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents_queue() end\n"); 03852 03853 return IDO_OK; 03854 } 03855 03856 int ido2db_oci_prepared_statement_timedeventqueue(ido2db_idi *idi) { 03857 03858 char *buf = NULL; 03859 03860 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedeventqueue() start\n"); 03861 03862 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND event_type=:X2 AND scheduled_time=(SELECT unixts2date(:X5) FROM DUAL) AND object_id=:X7) WHEN MATCHED THEN UPDATE SET queued_time=(SELECT unixts2date(:X3) FROM DUAL), queued_time_usec=:X4, recurring_event=:X6 WHEN NOT MATCHED THEN INSERT (id, instance_id, event_type, queued_time, queued_time_usec, scheduled_time, recurring_event, object_id) VALUES (seq_timedeventqueue.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, (SELECT unixts2date(:X5) FROM DUAL), :X6, :X7)", 03863 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE]) == -1) { 03864 buf = NULL; 03865 } 03866 03867 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedeventqueue() query: %s\n", buf); 03868 03869 if(idi->dbinfo.oci_connection) { 03870 03871 idi->dbinfo.oci_statement_timedeventqueue = OCI_StatementCreate(idi->dbinfo.oci_connection); 03872 03873 /* allow rebinding values */ 03874 OCI_AllowRebinding(idi->dbinfo.oci_statement_timedeventqueue, 1); 03875 03876 if(!OCI_Prepare(idi->dbinfo.oci_statement_timedeventqueue, MT(buf))) { 03877 free(buf); 03878 return IDO_ERROR; 03879 } 03880 } else { 03881 free(buf); 03882 return IDO_ERROR; 03883 } 03884 free(buf); 03885 03886 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedeventqueue() end\n"); 03887 03888 return IDO_OK; 03889 } 03890 03891 int ido2db_oci_prepared_statement_timedevents(ido2db_idi *idi) { 03892 03893 char *buf = NULL; 03894 03895 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents() start\n"); 03896 03897 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND event_type=:X2 AND scheduled_time=(SELECT unixts2date(:X5) FROM DUAL) AND object_id=:X7) WHEN MATCHED THEN UPDATE SET event_time=(SELECT unixts2date(:X3) FROM DUAL), event_time_usec=:X4, recurring_event=:X6 WHEN NOT MATCHED THEN INSERT (id, instance_id, event_type, event_time, event_time_usec, scheduled_time, recurring_event, object_id) VALUES (seq_timedevents.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, (SELECT unixts2date(:X5) FROM DUAL), :X6, :X7)", 03898 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS]) == -1) { 03899 buf = NULL; 03900 } 03901 03902 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents() query: %s\n", buf); 03903 03904 if(idi->dbinfo.oci_connection) { 03905 03906 idi->dbinfo.oci_statement_timedevents = OCI_StatementCreate(idi->dbinfo.oci_connection); 03907 03908 /* allow rebinding values */ 03909 OCI_AllowRebinding(idi->dbinfo.oci_statement_timedevents, 1); 03910 03911 if(!OCI_Prepare(idi->dbinfo.oci_statement_timedevents, MT(buf))) { 03912 free(buf); 03913 return IDO_ERROR; 03914 } 03915 } else { 03916 free(buf); 03917 return IDO_ERROR; 03918 } 03919 free(buf); 03920 03921 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_timedevents() end\n"); 03922 03923 return IDO_OK; 03924 } 03925 03926 int ido2db_oci_prepared_statement_timedevents_update(ido2db_idi *idi) { 03927 03928 char *buf = NULL; 03929 03930 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 03931 03932 if(asprintf(&buf, "UPDATE %s SET deletion_time=(SELECT unixts2date(:X1) FROM DUAL), deletion_time_usec=:X2 WHERE instance_id=:X3 AND event_type=:X4 AND scheduled_time=(SELECT unixts2date(:X5) FROM DUAL) AND recurring_event=:X6 AND object_id=:X7", 03933 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS]) == -1) { 03934 buf = NULL; 03935 } 03936 03937 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 03938 03939 if(idi->dbinfo.oci_connection) { 03940 03941 idi->dbinfo.oci_statement_timedevents_update = OCI_StatementCreate(idi->dbinfo.oci_connection); 03942 03943 /* allow rebinding values */ 03944 OCI_AllowRebinding(idi->dbinfo.oci_statement_timedevents_update, 1); 03945 03946 if(!OCI_Prepare(idi->dbinfo.oci_statement_timedevents_update, MT(buf))) { 03947 free(buf); 03948 return IDO_ERROR; 03949 } 03950 } else { 03951 free(buf); 03952 return IDO_ERROR; 03953 } 03954 free(buf); 03955 03956 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 03957 03958 return IDO_OK; 03959 } 03960 03961 03962 /************************************/ 03963 /* HOSTSTATUS/CHECK */ 03964 /************************************/ 03965 03966 int ido2db_oci_prepared_statement_hoststatus(ido2db_idi *idi) { 03967 03968 char *buf = NULL; 03969 03970 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hoststatus() start\n"); 03971 03972 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (host_object_id=:X2) WHEN MATCHED THEN UPDATE SET instance_id=:X1, status_update_time=(SELECT unixts2date(:X3) FROM DUAL), output=:X4, long_output=:X5, perfdata=:X6, current_state=:X7, has_been_checked=:X8, should_be_scheduled=:X9, current_check_attempt=:X10, max_check_attempts=:X11, last_check=(SELECT unixts2date(:X12) FROM DUAL), next_check=(SELECT unixts2date(:X13) FROM DUAL), check_type=:X14, last_state_change=(SELECT unixts2date(:X15) FROM DUAL), last_hard_state_change=(SELECT unixts2date(:X16) FROM DUAL), last_hard_state=:X17, last_time_up=(SELECT unixts2date(:X18) FROM DUAL), last_time_down=(SELECT unixts2date(:X19) FROM DUAL), last_time_unreachable=(SELECT unixts2date(:X20) FROM DUAL), state_type=:X21, last_notification=(SELECT unixts2date(:X22) FROM DUAL), next_notification=(SELECT unixts2date(:X23) FROM DUAL), no_more_notifications=:X24, notifications_enabled=:X25, problem_has_been_acknowledged=:X26, acknowledgement_type=:X27, current_notification_number=:X28, passive_checks_enabled=:X29, active_checks_enabled=:X30, event_handler_enabled=:X31, flap_detection_enabled=:X32, is_flapping=:X33, percent_state_change=:X34, latency=:X35, execution_time=:X36, scheduled_downtime_depth=:X37, failure_prediction_enabled=:X38, process_performance_data=:X39, obsess_over_host=:X40, modified_host_attributes=:X41, event_handler=:X42, check_command=:X43, normal_check_interval=:X44, retry_check_interval=:X45, check_timeperiod_object_id=:X46 WHEN NOT MATCHED THEN INSERT (id, instance_id, host_object_id, status_update_time, output, long_output, perfdata, current_state, has_been_checked, should_be_scheduled, current_check_attempt, max_check_attempts, last_check, next_check, check_type, last_state_change, last_hard_state_change, last_hard_state, last_time_up, last_time_down, last_time_unreachable, state_type, last_notification, next_notification, no_more_notifications, notifications_enabled, problem_has_been_acknowledged, acknowledgement_type, current_notification_number, passive_checks_enabled, active_checks_enabled, event_handler_enabled, flap_detection_enabled, is_flapping, percent_state_change, latency, execution_time, scheduled_downtime_depth, failure_prediction_enabled, process_performance_data, obsess_over_host, modified_host_attributes, event_handler, check_command, normal_check_interval, retry_check_interval, check_timeperiod_object_id) VALUES (seq_hoststatus.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11, (SELECT unixts2date(:X12) FROM DUAL), (SELECT unixts2date(:X13) FROM DUAL), :X14, (SELECT unixts2date(:X15) FROM DUAL), (SELECT unixts2date(:X16) FROM DUAL), :X17, (SELECT unixts2date(:X18) FROM DUAL), (SELECT unixts2date(:X19) FROM DUAL), (SELECT unixts2date(:X20) FROM DUAL), :X21, (SELECT unixts2date(:X22) FROM DUAL), (SELECT unixts2date(:X23) FROM DUAL), :X24, :X25, :X26, :X27, :X28, :X29, :X30, :X31, :X32, :X33, :X34, :X35, :X36, :X37, :X38, :X39, :X40, :X41, :X42, :X43, :X44, :X45, :X46)", 03973 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTSTATUS]) == -1) { 03974 buf = NULL; 03975 } 03976 03977 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hoststatus() query: %s\n", buf); 03978 03979 if(idi->dbinfo.oci_connection) { 03980 03981 idi->dbinfo.oci_statement_hoststatus = OCI_StatementCreate(idi->dbinfo.oci_connection); 03982 03983 /* allow rebinding values */ 03984 OCI_AllowRebinding(idi->dbinfo.oci_statement_hoststatus, 1); 03985 03986 if(!OCI_Prepare(idi->dbinfo.oci_statement_hoststatus, MT(buf))) { 03987 free(buf); 03988 return IDO_ERROR; 03989 } 03990 } else { 03991 free(buf); 03992 return IDO_ERROR; 03993 } 03994 free(buf); 03995 03996 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hoststatus() end\n"); 03997 03998 return IDO_OK; 03999 } 04000 04001 04002 int ido2db_oci_prepared_statement_hostchecks(ido2db_idi *idi) { 04003 04004 char *buf = NULL; 04005 04006 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostchecks() start\n"); 04007 04008 if(asprintf(&buf, "INSERT INTO %s (id, command_object_id, command_args, command_line, instance_id, host_object_id, check_type, is_raw_check, current_check_attempt, max_check_attempts, state, state_type, start_time, start_time_usec, end_time, end_time_usec, timeout, early_timeout, execution_time, latency, return_code, output, long_output, perfdata) VALUES (seq_hostchecks.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11, (SELECT unixts2date(:X12) FROM DUAL), :X13, (SELECT unixts2date(:X14) FROM DUAL), :X15, :X16, :X17, :X18, :X19, :X20, :X21, :X22, :X23)", 04009 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCHECKS]) == -1) { 04010 buf = NULL; 04011 } 04012 04013 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostchecks() query: %s\n", buf); 04014 04015 if(idi->dbinfo.oci_connection) { 04016 04017 idi->dbinfo.oci_statement_hostchecks = OCI_StatementCreate(idi->dbinfo.oci_connection); 04018 04019 /* allow rebinding values */ 04020 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostchecks, 1); 04021 04022 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostchecks, MT(buf))) { 04023 free(buf); 04024 return IDO_ERROR; 04025 } 04026 } else { 04027 free(buf); 04028 return IDO_ERROR; 04029 } 04030 free(buf); 04031 04032 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_hostchecks() end\n"); 04033 04034 return IDO_OK; 04035 } 04036 04037 /************************************/ 04038 /* SERVICESTATUS/CHECK */ 04039 /************************************/ 04040 04041 int ido2db_oci_prepared_statement_servicestatus(ido2db_idi *idi) { 04042 04043 char *buf = NULL; 04044 04045 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicestatus() start\n"); 04046 04047 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (service_object_id=:X2) WHEN MATCHED THEN UPDATE SET instance_id=:X1, status_update_time=(SELECT unixts2date(:X3) FROM DUAL), output=:X4, long_output=:X5, perfdata=:X6, current_state=:X7, has_been_checked=:X8, should_be_scheduled=:X9, current_check_attempt=:X10, max_check_attempts=:X11, last_check=(SELECT unixts2date(:X12) FROM DUAL), next_check=(SELECT unixts2date(:X13) FROM DUAL), check_type=:X14, last_state_change=(SELECT unixts2date(:X15) FROM DUAL), last_hard_state_change=(SELECT unixts2date(:X16) FROM DUAL), last_hard_state=:X17, last_time_ok=(SELECT unixts2date(:X18) FROM DUAL), last_time_warning=(SELECT unixts2date(:X19) FROM DUAL), last_time_unknown=(SELECT unixts2date(:X20) FROM DUAL), last_time_critical=(SELECT unixts2date(:X21) FROM DUAL), state_type=:X22, last_notification=(SELECT unixts2date(:X23) FROM DUAL), next_notification=(SELECT unixts2date(:X24) FROM DUAL), no_more_notifications=:X25, notifications_enabled=:X26, problem_has_been_acknowledged=:X27, acknowledgement_type=:X28, current_notification_number=:X29, passive_checks_enabled=:X30, active_checks_enabled=:X31, event_handler_enabled=:X32, flap_detection_enabled=:X33, is_flapping=:X34, percent_state_change=:X35, latency=:X36, execution_time=:X37, scheduled_downtime_depth=:X38, failure_prediction_enabled=:X39, process_performance_data=:X40, obsess_over_service=:X41, modified_service_attributes=:X42, event_handler=:X43, check_command=:X44, normal_check_interval=:X45, retry_check_interval=:X46, check_timeperiod_object_id=:X47 WHEN NOT MATCHED THEN INSERT (id, instance_id, service_object_id, status_update_time, output, long_output, perfdata, current_state, has_been_checked, should_be_scheduled, current_check_attempt, max_check_attempts, last_check, next_check, check_type, last_state_change, last_hard_state_change, last_hard_state, last_time_ok, last_time_warning, last_time_unknown, last_time_critical, state_type, last_notification, next_notification, no_more_notifications, notifications_enabled, problem_has_been_acknowledged, acknowledgement_type, current_notification_number, passive_checks_enabled, active_checks_enabled, event_handler_enabled, flap_detection_enabled, is_flapping, percent_state_change, latency, execution_time, scheduled_downtime_depth, failure_prediction_enabled, process_performance_data, obsess_over_service, modified_service_attributes, event_handler, check_command, normal_check_interval, retry_check_interval, check_timeperiod_object_id) VALUES (seq_servicestatus.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11, (SELECT unixts2date(:X12) FROM DUAL), (SELECT unixts2date(:X13) FROM DUAL), :X14, (SELECT unixts2date(:X15) FROM DUAL), (SELECT unixts2date(:X16) FROM DUAL), :X17, (SELECT unixts2date(:X18) FROM DUAL), (SELECT unixts2date(:X19) FROM DUAL), (SELECT unixts2date(:X20) FROM DUAL), (SELECT unixts2date(:X21) FROM DUAL), :X22, (SELECT unixts2date(:X23) FROM DUAL), (SELECT unixts2date(:X24) FROM DUAL), :X25, :X26, :X27, :X28, :X29, :X30, :X31, :X32, :X33, :X34, :X35, :X36, :X37, :X38, :X39, :X40, :X41, :X42, :X43, :X44, :X45, :X46, :X47)", 04048 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICESTATUS]) == -1) { 04049 buf = NULL; 04050 } 04051 04052 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicestatus() query: %s\n", buf); 04053 04054 if(idi->dbinfo.oci_connection) { 04055 04056 idi->dbinfo.oci_statement_servicestatus = OCI_StatementCreate(idi->dbinfo.oci_connection); 04057 04058 /* allow rebinding values */ 04059 OCI_AllowRebinding(idi->dbinfo.oci_statement_servicestatus, 1); 04060 04061 if(!OCI_Prepare(idi->dbinfo.oci_statement_servicestatus, MT(buf))) { 04062 free(buf); 04063 return IDO_ERROR; 04064 } 04065 } else { 04066 free(buf); 04067 return IDO_ERROR; 04068 } 04069 free(buf); 04070 04071 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicestatus() end\n"); 04072 04073 return IDO_OK; 04074 } 04075 04076 04077 int ido2db_oci_prepared_statement_servicechecks(ido2db_idi *idi) { 04078 04079 char *buf = NULL; 04080 04081 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicechecks() start\n"); 04082 04083 if(asprintf(&buf, "INSERT INTO %s (id, instance_id, service_object_id, check_type, current_check_attempt, max_check_attempts, state, state_type, start_time, start_time_usec, end_time, end_time_usec, timeout, early_timeout, execution_time, latency, return_code, output, long_output, perfdata, command_object_id, command_args, command_line) VALUES (seq_servicechecks.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, (SELECT unixts2date(:X8) FROM DUAL), :X9, (SELECT unixts2date(:X10) FROM DUAL), :X11, :X12, :X13, :X14, :X15, :X16, :X17, :X18, :X19, :X20, :X21, :X22)", 04084 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECHECKS]) == -1) { 04085 buf = NULL; 04086 } 04087 04088 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicechecks() query: %s\n", buf); 04089 04090 if(idi->dbinfo.oci_connection) { 04091 04092 idi->dbinfo.oci_statement_servicechecks = OCI_StatementCreate(idi->dbinfo.oci_connection); 04093 04094 /* allow rebinding values */ 04095 OCI_AllowRebinding(idi->dbinfo.oci_statement_servicechecks, 1); 04096 04097 if(!OCI_Prepare(idi->dbinfo.oci_statement_servicechecks, MT(buf))) { 04098 free(buf); 04099 return IDO_ERROR; 04100 } 04101 } else { 04102 free(buf); 04103 return IDO_ERROR; 04104 } 04105 free(buf); 04106 04107 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_servicechecks() end\n"); 04108 04109 return IDO_OK; 04110 } 04111 04112 /************************************/ 04113 /* CONTACTNOTIFICATION */ 04114 /************************************/ 04115 04116 int ido2db_oci_prepared_statement_contact_notificationcommands(ido2db_idi *idi) { 04117 04118 char *buf = NULL; 04119 04120 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contact_notificationcommands() start\n"); 04121 04122 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND contact_id=:X2 AND notification_type=:X3 AND command_object_id=:X4) WHEN MATCHED THEN UPDATE SET command_args=:X5 WHEN NOT MATCHED THEN INSERT (id, instance_id, contact_id, notification_type, command_object_id, command_args) VALUES (seq_contact_notifcommands.nextval, :X1, :X2, :X3, :X4, :X5)", 04123 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS]) == -1) { 04124 buf = NULL; 04125 } 04126 04127 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contact_notificationcommands() query: %s\n", buf); 04128 04129 if(idi->dbinfo.oci_connection) { 04130 04131 idi->dbinfo.oci_statement_contact_notificationcommands = OCI_StatementCreate(idi->dbinfo.oci_connection); 04132 04133 /* allow rebinding values */ 04134 OCI_AllowRebinding(idi->dbinfo.oci_statement_contact_notificationcommands, 1); 04135 04136 if(!OCI_Prepare(idi->dbinfo.oci_statement_contact_notificationcommands, MT(buf))) { 04137 free(buf); 04138 return IDO_ERROR; 04139 } 04140 } else { 04141 free(buf); 04142 return IDO_ERROR; 04143 } 04144 free(buf); 04145 04146 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contact_notificationcommands() end\n"); 04147 04148 return IDO_OK; 04149 } 04150 04151 /************************************/ 04152 /* PROGRAMSTATUS */ 04153 /************************************/ 04154 04155 int ido2db_oci_prepared_statement_programstatus(ido2db_idi *idi) { 04156 04157 char *buf = NULL; 04158 04159 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_programstatus() start\n"); 04160 04161 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1) WHEN MATCHED THEN UPDATE SET status_update_time=(SELECT unixts2date(:X2) FROM DUAL), program_start_time=(SELECT unixts2date(:X3) FROM DUAL), is_currently_running=1, process_id=:X4, daemon_mode=:X5, last_command_check=(SELECT unixts2date(:X6) FROM DUAL), last_log_rotation=(SELECT unixts2date(:X7) FROM DUAL), notifications_enabled=:X8, active_service_checks_enabled=:X9, passive_service_checks_enabled=:X10, active_host_checks_enabled=:X11, passive_host_checks_enabled=:X12, event_handlers_enabled=:X13, flap_detection_enabled=:X14, failure_prediction_enabled=:X15, process_performance_data=:X16, obsess_over_hosts=:X17, obsess_over_services=:X18, modified_host_attributes=:X19, modified_service_attributes=:X20, global_host_event_handler=:X21, global_service_event_handler=:X22 WHEN NOT MATCHED THEN INSERT (id, instance_id, status_update_time, program_start_time, is_currently_running, process_id, daemon_mode, last_command_check, last_log_rotation, notifications_enabled, active_service_checks_enabled, passive_service_checks_enabled, active_host_checks_enabled, passive_host_checks_enabled, event_handlers_enabled, flap_detection_enabled, failure_prediction_enabled, process_performance_data, obsess_over_hosts, obsess_over_services, modified_host_attributes, modified_service_attributes, global_host_event_handler, global_service_event_handler) VALUES (seq_programstatus.nextval, :X1, (SELECT unixts2date(:X2) FROM DUAL), (SELECT unixts2date(:X3) FROM DUAL), '1', :X4, :X5, (SELECT unixts2date(:X6) FROM DUAL), (SELECT unixts2date(:X7) FROM DUAL), :X8, :X9, :X10, :X11, :X12, :X13, :X14, :X15, :X16, :X17, :X18, :X19, :X20, :X21, :X22)", 04162 ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS]) == -1) { 04163 buf = NULL; 04164 } 04165 04166 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_programstatus() query: %s\n", buf); 04167 04168 if(idi->dbinfo.oci_connection) { 04169 04170 idi->dbinfo.oci_statement_programstatus = OCI_StatementCreate(idi->dbinfo.oci_connection); 04171 04172 /* allow rebinding values */ 04173 OCI_AllowRebinding(idi->dbinfo.oci_statement_programstatus, 1); 04174 04175 if(!OCI_Prepare(idi->dbinfo.oci_statement_programstatus, MT(buf))) { 04176 free(buf); 04177 return IDO_ERROR; 04178 } 04179 } else { 04180 free(buf); 04181 return IDO_ERROR; 04182 } 04183 free(buf); 04184 04185 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_programstatus() end\n"); 04186 04187 return IDO_OK; 04188 } 04189 04190 int ido2db_oci_prepared_statement_programstatus_update(ido2db_idi *idi) { 04191 04192 char *buf = NULL; 04193 04194 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04195 04196 if(asprintf(&buf, "UPDATE %s SET program_end_time=(SELECT unixts2date(:X1) FROM DUAL), is_currently_running=:X2 WHERE instance_id=:X3", 04197 ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS]) == -1) { 04198 buf = NULL; 04199 } 04200 04201 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04202 04203 if(idi->dbinfo.oci_connection) { 04204 04205 idi->dbinfo.oci_statement_programstatus_update = OCI_StatementCreate(idi->dbinfo.oci_connection); 04206 04207 /* allow rebinding values */ 04208 OCI_AllowRebinding(idi->dbinfo.oci_statement_programstatus_update, 1); 04209 04210 if(!OCI_Prepare(idi->dbinfo.oci_statement_programstatus_update, MT(buf))) { 04211 free(buf); 04212 return IDO_ERROR; 04213 } 04214 } else { 04215 free(buf); 04216 return IDO_ERROR; 04217 } 04218 free(buf); 04219 04220 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04221 04222 return IDO_OK; 04223 } 04224 04225 04226 /************************************/ 04227 /* SYSTEMCOMMANDS */ 04228 /************************************/ 04229 04230 04231 int ido2db_oci_prepared_statement_systemcommanddata(ido2db_idi *idi) { 04232 04233 char *buf = NULL; 04234 04235 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_systemcommanddata() start\n"); 04236 04237 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND start_time=(SELECT unixts2date(:X2) FROM DUAL) AND start_time_usec=:X3) WHEN MATCHED THEN UPDATE SET end_time=(SELECT unixts2date(:X4) FROM DUAL), end_time_usec=:X5, command_line=:X6, timeout=:X7, early_timeout=:X8, execution_time=:X9, return_code=:X10, output=:X11, long_output=:X12 WHEN NOT MATCHED THEN INSERT (id, instance_id, start_time, start_time_usec, end_time, end_time_usec, command_line, timeout, early_timeout, execution_time, return_code, output, long_output) VALUES (seq_systemcommands.nextval, :X1, (SELECT unixts2date(:X2) FROM DUAL), :X3, (SELECT unixts2date(:X4) FROM DUAL), :X5, :X6, :X7, :X8, :X9, :X10, :X11, :X12)", 04238 ido2db_db_tablenames[IDO2DB_DBTABLE_SYSTEMCOMMANDS]) == -1) { 04239 buf = NULL; 04240 } 04241 04242 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_systemcommanddata() query: %s\n", buf); 04243 04244 if(idi->dbinfo.oci_connection) { 04245 04246 idi->dbinfo.oci_statement_systemcommanddata = OCI_StatementCreate(idi->dbinfo.oci_connection); 04247 04248 /* allow rebinding values */ 04249 OCI_AllowRebinding(idi->dbinfo.oci_statement_systemcommanddata, 1); 04250 04251 if(!OCI_Prepare(idi->dbinfo.oci_statement_systemcommanddata, MT(buf))) { 04252 free(buf); 04253 return IDO_ERROR; 04254 } 04255 } else { 04256 free(buf); 04257 return IDO_ERROR; 04258 } 04259 free(buf); 04260 04261 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_systemcommanddata() end\n"); 04262 04263 return IDO_OK; 04264 } 04265 04266 /************************************/ 04267 /* EVENTHANLDERS */ 04268 /************************************/ 04269 04270 04271 int ido2db_oci_prepared_statement_eventhandlerdata(ido2db_idi *idi) { 04272 04273 char *buf = NULL; 04274 04275 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_eventhandlerdata() start\n"); 04276 04277 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND start_time=(SELECT unixts2date(:X6) FROM DUAL) AND start_time_usec=:X7) WHEN MATCHED THEN UPDATE SET eventhandler_type=:X2, object_id=:X3, state=:X4, state_type=:X5, end_time=:X8, end_time_usec=:X9, command_object_id=:X10, command_args=:X11, command_line=:X12, timeout=:X13, early_timeout=:X14, execution_time=:X15, return_code=:X16, output=:X17, long_output=:X18 WHEN NOT MATCHED THEN INSERT (instance_id, eventhandler_type, object_id, state, state_type, start_time, start_time_usec, end_time, end_time_usec, command_object_id, command_args, command_line, timeout, early_timeout, execution_time, return_code, output, long_output) VALUES (seq_eventhandlers.nextval, :X1, :X2, :X3, :X4, :X5, (SELECT unixts2date(:X6) FROM DUAL), :X7, (SELECT unixts2date(:X8) FROM DUAL), :X9, :X10, :X11, :X12, :X13, :X14, :X15, :X16, :X17, :X18)", 04278 ido2db_db_tablenames[IDO2DB_DBTABLE_EVENTHANDLERS]) == -1) { 04279 buf = NULL; 04280 } 04281 04282 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_eventhandlerdata() query: %s\n", buf); 04283 04284 if(idi->dbinfo.oci_connection) { 04285 04286 idi->dbinfo.oci_statement_eventhandlerdata = OCI_StatementCreate(idi->dbinfo.oci_connection); 04287 04288 OCI_AllowRebinding(idi->dbinfo.oci_statement_eventhandlerdata, 1); 04289 04290 if(!OCI_Prepare(idi->dbinfo.oci_statement_eventhandlerdata, MT(buf))) { 04291 free(buf); 04292 return IDO_ERROR; 04293 } 04294 } else { 04295 free(buf); 04296 return IDO_ERROR; 04297 } 04298 free(buf); 04299 04300 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_eventhandlerdata() end\n"); 04301 04302 return IDO_OK; 04303 } 04304 04305 04306 04307 /************************************/ 04308 /* NOTIFICATIONS */ 04309 /************************************/ 04310 04311 04312 int ido2db_oci_prepared_statement_notificationdata(ido2db_idi *idi) { 04313 04314 char *buf = NULL; 04315 04316 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_notificationdata() start\n"); 04317 04318 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND start_time=(SELECT unixts2date(:X4) FROM DUAL) AND start_time_usec=:X5 AND object_id=:X8) WHEN MATCHED THEN UPDATE SET notification_type=:X2, notification_reason=:X3, end_time=(SELECT unixts2date(:X6) FROM DUAL), end_time_usec=:X7, state=:X9, output=:X10, long_output=:X11, escalated=:X12, contacts_notified=:X13 WHEN NOT MATCHED THEN INSERT (id, instance_id, notification_type, notification_reason, start_time, start_time_usec, end_time, end_time_usec, object_id, state, output, long_output, escalated, contacts_notified) VALUES (seq_notifications.nextval, :X1, :X2, :X3, (SELECT unixts2date(:X4) FROM DUAL), :X5, (SELECT unixts2date(:X6) FROM DUAL), :X7, :X8, :X9, :X10, :X11, :X12, :X13)", 04319 ido2db_db_tablenames[IDO2DB_DBTABLE_NOTIFICATIONS]) == -1) { 04320 buf = NULL; 04321 } 04322 04323 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_notificationdata() query: %s\n", buf); 04324 04325 if(idi->dbinfo.oci_connection) { 04326 04327 idi->dbinfo.oci_statement_notificationdata = OCI_StatementCreate(idi->dbinfo.oci_connection); 04328 04329 OCI_AllowRebinding(idi->dbinfo.oci_statement_notificationdata, 1); 04330 04331 if(!OCI_Prepare(idi->dbinfo.oci_statement_notificationdata, MT(buf))) { 04332 free(buf); 04333 return IDO_ERROR; 04334 } 04335 } else { 04336 free(buf); 04337 return IDO_ERROR; 04338 } 04339 free(buf); 04340 04341 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_notificationdata() end\n"); 04342 04343 return IDO_OK; 04344 } 04345 04346 04347 int ido2db_oci_prepared_statement_contactnotificationdata(ido2db_idi *idi) { 04348 04349 char *buf = NULL; 04350 04351 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactnotificationdata() start\n"); 04352 04353 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND contact_object_id=:X7 AND start_time=(SELECT unixts2date(:X3) FROM DUAL) AND start_time_usec=:X4) WHEN MATCHED THEN UPDATE SET notification_id=:X2, end_time=(SELECT unixts2date(:X5) FROM DUAL), end_time_usec=:X6 WHEN NOT MATCHED THEN INSERT (id, instance_id, notification_id, start_time, start_time_usec, end_time, end_time_usec, contact_object_id) VALUES (seq_contactnotifications.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, (SELECT unixts2date(:X5) FROM DUAL), :X6, :X7)", 04354 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONS]) == -1) { 04355 buf = NULL; 04356 } 04357 04358 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactnotificationdata() query: %s\n", buf); 04359 04360 if(idi->dbinfo.oci_connection) { 04361 04362 idi->dbinfo.oci_statement_contactnotificationdata = OCI_StatementCreate(idi->dbinfo.oci_connection); 04363 04364 OCI_AllowRebinding(idi->dbinfo.oci_statement_contactnotificationdata, 1); 04365 04366 if(!OCI_Prepare(idi->dbinfo.oci_statement_contactnotificationdata, MT(buf))) { 04367 free(buf); 04368 return IDO_ERROR; 04369 } 04370 } else { 04371 free(buf); 04372 return IDO_ERROR; 04373 } 04374 free(buf); 04375 04376 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactnotificationdata() end\n"); 04377 04378 return IDO_OK; 04379 } 04380 04381 int ido2db_oci_prepared_statement_contactnotificationmethoddata(ido2db_idi *idi) { 04382 04383 char *buf = NULL; 04384 04385 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactnotificationmethoddata() start\n"); 04386 04387 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND contactnotification_id=:X2 AND start_time=(SELECT unixts2date(:X3) FROM DUAL) AND start_time_usec=:X4) WHEN MATCHED THEN UPDATE SET end_time=(SELECT unixts2date(:X5) FROM DUAL), end_time_usec=:X6, command_object_id=:X7, command_args=:X8 WHEN NOT MATCHED THEN INSERT (id, instance_id, contactnotification_id, start_time, start_time_usec, end_time, end_time_usec, command_object_id, command_args) VALUES (seq_contactnotifmethods.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, (SELECT unixts2date(:X5) FROM DUAL), :X6, :X7, :X8)", 04388 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONMETHODS]) == -1) { 04389 buf = NULL; 04390 } 04391 04392 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactnotificationmethoddata() query: %s\n", buf); 04393 04394 if(idi->dbinfo.oci_connection) { 04395 04396 idi->dbinfo.oci_statement_contactnotificationmethoddata = OCI_StatementCreate(idi->dbinfo.oci_connection); 04397 04398 OCI_AllowRebinding(idi->dbinfo.oci_statement_contactnotificationmethoddata, 1); 04399 04400 if(!OCI_Prepare(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(buf))) { 04401 free(buf); 04402 return IDO_ERROR; 04403 } 04404 } else { 04405 free(buf); 04406 return IDO_ERROR; 04407 } 04408 free(buf); 04409 04410 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactnotificationmethoddata() end\n"); 04411 04412 return IDO_OK; 04413 } 04414 04415 04416 04417 04418 /************************************/ 04419 /* COMMENTS */ 04420 /************************************/ 04421 04422 04423 int ido2db_oci_prepared_statement_commentdata(ido2db_idi *idi) { 04424 04425 char *buf = NULL; 04426 04427 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commentdata() start\n"); 04428 04429 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X3 AND comment_time=(SELECT unixts2date(:X7) FROM DUAL) AND internal_comment_id=:X8) WHEN MATCHED THEN UPDATE SET comment_type=:X4, entry_type=:X5, object_id=:X6, author_name=:X9, comment_data=:X10, is_persistent=:X11, comment_source=:X12, expires=:X13, expiration_time=(SELECT unixts2date(:X14) FROM DUAL) WHEN NOT MATCHED THEN INSERT (id, entry_time, entry_time_usec, instance_id, comment_type, entry_type, object_id, comment_time, internal_comment_id, author_name, comment_data, is_persistent, comment_source, expires, expiration_time) VALUES (seq_comments.nextval, (SELECT unixts2date(:X1) FROM DUAL), :X2, :X3, :X4, :X5, :X6, (SELECT unixts2date(:X7) FROM DUAL), :X8, :X9, :X10, :X11, :X12, :X13, (SELECT unixts2date(:X14) FROM DUAL))", 04430 ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS]) == -1) { 04431 buf = NULL; 04432 } 04433 04434 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commentdata() query: %s\n", buf); 04435 04436 if(idi->dbinfo.oci_connection) { 04437 04438 idi->dbinfo.oci_statement_commentdata = OCI_StatementCreate(idi->dbinfo.oci_connection); 04439 04440 OCI_AllowRebinding(idi->dbinfo.oci_statement_commentdata, 1); 04441 04442 if(!OCI_Prepare(idi->dbinfo.oci_statement_commentdata, MT(buf))) { 04443 free(buf); 04444 return IDO_ERROR; 04445 } 04446 } else { 04447 free(buf); 04448 return IDO_ERROR; 04449 } 04450 free(buf); 04451 04452 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commentdata() end\n"); 04453 04454 return IDO_OK; 04455 } 04456 04457 int ido2db_oci_prepared_statement_commentdata_history(ido2db_idi *idi) { 04458 04459 char *buf = NULL; 04460 04461 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commentdata_history() start\n"); 04462 04463 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X3 AND comment_time=(SELECT unixts2date(:X7) FROM DUAL) AND internal_comment_id=:X8) WHEN MATCHED THEN UPDATE SET comment_type=:X4, entry_type=:X5, object_id=:X6, author_name=:X9, comment_data=:X10, is_persistent=:X11, comment_source=:X12, expires=:X13, expiration_time=(SELECT unixts2date(:X14) FROM DUAL) WHEN NOT MATCHED THEN INSERT (id, entry_time, entry_time_usec, instance_id, comment_type, entry_type, object_id, comment_time, internal_comment_id, author_name, comment_data, is_persistent, comment_source, expires, expiration_time) VALUES (seq_commenthistory.nextval, (SELECT unixts2date(:X1) FROM DUAL), :X2, :X3, :X4, :X5, :X6, (SELECT unixts2date(:X7) FROM DUAL), :X8, :X9, :X10, :X11, :X12, :X13, (SELECT unixts2date(:X14) FROM DUAL))", 04464 ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTHISTORY]) == -1) { 04465 buf = NULL; 04466 } 04467 04468 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commentdata_history() query: %s\n", buf); 04469 04470 if(idi->dbinfo.oci_connection) { 04471 04472 idi->dbinfo.oci_statement_commentdata_history = OCI_StatementCreate(idi->dbinfo.oci_connection); 04473 04474 OCI_AllowRebinding(idi->dbinfo.oci_statement_commentdata_history, 1); 04475 04476 if(!OCI_Prepare(idi->dbinfo.oci_statement_commentdata_history, MT(buf))) { 04477 free(buf); 04478 return IDO_ERROR; 04479 } 04480 } else { 04481 free(buf); 04482 return IDO_ERROR; 04483 } 04484 free(buf); 04485 04486 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commentdata_history() end\n"); 04487 04488 return IDO_OK; 04489 } 04490 04491 04492 int ido2db_oci_prepared_statement_comment_history_update(ido2db_idi *idi) { 04493 04494 char *buf = NULL; 04495 04496 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04497 04498 if(asprintf(&buf, "UPDATE %s SET deletion_time=(SELECT unixts2date(:X1) FROM DUAL), deletion_time_usec=:X2 WHERE instance_id=:X3 AND comment_time=(SELECT unixts2date(:X4) FROM DUAL) AND internal_comment_id=:X5", 04499 ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTHISTORY]) == -1) { 04500 buf = NULL; 04501 } 04502 04503 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04504 04505 if(idi->dbinfo.oci_connection) { 04506 04507 idi->dbinfo.oci_statement_comment_history_update = OCI_StatementCreate(idi->dbinfo.oci_connection); 04508 04509 /* allow rebinding values */ 04510 OCI_AllowRebinding(idi->dbinfo.oci_statement_comment_history_update, 1); 04511 04512 if(!OCI_Prepare(idi->dbinfo.oci_statement_comment_history_update, MT(buf))) { 04513 free(buf); 04514 return IDO_ERROR; 04515 } 04516 } else { 04517 free(buf); 04518 return IDO_ERROR; 04519 } 04520 free(buf); 04521 04522 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04523 04524 return IDO_OK; 04525 } 04526 04527 /************************************/ 04528 /* DOWNTIME */ 04529 /************************************/ 04530 04531 04532 int ido2db_oci_prepared_statement_downtimedata_scheduled_downtime(ido2db_idi *idi) { 04533 04534 char *buf = NULL; 04535 04536 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_downtimedata_scheduled_downtime() start\n"); 04537 04538 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND object_id=:X3 AND entry_time=(SELECT unixts2date(:X4) FROM DUAL) AND internal_downtime_id=:X7) WHEN MATCHED THEN UPDATE SET downtime_type=:X2, author_name=:X5, comment_data=:X6, triggered_by_id=:X8, is_fixed=:X9, duration=:X10, scheduled_start_time=(SELECT unixts2date(:X11) FROM DUAL), scheduled_end_time=(SELECT unixts2date(:X12) FROM DUAL) WHEN NOT MATCHED THEN INSERT (id, instance_id, downtime_type, object_id, entry_time, author_name, comment_data, internal_downtime_id, triggered_by_id, is_fixed, duration, scheduled_start_time, scheduled_end_time) VALUES (seq_scheduleddowntime.nextval, :X1, :X2, :X3, (SELECT unixts2date(:X4) FROM DUAL), :X5, :X6, :X7, :X8, :X9, :X10, (SELECT unixts2date(:X11) FROM DUAL), (SELECT unixts2date(:X12) FROM DUAL))", 04539 ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME]) == -1) { 04540 buf = NULL; 04541 } 04542 04543 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_scheduled_downtime() query: %s\n", buf); 04544 04545 if(idi->dbinfo.oci_connection) { 04546 04547 idi->dbinfo.oci_statement_downtimedata_scheduled_downtime = OCI_StatementCreate(idi->dbinfo.oci_connection); 04548 04549 OCI_AllowRebinding(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, 1); 04550 04551 if(!OCI_Prepare(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(buf))) { 04552 free(buf); 04553 return IDO_ERROR; 04554 } 04555 } else { 04556 free(buf); 04557 return IDO_ERROR; 04558 } 04559 free(buf); 04560 04561 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_downtimedata_scheduled_downtime() end\n"); 04562 04563 return IDO_OK; 04564 } 04565 04566 int ido2db_oci_prepared_statement_downtimedata_downtime_history(ido2db_idi *idi) { 04567 04568 char *buf = NULL; 04569 04570 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_downtimedata_downtime_history() start\n"); 04571 04572 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND object_id=:X3 AND entry_time=(SELECT unixts2date(:X4) FROM DUAL) AND internal_downtime_id=:X7) WHEN MATCHED THEN UPDATE SET downtime_type=:X2, author_name=:X5, comment_data=:X6, triggered_by_id=:X8, is_fixed=:X9, duration=:X10, scheduled_start_time=(SELECT unixts2date(:X11) FROM DUAL), scheduled_end_time=(SELECT unixts2date(:X12) FROM DUAL) WHEN NOT MATCHED THEN INSERT (id, instance_id, downtime_type, object_id, entry_time, author_name, comment_data, internal_downtime_id, triggered_by_id, is_fixed, duration, scheduled_start_time, scheduled_end_time) VALUES (seq_downtimehistory.nextval, :X1, :X2, :X3, (SELECT unixts2date(:X4) FROM DUAL), :X5, :X6, :X7, :X8, :X9, :X10, (SELECT unixts2date(:X11) FROM DUAL), (SELECT unixts2date(:X12) FROM DUAL))", 04573 ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY]) == -1) { 04574 buf = NULL; 04575 } 04576 04577 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_downtime_history() query: %s\n", buf); 04578 04579 if(idi->dbinfo.oci_connection) { 04580 04581 idi->dbinfo.oci_statement_downtimedata_downtime_history = OCI_StatementCreate(idi->dbinfo.oci_connection); 04582 04583 OCI_AllowRebinding(idi->dbinfo.oci_statement_downtimedata_downtime_history, 1); 04584 04585 if(!OCI_Prepare(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(buf))) { 04586 free(buf); 04587 return IDO_ERROR; 04588 } 04589 } else { 04590 free(buf); 04591 return IDO_ERROR; 04592 } 04593 free(buf); 04594 04595 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_downtimedata_downtime_history() end\n"); 04596 04597 return IDO_OK; 04598 } 04599 04600 int ido2db_oci_prepared_statement_downtimehistory_update_start(ido2db_idi *idi) { 04601 04602 char *buf = NULL; 04603 04604 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04605 04606 if(asprintf(&buf, "UPDATE %s SET actual_start_time=(SELECT unixts2date(:X1) FROM DUAL), actual_start_time_usec=:X2, was_started=:X3 WHERE instance_id=:X4 AND downtime_type=:X5 AND object_id=:X6 AND entry_time=(SELECT unixts2date(:X7) FROM DUAL) AND scheduled_start_time=(SELECT unixts2date(:X8) FROM DUAL) AND scheduled_end_time=(SELECT unixts2date(:X9) FROM DUAL)", 04607 ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY]) == -1) { 04608 buf = NULL; 04609 } 04610 04611 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04612 04613 if(idi->dbinfo.oci_connection) { 04614 04615 idi->dbinfo.oci_statement_downtimehistory_update_start = OCI_StatementCreate(idi->dbinfo.oci_connection); 04616 04617 /* allow rebinding values */ 04618 OCI_AllowRebinding(idi->dbinfo.oci_statement_downtimehistory_update_start, 1); 04619 04620 if(!OCI_Prepare(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(buf))) { 04621 free(buf); 04622 return IDO_ERROR; 04623 } 04624 } else { 04625 free(buf); 04626 return IDO_ERROR; 04627 } 04628 free(buf); 04629 04630 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04631 04632 return IDO_OK; 04633 } 04634 04635 04636 int ido2db_oci_prepared_statement_downtimehistory_update_stop(ido2db_idi *idi) { 04637 04638 char *buf = NULL; 04639 04640 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04641 04642 if(asprintf(&buf, "UPDATE %s SET actual_end_time=(SELECT unixts2date(:X1) FROM DUAL), actual_end_time_usec=:X2, was_cancelled=:X3 WHERE instance_id=:X4 AND downtime_type=:X5 AND object_id=:X6 AND entry_time=(SELECT unixts2date(:X7) FROM DUAL) AND scheduled_start_time=(SELECT unixts2date(:X8) FROM DUAL) AND scheduled_end_time=(SELECT unixts2date(:X9) FROM DUAL)", 04643 ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY]) == -1) { 04644 buf = NULL; 04645 } 04646 04647 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04648 04649 if(idi->dbinfo.oci_connection) { 04650 04651 idi->dbinfo.oci_statement_downtimehistory_update_stop = OCI_StatementCreate(idi->dbinfo.oci_connection); 04652 04653 /* allow rebinding values */ 04654 OCI_AllowRebinding(idi->dbinfo.oci_statement_downtimehistory_update_stop, 1); 04655 04656 if(!OCI_Prepare(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(buf))) { 04657 free(buf); 04658 return IDO_ERROR; 04659 } 04660 } else { 04661 free(buf); 04662 return IDO_ERROR; 04663 } 04664 free(buf); 04665 04666 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04667 04668 return IDO_OK; 04669 } 04670 04671 /************************************/ 04672 /* CONTACTSTATUS */ 04673 /************************************/ 04674 04675 04676 int ido2db_oci_prepared_statement_contactstatusdata(ido2db_idi *idi) { 04677 04678 char *buf = NULL; 04679 04680 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04681 04682 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (contact_object_id=:X2) WHEN MATCHED THEN UPDATE SET instance_id=:X1, status_update_time=(SELECT unixts2date(:X3) FROM DUAL), host_notifications_enabled=:X4, service_notifications_enabled=:X5, last_host_notification=(SELECT unixts2date(:X6) FROM DUAL), last_service_notification=(SELECT unixts2date(:X7) FROM DUAL), modified_attributes=:X8, modified_host_attributes=:X9, modified_service_attributes=:X10 WHEN NOT MATCHED THEN INSERT (id, instance_id, contact_object_id, status_update_time, host_notifications_enabled, service_notifications_enabled, last_host_notification, last_service_notification, modified_attributes, modified_host_attributes, modified_service_attributes) VALUES (seq_contactstatus.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, :X5, (SELECT unixts2date(:X6) FROM DUAL), (SELECT unixts2date(:X7) FROM DUAL), :X8, :X9, :X10)", 04683 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTSTATUS]) == -1) { 04684 buf = NULL; 04685 } 04686 04687 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_contactstatusdata() query: %s\n", buf); 04688 04689 if(idi->dbinfo.oci_connection) { 04690 04691 idi->dbinfo.oci_statement_contactstatusdata = OCI_StatementCreate(idi->dbinfo.oci_connection); 04692 04693 OCI_AllowRebinding(idi->dbinfo.oci_statement_contactstatusdata, 1); 04694 04695 if(!OCI_Prepare(idi->dbinfo.oci_statement_contactstatusdata, MT(buf))) { 04696 free(buf); 04697 return IDO_ERROR; 04698 } 04699 } else { 04700 free(buf); 04701 return IDO_ERROR; 04702 } 04703 free(buf); 04704 04705 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04706 04707 return IDO_OK; 04708 } 04709 04710 04711 04712 /************************************/ 04713 /* VARIABLES */ 04714 /************************************/ 04715 04716 04717 int ido2db_oci_prepared_statement_configfilevariables(ido2db_idi *idi) { 04718 04719 char *buf = NULL; 04720 04721 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04722 04723 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1) WHEN MATCHED THEN UPDATE SET configfile_type=:X2, configfile_path=:X3 WHEN NOT MATCHED THEN INSERT (id, instance_id, configfile_type, configfile_path) VALUES (seq_configfiles.nextval, :X1, :X2, :X3)", 04724 ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILES]) == -1) { 04725 buf = NULL; 04726 } 04727 04728 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04729 04730 if(idi->dbinfo.oci_connection) { 04731 04732 idi->dbinfo.oci_statement_configfilevariables = OCI_StatementCreate(idi->dbinfo.oci_connection); 04733 04734 OCI_AllowRebinding(idi->dbinfo.oci_statement_configfilevariables, 1); 04735 04736 if(!OCI_Prepare(idi->dbinfo.oci_statement_configfilevariables, MT(buf))) { 04737 free(buf); 04738 return IDO_ERROR; 04739 } 04740 } else { 04741 free(buf); 04742 return IDO_ERROR; 04743 } 04744 free(buf); 04745 04746 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04747 04748 return IDO_OK; 04749 } 04750 04751 int ido2db_oci_prepared_statement_configfilevariables_insert(ido2db_idi *idi) { 04752 04753 char *buf = NULL; 04754 04755 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04756 04757 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND configfile_id=:X2 AND varname=:X3) WHEN MATCHED THEN UPDATE SET varvalue=:X4 WHEN NOT MATCHED THEN INSERT (id, instance_id, configfile_id, varname, varvalue) VALUES (seq_configfilevariables.nextval, :X1, :X2, :X3, :X4)", 04758 ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILEVARIABLES]) == -1) { 04759 buf = NULL; 04760 } 04761 04762 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04763 04764 if(idi->dbinfo.oci_connection) { 04765 04766 idi->dbinfo.oci_statement_configfilevariables_insert = OCI_StatementCreate(idi->dbinfo.oci_connection); 04767 04768 OCI_AllowRebinding(idi->dbinfo.oci_statement_configfilevariables_insert, 1); 04769 04770 if(!OCI_Prepare(idi->dbinfo.oci_statement_configfilevariables_insert, MT(buf))) { 04771 free(buf); 04772 return IDO_ERROR; 04773 } 04774 } else { 04775 free(buf); 04776 return IDO_ERROR; 04777 } 04778 free(buf); 04779 04780 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04781 04782 return IDO_OK; 04783 } 04784 04785 04786 04787 int ido2db_oci_prepared_statement_runtimevariables(ido2db_idi *idi) { 04788 04789 char *buf = NULL; 04790 04791 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04792 04793 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND varname=:X2) WHEN MATCHED THEN UPDATE SET varvalue=:X3 WHEN NOT MATCHED THEN INSERT (id, instance_id, varname, varvalue) VALUES (seq_runtimevariables.nextval, :X1, :X2, :X3)", 04794 ido2db_db_tablenames[IDO2DB_DBTABLE_RUNTIMEVARIABLES]) == -1) { 04795 buf = NULL; 04796 } 04797 04798 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04799 04800 if(idi->dbinfo.oci_connection) { 04801 04802 idi->dbinfo.oci_statement_runtimevariables = OCI_StatementCreate(idi->dbinfo.oci_connection); 04803 04804 OCI_AllowRebinding(idi->dbinfo.oci_statement_runtimevariables, 1); 04805 04806 if(!OCI_Prepare(idi->dbinfo.oci_statement_runtimevariables, MT(buf))) { 04807 free(buf); 04808 return IDO_ERROR; 04809 } 04810 } else { 04811 free(buf); 04812 return IDO_ERROR; 04813 } 04814 free(buf); 04815 04816 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04817 04818 return IDO_OK; 04819 } 04820 04821 04822 /************************************/ 04823 /* HOSTDEFINITION */ 04824 /************************************/ 04825 04826 04827 int ido2db_oci_prepared_statement_hostdefinition_definition(ido2db_idi *idi) { 04828 04829 char *buf = NULL; 04830 04831 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04832 04833 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND host_object_id=:X3) WHEN MATCHED THEN UPDATE SET alias=:X4, display_name=:X5, address=:X6, check_command_object_id=:X7, check_command_args=:X8, eventhandler_command_object_id=:X9, eventhandler_command_args=:X10, check_timeperiod_object_id=:X11, notif_timeperiod_object_id=:X12, failure_prediction_options=:X13, check_interval=:X14, retry_interval=:X15, max_check_attempts=:X16, first_notification_delay=:X17, notification_interval=:X18, notify_on_down=:X19, notify_on_unreachable=:X20, notify_on_recovery=:X21, notify_on_flapping=:X22, notify_on_downtime=:X23, stalk_on_up=:X24, stalk_on_down=:X25, stalk_on_unreachable=:X26, flap_detection_enabled=:X27, flap_detection_on_up=:X28, flap_detection_on_down=:X29, flap_detection_on_unreachable=:X30, low_flap_threshold=:X31, high_flap_threshold=:X32, process_performance_data=:X33, freshness_checks_enabled=:X34, freshness_threshold=:X35, passive_checks_enabled=:X36, event_handler_enabled=:X37, active_checks_enabled=:X38, retain_status_information=:X39, retain_nonstatus_information=:X40, notifications_enabled=:X41, obsess_over_host=:X42, failure_prediction_enabled=:X43, notes=:X44, notes_url=:X45, action_url=:X46, icon_image=:X47, icon_image_alt=:X48, vrml_image=:X49, statusmap_image=:X50, have_2d_coords=:X51, x_2d=:X52, y_2d=:X53, have_3d_coords=:X54, x_3d=:X55, y_3d=:X56, z_3d=:X57, address6=:X58 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, host_object_id, alias, display_name, address, check_command_object_id, check_command_args, eventhandler_command_object_id, eventhandler_command_args, check_timeperiod_object_id, notif_timeperiod_object_id, failure_prediction_options, check_interval, retry_interval, max_check_attempts, first_notification_delay, notification_interval, notify_on_down, notify_on_unreachable, notify_on_recovery, notify_on_flapping, notify_on_downtime, stalk_on_up, stalk_on_down, stalk_on_unreachable, flap_detection_enabled, flap_detection_on_up, flap_detection_on_down, flap_detection_on_unreachable, low_flap_threshold, high_flap_threshold, process_performance_data, freshness_checks_enabled, freshness_threshold, passive_checks_enabled, event_handler_enabled, active_checks_enabled, retain_status_information, retain_nonstatus_information, notifications_enabled, obsess_over_host, failure_prediction_enabled, notes, notes_url, action_url, icon_image, icon_image_alt, vrml_image, statusmap_image, have_2d_coords, x_2d, y_2d, have_3d_coords, x_3d, y_3d, z_3d, address6) VALUES (seq_hosts.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11, :X12, :X13, :X14, :X15, :X16, :X17, :X18, :X19, :X20, :X21, :X22, :X23, :X24, :X25, :X26, :X27, :X28, :X29, :X30, :X31, :X32, :X33, :X34, :X35, :X36, :X37, :X38, :X39, :X40, :X41, :X42, :X43, :X44, :X45, :X46, :X47, :X48, :X49, :X50, :X51, :X52, :X53, :X54, :X55, :X56, :X57, :X58)", 04834 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTS]) == -1) { 04835 buf = NULL; 04836 } 04837 04838 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04839 04840 if(idi->dbinfo.oci_connection) { 04841 04842 idi->dbinfo.oci_statement_hostdefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 04843 04844 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostdefinition_definition, 1); 04845 04846 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostdefinition_definition, MT(buf))) { 04847 free(buf); 04848 return IDO_ERROR; 04849 } 04850 } else { 04851 free(buf); 04852 return IDO_ERROR; 04853 } 04854 free(buf); 04855 04856 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04857 04858 return IDO_OK; 04859 } 04860 04861 int ido2db_oci_prepared_statement_hostdefinition_parenthosts(ido2db_idi *idi) { 04862 04863 char *buf = NULL; 04864 04865 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04866 04867 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (host_id=:X2 AND parent_host_object_id=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, host_id, parent_host_object_id) VALUES (seq_host_parenthosts.nextval, :X1, :X2, :X3)", 04868 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTPARENTHOSTS]) == -1) { 04869 buf = NULL; 04870 } 04871 04872 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04873 04874 if(idi->dbinfo.oci_connection) { 04875 04876 idi->dbinfo.oci_statement_hostdefinition_parenthosts = OCI_StatementCreate(idi->dbinfo.oci_connection); 04877 04878 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostdefinition_parenthosts, 1); 04879 04880 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostdefinition_parenthosts, MT(buf))) { 04881 free(buf); 04882 return IDO_ERROR; 04883 } 04884 } else { 04885 free(buf); 04886 return IDO_ERROR; 04887 } 04888 free(buf); 04889 04890 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04891 04892 return IDO_OK; 04893 } 04894 04895 int ido2db_oci_prepared_statement_hostdefinition_contactgroups(ido2db_idi *idi) { 04896 04897 char *buf = NULL; 04898 04899 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04900 04901 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (host_id=:X2 AND contactgroup_object_id=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, host_id, contactgroup_object_id) VALUES (seq_host_contactgroups.nextval, :X1, :X2, :X3)", 04902 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTGROUPS]) == -1) { 04903 buf = NULL; 04904 } 04905 04906 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04907 04908 if(idi->dbinfo.oci_connection) { 04909 04910 idi->dbinfo.oci_statement_hostdefinition_contactgroups = OCI_StatementCreate(idi->dbinfo.oci_connection); 04911 04912 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostdefinition_contactgroups, 1); 04913 04914 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostdefinition_contactgroups, MT(buf))) { 04915 free(buf); 04916 return IDO_ERROR; 04917 } 04918 } else { 04919 free(buf); 04920 return IDO_ERROR; 04921 } 04922 free(buf); 04923 04924 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04925 04926 return IDO_OK; 04927 } 04928 04929 int ido2db_oci_prepared_statement_hostdefinition_contacts(ido2db_idi *idi) { 04930 04931 char *buf = NULL; 04932 04933 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04934 04935 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1) WHEN MATCHED THEN UPDATE SET host_id=:X2, contact_object_id=:X3 WHEN NOT MATCHED THEN INSERT (id, instance_id, host_id, contact_object_id) VALUES (seq_host_contacts.nextval, :X1, :X2, :X3)", 04936 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTS]) == -1) { 04937 buf = NULL; 04938 } 04939 04940 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04941 04942 if(idi->dbinfo.oci_connection) { 04943 04944 idi->dbinfo.oci_statement_hostdefinition_contacts = OCI_StatementCreate(idi->dbinfo.oci_connection); 04945 04946 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostdefinition_contacts, 1); 04947 04948 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostdefinition_contacts, MT(buf))) { 04949 free(buf); 04950 return IDO_ERROR; 04951 } 04952 } else { 04953 free(buf); 04954 return IDO_ERROR; 04955 } 04956 free(buf); 04957 04958 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04959 04960 return IDO_OK; 04961 } 04962 04963 04964 /************************************/ 04965 /* HOSTGROUPDEFINITION */ 04966 /************************************/ 04967 04968 04969 int ido2db_oci_prepared_statement_hostgroupdefinition_definition(ido2db_idi *idi) { 04970 04971 char *buf = NULL; 04972 04973 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 04974 04975 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:x1 AND hostgroup_object_id=:X3) WHEN MATCHED THEN UPDATE SET config_type=:X2, alias=:X4 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, hostgroup_object_id, alias) VALUES (seq_hostgroups.nextval, :X1, :X2, :X3, :X4)", 04976 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPS]) == -1) { 04977 buf = NULL; 04978 } 04979 04980 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 04981 04982 if(idi->dbinfo.oci_connection) { 04983 04984 idi->dbinfo.oci_statement_hostgroupdefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 04985 04986 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostgroupdefinition_definition, 1); 04987 04988 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostgroupdefinition_definition, MT(buf))) { 04989 free(buf); 04990 return IDO_ERROR; 04991 } 04992 } else { 04993 free(buf); 04994 return IDO_ERROR; 04995 } 04996 free(buf); 04997 04998 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 04999 05000 return IDO_OK; 05001 } 05002 05003 int ido2db_oci_prepared_statement_hostgroupdefinition_hostgroupmembers(ido2db_idi *idi) { 05004 05005 char *buf = NULL; 05006 05007 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05008 05009 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (hostgroup_id=:X2 AND host_object_id=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, hostgroup_id, host_object_id) VALUES (seq_hostgroup_members.nextval, :X1, :X2, :X3)", 05010 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPMEMBERS]) == -1) { 05011 buf = NULL; 05012 } 05013 05014 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05015 05016 if(idi->dbinfo.oci_connection) { 05017 05018 idi->dbinfo.oci_statement_hostgroupdefinition_hostgroupmembers = OCI_StatementCreate(idi->dbinfo.oci_connection); 05019 05020 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostgroupdefinition_hostgroupmembers, 1); 05021 05022 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostgroupdefinition_hostgroupmembers, MT(buf))) { 05023 free(buf); 05024 return IDO_ERROR; 05025 } 05026 } else { 05027 free(buf); 05028 return IDO_ERROR; 05029 } 05030 free(buf); 05031 05032 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05033 05034 return IDO_OK; 05035 } 05036 05037 05038 /************************************/ 05039 /* SERVICEDEFINITION */ 05040 /************************************/ 05041 05042 05043 int ido2db_oci_prepared_statement_servicedefinition_definition(ido2db_idi *idi) { 05044 05045 char *buf = NULL; 05046 05047 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05048 05049 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND service_object_id=:X4) WHEN MATCHED THEN UPDATE SET host_object_id=:X3, display_name=:X5, check_command_object_id=:X6, check_command_args=:X7, eventhandler_command_object_id=:X8, eventhandler_command_args=:X9, check_timeperiod_object_id=:X10, notif_timeperiod_object_id=:X11, failure_prediction_options=:X12, check_interval=:X13, retry_interval=:X14, max_check_attempts=:X15, first_notification_delay=:X16, notification_interval=:X17, notify_on_warning=:X18, notify_on_unknown=:X19, notify_on_critical=:X20, notify_on_recovery=:X21, notify_on_flapping=:X22, notify_on_downtime=:X23, stalk_on_ok=:X24, stalk_on_warning=:X25, stalk_on_unknown=:X26, stalk_on_critical=:X27, is_volatile=:X28, flap_detection_enabled=:X29, flap_detection_on_ok=:X30, flap_detection_on_warning=:X31, flap_detection_on_unknown=:X32, flap_detection_on_critical=:X33, low_flap_threshold=:X34, high_flap_threshold=:X35, process_performance_data=:X36, freshness_checks_enabled=:X37, freshness_threshold=:X38, passive_checks_enabled=:X39, event_handler_enabled=:X40, active_checks_enabled=:X41, retain_status_information=:X42, retain_nonstatus_information=:X43, notifications_enabled=:X44, obsess_over_service=:X45, failure_prediction_enabled=:X46, notes=:X47, notes_url=:X48, action_url=:X49, icon_image=:X50, icon_image_alt=:X51 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, host_object_id, service_object_id, display_name, check_command_object_id, check_command_args, eventhandler_command_object_id, eventhandler_command_args, check_timeperiod_object_id, notif_timeperiod_object_id, failure_prediction_options, check_interval, retry_interval, max_check_attempts, first_notification_delay, notification_interval, notify_on_warning, notify_on_unknown, notify_on_critical, notify_on_recovery, notify_on_flapping, notify_on_downtime, stalk_on_ok, stalk_on_warning, stalk_on_unknown, stalk_on_critical, is_volatile, flap_detection_enabled, flap_detection_on_ok, flap_detection_on_warning, flap_detection_on_unknown, flap_detection_on_critical, low_flap_threshold, high_flap_threshold, process_performance_data, freshness_checks_enabled, freshness_threshold, passive_checks_enabled, event_handler_enabled, active_checks_enabled, retain_status_information, retain_nonstatus_information, notifications_enabled, obsess_over_service, failure_prediction_enabled, notes, notes_url, action_url, icon_image, icon_image_alt) VALUES (seq_services.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11, :X12, :X13, :X14, :X15, :X16, :X17, :X18, :X19, :X20, :X21, :X22, :X23, :X24, :X25, :X26, :X27, :X28, :X29, :X30, :X31, :X32, :X33, :X34, :X35, :X36, :X37, :X38, :X39, :X40, :X41, :X42, :X43, :X44, :X45, :X46, :X47, :X48, :X49, :X50, :X51)", 05050 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICES]) == -1) { 05051 buf = NULL; 05052 } 05053 05054 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05055 05056 if(idi->dbinfo.oci_connection) { 05057 05058 idi->dbinfo.oci_statement_servicedefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05059 05060 OCI_AllowRebinding(idi->dbinfo.oci_statement_servicedefinition_definition, 1); 05061 05062 if(!OCI_Prepare(idi->dbinfo.oci_statement_servicedefinition_definition, MT(buf))) { 05063 free(buf); 05064 return IDO_ERROR; 05065 } 05066 } else { 05067 free(buf); 05068 return IDO_ERROR; 05069 } 05070 free(buf); 05071 05072 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05073 05074 return IDO_OK; 05075 } 05076 05077 int ido2db_oci_prepared_statement_servicedefinition_contactgroups(ido2db_idi *idi) { 05078 05079 char *buf = NULL; 05080 05081 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05082 05083 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (service_id=:X2 AND contactgroup_object_id=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, service_id, contactgroup_object_id) VALUES (seq_service_contactgroups.nextval, :X1, :X2, :X3)", 05084 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTGROUPS]) == -1) { 05085 buf = NULL; 05086 } 05087 05088 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05089 05090 if(idi->dbinfo.oci_connection) { 05091 05092 idi->dbinfo.oci_statement_servicedefinition_contactgroups = OCI_StatementCreate(idi->dbinfo.oci_connection); 05093 05094 OCI_AllowRebinding(idi->dbinfo.oci_statement_servicedefinition_contactgroups, 1); 05095 05096 if(!OCI_Prepare(idi->dbinfo.oci_statement_servicedefinition_contactgroups, MT(buf))) { 05097 free(buf); 05098 return IDO_ERROR; 05099 } 05100 } else { 05101 free(buf); 05102 return IDO_ERROR; 05103 } 05104 free(buf); 05105 05106 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05107 05108 return IDO_OK; 05109 } 05110 05111 int ido2db_oci_prepared_statement_servicedefinition_contacts(ido2db_idi *idi) { 05112 05113 char *buf = NULL; 05114 05115 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05116 05117 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1) WHEN MATCHED THEN UPDATE SET service_id=:X2, contact_object_id=:X3 WHEN NOT MATCHED THEN INSERT (id, instance_id, service_id, contact_object_id) VALUES (seq_service_contacts.nextval, :X1, :X2, :X3)", 05118 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTS]) == -1) { 05119 buf = NULL; 05120 } 05121 05122 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05123 05124 if(idi->dbinfo.oci_connection) { 05125 05126 idi->dbinfo.oci_statement_servicedefinition_contacts = OCI_StatementCreate(idi->dbinfo.oci_connection); 05127 05128 OCI_AllowRebinding(idi->dbinfo.oci_statement_servicedefinition_contacts, 1); 05129 05130 if(!OCI_Prepare(idi->dbinfo.oci_statement_servicedefinition_contacts, MT(buf))) { 05131 free(buf); 05132 return IDO_ERROR; 05133 } 05134 } else { 05135 free(buf); 05136 return IDO_ERROR; 05137 } 05138 free(buf); 05139 05140 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05141 05142 return IDO_OK; 05143 } 05144 05145 05146 /************************************/ 05147 /* SERVICEGROUPDEFINITION */ 05148 /************************************/ 05149 05150 05151 int ido2db_oci_prepared_statement_servicegroupdefinition_definition(ido2db_idi *idi) { 05152 05153 char *buf = NULL; 05154 05155 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05156 05157 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND servicegroup_object_id=:X3) WHEN MATCHED THEN UPDATE SET alias=:X4 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, servicegroup_object_id, alias) VALUES (seq_servicegroups.nextval, :X1, :X2, :X3, :X4)", 05158 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPS]) == -1) { 05159 buf = NULL; 05160 } 05161 05162 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05163 05164 if(idi->dbinfo.oci_connection) { 05165 05166 idi->dbinfo.oci_statement_servicegroupdefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05167 05168 OCI_AllowRebinding(idi->dbinfo.oci_statement_servicegroupdefinition_definition, 1); 05169 05170 if(!OCI_Prepare(idi->dbinfo.oci_statement_servicegroupdefinition_definition, MT(buf))) { 05171 free(buf); 05172 return IDO_ERROR; 05173 } 05174 } else { 05175 free(buf); 05176 return IDO_ERROR; 05177 } 05178 free(buf); 05179 05180 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05181 05182 return IDO_OK; 05183 } 05184 05185 int ido2db_oci_prepared_statement_servicegroupdefinition_members(ido2db_idi *idi) { 05186 05187 char *buf = NULL; 05188 05189 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05190 05191 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (servicegroup_id=:X2 AND service_object_id=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, servicegroup_id, service_object_id) VALUES (seq_servicegroup_members.nextval, :X1, :X2, :X3)", 05192 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPMEMBERS]) == -1) { 05193 buf = NULL; 05194 } 05195 05196 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05197 05198 if(idi->dbinfo.oci_connection) { 05199 05200 idi->dbinfo.oci_statement_servicegroupdefinition_members = OCI_StatementCreate(idi->dbinfo.oci_connection); 05201 05202 OCI_AllowRebinding(idi->dbinfo.oci_statement_servicegroupdefinition_members, 1); 05203 05204 if(!OCI_Prepare(idi->dbinfo.oci_statement_servicegroupdefinition_members, MT(buf))) { 05205 free(buf); 05206 return IDO_ERROR; 05207 } 05208 } else { 05209 free(buf); 05210 return IDO_ERROR; 05211 } 05212 free(buf); 05213 05214 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05215 05216 return IDO_OK; 05217 } 05218 05219 05220 05221 /************************************/ 05222 /* DEPENDENCYDEFINITION */ 05223 /************************************/ 05224 05225 05226 int ido2db_oci_prepared_statement_hostdependencydefinition_definition(ido2db_idi *idi) { 05227 05228 char *buf = NULL; 05229 05230 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05231 05232 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND host_object_id=:X3 AND dependent_host_object_id=:X4 AND dependency_type=:X5 AND inherits_parent=:X6 AND fail_on_up=:X8 AND fail_on_down=:X9 AND fail_on_unreachable=:X10) WHEN MATCHED THEN UPDATE SET timeperiod_object_id=:X7 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, host_object_id, dependent_host_object_id, dependency_type, inherits_parent, timeperiod_object_id, fail_on_up, fail_on_down, fail_on_unreachable) VALUES (seq_hostdependencies.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10)", 05233 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTDEPENDENCIES]) == -1) { 05234 buf = NULL; 05235 } 05236 05237 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05238 05239 if(idi->dbinfo.oci_connection) { 05240 05241 idi->dbinfo.oci_statement_hostdependencydefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05242 05243 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostdependencydefinition_definition, 1); 05244 05245 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(buf))) { 05246 free(buf); 05247 return IDO_ERROR; 05248 } 05249 } else { 05250 free(buf); 05251 return IDO_ERROR; 05252 } 05253 free(buf); 05254 05255 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05256 05257 return IDO_OK; 05258 } 05259 05260 int ido2db_oci_prepared_statement_servicedependencydefinition_definition(ido2db_idi *idi) { 05261 05262 char *buf = NULL; 05263 05264 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05265 05266 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND service_object_id=:X3 AND dependent_service_object_id=:X4 AND dependency_type=:X5 AND inherits_parent=:X6 AND fail_on_ok=:X8 AND fail_on_warning=:X9 AND fail_on_unknown=:X10 AND fail_on_critical=:X11) WHEN MATCHED THEN UPDATE SET timeperiod_object_id=:X7 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, service_object_id, dependent_service_object_id, dependency_type, inherits_parent, timeperiod_object_id, fail_on_ok, fail_on_warning, fail_on_unknown, fail_on_critical) VALUES (seq_servicedependencies.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11)", 05267 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEDEPENDENCIES]) == -1) { 05268 buf = NULL; 05269 } 05270 05271 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05272 05273 if(idi->dbinfo.oci_connection) { 05274 05275 idi->dbinfo.oci_statement_servicedependencydefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05276 05277 OCI_AllowRebinding(idi->dbinfo.oci_statement_servicedependencydefinition_definition, 1); 05278 05279 if(!OCI_Prepare(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(buf))) { 05280 free(buf); 05281 return IDO_ERROR; 05282 } 05283 } else { 05284 free(buf); 05285 return IDO_ERROR; 05286 } 05287 free(buf); 05288 05289 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05290 05291 return IDO_OK; 05292 } 05293 05294 05295 /************************************/ 05296 /* HOSTESCALATIONDEFINITION */ 05297 /************************************/ 05298 05299 05300 int ido2db_oci_prepared_statement_hostescalationdefinition_definition(ido2db_idi *idi) { 05301 05302 char *buf = NULL; 05303 05304 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05305 05306 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND host_object_id=:X3 AND timeperiod_object_id=:X4 AND first_notification=:X5 AND last_notification=:X6) WHEN MATCHED THEN UPDATE SET notification_interval=:X7, escalate_on_recovery=:X8, escalate_on_down=:X9, escalate_on_unreachable=:X10 WHEN NOT MATCHED THEN INSERT (instance_id, config_type, host_object_id, timeperiod_object_id, first_notification, last_notification, notification_interval, escalate_on_recovery, escalate_on_down, escalate_on_unreachable) VALUES (seq_hostescalations.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10)", 05307 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONS]) == -1) { 05308 buf = NULL; 05309 } 05310 05311 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05312 05313 if(idi->dbinfo.oci_connection) { 05314 05315 idi->dbinfo.oci_statement_hostescalationdefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05316 05317 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostescalationdefinition_definition, 1); 05318 05319 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(buf))) { 05320 free(buf); 05321 return IDO_ERROR; 05322 } 05323 } else { 05324 free(buf); 05325 return IDO_ERROR; 05326 } 05327 free(buf); 05328 05329 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05330 05331 return IDO_OK; 05332 } 05333 05334 int ido2db_oci_prepared_statement_hostescalationdefinition_contactgroups(ido2db_idi *idi) { 05335 05336 char *buf = NULL; 05337 05338 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05339 05340 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (hostescalation_id=:X2 AND contactgroup_object_id=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, hostescalation_id, contactgroup_object_id) VALUES (seq_hostesc_contactgroups.nextval, :X1, :X2, :X3)", 05341 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTGROUPS]) == -1) { 05342 buf = NULL; 05343 } 05344 05345 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05346 05347 if(idi->dbinfo.oci_connection) { 05348 05349 idi->dbinfo.oci_statement_hostescalationdefinition_contactgroups = OCI_StatementCreate(idi->dbinfo.oci_connection); 05350 05351 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostescalationdefinition_contactgroups, 1); 05352 05353 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostescalationdefinition_contactgroups, MT(buf))) { 05354 free(buf); 05355 return IDO_ERROR; 05356 } 05357 } else { 05358 free(buf); 05359 return IDO_ERROR; 05360 } 05361 free(buf); 05362 05363 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05364 05365 return IDO_OK; 05366 } 05367 05368 int ido2db_oci_prepared_statement_hostescalationdefinition_contacts(ido2db_idi *idi) { 05369 05370 char *buf = NULL; 05371 05372 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05373 05374 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1) WHEN MATCHED THEN UPDATE SET hostescalation_id=:X2, contact_object_id=:X3 WHEN NOT MATCHED THEN INSERT (id, instance_id, hostescalation_id, contact_object_id) VALUES (seq_hostesc_contacts.nextval, :X1, :X2, :X3)", 05375 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTS]) == -1) { 05376 buf = NULL; 05377 } 05378 05379 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05380 05381 if(idi->dbinfo.oci_connection) { 05382 05383 idi->dbinfo.oci_statement_hostescalationdefinition_contacts = OCI_StatementCreate(idi->dbinfo.oci_connection); 05384 05385 OCI_AllowRebinding(idi->dbinfo.oci_statement_hostescalationdefinition_contacts, 1); 05386 05387 if(!OCI_Prepare(idi->dbinfo.oci_statement_hostescalationdefinition_contacts, MT(buf))) { 05388 free(buf); 05389 return IDO_ERROR; 05390 } 05391 } else { 05392 free(buf); 05393 return IDO_ERROR; 05394 } 05395 free(buf); 05396 05397 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05398 05399 return IDO_OK; 05400 } 05401 05402 05403 /************************************/ 05404 /* SERVICEESCALATIONDEFINITION */ 05405 /************************************/ 05406 05407 05408 int ido2db_oci_prepared_statement_serviceescalationdefinition_definition(ido2db_idi *idi) { 05409 05410 char *buf = NULL; 05411 05412 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05413 05414 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND service_object_id=:X3 AND timeperiod_object_id=:X4 AND first_notification=:X5 AND last_notification=:X6) WHEN MATCHED THEN UPDATE SET notification_interval=:X7, escalate_on_recovery=:X8, escalate_on_warning=:X9, escalate_on_unknown=:X10, escalate_on_critical=:X11 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, service_object_id, timeperiod_object_id, first_notification, last_notification, notification_interval, escalate_on_recovery, escalate_on_warning, escalate_on_unknown, escalate_on_critical) VALUES (seq_serviceescalations.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11)", 05415 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONS]) == -1) { 05416 buf = NULL; 05417 } 05418 05419 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05420 05421 if(idi->dbinfo.oci_connection) { 05422 05423 idi->dbinfo.oci_statement_serviceescalationdefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05424 05425 OCI_AllowRebinding(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, 1); 05426 05427 if(!OCI_Prepare(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(buf))) { 05428 free(buf); 05429 return IDO_ERROR; 05430 } 05431 } else { 05432 free(buf); 05433 return IDO_ERROR; 05434 } 05435 free(buf); 05436 05437 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05438 05439 return IDO_OK; 05440 } 05441 05442 int ido2db_oci_prepared_statement_serviceescalationdefinition_contactgroups(ido2db_idi *idi) { 05443 05444 char *buf = NULL; 05445 05446 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05447 05448 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (serviceescalation_id=:X2 AND contactgroup_object_id=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, serviceescalation_id, contactgroup_object_id) VALUES (seq_serviceesccontactgroups.nextval, :X1, :X2, :X3)", 05449 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTGROUPS]) == -1) { 05450 buf = NULL; 05451 } 05452 05453 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05454 05455 if(idi->dbinfo.oci_connection) { 05456 05457 idi->dbinfo.oci_statement_serviceescalationdefinition_contactgroups = OCI_StatementCreate(idi->dbinfo.oci_connection); 05458 05459 OCI_AllowRebinding(idi->dbinfo.oci_statement_serviceescalationdefinition_contactgroups, 1); 05460 05461 if(!OCI_Prepare(idi->dbinfo.oci_statement_serviceescalationdefinition_contactgroups, MT(buf))) { 05462 free(buf); 05463 return IDO_ERROR; 05464 } 05465 } else { 05466 free(buf); 05467 return IDO_ERROR; 05468 } 05469 free(buf); 05470 05471 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05472 05473 return IDO_OK; 05474 } 05475 05476 int ido2db_oci_prepared_statement_serviceescalationdefinition_contacts(ido2db_idi *idi) { 05477 05478 char *buf = NULL; 05479 05480 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05481 05482 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1) WHEN MATCHED THEN UPDATE SET serviceescalation_id=:X2, contact_object_id=:X3 WHEN NOT MATCHED THEN INSERT (id, instance_id, serviceescalation_id, contact_object_id) VALUES (seq_serviceesc_contacts.nextval, :X1, :X2, :X3)", 05483 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTS]) == -1) { 05484 buf = NULL; 05485 } 05486 05487 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05488 05489 if(idi->dbinfo.oci_connection) { 05490 05491 idi->dbinfo.oci_statement_serviceescalationdefinition_contacts = OCI_StatementCreate(idi->dbinfo.oci_connection); 05492 05493 OCI_AllowRebinding(idi->dbinfo.oci_statement_serviceescalationdefinition_contacts, 1); 05494 05495 if(!OCI_Prepare(idi->dbinfo.oci_statement_serviceescalationdefinition_contacts, MT(buf))) { 05496 free(buf); 05497 return IDO_ERROR; 05498 } 05499 } else { 05500 free(buf); 05501 return IDO_ERROR; 05502 } 05503 free(buf); 05504 05505 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05506 05507 return IDO_OK; 05508 } 05509 05510 05511 /************************************/ 05512 /* COMMANDDEFINITION */ 05513 /************************************/ 05514 05515 05516 int ido2db_oci_prepared_statement_commanddefinition_definition(ido2db_idi *idi) { 05517 05518 char *buf = NULL; 05519 05520 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commanddefinition_definition() start\n"); 05521 05522 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND object_id=:X2 AND config_type=:X3) WHEN MATCHED THEN UPDATE SET command_line=:X4 WHEN NOT MATCHED THEN INSERT (id, instance_id, object_id, config_type, command_line) VALUES (seq_commands.nextval, :X1, :X2, :X3, :X4)", 05523 ido2db_db_tablenames[IDO2DB_DBTABLE_COMMANDS]) == -1) { 05524 buf = NULL; 05525 } 05526 05527 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_commanddefinition_definition() query: %s\n", buf); 05528 05529 if(idi->dbinfo.oci_connection) { 05530 05531 idi->dbinfo.oci_statement_commanddefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05532 05533 OCI_AllowRebinding(idi->dbinfo.oci_statement_commanddefinition_definition, 1); 05534 05535 if(!OCI_Prepare(idi->dbinfo.oci_statement_commanddefinition_definition, MT(buf))) { 05536 free(buf); 05537 return IDO_ERROR; 05538 } 05539 } else { 05540 free(buf); 05541 return IDO_ERROR; 05542 } 05543 free(buf); 05544 05545 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_(nddefinition_definition) end\n"); 05546 05547 return IDO_OK; 05548 } 05549 05550 05551 /************************************/ 05552 /* TIMEPERIODEFINTION */ 05553 /************************************/ 05554 05555 05556 int ido2db_oci_prepared_statement_timeperiodefinition_definition(ido2db_idi *idi) { 05557 05558 char *buf = NULL; 05559 05560 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05561 05562 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND timeperiod_object_id=:X3) WHEN MATCHED THEN UPDATE SET alias=:X4 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, timeperiod_object_id, alias) VALUES (seq_timeperiods.nextval, :X1, :X2, :X3, :X4)", 05563 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODS]) == -1) { 05564 buf = NULL; 05565 } 05566 05567 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05568 05569 if(idi->dbinfo.oci_connection) { 05570 05571 idi->dbinfo.oci_statement_timeperiodefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05572 05573 05574 OCI_AllowRebinding(idi->dbinfo.oci_statement_timeperiodefinition_definition, 1); 05575 05576 if(!OCI_Prepare(idi->dbinfo.oci_statement_timeperiodefinition_definition, MT(buf))) { 05577 free(buf); 05578 return IDO_ERROR; 05579 } 05580 } else { 05581 free(buf); 05582 return IDO_ERROR; 05583 } 05584 free(buf); 05585 05586 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05587 05588 return IDO_OK; 05589 } 05590 05591 int ido2db_oci_prepared_statement_timeperiodefinition_timeranges(ido2db_idi *idi) { 05592 05593 char *buf = NULL; 05594 05595 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05596 05597 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (timeperiod_id=:X2 AND day=:X3 AND start_sec=:X4 AND end_sec=:X5) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, timeperiod_id, day, start_sec, end_sec) VALUES (seq_timep_timer.nextval, :X1, :X2, :X3, :X4, :X5)", 05598 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODTIMERANGES]) == -1) { 05599 buf = NULL; 05600 } 05601 05602 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05603 05604 if(idi->dbinfo.oci_connection) { 05605 05606 idi->dbinfo.oci_statement_timeperiodefinition_timeranges = OCI_StatementCreate(idi->dbinfo.oci_connection); 05607 05608 OCI_AllowRebinding(idi->dbinfo.oci_statement_timeperiodefinition_timeranges, 1); 05609 05610 if(!OCI_Prepare(idi->dbinfo.oci_statement_timeperiodefinition_timeranges, MT(buf))) { 05611 free(buf); 05612 return IDO_ERROR; 05613 } 05614 } else { 05615 free(buf); 05616 return IDO_ERROR; 05617 } 05618 free(buf); 05619 05620 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05621 05622 return IDO_OK; 05623 } 05624 05625 05626 /************************************/ 05627 /* CONTACTDEFINTION */ 05628 /************************************/ 05629 05630 05631 int ido2db_oci_prepared_statement_contactdefinition_definition(ido2db_idi *idi) { 05632 05633 char *buf = NULL; 05634 05635 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05636 05637 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND contact_object_id=:X3) WHEN MATCHED THEN UPDATE SET alias=:X4, email_address=:X5, pager_address=:X6, host_timeperiod_object_id=:X7, service_timeperiod_object_id=:X8, host_notifications_enabled=:X9, service_notifications_enabled=:X10, can_submit_commands=:X11, notify_service_recovery=:X12, notify_service_warning=:X13, notify_service_unknown=:X14, notify_service_critical=:X15, notify_service_flapping=:X16, notify_service_downtime=:X17, notify_host_recovery=:X18, notify_host_down=:X19, notify_host_unreachable=:X20, notify_host_flapping=:X21, notify_host_downtime=:X22 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, contact_object_id, alias, email_address, pager_address, host_timeperiod_object_id, service_timeperiod_object_id, host_notifications_enabled, service_notifications_enabled, can_submit_commands, notify_service_recovery, notify_service_warning, notify_service_unknown, notify_service_critical, notify_service_flapping, notify_service_downtime, notify_host_recovery, notify_host_down, notify_host_unreachable, notify_host_flapping, notify_host_downtime) VALUES (seq_contacts.nextval, :X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10, :X11, :X12, :X13, :X14, :X15, :X16, :X17, :X18, :X19, :X20, :X21, :X22)", 05638 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTS]) == -1) { 05639 buf = NULL; 05640 } 05641 05642 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05643 05644 if(idi->dbinfo.oci_connection) { 05645 05646 idi->dbinfo.oci_statement_contactdefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05647 05648 OCI_AllowRebinding(idi->dbinfo.oci_statement_contactdefinition_definition, 1); 05649 05650 if(!OCI_Prepare(idi->dbinfo.oci_statement_contactdefinition_definition, MT(buf))) { 05651 free(buf); 05652 return IDO_ERROR; 05653 } 05654 } else { 05655 free(buf); 05656 return IDO_ERROR; 05657 } 05658 free(buf); 05659 05660 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05661 05662 return IDO_OK; 05663 } 05664 05665 int ido2db_oci_prepared_statement_contactdefinition_addresses(ido2db_idi *idi) { 05666 05667 char *buf = NULL; 05668 05669 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05670 05671 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (contact_id=:X1 AND address_number=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X2, address=:X4 WHEN NOT MATCHED THEN INSERT (id, instance_id, contact_id, address_number, address) VALUES (seq_contact_addresses.nextval, :X1, :X2, :X3, :X4)", 05672 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTADDRESSES]) == -1) { 05673 buf = NULL; 05674 } 05675 05676 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05677 05678 if(idi->dbinfo.oci_connection) { 05679 05680 idi->dbinfo.oci_statement_contactdefinition_addresses = OCI_StatementCreate(idi->dbinfo.oci_connection); 05681 05682 OCI_AllowRebinding(idi->dbinfo.oci_statement_contactdefinition_addresses, 1); 05683 05684 if(!OCI_Prepare(idi->dbinfo.oci_statement_contactdefinition_addresses, MT(buf))) { 05685 free(buf); 05686 return IDO_ERROR; 05687 } 05688 } else { 05689 free(buf); 05690 return IDO_ERROR; 05691 } 05692 free(buf); 05693 05694 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05695 05696 return IDO_OK; 05697 } 05698 05699 int ido2db_oci_prepared_statement_contactdefinition_servicenotificationcommands(ido2db_idi *idi) { 05700 05701 char *buf = NULL; 05702 05703 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05704 05705 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND contact_id=:X2 AND notification_type=:X3 AND command_object_id=:X4) WHEN MATCHED THEN UPDATE SET command_args=:X5 WHEN NOT MATCHED THEN INSERT (id, instance_id, contact_id, notification_type, command_object_id, command_args) VALUES (seq_contact_notifcommands.nextval, :X1, :X2, :X3, :X4, :X5)", 05706 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS]) == -1) { 05707 buf = NULL; 05708 } 05709 05710 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05711 05712 if(idi->dbinfo.oci_connection) { 05713 05714 idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands = OCI_StatementCreate(idi->dbinfo.oci_connection); 05715 05716 OCI_AllowRebinding(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands, 1); 05717 05718 if(!OCI_Prepare(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands, MT(buf))) { 05719 free(buf); 05720 return IDO_ERROR; 05721 } 05722 } else { 05723 free(buf); 05724 return IDO_ERROR; 05725 } 05726 free(buf); 05727 05728 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05729 05730 return IDO_OK; 05731 } 05732 05733 05734 /************************************/ 05735 /* CUSTOMVARIABLES */ 05736 /************************************/ 05737 05738 05739 int ido2db_oci_prepared_statement_save_custom_variables_customvariables(ido2db_idi *idi) { 05740 05741 char *buf = NULL; 05742 05743 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05744 05745 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (object_id=:X2 AND varname=:X5) WHEN MATCHED THEN UPDATE SET instance_id=:X1, config_type=:X3, has_been_modified=:X4, varvalue=:X6 WHEN NOT MATCHED THEN INSERT (id, instance_id, object_id, config_type, has_been_modified, varname, varvalue) VALUES (seq_customvariables.nextval, :X1, :X2, :X3, :X4, :X5, :X6)", 05746 ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLES]) == -1) { 05747 buf = NULL; 05748 } 05749 05750 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05751 05752 if(idi->dbinfo.oci_connection) { 05753 05754 idi->dbinfo.oci_statement_save_custom_variables_customvariables = OCI_StatementCreate(idi->dbinfo.oci_connection); 05755 05756 OCI_AllowRebinding(idi->dbinfo.oci_statement_save_custom_variables_customvariables, 1); 05757 05758 if(!OCI_Prepare(idi->dbinfo.oci_statement_save_custom_variables_customvariables, MT(buf))) { 05759 free(buf); 05760 return IDO_ERROR; 05761 } 05762 } else { 05763 free(buf); 05764 return IDO_ERROR; 05765 } 05766 free(buf); 05767 05768 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05769 05770 return IDO_OK; 05771 } 05772 05773 int ido2db_oci_prepared_statement_save_custom_variables_customvariablestatus(ido2db_idi *idi) { 05774 05775 char *buf = NULL; 05776 05777 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05778 05779 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (object_id=:X2 AND varname=:X5) WHEN MATCHED THEN UPDATE SET instance_id=:X1, status_update_time=(SELECT unixts2date(:X3) FROM DUAL), has_been_modified=:X4, varvalue=:X6 WHEN NOT MATCHED THEN INSERT (id, instance_id, object_id, status_update_time, has_been_modified, varname, varvalue) VALUES (seq_customvariablestatus.nextval, :X1, :X2, (SELECT unixts2date(:X3) FROM DUAL), :X4, :X5, :X6)", 05780 ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS]) == -1) { 05781 buf = NULL; 05782 } 05783 05784 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05785 05786 if(idi->dbinfo.oci_connection) { 05787 05788 idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus = OCI_StatementCreate(idi->dbinfo.oci_connection); 05789 05790 OCI_AllowRebinding(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, 1); 05791 05792 if(!OCI_Prepare(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, MT(buf))) { 05793 free(buf); 05794 return IDO_ERROR; 05795 } 05796 } else { 05797 free(buf); 05798 return IDO_ERROR; 05799 } 05800 free(buf); 05801 05802 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05803 05804 return IDO_OK; 05805 } 05806 05807 05808 /************************************/ 05809 /* CONTACTGROUPDEFINITION */ 05810 /************************************/ 05811 05812 05813 int ido2db_oci_prepared_statement_contactgroupdefinition_definition(ido2db_idi *idi) { 05814 05815 char *buf = NULL; 05816 05817 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05818 05819 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (instance_id=:X1 AND config_type=:X2 AND contactgroup_object_id=:X3) WHEN MATCHED THEN UPDATE SET alias=:X4 WHEN NOT MATCHED THEN INSERT (id, instance_id, config_type, contactgroup_object_id, alias) VALUES (seq_contactgroups.nextval, :X1, :X2, :X3, :X4)", 05820 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPS]) == -1) { 05821 buf = NULL; 05822 } 05823 05824 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05825 05826 if(idi->dbinfo.oci_connection) { 05827 05828 idi->dbinfo.oci_statement_contactgroupdefinition_definition = OCI_StatementCreate(idi->dbinfo.oci_connection); 05829 05830 OCI_AllowRebinding(idi->dbinfo.oci_statement_contactgroupdefinition_definition, 1); 05831 05832 if(!OCI_Prepare(idi->dbinfo.oci_statement_contactgroupdefinition_definition, MT(buf))) { 05833 free(buf); 05834 return IDO_ERROR; 05835 } 05836 } else { 05837 free(buf); 05838 return IDO_ERROR; 05839 } 05840 free(buf); 05841 05842 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05843 05844 return IDO_OK; 05845 } 05846 05847 int ido2db_oci_prepared_statement_contactgroupdefinition_contactgroupmembers(ido2db_idi *idi) { 05848 05849 char *buf = NULL; 05850 05851 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05852 05853 if(asprintf(&buf, "MERGE INTO %s USING DUAL ON (contactgroup_id=:X2 AND contact_object_id=:X3) WHEN MATCHED THEN UPDATE SET instance_id=:X1 WHEN NOT MATCHED THEN INSERT (id, instance_id, contactgroup_id, contact_object_id) VALUES (seq_contactgroup_members.nextval, :X1, :X2, :X3)", 05854 ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPMEMBERS]) == -1) { 05855 buf = NULL; 05856 } 05857 05858 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05859 05860 if(idi->dbinfo.oci_connection) { 05861 05862 idi->dbinfo.oci_statement_contactgroupdefinition_contactgroupmembers = OCI_StatementCreate(idi->dbinfo.oci_connection); 05863 05864 OCI_AllowRebinding(idi->dbinfo.oci_statement_contactgroupdefinition_contactgroupmembers, 1); 05865 05866 if(!OCI_Prepare(idi->dbinfo.oci_statement_contactgroupdefinition_contactgroupmembers, MT(buf))) { 05867 free(buf); 05868 return IDO_ERROR; 05869 } 05870 } else { 05871 free(buf); 05872 return IDO_ERROR; 05873 } 05874 free(buf); 05875 05876 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05877 05878 return IDO_OK; 05879 } 05880 05881 05882 /************************************/ 05883 /* DELETE */ 05884 /************************************/ 05885 05886 05887 int ido2db_oci_prepared_statement_timedeventqueue_delete(ido2db_idi *idi) { 05888 05889 char *buf = NULL; 05890 05891 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05892 05893 if(asprintf(&buf, "DELETE FROM %s WHERE instance_id=:X1 AND scheduled_time<=(SELECT unixts2date(:X2) FROM DUAL)", 05894 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE]) == -1) { 05895 buf = NULL; 05896 } 05897 05898 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05899 05900 if(idi->dbinfo.oci_connection) { 05901 05902 idi->dbinfo.oci_statement_timedeventqueue_delete = OCI_StatementCreate(idi->dbinfo.oci_connection); 05903 05904 /* allow rebinding values */ 05905 OCI_AllowRebinding(idi->dbinfo.oci_statement_timedeventqueue_delete, 1); 05906 05907 if(!OCI_Prepare(idi->dbinfo.oci_statement_timedeventqueue_delete, MT(buf))) { 05908 free(buf); 05909 return IDO_ERROR; 05910 } 05911 } else { 05912 free(buf); 05913 return IDO_ERROR; 05914 } 05915 free(buf); 05916 05917 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05918 05919 return IDO_OK; 05920 } 05921 05922 int ido2db_oci_prepared_statement_timedeventqueue_delete_more(ido2db_idi *idi) { 05923 05924 char *buf = NULL; 05925 05926 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05927 05928 if(asprintf(&buf, "DELETE FROM %s WHERE instance_id=:X1 AND event_type=:X2 AND scheduled_time=(SELECT unixts2date(:X3) FROM DUAL) AND recurring_event=:X4 AND object_id=:X5", 05929 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE]) == -1) { 05930 buf = NULL; 05931 } 05932 05933 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05934 05935 if(idi->dbinfo.oci_connection) { 05936 05937 idi->dbinfo.oci_statement_timedeventqueue_delete_more = OCI_StatementCreate(idi->dbinfo.oci_connection); 05938 05939 /* allow rebinding values */ 05940 OCI_AllowRebinding(idi->dbinfo.oci_statement_timedeventqueue_delete_more, 1); 05941 05942 if(!OCI_Prepare(idi->dbinfo.oci_statement_timedeventqueue_delete_more, MT(buf))) { 05943 free(buf); 05944 return IDO_ERROR; 05945 } 05946 } else { 05947 free(buf); 05948 return IDO_ERROR; 05949 } 05950 free(buf); 05951 05952 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05953 05954 return IDO_OK; 05955 } 05956 05957 05958 int ido2db_oci_prepared_statement_comments_delete(ido2db_idi *idi) { 05959 05960 char *buf = NULL; 05961 05962 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05963 05964 if(asprintf(&buf, "DELETE FROM %s WHERE instance_id=:X1 AND comment_time=(SELECT unixts2date(:X2) FROM DUAL) AND internal_comment_id=:X3", 05965 ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS]) == -1) { 05966 buf = NULL; 05967 } 05968 05969 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 05970 05971 if(idi->dbinfo.oci_connection) { 05972 05973 idi->dbinfo.oci_statement_comments_delete = OCI_StatementCreate(idi->dbinfo.oci_connection); 05974 05975 /* allow rebinding values */ 05976 OCI_AllowRebinding(idi->dbinfo.oci_statement_comments_delete, 1); 05977 05978 if(!OCI_Prepare(idi->dbinfo.oci_statement_comments_delete, MT(buf))) { 05979 free(buf); 05980 return IDO_ERROR; 05981 } 05982 } else { 05983 free(buf); 05984 return IDO_ERROR; 05985 } 05986 free(buf); 05987 05988 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 05989 05990 return IDO_OK; 05991 } 05992 05993 05994 int ido2db_oci_prepared_statement_downtime_delete(ido2db_idi *idi) { 05995 05996 char *buf = NULL; 05997 05998 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 05999 06000 if(asprintf(&buf, "DELETE FROM %s WHERE instance_id=:X1 AND downtime_type=:X2 AND object_id=:X3 AND entry_time=(SELECT unixts2date(:X4) FROM DUAL) AND scheduled_start_time=(SELECT unixts2date(:X5) FROM DUAL) AND scheduled_end_time=(SELECT unixts2date(:X6) FROM DUAL)", 06001 ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME]) == -1) { 06002 buf = NULL; 06003 } 06004 06005 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 06006 06007 if(idi->dbinfo.oci_connection) { 06008 06009 idi->dbinfo.oci_statement_downtime_delete = OCI_StatementCreate(idi->dbinfo.oci_connection); 06010 06011 /* allow rebinding values */ 06012 OCI_AllowRebinding(idi->dbinfo.oci_statement_downtime_delete, 1); 06013 06014 if(!OCI_Prepare(idi->dbinfo.oci_statement_downtime_delete, MT(buf))) { 06015 free(buf); 06016 return IDO_ERROR; 06017 } 06018 } else { 06019 free(buf); 06020 return IDO_ERROR; 06021 } 06022 free(buf); 06023 06024 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 06025 06026 return IDO_OK; 06027 } 06028 06029 06030 int ido2db_oci_prepared_statement_instances_delete(ido2db_idi *idi) { 06031 06032 char *buf = NULL; 06033 06034 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 06035 06036 if(asprintf(&buf, "BEGIN clean_table_by_instance(:X1, :X2); END;") == -1) { 06037 buf = NULL; 06038 } 06039 06040 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 06041 06042 if(idi->dbinfo.oci_connection) { 06043 06044 idi->dbinfo.oci_statement_instances_delete = OCI_StatementCreate(idi->dbinfo.oci_connection); 06045 06046 /* allow rebinding values */ 06047 OCI_AllowRebinding(idi->dbinfo.oci_statement_instances_delete, 1); 06048 06049 if(!OCI_Prepare(idi->dbinfo.oci_statement_instances_delete, MT(buf))) { 06050 free(buf); 06051 return IDO_ERROR; 06052 } 06053 } else { 06054 free(buf); 06055 return IDO_ERROR; 06056 } 06057 free(buf); 06058 06059 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 06060 06061 return IDO_OK; 06062 } 06063 06064 int ido2db_oci_prepared_statement_instances_delete_time(ido2db_idi *idi) { 06065 06066 char *buf = NULL; 06067 06068 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() start\n"); 06069 06070 if(asprintf(&buf, "BEGIN clean_table_by_instance_time(:X1, :X2, :X3, :X4); END;") == -1) { 06071 buf = NULL; 06072 } 06073 06074 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() query: %s\n", buf); 06075 06076 if(idi->dbinfo.oci_connection) { 06077 06078 idi->dbinfo.oci_statement_instances_delete_time = OCI_StatementCreate(idi->dbinfo.oci_connection); 06079 06080 /* allow rebinding values */ 06081 OCI_AllowRebinding(idi->dbinfo.oci_statement_instances_delete_time, 1); 06082 06083 if(!OCI_Prepare(idi->dbinfo.oci_statement_instances_delete_time, MT(buf))) { 06084 free(buf); 06085 return IDO_ERROR; 06086 } 06087 } else { 06088 free(buf); 06089 return IDO_ERROR; 06090 } 06091 free(buf); 06092 06093 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_() end\n"); 06094 06095 return IDO_OK; 06096 } 06097 06098 06099 /****************************************************************************/ 06100 /* MISC FUNCTIONS */ 06101 /****************************************************************************/ 06102 06103 /************************************/ 06104 /* NULL BINDING */ 06105 /************************************/ 06106 06107 int ido2db_oci_prepared_statement_bind_null_param(OCI_Statement *oci_statement_null, char *param_name) { 06108 06109 char *oci_tmp; 06110 06111 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_bind_null_param() start\n"); 06112 //syslog(LOG_USER | LOG_INFO, "bind null param %s\n", param_name); 06113 06114 dummy=asprintf(&oci_tmp, "a"); /* just malloc sth that ocilib is happy */ 06115 06116 if(param_name==NULL) 06117 return IDO_ERROR; 06118 06119 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_bind_null_param() param=%s\n", param_name); 06120 06121 /* bind to dummy value */ 06122 if(!OCI_BindString(oci_statement_null, MT(param_name), oci_tmp, 0)) { 06123 return IDO_ERROR; 06124 } 06125 06126 /* free dummy */ 06127 free(oci_tmp); 06128 06129 /* get bind ptr, set to NULL */ 06130 if(!OCI_BindSetNull(OCI_GetBind2(oci_statement_null,MT(param_name)))){ 06131 return IDO_ERROR; 06132 } 06133 06134 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_oci_prepared_statement_bind_null_param() end\n"); 06135 06136 return IDO_OK; 06137 } 06138 06139 #endif /* Oracle ocilib specific */