![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /*************************************************************** 00002 * DBHANDLERS.C - Data handler 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/db.h" 00017 #include "../include/dbhandlers.h" 00018 #include "../include/dbqueries.h" 00019 00020 /* Icinga header files */ 00021 #include "../../../include/icinga.h" 00022 #include "../../../include/broker.h" 00023 #include "../../../include/comments.h" 00024 00025 extern int errno; 00026 00027 extern char *ido2db_db_tablenames[IDO2DB_MAX_DBTABLES]; 00028 00029 extern ido2db_dbconfig ido2db_db_settings; /* for tables cleanup settings */ 00030 00031 int dummy; /* reduce compiler warnings */ 00032 00033 /****************************************************************************/ 00034 /* OBJECT ROUTINES */ 00035 /****************************************************************************/ 00036 00037 int ido2db_get_object_id(ido2db_idi *idi, int object_type, char *n1, char *n2, unsigned long *object_id) { 00038 int result = IDO_OK; 00039 int x = 0; 00040 unsigned long cached_object_id = 0L; 00041 char *name1 = NULL; 00042 char *name2 = NULL; 00043 #ifdef USE_LIBDBI 00044 char *buf = NULL; 00045 char *buf1 = NULL; 00046 char *buf2 = NULL; 00047 #endif 00048 #ifdef USE_ORACLE 00049 void *data[4]; 00050 #endif 00051 char *es[2]; 00052 00053 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id() start\n"); 00054 00055 /* make sure empty strings are set to null */ 00056 name1 = n1; 00057 name2 = n2; 00058 if (name1 && !strcmp(name1, "")) 00059 name1 = NULL; 00060 if (name2 && !strcmp(name2, "")) 00061 name2 = NULL; 00062 00063 /* null names mean no object id */ 00064 if (name1 == NULL && name2 == NULL) { 00065 *object_id = 0L; 00066 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id() return null names\n"); 00067 return IDO_OK; 00068 } 00069 00070 /* see if the object already exists in cached lookup table */ 00071 if (ido2db_get_cached_object_id(idi, object_type, name1, name2, &cached_object_id) == IDO_OK) { 00072 *object_id = cached_object_id; 00073 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id(%lu) return cached object\n", *object_id); 00074 return IDO_OK; 00075 } 00076 00077 #ifdef USE_LIBDBI /* everything else will be libdbi */ 00078 00079 /* normal parts for !oracle */ 00080 00081 if (name1 == NULL) { 00082 es[0] = NULL; 00083 if (asprintf(&buf1, "name1 IS NULL") == -1) 00084 buf1 = NULL; 00085 } else { 00086 es[0] = ido2db_db_escape_string(idi, name1); 00087 switch (idi->dbinfo.server_type) { 00088 case IDO2DB_DBSERVER_DB2: 00089 break; 00090 case IDO2DB_DBSERVER_FIREBIRD: 00091 break; 00092 case IDO2DB_DBSERVER_FREETDS: 00093 break; 00094 case IDO2DB_DBSERVER_INGRES: 00095 break; 00096 case IDO2DB_DBSERVER_MSQL: 00097 break; 00098 case IDO2DB_DBSERVER_ORACLE: 00099 break; 00100 case IDO2DB_DBSERVER_SQLITE: 00101 break; 00102 case IDO2DB_DBSERVER_SQLITE3: 00103 break; 00104 default: 00105 /* William Preston: mysql does case sensitive compare 00106 * IF the collation is changed to latin1_general_cs */ 00107 /* Postgres does case sensitive compare */ 00108 if (asprintf(&buf1, "name1='%s'", es[0]) == -1) 00109 buf1 = NULL; 00110 break; 00111 } 00112 } 00113 00114 if (name2 == NULL) { 00115 es[1] = NULL; 00116 if (asprintf(&buf2, "name2 IS NULL") == -1) 00117 buf2 = NULL; 00118 } else { 00119 es[1] = ido2db_db_escape_string(idi, name2); 00120 switch (idi->dbinfo.server_type) { 00121 case IDO2DB_DBSERVER_DB2: 00122 break; 00123 case IDO2DB_DBSERVER_FIREBIRD: 00124 break; 00125 case IDO2DB_DBSERVER_FREETDS: 00126 break; 00127 case IDO2DB_DBSERVER_INGRES: 00128 break; 00129 case IDO2DB_DBSERVER_MSQL: 00130 break; 00131 case IDO2DB_DBSERVER_ORACLE: 00132 break; 00133 case IDO2DB_DBSERVER_SQLITE: 00134 break; 00135 case IDO2DB_DBSERVER_SQLITE3: 00136 break; 00137 default: 00138 /* William Preston: mysql does case sensitive compare 00139 * IF the collation is changed to latin1_general_cs */ 00140 /* Postgres does case sensitive compare */ 00141 if (asprintf(&buf2, "name2='%s'", es[1]) == -1) 00142 buf2 = NULL; 00143 break; 00144 } 00145 } 00146 00147 if (asprintf(&buf, "SELECT object_id FROM %s WHERE instance_id=%lu AND objecttype_id=%d AND %s AND %s", ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS], idi->dbinfo.instance_id, object_type, buf1, buf2) == -1) 00148 buf = NULL; 00149 00150 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 00151 if (idi->dbinfo.dbi_result != NULL) { 00152 if (dbi_result_next_row(idi->dbinfo.dbi_result)) { 00153 *object_id = dbi_result_get_uint(idi->dbinfo.dbi_result, "object_id"); 00154 } else { 00155 result = IDO_ERROR; 00156 } 00157 00158 dbi_result_free(idi->dbinfo.dbi_result); 00159 idi->dbinfo.dbi_result = NULL; 00160 } 00161 } 00162 00163 dbi_result_free(idi->dbinfo.dbi_result); 00164 00165 free(buf); 00166 free(buf1); 00167 free(buf2); 00168 00169 #endif 00170 00171 #ifdef USE_PGSQL /* pgsql */ 00172 00173 #endif 00174 00175 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00176 00177 /* check if we lost connection, and reconnect */ 00178 if(ido2db_db_reconnect(idi)==IDO_ERROR) 00179 return IDO_ERROR; 00180 00181 /* above code for other rdbms is real bullshit and not even modular for prepared statements ... */ 00182 /* ......... db.c ......... */ 00183 /* ok we have prepared 4 queries - now for the fun part */ 00184 /* if name1/2 is NULL, the prepared statement will already now about that, and the value does not get binded */ 00185 00186 if(name1 != NULL && name2 != NULL) { 00187 00188 es[0] = ido2db_db_escape_string(idi, name1); 00189 es[1] = ido2db_db_escape_string(idi, name2); 00190 00191 data[0] = (void *) &idi->dbinfo.instance_id; 00192 data[1] = (void *) &object_type; 00193 data[2] = (void *) &es[0]; 00194 data[3] = (void *) &es[1]; 00195 00196 00197 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_select_name1_name2, MT(":X1"), (big_uint *) data[0])) { 00198 return IDO_ERROR; 00199 } 00200 if(!OCI_BindInt(idi->dbinfo.oci_statement_objects_select_name1_name2, MT(":X2"), (int *) data[1])) { 00201 return IDO_ERROR; 00202 } 00203 if(!OCI_BindString(idi->dbinfo.oci_statement_objects_select_name1_name2, MT(":X3"), *(char **) data[2], 0)) { 00204 return IDO_ERROR; 00205 } 00206 if(!OCI_BindString(idi->dbinfo.oci_statement_objects_select_name1_name2, MT(":X4"), *(char **) data[3], 0)) { 00207 return IDO_ERROR; 00208 } 00209 00210 /* execute statement */ 00211 if(!OCI_Execute(idi->dbinfo.oci_statement_objects_select_name1_name2)) { 00212 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_name2() execute error\n"); 00213 return IDO_ERROR; 00214 } 00215 00216 OCI_Commit(idi->dbinfo.oci_connection); 00217 00218 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_objects_select_name1_name2); 00219 00220 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 00221 *object_id = OCI_GetUnsignedInt2(idi->dbinfo.oci_resultset, MT("id")); 00222 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_name2(%lu) insert_id\n", *object_id); 00223 } else { 00224 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_name2() insert_id could not be fetched\n"); 00225 result = IDO_ERROR; 00226 } 00227 00228 /* do not free statement yet! */ 00229 00230 } 00231 else if(name1 == NULL && name2 != NULL) { 00232 00233 es[0] = NULL; 00234 es[1] = ido2db_db_escape_string(idi, name2); 00235 00236 data[0] = (void *) &idi->dbinfo.instance_id; 00237 data[1] = (void *) &object_type; 00238 data[2] = (void *) &es[1]; 00239 00240 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_select_name1_null_name2, MT(":X1"), (big_uint *) data[0])) { 00241 return IDO_ERROR; 00242 } 00243 if(!OCI_BindInt(idi->dbinfo.oci_statement_objects_select_name1_null_name2, MT(":X2"), (int *) data[1])) { 00244 return IDO_ERROR; 00245 } 00246 if(!OCI_BindString(idi->dbinfo.oci_statement_objects_select_name1_null_name2, MT(":X3"), *(char **) data[2], 0)) { 00247 return IDO_ERROR; 00248 } 00249 00250 /* execute statement */ 00251 if(!OCI_Execute(idi->dbinfo.oci_statement_objects_select_name1_null_name2)) { 00252 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_null_name2() execute error\n"); 00253 return IDO_ERROR; 00254 } 00255 00256 OCI_Commit(idi->dbinfo.oci_connection); 00257 00258 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_objects_select_name1_null_name2); 00259 00260 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 00261 *object_id = OCI_GetUnsignedInt2(idi->dbinfo.oci_resultset, MT("id")); 00262 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_null_name2(%lu) insert_id\n", *object_id); 00263 } else { 00264 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_null_name2() insert_id could not be fetched\n"); 00265 result = IDO_ERROR; 00266 } 00267 00268 00269 /* do not free statement yet! */ 00270 00271 } 00272 else if(name1 !=NULL && name2 == NULL) { 00273 00274 es[0] = ido2db_db_escape_string(idi, name1); 00275 es[1] = NULL; 00276 00277 data[0] = (void *) &idi->dbinfo.instance_id; 00278 data[1] = (void *) &object_type; 00279 data[2] = (void *) &es[0]; 00280 00281 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_select_name1_name2_null, MT(":X1"), (big_uint *) data[0])) { 00282 return IDO_ERROR; 00283 } 00284 if(!OCI_BindInt(idi->dbinfo.oci_statement_objects_select_name1_name2_null, MT(":X2"), (int *) data[1])) { 00285 return IDO_ERROR; 00286 } 00287 if(!OCI_BindString(idi->dbinfo.oci_statement_objects_select_name1_name2_null, MT(":X3"), *(char **) data[2], 0)) { 00288 return IDO_ERROR; 00289 } 00290 00291 /* execute statement */ 00292 if(!OCI_Execute(idi->dbinfo.oci_statement_objects_select_name1_name2_null)) { 00293 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_name2_null() execute error\n"); 00294 return IDO_ERROR; 00295 } 00296 OCI_Commit(idi->dbinfo.oci_connection); 00297 00298 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_objects_select_name1_name2_null); 00299 00300 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 00301 *object_id = OCI_GetUnsignedInt2(idi->dbinfo.oci_resultset, MT("id")); 00302 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_name2_null(%lu) insert_id\n", *object_id); 00303 } else { 00304 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_name2_null() insert_id could not be fetched\n"); 00305 result = IDO_ERROR; 00306 } 00307 00308 00309 /* do not free statement yet! */ 00310 00311 } 00312 else if(name1 == NULL && name2 == NULL) { 00313 00314 es[0] = NULL; 00315 es[1] = NULL; 00316 00317 data[0] = (void *) &idi->dbinfo.instance_id; 00318 data[1] = (void *) &object_type; 00319 00320 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_select_name1_null_name2_null, MT(":X1"), (big_uint *) data[0])) { 00321 return IDO_ERROR; 00322 } 00323 if(!OCI_BindInt(idi->dbinfo.oci_statement_objects_select_name1_null_name2_null, MT(":X2"), (int *) data[1])) { 00324 return IDO_ERROR; 00325 } 00326 00327 /* execute statement */ 00328 if(!OCI_Execute(idi->dbinfo.oci_statement_objects_select_name1_null_name2_null)) { 00329 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_null_name2_null() execute error\n"); 00330 return IDO_ERROR; 00331 } 00332 00333 OCI_Commit(idi->dbinfo.oci_connection); 00334 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_objects_select_name1_null_name2_null); 00335 00336 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 00337 *object_id = OCI_GetUnsignedInt2(idi->dbinfo.oci_resultset, MT("id")); 00338 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_null_name2_null(%lu) insert_id\n", *object_id); 00339 } else { 00340 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_name1_null_name2_null() insert_id could not be fetched\n"); 00341 result = IDO_ERROR; 00342 } 00343 00344 00345 /* do not free statement yet! */ 00346 } 00347 00348 00349 #endif /* Oracle ocilib specific */ 00350 00351 /* free memory */ 00352 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_() before free\n"); 00353 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 00354 free(es[x]); 00355 00356 //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_() free of es\n"); 00357 00358 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id(%lu) end\n", *object_id); 00359 00360 return result; 00361 } 00362 00363 int ido2db_get_object_id_with_insert(ido2db_idi *idi, int object_type, char *n1, char *n2, unsigned long *object_id) { 00364 int result = IDO_OK; 00365 int x = 0; 00366 char *buf = NULL; 00367 char *buf1 = NULL; 00368 char *buf2 = NULL; 00369 #ifdef USE_LIBDBI 00370 char *tmp = NULL; 00371 #endif 00372 char *name1 = NULL; 00373 char *name2 = NULL; 00374 char *es[2]; 00375 #ifdef USE_ORACLE 00376 void *data[4]; 00377 #endif 00378 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id_with_insert() start\n"); 00379 00380 /* make sure empty strings are set to null */ 00381 name1 = n1; 00382 name2 = n2; 00383 if (name1 && !strcmp(name1, "")) 00384 name1 = NULL; 00385 if (name2 && !strcmp(name2, "")) 00386 name2 = NULL; 00387 00388 /* null names mean no object id */ 00389 if (name1 == NULL && name2 == NULL) { 00390 *object_id = 0L; 00391 return IDO_OK; 00392 } 00393 00394 /* object already exists */ 00395 if ((result = ido2db_get_object_id(idi, object_type, name1, name2, 00396 object_id)) == IDO_OK) 00397 return IDO_OK; 00398 00399 #ifdef USE_LIBDBI /* everything else will be libdbi */ 00400 if (name1 != NULL) { 00401 tmp = ido2db_db_escape_string(idi, name1); 00402 dummy=asprintf(&es[0], "'%s'", tmp); 00403 if (tmp) { 00404 free(tmp); 00405 tmp = NULL; 00406 } 00407 } else 00408 dummy=asprintf(&es[0],"NULL"); 00409 00410 if (name2 != NULL) { 00411 tmp = ido2db_db_escape_string(idi, name2); 00412 dummy=asprintf(&es[1], "'%s'", tmp); 00413 if (tmp) { 00414 free(tmp); 00415 tmp = NULL; 00416 } 00417 } else 00418 dummy=asprintf(&es[1], "NULL"); 00419 00420 if (asprintf(&buf, 00421 "INSERT INTO %s (instance_id, objecttype_id, name1, name2) VALUES (%lu, %d, %s, %s)", 00422 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS], 00423 idi->dbinfo.instance_id, object_type, es[0], 00424 es[1]) == -1) 00425 buf = NULL; 00426 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 00427 00428 switch (idi->dbinfo.server_type) { 00429 case IDO2DB_DBSERVER_MYSQL: 00430 /* mysql doesn't use sequences */ 00431 *object_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 00432 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id_with_insert(%lu) object_id\n", *object_id); 00433 break; 00434 case IDO2DB_DBSERVER_PGSQL: 00435 /* depending on tableprefix/tablename a sequence will be used */ 00436 if(asprintf(&tmp, "%s_object_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS]) == -1) 00437 tmp = NULL; 00438 00439 *object_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, tmp); 00440 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id_with_insert(%s=%lu) object_id\n", tmp, *object_id); 00441 free(tmp); 00442 break; 00443 case IDO2DB_DBSERVER_DB2: 00444 break; 00445 case IDO2DB_DBSERVER_FIREBIRD: 00446 break; 00447 case IDO2DB_DBSERVER_FREETDS: 00448 break; 00449 case IDO2DB_DBSERVER_INGRES: 00450 break; 00451 case IDO2DB_DBSERVER_MSQL: 00452 break; 00453 case IDO2DB_DBSERVER_ORACLE: 00454 break; 00455 case IDO2DB_DBSERVER_SQLITE: 00456 break; 00457 case IDO2DB_DBSERVER_SQLITE3: 00458 break; 00459 default: 00460 break; 00461 } 00462 } 00463 dbi_result_free(idi->dbinfo.dbi_result); 00464 00465 #endif 00466 00467 #ifdef USE_PGSQL /* pgsql */ 00468 00469 #endif 00470 00471 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00472 00473 /* check if we lost connection, and reconnect */ 00474 if(ido2db_db_reconnect(idi)==IDO_ERROR) 00475 return IDO_ERROR; 00476 00477 es[0] = ido2db_db_escape_string(idi, name1); 00478 es[1] = ido2db_db_escape_string(idi, name2); 00479 00480 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id_with_insert() name1=%s, name2=%s\n", es[0], es[1]); 00481 00482 #ifdef DEBUG_IDO2DB 00483 syslog(LOG_USER | LOG_INFO, "name1=%s, name2=%s\n", es[0], es[1]); 00484 #endif 00485 00486 data[0] = (void *) &idi->dbinfo.instance_id; 00487 data[1] = (void *) &object_type; 00488 data[2] = (void *) &es[0]; 00489 data[3] = (void *) &es[1]; 00490 00491 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_insert, MT(":X1"), (big_uint *) data[0])) { 00492 return IDO_ERROR; 00493 } 00494 00495 if(!OCI_BindInt(idi->dbinfo.oci_statement_objects_insert, MT(":X2"), (int *) data[1])) { 00496 return IDO_ERROR; 00497 } 00498 00499 /* check if name1/2 would be NULL, explicitely bind that to NULL so that the IS NULL from the selects match */ 00500 if(name1==NULL) { 00501 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_objects_insert, ":X3")==IDO_ERROR) { 00502 //syslog(LOG_USER | LOG_INFO, "bind null name1=%s FAIL\n", es[0]); 00503 return IDO_ERROR; 00504 } 00505 } else { 00506 //syslog(LOG_USER | LOG_INFO, "bind value name1=%s\n", es[0]); 00507 if(!OCI_BindString(idi->dbinfo.oci_statement_objects_insert, MT(":X3"), *(char **) data[2], 0)) { 00508 return IDO_ERROR; 00509 } 00510 } 00511 00512 if(name2==NULL) { 00513 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_objects_insert, ":X4")==IDO_ERROR) { 00514 //syslog(LOG_USER | LOG_INFO, "bind null name2=%s FAIL\n", es[1]); 00515 return IDO_ERROR; 00516 } 00517 } else { 00518 //syslog(LOG_USER | LOG_INFO, "bind value name2=%s\n", es[1]); 00519 if(!OCI_BindString(idi->dbinfo.oci_statement_objects_insert, MT(":X4"), *(char **) data[3], 0)) { 00520 return IDO_ERROR; 00521 } 00522 } 00523 00524 00525 /* execute statement */ 00526 if(!OCI_Execute(idi->dbinfo.oci_statement_objects_insert)) { 00527 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_insert() execute error\n"); 00528 return IDO_ERROR; 00529 } 00530 00531 OCI_Commit(idi->dbinfo.oci_connection); 00532 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_objects_insert); 00533 00534 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 00535 *object_id = OCI_GetInt(idi->dbinfo.oci_resultset, 1); 00536 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_insert(%lu) insert_id\n", *object_id); 00537 } else { 00538 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_insert() insert_id could not be fetched\n"); 00539 } 00540 00541 00542 /* do not free statement yet! */ 00543 00544 #endif /* Oracle ocilib specific */ 00545 00546 free(buf); 00547 00548 /* cache object id for later lookups */ 00549 ido2db_add_cached_object_id(idi, object_type, name1, name2, *object_id); 00550 00551 /* free memory */ 00552 free(buf1); 00553 free(buf2); 00554 00555 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 00556 free(es[x]); 00557 00558 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_object_id_with_insert(%lu) end\n", *object_id); 00559 00560 return result; 00561 } 00562 00563 int ido2db_get_cached_object_ids(ido2db_idi *idi) { 00564 int result = IDO_OK; 00565 unsigned long object_id = 0L; 00566 int objecttype_id = 0; 00567 #ifdef USE_LIBDBI 00568 char *buf = NULL; 00569 #endif 00570 00571 #ifdef USE_ORACLE 00572 char *tmp1 = NULL; 00573 char *tmp2 = NULL; 00574 void *data[1]; 00575 #endif 00576 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_cached_object_ids() start\n"); 00577 00578 /* find all the object definitions we already have */ 00579 #ifdef USE_LIBDBI /* everything else will be libdbi */ 00580 if (asprintf(&buf, "SELECT object_id, objecttype_id, name1, name2 FROM %s WHERE instance_id='%lu'", ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS], idi->dbinfo.instance_id) == -1) 00581 buf = NULL; 00582 00583 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 00584 while (idi->dbinfo.dbi_result) { 00585 if (dbi_result_next_row(idi->dbinfo.dbi_result)) { 00586 object_id = dbi_result_get_uint(idi->dbinfo.dbi_result, 00587 "object_id"); 00588 objecttype_id = dbi_result_get_int(idi->dbinfo.dbi_result, 00589 "objecttype_id"); 00590 ido2db_add_cached_object_id(idi, objecttype_id, 00591 dbi_result_get_string_copy(idi->dbinfo.dbi_result, 00592 "name1"), dbi_result_get_string_copy( 00593 idi->dbinfo.dbi_result, "name2"), object_id); 00594 } 00595 dbi_result_free(idi->dbinfo.dbi_result); 00596 idi->dbinfo.dbi_result = NULL; 00597 } 00598 } 00599 00600 free(buf); 00601 #endif 00602 00603 #ifdef USE_PGSQL /* pgsql */ 00604 00605 #endif 00606 00607 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00608 00609 /* check if we lost connection, and reconnect */ 00610 if(ido2db_db_reconnect(idi)==IDO_ERROR) 00611 return IDO_ERROR; 00612 00613 00614 data[0] = (void *) &idi->dbinfo.instance_id; 00615 00616 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_select_cached, MT(":X1"), (big_uint *) data[0])) { 00617 return IDO_ERROR; 00618 } 00619 00620 /* execute statement */ 00621 if(!OCI_Execute(idi->dbinfo.oci_statement_objects_select_cached)) { 00622 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_select_cached() execute error\n"); 00623 return IDO_ERROR; 00624 } 00625 00626 OCI_Commit(idi->dbinfo.oci_connection); 00627 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_objects_select_cached); 00628 00629 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 00630 00631 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_cached_object_ids() fetchnext ok\n"); 00632 object_id = OCI_GetUnsignedInt2(idi->dbinfo.oci_resultset, MT("id")); 00633 objecttype_id = OCI_GetUnsignedInt2(idi->dbinfo.oci_resultset, MT("objecttype_id")); 00634 00635 /* dirty little hack for mtext* <-> char* */ 00636 if(asprintf(&tmp1, "%s", OCI_GetString2(idi->dbinfo.oci_resultset, MT("name1")))==-1) 00637 tmp1=NULL; 00638 if(asprintf(&tmp2, "%s", OCI_GetString2(idi->dbinfo.oci_resultset, MT("name2")))==-1) 00639 tmp2=NULL; 00640 00641 ido2db_add_cached_object_id(idi, objecttype_id, tmp1, tmp2, object_id); 00642 00643 } else { 00644 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_cached_object_ids() fetchnext ok\n\n"); 00645 } 00646 00647 00648 /* do not free statement yet! */ 00649 00650 free(tmp1); 00651 free(tmp2); 00652 00653 #endif /* Oracle ocilib specific */ 00654 00655 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_cached_object_ids(%lu) end\n", object_id); 00656 00657 return result; 00658 } 00659 00660 int ido2db_get_cached_object_id(ido2db_idi *idi, int object_type, char *name1, 00661 char *name2, unsigned long *object_id) { 00662 int result = IDO_ERROR; 00663 int hashslot = 0; 00664 int compare = 0; 00665 ido2db_dbobject *temp_object = NULL; 00666 int y = 0; 00667 00668 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_cached_object_id() start\n"); 00669 00670 hashslot = ido2db_object_hashfunc(name1, name2, IDO2DB_OBJECT_HASHSLOTS); 00671 #ifdef IDO2DB_DEBUG_CACHING 00672 printf("OBJECT LOOKUP: type=%d, name1=%s, name2=%s\n",object_type,(name1==NULL)?"NULL":name1,(name2==NULL)?"NULL":name2); 00673 #endif 00674 00675 if (idi->dbinfo.object_hashlist == NULL) 00676 return IDO_ERROR; 00677 00678 for (temp_object = idi->dbinfo.object_hashlist[hashslot], y = 0; temp_object 00679 != NULL; temp_object = temp_object->nexthash, y++) { 00680 #ifdef IDO2DB_DEBUG_CACHING 00681 printf("OBJECT LOOKUP LOOPING [%d][%d]: type=%d, id=%lu, name1=%s, name2=%s\n",hashslot,y,temp_object->object_type,temp_object->object_id,(temp_object->name1==NULL)?"NULL":temp_object->name1,(temp_object->name2==NULL)?"NULL":temp_object->name2); 00682 #endif 00683 compare = ido2db_compare_object_hashdata(temp_object->name1, 00684 temp_object->name2, name1, name2); 00685 if (compare == 0 && temp_object->object_type == object_type) 00686 break; 00687 } 00688 00689 /* we have a match! */ 00690 if (temp_object && (ido2db_compare_object_hashdata(temp_object->name1, 00691 temp_object->name2, name1, name2) == 0) && temp_object->object_type 00692 == object_type) { 00693 #ifdef IDO2DB_DEBUG_CACHING 00694 printf("OBJECT CACHE HIT [%d][%d]: type=%d, id=%lu, name1=%s, name2=%s\n",hashslot,y,object_type,temp_object->object_id,(name1==NULL)?"NULL":name1,(name2==NULL)?"NULL":name2); 00695 #endif 00696 *object_id = temp_object->object_id; 00697 result = IDO_OK; 00698 } 00699 #ifdef IDO2DB_DEBUG_CACHING 00700 else { 00701 printf("OBJECT CACHE MISS: type=%d, name1=%s, name2=%s\n",object_type,(name1==NULL)?"NULL":name1,(name2==NULL)?"NULL":name2); 00702 } 00703 #endif 00704 00705 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_get_cached_object_id(%lu) end\n", *object_id); 00706 00707 return result; 00708 } 00709 00710 int ido2db_add_cached_object_id(ido2db_idi *idi, int object_type, char *n1, char *n2, unsigned long object_id) { 00711 int result = IDO_OK; 00712 ido2db_dbobject *temp_object = NULL; 00713 ido2db_dbobject *lastpointer = NULL; 00714 ido2db_dbobject *new_object = NULL; 00715 int x = 0; 00716 int y = 0; 00717 int hashslot = 0; 00718 int compare = 0; 00719 char *name1 = NULL; 00720 char *name2 = NULL; 00721 00722 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_add_cached_object_id() start\n"); 00723 00724 /* make sure empty strings are set to null */ 00725 name1 = n1; 00726 name2 = n2; 00727 if (name1 && !strcmp(name1, "")) 00728 name1 = NULL; 00729 if (name2 && !strcmp(name2, "")) 00730 name2 = NULL; 00731 00732 /* null names mean no object id, so don't cache */ 00733 if (name1 == NULL && name2 == NULL) { 00734 return IDO_OK; 00735 } 00736 00737 #ifdef IDO2DB_DEBUG_CACHING 00738 printf("OBJECT CACHE ADD: type=%d, id=%lu, name1=%s, name2=%s\n",object_type,object_id,(name1==NULL)?"NULL":name1,(name2==NULL)?"NULL":name2); 00739 #endif 00740 00741 /* initialize hash list if necessary */ 00742 if (idi->dbinfo.object_hashlist == NULL) { 00743 00744 idi->dbinfo.object_hashlist = (ido2db_dbobject **) malloc( 00745 sizeof(ido2db_dbobject *) * IDO2DB_OBJECT_HASHSLOTS); 00746 if (idi->dbinfo.object_hashlist == NULL) 00747 return IDO_ERROR; 00748 00749 for (x = 0; x < IDO2DB_OBJECT_HASHSLOTS; x++) 00750 idi->dbinfo.object_hashlist[x] = NULL; 00751 } 00752 00753 /* allocate and populate new object */ 00754 if ((new_object = (ido2db_dbobject *) malloc(sizeof(ido2db_dbobject))) 00755 ==NULL) 00756 return IDO_ERROR; 00757 new_object->object_type = object_type; 00758 new_object->object_id = object_id; 00759 new_object->name1 = NULL; 00760 if (name1) 00761 new_object->name1 = strdup(name1); 00762 new_object->name2 = NULL; 00763 if (name2) 00764 new_object->name2 = strdup(name2); 00765 00766 hashslot = ido2db_object_hashfunc(new_object->name1, new_object->name2, 00767 IDO2DB_OBJECT_HASHSLOTS); 00768 00769 lastpointer = NULL; 00770 for (temp_object = idi->dbinfo.object_hashlist[hashslot], y = 0; temp_object 00771 != NULL; temp_object = temp_object->nexthash, y++) { 00772 compare = ido2db_compare_object_hashdata(temp_object->name1, 00773 temp_object->name2, new_object->name1, new_object->name2); 00774 if (compare < 0) 00775 break; 00776 lastpointer = temp_object; 00777 } 00778 00779 if (lastpointer) 00780 lastpointer->nexthash = new_object; 00781 else 00782 idi->dbinfo.object_hashlist[hashslot] = new_object; 00783 new_object->nexthash = temp_object; 00784 00785 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_add_cached_object_id() end\n"); 00786 00787 return result; 00788 } 00789 00790 int ido2db_object_hashfunc(const char *name1, const char *name2, int hashslots) { 00791 unsigned int i, result; 00792 00793 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_object_hashfunc() start\n"); 00794 00795 result = 0; 00796 if (name1) 00797 for (i = 0; i < strlen(name1); i++) 00798 result += name1[i]; 00799 00800 if (name2) 00801 for (i = 0; i < strlen(name2); i++) 00802 result += name2[i]; 00803 00804 result = result % hashslots; 00805 00806 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_object_hashfunc() end\n"); 00807 00808 return result; 00809 } 00810 00811 int ido2db_compare_object_hashdata(const char *val1a, const char *val1b, 00812 const char *val2a, const char *val2b) { 00813 int result = 0; 00814 00815 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_compare_object_hashdata() start\n"); 00816 00817 /* check first name */ 00818 if (val1a == NULL && val2a == NULL) 00819 result = 0; 00820 else if (val1a == NULL) 00821 result = 1; 00822 else if (val2a == NULL) 00823 result = -1; 00824 else 00825 result = strcmp(val1a, val2a); 00826 00827 /* check second name if necessary */ 00828 if (result == 0) { 00829 if (val1b == NULL && val2b == NULL) 00830 result = 0; 00831 else if (val1b == NULL) 00832 result = 1; 00833 else if (val2b == NULL) 00834 result = -1; 00835 else 00836 return strcmp(val1b, val2b); 00837 } 00838 00839 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_compare_object_hashdata() end\n"); 00840 00841 return result; 00842 } 00843 00844 int ido2db_free_cached_object_ids(ido2db_idi *idi) { 00845 int x = 0; 00846 ido2db_dbobject *temp_object = NULL; 00847 ido2db_dbobject *next_object = NULL; 00848 00849 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_free_cached_object_ids() start\n"); 00850 00851 if (idi == NULL) 00852 return IDO_OK; 00853 00854 if (idi->dbinfo.object_hashlist) { 00855 00856 for (x = 0; x < IDO2DB_OBJECT_HASHSLOTS; x++) { 00857 for (temp_object = idi->dbinfo.object_hashlist[x]; temp_object 00858 !=NULL; temp_object = next_object) { 00859 next_object = temp_object->nexthash; 00860 free(temp_object->name1); 00861 free(temp_object->name2); 00862 free(temp_object); 00863 } 00864 } 00865 00866 free(idi->dbinfo.object_hashlist); 00867 idi->dbinfo.object_hashlist = NULL; 00868 } 00869 00870 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_free_cached_object_ids() end\n"); 00871 00872 return IDO_OK; 00873 } 00874 00875 int ido2db_set_all_objects_as_inactive(ido2db_idi *idi) { 00876 int result = IDO_OK; 00877 #ifdef USE_LIBDBI 00878 char *buf = NULL; 00879 #endif 00880 00881 #ifdef USE_ORACLE 00882 unsigned long is_active = 0; 00883 void *data[2]; 00884 #endif 00885 00886 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_set_all_objects_as_inactive() start\n"); 00887 00888 /* mark all objects as being inactive */ 00889 #ifdef USE_LIBDBI /* everything else will be libdbi */ 00890 if (asprintf(&buf, "UPDATE %s SET is_active='0' WHERE instance_id='%lu'", 00891 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS], 00892 idi->dbinfo.instance_id) == -1) 00893 buf = NULL; 00894 00895 result = ido2db_db_query(idi, buf); 00896 00897 dbi_result_free(idi->dbinfo.dbi_result); 00898 free(buf); 00899 00900 #endif 00901 00902 #ifdef USE_PGSQL /* pgsql */ 00903 00904 #endif 00905 00906 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00907 00908 data[0] = (void *) &is_active; 00909 data[1] = (void *) &idi->dbinfo.instance_id; 00910 00911 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_update_inactive, MT(":X1"), (big_uint *) data[0])) { 00912 return IDO_ERROR; 00913 } 00914 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_update_inactive, MT(":X2"), (big_uint *) data[1])) { 00915 return IDO_ERROR; 00916 } 00917 00918 /* execute statement */ 00919 if(!OCI_Execute(idi->dbinfo.oci_statement_objects_update_inactive)) { 00920 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_update_inactive() execute error\n"); 00921 return IDO_ERROR; 00922 } 00923 00924 /* commit statement */ 00925 OCI_Commit(idi->dbinfo.oci_connection); 00926 00927 /* do not free statement yet! */ 00928 00929 #endif /* Oracle ocilib specific */ 00930 00931 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_set_all_objects_as_inactive() end\n"); 00932 00933 return result; 00934 } 00935 00936 int ido2db_set_object_as_active(ido2db_idi *idi, int object_type, 00937 unsigned long object_id) { 00938 int result = IDO_OK; 00939 #ifdef USE_LIBDBI 00940 char *buf = NULL; 00941 #endif 00942 00943 #ifdef USE_ORACLE 00944 unsigned long is_active = 1; 00945 void *data[4]; 00946 #endif 00947 00948 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_set_object_as_active() start\n"); 00949 00950 /* mark the object as being active */ 00951 #ifdef USE_LIBDBI /* everything else will be libdbi */ 00952 if (asprintf( 00953 &buf, 00954 "UPDATE %s SET is_active='1' WHERE instance_id='%lu' AND objecttype_id='%d' AND object_id='%lu'", 00955 ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS], 00956 idi->dbinfo.instance_id, object_type, object_id) == -1) 00957 buf = NULL; 00958 00959 result = ido2db_db_query(idi, buf); 00960 00961 dbi_result_free(idi->dbinfo.dbi_result); 00962 free(buf); 00963 00964 #endif 00965 00966 #ifdef USE_PGSQL /* pgsql */ 00967 00968 #endif 00969 00970 #ifdef USE_ORACLE /* Oracle ocilib specific */ 00971 00972 /* check if we lost connection, and reconnect */ 00973 if(ido2db_db_reconnect(idi)==IDO_ERROR) 00974 return IDO_ERROR; 00975 00976 data[0] = (void *) &is_active; 00977 data[1] = (void *) &idi->dbinfo.instance_id; 00978 data[2] = (void *) &object_type; 00979 data[3] = (void *) &object_id; 00980 00981 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_update_active, MT(":X1"), (big_uint *) data[0])) { 00982 return IDO_ERROR; 00983 } 00984 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_update_active, MT(":X2"), (big_uint *) data[1])) { 00985 return IDO_ERROR; 00986 } 00987 if(!OCI_BindInt(idi->dbinfo.oci_statement_objects_update_active, MT(":X3"), (int *) data[2])) { 00988 return IDO_ERROR; 00989 } 00990 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_objects_update_active, MT(":X4"), (big_uint *) data[3])) { 00991 return IDO_ERROR; 00992 } 00993 00994 /* execute statement */ 00995 if(!OCI_Execute(idi->dbinfo.oci_statement_objects_update_active)) { 00996 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_objects_update_active() execute error\n"); 00997 return IDO_ERROR; 00998 } 00999 01000 /* commit statement */ 01001 OCI_Commit(idi->dbinfo.oci_connection); 01002 01003 /* do not free statement yet! */ 01004 01005 #endif /* Oracle ocilib specific */ 01006 01007 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_set_object_as_active() end\n"); 01008 01009 return result; 01010 } 01011 01012 /****************************************************************************/ 01013 /* ARCHIVED LOG DATA HANDLER */ 01014 /****************************************************************************/ 01015 01016 int ido2db_handle_logentry(ido2db_idi *idi) { 01017 char *ptr = NULL; 01018 char *buf = NULL; 01019 char *es[1]; 01020 time_t etime = 0L; 01021 char *ts[1]; 01022 unsigned long type = 0L; 01023 int result = IDO_OK; 01024 int duplicate_record = IDO_FALSE; 01025 int len = 0; 01026 int x = 0; 01027 01028 #ifdef USE_ORACLE 01029 int n_zero = 0; 01030 void *data[8]; 01031 #endif 01032 01033 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logentry() start\n"); 01034 01035 if (idi == NULL) 01036 return IDO_ERROR; 01037 01038 /* break log entry in pieces */ 01039 if ((ptr = strtok(idi->buffered_input[IDO_DATA_LOGENTRY], "]")) == NULL) 01040 return IDO_ERROR; 01041 if ((ido2db_convert_string_to_unsignedlong(ptr + 1, 01042 (unsigned long *) &etime)) == IDO_ERROR) 01043 return IDO_ERROR; 01044 ts[0] = ido2db_db_timet_to_sql(idi, etime); 01045 if ((ptr = strtok(NULL, "\x0")) == NULL) 01046 return IDO_ERROR; 01047 es[0] = ido2db_db_escape_string(idi, (ptr + 1)); 01048 01049 /* strip newline chars from end */ 01050 len = strlen(es[0]); 01051 for (x = len - 1; x >= 0; x--) { 01052 if (es[0][x] == '\n') 01053 es[0][x] = '\x0'; 01054 else 01055 break; 01056 } 01057 01058 /* what type of log entry is this? */ 01059 type = 0; 01060 01061 /* make sure we aren't importing a duplicate log entry... */ 01062 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01063 01064 if (asprintf(&buf, "SELECT logentry_id FROM %s WHERE instance_id='%lu' AND logentry_time=%s AND logentry_data='%s'", ido2db_db_tablenames[IDO2DB_DBTABLE_LOGENTRIES], idi->dbinfo.instance_id, ts[0], es[0]) == -1) 01065 buf = NULL; 01066 01067 if ((result = ido2db_db_query(idi, buf)) == IDO_OK) { 01068 if (idi->dbinfo.dbi_result != NULL) { 01069 if (dbi_result_next_row(idi->dbinfo.dbi_result) != 0) 01070 duplicate_record = IDO_TRUE; 01071 } 01072 } 01073 01074 dbi_result_free(idi->dbinfo.dbi_result); 01075 free(buf); 01076 01077 #endif 01078 01079 #ifdef USE_PGSQL /* pgsql */ 01080 01081 #endif 01082 01083 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01084 01085 /* check if we lost connection, and reconnect */ 01086 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01087 return IDO_ERROR; 01088 01089 data[0] = (void *) &idi->dbinfo.instance_id; 01090 data[1] = (void *) &etime; 01091 data[2] = (void *) &es[0]; 01092 01093 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_select, MT(":X1"), (big_uint *) data[0])) { 01094 return IDO_ERROR; 01095 } 01096 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_select, MT(":X2"), (big_uint *) data[1])) { /* unixtimestamp instead of time2sql */ 01097 return IDO_ERROR; 01098 } 01099 if(!OCI_BindString(idi->dbinfo.oci_statement_logentries_select, MT(":X3"), *(char **) data[2], 0)) { 01100 return IDO_ERROR; 01101 } 01102 01103 /* execute statement */ 01104 if(!OCI_Execute(idi->dbinfo.oci_statement_logentries_select)) { 01105 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_() execute error\n"); 01106 return IDO_ERROR; 01107 } 01108 01109 OCI_Commit(idi->dbinfo.oci_connection); 01110 idi->dbinfo.oci_resultset = OCI_GetResultset(idi->dbinfo.oci_statement_logentries_select); 01111 01112 if(OCI_FetchNext(idi->dbinfo.oci_resultset)) { 01113 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logentry() fetchnext ok\n"); 01114 duplicate_record = IDO_TRUE; 01115 } else { 01116 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logentry() fetchnext not ok\n"); 01117 } 01118 01119 01120 /* do not free statement yet! */ 01121 01122 #endif /* Oracle ocilib specific */ 01123 01124 01125 /*if(duplicate_record==IDO_TRUE && idi->last_logentry_time!=etime){*/ 01126 /*if(duplicate_record==IDO_TRUE && strcmp((es[0]==NULL)?"":es[0],idi->dbinfo.last_logentry_data)){*/ 01127 if (duplicate_record == IDO_TRUE) { 01128 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logentry() ignoring duplicate log record\n"); 01129 #ifdef IDO2DB_DEBUG 01130 printf("IGNORING DUPLICATE LOG RECORD!\n"); 01131 #endif 01132 return IDO_OK; 01133 } 01134 01135 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01136 /* save entry to db */ 01137 if (asprintf( 01138 &buf, 01139 "INSERT INTO %s (instance_id, logentry_time, entry_time, entry_time_usec, logentry_type, logentry_data, realtime_data, inferred_data_extracted) VALUES ('%lu', %s, %s, '0', '%lu', '%s', '0', '0')", 01140 ido2db_db_tablenames[IDO2DB_DBTABLE_LOGENTRIES], 01141 idi->dbinfo.instance_id, ts[0], ts[0], type, (es[0] == NULL) ? "" 01142 : es[0]) == -1) 01143 buf = NULL; 01144 result = ido2db_db_query(idi, buf); 01145 01146 dbi_result_free(idi->dbinfo.dbi_result); 01147 #endif 01148 01149 #ifdef USE_PGSQL /* pgsql */ 01150 01151 #endif 01152 01153 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01154 01155 /* check if we lost connection, and reconnect */ 01156 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01157 return IDO_ERROR; 01158 01159 /* set only values needed */ 01160 n_zero = 0; 01161 01162 data[0] = (void *) &idi->dbinfo.instance_id; 01163 data[1] = (void *) &etime; 01164 data[2] = (void *) &etime; 01165 data[3] = (void *) &n_zero; 01166 data[4] = (void *) &type; 01167 data[5] = (void *) &es[0]; 01168 data[6] = (void *) &n_zero; 01169 data[7] = (void *) &n_zero; 01170 01171 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X1"), (big_uint *) data[0])) { 01172 return IDO_ERROR; 01173 } 01174 if(!OCI_BindString(idi->dbinfo.oci_statement_logentries_insert, MT(":X2"), *(char **) data[1], 0)) { 01175 return IDO_ERROR; 01176 } 01177 if(!OCI_BindString(idi->dbinfo.oci_statement_logentries_insert, MT(":X3"), *(char **) data[2], 0)) { 01178 return IDO_ERROR; 01179 } 01180 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X4"), (big_uint *) data[3])) { 01181 return IDO_ERROR; 01182 } 01183 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X5"), (big_uint *) data[4])) { 01184 return IDO_ERROR; 01185 } 01186 01187 if(es[0]==NULL) { 01188 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_logentries_insert, ":X6")==IDO_ERROR) { 01189 return IDO_ERROR; 01190 } 01191 } else { 01192 if(!OCI_BindString(idi->dbinfo.oci_statement_logentries_insert, MT(":X6"), *(char **) data[5], 0)) { 01193 return IDO_ERROR; 01194 } 01195 } 01196 01197 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X7"), (big_uint *) data[6])) { 01198 return IDO_ERROR; 01199 } 01200 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X8"), (big_uint *) data[7])) { 01201 return IDO_ERROR; 01202 } 01203 01204 /* execute statement */ 01205 if(!OCI_Execute(idi->dbinfo.oci_statement_logentries_insert)) { 01206 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_logentries_insert() execute error\n"); 01207 return IDO_ERROR; 01208 } 01209 01210 /* commit statement */ 01211 OCI_Commit(idi->dbinfo.oci_connection); 01212 01213 /* do not free statement yet! */ 01214 01215 #endif /* Oracle ocilib specific */ 01216 01217 free(buf); 01218 01219 /* record timestamp of last log entry */ 01220 idi->dbinfo.last_logentry_time = etime; 01221 01222 /* save last log entry (for detecting duplicates) */ 01223 if (idi->dbinfo.last_logentry_data) 01224 free(idi->dbinfo.last_logentry_data); 01225 idi->dbinfo.last_logentry_data = strdup((es[0] == NULL) ? "" : es[0]); 01226 01227 /* free memory */ 01228 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) { 01229 free(es[x]); 01230 } 01231 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 01232 free(ts[x]); 01233 01234 /* TODO - further processing of log entry to expand archived data... */ 01235 01236 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logentry() end\n"); 01237 01238 return result; 01239 } 01240 01241 /****************************************************************************/ 01242 /* REALTIME DATA HANDLERS */ 01243 /****************************************************************************/ 01244 01245 int ido2db_handle_processdata(ido2db_idi *idi) { 01246 int type, flags, attr; 01247 struct timeval tstamp; 01248 unsigned long process_id; 01249 int result = IDO_OK; 01250 char *ts[1]; 01251 char *es[3]; 01252 int x = 0; 01253 char *buf = NULL; 01254 #ifdef USE_ORACLE 01255 void *data[8]; 01256 unsigned long is_currently_running = 0; 01257 #endif 01258 01259 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_processdata() start\n"); 01260 01261 if (idi == NULL) 01262 return IDO_ERROR; 01263 01264 /* convert timestamp, etc */ 01265 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 01266 &tstamp); 01267 01268 /* convert vars */ 01269 result = ido2db_convert_string_to_unsignedlong( 01270 idi->buffered_input[IDO_DATA_PROCESSID], &process_id); 01271 01272 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 01273 01274 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_PROGRAMNAME]); 01275 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_PROGRAMVERSION]); 01276 es[2] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_PROGRAMDATE]); 01277 01278 /* save entry to db */ 01279 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01280 if (asprintf(&buf, "INSERT INTO %s (instance_id, event_type, event_time, event_time_usec, process_id, program_name, program_version, program_date) VALUES ('%lu', '%d', %s, '%lu', '%lu', '%s', '%s', '%s')", 01281 ido2db_db_tablenames[IDO2DB_DBTABLE_PROCESSEVENTS], 01282 idi->dbinfo.instance_id, type, ts[0], tstamp.tv_usec, process_id, 01283 es[0], es[1], es[2]) == -1) 01284 buf = NULL; 01285 result = ido2db_db_query(idi, buf); 01286 01287 dbi_result_free(idi->dbinfo.dbi_result); 01288 #endif 01289 01290 #ifdef USE_PGSQL /* pgsql */ 01291 01292 #endif 01293 01294 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01295 01296 /* check if we lost connection, and reconnect */ 01297 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01298 return IDO_ERROR; 01299 01300 data[0] = (void *) &idi->dbinfo.instance_id; 01301 data[1] = (void *) &type; 01302 data[2] = (void *) &tstamp.tv_sec; 01303 data[3] = (void *) &tstamp.tv_usec; 01304 data[4] = (void *) &process_id; 01305 data[5] = (void *) &es[0]; 01306 data[6] = (void *) &es[1]; 01307 data[7] = (void *) &es[2]; 01308 01309 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_process_events, MT(":X1"), (big_uint *) data[0])) { 01310 return IDO_ERROR; 01311 } 01312 if(!OCI_BindInt(idi->dbinfo.oci_statement_process_events, MT(":X2"), (int *) data[1])) { 01313 return IDO_ERROR; 01314 } 01315 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_process_events, MT(":X3"), (big_uint *) data[2])) { /* unixtimestamp instead of time2sql */ 01316 return IDO_ERROR; 01317 } 01318 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_process_events, MT(":X4"), (big_uint *) data[3])) { 01319 return IDO_ERROR; 01320 } 01321 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_process_events, MT(":X5"), (big_uint *) data[4])) { 01322 return IDO_ERROR; 01323 } 01324 if(!OCI_BindString(idi->dbinfo.oci_statement_process_events, MT(":X6"), *(char **) data[5], 0)) { 01325 return IDO_ERROR; 01326 } 01327 if(!OCI_BindString(idi->dbinfo.oci_statement_process_events, MT(":X7"), *(char **) data[6], 0)) { 01328 return IDO_ERROR; 01329 } 01330 if(!OCI_BindString(idi->dbinfo.oci_statement_process_events, MT(":X8"), *(char **) data[7], 0)) { 01331 return IDO_ERROR; 01332 } 01333 01334 /* execute statement */ 01335 if(!OCI_Execute(idi->dbinfo.oci_statement_process_events)) { 01336 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_process_events() execute error\n"); 01337 return IDO_ERROR; 01338 } 01339 01340 /* commit statement */ 01341 OCI_Commit(idi->dbinfo.oci_connection); 01342 01343 /* do not free statement yet! */ 01344 01345 #endif /* Oracle ocilib specific */ 01346 01347 free(buf); 01348 01349 /* MORE PROCESSING.... */ 01350 01351 /* if process is starting up, clearstatus data, event queue, etc. */ 01352 if (type == NEBTYPE_PROCESS_PRELAUNCH && tstamp.tv_sec >= idi->dbinfo.latest_realtime_data_time) { 01353 01354 if(ido2db_db_settings.clean_realtime_tables_on_core_startup==IDO_TRUE){ /* only if desired */ 01355 01356 /* clear realtime data */ 01357 /* don't clear necessary status tables on restart/reload of the core, as Icinga Web 01358 won't show any data then */ 01359 /* ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTSTATUS]); */ 01360 /* ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICESTATUS]); */ 01361 /* ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME]); */ 01362 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS]); 01363 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTSTATUS]); 01364 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE]); 01365 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS]); 01366 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_RUNTIMEVARIABLES]); 01367 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS]); 01368 } 01369 01370 if(ido2db_db_settings.clean_config_tables_on_core_startup==IDO_TRUE){ /* only if desired */ 01371 /* clear config data */ 01372 01373 /* host definition */ 01374 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTS]); /* IDO2DB_OBJECTTYPE_HOST */ 01375 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTPARENTHOSTS]); 01376 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTGROUPS]); 01377 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTS]); 01378 01379 /* hostgroup definition */ 01380 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPS]); /* IDO2DB_OBJECTTYPE_HOSTGROUP */ 01381 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPMEMBERS]); 01382 01383 01384 /* service definition */ 01385 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICES]); /* IDO2DB_OBJECTTYPE_SERVICE */ 01386 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTGROUPS]); 01387 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTS]); 01388 01389 /* servicegroup definition */ 01390 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPS]); /* IDO2DB_OBJECTTYPE_SERVICEGROUP */ 01391 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPMEMBERS]); 01392 01393 /* hostdependency definition */ 01394 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTDEPENDENCIES]); 01395 01396 /* servicedependency definition */ 01397 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEDEPENDENCIES]); 01398 01399 /* hostescalation definition */ 01400 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONS]); 01401 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTGROUPS]); 01402 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTS]); 01403 01404 /* serviceescalation definition */ 01405 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONS]); 01406 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTGROUPS]); 01407 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTS]); 01408 01409 /* command definition */ 01410 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_COMMANDS]); /* IDO2DB_OBJECTTYPE_COMMAND */ 01411 01412 /* timeperiod definition */ 01413 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODS]); /* IDO2DB_OBJECTTYPE_TIMEPERIOD */ 01414 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODTIMERANGES]); 01415 01416 /* contact definition */ 01417 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTS]); /* IDO2DB_OBJECTTYPE_CONTACT */ 01418 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTADDRESSES]); 01419 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS]); /* both host and service */ 01420 01421 /* contactgroup definition */ 01422 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPS]); /* IDO2DB_OBJECTTYPE_CONTACTGROUP */ 01423 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPMEMBERS]); 01424 01425 /* configfile definition */ 01426 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILES]); 01427 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILEVARIABLES]); 01428 01429 /* customvariable definition */ 01430 ido2db_db_clear_table(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLES]); 01431 01432 01433 } 01434 01435 /* flag all objects as being inactive */ 01436 /* if the core starts up, the fresh config is being pushed 01437 into ido2db, marking actual config object ids as active. */ 01438 ido2db_set_all_objects_as_inactive(idi); 01439 } 01440 01441 /* if process is shutting down or restarting, update process status data */ 01442 if ((type == NEBTYPE_PROCESS_SHUTDOWN || type == NEBTYPE_PROCESS_RESTART) 01443 && tstamp.tv_sec >= idi->dbinfo.latest_realtime_data_time) { 01444 01445 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01446 if (asprintf(&buf, "UPDATE %s SET program_end_time=%s, is_currently_running='0' WHERE instance_id='%lu'", 01447 ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS], ts[0], 01448 idi->dbinfo.instance_id) == -1) 01449 buf = NULL; 01450 result = ido2db_db_query(idi, buf); 01451 dbi_result_free(idi->dbinfo.dbi_result); 01452 free(buf); 01453 01454 #endif 01455 01456 #ifdef USE_PGSQL /* pgsql */ 01457 01458 #endif 01459 01460 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01461 01462 /* check if we lost connection, and reconnect */ 01463 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01464 return IDO_ERROR; 01465 01466 data[0] = (void *) &tstamp.tv_sec; 01467 data[1] = (void *) &is_currently_running; 01468 data[2] = (void *) &idi->dbinfo.instance_id; 01469 01470 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus_update, MT(":X1"), (big_uint *) data[0])) { /* unixtimestamp instead of time2sql */ 01471 return IDO_ERROR; 01472 } 01473 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus_update, MT(":X2"), (big_uint *) data[1])) { 01474 return IDO_ERROR; 01475 } 01476 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus_update, MT(":X3"), (big_uint *) data[2])) { 01477 return IDO_ERROR; 01478 } 01479 01480 /* execute statement */ 01481 if(!OCI_Execute(idi->dbinfo.oci_statement_programstatus_update)) { 01482 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_programstatus_update() execute error\n"); 01483 return IDO_ERROR; 01484 } 01485 01486 /* commit statement */ 01487 OCI_Commit(idi->dbinfo.oci_connection); 01488 01489 /* do not free statement yet! */ 01490 01491 01492 #endif /* Oracle ocilib specific */ 01493 01494 } 01495 01496 /* free memory */ 01497 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 01498 free(ts[x]); 01499 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 01500 free(es[x]); 01501 01502 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_processdata() end\n"); 01503 01504 return IDO_OK; 01505 } 01506 01507 int ido2db_handle_timedeventdata(ido2db_idi *idi) { 01508 int type, flags, attr; 01509 struct timeval tstamp; 01510 int event_type = 0; 01511 unsigned long run_time = 0L; 01512 int recurring_event = 0; 01513 unsigned long object_id = 0L; 01514 int result = IDO_OK; 01515 char *ts[2]; 01516 int x = 0; 01517 #ifdef USE_LIBDBI 01518 char *buf = NULL; 01519 #endif 01520 void *data[9]; 01521 01522 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_timedeventdata() start\n"); 01523 01524 if (idi == NULL) 01525 return IDO_ERROR; 01526 01527 /* convert timestamp, etc */ 01528 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 01529 &tstamp); 01530 01531 /* convert vars */ 01532 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EVENTTYPE], &event_type); 01533 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_RECURRING], &recurring_event); 01534 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_RUNTIME], &run_time); 01535 01536 /* skip sleep events.... */ 01537 if (type == NEBTYPE_TIMEDEVENT_SLEEP) { 01538 01539 /* we could do some maintenance here if we wanted.... */ 01540 return IDO_OK; 01541 } 01542 01543 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 01544 ts[1] = ido2db_db_timet_to_sql(idi, run_time); 01545 01546 /* get the object id (if applicable) */ 01547 if (event_type == EVENT_SERVICE_CHECK || (event_type == EVENT_SCHEDULED_DOWNTIME && idi->buffered_input[IDO_DATA_SERVICE] != NULL && strcmp(idi->buffered_input[IDO_DATA_SERVICE], ""))) 01548 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOST], idi->buffered_input[IDO_DATA_SERVICE], &object_id); 01549 01550 if (event_type == EVENT_HOST_CHECK || (event_type == EVENT_SCHEDULED_DOWNTIME && (idi->buffered_input[IDO_DATA_SERVICE] == NULL || !strcmp(idi->buffered_input[IDO_DATA_SERVICE], "")))) 01551 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 01552 01553 /* HISTORICAL TIMED EVENTS */ 01554 01555 /* save a record of timed events that get added */ 01556 if (type == NEBTYPE_TIMEDEVENT_ADD) { 01557 01558 data[0] = (void *) &idi->dbinfo.instance_id; 01559 data[1] = (void *) &event_type; 01560 data[2] = (void *) &ts[0]; 01561 data[3] = (void *) &tstamp.tv_usec; 01562 data[4] = (void *) &ts[1]; 01563 data[5] = (void *) &recurring_event; 01564 data[6] = (void *) &object_id; 01565 /* add unixtime for bind params */ 01566 data[7] = (void *) &tstamp.tv_sec; 01567 data[8] = (void *) &run_time; 01568 01569 01570 result = ido2db_query_insert_or_update_timedevent_add(idi, data); 01571 01572 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01573 dbi_result_free(idi->dbinfo.dbi_result); 01574 #endif 01575 01576 #ifdef USE_PGSQL /* pgsql */ 01577 01578 #endif 01579 01580 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01581 01582 /* do not free if prepared statement */ 01583 01584 #endif /* Oracle ocilib specific */ 01585 } 01586 01587 /* save a record of timed events that get executed.... */ 01588 if (type == NEBTYPE_TIMEDEVENT_EXECUTE) { 01589 01590 /* save entry to db */ 01591 data[0] = (void *) &idi->dbinfo.instance_id; 01592 data[1] = (void *) &event_type; 01593 data[2] = (void *) &ts[0]; 01594 data[3] = (void *) &tstamp.tv_usec; 01595 data[4] = (void *) &ts[1]; 01596 data[5] = (void *) &recurring_event; 01597 data[6] = (void *) &object_id; 01598 /* add unixtime for bind params */ 01599 data[7] = (void *) &tstamp.tv_sec; 01600 data[8] = (void *) &run_time; 01601 01602 result = ido2db_query_insert_or_update_timedevents_execute_add(idi, data); 01603 01604 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01605 dbi_result_free(idi->dbinfo.dbi_result); 01606 #endif 01607 01608 #ifdef USE_PGSQL /* pgsql */ 01609 01610 #endif 01611 01612 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01613 01614 /* do not free if prepared statement */ 01615 01616 #endif /* Oracle ocilib specific */ 01617 } 01618 01619 /* save a record of timed events that get removed.... */ 01620 if (type == NEBTYPE_TIMEDEVENT_REMOVE) { 01621 01622 /* save entry to db */ 01623 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01624 if (asprintf(&buf, "UPDATE %s SET deletion_time=%s, deletion_time_usec='%lu' WHERE instance_id='%lu' AND event_type='%d' AND scheduled_time=%s AND recurring_event='%d' AND object_id='%lu'", 01625 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS], ts[0], 01626 tstamp.tv_usec, idi->dbinfo.instance_id, event_type, ts[1], 01627 recurring_event, object_id) == -1) 01628 buf = NULL; 01629 01630 result = ido2db_db_query(idi, buf); 01631 01632 dbi_result_free(idi->dbinfo.dbi_result); 01633 free(buf); 01634 #endif 01635 01636 #ifdef USE_PGSQL /* pgsql */ 01637 01638 #endif 01639 01640 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01641 01642 /* check if we lost connection, and reconnect */ 01643 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01644 return IDO_ERROR; 01645 01646 data[0] = (void *) &tstamp.tv_sec; 01647 data[1] = (void *) &tstamp.tv_usec; 01648 data[2] = (void *) &idi->dbinfo.instance_id; 01649 data[3] = (void *) &event_type; 01650 data[4] = (void *) &run_time; 01651 data[5] = (void *) &recurring_event; 01652 data[6] = (void *) &object_id; 01653 01654 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_update, MT(":X1"), (big_uint *) data[0])) { /* unixtimestamp instead of time2sql */ 01655 return IDO_ERROR; 01656 } 01657 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_update, MT(":X2"), (big_uint *) data[1])) { 01658 return IDO_ERROR; 01659 } 01660 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_update, MT(":X3"), (big_uint *) data[2])) { 01661 return IDO_ERROR; 01662 } 01663 if(!OCI_BindInt(idi->dbinfo.oci_statement_timedevents_update, MT(":X4"), (int *) data[3])) { 01664 return IDO_ERROR; 01665 } 01666 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_update, MT(":X5"), (big_uint *) data[4])) { /* unixtimestamp instead of time2sql */ 01667 return IDO_ERROR; 01668 } 01669 if(!OCI_BindInt(idi->dbinfo.oci_statement_timedevents_update, MT(":X6"), (int *) data[5])) { 01670 return IDO_ERROR; 01671 } 01672 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_update, MT(":X7"), (big_uint *) data[6])) { 01673 return IDO_ERROR; 01674 } 01675 01676 /* execute statement */ 01677 if(!OCI_Execute(idi->dbinfo.oci_statement_timedevents_update)) { 01678 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_timedevents_update() execute error\n"); 01679 return IDO_ERROR; 01680 } 01681 01682 /* commit statement */ 01683 OCI_Commit(idi->dbinfo.oci_connection); 01684 01685 /* do not free statement yet! */ 01686 01687 01688 #endif /* Oracle ocilib specific */ 01689 01690 } 01691 01692 /* CURRENT TIMED EVENTS */ 01693 01694 /* remove (probably) expired events from the queue if client just connected */ 01695 if (idi->dbinfo.clean_event_queue == IDO_TRUE && tstamp.tv_sec >= idi->dbinfo.latest_realtime_data_time) { 01696 01697 idi->dbinfo.clean_event_queue = IDO_FALSE; 01698 01699 /* clear old entries from db */ 01700 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01701 01702 if (asprintf(&buf, "DELETE FROM %s WHERE instance_id='%lu' AND scheduled_time<=%s", 01703 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE], 01704 idi->dbinfo.instance_id, ts[0]) == -1) 01705 buf = NULL; 01706 result = ido2db_db_query(idi, buf); 01707 01708 dbi_result_free(idi->dbinfo.dbi_result); 01709 free(buf); 01710 #endif 01711 01712 #ifdef USE_PGSQL /* pgsql */ 01713 01714 #endif 01715 01716 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01717 01718 /* check if we lost connection, and reconnect */ 01719 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01720 return IDO_ERROR; 01721 01722 data[0] = (void *) &idi->dbinfo.instance_id; 01723 data[1] = (void *) &tstamp.tv_sec; 01724 01725 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue_delete, MT(":X1"), (big_uint *) data[0])) { 01726 return IDO_ERROR; 01727 } 01728 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue_delete, MT(":X2"), (big_uint *) data[1])) { /* unixtimestamp instead of time2sql */ 01729 return IDO_ERROR; 01730 } 01731 01732 /* execute statement */ 01733 if(!OCI_Execute(idi->dbinfo.oci_statement_timedeventqueue_delete)) { 01734 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_timedeventqueue_delete() execute error\n"); 01735 return IDO_ERROR; 01736 } 01737 01738 /* commit statement */ 01739 OCI_Commit(idi->dbinfo.oci_connection); 01740 01741 /* do not free statement yet! */ 01742 01743 01744 #endif /* Oracle ocilib specific */ 01745 01746 } 01747 01748 /* ADD QUEUED TIMED EVENTS */ 01749 if (type == NEBTYPE_TIMEDEVENT_ADD && tstamp.tv_sec >= idi->dbinfo.latest_realtime_data_time) { 01750 01751 /* save entry to db by update or insert */ 01752 data[0] = (void *) &idi->dbinfo.instance_id; 01753 data[1] = (void *) &event_type; 01754 data[2] = (void *) &ts[0]; 01755 data[3] = (void *) &tstamp.tv_usec; 01756 data[4] = (void *) &ts[1]; 01757 data[5] = (void *) &recurring_event; 01758 data[6] = (void *) &object_id; 01759 /* add unixtime for bind params */ 01760 data[7] = (void *) &tstamp.tv_sec; 01761 data[8] = (void *) &run_time; 01762 01763 01764 result = ido2db_query_insert_or_update_timedeventqueue_add(idi, data); 01765 01766 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01767 dbi_result_free(idi->dbinfo.dbi_result); 01768 #endif 01769 01770 #ifdef USE_PGSQL /* pgsql */ 01771 01772 #endif 01773 01774 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01775 01776 /* do not free if prepared statement */ 01777 01778 #endif /* Oracle ocilib specific */ 01779 } 01780 01781 /* REMOVE QUEUED TIMED EVENTS */ 01782 if ((type == NEBTYPE_TIMEDEVENT_REMOVE || type 01783 == NEBTYPE_TIMEDEVENT_EXECUTE) && tstamp.tv_sec 01784 >= idi->dbinfo.latest_realtime_data_time) { 01785 01786 /* clear entry from db */ 01787 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01788 01789 if (asprintf(&buf, "DELETE FROM %s WHERE instance_id='%lu' AND event_type='%d' AND scheduled_time=%s AND recurring_event='%d' AND object_id='%lu'", 01790 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE], 01791 idi->dbinfo.instance_id, event_type, ts[1], recurring_event, 01792 object_id) == -1) 01793 buf = NULL; 01794 result = ido2db_db_query(idi, buf); 01795 01796 dbi_result_free(idi->dbinfo.dbi_result); 01797 free(buf); 01798 01799 #endif 01800 01801 #ifdef USE_PGSQL /* pgsql */ 01802 01803 #endif 01804 01805 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01806 01807 /* check if we lost connection, and reconnect */ 01808 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01809 return IDO_ERROR; 01810 01811 data[0] = (void *) &idi->dbinfo.instance_id; 01812 data[1] = (void *) &event_type; 01813 data[2] = (void *) &run_time; 01814 data[3] = (void *) &recurring_event; 01815 data[4] = (void *) &object_id; 01816 01817 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue_delete_more, MT(":X1"), (big_uint *) data[0])) { 01818 return IDO_ERROR; 01819 } 01820 if(!OCI_BindInt(idi->dbinfo.oci_statement_timedeventqueue_delete_more, MT(":X2"), (int *) data[1])) { 01821 return IDO_ERROR; 01822 } 01823 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue_delete_more, MT(":X3"), (big_uint *) data[2])) { /* unixtimestamp instead of time2sql */ 01824 return IDO_ERROR; 01825 } 01826 if(!OCI_BindInt(idi->dbinfo.oci_statement_timedeventqueue_delete_more, MT(":X4"), (int *) data[3])) { 01827 return IDO_ERROR; 01828 } 01829 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue_delete_more, MT(":X5"), (big_uint *) data[4])) { 01830 return IDO_ERROR; 01831 } 01832 01833 /* execute statement */ 01834 if(!OCI_Execute(idi->dbinfo.oci_statement_timedeventqueue_delete_more)) { 01835 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_timedeventqueue_delete_more() execute error\n"); 01836 return IDO_ERROR; 01837 } 01838 01839 /* commit statement */ 01840 OCI_Commit(idi->dbinfo.oci_connection); 01841 01842 /* do not free statement yet! */ 01843 01844 01845 #endif /* Oracle ocilib specific */ 01846 01847 /* if we are executing a low-priority event, remove older events from the queue, as we know they've already been executed */ 01848 /* THIS IS A HACK! It shouldn't be necessary, but for some reason it is... Otherwise not all events are removed from the queue. :-( */ 01849 if (type == NEBTYPE_TIMEDEVENT_EXECUTE && (event_type == EVENT_SERVICE_CHECK || event_type == EVENT_HOST_CHECK)) { 01850 01851 /* clear entries from db */ 01852 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01853 01854 if (asprintf(&buf, "DELETE FROM %s WHERE instance_id='%lu' AND scheduled_time<%s", 01855 ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE], 01856 idi->dbinfo.instance_id, ts[1]) == -1) 01857 buf = NULL; 01858 result = ido2db_db_query(idi, buf); 01859 01860 dbi_result_free(idi->dbinfo.dbi_result); 01861 free(buf); 01862 #endif 01863 01864 #ifdef USE_PGSQL /* pgsql */ 01865 01866 #endif 01867 01868 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01869 01870 /* check if we lost connection, and reconnect */ 01871 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01872 return IDO_ERROR; 01873 01874 data[0] = (void *) &idi->dbinfo.instance_id; 01875 data[1] = (void *) &run_time; 01876 01877 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue_delete, MT(":X1"), (big_uint *) data[0])) { 01878 return IDO_ERROR; 01879 } 01880 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue_delete, MT(":X2"), (big_uint *) data[1])) { /* unixtimestamp instead of time2sql */ 01881 return IDO_ERROR; 01882 } 01883 01884 /* execute statement */ 01885 if(!OCI_Execute(idi->dbinfo.oci_statement_timedeventqueue_delete)) { 01886 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_timedeventqueue_delete() execute error\n"); 01887 return IDO_ERROR; 01888 } 01889 01890 /* commit statement */ 01891 OCI_Commit(idi->dbinfo.oci_connection); 01892 01893 /* do not free statement yet! */ 01894 01895 #endif /* Oracle ocilib specific */ 01896 01897 } 01898 01899 } 01900 01901 /* free memory */ 01902 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 01903 free(ts[x]); 01904 01905 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_timedeventdata() end\n"); 01906 01907 return IDO_OK; 01908 } 01909 01910 int ido2db_handle_logdata(ido2db_idi *idi) { 01911 int type, flags, attr; 01912 struct timeval tstamp; 01913 time_t etime = 0L; 01914 unsigned long letype = 0L; 01915 int result = IDO_OK; 01916 char *ts[2]; 01917 char *es[1]; 01918 char *buf = NULL; 01919 int len = 0; 01920 int x = 0; 01921 01922 #ifdef USE_ORACLE 01923 unsigned long n_one = 1; 01924 void *data[8]; 01925 #endif 01926 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logdata() start\n"); 01927 01928 if (idi == NULL) 01929 return IDO_ERROR; 01930 01931 /* convert timestamp, etc */ 01932 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 01933 &tstamp); 01934 01935 /* convert data */ 01936 result = ido2db_convert_string_to_unsignedlong( 01937 idi->buffered_input[IDO_DATA_LOGENTRYTYPE], &letype); 01938 result = ido2db_convert_string_to_unsignedlong( 01939 idi->buffered_input[IDO_DATA_LOGENTRYTIME], 01940 (unsigned long *) &etime); 01941 01942 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 01943 ts[1] = ido2db_db_timet_to_sql(idi, etime); 01944 01945 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LOGENTRY]); 01946 01947 /* strip newline chars from end */ 01948 len = strlen(es[0]); 01949 for (x = len - 1; x >= 0; x--) { 01950 if (es[0][x] == '\n') 01951 es[0][x] = '\x0'; 01952 else 01953 break; 01954 } 01955 01956 #ifdef USE_LIBDBI /* everything else will be libdbi */ 01957 /* save entry to db */ 01958 if (asprintf(&buf, "INSERT INTO %s (instance_id, logentry_time, entry_time, entry_time_usec, logentry_type, logentry_data, realtime_data, inferred_data_extracted) VALUES ('%lu', %s, %s, '%lu', '%lu', '%s', '1', '1')", 01959 ido2db_db_tablenames[IDO2DB_DBTABLE_LOGENTRIES], 01960 idi->dbinfo.instance_id, ts[1], ts[0], tstamp.tv_usec, letype, 01961 es[0]) == -1) 01962 buf = NULL; 01963 result = ido2db_db_query(idi, buf); 01964 dbi_result_free(idi->dbinfo.dbi_result); 01965 01966 #endif 01967 01968 #ifdef USE_PGSQL /* pgsql */ 01969 01970 #endif 01971 01972 #ifdef USE_ORACLE /* Oracle ocilib specific */ 01973 01974 /* check if we lost connection, and reconnect */ 01975 if(ido2db_db_reconnect(idi)==IDO_ERROR) 01976 return IDO_ERROR; 01977 01978 data[0] = (void *) &idi->dbinfo.instance_id; 01979 data[1] = (void *) &etime; 01980 data[2] = (void *) &tstamp.tv_sec; 01981 data[3] = (void *) &tstamp.tv_usec; 01982 data[4] = (void *) &letype; 01983 data[5] = (void *) &es[0]; 01984 data[6] = (void *) &n_one; 01985 data[7] = (void *) &n_one; 01986 01987 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logdata() data array\n"); 01988 01989 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X1"), (big_uint *) data[0])) { 01990 return IDO_ERROR; 01991 } 01992 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X2"), (big_uint *) data[1])) { /* unixtimestamp instead of time2sql */ 01993 return IDO_ERROR; 01994 } 01995 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X3"), (big_uint *) data[2])) { /* unixtimestamp instead of time2sql */ 01996 return IDO_ERROR; 01997 } 01998 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X4"), (big_uint *) data[3])) { 01999 return IDO_ERROR; 02000 } 02001 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X5"), (big_uint *) data[4])) { 02002 return IDO_ERROR; 02003 } 02004 02005 if(es[0]==NULL) { 02006 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_logentries_insert, ":X6")==IDO_ERROR) { 02007 return IDO_ERROR; 02008 } 02009 } else { 02010 if(!OCI_BindString(idi->dbinfo.oci_statement_logentries_insert, MT(":X6"), *(char **) data[5], 0)) { 02011 return IDO_ERROR; 02012 } 02013 } 02014 02015 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X7"), (big_uint *) data[6])) { 02016 return IDO_ERROR; 02017 } 02018 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_logentries_insert, MT(":X8"), (big_uint *) data[7])) { 02019 return IDO_ERROR; 02020 } 02021 02022 /* execute statement */ 02023 if(!OCI_Execute(idi->dbinfo.oci_statement_logentries_insert)) { 02024 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_logentries_insert() execute error\n"); 02025 return IDO_ERROR; 02026 } 02027 02028 /* commit statement */ 02029 OCI_Commit(idi->dbinfo.oci_connection); 02030 02031 /* do not free statement yet! */ 02032 #endif /* Oracle ocilib specific */ 02033 02034 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logdata() query ok\n"); 02035 02036 free(buf); 02037 02038 /* free memory */ 02039 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 02040 free(ts[x]); 02041 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 02042 free(es[x]); 02043 02044 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_logdata() end\n"); 02045 02046 return IDO_OK; 02047 } 02048 02049 int ido2db_handle_systemcommanddata(ido2db_idi *idi) { 02050 int type, flags, attr; 02051 int x = 0; 02052 struct timeval tstamp; 02053 struct timeval start_time; 02054 struct timeval end_time; 02055 int timeout = 0; 02056 int early_timeout = 0; 02057 double execution_time = 0.0; 02058 int return_code = 0; 02059 char *ts[2]; 02060 char *es[3]; 02061 int result = IDO_OK; 02062 void *data[14]; 02063 02064 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_systemcommanddata() start\n"); 02065 02066 if (idi == NULL) 02067 return IDO_ERROR; 02068 02069 /* convert timestamp, etc */ 02070 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 02071 02072 /* covert vars */ 02073 result = ido2db_convert_string_to_int( idi->buffered_input[IDO_DATA_TIMEOUT], &timeout); 02074 result = ido2db_convert_string_to_int( idi->buffered_input[IDO_DATA_EARLYTIMEOUT], &early_timeout); 02075 result = ido2db_convert_string_to_int( idi->buffered_input[IDO_DATA_RETURNCODE], &return_code); 02076 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_EXECUTIONTIME], &execution_time); 02077 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_STARTTIME], &start_time); 02078 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_ENDTIME], &end_time); 02079 02080 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDLINE]); 02081 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_OUTPUT]); 02082 es[2] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LONGOUTPUT]); 02083 02084 ts[0] = ido2db_db_timet_to_sql(idi, start_time.tv_sec); 02085 ts[1] = ido2db_db_timet_to_sql(idi, end_time.tv_sec); 02086 02087 /* save entry to db */ 02088 data[0] = (void *) &idi->dbinfo.instance_id; 02089 data[1] = (void *) &ts[0]; 02090 data[2] = (void *) &start_time.tv_usec; 02091 data[3] = (void *) &ts[1]; 02092 data[4] = (void *) &end_time.tv_usec; 02093 data[5] = (void *) &es[0]; 02094 data[6] = (void *) &timeout; 02095 data[7] = (void *) &early_timeout; 02096 data[8] = (void *) &execution_time; 02097 data[9] = (void *) &return_code; 02098 data[10] = (void *) &es[1]; 02099 data[11] = (void *) &es[2]; 02100 /* bind params */ 02101 data[12] = (void *) &start_time.tv_sec; 02102 data[13] = (void *) &end_time.tv_sec; 02103 02104 result = ido2db_query_insert_or_update_systemcommanddata_add(idi, data); 02105 02106 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02107 dbi_result_free(idi->dbinfo.dbi_result); 02108 #endif 02109 02110 #ifdef USE_PGSQL /* pgsql */ 02111 02112 #endif 02113 02114 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02115 02116 02117 #endif /* Oracle ocilib specific */ 02118 02119 /* free memory */ 02120 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 02121 free(ts[x]); 02122 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 02123 free(es[x]); 02124 02125 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_systemcommanddata() end\n"); 02126 02127 return IDO_OK; 02128 } 02129 02130 int ido2db_handle_eventhandlerdata(ido2db_idi *idi) { 02131 int type, flags, attr; 02132 struct timeval tstamp; 02133 char *ts[2]; 02134 char *es[4]; 02135 int x = 0; 02136 int eventhandler_type = 0; 02137 int state = 0; 02138 int state_type = 0; 02139 struct timeval start_time; 02140 struct timeval end_time; 02141 int timeout = 0; 02142 int early_timeout = 0; 02143 double execution_time = 0.0; 02144 int return_code = 0; 02145 unsigned long object_id = 0L; 02146 unsigned long command_id = 0L; 02147 int result = IDO_OK; 02148 void *data[20]; 02149 02150 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_eventhandlerdata() start\n"); 02151 02152 if (idi == NULL) 02153 return IDO_ERROR; 02154 02155 /* convert timestamp, etc */ 02156 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 02157 02158 /* covert vars */ 02159 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EVENTHANDLERTYPE], &eventhandler_type); 02160 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATE], &state); 02161 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATETYPE], &state_type); 02162 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_TIMEOUT], &timeout); 02163 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EARLYTIMEOUT], &early_timeout); 02164 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_RETURNCODE], &return_code); 02165 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_EXECUTIONTIME], &execution_time); 02166 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_STARTTIME], &start_time); 02167 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_ENDTIME], &end_time); 02168 02169 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDARGS]); 02170 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDLINE]); 02171 es[2] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_OUTPUT]); 02172 es[3] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LONGOUTPUT]); 02173 02174 ts[0] = ido2db_db_timet_to_sql(idi, start_time.tv_sec); 02175 ts[1] = ido2db_db_timet_to_sql(idi, end_time.tv_sec); 02176 02177 /* get the object id */ 02178 if (eventhandler_type == SERVICE_EVENTHANDLER || eventhandler_type == GLOBAL_SERVICE_EVENTHANDLER) 02179 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOST], idi->buffered_input[IDO_DATA_SERVICE], &object_id); 02180 else 02181 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 02182 02183 /* get the command id */ 02184 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, idi->buffered_input[IDO_DATA_COMMANDNAME], NULL, &command_id); 02185 02186 /* save entry to db */ 02187 data[0] = (void *) &idi->dbinfo.instance_id; 02188 data[1] = (void *) &eventhandler_type; 02189 data[2] = (void *) &object_id; 02190 data[3] = (void *) &state; 02191 data[4] = (void *) &state_type; 02192 data[5] = (void *) &ts[0]; 02193 data[6] = (void *) &start_time.tv_usec; 02194 data[7] = (void *) &ts[1]; 02195 data[8] = (void *) &end_time.tv_usec; 02196 data[9] = (void *) &command_id; 02197 data[10] = (void *) &es[0]; 02198 data[11] = (void *) &es[1]; 02199 data[12] = (void *) &timeout; 02200 data[13] = (void *) &early_timeout; 02201 data[14] = (void *) &execution_time; 02202 data[15] = (void *) &return_code; 02203 data[16] = (void *) &es[2]; 02204 data[17] = (void *) &es[3]; 02205 /* bind params */ 02206 data[18] = (void *) &start_time.tv_sec; 02207 data[19] = (void *) &end_time.tv_sec; 02208 02209 result = ido2db_query_insert_or_update_eventhandlerdata_add(idi, data); 02210 02211 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02212 dbi_result_free(idi->dbinfo.dbi_result); 02213 #endif 02214 02215 #ifdef USE_PGSQL /* pgsql */ 02216 02217 #endif 02218 02219 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02220 02221 02222 #endif /* Oracle ocilib specific */ 02223 02224 02225 /* free memory */ 02226 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 02227 free(ts[x]); 02228 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 02229 free(es[x]); 02230 02231 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_eventhandlerdata() end\n"); 02232 02233 return IDO_OK; 02234 } 02235 02236 int ido2db_handle_notificationdata(ido2db_idi *idi) { 02237 int type, flags, attr; 02238 struct timeval tstamp; 02239 int notification_type = 0; 02240 int notification_reason = 0; 02241 unsigned long object_id = 0L; 02242 struct timeval start_time; 02243 struct timeval end_time; 02244 int state = 0; 02245 int escalated = 0; 02246 int contacts_notified = 0; 02247 int result = IDO_OK; 02248 char *ts[2]; 02249 char *es[2]; 02250 int x = 0; 02251 #ifdef USE_LIBDBI 02252 char *buf = NULL; 02253 #endif 02254 #ifdef USE_ORACLE 02255 char *seq_name = NULL; 02256 #endif 02257 02258 void *data[15]; 02259 02260 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_notificationdata() start\n"); 02261 02262 if (idi == NULL) 02263 return IDO_ERROR; 02264 02265 /* convert timestamp, etc */ 02266 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 02267 02268 /* convert vars */ 02269 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFICATIONTYPE], ¬ification_type); 02270 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFICATIONREASON], ¬ification_reason); 02271 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATE], &state); 02272 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ESCALATED], &escalated); 02273 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CONTACTSNOTIFIED], &contacts_notified); 02274 02275 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_STARTTIME], &start_time); 02276 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_ENDTIME], &end_time); 02277 02278 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_OUTPUT]); 02279 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LONGOUTPUT]); 02280 02281 ts[0] = ido2db_db_timet_to_sql(idi, start_time.tv_sec); 02282 ts[1] = ido2db_db_timet_to_sql(idi, end_time.tv_sec); 02283 02284 /* get the object id */ 02285 if (notification_type == SERVICE_NOTIFICATION) 02286 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOST], idi->buffered_input[IDO_DATA_SERVICE], &object_id); 02287 if (notification_type == HOST_NOTIFICATION) 02288 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 02289 02290 /* save entry to db */ 02291 data[0] = (void *) &idi->dbinfo.instance_id; 02292 data[1] = (void *) ¬ification_type; 02293 data[2] = (void *) ¬ification_reason; 02294 data[3] = (void *) &ts[0]; 02295 data[4] = (void *) &start_time.tv_sec; 02296 data[5] = (void *) &ts[1]; 02297 data[6] = (void *) &end_time.tv_usec; 02298 data[7] = (void *) &object_id; 02299 data[8] = (void *) &state; 02300 data[9] = (void *) &es[0]; 02301 data[10] = (void *) &es[1]; 02302 data[11] = (void *) &escalated; 02303 data[12] = (void *) &contacts_notified; 02304 /* bind params */ 02305 data[13] = (void *) &start_time.tv_sec; 02306 data[14] = (void *) &end_time.tv_sec; 02307 02308 result = ido2db_query_insert_or_update_notificationdata_add(idi, data); 02309 02310 /* save the notification id for later use... */ 02311 if (type == NEBTYPE_NOTIFICATION_START) 02312 idi->dbinfo.last_notification_id = 0L; 02313 if (result == IDO_OK && type == NEBTYPE_NOTIFICATION_START) { 02314 02315 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02316 switch (idi->dbinfo.server_type) { 02317 case IDO2DB_DBSERVER_MYSQL: 02318 /* mysql doesn't use sequences */ 02319 idi->dbinfo.last_notification_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 02320 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_notificationdata(%lu) last_notification_id\n", idi->dbinfo.last_notification_id); 02321 break; 02322 case IDO2DB_DBSERVER_PGSQL: 02323 /* depending on tableprefix/tablename a sequence will be used */ 02324 if(asprintf(&buf, "%s_notification_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_NOTIFICATIONS]) == -1) 02325 buf = NULL; 02326 02327 idi->dbinfo.last_notification_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 02328 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_notificationdata(%s=%lu) last_notification_id\n", buf, idi->dbinfo.last_notification_id); 02329 free(buf); 02330 break; 02331 case IDO2DB_DBSERVER_DB2: 02332 break; 02333 case IDO2DB_DBSERVER_FIREBIRD: 02334 break; 02335 case IDO2DB_DBSERVER_FREETDS: 02336 break; 02337 case IDO2DB_DBSERVER_INGRES: 02338 break; 02339 case IDO2DB_DBSERVER_MSQL: 02340 break; 02341 case IDO2DB_DBSERVER_ORACLE: 02342 break; 02343 case IDO2DB_DBSERVER_SQLITE: 02344 break; 02345 case IDO2DB_DBSERVER_SQLITE3: 02346 break; 02347 default: 02348 break; 02349 } 02350 02351 #endif 02352 02353 #ifdef USE_PGSQL /* pgsql */ 02354 02355 #endif 02356 02357 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02358 if(asprintf(&seq_name, "seq_notifications")==-1) 02359 seq_name=NULL; 02360 idi->dbinfo.last_notification_id = ido2db_ocilib_insert_id(idi, seq_name); 02361 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_notificationdata(%lu) last_notification_id\n", idi->dbinfo.last_notification_id); 02362 free(seq_name); 02363 02364 #endif /* Oracle ocilib specific */ 02365 } 02366 02367 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02368 dbi_result_free(idi->dbinfo.dbi_result); 02369 #endif 02370 02371 #ifdef USE_PGSQL /* pgsql */ 02372 02373 #endif 02374 02375 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02376 02377 02378 #endif /* Oracle ocilib specific */ 02379 02380 /* free memory */ 02381 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 02382 free(ts[x]); 02383 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 02384 free(es[x]); 02385 02386 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_notificationdata() end\n"); 02387 02388 return IDO_OK; 02389 } 02390 02391 int ido2db_handle_contactnotificationdata(ido2db_idi *idi) { 02392 int type, flags, attr; 02393 struct timeval tstamp; 02394 unsigned long contact_id = 0L; 02395 struct timeval start_time; 02396 struct timeval end_time; 02397 int result = IDO_OK; 02398 char *ts[2]; 02399 int x = 0; 02400 #ifdef USE_LIBDBI 02401 char *buf = NULL; 02402 #endif 02403 #ifdef USE_ORACLE 02404 char *seq_name = NULL; 02405 #endif 02406 void *data[9]; 02407 02408 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactnotificationdata() start\n"); 02409 02410 if (idi == NULL) 02411 return IDO_ERROR; 02412 02413 /* convert timestamp, etc */ 02414 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 02415 &tstamp); 02416 02417 /* convert vars */ 02418 02419 result = ido2db_convert_string_to_timeval( 02420 idi->buffered_input[IDO_DATA_STARTTIME], &start_time); 02421 result = ido2db_convert_string_to_timeval( 02422 idi->buffered_input[IDO_DATA_ENDTIME], &end_time); 02423 02424 ts[0] = ido2db_db_timet_to_sql(idi, start_time.tv_sec); 02425 ts[1] = ido2db_db_timet_to_sql(idi, end_time.tv_sec); 02426 02427 /* get the contact id */ 02428 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_CONTACT, 02429 idi->buffered_input[IDO_DATA_CONTACTNAME], NULL, &contact_id); 02430 02431 /* save entry to db */ 02432 data[0] = (void *) &idi->dbinfo.instance_id; 02433 data[1] = (void *) &idi->dbinfo.last_notification_id; 02434 data[2] = (void *) &ts[0]; 02435 data[3] = (void *) &start_time.tv_usec; 02436 data[4] = (void *) &ts[1]; 02437 data[5] = (void *) &end_time.tv_usec; 02438 data[6] = (void *) &contact_id; 02439 /* bind params */ 02440 data[7] = (void *) &start_time.tv_sec; 02441 data[8] = (void *) &end_time.tv_sec; 02442 02443 result = ido2db_query_insert_or_update_contactnotificationdata_add(idi, data); 02444 02445 /* save the contact notification id for later use... */ 02446 if (type == NEBTYPE_CONTACTNOTIFICATION_START) 02447 idi->dbinfo.last_contact_notification_id = 0L; 02448 if (result == IDO_OK && type == NEBTYPE_CONTACTNOTIFICATION_START) { 02449 02450 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02451 switch (idi->dbinfo.server_type) { 02452 case IDO2DB_DBSERVER_MYSQL: 02453 /* mysql doesn't use sequences */ 02454 idi->dbinfo.last_contact_notification_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 02455 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactnotificationdata(%lu) contactnotification_id\n", idi->dbinfo.last_contact_notification_id); 02456 break; 02457 case IDO2DB_DBSERVER_PGSQL: 02458 /* depending on tableprefix/tablename a sequence will be used */ 02459 if(asprintf(&buf, "%s_contactnotification_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONS]) == -1) 02460 buf = NULL; 02461 02462 idi->dbinfo.last_contact_notification_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 02463 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactnotificationdata(%s=%lu) contactnotification_id\n", buf, idi->dbinfo.last_contact_notification_id); 02464 free(buf); 02465 break; 02466 case IDO2DB_DBSERVER_DB2: 02467 break; 02468 case IDO2DB_DBSERVER_FIREBIRD: 02469 break; 02470 case IDO2DB_DBSERVER_FREETDS: 02471 break; 02472 case IDO2DB_DBSERVER_INGRES: 02473 break; 02474 case IDO2DB_DBSERVER_MSQL: 02475 break; 02476 case IDO2DB_DBSERVER_ORACLE: 02477 break; 02478 case IDO2DB_DBSERVER_SQLITE: 02479 break; 02480 case IDO2DB_DBSERVER_SQLITE3: 02481 break; 02482 default: 02483 break; 02484 } 02485 #endif 02486 02487 #ifdef USE_PGSQL /* pgsql */ 02488 02489 #endif 02490 02491 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02492 if(asprintf(&seq_name, "seq_contactnotifications")==-1) 02493 seq_name=NULL; 02494 idi->dbinfo.last_contact_notification_id = ido2db_ocilib_insert_id(idi, seq_name); 02495 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactnotificationdata(%lu) \n", idi->dbinfo.last_contact_notification_id); 02496 free(seq_name); 02497 02498 #endif /* Oracle ocilib specific */ 02499 } 02500 02501 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02502 dbi_result_free(idi->dbinfo.dbi_result); 02503 #endif 02504 02505 #ifdef USE_PGSQL /* pgsql */ 02506 02507 #endif 02508 02509 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02510 02511 02512 #endif /* Oracle ocilib specific */ 02513 02514 /* free memory */ 02515 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 02516 free(ts[x]); 02517 02518 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactnotificationdata() end\n"); 02519 02520 return IDO_OK; 02521 } 02522 02523 int ido2db_handle_contactnotificationmethoddata(ido2db_idi *idi) { 02524 int type, flags, attr; 02525 struct timeval tstamp; 02526 unsigned long command_id = 0L; 02527 struct timeval start_time; 02528 struct timeval end_time; 02529 int result = IDO_OK; 02530 char *ts[2]; 02531 char *es[1]; 02532 int x = 0; 02533 void *data[10]; 02534 02535 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactnotificationmethoddata() start\n"); 02536 02537 if (idi == NULL) 02538 return IDO_ERROR; 02539 02540 /* convert timestamp, etc */ 02541 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 02542 &tstamp); 02543 02544 /* convert vars */ 02545 02546 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_STARTTIME], &start_time); 02547 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_ENDTIME], &end_time); 02548 02549 es[0] = ido2db_db_escape_string(idi,idi->buffered_input[IDO_DATA_COMMANDARGS]); 02550 02551 ts[0] = ido2db_db_timet_to_sql(idi, start_time.tv_sec); 02552 ts[1] = ido2db_db_timet_to_sql(idi, end_time.tv_sec); 02553 02554 /* get the command id */ 02555 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, 02556 idi->buffered_input[IDO_DATA_COMMANDNAME], NULL, &command_id); 02557 02558 /* save entry to db */ 02559 data[0] = (void *) &idi->dbinfo.instance_id; 02560 data[1] = (void *) &idi->dbinfo.last_contact_notification_id; 02561 data[2] = (void *) &ts[0]; 02562 data[3] = (void *) &start_time.tv_usec; 02563 data[4] = (void *) &ts[1]; 02564 data[5] = (void *) &end_time.tv_usec; 02565 data[6] = (void *) &command_id; 02566 data[7] = (void *) &es[0]; 02567 /* bind params */ 02568 data[8] = (void *) &start_time.tv_sec; 02569 data[9] = (void *) &end_time.tv_sec; 02570 02571 result = ido2db_query_insert_or_update_contactnotificationmethoddata_add(idi, data); 02572 02573 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02574 dbi_result_free(idi->dbinfo.dbi_result); 02575 #endif 02576 02577 #ifdef USE_PGSQL /* pgsql */ 02578 02579 #endif 02580 02581 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02582 02583 02584 #endif /* Oracle ocilib specific */ 02585 02586 /* free memory */ 02587 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 02588 free(ts[x]); 02589 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 02590 free(es[x]); 02591 02592 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactnotificationmethoddata() end\n"); 02593 02594 return IDO_OK; 02595 } 02596 02597 int ido2db_handle_servicecheckdata(ido2db_idi *idi) { 02598 int type, flags, attr; 02599 struct timeval tstamp; 02600 char *ts[2]; 02601 char *es[5]; 02602 int check_type = 0; 02603 struct timeval start_time; 02604 struct timeval end_time; 02605 int current_check_attempt = 0; 02606 int max_check_attempts = 0; 02607 int state = 0; 02608 int state_type = 0; 02609 int timeout = 0; 02610 int early_timeout = 0; 02611 double execution_time = 0.0; 02612 double latency = 0.0; 02613 int return_code = 0; 02614 unsigned long object_id = 0L; 02615 unsigned long command_id = 0L; 02616 void *data[24]; 02617 02618 int x = 0; 02619 int result = IDO_OK; 02620 02621 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicecheckdata() start\n"); 02622 02623 if (idi == NULL) 02624 return IDO_ERROR; 02625 02626 /* convert timestamp, etc */ 02627 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 02628 &tstamp); 02629 02630 /* only process finished service checks... */ 02631 if(type!=NEBTYPE_SERVICECHECK_PROCESSED) 02632 return IDO_OK; 02633 02634 /* only process some types of service checks... */ 02635 if (type != NEBTYPE_SERVICECHECK_INITIATE && type != NEBTYPE_SERVICECHECK_PROCESSED) 02636 return IDO_OK; 02637 02638 /* skip precheck events - they aren't useful to us */ 02639 if (type == NEBTYPE_SERVICECHECK_ASYNC_PRECHECK) 02640 return IDO_OK; 02641 02642 /* covert vars */ 02643 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CHECKTYPE], &check_type); 02644 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTCHECKATTEMPT], ¤t_check_attempt); 02645 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_MAXCHECKATTEMPTS], &max_check_attempts); 02646 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATE], &state); 02647 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATETYPE], &state_type); 02648 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_TIMEOUT], &timeout); 02649 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EARLYTIMEOUT], &early_timeout); 02650 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_RETURNCODE], &return_code); 02651 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_EXECUTIONTIME], &execution_time); 02652 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_LATENCY], &latency); 02653 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_STARTTIME], &start_time); 02654 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_ENDTIME], &end_time); 02655 02656 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDARGS]); 02657 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDLINE]); 02658 es[2] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_OUTPUT]); 02659 es[3] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LONGOUTPUT]); 02660 es[4] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_PERFDATA]); 02661 02662 ts[0] = ido2db_db_timet_to_sql(idi, start_time.tv_sec); 02663 ts[1] = ido2db_db_timet_to_sql(idi, end_time.tv_sec); 02664 02665 /* get the object id */ 02666 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, 02667 idi->buffered_input[IDO_DATA_HOST], 02668 idi->buffered_input[IDO_DATA_SERVICE], &object_id); 02669 02670 /* get the command id */ 02671 if (idi->buffered_input[IDO_DATA_COMMANDNAME] != NULL && strcmp(idi->buffered_input[IDO_DATA_COMMANDNAME], "")) 02672 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, idi->buffered_input[IDO_DATA_COMMANDNAME], NULL, &command_id); 02673 else 02674 command_id = 0L; 02675 02676 /* save entry to db */ 02677 data[0] = (void *) &idi->dbinfo.instance_id; 02678 data[1] = (void *) &object_id; 02679 data[2] = (void *) &check_type; 02680 data[3] = (void *) ¤t_check_attempt; 02681 data[4] = (void *) &max_check_attempts; 02682 data[5] = (void *) &state; 02683 data[6] = (void *) &state_type; 02684 data[7] = (void *) &ts[0]; 02685 data[8] = (void *) &start_time.tv_usec; 02686 data[9] = (void *) &ts[1]; 02687 data[10] = (void *) &end_time.tv_usec; 02688 data[11] = (void *) &timeout; 02689 data[12] = (void *) &early_timeout; 02690 data[13] = (void *) &execution_time; 02691 data[14] = (void *) &latency; 02692 data[15] = (void *) &return_code; 02693 data[16] = (void *) &es[2]; 02694 data[17] = (void *) &es[3]; 02695 data[18] = (void *) &es[4]; 02696 data[19] = (void *) &command_id; 02697 data[20] = (void *) &es[0]; 02698 data[21] = (void *) &es[1]; 02699 /* add unixtime for bind params */ 02700 data[22] = (void *) &start_time.tv_sec; 02701 data[23] = (void *) &end_time.tv_sec; 02702 02703 result = ido2db_query_insert_servicecheckdata_add(idi, data); 02704 02705 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02706 dbi_result_free(idi->dbinfo.dbi_result); 02707 #endif 02708 02709 #ifdef USE_PGSQL /* pgsql */ 02710 02711 #endif 02712 02713 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02714 02715 /* do not free if prepared statement */ 02716 02717 #endif /* Oracle ocilib specific */ 02718 02719 /* free memory */ 02720 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 02721 free(ts[x]); 02722 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 02723 free(es[x]); 02724 02725 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicecheckdata() end\n"); 02726 02727 return IDO_OK; 02728 } 02729 02730 int ido2db_handle_hostcheckdata(ido2db_idi *idi) { 02731 int type, flags, attr; 02732 struct timeval tstamp; 02733 char *ts[2]; 02734 char *es[5]; 02735 int check_type = 0; 02736 int is_raw_check = 0; 02737 struct timeval start_time; 02738 struct timeval end_time; 02739 int current_check_attempt = 0; 02740 int max_check_attempts = 0; 02741 int state = 0; 02742 int state_type = 0; 02743 int timeout = 0; 02744 int early_timeout = 0; 02745 double execution_time = 0.0; 02746 double latency = 0.0; 02747 int return_code = 0; 02748 unsigned long object_id = 0L; 02749 unsigned long command_id = 0L; 02750 int x = 0; 02751 int result = IDO_OK; 02752 void *data[25]; 02753 02754 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostcheckdata() start\n"); 02755 02756 if (idi == NULL) 02757 return IDO_ERROR; 02758 02759 /* convert timestamp, etc */ 02760 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 02761 &tstamp); 02762 02763 /* only process finished host checks... */ 02764 if(type!=NEBTYPE_HOSTCHECK_PROCESSED) 02765 return IDO_OK; 02766 02767 /* skip precheck events - they aren't useful to us */ 02768 if (type == NEBTYPE_HOSTCHECK_ASYNC_PRECHECK || type == NEBTYPE_HOSTCHECK_SYNC_PRECHECK) 02769 return IDO_OK; 02770 02771 /* covert vars */ 02772 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CHECKTYPE], &check_type); 02773 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTCHECKATTEMPT], ¤t_check_attempt); 02774 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_MAXCHECKATTEMPTS], &max_check_attempts); 02775 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATE], &state); 02776 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATETYPE], &state_type); 02777 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_TIMEOUT], &timeout); 02778 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EARLYTIMEOUT], &early_timeout); 02779 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_RETURNCODE], &return_code); 02780 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_EXECUTIONTIME], &execution_time); 02781 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_LATENCY], &latency); 02782 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_STARTTIME], &start_time); 02783 result = ido2db_convert_string_to_timeval(idi->buffered_input[IDO_DATA_ENDTIME], &end_time); 02784 02785 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDARGS]); 02786 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDLINE]); 02787 es[2] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_OUTPUT]); 02788 es[3] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LONGOUTPUT]); 02789 es[4] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_PERFDATA]); 02790 02791 ts[0] = ido2db_db_timet_to_sql(idi, start_time.tv_sec); 02792 ts[1] = ido2db_db_timet_to_sql(idi, end_time.tv_sec); 02793 02794 /* get the object id */ 02795 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 02796 02797 /* get the command id */ 02798 if (idi->buffered_input[IDO_DATA_COMMANDNAME] != NULL && strcmp(idi->buffered_input[IDO_DATA_COMMANDNAME], "")) 02799 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, idi->buffered_input[IDO_DATA_COMMANDNAME], NULL, &command_id); 02800 else 02801 command_id = 0L; 02802 02803 /* is this a raw check? */ 02804 if (type == NEBTYPE_HOSTCHECK_RAW_START || type == NEBTYPE_HOSTCHECK_RAW_END) 02805 is_raw_check = 1; 02806 else 02807 is_raw_check = 0; 02808 02809 /* save entry to db */ 02810 data[0] = (void *) &command_id; 02811 data[1] = (void *) &es[0]; 02812 data[2] = (void *) &es[1]; 02813 data[3] = (void *) &idi->dbinfo.instance_id; 02814 data[4] = (void *) &object_id; 02815 data[5] = (void *) &check_type; 02816 data[6] = (void *) &is_raw_check; 02817 data[7] = (void *) ¤t_check_attempt; 02818 data[8] = (void *) &max_check_attempts; 02819 data[9] = (void *) &state; 02820 data[10] = (void *) &state_type; 02821 data[11] = (void *) &ts[0]; 02822 data[12] = (void *) &start_time.tv_usec; 02823 data[13] = (void *) &ts[1]; 02824 data[14] = (void *) &end_time.tv_usec; 02825 data[15] = (void *) &timeout; 02826 data[16] = (void *) &early_timeout; 02827 data[17] = (void *) &execution_time; 02828 data[18] = (void *) &latency; 02829 data[19] = (void *) &return_code; 02830 data[20] = (void *) &es[2]; 02831 data[21] = (void *) &es[3]; 02832 data[22] = (void *) &es[4]; 02833 /* add unixtime for bind params */ 02834 data[23] = (void *) &start_time.tv_sec; 02835 data[24] = (void *) &end_time.tv_sec; 02836 02837 result = ido2db_query_insert_hostcheckdata_add(idi, data); 02838 02839 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02840 dbi_result_free(idi->dbinfo.dbi_result); 02841 #endif 02842 02843 #ifdef USE_PGSQL /* pgsql */ 02844 02845 #endif 02846 02847 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02848 02849 /* do not free if prepared statement */ 02850 02851 #endif /* Oracle ocilib specific */ 02852 02853 /* free memory */ 02854 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 02855 free(ts[x]); 02856 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 02857 free(es[x]); 02858 02859 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostcheckdata() end\n"); 02860 02861 return IDO_OK; 02862 } 02863 02864 int ido2db_handle_commentdata(ido2db_idi *idi) { 02865 int type, flags, attr; 02866 struct timeval tstamp; 02867 int comment_type = 0; 02868 int entry_type = 0; 02869 unsigned long object_id = 0L; 02870 unsigned long comment_time = 0L; 02871 unsigned long internal_comment_id = 0L; 02872 int is_persistent = 0; 02873 int comment_source = 0; 02874 int expires = 0; 02875 unsigned long expire_time = 0L; 02876 int result = IDO_OK; 02877 char *ts[3]; 02878 char *es[2]; 02879 int x = 0; 02880 #ifdef USE_LIBDBI 02881 char *buf = NULL; 02882 #endif 02883 02884 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_commentdata() start\n"); 02885 02886 if (idi == NULL) 02887 return IDO_ERROR; 02888 02889 /* convert timestamp, etc */ 02890 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 02891 02892 /* convert vars */ 02893 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_COMMENTTYPE], &comment_type); 02894 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ENTRYTYPE], &entry_type); 02895 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PERSISTENT], &is_persistent); 02896 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SOURCE], &comment_source); 02897 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EXPIRES], &expires); 02898 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_COMMENTID], &internal_comment_id); 02899 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_ENTRYTIME], &comment_time); 02900 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_EXPIRATIONTIME], &expire_time); 02901 02902 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_AUTHORNAME]); 02903 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMENT]); 02904 02905 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 02906 ts[1] = ido2db_db_timet_to_sql(idi, comment_time); 02907 ts[2] = ido2db_db_timet_to_sql(idi, expire_time); 02908 02909 /* get the object id */ 02910 if (comment_type == SERVICE_COMMENT) 02911 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOST], idi->buffered_input[IDO_DATA_SERVICE], &object_id); 02912 02913 if (comment_type == HOST_COMMENT) 02914 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 02915 02916 /* ADD HISTORICAL COMMENTS */ 02917 /* save a record of comments that get added (or get loaded and weren't previously recorded).... */ 02918 if (type == NEBTYPE_COMMENT_ADD || type == NEBTYPE_COMMENT_LOAD) { 02919 02920 /* save entry to db */ 02921 void *data[17]; 02922 data[0] = (void *) &ts[0]; 02923 data[1] = (void *) &tstamp.tv_usec; 02924 data[2] = (void *) &idi->dbinfo.instance_id; 02925 data[3] = (void *) &comment_type; 02926 data[4] = (void *) &entry_type; 02927 data[5] = (void *) &object_id; 02928 data[6] = (void *) &ts[1]; 02929 data[7] = (void *) &internal_comment_id; 02930 data[8] = (void *) &es[0]; 02931 data[9] = (void *) &es[1]; 02932 data[10] = (void *) &is_persistent; 02933 data[11] = (void *) &comment_source; 02934 data[12] = (void *) &expires; 02935 data[13] = (void *) &ts[2]; 02936 /* bind params */ 02937 data[14] = &tstamp.tv_sec; 02938 data[15] = &comment_time; 02939 data[16] = &expire_time; 02940 02941 result = ido2db_query_insert_or_update_commentdata_history_add(idi, data); 02942 02943 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02944 dbi_result_free(idi->dbinfo.dbi_result); 02945 #endif 02946 02947 #ifdef USE_PGSQL /* pgsql */ 02948 02949 #endif 02950 02951 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02952 02953 02954 #endif /* Oracle ocilib specific */ 02955 02956 } 02957 02958 /* UPDATE HISTORICAL COMMENTS */ 02959 /* mark records that have been deleted */ 02960 if (type == NEBTYPE_COMMENT_DELETE) { 02961 02962 /* update db entry */ 02963 #ifdef USE_LIBDBI /* everything else will be libdbi */ 02964 02965 if (asprintf( 02966 &buf, 02967 "UPDATE %s SET deletion_time=%s, deletion_time_usec='%lu' WHERE instance_id='%lu' AND comment_time=%s AND internal_comment_id='%lu'", 02968 ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTHISTORY], ts[0], 02969 tstamp.tv_usec, idi->dbinfo.instance_id, ts[1], 02970 internal_comment_id) == -1) 02971 buf = NULL; 02972 result = ido2db_db_query(idi, buf); 02973 02974 dbi_result_free(idi->dbinfo.dbi_result); 02975 free(buf); 02976 02977 #endif 02978 02979 #ifdef USE_PGSQL /* pgsql */ 02980 02981 #endif 02982 02983 #ifdef USE_ORACLE /* Oracle ocilib specific */ 02984 02985 void *data[5]; 02986 02987 /* check if we lost connection, and reconnect */ 02988 if(ido2db_db_reconnect(idi)==IDO_ERROR) 02989 return IDO_ERROR; 02990 02991 data[0] = (void *) &tstamp.tv_sec; 02992 data[1] = (void *) &tstamp.tv_usec; 02993 data[2] = (void *) &idi->dbinfo.instance_id; 02994 data[3] = (void *) &comment_time; 02995 data[4] = (void *) &internal_comment_id; 02996 02997 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_comment_history_update, MT(":X1"), (big_uint *) data[0])) { /* unixtimestamp instead of time2sql */ 02998 return IDO_ERROR; 02999 } 03000 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_comment_history_update, MT(":X2"), (big_uint *) data[1])) { 03001 return IDO_ERROR; 03002 } 03003 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_comment_history_update, MT(":X3"), (big_uint *) data[2])) { 03004 return IDO_ERROR; 03005 } 03006 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_comment_history_update, MT(":X4"), (big_uint *) data[3])) { /* unixtimestamp instead of time2sql */ 03007 return IDO_ERROR; 03008 } 03009 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_comment_history_update, MT(":X5"), (big_uint *) data[4])) { 03010 return IDO_ERROR; 03011 } 03012 03013 /* execute statement */ 03014 if(!OCI_Execute(idi->dbinfo.oci_statement_comment_history_update)) { 03015 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_comment_history_update() execute error\n"); 03016 return IDO_ERROR; 03017 } 03018 03019 /* commit statement */ 03020 OCI_Commit(idi->dbinfo.oci_connection); 03021 03022 /* do not free statement yet! */ 03023 03024 #endif /* Oracle ocilib specific */ 03025 03026 } 03027 03028 /* ADD CURRENT COMMENTS */ 03029 if ((type == NEBTYPE_COMMENT_ADD || type == NEBTYPE_COMMENT_LOAD) 03030 && tstamp.tv_sec >= idi->dbinfo.latest_realtime_data_time) { 03031 03032 /* save entry to db */ 03033 void *data[17]; 03034 data[0] = (void *) &ts[0]; 03035 data[1] = (void *) &tstamp.tv_usec; 03036 data[2] = (void *) &idi->dbinfo.instance_id; 03037 data[3] = (void *) &comment_type; 03038 data[4] = (void *) &entry_type; 03039 data[5] = (void *) &object_id; 03040 data[6] = (void *) &ts[1]; 03041 data[7] = (void *) &internal_comment_id; 03042 data[8] = (void *) &es[0]; 03043 data[9] = (void *) &es[1]; 03044 data[10] = (void *) &is_persistent; 03045 data[11] = (void *) &comment_source; 03046 data[12] = (void *) &expires; 03047 data[13] = (void *) &ts[2]; 03048 /* bind params */ 03049 data[14] = &tstamp.tv_sec; 03050 data[15] = &comment_time; 03051 data[16] = &expire_time; 03052 03053 result = ido2db_query_insert_or_update_commentdata_add(idi, data); 03054 03055 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03056 dbi_result_free(idi->dbinfo.dbi_result); 03057 #endif 03058 03059 #ifdef USE_PGSQL /* pgsql */ 03060 03061 #endif 03062 03063 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03064 03065 03066 #endif /* Oracle ocilib specific */ 03067 03068 } 03069 03070 /* REMOVE CURRENT COMMENTS */ 03071 if (type == NEBTYPE_COMMENT_DELETE && tstamp.tv_sec 03072 >= idi->dbinfo.latest_realtime_data_time) { 03073 03074 /* clear entry from db */ 03075 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03076 03077 if (asprintf( 03078 &buf, 03079 "DELETE FROM %s WHERE instance_id='%lu' AND comment_time=%s AND internal_comment_id='%lu'", 03080 ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS], 03081 idi->dbinfo.instance_id, ts[1], internal_comment_id) == -1) 03082 buf = NULL; 03083 result = ido2db_db_query(idi, buf); 03084 03085 dbi_result_free(idi->dbinfo.dbi_result); 03086 free(buf); 03087 #endif 03088 03089 #ifdef USE_PGSQL /* pgsql */ 03090 03091 #endif 03092 03093 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03094 03095 void *data[3]; 03096 /* check if we lost connection, and reconnect */ 03097 if(ido2db_db_reconnect(idi)==IDO_ERROR) 03098 return IDO_ERROR; 03099 03100 data[0] = (void *) &idi->dbinfo.instance_id; 03101 data[1] = (void *) &comment_time; 03102 data[2] = (void *) &internal_comment_id; 03103 03104 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_comments_delete, MT(":X1"), (big_uint *) data[0])) { 03105 return IDO_ERROR; 03106 } 03107 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_comments_delete, MT(":X2"), (big_uint *) data[1])) { /* unixtimestamp instead of time2sql */ 03108 return IDO_ERROR; 03109 } 03110 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_comments_delete, MT(":X3"), (big_uint *) data[2])) { 03111 return IDO_ERROR; 03112 } 03113 03114 /* execute statement */ 03115 if(!OCI_Execute(idi->dbinfo.oci_statement_comments_delete)) { 03116 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_comments_delete() execute error\n"); 03117 return IDO_ERROR; 03118 } 03119 03120 /* commit statement */ 03121 OCI_Commit(idi->dbinfo.oci_connection); 03122 03123 /* do not free statement yet! */ 03124 03125 03126 #endif /* Oracle ocilib specific */ 03127 03128 } 03129 03130 /* free memory */ 03131 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 03132 free(ts[x]); 03133 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 03134 free(es[x]); 03135 03136 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_commentdata() end\n"); 03137 03138 return IDO_OK; 03139 } 03140 03141 int ido2db_handle_downtimedata(ido2db_idi *idi) { 03142 int type, flags, attr; 03143 struct timeval tstamp; 03144 int downtime_type = 0; 03145 int fixed = 0; 03146 unsigned long duration = 0L; 03147 unsigned long internal_downtime_id = 0L; 03148 unsigned long triggered_by = 0L; 03149 unsigned long entry_time = 0L; 03150 unsigned long start_time = 0L; 03151 unsigned long end_time = 0L; 03152 unsigned long object_id = 0L; 03153 int result = IDO_OK; 03154 char *ts[4]; 03155 char *es[2]; 03156 int x = 0; 03157 #ifdef USE_LIBDBI 03158 char *buf = NULL; 03159 #endif 03160 03161 #ifdef USE_ORACLE 03162 unsigned long was_started = 1; 03163 #endif 03164 void *data[15]; 03165 03166 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_downtimedata() start\n"); 03167 03168 if (idi == NULL) 03169 return IDO_ERROR; 03170 03171 /* convert timestamp, etc */ 03172 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 03173 &tstamp); 03174 03175 /* convert vars */ 03176 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_DOWNTIMETYPE], &downtime_type); 03177 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FIXED], &fixed); 03178 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_DURATION], &duration); 03179 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_DOWNTIMEID], &internal_downtime_id); 03180 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_TRIGGEREDBY], &triggered_by); 03181 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_ENTRYTIME], &entry_time); 03182 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_STARTTIME], &start_time); 03183 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_ENDTIME], &end_time); 03184 03185 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_AUTHORNAME]); 03186 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMENT]); 03187 03188 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 03189 ts[1] = ido2db_db_timet_to_sql(idi, entry_time); 03190 ts[2] = ido2db_db_timet_to_sql(idi, start_time); 03191 ts[3] = ido2db_db_timet_to_sql(idi, end_time); 03192 03193 /* get the object id */ 03194 if (downtime_type == SERVICE_DOWNTIME) 03195 result = ido2db_get_object_id_with_insert(idi, 03196 IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOST], 03197 idi->buffered_input[IDO_DATA_SERVICE], &object_id); 03198 if (downtime_type == HOST_DOWNTIME) 03199 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, 03200 idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 03201 03202 /* HISTORICAL DOWNTIME */ 03203 03204 /* save a record of scheduled downtime that gets added (or gets loaded and wasn't previously recorded).... */ 03205 if (type == NEBTYPE_DOWNTIME_ADD || type == NEBTYPE_DOWNTIME_LOAD) { 03206 03207 /* save entry to db */ 03208 data[0] = (void *) &idi->dbinfo.instance_id; 03209 data[1] = (void *) &downtime_type; 03210 data[2] = (void *) &object_id; 03211 data[3] = (void *) &ts[1]; 03212 data[4] = (void *) &es[0]; 03213 data[5] = (void *) &es[1]; 03214 data[6] = (void *) &internal_downtime_id; 03215 data[7] = (void *) &triggered_by; 03216 data[8] = (void *) &fixed; 03217 data[9] = (void *) &duration; 03218 data[10] = (void *) &ts[2]; 03219 data[11] = (void *) &ts[3]; 03220 /* bind params */ 03221 data[12] = (void *) &entry_time; 03222 data[13] = (void *) &start_time; 03223 data[14] = (void *) &end_time; 03224 03225 result = ido2db_query_insert_or_update_downtimedata_downtime_history_add(idi, data); 03226 03227 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03228 dbi_result_free(idi->dbinfo.dbi_result); 03229 #endif 03230 03231 #ifdef USE_PGSQL /* pgsql */ 03232 03233 #endif 03234 03235 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03236 03237 03238 #endif /* Oracle ocilib specific */ 03239 03240 } 03241 03242 /* save a record of scheduled downtime that starts */ 03243 if (type == NEBTYPE_DOWNTIME_START) { 03244 03245 /* save entry to db */ 03246 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03247 03248 if (asprintf(&buf, 03249 "UPDATE %s SET actual_start_time=%s, actual_start_time_usec='%lu', was_started='%d' WHERE instance_id='%lu' AND downtime_type='%d' AND object_id='%lu' AND entry_time=%s AND scheduled_start_time=%s AND scheduled_end_time=%s", 03250 ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY], ts[0], 03251 tstamp.tv_usec, 1, idi->dbinfo.instance_id, downtime_type, 03252 object_id, ts[1], ts[2], ts[3]) == -1) 03253 buf = NULL; 03254 03255 result = ido2db_db_query(idi, buf); 03256 03257 dbi_result_free(idi->dbinfo.dbi_result); 03258 free(buf); 03259 #endif 03260 03261 #ifdef USE_PGSQL /* pgsql */ 03262 03263 #endif 03264 03265 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03266 03267 /* check if we lost connection, and reconnect */ 03268 if(ido2db_db_reconnect(idi)==IDO_ERROR) 03269 return IDO_ERROR; 03270 03271 was_started = 1; 03272 data[0] = (void *) &tstamp.tv_sec; 03273 data[1] = (void *) &tstamp.tv_usec; 03274 data[2] = (void *) &was_started; 03275 data[3] = (void *) &idi->dbinfo.instance_id; 03276 data[4] = (void *) &downtime_type; 03277 data[5] = (void *) &object_id; 03278 data[6] = (void *) &entry_time; 03279 data[7] = (void *) &start_time; 03280 data[8] = (void *) &end_time; 03281 03282 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X1"), (big_uint *) data[0])) { /* unixtimestamp instead of time2sql */ 03283 return IDO_ERROR; 03284 } 03285 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X2"), (big_uint *) data[1])) { 03286 return IDO_ERROR; 03287 } 03288 if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X3"), (int *) data[2])) { 03289 return IDO_ERROR; 03290 } 03291 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X4"), (big_uint *) data[3])) { 03292 return IDO_ERROR; 03293 } 03294 if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X5"), (int *) data[4])) { 03295 return IDO_ERROR; 03296 } 03297 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X6"), (big_uint *) data[5])) { 03298 return IDO_ERROR; 03299 } 03300 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X7"), (big_uint *) data[6])) { /* unixtimestamp instead of time2sql */ 03301 return IDO_ERROR; 03302 } 03303 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X8"), (big_uint *) data[7])) { /* unixtimestamp instead of time2sql */ 03304 return IDO_ERROR; 03305 } 03306 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X9"), (big_uint *) data[8])) { /* unixtimestamp instead of time2sql */ 03307 return IDO_ERROR; 03308 } 03309 03310 /* execute statement */ 03311 if(!OCI_Execute(idi->dbinfo.oci_statement_downtimehistory_update_start)) { 03312 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_downtimehistory_update_start() execute error\n"); 03313 return IDO_ERROR; 03314 } 03315 03316 /* commit statement */ 03317 OCI_Commit(idi->dbinfo.oci_connection); 03318 03319 /* do not free statement yet! */ 03320 03321 03322 #endif /* Oracle ocilib specific */ 03323 03324 } 03325 03326 /* save a record of scheduled downtime that ends */ 03327 if (type == NEBTYPE_DOWNTIME_STOP) { 03328 03329 /* save entry to db */ 03330 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03331 03332 if (asprintf( 03333 &buf, 03334 "UPDATE %s SET actual_end_time=%s, actual_end_time_usec='%lu', was_cancelled='%d' WHERE instance_id='%lu' AND downtime_type='%d' AND object_id='%lu' AND entry_time=%s AND scheduled_start_time=%s AND scheduled_end_time=%s", 03335 ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY], ts[0], 03336 tstamp.tv_usec, (attr == NEBATTR_DOWNTIME_STOP_CANCELLED) ? 1 03337 : 0, idi->dbinfo.instance_id, downtime_type, object_id, 03338 ts[1], ts[2], ts[3]) == -1) 03339 buf = NULL; 03340 03341 result = ido2db_db_query(idi, buf); 03342 03343 dbi_result_free(idi->dbinfo.dbi_result); 03344 free(buf); 03345 #endif 03346 03347 #ifdef USE_PGSQL /* pgsql */ 03348 03349 #endif 03350 03351 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03352 03353 int was_cancelled; 03354 03355 /* check if we lost connection, and reconnect */ 03356 if(ido2db_db_reconnect(idi)==IDO_ERROR) 03357 return IDO_ERROR; 03358 03359 if(attr == NEBATTR_DOWNTIME_STOP_CANCELLED) { 03360 was_cancelled = 1; 03361 } else { 03362 was_cancelled = 0; 03363 } 03364 03365 data[0] = (void *) &tstamp.tv_sec; 03366 data[1] = (void *) &tstamp.tv_usec; 03367 data[2] = (void *) &was_cancelled; 03368 data[3] = (void *) &idi->dbinfo.instance_id; 03369 data[4] = (void *) &downtime_type; 03370 data[5] = (void *) &object_id; 03371 data[6] = (void *) &entry_time; 03372 data[7] = (void *) &start_time; 03373 data[8] = (void *) &end_time; 03374 03375 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X1"), (big_uint *) data[0])) { /* unixtimestamp instead of time2sql */ 03376 return IDO_ERROR; 03377 } 03378 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X2"), (big_uint *) data[1])) { 03379 return IDO_ERROR; 03380 } 03381 if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X3"), (int *) data[2])) { 03382 return IDO_ERROR; 03383 } 03384 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X4"), (big_uint *) data[3])) { 03385 return IDO_ERROR; 03386 } 03387 if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X5"), (int *) data[4])) { 03388 return IDO_ERROR; 03389 } 03390 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X6"), (big_uint *) data[5])) { 03391 return IDO_ERROR; 03392 } 03393 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X7"), (big_uint *) data[6])) { /* unixtimestamp instead of time2sql */ 03394 return IDO_ERROR; 03395 } 03396 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X8"), (big_uint *) data[7])) { /* unixtimestamp instead of time2sql */ 03397 return IDO_ERROR; 03398 } 03399 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_stop, MT(":X9"), (big_uint *) data[8])) { /* unixtimestamp instead of time2sql */ 03400 return IDO_ERROR; 03401 } 03402 03403 /* execute statement */ 03404 if(!OCI_Execute(idi->dbinfo.oci_statement_downtimehistory_update_stop)) { 03405 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_downtimehistory_update_stop() execute error\n"); 03406 return IDO_ERROR; 03407 } 03408 03409 /* commit statement */ 03410 OCI_Commit(idi->dbinfo.oci_connection); 03411 03412 /* do not free statement yet! */ 03413 03414 #endif /* Oracle ocilib specific */ 03415 03416 } 03417 03418 /* CURRENT DOWNTIME */ 03419 03420 /* save a record of scheduled downtime that gets added (or gets loaded and wasn't previously recorded).... */ 03421 if ((type == NEBTYPE_DOWNTIME_ADD || type == NEBTYPE_DOWNTIME_LOAD) 03422 && tstamp.tv_sec >= idi->dbinfo.latest_realtime_data_time) { 03423 03424 /* save entry to db */ 03425 data[0] = (void *) &idi->dbinfo.instance_id; 03426 data[1] = (void *) &downtime_type; 03427 data[2] = (void *) &object_id; 03428 data[3] = (void *) &ts[1]; 03429 data[4] = (void *) &es[0]; 03430 data[5] = (void *) &es[1]; 03431 data[6] = (void *) &internal_downtime_id; 03432 data[7] = (void *) &triggered_by; 03433 data[8] = (void *) &fixed; 03434 data[9] = (void *) &duration; 03435 data[10] = (void *) &ts[2]; 03436 data[11] = (void *) &ts[3]; 03437 /* bind params */ 03438 data[12] = (void *) &entry_time; 03439 data[13] = (void *) &start_time; 03440 data[14] = (void *) &end_time; 03441 03442 result = ido2db_query_insert_or_update_downtimedata_scheduled_downtime_add(idi, data); 03443 03444 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03445 dbi_result_free(idi->dbinfo.dbi_result); 03446 #endif 03447 03448 #ifdef USE_PGSQL /* pgsql */ 03449 03450 #endif 03451 03452 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03453 03454 03455 #endif /* Oracle ocilib specific */ 03456 03457 } 03458 03459 /* save a record of scheduled downtime that starts */ 03460 if (type == NEBTYPE_DOWNTIME_START && tstamp.tv_sec 03461 >= idi->dbinfo.latest_realtime_data_time) { 03462 03463 /* save entry to db */ 03464 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03465 03466 if (asprintf(&buf, 03467 "UPDATE %s SET actual_start_time=%s, actual_start_time_usec='%lu', was_started='%d' WHERE instance_id='%lu' AND downtime_type='%d' AND object_id='%lu' AND entry_time=%s AND scheduled_start_time=%s AND scheduled_end_time=%s", 03468 ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME], ts[0], 03469 tstamp.tv_usec, 1, idi->dbinfo.instance_id, downtime_type, 03470 object_id, ts[1], ts[2], ts[3]) == -1) 03471 buf = NULL; 03472 03473 result = ido2db_db_query(idi, buf); 03474 03475 dbi_result_free(idi->dbinfo.dbi_result); 03476 free(buf); 03477 03478 #endif 03479 03480 #ifdef USE_PGSQL /* pgsql */ 03481 03482 #endif 03483 03484 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03485 03486 /* check if we lost connection, and reconnect */ 03487 if(ido2db_db_reconnect(idi)==IDO_ERROR) 03488 return IDO_ERROR; 03489 03490 was_started = 1; 03491 data[0] = (void *) &tstamp.tv_sec; 03492 data[1] = (void *) &tstamp.tv_usec; 03493 data[2] = (void *) &was_started; 03494 data[3] = (void *) &idi->dbinfo.instance_id; 03495 data[4] = (void *) &downtime_type; 03496 data[5] = (void *) &object_id; 03497 data[6] = (void *) &entry_time; 03498 data[7] = (void *) &start_time; 03499 data[8] = (void *) &end_time; 03500 03501 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X1"), (big_uint *) data[0])) { /* unixtimestamp instead of time2sql */ 03502 return IDO_ERROR; 03503 } 03504 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X2"), (big_uint *) data[1])) { 03505 return IDO_ERROR; 03506 } 03507 if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X3"), (int *) data[2])) { 03508 return IDO_ERROR; 03509 } 03510 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X4"), (big_uint *) data[3])) { 03511 return IDO_ERROR; 03512 } 03513 if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X5"), (int *) data[4])) { 03514 return IDO_ERROR; 03515 } 03516 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X6"), (big_uint *) data[5])) { 03517 return IDO_ERROR; 03518 } 03519 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X7"), (big_uint *) data[6])) { /* unixtimestamp instead of time2sql */ 03520 return IDO_ERROR; 03521 } 03522 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X8"), (big_uint *) data[7])) { /* unixtimestamp instead of time2sql */ 03523 return IDO_ERROR; 03524 } 03525 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimehistory_update_start, MT(":X9"), (big_uint *) data[8])) { /* unixtimestamp instead of time2sql */ 03526 return IDO_ERROR; 03527 } 03528 03529 /* execute statement */ 03530 if(!OCI_Execute(idi->dbinfo.oci_statement_downtimehistory_update_start)) { 03531 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_downtimehistory_update_start() execute error\n"); 03532 return IDO_ERROR; 03533 } 03534 03535 /* commit statement */ 03536 OCI_Commit(idi->dbinfo.oci_connection); 03537 03538 /* do not free statement yet! */ 03539 03540 03541 03542 #endif /* Oracle ocilib specific */ 03543 03544 } 03545 03546 /* remove completed or deleted downtime */ 03547 if ((type == NEBTYPE_DOWNTIME_STOP || type == NEBTYPE_DOWNTIME_DELETE) 03548 && tstamp.tv_sec >= idi->dbinfo.latest_realtime_data_time) { 03549 03550 /* save entry to db */ 03551 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03552 03553 if (asprintf(&buf, 03554 "DELETE FROM %s WHERE instance_id='%lu' AND downtime_type='%d' AND object_id='%lu' AND entry_time=%s AND scheduled_start_time=%s AND scheduled_end_time=%s", 03555 ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME], 03556 idi->dbinfo.instance_id, downtime_type, object_id, ts[1], 03557 ts[2], ts[3]) == -1) 03558 buf = NULL; 03559 03560 result = ido2db_db_query(idi, buf); 03561 03562 dbi_result_free(idi->dbinfo.dbi_result); 03563 free(buf); 03564 #endif 03565 03566 #ifdef USE_PGSQL /* pgsql */ 03567 03568 #endif 03569 03570 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03571 03572 /* check if we lost connection, and reconnect */ 03573 if(ido2db_db_reconnect(idi)==IDO_ERROR) 03574 return IDO_ERROR; 03575 03576 data[0] = (void *) &idi->dbinfo.instance_id; 03577 data[1] = (void *) &downtime_type; 03578 data[2] = (void *) &object_id; 03579 data[3] = (void *) &entry_time; 03580 data[4] = (void *) &start_time; 03581 data[5] = (void *) &end_time; 03582 03583 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtime_delete, MT(":X1"), (big_uint *) data[0])) { 03584 return IDO_ERROR; 03585 } 03586 if(!OCI_BindInt(idi->dbinfo.oci_statement_downtime_delete, MT(":X2"), (int *) data[1])) { 03587 return IDO_ERROR; 03588 } 03589 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtime_delete, MT(":X3"), (big_uint *) data[2])) { 03590 return IDO_ERROR; 03591 } 03592 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtime_delete, MT(":X4"), (big_uint *) data[3])) { /* unixtimestamp instead of time2sql */ 03593 return IDO_ERROR; 03594 } 03595 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtime_delete, MT(":X5"), (big_uint *) data[4])) { /* unixtimestamp instead of time2sql */ 03596 return IDO_ERROR; 03597 } 03598 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtime_delete, MT(":X6"), (big_uint *) data[5])) { /* unixtimestamp instead of time2sql */ 03599 return IDO_ERROR; 03600 } 03601 03602 /* execute statement */ 03603 if(!OCI_Execute(idi->dbinfo.oci_statement_downtime_delete)) { 03604 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_downtime_delete() execute error\n"); 03605 return IDO_ERROR; 03606 } 03607 03608 /* commit statement */ 03609 OCI_Commit(idi->dbinfo.oci_connection); 03610 03611 /* do not free statement yet! */ 03612 03613 03614 #endif /* Oracle ocilib specific */ 03615 03616 03617 } 03618 03619 /* free memory */ 03620 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 03621 free(ts[x]); 03622 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 03623 free(es[x]); 03624 03625 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_downtimedata() end\n"); 03626 03627 return IDO_OK; 03628 } 03629 03630 int ido2db_handle_flappingdata(ido2db_idi *idi) { 03631 int type, flags, attr; 03632 int x = 0; 03633 struct timeval tstamp; 03634 int flapping_type = 0; 03635 unsigned long object_id = 0L; 03636 double percent_state_change = 0.0; 03637 double low_threshold = 0.0; 03638 double high_threshold = 0.0; 03639 unsigned long comment_time = 0L; 03640 unsigned long internal_comment_id = 0L; 03641 int result = IDO_OK; 03642 char *ts[2]; 03643 char *buf = NULL; 03644 03645 #ifdef USE_ORACLE 03646 void *data[12]; 03647 #endif 03648 03649 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_flappingdata() start\n"); 03650 03651 if (idi == NULL) 03652 return IDO_ERROR; 03653 03654 /* convert timestamp, etc */ 03655 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 03656 03657 /* convert vars */ 03658 result = ido2db_convert_string_to_int( idi->buffered_input[IDO_DATA_FLAPPINGTYPE], &flapping_type); 03659 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_PERCENTSTATECHANGE], &percent_state_change); 03660 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_LOWTHRESHOLD], &low_threshold); 03661 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_HIGHTHRESHOLD], &high_threshold); 03662 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_COMMENTTIME], &comment_time); 03663 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_COMMENTID], &internal_comment_id); 03664 03665 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 03666 ts[1] = ido2db_db_timet_to_sql(idi, comment_time); 03667 03668 /* get the object id (if applicable) */ 03669 if (flapping_type == SERVICE_FLAPPING) 03670 result = ido2db_get_object_id_with_insert(idi, 03671 IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOST], 03672 idi->buffered_input[IDO_DATA_SERVICE], &object_id); 03673 if (flapping_type == HOST_FLAPPING) 03674 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, 03675 idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 03676 03677 /* save entry to db */ 03678 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03679 if (asprintf( 03680 &buf, 03681 "INSERT INTO %s (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 ('%lu', %s, '%lu', '%d', '%d', '%d', '%lu', '%lf', '%lf', '%lf', %s, '%lu')", 03682 ido2db_db_tablenames[IDO2DB_DBTABLE_FLAPPINGHISTORY], 03683 idi->dbinfo.instance_id, ts[0], tstamp.tv_usec, type, attr, 03684 flapping_type, object_id, percent_state_change, low_threshold, 03685 high_threshold, ts[1], internal_comment_id) == -1) 03686 buf = NULL; 03687 result = ido2db_db_query(idi, buf); 03688 03689 dbi_result_free(idi->dbinfo.dbi_result); 03690 #endif 03691 03692 #ifdef USE_PGSQL /* pgsql */ 03693 03694 #endif 03695 03696 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03697 03698 /* check if we lost connection, and reconnect */ 03699 if(ido2db_db_reconnect(idi)==IDO_ERROR) 03700 return IDO_ERROR; 03701 03702 data[0] = (void *) &idi->dbinfo.instance_id; 03703 data[1] = (void *) &tstamp.tv_sec; 03704 data[2] = (void *) &tstamp.tv_usec; 03705 data[3] = (void *) &type; 03706 data[4] = (void *) &attr; 03707 data[5] = (void *) &flapping_type; 03708 data[6] = (void *) &object_id; 03709 data[7] = (void *) &percent_state_change; 03710 data[8] = (void *) &low_threshold; 03711 data[9] = (void *) &high_threshold; 03712 data[10] = (void *) &comment_time; 03713 data[11] = (void *) &internal_comment_id; 03714 03715 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X1"), (big_uint *) data[0])) { 03716 return IDO_ERROR; 03717 } 03718 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X2"), (big_uint *) data[1])) { /* unixtimestamp instead of time2sql */ 03719 return IDO_ERROR; 03720 } 03721 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X3"), (big_uint *) data[2])) { 03722 return IDO_ERROR; 03723 } 03724 if(!OCI_BindInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X4"), (int *) data[3])) { 03725 return IDO_ERROR; 03726 } 03727 if(!OCI_BindInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X5"), (int *) data[4])) { 03728 return IDO_ERROR; 03729 } 03730 if(!OCI_BindInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X6"), (int *) data[5])) { 03731 return IDO_ERROR; 03732 } 03733 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X7"), (big_uint *) data[6])) { 03734 return IDO_ERROR; 03735 } 03736 if(!OCI_BindDouble(idi->dbinfo.oci_statement_flappinghistory, MT(":X8"), (double *) data[7])) { 03737 return IDO_ERROR; 03738 } 03739 if(!OCI_BindDouble(idi->dbinfo.oci_statement_flappinghistory, MT(":X9"), (double *) data[8])) { 03740 return IDO_ERROR; 03741 } 03742 if(!OCI_BindDouble(idi->dbinfo.oci_statement_flappinghistory, MT(":X10"), (double *) data[9])) { 03743 return IDO_ERROR; 03744 } 03745 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X11"), (big_uint *) data[10])) { /* unixtimestamp instead of time2sql */ 03746 return IDO_ERROR; 03747 } 03748 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_flappinghistory, MT(":X12"), (big_uint *) data[11])) { 03749 return IDO_ERROR; 03750 } 03751 03752 /* execute statement */ 03753 if(!OCI_Execute(idi->dbinfo.oci_statement_flappinghistory)) { 03754 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_flappinghistory() execute error\n"); 03755 return IDO_ERROR; 03756 } 03757 03758 /* commit statement */ 03759 OCI_Commit(idi->dbinfo.oci_connection); 03760 03761 /* do not free statement yet! */ 03762 03763 03764 03765 #endif /* Oracle ocilib specific */ 03766 03767 free(buf); 03768 03769 /* free memory */ 03770 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 03771 free(ts[x]); 03772 03773 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_flappingdata() end\n"); 03774 03775 return IDO_OK; 03776 } 03777 03778 int ido2db_handle_programstatusdata(ido2db_idi *idi) { 03779 int type, flags, attr; 03780 int x = 0; 03781 struct timeval tstamp; 03782 unsigned long program_start_time = 0L; 03783 unsigned long process_id = 0L; 03784 int daemon_mode = 0; 03785 unsigned long last_command_check = 0L; 03786 unsigned long last_log_rotation = 0L; 03787 int notifications_enabled = 0; 03788 int active_service_checks_enabled = 0; 03789 int passive_service_checks_enabled = 0; 03790 int active_host_checks_enabled = 0; 03791 int passive_host_checks_enabled = 0; 03792 int event_handlers_enabled = 0; 03793 int flap_detection_enabled = 0; 03794 int failure_prediction_enabled = 0; 03795 int process_performance_data = 0; 03796 int obsess_over_hosts = 0; 03797 int obsess_over_services = 0; 03798 unsigned long modified_host_attributes = 0L; 03799 unsigned long modified_service_attributes = 0L; 03800 char *ts[4]; 03801 char *es[2]; 03802 int result = IDO_OK; 03803 void *data[26]; 03804 03805 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_programstatusdata() start\n"); 03806 03807 if (idi == NULL) 03808 return IDO_ERROR; 03809 03810 /* convert timestamp, etc */ 03811 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 03812 03813 /* don't store old data */ 03814 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 03815 return IDO_OK; 03816 03817 /* covert vars */ 03818 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_PROGRAMSTARTTIME], &program_start_time); 03819 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_PROCESSID], &process_id); 03820 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_DAEMONMODE], &daemon_mode); 03821 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTCOMMANDCHECK], &last_command_check); 03822 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTLOGROTATION], &last_log_rotation); 03823 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFICATIONSENABLED], ¬ifications_enabled); 03824 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACTIVESERVICECHECKSENABLED], &active_service_checks_enabled); 03825 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PASSIVESERVICECHECKSENABLED], &passive_service_checks_enabled); 03826 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACTIVEHOSTCHECKSENABLED], &active_host_checks_enabled); 03827 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PASSIVEHOSTCHECKSENABLED], &passive_host_checks_enabled); 03828 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EVENTHANDLERSENABLED], &event_handlers_enabled); 03829 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONENABLED], &flap_detection_enabled); 03830 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILUREPREDICTIONENABLED], &failure_prediction_enabled); 03831 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PROCESSPERFORMANCEDATA], &process_performance_data); 03832 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_OBSESSOVERHOSTS], &obsess_over_hosts); 03833 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_OBSESSOVERSERVICES], &obsess_over_services); 03834 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_MODIFIEDHOSTATTRIBUTES], &modified_host_attributes); 03835 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_MODIFIEDSERVICEATTRIBUTES], &modified_service_attributes); 03836 03837 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_GLOBALHOSTEVENTHANDLER]); 03838 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_GLOBALSERVICEEVENTHANDLER]); 03839 03840 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 03841 ts[1] = ido2db_db_timet_to_sql(idi, program_start_time); 03842 ts[2] = ido2db_db_timet_to_sql(idi, last_command_check); 03843 ts[3] = ido2db_db_timet_to_sql(idi, last_log_rotation); 03844 03845 data[0] = (void *) &idi->dbinfo.instance_id; 03846 data[1] = (void *) &ts[0]; 03847 data[2] = (void *) &ts[1]; 03848 data[3] = (void *) &process_id; 03849 data[4] = (void *) &daemon_mode; 03850 data[5] = (void *) &ts[2]; 03851 data[6] = (void *) &ts[3]; 03852 data[7] = (void *) ¬ifications_enabled; 03853 data[8] = (void *) &active_service_checks_enabled; 03854 data[9] = (void *) &passive_service_checks_enabled; 03855 data[10] = (void *) &active_host_checks_enabled; 03856 data[11] = (void *) &passive_host_checks_enabled; 03857 data[12] = (void *) &event_handlers_enabled; 03858 data[13] = (void *) &flap_detection_enabled; 03859 data[14] = (void *) &failure_prediction_enabled; 03860 data[15] = (void *) &process_performance_data; 03861 data[16] = (void *) &obsess_over_hosts; 03862 data[17] = (void *) &obsess_over_services; 03863 data[18] = (void *) &modified_host_attributes; 03864 data[19] = (void *) &modified_service_attributes; 03865 data[20] = (void *) &es[0]; 03866 data[21] = (void *) &es[1]; 03867 /* add unixtime for bind params */ 03868 data[22] = (void *) &tstamp.tv_sec; 03869 data[23] = (void *) &program_start_time; 03870 data[24] = (void *) &last_command_check; 03871 data[25] = (void *) &last_log_rotation; 03872 03873 /* save entry to db */ 03874 result = ido2db_query_insert_or_update_programstatusdata_add(idi, data); 03875 03876 if(result == IDO_ERROR) { 03877 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_programstatusdata() error\n"); 03878 return result; 03879 } 03880 03881 #ifdef USE_LIBDBI /* everything else will be libdbi */ 03882 dbi_result_free(idi->dbinfo.dbi_result); 03883 #endif 03884 03885 #ifdef USE_PGSQL /* pgsql */ 03886 03887 #endif 03888 03889 #ifdef USE_ORACLE /* Oracle ocilib specific */ 03890 03891 /* do not free if prepared statement */ 03892 03893 #endif /* Oracle ocilib specific */ 03894 03895 /* free memory */ 03896 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 03897 free(ts[x]); 03898 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 03899 free(es[x]); 03900 03901 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_programstatusdata() end\n"); 03902 03903 return IDO_OK; 03904 } 03905 03906 int ido2db_handle_hoststatusdata(ido2db_idi *idi) { 03907 int type, flags, attr; 03908 struct timeval tstamp; 03909 unsigned long last_check = 0L; 03910 unsigned long next_check = 0L; 03911 unsigned long last_state_change = 0L; 03912 unsigned long last_hard_state_change = 0L; 03913 unsigned long last_time_up = 0L; 03914 unsigned long last_time_down = 0L; 03915 unsigned long last_time_unreachable = 0L; 03916 unsigned long last_notification = 0L; 03917 unsigned long next_notification = 0L; 03918 unsigned long modified_host_attributes = 0L; 03919 double percent_state_change = 0.0; 03920 double latency = 0.0; 03921 double execution_time = 0.0; 03922 int current_state = 0; 03923 int has_been_checked = 0; 03924 int should_be_scheduled = 0; 03925 int current_check_attempt = 0; 03926 int max_check_attempts = 0; 03927 int check_type = 0; 03928 int last_hard_state = 0; 03929 int state_type = 0; 03930 int no_more_notifications = 0; 03931 int notifications_enabled = 0; 03932 int problem_has_been_acknowledged = 0; 03933 int acknowledgement_type = 0; 03934 int current_notification_number = 0; 03935 int passive_checks_enabled = 0; 03936 int active_checks_enabled = 0; 03937 int event_handler_enabled; 03938 int flap_detection_enabled = 0; 03939 int is_flapping = 0; 03940 int scheduled_downtime_depth = 0; 03941 int failure_prediction_enabled = 0; 03942 int process_performance_data; 03943 int obsess_over_host = 0; 03944 double normal_check_interval = 0.0; 03945 double retry_check_interval = 0.0; 03946 char *ts[10]; 03947 char *es[5]; 03948 unsigned long object_id = 0L; 03949 unsigned long check_timeperiod_object_id = 0L; 03950 int x = 0; 03951 int result = IDO_OK; 03952 void *data[56]; 03953 03954 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hoststatusdata() start\n"); 03955 03956 if (idi == NULL) 03957 return IDO_ERROR; 03958 03959 /* convert timestamp, etc */ 03960 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 03961 03962 /* don't store old data */ 03963 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 03964 return IDO_OK; 03965 03966 /* covert vars */ 03967 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTHOSTCHECK], &last_check); 03968 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_NEXTHOSTCHECK], &next_check); 03969 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTSTATECHANGE], &last_state_change); 03970 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTHARDSTATECHANGE], &last_hard_state_change); 03971 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTTIMEUP], &last_time_up); 03972 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTTIMEDOWN], &last_time_down); 03973 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTTIMEUNREACHABLE], &last_time_unreachable); 03974 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTHOSTNOTIFICATION], &last_notification); 03975 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_NEXTHOSTNOTIFICATION], &next_notification); 03976 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_MODIFIEDHOSTATTRIBUTES], &modified_host_attributes); 03977 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_PERCENTSTATECHANGE], &percent_state_change); 03978 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_LATENCY], &latency); 03979 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_EXECUTIONTIME], &execution_time); 03980 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTSTATE], ¤t_state); 03981 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HASBEENCHECKED], &has_been_checked); 03982 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SHOULDBESCHEDULED], &should_be_scheduled); 03983 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTCHECKATTEMPT], ¤t_check_attempt); 03984 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_MAXCHECKATTEMPTS], &max_check_attempts); 03985 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CHECKTYPE], &check_type); 03986 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_LASTHARDSTATE], &last_hard_state); 03987 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATETYPE], &state_type); 03988 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOMORENOTIFICATIONS], &no_more_notifications); 03989 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFICATIONSENABLED], ¬ifications_enabled); 03990 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PROBLEMHASBEENACKNOWLEDGED], &problem_has_been_acknowledged); 03991 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACKNOWLEDGEMENTTYPE], &acknowledgement_type); 03992 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTNOTIFICATIONNUMBER], ¤t_notification_number); 03993 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PASSIVEHOSTCHECKSENABLED], &passive_checks_enabled); 03994 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACTIVEHOSTCHECKSENABLED], &active_checks_enabled); 03995 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EVENTHANDLERENABLED], &event_handler_enabled); 03996 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONENABLED], &flap_detection_enabled); 03997 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ISFLAPPING], &is_flapping); 03998 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SCHEDULEDDOWNTIMEDEPTH], &scheduled_downtime_depth); 03999 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILUREPREDICTIONENABLED], &failure_prediction_enabled); 04000 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PROCESSPERFORMANCEDATA], &process_performance_data); 04001 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_OBSESSOVERHOST], &obsess_over_host); 04002 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_NORMALCHECKINTERVAL], &normal_check_interval); 04003 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_RETRYCHECKINTERVAL], &retry_check_interval); 04004 04005 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_OUTPUT]); 04006 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LONGOUTPUT]); 04007 es[2] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_PERFDATA]); 04008 es[3] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_EVENTHANDLER]); 04009 es[4] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_CHECKCOMMAND]); 04010 04011 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 04012 ts[1] = ido2db_db_timet_to_sql(idi, last_check); 04013 ts[2] = ido2db_db_timet_to_sql(idi, next_check); 04014 ts[3] = ido2db_db_timet_to_sql(idi, last_state_change); 04015 ts[4] = ido2db_db_timet_to_sql(idi, last_hard_state_change); 04016 ts[5] = ido2db_db_timet_to_sql(idi, last_time_up); 04017 ts[6] = ido2db_db_timet_to_sql(idi, last_time_down); 04018 ts[7] = ido2db_db_timet_to_sql(idi, last_time_unreachable); 04019 ts[8] = ido2db_db_timet_to_sql(idi, last_notification); 04020 ts[9] = ido2db_db_timet_to_sql(idi, next_notification); 04021 04022 /* get the object id */ 04023 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 04024 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_HOSTCHECKPERIOD], NULL, &check_timeperiod_object_id); 04025 04026 /* save entry to db */ 04027 data[0] = (void *) &idi->dbinfo.instance_id; 04028 data[1] = (void *) &object_id; 04029 data[2] = (void *) &ts[0]; 04030 data[3] = (void *) &es[0]; 04031 data[4] = (void *) &es[1]; 04032 data[5] = (void *) &es[2]; 04033 data[6] = (void *) ¤t_state; 04034 data[7] = (void *) &has_been_checked; 04035 data[8] = (void *) &should_be_scheduled; 04036 data[9] = (void *) ¤t_check_attempt; 04037 data[10] = (void *) &max_check_attempts; 04038 data[11] = (void *) &ts[1]; 04039 data[12] = (void *) &ts[2]; 04040 data[13] = (void *) &check_type; 04041 data[14] = (void *) &ts[3]; 04042 data[15] = (void *) &ts[4]; 04043 data[16] = (void *) &last_hard_state; 04044 data[17] = (void *) &ts[5]; 04045 data[18] = (void *) &ts[6]; 04046 data[19] = (void *) &ts[7]; 04047 data[20] = (void *) &state_type; 04048 data[21] = (void *) &ts[8]; 04049 data[22] = (void *) &ts[9]; 04050 data[23] = (void *) &no_more_notifications; 04051 data[24] = (void *) ¬ifications_enabled; 04052 data[25] = (void *) &problem_has_been_acknowledged; 04053 data[26] = (void *) &acknowledgement_type; 04054 data[27] = (void *) ¤t_notification_number; 04055 data[28] = (void *) &passive_checks_enabled; 04056 data[29] = (void *) &active_checks_enabled; 04057 data[30] = (void *) &event_handler_enabled; 04058 data[31] = (void *) &flap_detection_enabled; 04059 data[32] = (void *) &is_flapping; 04060 data[33] = (void *) &percent_state_change; 04061 data[34] = (void *) &latency; 04062 data[35] = (void *) &execution_time; 04063 data[36] = (void *) &scheduled_downtime_depth; 04064 data[37] = (void *) &failure_prediction_enabled; 04065 data[38] = (void *) &process_performance_data; 04066 data[39] = (void *) &obsess_over_host; 04067 data[40] = (void *) &modified_host_attributes; 04068 data[41] = (void *) &es[3]; 04069 data[42] = (void *) &es[4]; 04070 data[43] = (void *) &normal_check_interval; 04071 data[44] = (void *) &retry_check_interval; 04072 data[45] = (void *) &check_timeperiod_object_id; 04073 /* add unixtime for bind params */ 04074 data[46] = (void *) &tstamp.tv_sec; 04075 data[47] = (void *) &last_check; 04076 data[48] = (void *) &next_check; 04077 data[49] = (void *) &last_state_change; 04078 data[50] = (void *) &last_hard_state_change; 04079 data[51] = (void *) &last_time_up; 04080 data[52] = (void *) &last_time_down; 04081 data[53] = (void *) &last_time_unreachable; 04082 data[54] = (void *) &last_notification; 04083 data[55] = (void *) &next_notification; 04084 04085 04086 result = ido2db_query_insert_or_update_hoststatusdata_add(idi, data); 04087 04088 #ifdef USE_LIBDBI /* everything else will be libdbi */ 04089 dbi_result_free(idi->dbinfo.dbi_result); 04090 #endif 04091 04092 #ifdef USE_PGSQL /* pgsql */ 04093 04094 #endif 04095 04096 #ifdef USE_ORACLE /* Oracle ocilib specific */ 04097 04098 /* do not free if prepared statement */ 04099 04100 #endif /* Oracle ocilib specific */ 04101 04102 /* save custom variables to db */ 04103 result=ido2db_save_custom_variables(idi,IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS,object_id,ts[0], tstamp.tv_sec); 04104 04105 /* free memory */ 04106 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 04107 free(ts[x]); 04108 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 04109 free(es[x]); 04110 04111 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hoststatusdata() end\n"); 04112 04113 return IDO_OK; 04114 } 04115 04116 int ido2db_handle_servicestatusdata(ido2db_idi *idi) { 04117 int type, flags, attr; 04118 struct timeval tstamp; 04119 unsigned long last_check = 0L; 04120 unsigned long next_check = 0L; 04121 unsigned long last_state_change = 0L; 04122 unsigned long last_hard_state_change = 0L; 04123 unsigned long last_time_ok = 0L; 04124 unsigned long last_time_warning = 0L; 04125 unsigned long last_time_unknown = 0L; 04126 unsigned long last_time_critical = 0L; 04127 unsigned long last_notification = 0L; 04128 unsigned long next_notification = 0L; 04129 unsigned long modified_service_attributes = 0L; 04130 double percent_state_change = 0.0; 04131 double latency = 0.0; 04132 double execution_time = 0.0; 04133 int current_state = 0; 04134 int has_been_checked = 0; 04135 int should_be_scheduled = 0; 04136 int current_check_attempt = 0; 04137 int max_check_attempts = 0; 04138 int check_type = 0; 04139 int last_hard_state = 0; 04140 int state_type = 0; 04141 int no_more_notifications = 0; 04142 int notifications_enabled = 0; 04143 int problem_has_been_acknowledged = 0; 04144 int acknowledgement_type = 0; 04145 int current_notification_number = 0; 04146 int passive_checks_enabled = 0; 04147 int active_checks_enabled = 0; 04148 int event_handler_enabled; 04149 int flap_detection_enabled = 0; 04150 int is_flapping = 0; 04151 int scheduled_downtime_depth = 0; 04152 int failure_prediction_enabled = 0; 04153 int process_performance_data; 04154 int obsess_over_service = 0; 04155 double normal_check_interval = 0.0; 04156 double retry_check_interval = 0.0; 04157 char *ts[11]; 04158 char *es[5]; 04159 unsigned long object_id = 0L; 04160 unsigned long check_timeperiod_object_id = 0L; 04161 int x = 0; 04162 int result = IDO_OK; 04163 void *data[58]; 04164 04165 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicestatusdata() start\n"); 04166 04167 if (idi == NULL) 04168 return IDO_ERROR; 04169 04170 /* convert timestamp, etc */ 04171 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 04172 04173 /* don't store old data */ 04174 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 04175 return IDO_OK; 04176 04177 /* covert vars */ 04178 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTSERVICECHECK], &last_check); 04179 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_NEXTSERVICECHECK], &next_check); 04180 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTSTATECHANGE], &last_state_change); 04181 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTHARDSTATECHANGE], &last_hard_state_change); 04182 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTTIMEOK], &last_time_ok); 04183 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTTIMEWARNING], &last_time_warning); 04184 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTTIMEUNKNOWN], &last_time_unknown); 04185 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTTIMECRITICAL], &last_time_critical); 04186 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_LASTSERVICENOTIFICATION], &last_notification); 04187 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_NEXTSERVICENOTIFICATION], &next_notification); 04188 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_MODIFIEDSERVICEATTRIBUTES], &modified_service_attributes); 04189 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_PERCENTSTATECHANGE], &percent_state_change); 04190 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_LATENCY], &latency); 04191 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_EXECUTIONTIME], &execution_time); 04192 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTSTATE], ¤t_state); 04193 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HASBEENCHECKED], &has_been_checked); 04194 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SHOULDBESCHEDULED], &should_be_scheduled); 04195 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTCHECKATTEMPT], ¤t_check_attempt); 04196 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_MAXCHECKATTEMPTS], &max_check_attempts); 04197 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CHECKTYPE], &check_type); 04198 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_LASTHARDSTATE], &last_hard_state); 04199 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATETYPE], &state_type); 04200 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOMORENOTIFICATIONS], &no_more_notifications); 04201 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFICATIONSENABLED], ¬ifications_enabled); 04202 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PROBLEMHASBEENACKNOWLEDGED], &problem_has_been_acknowledged); 04203 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACKNOWLEDGEMENTTYPE], &acknowledgement_type); 04204 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTNOTIFICATIONNUMBER], ¤t_notification_number); 04205 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PASSIVESERVICECHECKSENABLED], &passive_checks_enabled); 04206 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACTIVESERVICECHECKSENABLED], &active_checks_enabled); 04207 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_EVENTHANDLERENABLED], &event_handler_enabled); 04208 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONENABLED], &flap_detection_enabled); 04209 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ISFLAPPING], &is_flapping); 04210 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SCHEDULEDDOWNTIMEDEPTH], &scheduled_downtime_depth); 04211 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILUREPREDICTIONENABLED], &failure_prediction_enabled); 04212 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PROCESSPERFORMANCEDATA], &process_performance_data); 04213 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_OBSESSOVERSERVICE], &obsess_over_service); 04214 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_NORMALCHECKINTERVAL], &normal_check_interval); 04215 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_RETRYCHECKINTERVAL], &retry_check_interval); 04216 04217 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_OUTPUT]); 04218 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LONGOUTPUT]); 04219 es[2] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_PERFDATA]); 04220 es[3] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_EVENTHANDLER]); 04221 es[4] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_CHECKCOMMAND]); 04222 04223 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 04224 ts[1] = ido2db_db_timet_to_sql(idi, last_check); 04225 ts[2] = ido2db_db_timet_to_sql(idi, next_check); 04226 ts[3] = ido2db_db_timet_to_sql(idi, last_state_change); 04227 ts[4] = ido2db_db_timet_to_sql(idi, last_hard_state_change); 04228 ts[5] = ido2db_db_timet_to_sql(idi, last_time_ok); 04229 ts[6] = ido2db_db_timet_to_sql(idi, last_time_warning); 04230 ts[7] = ido2db_db_timet_to_sql(idi, last_time_unknown); 04231 ts[8] = ido2db_db_timet_to_sql(idi, last_time_critical); 04232 ts[9] = ido2db_db_timet_to_sql(idi, last_notification); 04233 ts[10] = ido2db_db_timet_to_sql(idi, next_notification); 04234 04235 /* get the object id */ 04236 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, 04237 idi->buffered_input[IDO_DATA_HOST], 04238 idi->buffered_input[IDO_DATA_SERVICE], &object_id); 04239 result = ido2db_get_object_id_with_insert(idi, 04240 IDO2DB_OBJECTTYPE_TIMEPERIOD, 04241 idi->buffered_input[IDO_DATA_SERVICECHECKPERIOD], NULL, 04242 &check_timeperiod_object_id); 04243 04244 /* save entry to db */ 04245 data[0] = (void *) &idi->dbinfo.instance_id; 04246 data[1] = (void *) &object_id; 04247 data[2] = (void *) &ts[0]; 04248 data[3] = (void *) &es[0]; 04249 data[4] = (void *) &es[1]; 04250 data[5] = (void *) &es[2]; 04251 data[6] = (void *) ¤t_state; 04252 data[7] = (void *) &has_been_checked; 04253 data[8] = (void *) &should_be_scheduled; 04254 data[9] = (void *) ¤t_check_attempt; 04255 data[10] = (void *) &max_check_attempts; 04256 data[11] = (void *) &ts[1]; 04257 data[12] = (void *) &ts[2]; 04258 data[13] = (void *) &check_type; 04259 data[14] = (void *) &ts[3]; 04260 data[15] = (void *) &ts[4]; 04261 data[16] = (void *) &last_hard_state; 04262 data[17] = (void *) &ts[5]; 04263 data[18] = (void *) &ts[6]; 04264 data[19] = (void *) &ts[7]; 04265 data[20] = (void *) &ts[8]; 04266 data[21] = (void *) &state_type; 04267 data[22] = (void *) &ts[9]; 04268 data[23] = (void *) &ts[10]; 04269 data[24] = (void *) &no_more_notifications; 04270 data[25] = (void *) ¬ifications_enabled; 04271 data[26] = (void *) &problem_has_been_acknowledged; 04272 data[27] = (void *) &acknowledgement_type; 04273 data[28] = (void *) ¤t_notification_number; 04274 data[29] = (void *) &passive_checks_enabled; 04275 data[30] = (void *) &active_checks_enabled; 04276 data[31] = (void *) &event_handler_enabled; 04277 data[32] = (void *) &flap_detection_enabled; 04278 data[33] = (void *) &is_flapping; 04279 data[34] = (void *) &percent_state_change; 04280 data[35] = (void *) &latency; 04281 data[36] = (void *) &execution_time; 04282 data[37] = (void *) &scheduled_downtime_depth; 04283 data[38] = (void *) &failure_prediction_enabled; 04284 data[39] = (void *) &process_performance_data; 04285 data[40] = (void *) &obsess_over_service; 04286 data[41] = (void *) &modified_service_attributes; 04287 data[42] = (void *) &es[3]; 04288 data[43] = (void *) &es[4]; 04289 data[44] = (void *) &normal_check_interval; 04290 data[45] = (void *) &retry_check_interval; 04291 data[46] = (void *) &check_timeperiod_object_id; 04292 /* add unixtime for bind params */ 04293 data[47] = (void *) &tstamp.tv_sec; 04294 data[48] = (void *) &last_check; 04295 data[49] = (void *) &next_check; 04296 data[50] = (void *) &last_state_change; 04297 data[51] = (void *) &last_hard_state_change; 04298 data[52] = (void *) &last_time_ok; 04299 data[53] = (void *) &last_time_warning; 04300 data[54] = (void *) &last_time_unknown; 04301 data[55] = (void *) &last_time_critical; 04302 data[56] = (void *) &last_notification; 04303 data[57] = (void *) &next_notification; 04304 04305 result = ido2db_query_insert_or_update_servicestatusdata_add(idi, data); 04306 04307 #ifdef USE_LIBDBI /* everything else will be libdbi */ 04308 dbi_result_free(idi->dbinfo.dbi_result); 04309 #endif 04310 04311 #ifdef USE_PGSQL /* pgsql */ 04312 04313 #endif 04314 04315 #ifdef USE_ORACLE /* Oracle ocilib specific */ 04316 04317 /* do not free if prepared statement */ 04318 04319 #endif /* Oracle ocilib specific */ 04320 04321 /* free memory */ 04322 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 04323 free(es[x]); 04324 04325 /* save custom variables to db */ 04326 result=ido2db_save_custom_variables(idi,IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS,object_id,ts[0], tstamp.tv_sec); 04327 04328 /* free memory */ 04329 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 04330 free(ts[x]); 04331 04332 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicestatusdata() end\n"); 04333 04334 return IDO_OK; 04335 } 04336 04337 int ido2db_handle_contactstatusdata(ido2db_idi *idi) { 04338 int type, flags, attr; 04339 struct timeval tstamp; 04340 unsigned long last_host_notification = 0L; 04341 unsigned long last_service_notification = 0L; 04342 unsigned long modified_attributes = 0L; 04343 unsigned long modified_host_attributes = 0L; 04344 unsigned long modified_service_attributes = 0L; 04345 int host_notifications_enabled = 0; 04346 int service_notifications_enabled = 0; 04347 char *ts[3]; 04348 unsigned long object_id = 0L; 04349 int x = 0; 04350 int result = IDO_OK; 04351 void *data[13]; 04352 04353 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactstatusdata() start\n"); 04354 04355 if (idi == NULL) 04356 return IDO_ERROR; 04357 04358 /* convert timestamp, etc */ 04359 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 04360 &tstamp); 04361 04362 /* don't store old data */ 04363 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 04364 return IDO_OK; 04365 04366 /* covert vars */ 04367 result = ido2db_convert_string_to_unsignedlong( idi->buffered_input[IDO_DATA_LASTHOSTNOTIFICATION], &last_host_notification); 04368 result = ido2db_convert_string_to_unsignedlong( idi->buffered_input[IDO_DATA_LASTSERVICENOTIFICATION], &last_service_notification); 04369 result = ido2db_convert_string_to_unsignedlong( idi->buffered_input[IDO_DATA_MODIFIEDCONTACTATTRIBUTES], &modified_attributes); 04370 result = ido2db_convert_string_to_unsignedlong( idi->buffered_input[IDO_DATA_MODIFIEDHOSTATTRIBUTES], &modified_host_attributes); 04371 result = ido2db_convert_string_to_unsignedlong( idi->buffered_input[IDO_DATA_MODIFIEDSERVICEATTRIBUTES], &modified_service_attributes); 04372 result = ido2db_convert_string_to_int( idi->buffered_input[IDO_DATA_HOSTNOTIFICATIONSENABLED], &host_notifications_enabled); 04373 result = ido2db_convert_string_to_int( idi->buffered_input[IDO_DATA_SERVICENOTIFICATIONSENABLED], &service_notifications_enabled); 04374 04375 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 04376 ts[1] = ido2db_db_timet_to_sql(idi, last_host_notification); 04377 ts[2] = ido2db_db_timet_to_sql(idi, last_service_notification); 04378 04379 /* get the object id */ 04380 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_CONTACT, idi->buffered_input[IDO_DATA_CONTACTNAME], NULL, &object_id); 04381 04382 /* save entry to db */ 04383 data[0] = (void *) &idi->dbinfo.instance_id; 04384 data[1] = (void *) &object_id; 04385 data[2] = (void *) &ts[0]; 04386 data[3] = (void *) &host_notifications_enabled; 04387 data[4] = (void *) &service_notifications_enabled; 04388 data[5] = (void *) &ts[1]; 04389 data[6] = (void *) &ts[2]; 04390 data[7] = (void *) &modified_attributes; 04391 data[8] = (void *) &modified_host_attributes; 04392 data[9] = (void *) &modified_service_attributes; 04393 /* bind params */ 04394 data [10] = (void *) &tstamp.tv_sec; 04395 data [11] = (void *) &last_host_notification; 04396 data [12] = (void *) &last_service_notification; 04397 04398 result = ido2db_query_insert_or_update_contactstatusdata_add(idi, data); 04399 04400 #ifdef USE_LIBDBI /* everything else will be libdbi */ 04401 dbi_result_free(idi->dbinfo.dbi_result); 04402 #endif 04403 04404 #ifdef USE_PGSQL /* pgsql */ 04405 04406 #endif 04407 04408 #ifdef USE_ORACLE /* Oracle ocilib specific */ 04409 04410 04411 #endif /* Oracle ocilib specific */ 04412 04413 /* save custom variables to db */ 04414 result=ido2db_save_custom_variables(idi,IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS,object_id,ts[0], tstamp.tv_sec); 04415 04416 /* free memory */ 04417 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 04418 free(ts[x]); 04419 04420 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactstatusdata() end\n"); 04421 04422 return IDO_OK; 04423 } 04424 04425 int ido2db_handle_adaptiveprogramdata(ido2db_idi *idi) { 04426 04427 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_adaptiveprogramdata() start\n"); 04428 04429 if (idi == NULL) 04430 return IDO_ERROR; 04431 04432 /* IGNORED */ 04433 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_adaptiveprogramdata() end\n"); 04434 04435 return IDO_OK; 04436 } 04437 04438 int ido2db_handle_adaptivehostdata(ido2db_idi *idi) { 04439 04440 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_adaptivehostdata() start\n"); 04441 04442 if (idi == NULL) 04443 return IDO_ERROR; 04444 04445 /* IGNORED */ 04446 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_adaptivehostdata() end\n"); 04447 04448 return IDO_OK; 04449 } 04450 04451 int ido2db_handle_adaptiveservicedata(ido2db_idi *idi) { 04452 04453 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_adaptiveservicedata() start\n"); 04454 04455 if (idi == NULL) 04456 return IDO_ERROR; 04457 04458 /* IGNORED */ 04459 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_adaptiveservicedata() end\n"); 04460 04461 return IDO_OK; 04462 } 04463 04464 int ido2db_handle_adaptivecontactdata(ido2db_idi *idi) { 04465 04466 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_adaptivecontactdata() start\n"); 04467 04468 if (idi == NULL) 04469 return IDO_ERROR; 04470 04471 /* IGNORED */ 04472 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_adaptivecontactdata() end\n"); 04473 04474 return IDO_OK; 04475 } 04476 04477 int ido2db_handle_externalcommanddata(ido2db_idi *idi) { 04478 int type, flags, attr; 04479 int x = 0; 04480 struct timeval tstamp; 04481 char *ts = NULL; 04482 char *es[2]; 04483 int command_type = 0; 04484 unsigned long entry_time = 0L; 04485 char *buf = NULL; 04486 int result = IDO_OK; 04487 04488 #ifdef USE_ORACLE 04489 void *data[5]; 04490 #endif 04491 04492 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_externalcommanddata() start\n"); 04493 04494 if (idi == NULL) 04495 return IDO_ERROR; 04496 04497 /* convert timestamp, etc */ 04498 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 04499 &tstamp); 04500 04501 /* only handle start events */ 04502 if (type != NEBTYPE_EXTERNALCOMMAND_START) 04503 return IDO_OK; 04504 04505 /* covert vars */ 04506 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_COMMANDTYPE], &command_type); 04507 result = ido2db_convert_string_to_unsignedlong(idi->buffered_input[IDO_DATA_ENTRYTIME], &entry_time); 04508 04509 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDSTRING]); 04510 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDARGS]); 04511 04512 ts = ido2db_db_timet_to_sql(idi, entry_time); 04513 04514 /* save entry to db */ 04515 #ifdef USE_LIBDBI /* everything else will be libdbi */ 04516 if (asprintf(&buf, "INSERT INTO %s (instance_id, command_type, entry_time, command_name, command_args) VALUES ('%lu', '%d', %s, '%s', '%s')", 04517 ido2db_db_tablenames[IDO2DB_DBTABLE_EXTERNALCOMMANDS], 04518 idi->dbinfo.instance_id, command_type, ts, es[0], es[1]) == -1) 04519 buf = NULL; 04520 result = ido2db_db_query(idi, buf); 04521 04522 dbi_result_free(idi->dbinfo.dbi_result); 04523 #endif 04524 04525 #ifdef USE_PGSQL /* pgsql */ 04526 04527 #endif 04528 04529 #ifdef USE_ORACLE /* Oracle ocilib specific */ 04530 04531 /* check if we lost connection, and reconnect */ 04532 if(ido2db_db_reconnect(idi)==IDO_ERROR) 04533 return IDO_ERROR; 04534 04535 data[0] = (void *) &idi->dbinfo.instance_id; 04536 data[1] = (void *) &command_type; 04537 data[2] = (void *) &entry_time; 04538 data[3] = (void *) &es[0]; 04539 data[4] = (void *) &es[1]; 04540 04541 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_external_commands, MT(":X1"), (big_uint *) data[0])) { 04542 return IDO_ERROR; 04543 } 04544 if(!OCI_BindInt(idi->dbinfo.oci_statement_external_commands, MT(":X2"), (int *) data[1])) { 04545 return IDO_ERROR; 04546 } 04547 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_external_commands, MT(":X3"), (big_uint *) data[2])) { /* unixtimestamp instead of time2sql */ 04548 return IDO_ERROR; 04549 } 04550 if(es[0]==NULL) { 04551 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_external_commands, ":X4")==IDO_ERROR) { 04552 return IDO_ERROR; 04553 } 04554 } else { 04555 if(!OCI_BindString(idi->dbinfo.oci_statement_external_commands, MT(":X4"), *(char **) data[3], 0)) { 04556 return IDO_ERROR; 04557 } 04558 } 04559 if(es[1]==NULL) { 04560 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_external_commands, ":X5")==IDO_ERROR) { 04561 return IDO_ERROR; 04562 } 04563 } else { 04564 if(!OCI_BindString(idi->dbinfo.oci_statement_external_commands, MT(":X5"), *(char **) data[4], 0)) { 04565 return IDO_ERROR; 04566 } 04567 } 04568 /* execute statement */ 04569 if(!OCI_Execute(idi->dbinfo.oci_statement_external_commands)) { 04570 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_external_commands() execute error\n"); 04571 return IDO_ERROR; 04572 } 04573 04574 /* commit statement */ 04575 OCI_Commit(idi->dbinfo.oci_connection); 04576 04577 /* do not free statement yet! */ 04578 04579 #endif /* Oracle ocilib specific */ 04580 04581 free(buf); 04582 04583 /* free memory */ 04584 free(ts); 04585 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 04586 free(es[x]); 04587 04588 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_externalcommanddata() end\n"); 04589 04590 return IDO_OK; 04591 } 04592 04593 int ido2db_handle_aggregatedstatusdata(ido2db_idi *idi) { 04594 04595 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_aggregatedstatusdata() start\n"); 04596 04597 if (idi == NULL) 04598 return IDO_ERROR; 04599 04600 /* IGNORED */ 04601 04602 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_aggregatedstatusdata() end\n"); 04603 04604 return IDO_OK; 04605 } 04606 04607 int ido2db_handle_retentiondata(ido2db_idi *idi) { 04608 04609 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_retentiondata() start\n"); 04610 04611 if (idi == NULL) 04612 return IDO_ERROR; 04613 04614 /* IGNORED */ 04615 04616 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_retentiondata() end\n"); 04617 04618 return IDO_OK; 04619 } 04620 04621 int ido2db_handle_acknowledgementdata(ido2db_idi *idi) { 04622 int type, flags, attr; 04623 struct timeval tstamp; 04624 int acknowledgement_type = 0; 04625 int state = 0; 04626 int is_sticky = 0; 04627 int persistent_comment = 0; 04628 int notify_contacts = 0; 04629 unsigned long object_id = 0L; 04630 int result = IDO_OK; 04631 char *ts[1]; 04632 char *es[2]; 04633 int x = 0; 04634 #ifdef USE_LIBDBI 04635 char *buf = NULL; 04636 char *buf1 = NULL; 04637 #endif 04638 04639 #ifdef USE_ORACLE 04640 void *data[11]; 04641 #endif 04642 04643 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_acknowledgementdata() start\n"); 04644 04645 if (idi == NULL) 04646 return IDO_ERROR; 04647 04648 /* convert timestamp, etc */ 04649 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 04650 &tstamp); 04651 04652 /* convert vars */ 04653 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACKNOWLEDGEMENTTYPE], &acknowledgement_type); 04654 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATE], &state); 04655 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STICKY], &is_sticky); 04656 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PERSISTENT], &persistent_comment); 04657 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYCONTACTS], ¬ify_contacts); 04658 04659 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_AUTHORNAME]); 04660 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMENT]); 04661 04662 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 04663 04664 /* get the object id */ 04665 if (acknowledgement_type == SERVICE_ACKNOWLEDGEMENT) 04666 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOST], idi->buffered_input[IDO_DATA_SERVICE], &object_id); 04667 if (acknowledgement_type == HOST_ACKNOWLEDGEMENT) 04668 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 04669 04670 /* save entry to db */ 04671 /* NOTE Primary Key and only unique key is auto_increment thus ON DUPLICATE KEY will not occur ever */ 04672 04673 #ifdef USE_LIBDBI /* everything else will be libdbi */ 04674 /* the data part of the INSERT statement */ 04675 if(asprintf(&buf1,"(instance_id, entry_time, entry_time_usec, acknowledgement_type, object_id, state, author_name, comment_data, is_sticky, persistent_comment, notify_contacts) VALUES (%lu, %s, %lu, %d, %lu, %d, '%s', '%s', %d, %d, %d)" 04676 ,idi->dbinfo.instance_id 04677 ,ts[0] 04678 ,tstamp.tv_usec 04679 ,acknowledgement_type 04680 ,object_id 04681 ,state 04682 ,es[0] 04683 ,es[1] 04684 ,is_sticky 04685 ,persistent_comment 04686 ,notify_contacts 04687 )==-1) 04688 buf1=NULL; 04689 04690 if(asprintf(&buf,"INSERT INTO %s %s" 04691 ,ido2db_db_tablenames[IDO2DB_DBTABLE_ACKNOWLEDGEMENTS] 04692 ,buf1 04693 )==-1) 04694 buf=NULL; 04695 04696 free(buf1); 04697 04698 result = ido2db_db_query(idi, buf); 04699 free(buf); 04700 04701 dbi_result_free(idi->dbinfo.dbi_result); 04702 #endif 04703 04704 #ifdef USE_PGSQL /* pgsql */ 04705 04706 #endif 04707 04708 #ifdef USE_ORACLE /* Oracle ocilib specific */ 04709 04710 /* check if we lost connection, and reconnect */ 04711 if(ido2db_db_reconnect(idi)==IDO_ERROR) 04712 return IDO_ERROR; 04713 04714 data[0] = (void *) &idi->dbinfo.instance_id; 04715 data[1] = (void *) &tstamp.tv_sec; 04716 data[2] = (void *) &tstamp.tv_usec; 04717 data[3] = (void *) &acknowledgement_type; 04718 data[4] = (void *) &object_id; 04719 data[5] = (void *) &state; 04720 data[6] = (void *) &es[0]; 04721 data[7] = (void *) &es[1]; 04722 data[8] = (void *) &is_sticky; 04723 data[9] = (void *) &persistent_comment; 04724 data[10] = (void *) ¬ify_contacts; 04725 04726 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X1"), (big_uint *) data[0])) { 04727 return IDO_ERROR; 04728 } 04729 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X2"), (big_uint *) data[1])) { /* unixtimestamp instead of time2sql */ 04730 return IDO_ERROR; 04731 } 04732 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X3"), (big_uint *) data[2])) { 04733 return IDO_ERROR; 04734 } 04735 if(!OCI_BindInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X4"), (int *) data[3])) { 04736 return IDO_ERROR; 04737 } 04738 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X5"), (big_uint *) data[4])) { 04739 return IDO_ERROR; 04740 } 04741 if(!OCI_BindInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X6"), (int *) data[5])) { 04742 return IDO_ERROR; 04743 } 04744 if(es[0]==NULL) { 04745 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_acknowledgements, ":X7")==IDO_ERROR) { 04746 return IDO_ERROR; 04747 } 04748 } else { 04749 if(!OCI_BindString(idi->dbinfo.oci_statement_acknowledgements, MT(":X7"), *(char **) data[6], 0)) { 04750 return IDO_ERROR; 04751 } 04752 } 04753 if(es[1]==NULL) { 04754 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_acknowledgements, ":X8")==IDO_ERROR) { 04755 return IDO_ERROR; 04756 } 04757 } else { 04758 if(!OCI_BindString(idi->dbinfo.oci_statement_acknowledgements, MT(":X8"), *(char **) data[7], 0)) { 04759 return IDO_ERROR; 04760 } 04761 } 04762 if(!OCI_BindInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X9"), (int *) data[8])) { 04763 return IDO_ERROR; 04764 } 04765 if(!OCI_BindInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X10"), (int *) data[9])) { 04766 return IDO_ERROR; 04767 } 04768 if(!OCI_BindInt(idi->dbinfo.oci_statement_acknowledgements, MT(":X11"), (int *) data[10])) { 04769 return IDO_ERROR; 04770 } 04771 04772 /* execute statement */ 04773 if(!OCI_Execute(idi->dbinfo.oci_statement_acknowledgements)) { 04774 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_acknowledgements() execute error\n"); 04775 return IDO_ERROR; 04776 } 04777 04778 /* commit statement */ 04779 OCI_Commit(idi->dbinfo.oci_connection); 04780 04781 /* do not free statement yet! */ 04782 04783 #endif /* Oracle ocilib specific */ 04784 04785 /* free memory */ 04786 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 04787 free(ts[x]); 04788 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 04789 free(es[x]); 04790 04791 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_acknowledgementdata() end\n"); 04792 04793 return IDO_OK; 04794 } 04795 04796 int ido2db_handle_statechangedata(ido2db_idi *idi) { 04797 int type, flags, attr; 04798 int x = 0; 04799 struct timeval tstamp; 04800 int statechange_type = 0; 04801 int state_change_occurred = 0; 04802 int state = 0; 04803 int state_type = 0; 04804 int current_attempt = 0; 04805 int max_attempts = 0; 04806 int last_state = -1; 04807 int last_hard_state = -1; 04808 unsigned long object_id = 0L; 04809 int result = IDO_OK; 04810 char *ts[1]; 04811 char *es[2]; 04812 char *buf = NULL; 04813 04814 #ifdef USE_ORACLE 04815 void *data[13]; 04816 #endif 04817 04818 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_statechangedata() start\n"); 04819 04820 if (idi == NULL) 04821 return IDO_ERROR; 04822 04823 /* convert timestamp, etc */ 04824 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 04825 &tstamp); 04826 04827 /* only process completed state changes */ 04828 if (type != NEBTYPE_STATECHANGE_END) 04829 return IDO_OK; 04830 04831 /* convert vars */ 04832 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATECHANGETYPE], &statechange_type); 04833 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATECHANGE], &state_change_occurred); 04834 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATE], &state); 04835 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STATETYPE], &state_type); 04836 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CURRENTCHECKATTEMPT], ¤t_attempt); 04837 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_MAXCHECKATTEMPTS], &max_attempts); 04838 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_LASTHARDSTATE], &last_hard_state); 04839 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_LASTSTATE], &last_state); 04840 04841 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_OUTPUT]); 04842 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_LONGOUTPUT]); 04843 04844 ts[0] = ido2db_db_timet_to_sql(idi, tstamp.tv_sec); 04845 04846 /* get the object id */ 04847 if (statechange_type == SERVICE_STATECHANGE) 04848 result = ido2db_get_object_id_with_insert(idi, 04849 IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOST], 04850 idi->buffered_input[IDO_DATA_SERVICE], &object_id); 04851 else 04852 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, 04853 idi->buffered_input[IDO_DATA_HOST], NULL, &object_id); 04854 04855 /* save entry to db */ 04856 #ifdef USE_LIBDBI /* everything else will be libdbi */ 04857 if (asprintf( 04858 &buf, 04859 "INSERT INTO %s (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 ('%lu', %s, '%lu', '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%s')", 04860 ido2db_db_tablenames[IDO2DB_DBTABLE_STATEHISTORY], 04861 idi->dbinfo.instance_id, ts[0], tstamp.tv_usec, object_id, 04862 state_change_occurred, state, state_type, current_attempt, 04863 max_attempts, last_state, last_hard_state, es[0], es[1]) == -1) 04864 buf = NULL; 04865 04866 result = ido2db_db_query(idi, buf); 04867 04868 dbi_result_free(idi->dbinfo.dbi_result); 04869 #endif 04870 04871 #ifdef USE_PGSQL /* pgsql */ 04872 04873 #endif 04874 04875 #ifdef USE_ORACLE /* Oracle ocilib specific */ 04876 04877 /* check if we lost connection, and reconnect */ 04878 if(ido2db_db_reconnect(idi)==IDO_ERROR) 04879 return IDO_ERROR; 04880 04881 data[0] = (void *) &idi->dbinfo.instance_id; 04882 data[1] = (void *) &tstamp.tv_sec; 04883 data[2] = (void *) &tstamp.tv_usec; 04884 data[3] = (void *) &object_id; 04885 data[4] = (void *) &state_change_occurred; 04886 data[5] = (void *) &state; 04887 data[6] = (void *) &state_type; 04888 data[7] = (void *) ¤t_attempt; 04889 data[8] = (void *) &max_attempts; 04890 data[9] = (void *) &last_state; 04891 data[10] = (void *) &last_hard_state; 04892 data[11] = (void *) &es[0]; 04893 data[12] = (void *) &es[1]; 04894 04895 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_statehistory, MT(":X1"), (big_uint *) data[0])) { 04896 return IDO_ERROR; 04897 } 04898 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_statehistory, MT(":X2"), (big_uint *) data[1])) { /* unixtimestamp instead of time2sql */ 04899 return IDO_ERROR; 04900 } 04901 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_statehistory, MT(":X3"), (big_uint *) data[2])) { 04902 return IDO_ERROR; 04903 } 04904 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_statehistory, MT(":X4"), (big_uint *) data[3])) { 04905 return IDO_ERROR; 04906 } 04907 if(!OCI_BindInt(idi->dbinfo.oci_statement_statehistory, MT(":X5"), (int *) data[4])) { 04908 return IDO_ERROR; 04909 } 04910 if(!OCI_BindInt(idi->dbinfo.oci_statement_statehistory, MT(":X6"), (int *) data[5])) { 04911 return IDO_ERROR; 04912 } 04913 if(!OCI_BindInt(idi->dbinfo.oci_statement_statehistory, MT(":X7"), (int *) data[6])) { 04914 return IDO_ERROR; 04915 } 04916 if(!OCI_BindInt(idi->dbinfo.oci_statement_statehistory, MT(":X8"), (int *) data[7])) { 04917 return IDO_ERROR; 04918 } 04919 if(!OCI_BindInt(idi->dbinfo.oci_statement_statehistory, MT(":X9"), (int *) data[8])) { 04920 return IDO_ERROR; 04921 } 04922 if(!OCI_BindInt(idi->dbinfo.oci_statement_statehistory, MT(":X10"), (int *) data[9])) { 04923 return IDO_ERROR; 04924 } 04925 if(!OCI_BindInt(idi->dbinfo.oci_statement_statehistory, MT(":X11"), (int *) data[10])) { 04926 return IDO_ERROR; 04927 } 04928 if(es[0]==NULL) { 04929 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_statehistory, ":X12")==IDO_ERROR) { 04930 return IDO_ERROR; 04931 } 04932 } else { 04933 if(!OCI_BindString(idi->dbinfo.oci_statement_statehistory, MT(":X12"), *(char **) data[11], 0)) { 04934 return IDO_ERROR; 04935 } 04936 } 04937 if(es[1]==NULL) { 04938 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_statehistory, ":X13")==IDO_ERROR) { 04939 return IDO_ERROR; 04940 } 04941 } else { 04942 if(!OCI_BindString(idi->dbinfo.oci_statement_statehistory, MT(":X13"), *(char **) data[12], 0)) { 04943 return IDO_ERROR; 04944 } 04945 } 04946 /* execute statement */ 04947 if(!OCI_Execute(idi->dbinfo.oci_statement_statehistory)) { 04948 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_statehistory() execute error\n"); 04949 return IDO_ERROR; 04950 } 04951 04952 /* commit statement */ 04953 OCI_Commit(idi->dbinfo.oci_connection); 04954 04955 /* do not free statement yet! */ 04956 04957 #endif /* Oracle ocilib specific */ 04958 04959 free(buf); 04960 04961 /* free memory */ 04962 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 04963 free(es[x]); 04964 for (x = 0; x < ICINGA_SIZEOF_ARRAY(ts); x++) 04965 free(ts[x]); 04966 04967 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_statechangedata() end\n"); 04968 04969 return IDO_OK; 04970 } 04971 04972 /****************************************************************************/ 04973 /* VARIABLE DATA HANDLERS */ 04974 /****************************************************************************/ 04975 04976 int ido2db_handle_configfilevariables(ido2db_idi *idi, int configfile_type) { 04977 int type, flags, attr; 04978 struct timeval tstamp; 04979 unsigned long configfile_id = 0L; 04980 int result = IDO_OK; 04981 char *es[3]; 04982 int x = 0; 04983 #ifdef USE_LIBDBI 04984 char *buf = NULL; 04985 char *buf1 = NULL; 04986 #endif 04987 char *varname = NULL; 04988 char *varvalue = NULL; 04989 ido2db_mbuf mbuf; 04990 #ifdef USE_ORACLE 04991 char *seq_name = NULL; 04992 #endif 04993 void *data[4]; 04994 04995 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_configfilevariables() start\n"); 04996 ido2db_log_debug_info(IDO2DB_DEBUGL_SQL, 0, "HANDLE_CONFIGFILEVARS [1]\n"); 04997 04998 if (idi == NULL) 04999 return IDO_ERROR; 05000 05001 /* convert timestamp, etc */ 05002 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 05003 &tstamp); 05004 05005 ido2db_log_debug_info(IDO2DB_DEBUGL_SQL, 0, "HANDLE_CONFIGFILEVARS [2]\n"); 05006 ido2db_log_debug_info(IDO2DB_DEBUGL_SQL, 0, "TSTAMP: %lu LATEST: %lu\n", tstamp.tv_sec, idi->dbinfo.latest_realtime_data_time); 05007 05008 /* don't store old data */ 05009 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 05010 return IDO_OK; 05011 05012 ido2db_log_debug_info(IDO2DB_DEBUGL_SQL, 0, "HANDLE_CONFIGFILEVARS [3]\n"); 05013 05014 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_CONFIGFILENAME]); 05015 05016 /* add config file to db */ 05017 data[0] = (void *) &idi->dbinfo.instance_id; 05018 data[1] = (void *) &configfile_type; 05019 data[2] = (void *) &es[0]; 05020 05021 result = ido2db_query_insert_or_update_configfilevariables_add(idi, data); 05022 05023 if (result == IDO_OK) { 05024 05025 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05026 switch (idi->dbinfo.server_type) { 05027 case IDO2DB_DBSERVER_MYSQL: 05028 /* mysql doesn't use sequences */ 05029 configfile_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 05030 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_configfilevariables(%lu) configfilevariables_id\n", configfile_id); 05031 break; 05032 case IDO2DB_DBSERVER_PGSQL: 05033 /* depending on tableprefix/tablename a sequence will be used */ 05034 if(asprintf(&buf1, "%s_configfile_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILES]) == -1) 05035 buf1 = NULL; 05036 05037 configfile_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf1); 05038 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_configfilevariables(%s=%lu) configfilevariables_id\n", buf1, configfile_id); 05039 free(buf1); 05040 break; 05041 case IDO2DB_DBSERVER_DB2: 05042 break; 05043 case IDO2DB_DBSERVER_FIREBIRD: 05044 break; 05045 case IDO2DB_DBSERVER_FREETDS: 05046 break; 05047 case IDO2DB_DBSERVER_INGRES: 05048 break; 05049 case IDO2DB_DBSERVER_MSQL: 05050 break; 05051 case IDO2DB_DBSERVER_ORACLE: 05052 break; 05053 case IDO2DB_DBSERVER_SQLITE: 05054 break; 05055 case IDO2DB_DBSERVER_SQLITE3: 05056 break; 05057 default: 05058 break; 05059 } 05060 #endif 05061 05062 #ifdef USE_PGSQL /* pgsql */ 05063 05064 #endif 05065 05066 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05067 if(asprintf(&seq_name, "seq_configfiles")==-1) 05068 seq_name=NULL; 05069 configfile_id = ido2db_ocilib_insert_id(idi, seq_name); 05070 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_configfilevariables(%lu) \n", configfile_id); 05071 free(seq_name); 05072 05073 #endif /* Oracle ocilib specific */ 05074 } 05075 05076 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05077 dbi_result_free(idi->dbinfo.dbi_result); 05078 #endif 05079 05080 #ifdef USE_PGSQL /* pgsql */ 05081 05082 #endif 05083 05084 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05085 05086 05087 #endif /* Oracle ocilib specific */ 05088 05089 free(es[0]); 05090 05091 /* save config file variables to db */ 05092 mbuf = idi->mbuf[IDO2DB_MBUF_CONFIGFILEVARIABLE]; 05093 for (x = 0; x < mbuf.used_lines; x++) { 05094 05095 if (mbuf.buffer[x] == NULL) 05096 continue; 05097 05098 /* get var name/val pair */ 05099 varname = strtok(mbuf.buffer[x], "="); 05100 varvalue = strtok(NULL, "\x0"); 05101 05102 es[1] = ido2db_db_escape_string(idi, varname); 05103 es[2] = ido2db_db_escape_string(idi, varvalue); 05104 05105 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05106 if (asprintf(&buf,"(instance_id, configfile_id, varname, varvalue) VALUES ('%lu', '%lu', '%s', '%s')", 05107 idi->dbinfo.instance_id, configfile_id, es[1], es[2]) == -1) 05108 buf = NULL; 05109 05110 if (asprintf(&buf1, "INSERT INTO %s %s", 05111 ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILEVARIABLES], buf) 05112 == -1) 05113 buf1 = NULL; 05114 05115 result = ido2db_db_query(idi, buf1); 05116 dbi_result_free(idi->dbinfo.dbi_result); 05117 free(buf); 05118 free(buf1); 05119 05120 #endif 05121 05122 #ifdef USE_PGSQL /* pgsql */ 05123 05124 #endif 05125 05126 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05127 05128 /* check if we lost connection, and reconnect */ 05129 if(ido2db_db_reconnect(idi)==IDO_ERROR) 05130 return IDO_ERROR; 05131 05132 data[0] = (void *) &idi->dbinfo.instance_id; 05133 data[1] = (void *) &configfile_id; 05134 data[2] = (void *) &es[1]; 05135 data[3] = (void *) &es[2]; 05136 05137 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_configfilevariables_insert, MT(":X1"), (big_uint *) data[0])) { 05138 return IDO_ERROR; 05139 } 05140 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_configfilevariables_insert, MT(":X2"), (big_uint *) data[1])) { 05141 return IDO_ERROR; 05142 } 05143 if(es[1]==NULL) { 05144 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_configfilevariables_insert, ":X3")==IDO_ERROR) { 05145 return IDO_ERROR; 05146 } 05147 } else { 05148 if(!OCI_BindString(idi->dbinfo.oci_statement_configfilevariables_insert, MT(":X3"), *(char **) data[2], 0)) { 05149 return IDO_ERROR; 05150 } 05151 } 05152 if(es[2]==NULL) { 05153 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_configfilevariables_insert, ":X4")==IDO_ERROR) { 05154 return IDO_ERROR; 05155 } 05156 } else { 05157 if(!OCI_BindString(idi->dbinfo.oci_statement_configfilevariables_insert, MT(":X4"), *(char **) data[3], 0)) { 05158 return IDO_ERROR; 05159 } 05160 } 05161 /* execute statement */ 05162 if(!OCI_Execute(idi->dbinfo.oci_statement_configfilevariables_insert)) { 05163 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_configfilevariables_insert() execute error\n"); 05164 return IDO_ERROR; 05165 } 05166 05167 /* commit statement */ 05168 OCI_Commit(idi->dbinfo.oci_connection); 05169 05170 #endif /* Oracle ocilib specific */ 05171 05172 free(es[1]); 05173 free(es[2]); 05174 } 05175 05176 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_configfilevariables() end\n"); 05177 return IDO_OK; 05178 } 05179 05180 int ido2db_handle_configvariables(ido2db_idi *idi) { 05181 05182 if (idi == NULL) 05183 return IDO_ERROR; 05184 05185 return IDO_OK; 05186 } 05187 05188 int ido2db_handle_runtimevariables(ido2db_idi *idi) { 05189 int type, flags, attr; 05190 struct timeval tstamp; 05191 int result = IDO_OK; 05192 char *es[2]; 05193 int x = 0; 05194 char *varname = NULL; 05195 char *varvalue = NULL; 05196 ido2db_mbuf mbuf; 05197 void *data[3]; 05198 05199 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_runtimevariables() start\n"); 05200 05201 if (idi == NULL) 05202 return IDO_ERROR; 05203 05204 /* convert timestamp, etc */ 05205 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 05206 &tstamp); 05207 05208 /* don't store old data */ 05209 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 05210 return IDO_OK; 05211 05212 /* save config file variables to db */ 05213 mbuf = idi->mbuf[IDO2DB_MBUF_RUNTIMEVARIABLE]; 05214 for (x = 0; x < mbuf.used_lines; x++) { 05215 05216 if (mbuf.buffer[x] == NULL) 05217 continue; 05218 05219 /* get var name/val pair */ 05220 varname = strtok(mbuf.buffer[x], "="); 05221 varvalue = strtok(NULL, "\x0"); 05222 05223 es[0] = ido2db_db_escape_string(idi, varname); 05224 es[1] = ido2db_db_escape_string(idi, varvalue); 05225 05226 /* save entry to db */ 05227 data[0] = (void *) &idi->dbinfo.instance_id; 05228 data[1] = (void *) &es[0]; 05229 data[2] = (void *) &es[1]; 05230 05231 result = ido2db_query_insert_or_update_runtimevariables_add(idi, data); 05232 05233 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05234 dbi_result_free(idi->dbinfo.dbi_result); 05235 #endif 05236 05237 #ifdef USE_PGSQL /* pgsql */ 05238 05239 #endif 05240 05241 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05242 05243 05244 #endif /* Oracle ocilib specific */ 05245 05246 free(es[0]); 05247 free(es[1]); 05248 } 05249 05250 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_runtimevariables() end\n"); 05251 05252 return IDO_OK; 05253 } 05254 05255 /****************************************************************************/ 05256 /* OBJECT DEFINITION DATA HANDLERS */ 05257 /****************************************************************************/ 05258 05259 int ido2db_handle_configdumpstart(ido2db_idi *idi) { 05260 int type, flags, attr; 05261 struct timeval tstamp; 05262 int result = IDO_OK; 05263 05264 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_configdumpstart() start\n"); 05265 05266 /* convert timestamp, etc */ 05267 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 05268 &tstamp); 05269 05270 /* set config dump type */ 05271 if (idi->buffered_input[IDO_DATA_CONFIGDUMPTYPE] != NULL && !strcmp( 05272 idi->buffered_input[IDO_DATA_CONFIGDUMPTYPE], 05273 IDO_API_CONFIGDUMP_RETAINED)) 05274 idi->current_object_config_type = 1; 05275 else 05276 idi->current_object_config_type = 0; 05277 05278 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_configdumpstart() end\n"); 05279 05280 return IDO_OK; 05281 } 05282 05283 int ido2db_handle_configdumpend(ido2db_idi *idi) { 05284 05285 return IDO_OK; 05286 } 05287 05288 int ido2db_handle_hostdefinition(ido2db_idi *idi) { 05289 int type, flags, attr; 05290 struct timeval tstamp; 05291 unsigned long object_id = 0L; 05292 unsigned long check_timeperiod_id = 0L; 05293 unsigned long notification_timeperiod_id = 0L; 05294 unsigned long check_command_id = 0L; 05295 unsigned long eventhandler_command_id = 0L; 05296 double check_interval = 0.0; 05297 double retry_interval = 0.0; 05298 int max_check_attempts = 0; 05299 double first_notification_delay = 0.0; 05300 double notification_interval = 0.0; 05301 int notify_on_down = 0; 05302 int notify_on_unreachable = 0; 05303 int notify_on_recovery = 0; 05304 int notify_on_flapping = 0; 05305 int notify_on_downtime = 0; 05306 int stalk_on_up = 0; 05307 int stalk_on_down = 0; 05308 int stalk_on_unreachable = 0; 05309 int flap_detection_enabled = 0; 05310 int flap_detection_on_up = 0; 05311 int flap_detection_on_down = 0; 05312 int flap_detection_on_unreachable = 0; 05313 int process_performance_data = 0; 05314 int freshness_checks_enabled = 0; 05315 int freshness_threshold = 0; 05316 int passive_checks_enabled = 0; 05317 int event_handler_enabled = 0; 05318 int active_checks_enabled = 0; 05319 int retain_status_information = 0; 05320 int retain_nonstatus_information = 0; 05321 int notifications_enabled = 0; 05322 int obsess_over_host = 0; 05323 int failure_prediction_enabled = 0; 05324 double low_flap_threshold = 0.0; 05325 double high_flap_threshold = 0.0; 05326 int have_2d_coords = 0; 05327 int x_2d = 0; 05328 int y_2d = 0; 05329 int have_3d_coords = 0; 05330 double x_3d = 0.0; 05331 double y_3d = 0.0; 05332 double z_3d = 0.0; 05333 unsigned long host_id = 0L; 05334 unsigned long member_id = 0L; 05335 int result = IDO_OK; 05336 char *es[14]; 05337 int x = 0; 05338 char *buf = NULL; 05339 char *buf1 = NULL; 05340 05341 ido2db_mbuf mbuf; 05342 char *cmdptr = NULL; 05343 char *argptr = NULL; 05344 #ifdef USE_ORACLE 05345 char *seq_name = NULL; 05346 #endif 05347 void *data[58]; 05348 int first; 05349 05350 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdefinition() start\n"); 05351 05352 if (idi == NULL) 05353 return IDO_ERROR; 05354 05355 /* convert timestamp, etc */ 05356 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 05357 &tstamp); 05358 05359 /* don't store old data */ 05360 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 05361 return IDO_OK; 05362 05363 /* convert vars */ 05364 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_HOSTCHECKINTERVAL], &check_interval); 05365 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_HOSTRETRYINTERVAL], &retry_interval); 05366 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HOSTMAXCHECKATTEMPTS], &max_check_attempts); 05367 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_FIRSTNOTIFICATIONDELAY], &first_notification_delay); 05368 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_HOSTNOTIFICATIONINTERVAL], ¬ification_interval); 05369 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTDOWN], ¬ify_on_down); 05370 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTUNREACHABLE], ¬ify_on_unreachable); 05371 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTRECOVERY], ¬ify_on_recovery); 05372 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTFLAPPING], ¬ify_on_flapping); 05373 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTDOWNTIME], ¬ify_on_downtime); 05374 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STALKHOSTONUP], &stalk_on_up); 05375 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STALKHOSTOIDOWN], &stalk_on_down); 05376 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STALKHOSTONUNREACHABLE], &stalk_on_unreachable); 05377 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HOSTFLAPDETECTIONENABLED], &flap_detection_enabled); 05378 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONONUP], &flap_detection_on_up); 05379 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONOIDOWN], &flap_detection_on_down); 05380 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONONUNREACHABLE], &flap_detection_on_unreachable); 05381 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PROCESSHOSTPERFORMANCEDATA], &process_performance_data); 05382 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HOSTFRESHNESSCHECKSENABLED], &freshness_checks_enabled); 05383 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HOSTFRESHNESSTHRESHOLD], &freshness_threshold); 05384 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PASSIVEHOSTCHECKSENABLED], &passive_checks_enabled); 05385 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HOSTEVENTHANDLERENABLED], &event_handler_enabled); 05386 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACTIVEHOSTCHECKSENABLED], &active_checks_enabled); 05387 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_RETAINHOSTSTATUSINFORMATION], &retain_status_information); 05388 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_RETAINHOSTNONSTATUSINFORMATION], &retain_nonstatus_information); 05389 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HOSTNOTIFICATIONSENABLED], ¬ifications_enabled); 05390 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_OBSESSOVERHOST], &obsess_over_host); 05391 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HOSTFAILUREPREDICTIONENABLED], &failure_prediction_enabled); 05392 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_LOWHOSTFLAPTHRESHOLD], &low_flap_threshold); 05393 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_HIGHHOSTFLAPTHRESHOLD], &high_flap_threshold); 05394 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HAVE2DCOORDS], &have_2d_coords); 05395 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_X2D], &x_2d); 05396 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_Y2D], &y_2d); 05397 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HAVE3DCOORDS], &have_3d_coords); 05398 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_X3D], &x_3d); 05399 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_Y3D], &y_3d); 05400 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_Z3D], &z_3d); 05401 05402 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_HOSTADDRESS]); 05403 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_HOSTFAILUREPREDICTIONOPTIONS]); 05404 05405 /* get the check command */ 05406 cmdptr = strtok(idi->buffered_input[IDO_DATA_HOSTCHECKCOMMAND], "!"); 05407 argptr = strtok(NULL, "\x0"); 05408 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, cmdptr, NULL, &check_command_id); 05409 es[2] = ido2db_db_escape_string(idi, argptr); 05410 05411 /* get the event handler command */ 05412 cmdptr = strtok(idi->buffered_input[IDO_DATA_HOSTEVENTHANDLER], "!"); 05413 argptr = strtok(NULL, "\x0"); 05414 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, cmdptr, NULL, &eventhandler_command_id); 05415 es[3] = ido2db_db_escape_string(idi, argptr); 05416 05417 es[4] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_NOTES]); 05418 es[5] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_NOTESURL]); 05419 es[6] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_ACTIONURL]); 05420 es[7] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_ICONIMAGE]); 05421 es[8] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_ICONIMAGEALT]); 05422 es[9] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_VRMLIMAGE]); 05423 es[10] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_STATUSMAPIMAGE]); 05424 es[11] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_DISPLAYNAME]); 05425 es[12] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_HOSTALIAS]); 05426 es[13] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_HOSTADDRESS6]); 05427 05428 /* get the object id */ 05429 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOSTNAME], NULL, &object_id); 05430 05431 /* flag the object as being active */ 05432 ido2db_set_object_as_active(idi, IDO2DB_OBJECTTYPE_HOST, object_id); 05433 05434 /* get the timeperiod ids */ 05435 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_HOSTCHECKPERIOD], NULL, &check_timeperiod_id); 05436 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_HOSTNOTIFICATIONPERIOD], NULL, ¬ification_timeperiod_id); 05437 05438 /* add definition to db */ 05439 05440 /* save entry to db */ 05441 data[0] = (void *) &idi->dbinfo.instance_id; 05442 data[1] = (void *) &idi->current_object_config_type; 05443 data[2] = (void *) &object_id; 05444 data[3] = (void *) &es[12]; 05445 data[4] = (void *) &es[11]; 05446 data[5] = (void *) &es[0]; 05447 data[6] = (void *) &check_command_id; 05448 data[7] = (void *) &es[2]; 05449 data[8] = (void *) &eventhandler_command_id; 05450 data[9] = (void *) &es[3]; 05451 data[10] = (void *) &check_timeperiod_id; 05452 data[11] = (void *) ¬ification_timeperiod_id; 05453 data[12] = (void *) &es[1]; 05454 data[13] = (void *) &check_interval; 05455 data[14] = (void *) &retry_interval; 05456 data[15] = (void *) &max_check_attempts; 05457 data[16] = (void *) &first_notification_delay; 05458 data[17] = (void *) ¬ification_interval; 05459 data[18] = (void *) ¬ify_on_down; 05460 data[19] = (void *) ¬ify_on_unreachable; 05461 data[20] = (void *) ¬ify_on_recovery; 05462 data[21] = (void *) ¬ify_on_flapping; 05463 data[22] = (void *) ¬ify_on_downtime; 05464 data[23] = (void *) &stalk_on_up; 05465 data[24] = (void *) &stalk_on_down; 05466 data[25] = (void *) &stalk_on_unreachable; 05467 data[26] = (void *) &flap_detection_enabled; 05468 data[27] = (void *) &flap_detection_on_up; 05469 data[28] = (void *) &flap_detection_on_down; 05470 data[29] = (void *) &flap_detection_on_unreachable; 05471 data[30] = (void *) &low_flap_threshold; 05472 data[31] = (void *) &high_flap_threshold; 05473 data[32] = (void *) &process_performance_data; 05474 data[33] = (void *) &freshness_checks_enabled; 05475 data[34] = (void *) &freshness_threshold; 05476 data[35] = (void *) &passive_checks_enabled; 05477 data[36] = (void *) &event_handler_enabled; 05478 data[37] = (void *) &active_checks_enabled; 05479 data[38] = (void *) &retain_status_information; 05480 data[39] = (void *) &retain_nonstatus_information; 05481 data[40] = (void *) ¬ifications_enabled; 05482 data[41] = (void *) &obsess_over_host; 05483 data[42] = (void *) &failure_prediction_enabled; 05484 data[43] = (void *) &es[4]; 05485 data[44] = (void *) &es[5]; 05486 data[45] = (void *) &es[6]; 05487 data[46] = (void *) &es[7]; 05488 data[47] = (void *) &es[8]; 05489 data[48] = (void *) &es[9]; 05490 data[49] = (void *) &es[10]; 05491 data[50] = (void *) &have_2d_coords; 05492 data[51] = (void *) &x_2d; 05493 data[52] = (void *) &y_2d; 05494 data[53] = (void *) &have_3d_coords; 05495 data[54] = (void *) &x_3d; 05496 data[55] = (void *) &y_3d; 05497 data[56] = (void *) &z_3d; 05498 data[57] = (void *) &es[13]; /* HOSTADDRESS6 */ 05499 05500 result = ido2db_query_insert_or_update_hostdefinition_definition_add(idi, data); 05501 05502 if (result == IDO_OK) { 05503 05504 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05505 switch (idi->dbinfo.server_type) { 05506 case IDO2DB_DBSERVER_MYSQL: 05507 /* mysql doesn't use sequences */ 05508 host_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 05509 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdefinitio(%lu) host_id\n", host_id); 05510 break; 05511 case IDO2DB_DBSERVER_PGSQL: 05512 /* depending on tableprefix/tablename a sequence will be used */ 05513 if(asprintf(&buf, "%s_host_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTS]) == -1) 05514 buf = NULL; 05515 05516 host_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 05517 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdefinitio(%s=%lu) host_id\n", buf, host_id); 05518 free(buf); 05519 break; 05520 case IDO2DB_DBSERVER_DB2: 05521 break; 05522 case IDO2DB_DBSERVER_FIREBIRD: 05523 break; 05524 case IDO2DB_DBSERVER_FREETDS: 05525 break; 05526 case IDO2DB_DBSERVER_INGRES: 05527 break; 05528 case IDO2DB_DBSERVER_MSQL: 05529 break; 05530 case IDO2DB_DBSERVER_ORACLE: 05531 break; 05532 case IDO2DB_DBSERVER_SQLITE: 05533 break; 05534 case IDO2DB_DBSERVER_SQLITE3: 05535 break; 05536 default: 05537 break; 05538 } 05539 #endif 05540 05541 #ifdef USE_PGSQL /* pgsql */ 05542 05543 #endif 05544 05545 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05546 if(asprintf(&seq_name, "seq_hosts")==-1) 05547 seq_name=NULL; 05548 host_id = ido2db_ocilib_insert_id(idi, seq_name); 05549 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdefinition(%lu) \n", host_id); 05550 free(seq_name); 05551 05552 #endif /* Oracle ocilib specific */ 05553 } 05554 05555 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05556 dbi_result_free(idi->dbinfo.dbi_result); 05557 #endif 05558 05559 #ifdef USE_PGSQL /* pgsql */ 05560 05561 #endif 05562 05563 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05564 05565 05566 #endif /* Oracle ocilib specific */ 05567 05568 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) { 05569 free(es[x]); 05570 } 05571 05572 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdefinition() free es\n"); 05573 05574 /* save parent hosts to db */ 05575 mbuf = idi->mbuf[IDO2DB_MBUF_PARENTHOST]; 05576 for (x = 0; x < mbuf.used_lines; x++) { 05577 05578 if (mbuf.buffer[x] == NULL) 05579 continue; 05580 05581 /* get the object id of the member */ 05582 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, 05583 mbuf.buffer[x], NULL, &member_id); 05584 05585 /* save entry to db */ 05586 data[0] = (void *) &idi->dbinfo.instance_id; 05587 data[1] = (void *) &host_id; 05588 data[2] = (void *) &member_id; 05589 05590 result = ido2db_query_insert_or_update_hostdefinition_parenthosts_add(idi, data); 05591 05592 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05593 dbi_result_free(idi->dbinfo.dbi_result); 05594 #endif 05595 05596 #ifdef USE_PGSQL /* pgsql */ 05597 05598 #endif 05599 05600 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05601 05602 05603 #endif /* Oracle ocilib specific */ 05604 05605 } 05606 05607 /* save contact groups to db */ 05608 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTGROUP]; 05609 for (x = 0; x < mbuf.used_lines; x++) { 05610 05611 if (mbuf.buffer[x] == NULL) 05612 continue; 05613 05614 /* get the object id of the member */ 05615 result = ido2db_get_object_id_with_insert(idi, 05616 IDO2DB_OBJECTTYPE_CONTACTGROUP, mbuf.buffer[x], NULL, 05617 &member_id); 05618 05619 /* save entry to db */ 05620 data[0] = (void *) &idi->dbinfo.instance_id; 05621 data[1] = (void *) &host_id; 05622 data[2] = (void *) &member_id; 05623 05624 result = ido2db_query_insert_or_update_hostdefinition_contactgroups_add(idi, data); 05625 05626 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05627 dbi_result_free(idi->dbinfo.dbi_result); 05628 #endif 05629 05630 #ifdef USE_PGSQL /* pgsql */ 05631 05632 #endif 05633 05634 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05635 05636 05637 #endif /* Oracle ocilib specific */ 05638 } 05639 05640 /* save contacts to db */ 05641 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdefinition() host_contacts start\n"); 05642 05643 #ifdef USE_LIBDBI 05644 /* build a multiple insert value array */ 05645 if(asprintf(&buf1, "INSERT INTO %s (instance_id,host_id,contact_object_id) VALUES ", 05646 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTS] 05647 )==-1) 05648 buf1=NULL; 05649 #endif 05650 05651 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05652 05653 /* build a multiple insert value array */ 05654 if(asprintf(&buf1, "INSERT INTO %s (id, instance_id,host_id,contact_object_id) SELECT seq_%s.nextval, x1, x2, x3 from (", 05655 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTS], 05656 ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTS] 05657 )==-1) 05658 buf1=NULL; 05659 05660 #endif /* Oracle ocilib specific */ 05661 05662 first=1; 05663 05664 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACT]; 05665 for (x = 0; x < mbuf.used_lines; x++) { 05666 05667 if (mbuf.buffer[x] == NULL) 05668 continue; 05669 05670 /* get the object id of the member */ 05671 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_CONTACT, mbuf.buffer[x], NULL, &member_id); 05672 05673 buf=buf1; /* save this pointer for later free'ing */ 05674 05675 #ifdef USE_LIBDBI 05676 if(asprintf(&buf1, "%s%s(%lu,%lu,%lu)", 05677 buf1, 05678 (first==1?"":","), 05679 idi->dbinfo.instance_id, 05680 host_id, 05681 member_id 05682 )==-1) 05683 buf1=NULL; 05684 #endif 05685 05686 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05687 if(first==1) { 05688 if(asprintf(&buf1, "%s SELECT %lu as x1, %lu as x2, %lu as x3 FROM DUAL ", 05689 buf1, 05690 idi->dbinfo.instance_id, 05691 host_id, 05692 member_id 05693 )==-1) 05694 buf1=NULL; 05695 } else { 05696 if(asprintf(&buf1, "%s UNION ALL SELECT %lu, %lu, %lu FROM DUAL ", 05697 buf1, 05698 idi->dbinfo.instance_id, 05699 host_id, 05700 member_id 05701 )==-1) 05702 buf1=NULL; 05703 } 05704 #endif /* Oracle ocilib specific */ 05705 05706 free(buf); 05707 first=0; 05708 } 05709 05710 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05711 05712 if(asprintf(&buf1, "%s)", buf1)==-1) 05713 buf1=NULL; 05714 05715 #endif /* Oracle ocilib specific */ 05716 05717 if(first==0){ 05718 result=ido2db_db_query(idi, buf1); 05719 05720 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05721 dbi_result_free(idi->dbinfo.dbi_result); 05722 #endif 05723 05724 #ifdef USE_PGSQL /* pgsql */ 05725 05726 #endif 05727 05728 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05729 05730 /* statement handle not re-binded */ 05731 OCI_StatementFree(idi->dbinfo.oci_statement); 05732 05733 #endif /* Oracle ocilib specific */ 05734 05735 } 05736 05737 free(buf1); 05738 05739 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdefinition() host_contacts end\n"); 05740 05741 /* save custom variables to db */ 05742 result=ido2db_save_custom_variables(idi,IDO2DB_DBTABLE_CUSTOMVARIABLES,object_id,NULL, -1); 05743 05744 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdefinition() end\n"); 05745 05746 return IDO_OK; 05747 } 05748 05749 int ido2db_handle_hostgroupdefinition(ido2db_idi *idi) { 05750 int type, flags, attr; 05751 struct timeval tstamp; 05752 unsigned long object_id = 0L; 05753 unsigned long group_id = 0L; 05754 unsigned long member_id = 0L; 05755 int result = IDO_OK; 05756 char *es[1]; 05757 int x = 0; 05758 #ifdef USE_LIBDBI 05759 char *buf = NULL; 05760 #endif 05761 ido2db_mbuf mbuf; 05762 #ifdef USE_ORACLE 05763 char *seq_name = NULL; 05764 #endif 05765 void *data[4]; 05766 05767 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostgroupdefinition() start\n"); 05768 05769 if (idi == NULL) 05770 return IDO_ERROR; 05771 05772 /* convert timestamp, etc */ 05773 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 05774 05775 /* don't store old data */ 05776 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 05777 return IDO_OK; 05778 05779 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_HOSTGROUPALIAS]); 05780 05781 /* get the object id */ 05782 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOSTGROUP, idi->buffered_input[IDO_DATA_HOSTGROUPNAME], NULL, &object_id); 05783 05784 /* flag the object as being active */ 05785 ido2db_set_object_as_active(idi, IDO2DB_OBJECTTYPE_HOSTGROUP, object_id); 05786 05787 /* add definition to db */ 05788 data[0] = (void *) &idi->dbinfo.instance_id; 05789 data[1] = (void *) &idi->current_object_config_type; 05790 data[2] = (void *) &object_id; 05791 data[3] = (void *) &es[0]; 05792 05793 result = ido2db_query_insert_or_update_hostgroupdefinition_definition_add(idi, data); 05794 05795 if (result == IDO_OK) { 05796 05797 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05798 switch (idi->dbinfo.server_type) { 05799 case IDO2DB_DBSERVER_MYSQL: 05800 /* mysql doesn't use sequences */ 05801 group_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 05802 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostgroupdefinition(%lu) hostgroup_id\n", group_id); 05803 break; 05804 case IDO2DB_DBSERVER_PGSQL: 05805 /* depending on tableprefix/tablename a sequence will be used */ 05806 if(asprintf(&buf, "%s_hostgroup_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPS]) == -1) 05807 buf = NULL; 05808 05809 group_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 05810 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostgroupdefinition(%s=%lu) hostgroup_id\n", buf, group_id); 05811 free(buf); 05812 break; 05813 case IDO2DB_DBSERVER_DB2: 05814 break; 05815 case IDO2DB_DBSERVER_FIREBIRD: 05816 break; 05817 case IDO2DB_DBSERVER_FREETDS: 05818 break; 05819 case IDO2DB_DBSERVER_INGRES: 05820 break; 05821 case IDO2DB_DBSERVER_MSQL: 05822 break; 05823 case IDO2DB_DBSERVER_ORACLE: 05824 break; 05825 case IDO2DB_DBSERVER_SQLITE: 05826 break; 05827 case IDO2DB_DBSERVER_SQLITE3: 05828 break; 05829 default: 05830 break; 05831 } 05832 #endif 05833 05834 #ifdef USE_PGSQL /* pgsql */ 05835 05836 #endif 05837 05838 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05839 if(asprintf(&seq_name, "seq_hostgroups")==-1) 05840 seq_name=NULL; 05841 group_id = ido2db_ocilib_insert_id(idi, seq_name); 05842 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostgroupdefinition(%lu) hostgroup_id\n", group_id); 05843 free(seq_name); 05844 05845 #endif /* Oracle ocilib specific */ 05846 } 05847 05848 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05849 dbi_result_free(idi->dbinfo.dbi_result); 05850 #endif 05851 05852 #ifdef USE_PGSQL /* pgsql */ 05853 05854 #endif 05855 05856 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05857 05858 05859 #endif /* Oracle ocilib specific */ 05860 05861 free(es[0]); 05862 05863 /* save hostgroup members to db */ 05864 mbuf = idi->mbuf[IDO2DB_MBUF_HOSTGROUPMEMBER]; 05865 for (x = 0; x < mbuf.used_lines; x++) { 05866 05867 if (mbuf.buffer[x] == NULL) 05868 continue; 05869 05870 /* get the object id of the member */ 05871 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, 05872 mbuf.buffer[x], NULL, &member_id); 05873 05874 /* save entry to db */ 05875 data[0] = (void *) &idi->dbinfo.instance_id; 05876 data[1] = (void *) &group_id; 05877 data[2] = (void *) &member_id; 05878 05879 result = ido2db_query_insert_or_update_hostgroupdefinition_hostgroupmembers_add(idi, data); 05880 05881 #ifdef USE_LIBDBI /* everything else will be libdbi */ 05882 dbi_result_free(idi->dbinfo.dbi_result); 05883 #endif 05884 05885 #ifdef USE_PGSQL /* pgsql */ 05886 05887 #endif 05888 05889 #ifdef USE_ORACLE /* Oracle ocilib specific */ 05890 05891 05892 #endif /* Oracle ocilib specific */ 05893 05894 } 05895 05896 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostgroupdefinition() end\n"); 05897 05898 return IDO_OK; 05899 } 05900 05901 int ido2db_handle_servicedefinition(ido2db_idi *idi) { 05902 int type, flags, attr; 05903 struct timeval tstamp; 05904 unsigned long object_id = 0L; 05905 unsigned long host_id = 0L; 05906 unsigned long check_timeperiod_id = 0L; 05907 unsigned long notification_timeperiod_id = 0L; 05908 unsigned long check_command_id = 0L; 05909 unsigned long eventhandler_command_id = 0L; 05910 double check_interval = 0.0; 05911 double retry_interval = 0.0; 05912 int max_check_attempts = 0; 05913 double first_notification_delay = 0.0; 05914 double notification_interval = 0.0; 05915 int notify_on_warning = 0; 05916 int notify_on_unknown = 0; 05917 int notify_on_critical = 0; 05918 int notify_on_recovery = 0; 05919 int notify_on_flapping = 0; 05920 int notify_on_downtime = 0; 05921 int stalk_on_ok = 0; 05922 int stalk_on_warning = 0; 05923 int stalk_on_unknown = 0; 05924 int stalk_on_critical = 0; 05925 int is_volatile = 0; 05926 int flap_detection_enabled = 0; 05927 int flap_detection_on_ok = 0; 05928 int flap_detection_on_warning = 0; 05929 int flap_detection_on_unknown = 0; 05930 int flap_detection_on_critical = 0; 05931 int process_performance_data = 0; 05932 int freshness_checks_enabled = 0; 05933 int freshness_threshold = 0; 05934 int passive_checks_enabled = 0; 05935 int event_handler_enabled = 0; 05936 int active_checks_enabled = 0; 05937 int retain_status_information = 0; 05938 int retain_nonstatus_information = 0; 05939 int notifications_enabled = 0; 05940 int obsess_over_service = 0; 05941 int failure_prediction_enabled = 0; 05942 double low_flap_threshold = 0.0; 05943 double high_flap_threshold = 0.0; 05944 unsigned long service_id = 0L; 05945 unsigned long member_id = 0L; 05946 int result = IDO_OK; 05947 char *es[9]; 05948 int x = 0; 05949 char *buf = NULL; 05950 char *buf1 = NULL; 05951 05952 ido2db_mbuf mbuf; 05953 char *cmdptr = NULL; 05954 char *argptr = NULL; 05955 #ifdef USE_ORACLE 05956 char *seq_name = NULL; 05957 #endif 05958 void *data[51]; 05959 int first; 05960 05961 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedefinition() start\n"); 05962 05963 if (idi == NULL) 05964 return IDO_ERROR; 05965 05966 /* convert timestamp, etc */ 05967 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 05968 &tstamp); 05969 05970 /* don't store old data */ 05971 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 05972 return IDO_OK; 05973 05974 /* convert vars */ 05975 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_SERVICECHECKINTERVAL], &check_interval); 05976 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_SERVICERETRYINTERVAL], &retry_interval); 05977 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_MAXSERVICECHECKATTEMPTS], &max_check_attempts); 05978 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_FIRSTNOTIFICATIONDELAY], &first_notification_delay); 05979 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_SERVICENOTIFICATIONINTERVAL], ¬ification_interval); 05980 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICEWARNING], ¬ify_on_warning); 05981 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICEUNKNOWN], ¬ify_on_unknown); 05982 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICECRITICAL], ¬ify_on_critical); 05983 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICERECOVERY], ¬ify_on_recovery); 05984 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICEFLAPPING], ¬ify_on_flapping); 05985 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICEDOWNTIME], ¬ify_on_downtime); 05986 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STALKSERVICEONOK], &stalk_on_ok); 05987 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STALKSERVICEONWARNING], &stalk_on_warning); 05988 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STALKSERVICEONUNKNOWN], &stalk_on_unknown); 05989 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_STALKSERVICEONCRITICAL], &stalk_on_critical); 05990 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SERVICEISVOLATILE], &is_volatile); 05991 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SERVICEFLAPDETECTIONENABLED], &flap_detection_enabled); 05992 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONONOK], &flap_detection_on_ok); 05993 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONONWARNING], &flap_detection_on_warning); 05994 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONONUNKNOWN], &flap_detection_on_unknown); 05995 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FLAPDETECTIONONCRITICAL], &flap_detection_on_critical); 05996 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PROCESSSERVICEPERFORMANCEDATA], &process_performance_data); 05997 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SERVICEFRESHNESSCHECKSENABLED], &freshness_checks_enabled); 05998 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SERVICEFRESHNESSTHRESHOLD], &freshness_threshold); 05999 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_PASSIVESERVICECHECKSENABLED], &passive_checks_enabled); 06000 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SERVICEEVENTHANDLERENABLED], &event_handler_enabled); 06001 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ACTIVESERVICECHECKSENABLED], &active_checks_enabled); 06002 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_RETAINSERVICESTATUSINFORMATION], &retain_status_information); 06003 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_RETAINSERVICENONSTATUSINFORMATION], &retain_nonstatus_information); 06004 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SERVICENOTIFICATIONSENABLED], ¬ifications_enabled); 06005 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_OBSESSOVERSERVICE], &obsess_over_service); 06006 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SERVICEFAILUREPREDICTIONENABLED], &failure_prediction_enabled); 06007 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_LOWSERVICEFLAPTHRESHOLD], &low_flap_threshold); 06008 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_HIGHSERVICEFLAPTHRESHOLD], &high_flap_threshold); 06009 06010 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_SERVICEFAILUREPREDICTIONOPTIONS]); 06011 06012 /* get the check command */ 06013 cmdptr = strtok(idi->buffered_input[IDO_DATA_SERVICECHECKCOMMAND], "!"); 06014 argptr = strtok(NULL, "\x0"); 06015 06016 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, cmdptr, NULL, &check_command_id); 06017 06018 es[1] = ido2db_db_escape_string(idi, argptr); 06019 06020 /* get the event handler command */ 06021 cmdptr = strtok(idi->buffered_input[IDO_DATA_SERVICEEVENTHANDLER], "!"); 06022 argptr = strtok(NULL, "\x0"); 06023 06024 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, cmdptr, NULL, &eventhandler_command_id); 06025 06026 es[2] = ido2db_db_escape_string(idi, argptr); 06027 es[3] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_NOTES]); 06028 es[4] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_NOTESURL]); 06029 es[5] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_ACTIONURL]); 06030 es[6] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_ICONIMAGE]); 06031 es[7] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_ICONIMAGEALT]); 06032 es[8] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_DISPLAYNAME]); 06033 06034 /* get the object ids */ 06035 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOSTNAME], idi->buffered_input[IDO_DATA_SERVICEDESCRIPTION], &object_id); 06036 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOSTNAME], NULL, &host_id); 06037 06038 /* flag the object as being active */ 06039 ido2db_set_object_as_active(idi, IDO2DB_OBJECTTYPE_SERVICE, object_id); 06040 06041 /* get the timeperiod ids */ 06042 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_SERVICECHECKPERIOD], NULL, &check_timeperiod_id); 06043 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_SERVICENOTIFICATIONPERIOD], NULL, ¬ification_timeperiod_id); 06044 06045 /* add definition to db */ 06046 06047 /* save entry to db */ 06048 data[0] = (void *) &idi->dbinfo.instance_id; 06049 data[1] = (void *) &idi->current_object_config_type; 06050 data[2] = (void *) &host_id; 06051 data[3] = (void *) &object_id; 06052 data[4] = (void *) &es[8]; 06053 data[5] = (void *) &check_command_id; 06054 data[6] = (void *) &es[1]; 06055 data[7] = (void *) &eventhandler_command_id; 06056 data[8] = (void *) &es[2]; 06057 data[9] = (void *) &check_timeperiod_id; 06058 data[10] = (void *) ¬ification_timeperiod_id; 06059 data[11] = (void *) &es[0]; 06060 data[12] = (void *) &check_interval; 06061 data[13] = (void *) &retry_interval; 06062 data[14] = (void *) &max_check_attempts; 06063 data[15] = (void *) &first_notification_delay; 06064 data[16] = (void *) ¬ification_interval; 06065 data[17] = (void *) ¬ify_on_warning; 06066 data[18] = (void *) ¬ify_on_unknown; 06067 data[19] = (void *) ¬ify_on_critical; 06068 data[20] = (void *) ¬ify_on_recovery; 06069 data[21] = (void *) ¬ify_on_flapping; 06070 data[22] = (void *) ¬ify_on_downtime; 06071 data[23] = (void *) &stalk_on_ok; 06072 data[24] = (void *) &stalk_on_warning; 06073 data[25] = (void *) &stalk_on_unknown; 06074 data[26] = (void *) &stalk_on_critical; 06075 data[27] = (void *) &is_volatile; 06076 data[28] = (void *) &flap_detection_enabled; 06077 data[29] = (void *) &flap_detection_on_ok; 06078 data[30] = (void *) &flap_detection_on_warning; 06079 data[31] = (void *) &flap_detection_on_unknown; 06080 data[32] = (void *) &flap_detection_on_critical; 06081 data[33] = (void *) &low_flap_threshold; 06082 data[34] = (void *) &high_flap_threshold; 06083 data[35] = (void *) &process_performance_data; 06084 data[36] = (void *) &freshness_checks_enabled; 06085 data[37] = (void *) &freshness_threshold; 06086 data[38] = (void *) &passive_checks_enabled; 06087 data[39] = (void *) &event_handler_enabled; 06088 data[40] = (void *) &active_checks_enabled; 06089 data[41] = (void *) &retain_status_information; 06090 data[42] = (void *) &retain_nonstatus_information; 06091 data[43] = (void *) ¬ifications_enabled; 06092 data[44] = (void *) &obsess_over_service; 06093 data[45] = (void *) &failure_prediction_enabled; 06094 data[46] = (void *) &es[3]; 06095 data[47] = (void *) &es[4]; 06096 data[48] = (void *) &es[5]; 06097 data[49] = (void *) &es[6]; 06098 data[50] = (void *) &es[7]; 06099 06100 result = ido2db_query_insert_or_update_servicedefinition_definition_add(idi, data); 06101 06102 if (result == IDO_OK) { 06103 06104 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06105 switch (idi->dbinfo.server_type) { 06106 case IDO2DB_DBSERVER_MYSQL: 06107 /* mysql doesn't use sequences */ 06108 service_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 06109 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedefinition(%lu) service_id\n", service_id); 06110 break; 06111 case IDO2DB_DBSERVER_PGSQL: 06112 /* depending on tableprefix/tablename a sequence will be used */ 06113 if(asprintf(&buf, "%s_service_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICES]) == -1) 06114 buf = NULL; 06115 06116 service_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 06117 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedefinition(%s=%lu) service_id\n", buf, service_id); 06118 free(buf); 06119 break; 06120 case IDO2DB_DBSERVER_DB2: 06121 break; 06122 case IDO2DB_DBSERVER_FIREBIRD: 06123 break; 06124 case IDO2DB_DBSERVER_FREETDS: 06125 break; 06126 case IDO2DB_DBSERVER_INGRES: 06127 break; 06128 case IDO2DB_DBSERVER_MSQL: 06129 break; 06130 case IDO2DB_DBSERVER_ORACLE: 06131 break; 06132 case IDO2DB_DBSERVER_SQLITE: 06133 break; 06134 case IDO2DB_DBSERVER_SQLITE3: 06135 break; 06136 default: 06137 break; 06138 } 06139 #endif 06140 06141 #ifdef USE_PGSQL /* pgsql */ 06142 06143 #endif 06144 06145 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06146 if(asprintf(&seq_name, "seq_services")==-1) 06147 seq_name=NULL; 06148 service_id = ido2db_ocilib_insert_id(idi, seq_name); 06149 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedefinition(%lu) service_id\n", service_id); 06150 free(seq_name); 06151 06152 #endif /* Oracle ocilib specific */ 06153 } 06154 06155 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06156 dbi_result_free(idi->dbinfo.dbi_result); 06157 #endif 06158 06159 #ifdef USE_PGSQL /* pgsql */ 06160 06161 #endif 06162 06163 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06164 06165 06166 #endif /* Oracle ocilib specific */ 06167 06168 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) { 06169 free(es[x]); 06170 } 06171 06172 /* save contact groups to db */ 06173 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTGROUP]; 06174 for (x = 0; x < mbuf.used_lines; x++) { 06175 06176 if (mbuf.buffer[x] == NULL) 06177 continue; 06178 06179 /* get the object id of the member */ 06180 result = ido2db_get_object_id_with_insert(idi, 06181 IDO2DB_OBJECTTYPE_CONTACTGROUP, mbuf.buffer[x], NULL, 06182 &member_id); 06183 06184 /* save entry to db */ 06185 data[0] = (void *) &idi->dbinfo.instance_id; 06186 data[1] = (void *) &service_id; 06187 data[2] = (void *) &member_id; 06188 06189 result = ido2db_query_insert_or_update_servicedefinition_contactgroups_add(idi, data); 06190 06191 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06192 dbi_result_free(idi->dbinfo.dbi_result); 06193 #endif 06194 06195 #ifdef USE_PGSQL /* pgsql */ 06196 06197 #endif 06198 06199 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06200 06201 06202 #endif /* Oracle ocilib specific */ 06203 06204 } 06205 06206 /* save contacts to db */ 06207 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedefinition() service_contacts start\n"); 06208 06209 #ifdef USE_LIBDBI 06210 /* build a multiple insert value array */ 06211 if(asprintf(&buf1, "INSERT INTO %s (instance_id,service_id,contact_object_id) VALUES ", 06212 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTS] 06213 )==-1) 06214 buf1=NULL; 06215 #endif 06216 06217 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06218 06219 /* build a multiple insert value array */ 06220 if(asprintf(&buf1, "INSERT INTO %s (id, instance_id,service_id,contact_object_id) SELECT seq_%s.nextval, x1, x2, x3 from (", 06221 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTS], 06222 ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTS] 06223 )==-1) 06224 buf1=NULL; 06225 06226 #endif /* Oracle ocilib specific */ 06227 06228 first=1; 06229 06230 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACT]; 06231 for (x = 0; x < mbuf.used_lines; x++) { 06232 06233 if (mbuf.buffer[x] == NULL) 06234 continue; 06235 06236 /* get the object id of the member */ 06237 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_CONTACT, mbuf.buffer[x], NULL, &member_id); 06238 06239 buf=buf1; /* save this pointer for later free'ing */ 06240 06241 #ifdef USE_LIBDBI 06242 if(asprintf(&buf1, "%s%s(%lu,%lu,%lu)", 06243 buf1, 06244 (first==1?"":","), 06245 idi->dbinfo.instance_id, 06246 service_id, 06247 member_id 06248 )==-1) 06249 buf1=NULL; 06250 #endif 06251 06252 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06253 if(first==1) { 06254 if(asprintf(&buf1, "%s SELECT %lu as x1, %lu as x2, %lu as x3 FROM DUAL ", 06255 buf1, 06256 idi->dbinfo.instance_id, 06257 service_id, 06258 member_id 06259 )==-1) 06260 buf1=NULL; 06261 } else { 06262 if(asprintf(&buf1, "%s UNION ALL SELECT %lu, %lu, %lu FROM DUAL ", 06263 buf1, 06264 idi->dbinfo.instance_id, 06265 service_id, 06266 member_id 06267 )==-1) 06268 buf1=NULL; 06269 } 06270 #endif /* Oracle ocilib specific */ 06271 06272 free(buf); 06273 first=0; 06274 } 06275 06276 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06277 06278 if(asprintf(&buf1, "%s)", buf1)==-1) 06279 buf1=NULL; 06280 06281 #endif /* Oracle ocilib specific */ 06282 06283 if(first==0){ 06284 result=ido2db_db_query(idi, buf1); 06285 06286 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06287 dbi_result_free(idi->dbinfo.dbi_result); 06288 #endif 06289 06290 #ifdef USE_PGSQL /* pgsql */ 06291 06292 #endif 06293 06294 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06295 06296 /* statement handle not re-binded */ 06297 OCI_StatementFree(idi->dbinfo.oci_statement); 06298 06299 #endif /* Oracle ocilib specific */ 06300 06301 } 06302 06303 free(buf1); 06304 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedefinition() service_contacts end\n"); 06305 06306 /* save custom variables to db */ 06307 result=ido2db_save_custom_variables(idi,IDO2DB_DBTABLE_CUSTOMVARIABLES,object_id,NULL, -1); 06308 06309 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedefinition() end\n"); 06310 06311 return IDO_OK; 06312 } 06313 06314 int ido2db_handle_servicegroupdefinition(ido2db_idi *idi) { 06315 int type, flags, attr; 06316 struct timeval tstamp; 06317 unsigned long object_id = 0L; 06318 unsigned long group_id = 0L; 06319 unsigned long member_id = 0L; 06320 int result = IDO_OK; 06321 char *es[1]; 06322 int x = 0; 06323 #ifdef USE_LIBDBI 06324 char *buf = NULL; 06325 #endif 06326 ido2db_mbuf mbuf; 06327 char *hptr = NULL; 06328 char *sptr = NULL; 06329 #ifdef USE_ORACLE 06330 char *seq_name = NULL; 06331 #endif 06332 void *data[4]; 06333 06334 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicegroupdefinition() start\n"); 06335 06336 if (idi == NULL) 06337 return IDO_ERROR; 06338 06339 /* convert timestamp, etc */ 06340 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 06341 &tstamp); 06342 06343 /* don't store old data */ 06344 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 06345 return IDO_OK; 06346 06347 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_SERVICEGROUPALIAS]); 06348 06349 /* get the object id */ 06350 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICEGROUP, idi->buffered_input[IDO_DATA_SERVICEGROUPNAME], NULL, &object_id); 06351 06352 /* flag the object as being active */ 06353 ido2db_set_object_as_active(idi, IDO2DB_OBJECTTYPE_SERVICEGROUP, object_id); 06354 06355 /* add definition to db */ 06356 data[0] = (void *) &idi->dbinfo.instance_id; 06357 data[1] = (void *) &idi->current_object_config_type; 06358 data[2] = (void *) &object_id; 06359 data[3] = (void *) &es[0]; 06360 06361 result = ido2db_query_insert_or_update_servicegroupdefinition_definition_add(idi, data); 06362 06363 if (result == IDO_OK) { 06364 06365 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06366 switch (idi->dbinfo.server_type) { 06367 case IDO2DB_DBSERVER_MYSQL: 06368 /* mysql doesn't use sequences */ 06369 group_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 06370 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicegroupdefinition(%lu) group_id\n", group_id); 06371 break; 06372 case IDO2DB_DBSERVER_PGSQL: 06373 /* depending on tableprefix/tablename a sequence will be used */ 06374 if(asprintf(&buf, "%s_servicegroup_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPS]) == -1) 06375 buf = NULL; 06376 06377 group_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 06378 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicegroupdefinition(%s=%lu) group_id\n", buf, group_id); 06379 free(buf); 06380 break; 06381 case IDO2DB_DBSERVER_DB2: 06382 break; 06383 case IDO2DB_DBSERVER_FIREBIRD: 06384 break; 06385 case IDO2DB_DBSERVER_FREETDS: 06386 break; 06387 case IDO2DB_DBSERVER_INGRES: 06388 break; 06389 case IDO2DB_DBSERVER_MSQL: 06390 break; 06391 case IDO2DB_DBSERVER_ORACLE: 06392 break; 06393 case IDO2DB_DBSERVER_SQLITE: 06394 break; 06395 case IDO2DB_DBSERVER_SQLITE3: 06396 break; 06397 default: 06398 break; 06399 } 06400 #endif 06401 06402 #ifdef USE_PGSQL /* pgsql */ 06403 06404 #endif 06405 06406 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06407 if(asprintf(&seq_name, "seq_servicegroups")==-1) 06408 seq_name=NULL; 06409 group_id = ido2db_ocilib_insert_id(idi, seq_name); 06410 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicegroupdefinition(%lu) group_id\n", group_id); 06411 free(seq_name); 06412 06413 #endif /* Oracle ocilib specific */ 06414 } 06415 06416 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06417 dbi_result_free(idi->dbinfo.dbi_result); 06418 #endif 06419 06420 #ifdef USE_PGSQL /* pgsql */ 06421 06422 #endif 06423 06424 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06425 06426 06427 #endif /* Oracle ocilib specific */ 06428 06429 free(es[0]); 06430 06431 /* save members to db */ 06432 mbuf = idi->mbuf[IDO2DB_MBUF_SERVICEGROUPMEMBER]; 06433 for (x = 0; x < mbuf.used_lines; x++) { 06434 06435 if (mbuf.buffer[x] == NULL) 06436 continue; 06437 06438 /* split the host/service name */ 06439 hptr = strtok(mbuf.buffer[x], ";"); 06440 sptr = strtok(NULL, "\x0"); 06441 06442 /* get the object id of the member */ 06443 result = ido2db_get_object_id_with_insert(idi, 06444 IDO2DB_OBJECTTYPE_SERVICE, hptr, sptr, &member_id); 06445 06446 /* save entry to db */ 06447 data[0] = (void *) &idi->dbinfo.instance_id; 06448 data[1] = (void *) &group_id; 06449 data[2] = (void *) &member_id; 06450 06451 result = ido2db_query_insert_or_update_servicegroupdefinition_members_add(idi, data); 06452 06453 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06454 dbi_result_free(idi->dbinfo.dbi_result); 06455 #endif 06456 06457 #ifdef USE_PGSQL /* pgsql */ 06458 06459 #endif 06460 06461 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06462 06463 06464 #endif /* Oracle ocilib specific */ 06465 06466 } 06467 06468 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicegroupdefinition() end\n"); 06469 06470 return IDO_OK; 06471 } 06472 06473 int ido2db_handle_hostdependencydefinition(ido2db_idi *idi) { 06474 int type, flags, attr; 06475 struct timeval tstamp; 06476 unsigned long object_id = 0L; 06477 unsigned long dependent_object_id = 0L; 06478 unsigned long timeperiod_object_id = 0L; 06479 int dependency_type = 0; 06480 int inherits_parent = 0; 06481 int fail_on_up = 0; 06482 int fail_on_down = 0; 06483 int fail_on_unreachable = 0; 06484 int result = IDO_OK; 06485 void *data[10]; 06486 06487 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdependencydefinition() start\n"); 06488 06489 if (idi == NULL) 06490 return IDO_ERROR; 06491 06492 /* convert timestamp, etc */ 06493 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 06494 &tstamp); 06495 06496 /* don't store old data */ 06497 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 06498 return IDO_OK; 06499 06500 /* convert vars */ 06501 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_DEPENDENCYTYPE], &dependency_type); 06502 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_INHERITSPARENT], &inherits_parent); 06503 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILONUP], &fail_on_up); 06504 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILOIDOWN], &fail_on_down); 06505 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILONUNREACHABLE], &fail_on_unreachable); 06506 06507 /* get the object ids */ 06508 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOSTNAME], NULL, &object_id); 06509 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_DEPENDENTHOSTNAME], NULL, &dependent_object_id); 06510 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_DEPENDENCYPERIOD], NULL, &timeperiod_object_id); 06511 06512 /* add definition to db */ 06513 data[0] = (void *) &idi->dbinfo.instance_id; 06514 data[1] = (void *) &idi->current_object_config_type; 06515 data[2] = (void *) &object_id; 06516 data[3] = (void *) &dependent_object_id; 06517 data[4] = (void *) &dependency_type; 06518 data[5] = (void *) &inherits_parent; 06519 data[6] = (void *) &timeperiod_object_id; 06520 data[7] = (void *) &fail_on_up; 06521 data[8] = (void *) &fail_on_down; 06522 data[9] = (void *) &fail_on_unreachable; 06523 06524 result = ido2db_query_insert_or_update_hostdependencydefinition_definition_add(idi, data); 06525 06526 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06527 dbi_result_free(idi->dbinfo.dbi_result); 06528 #endif 06529 06530 #ifdef USE_PGSQL /* pgsql */ 06531 06532 #endif 06533 06534 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06535 06536 06537 #endif /* Oracle ocilib specific */ 06538 06539 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostdependencydefinition() end\n"); 06540 06541 return IDO_OK; 06542 } 06543 06544 int ido2db_handle_servicedependencydefinition(ido2db_idi *idi) { 06545 int type, flags, attr; 06546 struct timeval tstamp; 06547 unsigned long object_id = 0L; 06548 unsigned long dependent_object_id = 0L; 06549 unsigned long timeperiod_object_id = 0L; 06550 int dependency_type = 0; 06551 int inherits_parent = 0; 06552 int fail_on_ok = 0; 06553 int fail_on_warning = 0; 06554 int fail_on_unknown = 0; 06555 int fail_on_critical = 0; 06556 int result = IDO_OK; 06557 void *data[11]; 06558 06559 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedependencydefinition() start\n"); 06560 06561 if (idi == NULL) 06562 return IDO_ERROR; 06563 06564 /* convert timestamp, etc */ 06565 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 06566 &tstamp); 06567 06568 /* don't store old data */ 06569 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 06570 return IDO_OK; 06571 06572 /* convert vars */ 06573 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_DEPENDENCYTYPE], &dependency_type); 06574 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_INHERITSPARENT], &inherits_parent); 06575 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILONOK], &fail_on_ok); 06576 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILONWARNING], &fail_on_warning); 06577 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILONUNKNOWN], &fail_on_unknown); 06578 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FAILONCRITICAL], &fail_on_critical); 06579 06580 /* get the object ids */ 06581 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOSTNAME], idi->buffered_input[IDO_DATA_SERVICEDESCRIPTION], &object_id); 06582 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_DEPENDENTHOSTNAME], idi->buffered_input[IDO_DATA_DEPENDENTSERVICEDESCRIPTION], &dependent_object_id); 06583 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_DEPENDENCYPERIOD], NULL, &timeperiod_object_id); 06584 06585 /* add definition to db */ 06586 data[0] = (void *) &idi->dbinfo.instance_id; 06587 data[1] = (void *) &idi->current_object_config_type; 06588 data[2] = (void *) &object_id; 06589 data[3] = (void *) &dependent_object_id; 06590 data[4] = (void *) &dependency_type; 06591 data[5] = (void *) &inherits_parent; 06592 data[6] = (void *) &timeperiod_object_id; 06593 data[7] = (void *) &fail_on_ok; 06594 data[8] = (void *) &fail_on_warning; 06595 data[9] = (void *) &fail_on_unknown; 06596 data[10] = (void *) &fail_on_critical; 06597 06598 result = ido2db_query_insert_or_update_servicedependencydefinition_definition_add(idi, data); 06599 06600 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06601 dbi_result_free(idi->dbinfo.dbi_result); 06602 #endif 06603 06604 #ifdef USE_PGSQL /* pgsql */ 06605 06606 #endif 06607 06608 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06609 06610 06611 #endif /* Oracle ocilib specific */ 06612 06613 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicedependencydefinition() end\n"); 06614 06615 return IDO_OK; 06616 } 06617 06618 int ido2db_handle_hostescalationdefinition(ido2db_idi *idi) { 06619 int type, flags, attr; 06620 struct timeval tstamp; 06621 unsigned long object_id = 0L; 06622 unsigned long timeperiod_id = 0L; 06623 unsigned long escalation_id = 0L; 06624 unsigned long member_id = 0L; 06625 int first_notification = 0; 06626 int last_notification = 0; 06627 double notification_interval = 0.0; 06628 int escalate_recovery = 0; 06629 int escalate_down = 0; 06630 int escalate_unreachable = 0; 06631 int result = IDO_OK; 06632 int x = 0; 06633 #ifdef USE_LIBDBI 06634 char *buf = NULL; 06635 #endif 06636 ido2db_mbuf mbuf; 06637 #ifdef USE_ORACLE 06638 char *seq_name = NULL; 06639 #endif 06640 void *data[10]; 06641 06642 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostescalationdefinition() start\n"); 06643 06644 if (idi == NULL) 06645 return IDO_ERROR; 06646 06647 /* convert timestamp, etc */ 06648 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 06649 &tstamp); 06650 06651 /* don't store old data */ 06652 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 06653 return IDO_OK; 06654 06655 /* convert vars */ 06656 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FIRSTNOTIFICATION], &first_notification); 06657 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_LASTNOTIFICATION], &last_notification); 06658 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_NOTIFICATIONINTERVAL], ¬ification_interval); 06659 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ESCALATEONRECOVERY], &escalate_recovery); 06660 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ESCALATEOIDOWN], &escalate_down); 06661 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ESCALATEONUNREACHABLE], &escalate_unreachable); 06662 06663 /* get the object id */ 06664 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST, idi->buffered_input[IDO_DATA_HOSTNAME], NULL, &object_id); 06665 06666 /* get the timeperiod id */ 06667 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_ESCALATIONPERIOD], NULL, &timeperiod_id); 06668 06669 /* add definition to db */ 06670 data[0] = (void *) &idi->dbinfo.instance_id; 06671 data[1] = (void *) &idi->current_object_config_type; 06672 data[2] = (void *) &object_id; 06673 data[3] = (void *) &timeperiod_id; 06674 data[4] = (void *) &first_notification; 06675 data[5] = (void *) &last_notification; 06676 data[6] = (void *) ¬ification_interval; 06677 data[7] = (void *) &escalate_recovery; 06678 data[8] = (void *) &escalate_down; 06679 data[9] = (void *) &escalate_unreachable; 06680 06681 result = ido2db_query_insert_or_update_hostescalationdefinition_definition_add(idi, data); 06682 06683 if (result == IDO_OK) { 06684 06685 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06686 switch (idi->dbinfo.server_type) { 06687 case IDO2DB_DBSERVER_MYSQL: 06688 /* mysql doesn't use sequences */ 06689 escalation_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 06690 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostescalationdefinition(%lu) escalation_id\n", escalation_id); 06691 break; 06692 case IDO2DB_DBSERVER_PGSQL: 06693 /* depending on tableprefix/tablename a sequence will be used */ 06694 if(asprintf(&buf, "%s_hostescalation_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONS]) == -1) 06695 buf = NULL; 06696 06697 escalation_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 06698 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostescalationdefinition(%s=%lu) escalation_id\n", buf, escalation_id); 06699 free(buf); 06700 break; 06701 case IDO2DB_DBSERVER_DB2: 06702 break; 06703 case IDO2DB_DBSERVER_FIREBIRD: 06704 break; 06705 case IDO2DB_DBSERVER_FREETDS: 06706 break; 06707 case IDO2DB_DBSERVER_INGRES: 06708 break; 06709 case IDO2DB_DBSERVER_MSQL: 06710 break; 06711 case IDO2DB_DBSERVER_ORACLE: 06712 break; 06713 case IDO2DB_DBSERVER_SQLITE: 06714 break; 06715 case IDO2DB_DBSERVER_SQLITE3: 06716 break; 06717 default: 06718 break; 06719 } 06720 #endif 06721 06722 #ifdef USE_PGSQL /* pgsql */ 06723 06724 #endif 06725 06726 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06727 if(asprintf(&seq_name, "seq_hostescalations")==-1) 06728 seq_name=NULL; 06729 escalation_id = ido2db_ocilib_insert_id(idi, seq_name); 06730 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostescalationdefinition(%lu) escalation_id\n", escalation_id); 06731 free(seq_name); 06732 06733 #endif /* Oracle ocilib specific */ 06734 } 06735 06736 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06737 dbi_result_free(idi->dbinfo.dbi_result); 06738 #endif 06739 06740 #ifdef USE_PGSQL /* pgsql */ 06741 06742 #endif 06743 06744 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06745 06746 06747 #endif /* Oracle ocilib specific */ 06748 06749 /* save contact groups to db */ 06750 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTGROUP]; 06751 for (x = 0; x < mbuf.used_lines; x++) { 06752 06753 if (mbuf.buffer[x] == NULL) 06754 continue; 06755 06756 /* get the object id of the member */ 06757 result = ido2db_get_object_id_with_insert(idi, 06758 IDO2DB_OBJECTTYPE_CONTACTGROUP, mbuf.buffer[x], NULL, 06759 &member_id); 06760 06761 /* save entry to db */ 06762 data[0] = (void *) &idi->dbinfo.instance_id; 06763 data[1] = (void *) &escalation_id; 06764 data[2] = (void *) &member_id; 06765 06766 result = ido2db_query_insert_or_update_hostescalationdefinition_contactgroups_add(idi, data); 06767 06768 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06769 dbi_result_free(idi->dbinfo.dbi_result); 06770 #endif 06771 06772 #ifdef USE_PGSQL /* pgsql */ 06773 06774 #endif 06775 06776 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06777 06778 06779 #endif /* Oracle ocilib specific */ 06780 06781 } 06782 06783 /* save contacts to db */ 06784 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACT]; 06785 for (x = 0; x < mbuf.used_lines; x++) { 06786 06787 if (mbuf.buffer[x] == NULL) 06788 continue; 06789 06790 /* get the object id of the member */ 06791 result = ido2db_get_object_id_with_insert(idi, 06792 IDO2DB_OBJECTTYPE_CONTACT, mbuf.buffer[x], NULL, &member_id); 06793 06794 /* save entry tp db */ 06795 data[0] = (void *) &idi->dbinfo.instance_id; 06796 data[1] = (void *) &escalation_id; 06797 data[2] = (void *) &member_id; 06798 06799 result = ido2db_query_insert_or_update_hostescalationdefinition_contacts_add(idi, data); 06800 06801 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06802 dbi_result_free(idi->dbinfo.dbi_result); 06803 #endif 06804 06805 #ifdef USE_PGSQL /* pgsql */ 06806 06807 #endif 06808 06809 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06810 06811 06812 #endif /* Oracle ocilib specific */ 06813 06814 } 06815 06816 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostescalationdefinition() end\n"); 06817 06818 return IDO_OK; 06819 } 06820 06821 int ido2db_handle_serviceescalationdefinition(ido2db_idi *idi) { 06822 int type, flags, attr; 06823 struct timeval tstamp; 06824 unsigned long object_id = 0L; 06825 unsigned long timeperiod_id = 0L; 06826 unsigned long escalation_id = 0L; 06827 unsigned long member_id = 0L; 06828 int first_notification = 0; 06829 int last_notification = 0; 06830 double notification_interval = 0.0; 06831 int escalate_recovery = 0; 06832 int escalate_warning = 0; 06833 int escalate_unknown = 0; 06834 int escalate_critical = 0; 06835 int result = IDO_OK; 06836 int x = 0; 06837 #ifdef USE_LIBDBI 06838 char *buf = NULL; 06839 #endif 06840 ido2db_mbuf mbuf; 06841 #ifdef USE_ORACLE 06842 char *seq_name = NULL; 06843 #endif 06844 void *data[11]; 06845 06846 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicetescalationdefinition() start\n"); 06847 06848 if (idi == NULL) 06849 return IDO_ERROR; 06850 06851 /* convert timestamp, etc */ 06852 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 06853 &tstamp); 06854 06855 /* don't store old data */ 06856 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 06857 return IDO_OK; 06858 06859 /* convert vars */ 06860 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_FIRSTNOTIFICATION], &first_notification); 06861 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_LASTNOTIFICATION], &last_notification); 06862 result = ido2db_convert_string_to_double(idi->buffered_input[IDO_DATA_NOTIFICATIONINTERVAL], ¬ification_interval); 06863 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ESCALATEONRECOVERY], &escalate_recovery); 06864 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ESCALATEONWARNING], &escalate_warning); 06865 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ESCALATEONUNKNOWN], &escalate_unknown); 06866 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_ESCALATEONCRITICAL], &escalate_critical); 06867 06868 /* get the object id */ 06869 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_SERVICE, idi->buffered_input[IDO_DATA_HOSTNAME], idi->buffered_input[IDO_DATA_SERVICEDESCRIPTION], &object_id); 06870 06871 /* get the timeperiod id */ 06872 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_ESCALATIONPERIOD], NULL, &timeperiod_id); 06873 06874 /* add definition to db */ 06875 data[0] = (void *) &idi->dbinfo.instance_id; 06876 data[1] = (void *) &idi->current_object_config_type; 06877 data[2] = (void *) &object_id; 06878 data[3] = (void *) &timeperiod_id; 06879 data[4] = (void *) &first_notification; 06880 data[5] = (void *) &last_notification; 06881 data[6] = (void *) ¬ification_interval; 06882 data[7] = (void *) &escalate_recovery; 06883 data[8] = (void *) &escalate_warning; 06884 data[9] = (void *) &escalate_unknown; 06885 data[10] = (void *) &escalate_critical; 06886 06887 result = ido2db_query_insert_or_update_serviceescalationdefinition_definition_add(idi, data); 06888 06889 if (result == IDO_OK) { 06890 06891 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06892 switch (idi->dbinfo.server_type) { 06893 case IDO2DB_DBSERVER_MYSQL: 06894 /* mysql doesn't use sequences */ 06895 escalation_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 06896 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_serviceescalationdefinition(%lu) escalation_id\n", escalation_id); 06897 break; 06898 case IDO2DB_DBSERVER_PGSQL: 06899 /* depending on tableprefix/tablename a sequence will be used */ 06900 if(asprintf(&buf, "%s_serviceescalation_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONS]) == -1) 06901 buf = NULL; 06902 06903 escalation_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 06904 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_serviceescalationdefinition(%s=%lu) escalation_id\n", buf, escalation_id); 06905 free(buf); 06906 break; 06907 case IDO2DB_DBSERVER_DB2: 06908 break; 06909 case IDO2DB_DBSERVER_FIREBIRD: 06910 break; 06911 case IDO2DB_DBSERVER_FREETDS: 06912 break; 06913 case IDO2DB_DBSERVER_INGRES: 06914 break; 06915 case IDO2DB_DBSERVER_MSQL: 06916 break; 06917 case IDO2DB_DBSERVER_ORACLE: 06918 break; 06919 case IDO2DB_DBSERVER_SQLITE: 06920 break; 06921 case IDO2DB_DBSERVER_SQLITE3: 06922 break; 06923 default: 06924 break; 06925 } 06926 #endif 06927 06928 #ifdef USE_PGSQL /* pgsql */ 06929 06930 #endif 06931 06932 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06933 if(asprintf(&seq_name, "seq_serviceescalations")==-1) 06934 seq_name=NULL; 06935 escalation_id = ido2db_ocilib_insert_id(idi, seq_name); 06936 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_serviceescalationdefinition(%lu) escalation_id\n", escalation_id); 06937 free(seq_name); 06938 06939 #endif /* Oracle ocilib specific */ 06940 } 06941 06942 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06943 dbi_result_free(idi->dbinfo.dbi_result); 06944 #endif 06945 06946 #ifdef USE_PGSQL /* pgsql */ 06947 06948 #endif 06949 06950 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06951 06952 06953 #endif /* Oracle ocilib specific */ 06954 06955 /* save contact groups to db */ 06956 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTGROUP]; 06957 for (x = 0; x < mbuf.used_lines; x++) { 06958 06959 if (mbuf.buffer[x] == NULL) 06960 continue; 06961 06962 /* get the object id of the member */ 06963 result = ido2db_get_object_id_with_insert(idi, 06964 IDO2DB_OBJECTTYPE_CONTACTGROUP, mbuf.buffer[x], NULL, 06965 &member_id); 06966 06967 /* save entry to db */ 06968 data[0] = (void *) &idi->dbinfo.instance_id; 06969 data[1] = (void *) &escalation_id; 06970 data[2] = (void *) &member_id; 06971 06972 result = ido2db_query_insert_or_update_serviceescalationdefinition_contactgroups_add(idi, data); 06973 06974 #ifdef USE_LIBDBI /* everything else will be libdbi */ 06975 dbi_result_free(idi->dbinfo.dbi_result); 06976 #endif 06977 06978 #ifdef USE_PGSQL /* pgsql */ 06979 06980 #endif 06981 06982 #ifdef USE_ORACLE /* Oracle ocilib specific */ 06983 06984 06985 #endif /* Oracle ocilib specific */ 06986 06987 } 06988 06989 /* save contacts to db */ 06990 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACT]; 06991 for (x = 0; x < mbuf.used_lines; x++) { 06992 06993 if (mbuf.buffer[x] == NULL) 06994 continue; 06995 06996 /* get the object id of the member */ 06997 result = ido2db_get_object_id_with_insert(idi, 06998 IDO2DB_OBJECTTYPE_CONTACT, mbuf.buffer[x], NULL, &member_id); 06999 07000 /* save entry to db */ 07001 data[0] = (void *) &idi->dbinfo.instance_id; 07002 data[1] = (void *) &escalation_id; 07003 data[2] = (void *) &member_id; 07004 07005 result = ido2db_query_insert_or_update_serviceescalationdefinition_contacts_add(idi, data); 07006 07007 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07008 dbi_result_free(idi->dbinfo.dbi_result); 07009 #endif 07010 07011 #ifdef USE_PGSQL /* pgsql */ 07012 07013 #endif 07014 07015 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07016 07017 07018 #endif /* Oracle ocilib specific */ 07019 07020 } 07021 07022 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicetescalationdefinition() end\n"); 07023 07024 return IDO_OK; 07025 } 07026 07027 int ido2db_handle_commanddefinition(ido2db_idi *idi) { 07028 int type, flags, attr; 07029 struct timeval tstamp; 07030 unsigned long object_id = 0L; 07031 int result = IDO_OK; 07032 char *es[1]; 07033 int x = 0; 07034 void *data[4]; 07035 07036 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_commanddefinition() start\n"); 07037 07038 if (idi == NULL) 07039 return IDO_ERROR; 07040 07041 /* convert timestamp, etc */ 07042 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 07043 &tstamp); 07044 07045 /* don't store old data */ 07046 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 07047 return IDO_OK; 07048 07049 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_COMMANDLINE]); 07050 07051 /* get the object id */ 07052 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, idi->buffered_input[IDO_DATA_COMMANDNAME], NULL, &object_id); 07053 07054 /* flag the object as being active */ 07055 ido2db_set_object_as_active(idi, IDO2DB_OBJECTTYPE_COMMAND, object_id); 07056 07057 /* add definition to db */ 07058 data[0] = (void *) &idi->dbinfo.instance_id; 07059 data[1] = (void *) &object_id; 07060 data[2] = (void *) &idi->current_object_config_type; 07061 data[3] = (void *) &es[0]; 07062 07063 result = ido2db_query_insert_or_update_commanddefinition_definition_add(idi, data); 07064 07065 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07066 dbi_result_free(idi->dbinfo.dbi_result); 07067 #endif 07068 07069 #ifdef USE_PGSQL /* pgsql */ 07070 07071 #endif 07072 07073 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07074 07075 07076 #endif /* Oracle ocilib specific */ 07077 07078 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 07079 free(es[x]); 07080 07081 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_commanddefinition() end\n"); 07082 07083 return IDO_OK; 07084 } 07085 07086 int ido2db_handle_timeperiodefinition(ido2db_idi *idi) { 07087 int type, flags, attr; 07088 struct timeval tstamp; 07089 unsigned long object_id = 0L; 07090 unsigned long timeperiod_id = 0L; 07091 char *dayptr = NULL; 07092 char *startptr = NULL; 07093 char *endptr = NULL; 07094 int day = 0; 07095 unsigned long start_sec = 0L; 07096 unsigned long end_sec = 0L; 07097 int result = IDO_OK; 07098 char *es[1]; 07099 int x = 0; 07100 #ifdef USE_LIBDBI 07101 char *buf = NULL; 07102 #endif 07103 ido2db_mbuf mbuf; 07104 #ifdef USE_ORACLE 07105 char *seq_name = NULL; 07106 #endif 07107 void *data[5]; 07108 07109 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_timeperiodefinition() start\n"); 07110 07111 if (idi == NULL) 07112 return IDO_ERROR; 07113 07114 /* convert timestamp, etc */ 07115 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, 07116 &tstamp); 07117 07118 /* don't store old data */ 07119 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 07120 return IDO_OK; 07121 07122 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_TIMEPERIODALIAS]); 07123 07124 /* get the object id */ 07125 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, idi->buffered_input[IDO_DATA_TIMEPERIODNAME], NULL, &object_id); 07126 07127 /* flag the object as being active */ 07128 ido2db_set_object_as_active(idi, IDO2DB_OBJECTTYPE_TIMEPERIOD, object_id); 07129 07130 /* add definition to db */ 07131 data[0] = (void *) &idi->dbinfo.instance_id; 07132 data[1] = (void *) &idi->current_object_config_type; 07133 data[2] = (void *) &object_id; 07134 data[3] = (void *) &es[0]; 07135 07136 result = ido2db_query_insert_or_update_timeperiodefinition_definition_add(idi, data); 07137 07138 if (result == IDO_OK) { 07139 07140 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07141 switch (idi->dbinfo.server_type) { 07142 case IDO2DB_DBSERVER_MYSQL: 07143 /* mysql doesn't use sequences */ 07144 timeperiod_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 07145 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_timeperiodefinition(%lu) timeperiod_id\n", timeperiod_id); 07146 break; 07147 case IDO2DB_DBSERVER_PGSQL: 07148 /* depending on tableprefix/tablename a sequence will be used */ 07149 if(asprintf(&buf, "%s_timeperiod_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODS]) == -1) 07150 buf = NULL; 07151 07152 timeperiod_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 07153 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_timeperiodefinition(%s=%lu) timeperiod_id\n", buf, timeperiod_id); 07154 free(buf); 07155 break; 07156 case IDO2DB_DBSERVER_DB2: 07157 break; 07158 case IDO2DB_DBSERVER_FIREBIRD: 07159 break; 07160 case IDO2DB_DBSERVER_FREETDS: 07161 break; 07162 case IDO2DB_DBSERVER_INGRES: 07163 break; 07164 case IDO2DB_DBSERVER_MSQL: 07165 break; 07166 case IDO2DB_DBSERVER_ORACLE: 07167 break; 07168 case IDO2DB_DBSERVER_SQLITE: 07169 break; 07170 case IDO2DB_DBSERVER_SQLITE3: 07171 break; 07172 default: 07173 break; 07174 } 07175 #endif 07176 07177 #ifdef USE_PGSQL /* pgsql */ 07178 07179 #endif 07180 07181 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07182 if(asprintf(&seq_name, "seq_timeperiods")==-1) 07183 seq_name=NULL; 07184 timeperiod_id = ido2db_ocilib_insert_id(idi, seq_name); 07185 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_timeperiodefinition(%lu) timeperiod_id\n", timeperiod_id); 07186 free(seq_name); 07187 #endif /* Oracle ocilib specific */ 07188 } 07189 07190 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07191 dbi_result_free(idi->dbinfo.dbi_result); 07192 #endif 07193 07194 #ifdef USE_PGSQL /* pgsql */ 07195 07196 #endif 07197 07198 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07199 07200 07201 #endif /* Oracle ocilib specific */ 07202 07203 free(es[0]); 07204 07205 /* save timeranges to db */ 07206 mbuf = idi->mbuf[IDO2DB_MBUF_TIMERANGE]; 07207 for (x = 0; x < mbuf.used_lines; x++) { 07208 07209 if (mbuf.buffer[x] == NULL) 07210 continue; 07211 07212 /* get var name/val pair */ 07213 dayptr = strtok(mbuf.buffer[x], ":"); 07214 startptr = strtok(NULL, "-"); 07215 endptr = strtok(NULL, "\x0"); 07216 07217 if (startptr == NULL || endptr == NULL) 07218 continue; 07219 07220 day = atoi(dayptr); 07221 start_sec = strtoul(startptr, NULL, 0); 07222 end_sec = strtoul(endptr, NULL, 0); 07223 07224 /* save entry to db */ 07225 data[0] = (void *) &idi->dbinfo.instance_id; 07226 data[1] = (void *) &timeperiod_id; 07227 data[2] = (void *) &day; 07228 data[3] = (void *) &start_sec; 07229 data[4] = (void *) &end_sec; 07230 07231 result = ido2db_query_insert_or_update_timeperiodefinition_timeranges_add(idi, data); 07232 07233 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07234 dbi_result_free(idi->dbinfo.dbi_result); 07235 #endif 07236 07237 #ifdef USE_PGSQL /* pgsql */ 07238 07239 #endif 07240 07241 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07242 07243 07244 #endif /* Oracle ocilib specific */ 07245 07246 } 07247 07248 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_timeperiodefinition() end\n"); 07249 07250 return IDO_OK; 07251 } 07252 07253 int ido2db_handle_contactdefinition(ido2db_idi *idi) { 07254 int type, flags, attr; 07255 struct timeval tstamp; 07256 unsigned long contact_id = 0L; 07257 unsigned long host_timeperiod_id = 0L; 07258 unsigned long service_timeperiod_id = 0L; 07259 int host_notifications_enabled = 0; 07260 int service_notifications_enabled = 0; 07261 int can_submit_commands = 0; 07262 int notify_service_recovery = 0; 07263 int notify_service_warning = 0; 07264 int notify_service_unknown = 0; 07265 int notify_service_critical = 0; 07266 int notify_service_flapping = 0; 07267 int notify_service_downtime = 0; 07268 int notify_host_recovery = 0; 07269 int notify_host_down = 0; 07270 int notify_host_unreachable = 0; 07271 int notify_host_flapping = 0; 07272 int notify_host_downtime = 0; 07273 unsigned long command_id = 0L; 07274 int result = IDO_OK; 07275 char *es[3]; 07276 int x = 0; 07277 #ifdef USE_LIBDBI 07278 char *buf = NULL; 07279 #endif 07280 ido2db_mbuf mbuf; 07281 char *numptr = NULL; 07282 char *addressptr = NULL; 07283 int address_number = 0; 07284 char *cmdptr = NULL; 07285 char *argptr = NULL; 07286 #ifdef USE_ORACLE 07287 char *seq_name = NULL; 07288 #endif 07289 void *data[22]; 07290 07291 int tmp1 = HOST_NOTIFICATION; 07292 int tmp2 = SERVICE_NOTIFICATION; 07293 07294 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactdefinition() start\n"); 07295 07296 if (idi == NULL) 07297 return IDO_ERROR; 07298 07299 /* convert timestamp, etc */ 07300 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 07301 07302 /* don't store old data */ 07303 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 07304 return IDO_OK; 07305 07306 /* convert vars */ 07307 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_HOSTNOTIFICATIONSENABLED], &host_notifications_enabled); 07308 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_SERVICENOTIFICATIONSENABLED], &service_notifications_enabled); 07309 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_CANSUBMITCOMMANDS], &can_submit_commands); 07310 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICEWARNING], ¬ify_service_warning); 07311 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICEUNKNOWN], ¬ify_service_unknown); 07312 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICECRITICAL], ¬ify_service_critical); 07313 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICERECOVERY], ¬ify_service_recovery); 07314 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICEFLAPPING], ¬ify_service_flapping); 07315 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYSERVICEDOWNTIME], ¬ify_service_downtime); 07316 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTDOWN], ¬ify_host_down); 07317 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTUNREACHABLE], ¬ify_host_unreachable); 07318 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTRECOVERY], ¬ify_host_recovery); 07319 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTFLAPPING], ¬ify_host_flapping); 07320 result = ido2db_convert_string_to_int(idi->buffered_input[IDO_DATA_NOTIFYHOSTDOWNTIME], ¬ify_host_downtime); 07321 07322 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_CONTACTALIAS]); 07323 es[1] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_EMAILADDRESS]); 07324 es[2] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_PAGERADDRESS]); 07325 07326 /* get the object id */ 07327 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_CONTACT, 07328 idi->buffered_input[IDO_DATA_CONTACTNAME], NULL, &contact_id); 07329 07330 /* get the timeperiod ids */ 07331 result = ido2db_get_object_id_with_insert(idi, 07332 IDO2DB_OBJECTTYPE_TIMEPERIOD, 07333 idi->buffered_input[IDO_DATA_HOSTNOTIFICATIONPERIOD], NULL, 07334 &host_timeperiod_id); 07335 result = ido2db_get_object_id_with_insert(idi, 07336 IDO2DB_OBJECTTYPE_TIMEPERIOD, 07337 idi->buffered_input[IDO_DATA_SERVICENOTIFICATIONPERIOD], NULL, 07338 &service_timeperiod_id); 07339 07340 /* flag the object as being active */ 07341 ido2db_set_object_as_active(idi, IDO2DB_OBJECTTYPE_CONTACT, contact_id); 07342 07343 /* add definition to db */ 07344 data[0] = (void *) &idi->dbinfo.instance_id; 07345 data[1] = (void *) &idi->current_object_config_type; 07346 data[2] = (void *) &contact_id; 07347 data[3] = (void *) &es[0]; 07348 data[4] = (void *) &es[1]; 07349 data[5] = (void *) &es[2]; 07350 data[6] = (void *) &host_timeperiod_id; 07351 data[7] = (void *) &service_timeperiod_id; 07352 data[8] = (void *) &host_notifications_enabled; 07353 data[9] = (void *) &service_notifications_enabled; 07354 data[10] = (void *) &can_submit_commands; 07355 data[11] = (void *) ¬ify_service_recovery; 07356 data[12] = (void *) ¬ify_service_warning; 07357 data[13] = (void *) ¬ify_service_unknown; 07358 data[14] = (void *) ¬ify_service_critical; 07359 data[15] = (void *) ¬ify_service_flapping; 07360 data[16] = (void *) ¬ify_service_downtime; 07361 data[17] = (void *) ¬ify_host_recovery; 07362 data[18] = (void *) ¬ify_host_down; 07363 data[19] = (void *) ¬ify_host_unreachable; 07364 data[20] = (void *) ¬ify_host_flapping; 07365 data[21] = (void *) ¬ify_host_downtime; 07366 07367 result = ido2db_query_insert_or_update_contactdefinition_definition_add(idi, data); 07368 07369 if (result == IDO_OK) { 07370 07371 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07372 switch (idi->dbinfo.server_type) { 07373 case IDO2DB_DBSERVER_MYSQL: 07374 /* mysql doesn't use sequences */ 07375 contact_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 07376 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactdefinition(ido2db_idi *idi)(%lu) contact_id\n", contact_id); 07377 break; 07378 case IDO2DB_DBSERVER_PGSQL: 07379 /* depending on tableprefix/tablename a sequence will be used */ 07380 if(asprintf(&buf, "%s_contact_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTS]) == -1) 07381 buf = NULL; 07382 07383 contact_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 07384 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactdefinition(ido2db_idi *idi)(%s=%lu) contact_id\n", buf, contact_id); 07385 free(buf); 07386 break; 07387 case IDO2DB_DBSERVER_DB2: 07388 break; 07389 case IDO2DB_DBSERVER_FIREBIRD: 07390 break; 07391 case IDO2DB_DBSERVER_FREETDS: 07392 break; 07393 case IDO2DB_DBSERVER_INGRES: 07394 break; 07395 case IDO2DB_DBSERVER_MSQL: 07396 break; 07397 case IDO2DB_DBSERVER_ORACLE: 07398 break; 07399 case IDO2DB_DBSERVER_SQLITE: 07400 break; 07401 case IDO2DB_DBSERVER_SQLITE3: 07402 break; 07403 default: 07404 break; 07405 } 07406 #endif 07407 07408 #ifdef USE_PGSQL /* pgsql */ 07409 07410 #endif 07411 07412 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07413 if(asprintf(&seq_name, "seq_contacts")==-1) 07414 seq_name=NULL; 07415 contact_id = ido2db_ocilib_insert_id(idi, seq_name); 07416 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactdefinition(ido2db_idi *idi)(%lu) contact_id\n", contact_id); 07417 free(seq_name); 07418 #endif /* Oracle ocilib specific */ 07419 } 07420 07421 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07422 dbi_result_free(idi->dbinfo.dbi_result); 07423 #endif 07424 07425 #ifdef USE_PGSQL /* pgsql */ 07426 07427 #endif 07428 07429 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07430 07431 07432 #endif /* Oracle ocilib specific */ 07433 07434 for (x = 0; x < ICINGA_SIZEOF_ARRAY(es); x++) 07435 free(es[x]); 07436 07437 /* save addresses to db */ 07438 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTADDRESS]; 07439 for (x = 0; x < mbuf.used_lines; x++) { 07440 07441 if (mbuf.buffer[x] == NULL) 07442 continue; 07443 07444 numptr = strtok(mbuf.buffer[x], ":"); 07445 addressptr = strtok(NULL, "\x0"); 07446 07447 if (numptr == NULL || addressptr == NULL) 07448 continue; 07449 07450 address_number = atoi(numptr); 07451 es[0] = ido2db_db_escape_string(idi, addressptr); 07452 07453 /* save entry to db */ 07454 data[0] = (void *) &idi->dbinfo.instance_id; 07455 data[1] = (void *) &contact_id; 07456 data[2] = (void *) &address_number; 07457 data[3] = (void *) &es[0]; 07458 07459 result = ido2db_query_insert_or_update_contactdefinition_addresses_add(idi, data); 07460 07461 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07462 dbi_result_free(idi->dbinfo.dbi_result); 07463 #endif 07464 07465 #ifdef USE_PGSQL /* pgsql */ 07466 07467 #endif 07468 07469 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07470 07471 07472 #endif /* Oracle ocilib specific */ 07473 07474 free(es[0]); 07475 } 07476 07477 /* save host notification commands to db */ 07478 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTADDRESS]; 07479 for (x = 0; x < mbuf.used_lines; x++) { 07480 07481 if (mbuf.buffer[x] == NULL) 07482 continue; 07483 07484 cmdptr = strtok(mbuf.buffer[x], "!"); 07485 argptr = strtok(NULL, "\x0"); 07486 07487 if (numptr == NULL) 07488 //if (cmdptr == NULL || argptr == NULL) 07489 continue; 07490 07491 /* find the command */ 07492 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, cmdptr, NULL, &command_id); 07493 07494 es[0] = ido2db_db_escape_string(idi, argptr); 07495 07496 /* save entry to db */ 07497 data[0] = (void *) &idi->dbinfo.instance_id; 07498 data[1] = (void *) &contact_id; 07499 data[2] = (void *) &tmp1; 07500 data[3] = (void *) &command_id; 07501 data[4] = (void *) &es[0]; 07502 07503 result = ido2db_query_insert_or_update_contactdefinition_notificationcommands_add(idi, data); 07504 07505 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07506 dbi_result_free(idi->dbinfo.dbi_result); 07507 #endif 07508 07509 #ifdef USE_PGSQL /* pgsql */ 07510 07511 #endif 07512 07513 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07514 07515 /* do not free if prepared statement */ 07516 07517 #endif /* Oracle ocilib specific */ 07518 07519 free(es[0]); 07520 } 07521 07522 /* save service notification commands to db */ 07523 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTADDRESS]; 07524 for (x = 0; x < mbuf.used_lines; x++) { 07525 07526 if (mbuf.buffer[x] == NULL) 07527 continue; 07528 07529 cmdptr = strtok(mbuf.buffer[x], "!"); 07530 argptr = strtok(NULL, "\x0"); 07531 07532 if (numptr == NULL) 07533 //if (cmdptr == NULL || argptr == NULL) 07534 continue; 07535 07536 /* find the command */ 07537 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_COMMAND, cmdptr, NULL, &command_id); 07538 07539 es[0] = ido2db_db_escape_string(idi, argptr); 07540 07541 /* save entry to db */ 07542 07543 data[0] = (void *) &idi->dbinfo.instance_id; 07544 data[1] = (void *) &contact_id; 07545 data[2] = (void *) &tmp2; 07546 data[3] = (void *) &command_id; 07547 data[4] = (void *) &es[0]; 07548 07549 result = ido2db_query_insert_or_update_contactdefinition_notificationcommands_add(idi, data); 07550 07551 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07552 dbi_result_free(idi->dbinfo.dbi_result); 07553 #endif 07554 07555 #ifdef USE_PGSQL /* pgsql */ 07556 07557 #endif 07558 07559 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07560 07561 /* do not free if prepared statement */ 07562 07563 #endif /* Oracle ocilib specific */ 07564 07565 free(es[0]); 07566 } 07567 07568 /* save custom variables to db */ 07569 result=ido2db_save_custom_variables(idi,IDO2DB_DBTABLE_CUSTOMVARIABLES,contact_id,NULL, -1); 07570 07571 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactdefinition() end\n"); 07572 07573 return IDO_OK; 07574 } 07575 07576 int ido2db_save_custom_variables(ido2db_idi *idi,int table_idx, unsigned long o_id, char *ts, unsigned long tstamp){ 07577 char *buf=NULL; 07578 ido2db_mbuf mbuf; 07579 char *es[2]; 07580 char *ptr1=NULL; 07581 char *ptr2=NULL; 07582 char *ptr3=NULL; 07583 int result=IDO_OK; 07584 int has_been_modified=0; 07585 int x=0; 07586 void *data[7]; 07587 07588 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_save_custom_variables() start\n"); 07589 07590 /* save custom variables to db */ 07591 mbuf=idi->mbuf[IDO2DB_MBUF_CUSTOMVARIABLE]; 07592 for(x=0;x<mbuf.used_lines;x++){ 07593 07594 if(mbuf.buffer[x]==NULL) 07595 continue; 07596 07597 if((ptr1=strtok(mbuf.buffer[x],":"))==NULL) 07598 continue; 07599 07600 es[0]=strdup(ptr1); 07601 07602 if((ptr2=strtok(NULL,":"))==NULL) 07603 continue; 07604 07605 has_been_modified=atoi(ptr2); 07606 ptr3=strtok(NULL,"\n"); 07607 buf=strdup((ptr3==NULL)?"":ptr3); 07608 es[1]=ido2db_db_escape_string(idi,buf); 07609 free(buf); 07610 07611 if(ts == NULL) { 07612 if(asprintf(&ts, "NULL")==-1) 07613 ; 07614 } 07615 07616 if (table_idx==IDO2DB_DBTABLE_CUSTOMVARIABLES) { 07617 07618 /* save entry to db */ 07619 data[0] = (void *) &idi->dbinfo.instance_id; 07620 data[1] = (void *) &o_id; 07621 data[2] = (void *) &idi->current_object_config_type; 07622 data[3] = (void *) &has_been_modified; 07623 data[4] = (es[0]==NULL)?NULL:(void *) &es[0]; 07624 data[5] = (es[1]==NULL)?NULL:(void *) &es[1]; 07625 07626 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_save_custom_variables() instance_id=%lu, object_id=%lu, config_type=%d, modified=%d, varname=%s, varvalue=%s\n", idi->dbinfo.instance_id, o_id, idi->current_object_config_type, has_been_modified, es[0], es[1]); 07627 07628 result = ido2db_query_insert_or_update_save_custom_variables_customvariables_add(idi, data); 07629 07630 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07631 dbi_result_free(idi->dbinfo.dbi_result); 07632 #endif 07633 07634 #ifdef USE_PGSQL /* pgsql */ 07635 07636 #endif 07637 07638 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07639 07640 07641 #endif /* Oracle ocilib specific */ 07642 07643 } 07644 if (table_idx==IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS) { 07645 07646 /* save entry to db */ 07647 data[0] = (void *) &idi->dbinfo.instance_id; 07648 data[1] = (void *) &o_id; 07649 data[2] = (void *) &ts; 07650 data[3] = (void *) &has_been_modified; 07651 data[4] = (es[0]==NULL)?NULL:(void *) &es[0]; 07652 data[5] = (es[1]==NULL)?NULL:(void *) &es[1]; 07653 /* wtf is ts doing here? */ 07654 data[6] = (void *) &tstamp; 07655 07656 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_save_custom_variablestatus() instance_id=%lu, object_id=%lu, ts=%s, modified=%d, varname=%s, varvalue=%s\n", idi->dbinfo.instance_id, o_id, ts, has_been_modified, es[0], es[1]); 07657 07658 result = ido2db_query_insert_or_update_save_custom_variables_customvariablestatus_add(idi, data); 07659 07660 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07661 dbi_result_free(idi->dbinfo.dbi_result); 07662 #endif 07663 07664 #ifdef USE_PGSQL /* pgsql */ 07665 07666 #endif 07667 07668 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07669 07670 07671 #endif /* Oracle ocilib specific */ 07672 07673 } 07674 07675 free(es[0]); 07676 free(es[1]); 07677 } 07678 07679 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_save_custom_variables() end\n"); 07680 07681 return result; 07682 07683 } 07684 07685 int ido2db_handle_contactgroupdefinition(ido2db_idi *idi) { 07686 int type, flags, attr; 07687 struct timeval tstamp; 07688 unsigned long object_id = 0L; 07689 unsigned long group_id = 0L; 07690 unsigned long member_id = 0L; 07691 int result = IDO_OK; 07692 char *es[1]; 07693 int x = 0; 07694 #ifdef USE_LIBDBI 07695 char *buf = NULL; 07696 #endif 07697 ido2db_mbuf mbuf; 07698 #ifdef USE_ORACLE 07699 char *seq_name = NULL; 07700 #endif 07701 void *data[4]; 07702 07703 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactgroupdefinition() start\n"); 07704 07705 if (idi == NULL) 07706 return IDO_ERROR; 07707 07708 /* convert timestamp, etc */ 07709 result = ido2db_convert_standard_data_elements(idi, &type, &flags, &attr, &tstamp); 07710 07711 /* don't store old data */ 07712 if (tstamp.tv_sec < idi->dbinfo.latest_realtime_data_time) 07713 return IDO_OK; 07714 07715 es[0] = ido2db_db_escape_string(idi, idi->buffered_input[IDO_DATA_CONTACTGROUPALIAS]); 07716 07717 /* get the object id */ 07718 result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_CONTACTGROUP, idi->buffered_input[IDO_DATA_CONTACTGROUPNAME], NULL, &object_id); 07719 07720 /* flag the object as being active */ 07721 ido2db_set_object_as_active(idi, IDO2DB_OBJECTTYPE_CONTACTGROUP, object_id); 07722 07723 /* add definition to db */ 07724 data[0] = (void *) &idi->dbinfo.instance_id; 07725 data[1] = (void *) &idi->current_object_config_type; 07726 data[2] = (void *) &object_id; 07727 data[3] = (void *) &es[0]; 07728 07729 result = ido2db_query_insert_or_update_contactgroupdefinition_definition_add(idi, data); 07730 07731 if (result == IDO_OK) { 07732 07733 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07734 switch (idi->dbinfo.server_type) { 07735 case IDO2DB_DBSERVER_MYSQL: 07736 /* mysql doesn't use sequences */ 07737 group_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, NULL); 07738 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactgroupdefinition(%lu) group_id\n", group_id); 07739 break; 07740 case IDO2DB_DBSERVER_PGSQL: 07741 /* depending on tableprefix/tablename a sequence will be used */ 07742 if(asprintf(&buf, "%s_contactgroup_id_seq", ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPS]) == -1) 07743 buf = NULL; 07744 07745 group_id = dbi_conn_sequence_last(idi->dbinfo.dbi_conn, buf); 07746 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactgroupdefinition(%s=%lu) group_id\n", buf, group_id); 07747 free(buf); 07748 break; 07749 case IDO2DB_DBSERVER_DB2: 07750 break; 07751 case IDO2DB_DBSERVER_FIREBIRD: 07752 break; 07753 case IDO2DB_DBSERVER_FREETDS: 07754 break; 07755 case IDO2DB_DBSERVER_INGRES: 07756 break; 07757 case IDO2DB_DBSERVER_MSQL: 07758 break; 07759 case IDO2DB_DBSERVER_ORACLE: 07760 break; 07761 case IDO2DB_DBSERVER_SQLITE: 07762 break; 07763 case IDO2DB_DBSERVER_SQLITE3: 07764 break; 07765 default: 07766 break; 07767 } 07768 #endif 07769 07770 #ifdef USE_PGSQL /* pgsql */ 07771 07772 #endif 07773 07774 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07775 dummy=asprintf(&seq_name, "seq_contactgroups"); 07776 group_id = ido2db_ocilib_insert_id(idi, seq_name); 07777 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactgroupdefinition(%lu) group_id\n", group_id); 07778 free(seq_name); 07779 07780 #endif /* Oracle ocilib specific */ 07781 } 07782 07783 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07784 dbi_result_free(idi->dbinfo.dbi_result); 07785 #endif 07786 07787 #ifdef USE_PGSQL /* pgsql */ 07788 07789 #endif 07790 07791 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07792 07793 07794 #endif /* Oracle ocilib specific */ 07795 07796 free(es[0]); 07797 07798 /* save contact group members to db */ 07799 mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTGROUPMEMBER]; 07800 for (x = 0; x < mbuf.used_lines; x++) { 07801 07802 if (mbuf.buffer[x] == NULL) 07803 continue; 07804 07805 /* get the object id of the member */ 07806 result = ido2db_get_object_id_with_insert(idi, 07807 IDO2DB_OBJECTTYPE_CONTACT, mbuf.buffer[x], NULL, &member_id); 07808 07809 /* save entry to db */ 07810 data[0] = (void *) &idi->dbinfo.instance_id; 07811 data[1] = (void *) &group_id; 07812 data[2] = (void *) &member_id; 07813 07814 result = ido2db_query_insert_or_update_contactgroupdefinition_contactgroupmembers_add(idi, data); 07815 07816 #ifdef USE_LIBDBI /* everything else will be libdbi */ 07817 dbi_result_free(idi->dbinfo.dbi_result); 07818 #endif 07819 07820 #ifdef USE_PGSQL /* pgsql */ 07821 07822 #endif 07823 07824 #ifdef USE_ORACLE /* Oracle ocilib specific */ 07825 07826 07827 #endif /* Oracle ocilib specific */ 07828 07829 } 07830 07831 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_contactgroupdefinition() end\n"); 07832 07833 return IDO_OK; 07834 }