module/idoutils/include/ido2db.h

Go to the documentation of this file.
00001 /************************************************************************
00002  *
00003  * IDO2DB.H - IDO2DB Include File
00004  * Copyright (c) 2005-2007 Ethan Galstad
00005  * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
00006  *
00007  ************************************************************************/
00008 
00009 #ifndef _IDO2DB_IDO2DB_H
00010 #define _IDO2DB_IDO2DB_H
00011 
00012 #include "../../../include/config.h"
00013 #include "utils.h"
00014 
00015 #define IDO2DB_NAME "IDO2DB"
00016 #define IDO2DB_DATE "03-31-2011"
00017 #define IDO2DB_VERSION "1.3.1"
00018 
00019 /*************** RDBMS headers *************/
00020 
00021 /* oracle */
00022 #ifdef USE_ORACLE
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #undef HAVE_CONFIG_H
00026 #include <ocilib.h>
00027 #define HAVE_CONFIG_H
00028 #else
00029 #include <ocilib.h>
00030 #endif
00031 
00032 #endif
00033 
00034 /* pgsql */
00035 #ifdef HAVE_LIBPQ_FE_H
00036 #include <libpq-fe.h>
00037 #endif
00038 
00039 /* libdbi */
00040 #ifdef HAVE_DBI_DBI_H
00041 #include <dbi/dbi.h>
00042 #endif
00043 
00044 
00045 /*************** mbuf definitions *************/
00046 #define IDO2DB_MBUF_CONTACTGROUP                        0
00047 #define IDO2DB_MBUF_CONTACTGROUPMEMBER                  1
00048 #define IDO2DB_MBUF_SERVICEGROUPMEMBER                  2
00049 #define IDO2DB_MBUF_HOSTGROUPMEMBER                     3
00050 #define IDO2DB_MBUF_SERVICENOTIFICATIONCOMMAND          4
00051 #define IDO2DB_MBUF_HOSTNOTIFICATIONCOMMAND             5
00052 #define IDO2DB_MBUF_CONTACTADDRESS                      6
00053 #define IDO2DB_MBUF_TIMERANGE                           7
00054 #define IDO2DB_MBUF_PARENTHOST                          8
00055 #define IDO2DB_MBUF_CONFIGFILEVARIABLE                  9
00056 #define IDO2DB_MBUF_CONFIGVARIABLE                      10
00057 #define IDO2DB_MBUF_RUNTIMEVARIABLE                     11
00058 #define IDO2DB_MBUF_CUSTOMVARIABLE                      12
00059 #define IDO2DB_MBUF_CONTACT                             13
00060 
00061 #define IDO2DB_MAX_MBUF_ITEMS                           14
00062 
00063 #define IDO2DB_MAX_BUFLEN                               16384
00064 
00065 
00066 /***************** structures *****************/
00067 
00068 typedef struct ido2db_mbuf_struct{
00069         int used_lines;
00070         int allocated_lines;
00071         char **buffer;
00072         }ido2db_mbuf;
00073 
00074 
00075 typedef struct ido2db_dbobject_struct{
00076         char *name1;
00077         char *name2;
00078         int object_type;
00079         unsigned long object_id;
00080         struct ido2db_dbobject_struct *nexthash;
00081         }ido2db_dbobject;
00082 
00083 
00084 typedef struct ido2db_dbconninfo_struct{
00085         int server_type;
00086         int connected;
00087         int error;
00088 #ifdef USE_LIBDBI /* libdbi specific */
00089         dbi_conn dbi_conn;
00090         dbi_result dbi_result;
00091 #endif
00092 
00093 #ifdef USE_PGSQL /* pgsql specific */
00094         PGconn *pg_conn;
00095         PGresult *pg_result;
00096 #endif
00097 
00098 #ifdef USE_ORACLE /* Oracle ocilib specific */
00099         OCI_Connection* oci_connection;
00100         OCI_Statement* oci_statement;
00101         OCI_Resultset* oci_resultset;
00102         /* for bind params keep prepared statements */
00103         OCI_Statement* oci_statement_objects_insert;
00104         OCI_Statement* oci_statement_logentries_insert;
00105         OCI_Statement* oci_statement_startup_clean;
00106         OCI_Statement* oci_statement_timedevents;
00107         OCI_Statement* oci_statement_timedevents_queue;
00108         OCI_Statement* oci_statement_timedeventqueue;
00109         OCI_Statement* oci_statement_hostchecks;
00110         OCI_Statement* oci_statement_hoststatus;
00111         OCI_Statement* oci_statement_servicechecks;
00112         OCI_Statement* oci_statement_servicestatus;
00113         OCI_Statement* oci_statement_contact_notificationcommands;
00114         OCI_Statement* oci_statement_programstatus;
00115         OCI_Statement* oci_statement_systemcommanddata;
00116         OCI_Statement* oci_statement_eventhandlerdata;
00117         OCI_Statement* oci_statement_notificationdata;
00118         OCI_Statement* oci_statement_contactnotificationdata;
00119         OCI_Statement* oci_statement_contactnotificationmethoddata;
00120         OCI_Statement* oci_statement_commentdata;
00121         OCI_Statement* oci_statement_commentdata_history;
00122         OCI_Statement* oci_statement_downtimedata_scheduled_downtime;
00123         OCI_Statement* oci_statement_downtimedata_downtime_history;
00124         OCI_Statement* oci_statement_contactstatusdata;
00125         OCI_Statement* oci_statement_configfilevariables;
00126         OCI_Statement* oci_statement_configfilevariables_insert;
00127         OCI_Statement* oci_statement_runtimevariables;
00128         OCI_Statement* oci_statement_hostdefinition_definition;
00129         OCI_Statement* oci_statement_hostdefinition_parenthosts;
00130         OCI_Statement* oci_statement_hostdefinition_contactgroups;
00131         OCI_Statement* oci_statement_hostdefinition_contacts;
00132         OCI_Statement* oci_statement_hostgroupdefinition_definition;
00133         OCI_Statement* oci_statement_hostgroupdefinition_hostgroupmembers;
00134         OCI_Statement* oci_statement_servicedefinition_definition;
00135         OCI_Statement* oci_statement_servicedefinition_contactgroups;
00136         OCI_Statement* oci_statement_servicedefinition_contacts;
00137         OCI_Statement* oci_statement_servicegroupdefinition_definition;
00138         OCI_Statement* oci_statement_servicegroupdefinition_members;
00139         OCI_Statement* oci_statement_hostdependencydefinition_definition;
00140         OCI_Statement* oci_statement_servicedependencydefinition_definition;
00141         OCI_Statement* oci_statement_hostescalationdefinition_definition;
00142         OCI_Statement* oci_statement_hostescalationdefinition_contactgroups;
00143         OCI_Statement* oci_statement_hostescalationdefinition_contacts;
00144         OCI_Statement* oci_statement_serviceescalationdefinition_definition;
00145         OCI_Statement* oci_statement_serviceescalationdefinition_contactgroups;
00146         OCI_Statement* oci_statement_serviceescalationdefinition_contacts;
00147         OCI_Statement* oci_statement_commanddefinition_definition;
00148         OCI_Statement* oci_statement_timeperiodefinition_definition;
00149         OCI_Statement* oci_statement_timeperiodefinition_timeranges;
00150         OCI_Statement* oci_statement_contactdefinition_definition;
00151         OCI_Statement* oci_statement_contactdefinition_addresses;
00152         OCI_Statement* oci_statement_contactdefinition_servicenotificationcommands;
00153         OCI_Statement* oci_statement_save_custom_variables_customvariables;
00154         OCI_Statement* oci_statement_save_custom_variables_customvariablestatus;
00155         OCI_Statement* oci_statement_contactgroupdefinition_definition;
00156         OCI_Statement* oci_statement_contactgroupdefinition_contactgroupmembers;
00157         OCI_Statement* oci_statement_process_events;
00158         OCI_Statement* oci_statement_flappinghistory;
00159         OCI_Statement* oci_statement_external_commands;
00160         OCI_Statement* oci_statement_acknowledgements;
00161         OCI_Statement* oci_statement_statehistory;
00162         OCI_Statement* oci_statement_instances;
00163         OCI_Statement* oci_statement_conninfo;
00164         /* well oh well */
00165         OCI_Statement* oci_statement_objects_select_name1_name2;
00166         OCI_Statement* oci_statement_objects_select_name1_null_name2;
00167         OCI_Statement* oci_statement_objects_select_name1_name2_null;
00168         OCI_Statement* oci_statement_objects_select_name1_null_name2_null;
00169         OCI_Statement* oci_statement_objects_select_cached;
00170         /* update */
00171         OCI_Statement* oci_statement_objects_update_inactive;
00172         OCI_Statement* oci_statement_objects_update_active;
00173         OCI_Statement* oci_statement_programstatus_update;
00174         OCI_Statement* oci_statement_timedevents_update;
00175         OCI_Statement* oci_statement_comment_history_update;
00176         OCI_Statement* oci_statement_downtimehistory_update_start;
00177         OCI_Statement* oci_statement_downtimehistory_update_stop;
00178         OCI_Statement* oci_statement_conninfo_update;
00179         OCI_Statement* oci_statement_conninfo_update_checkin;
00180         /* select */
00181         OCI_Statement* oci_statement_logentries_select;
00182         OCI_Statement* oci_statement_instances_select;
00183 
00184         /* delete */
00185         OCI_Statement* oci_statement_timedeventqueue_delete;
00186         OCI_Statement* oci_statement_timedeventqueue_delete_more;
00187         OCI_Statement* oci_statement_comments_delete;
00188         OCI_Statement* oci_statement_downtime_delete;
00189         OCI_Statement* oci_statement_instances_delete;
00190         OCI_Statement* oci_statement_instances_delete_time;
00191 
00192         /* dbversion */
00193         OCI_Statement* oci_statement_dbversion_select;
00194 
00195 #endif /* Oracle ocilib specific */
00196         unsigned long instance_id;
00197         unsigned long conninfo_id;
00198         time_t latest_program_status_time;
00199         time_t latest_host_status_time;
00200         time_t latest_service_status_time;
00201         time_t latest_contact_status_time;
00202         time_t latest_queued_event_time;
00203         time_t latest_realtime_data_time;
00204         time_t latest_comment_time;
00205         int clean_event_queue;
00206         unsigned long last_notification_id;
00207         unsigned long last_contact_notification_id;
00208         unsigned long max_timedevents_age;
00209         unsigned long max_systemcommands_age;
00210         unsigned long max_servicechecks_age;
00211         unsigned long max_hostchecks_age;
00212         unsigned long max_eventhandlers_age;
00213         unsigned long max_externalcommands_age;
00214         unsigned long max_logentries_age;
00215         unsigned long max_acknowledgements_age;
00216         unsigned long trim_db_interval;
00217         unsigned long housekeeping_thread_startup_delay;
00218         unsigned long clean_realtime_tables_on_core_startup;
00219         unsigned long clean_config_tables_on_core_startup;
00220         unsigned long oci_errors_to_syslog;
00221         time_t last_table_trim_time;
00222         time_t last_logentry_time;
00223         char *last_logentry_data;
00224         char *dbversion;
00225         ido2db_dbobject **object_hashlist;
00226         }ido2db_dbconninfo;
00227 
00228 
00229 typedef struct ido2db_input_data_info_struct{
00230         int protocol_version;
00231         int disconnect_client;
00232         int ignore_client_data;
00233         char *instance_name;
00234         char *agent_name;
00235         char *agent_version;
00236         char *disposition;
00237         char *connect_source;
00238         char *connect_type;
00239         int current_input_section;
00240         int current_input_data;
00241         unsigned long bytes_processed;
00242         unsigned long lines_processed;
00243         unsigned long entries_processed;
00244         unsigned long data_start_time;
00245         unsigned long data_end_time;
00246         int current_object_config_type;
00247         char **buffered_input;
00248         ido2db_mbuf mbuf[IDO2DB_MAX_MBUF_ITEMS];
00249         ido2db_dbconninfo dbinfo;
00250         }ido2db_idi;
00251 
00252 
00253 
00254 /*************** DB server types ***************/
00255 #define IDO2DB_DBSERVER_NONE                            0
00256 #define IDO2DB_DBSERVER_MYSQL                           1
00257 #define IDO2DB_DBSERVER_PGSQL                           2
00258 #define IDO2DB_DBSERVER_DB2                             3
00259 #define IDO2DB_DBSERVER_FIREBIRD                        4
00260 #define IDO2DB_DBSERVER_FREETDS                         5
00261 #define IDO2DB_DBSERVER_INGRES                          6
00262 #define IDO2DB_DBSERVER_MSQL                            7
00263 #define IDO2DB_DBSERVER_ORACLE                          8
00264 #define IDO2DB_DBSERVER_SQLITE                          9
00265 #define IDO2DB_DBSERVER_SQLITE3                         10
00266 
00267 /*************** DBI Driver names **************/
00268 #define IDO2DB_DBI_DRIVER_MYSQL                         "mysql"
00269 #define IDO2DB_DBI_DRIVER_PGSQL                         "pgsql"
00270 #define IDO2DB_DBI_DRIVER_DB2                           "db2l"
00271 #define IDO2DB_DBI_DRIVER_FIREBIRD                      "firebird"
00272 #define IDO2DB_DBI_DRIVER_FREETDS                       "freetds"
00273 #define IDO2DB_DBI_DRIVER_INGRES                        "ingres"
00274 #define IDO2DB_DBI_DRIVER_MSQL                          "msql"
00275 #define IDO2DB_DBI_DRIVER_ORACLE                        "Oracle"
00276 #define IDO2DB_DBI_DRIVER_SQLITE                        "sqlite"
00277 #define IDO2DB_DBI_DRIVER_SQLITE3                       "sqlite3"
00278 
00279 /*************** misc definitions **************/
00280 #define IDO2DB_INPUT_BUFFER                             1024
00281 /* #define IDO2DB_OBJECT_HASHSLOTS                         1024 */
00282 #define IDO2DB_OBJECT_HASHSLOTS                         50240   /* Altinity patch: Spread the list of linked lists thinner */
00283 
00284 
00285 /*********** types of input sections ***********/
00286 #define IDO2DB_INPUT_SECTION_NONE                       0
00287 #define IDO2DB_INPUT_SECTION_HEADER                     1
00288 #define IDO2DB_INPUT_SECTION_FOOTER                     2
00289 #define IDO2DB_INPUT_SECTION_DATA                       3
00290 
00291 
00292 /************* types of input data *************/
00293 #define IDO2DB_INPUT_DATA_NONE                          0
00294 
00295 #define IDO2DB_INPUT_DATA_CONFIGDUMPSTART               1
00296 #define IDO2DB_INPUT_DATA_CONFIGDUMPEND                 2
00297 
00298 #define IDO2DB_INPUT_DATA_LOGENTRY                      10
00299 
00300 #define IDO2DB_INPUT_DATA_PROCESSDATA                   20
00301 #define IDO2DB_INPUT_DATA_TIMEDEVENTDATA                21
00302 #define IDO2DB_INPUT_DATA_LOGDATA                       22
00303 #define IDO2DB_INPUT_DATA_SYSTEMCOMMANDDATA             23
00304 #define IDO2DB_INPUT_DATA_EVENTHANDLERDATA              24
00305 #define IDO2DB_INPUT_DATA_NOTIFICATIONDATA              25
00306 #define IDO2DB_INPUT_DATA_SERVICECHECKDATA              26
00307 #define IDO2DB_INPUT_DATA_HOSTCHECKDATA                 27
00308 #define IDO2DB_INPUT_DATA_COMMENTDATA                   28
00309 #define IDO2DB_INPUT_DATA_DOWNTIMEDATA                  29
00310 #define IDO2DB_INPUT_DATA_FLAPPINGDATA                  30
00311 #define IDO2DB_INPUT_DATA_PROGRAMSTATUSDATA             31
00312 #define IDO2DB_INPUT_DATA_HOSTSTATUSDATA                32
00313 #define IDO2DB_INPUT_DATA_SERVICESTATUSDATA             33
00314 #define IDO2DB_INPUT_DATA_ADAPTIVEPROGRAMDATA           34
00315 #define IDO2DB_INPUT_DATA_ADAPTIVEHOSTDATA              35
00316 #define IDO2DB_INPUT_DATA_ADAPTIVESERVICEDATA           36
00317 #define IDO2DB_INPUT_DATA_EXTERNALCOMMANDDATA           37
00318 #define IDO2DB_INPUT_DATA_AGGREGATEDSTATUSDATA          38
00319 #define IDO2DB_INPUT_DATA_RETENTIONDATA                 39
00320 #define IDO2DB_INPUT_DATA_CONTACTNOTIFICATIONDATA       40
00321 #define IDO2DB_INPUT_DATA_CONTACTNOTIFICATIONMETHODDATA 41
00322 #define IDO2DB_INPUT_DATA_ACKNOWLEDGEMENTDATA           42
00323 #define IDO2DB_INPUT_DATA_STATECHANGEDATA               43
00324 #define IDO2DB_INPUT_DATA_CONTACTSTATUSDATA             44
00325 #define IDO2DB_INPUT_DATA_ADAPTIVECONTACTDATA           45
00326 
00327 #define IDO2DB_INPUT_DATA_MAINCONFIGFILEVARIABLES       50
00328 #define IDO2DB_INPUT_DATA_RESOURCECONFIGFILEVARIABLES   51
00329 #define IDO2DB_INPUT_DATA_CONFIGVARIABLES               52
00330 #define IDO2DB_INPUT_DATA_RUNTIMEVARIABLES              53
00331 
00332 #define IDO2DB_INPUT_DATA_HOSTDEFINITION                61
00333 #define IDO2DB_INPUT_DATA_HOSTGROUPDEFINITION           62
00334 #define IDO2DB_INPUT_DATA_SERVICEDEFINITION             63
00335 #define IDO2DB_INPUT_DATA_SERVICEGROUPDEFINITION        64
00336 #define IDO2DB_INPUT_DATA_HOSTDEPENDENCYDEFINITION      65
00337 #define IDO2DB_INPUT_DATA_SERVICEDEPENDENCYDEFINITION   66
00338 #define IDO2DB_INPUT_DATA_HOSTESCALATIONDEFINITION      67
00339 #define IDO2DB_INPUT_DATA_SERVICEESCALATIONDEFINITION   68
00340 #define IDO2DB_INPUT_DATA_COMMANDDEFINITION             69
00341 #define IDO2DB_INPUT_DATA_TIMEPERIODDEFINITION          70
00342 #define IDO2DB_INPUT_DATA_CONTACTDEFINITION             71
00343 #define IDO2DB_INPUT_DATA_CONTACTGROUPDEFINITION        72
00344 #define IDO2DB_INPUT_DATA_HOSTEXTINFODEFINITION         73
00345 #define IDO2DB_INPUT_DATA_SERVICEEXTINFODEFINITION      74
00346 
00347 
00348 /************* types of config data ************/
00349 #define IDO2DB_CONFIGTYPE_ORIGINAL                      0
00350 #define IDO2DB_CONFIGTYPE_RETAINED                      1
00351 
00352 
00353 
00354 /************* debugging levels ****************/
00355 
00356 #define IDO2DB_DEBUGL_ALL                      -1
00357 #define IDO2DB_DEBUGL_NONE                     0
00358 #define IDO2DB_DEBUGL_PROCESSINFO              1
00359 #define IDO2DB_DEBUGL_SQL                      2
00360 
00361 #define IDO2DB_DEBUGV_BASIC                    0
00362 #define IDO2DB_DEBUGV_MORE                     1
00363 #define IDO2DB_DEBUGV_MOST                     2
00364 
00365 /************* default trim db interval ********/
00366 
00367 #define DEFAULT_TRIM_DB_INTERVAL 60
00368 
00369 /* default housekeeping thread startup delay  **/
00370 
00371 #define DEFAULT_HOUSEKEEPING_THREAD_STARTUP_DELAY 60
00372 
00373 /************* default trim db interval ********/
00374 
00375 #define DEFAULT_OCI_ERRORS_TO_SYSLOG            1
00376 
00377 /***************** functions *******************/
00378 
00379 /* config */
00380 int ido2db_process_arguments(int,char **);
00381 int ido2db_process_config_var(char *);
00382 int ido2db_process_config_file(char *);
00383 
00384 /* init */
00385 int ido2db_initialize_variables(void);
00386 int ido2db_check_init_reqs(void);
00387 
00388 /* daemonize */
00389 int ido2db_drop_privileges(char *,char *);
00390 int ido2db_daemonize(void);
00391 int ido2db_cleanup_socket(void);
00392 void ido2db_parent_sighandler(int);
00393 void ido2db_child_sighandler(int);
00394 
00395 /* cleanup */
00396 int ido2db_free_program_memory(void);
00397 int ido2db_free_input_memory(ido2db_idi *);
00398 int ido2db_free_connection_memory(ido2db_idi *);
00399 
00400 /* client connection */
00401 int ido2db_wait_for_connections(void);
00402 int ido2db_handle_client_connection(int);
00403 int ido2db_idi_init(ido2db_idi *);
00404 int ido2db_check_for_client_input(ido2db_idi *,ido_dbuf *, pthread_t *);
00405 int ido2db_handle_client_input(ido2db_idi *,char *, pthread_t *);
00406 
00407 /* data handling */
00408 int ido2db_start_input_data(ido2db_idi *);
00409 int ido2db_end_input_data(ido2db_idi *);
00410 int ido2db_add_input_data_item(ido2db_idi *,int,char *);
00411 int ido2db_add_input_data_mbuf(ido2db_idi *,int,int,char *);
00412 
00413 /* conversion */
00414 int ido2db_convert_standard_data_elements(ido2db_idi *,int *,int *,int *,struct timeval *);
00415 int ido2db_convert_string_to_int(char *,int *);
00416 int ido2db_convert_string_to_float(char *,float *);
00417 int ido2db_convert_string_to_double(char *,double *);
00418 int ido2db_convert_string_to_long(char *,long *);
00419 int ido2db_convert_string_to_unsignedlong(char *,unsigned long *);
00420 int ido2db_convert_string_to_timeval(char *,struct timeval *);
00421 
00422 /* logging */
00423 int ido2db_log_debug_info(int , int , const char *, ...);
00424 
00425 /* threads */
00426 void *ido2db_thread_cleanup(void *);
00427 int ido2db_kill_threads(void);
00428 
00429 #endif

Generated on Wed Mar 30 17:22:22 2011 for icinga-core by  doxygen 1.4.7