1 /**
2  * @file ndo2db.h Nagios Data Output to Database Daemon declarations
3  */
4 /*
5  * Copyright 2009-2014 Nagios Core Development Team and Community Contributors
6  * Copyright 2005-2009 Ethan Galstad
7  *
8  * This file is part of NDOUtils.
9  *
10  * NDOUtils is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  * NDOUtils is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with NDOUtils. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef NDO2DB_NDO2DB_H_INCLUDED
24 #define NDO2DB_NDO2DB_H_INCLUDED
25 
26 #include "config.h"
27 #include "utils.h"
28 
29 
30 /*************** mbuf definitions *************/
31 #define NDO2DB_MBUF_CONTACTGROUP                        0
32 #define NDO2DB_MBUF_CONTACTGROUPMEMBER                  1
33 #define NDO2DB_MBUF_SERVICEGROUPMEMBER                  2
34 #define NDO2DB_MBUF_HOSTGROUPMEMBER                     3
35 #define NDO2DB_MBUF_SERVICENOTIFICATIONCOMMAND          4
36 #define NDO2DB_MBUF_HOSTNOTIFICATIONCOMMAND             5
37 #define NDO2DB_MBUF_CONTACTADDRESS                      6
38 #define NDO2DB_MBUF_TIMERANGE                           7
39 #define NDO2DB_MBUF_PARENTHOST                          8
40 #define NDO2DB_MBUF_CONFIGFILEVARIABLE                  9
41 #define NDO2DB_MBUF_CONFIGVARIABLE                      10
42 #define NDO2DB_MBUF_RUNTIMEVARIABLE                     11
43 #define NDO2DB_MBUF_CUSTOMVARIABLE                      12
44 #define NDO2DB_MBUF_CONTACT                             13
45 #define NDO2DB_MBUF_PARENTSERVICE                       14
46 
47 #define NDO2DB_MAX_MBUF_ITEMS                           15
48 
49 
50 /***************** structures *****************/
51 
52 typedef struct ndo2db_mbuf_struct{
53 	int used_lines;
54 	int allocated_lines;
55 	char **buffer;
56         }ndo2db_mbuf;
57 
58 
59 typedef struct ndo2db_dbobject_struct{
60 	char *name1;
61 	char *name2;
62 	int object_type;
63 	unsigned long object_id;
64 	struct ndo2db_dbobject_struct *nexthash;
65         }ndo2db_dbobject;
66 
67 
68 typedef struct ndo2db_dbconninfo_struct{
69 	int server_type;
70 	int connected;
71 	int error;
72 #ifdef USE_MYSQL
73 	MYSQL mysql_conn;
74 	MYSQL_RES *mysql_result;
75 	MYSQL_ROW mysql_row;
76 #endif
77 	unsigned long instance_id;
78 	unsigned long conninfo_id;
79 	time_t latest_program_status_time;
80 	time_t latest_host_status_time;
81 	time_t latest_service_status_time;
82 	time_t latest_contact_status_time;
83 	time_t latest_queued_event_time;
84 	time_t latest_realtime_data_time;
85 	time_t latest_comment_time;
86 	int clean_event_queue;
87 	unsigned long last_notification_id;
88 	unsigned long last_contact_notification_id;
89 	unsigned long max_timedevents_age;
90 	unsigned long max_systemcommands_age;
91 	unsigned long max_servicechecks_age;
92 	unsigned long max_hostchecks_age;
93 	unsigned long max_eventhandlers_age;
94 	unsigned long max_externalcommands_age;
95 	unsigned long max_notifications_age;
96 	unsigned long max_contactnotifications_age;
97 	unsigned long max_contactnotificationmethods_age;
98 	unsigned long max_logentries_age;
99 	unsigned long max_acknowledgements_age;
100 	time_t last_table_trim_time;
101 	time_t last_logentry_time;
102 	char *last_logentry_data;
103 	ndo2db_dbobject **object_hashlist;
104         }ndo2db_dbconninfo;
105 
106 
107 typedef struct ndo2db_input_data_info_struct{
108 	int protocol_version;
109 	int disconnect_client;
110 	int ignore_client_data;
111 	char *instance_name;
112 	char *agent_name;
113 	char *agent_version;
114 	char *disposition;
115 	char *connect_source;
116 	char *connect_type;
117 	int current_input_section;
118 	int current_input_data;
119 	unsigned long bytes_processed;
120 	unsigned long lines_processed;
121 	unsigned long entries_processed;
122 	unsigned long data_start_time;
123 	unsigned long data_end_time;
124 	int current_object_config_type;
125 	char **buffered_input;
126 	ndo2db_mbuf mbuf[NDO2DB_MAX_MBUF_ITEMS];
127 	ndo2db_dbconninfo dbinfo;
128         }ndo2db_idi;
129 
130 
131 
132 /*************** DB server types ***************/
133 #define NDO2DB_DBSERVER_NONE                            0
134 #define NDO2DB_DBSERVER_MYSQL                           1
135 
136 
137 /*************** misc definitions **************/
138 #define NDO2DB_INPUT_BUFFER                             1024
139 #define NDO2DB_OBJECT_HASHSLOTS                         1024
140 
141 
142 /*********** types of input sections ***********/
143 #define NDO2DB_INPUT_SECTION_NONE                       0
144 #define NDO2DB_INPUT_SECTION_HEADER                     1
145 #define NDO2DB_INPUT_SECTION_FOOTER                     2
146 #define NDO2DB_INPUT_SECTION_DATA                       3
147 
148 
149 /************* types of input data *************/
150 #define NDO2DB_INPUT_DATA_NONE                          0
151 
152 #define NDO2DB_INPUT_DATA_CONFIGDUMPSTART               1
153 #define NDO2DB_INPUT_DATA_CONFIGDUMPEND                 2
154 
155 #define NDO2DB_INPUT_DATA_LOGENTRY                      10
156 
157 #define NDO2DB_INPUT_DATA_PROCESSDATA                   20
158 #define NDO2DB_INPUT_DATA_TIMEDEVENTDATA                21
159 #define NDO2DB_INPUT_DATA_LOGDATA                       22
160 #define NDO2DB_INPUT_DATA_SYSTEMCOMMANDDATA             23
161 #define NDO2DB_INPUT_DATA_EVENTHANDLERDATA              24
162 #define NDO2DB_INPUT_DATA_NOTIFICATIONDATA              25
163 #define NDO2DB_INPUT_DATA_SERVICECHECKDATA              26
164 #define NDO2DB_INPUT_DATA_HOSTCHECKDATA                 27
165 #define NDO2DB_INPUT_DATA_COMMENTDATA                   28
166 #define NDO2DB_INPUT_DATA_DOWNTIMEDATA                  29
167 #define NDO2DB_INPUT_DATA_FLAPPINGDATA                  30
168 #define NDO2DB_INPUT_DATA_PROGRAMSTATUSDATA             31
169 #define NDO2DB_INPUT_DATA_HOSTSTATUSDATA                32
170 #define NDO2DB_INPUT_DATA_SERVICESTATUSDATA             33
171 #define NDO2DB_INPUT_DATA_ADAPTIVEPROGRAMDATA           34
172 #define NDO2DB_INPUT_DATA_ADAPTIVEHOSTDATA              35
173 #define NDO2DB_INPUT_DATA_ADAPTIVESERVICEDATA           36
174 #define NDO2DB_INPUT_DATA_EXTERNALCOMMANDDATA           37
175 #define NDO2DB_INPUT_DATA_AGGREGATEDSTATUSDATA          38
176 #define NDO2DB_INPUT_DATA_RETENTIONDATA                 39
177 #define NDO2DB_INPUT_DATA_CONTACTNOTIFICATIONDATA       40
178 #define NDO2DB_INPUT_DATA_CONTACTNOTIFICATIONMETHODDATA 41
179 #define NDO2DB_INPUT_DATA_ACKNOWLEDGEMENTDATA           42
180 #define NDO2DB_INPUT_DATA_STATECHANGEDATA               43
181 #define NDO2DB_INPUT_DATA_CONTACTSTATUSDATA             44
182 #define NDO2DB_INPUT_DATA_ADAPTIVECONTACTDATA           45
183 
184 #define NDO2DB_INPUT_DATA_MAINCONFIGFILEVARIABLES       50
185 #define NDO2DB_INPUT_DATA_RESOURCECONFIGFILEVARIABLES   51
186 #define NDO2DB_INPUT_DATA_CONFIGVARIABLES               52
187 #define NDO2DB_INPUT_DATA_RUNTIMEVARIABLES              53
188 
189 #define NDO2DB_INPUT_DATA_HOSTDEFINITION                61
190 #define NDO2DB_INPUT_DATA_HOSTGROUPDEFINITION           62
191 #define NDO2DB_INPUT_DATA_SERVICEDEFINITION             63
192 #define NDO2DB_INPUT_DATA_SERVICEGROUPDEFINITION        64
193 #define NDO2DB_INPUT_DATA_HOSTDEPENDENCYDEFINITION      65
194 #define NDO2DB_INPUT_DATA_SERVICEDEPENDENCYDEFINITION   66
195 #define NDO2DB_INPUT_DATA_HOSTESCALATIONDEFINITION      67
196 #define NDO2DB_INPUT_DATA_SERVICEESCALATIONDEFINITION   68
197 #define NDO2DB_INPUT_DATA_COMMANDDEFINITION             69
198 #define NDO2DB_INPUT_DATA_TIMEPERIODDEFINITION          70
199 #define NDO2DB_INPUT_DATA_CONTACTDEFINITION             71
200 #define NDO2DB_INPUT_DATA_CONTACTGROUPDEFINITION        72
201 #define NDO2DB_INPUT_DATA_HOSTEXTINFODEFINITION         73
202 #define NDO2DB_INPUT_DATA_SERVICEEXTINFODEFINITION      74
203 #define NDO2DB_INPUT_DATA_ACTIVEOBJECTSLIST             75
204 
205 
206 /************* types of config data *************/
207 #define NDO2DB_CONFIGTYPE_ORIGINAL                      0
208 #define NDO2DB_CONFIGTYPE_RETAINED                      1
209 
210 
211 
212 /***************** debugging levels *******************/
213 
214 #define NDO2DB_DEBUGL_ALL                      -1
215 #define NDO2DB_DEBUGL_NONE                     0
216 #define NDO2DB_DEBUGL_PROCESSINFO              1
217 #define NDO2DB_DEBUGL_SQL                      2
218 
219 #define NDO2DB_DEBUGV_BASIC                    0
220 #define NDO2DB_DEBUGV_MORE		       1
221 #define NDO2DB_DEBUGV_MOST                     2
222 
223 
224 
225 
226 /***************** functions *******************/
227 
228 int ndo2db_process_arguments(int,char **);
229 
230 int ndo2db_process_config_var(char *);
231 int ndo2db_process_config_file(char *);
232 
233 int ndo2db_initialize_variables(void);
234 
235 int ndo2db_check_init_reqs(void);
236 
237 int ndo2db_drop_privileges(char *,char *);
238 int ndo2db_daemonize(void);
239 int ndo2db_cleanup_socket(void);
240 void ndo2db_parent_sighandler(int);
241 void ndo2db_child_sighandler(int);
242 
243 int ndo2db_free_program_memory(void);
244 int ndo2db_free_input_memory(ndo2db_idi *);
245 int ndo2db_free_connection_memory(ndo2db_idi *);
246 
247 int ndo2db_wait_for_connections(void);
248 int ndo2db_handle_client_connection(int);
249 int ndo2db_idi_init(ndo2db_idi *);
250 int ndo2db_check_for_client_input(ndo2db_idi *,ndo_dbuf *);
251 int ndo2db_handle_client_input(ndo2db_idi *,char *);
252 
253 int ndo2db_start_input_data(ndo2db_idi *);
254 int ndo2db_end_input_data(ndo2db_idi *);
255 int ndo2db_add_input_data_item(ndo2db_idi *,int,char *);
256 int ndo2db_add_input_data_mbuf(ndo2db_idi *,int,int,char *);
257 
258 int ndo2db_convert_standard_data_elements(ndo2db_idi *,int *,int *,int *,struct timeval *);
259 int ndo2db_convert_string_to_int(char *,int *);
260 int ndo2db_convert_string_to_float(char *,float *);
261 int ndo2db_convert_string_to_double(char *,double *);
262 int ndo2db_convert_string_to_long(char *,long *);
263 int ndo2db_convert_string_to_unsignedlong(char *,unsigned long *);
264 int ndo2db_convert_string_to_timeval(char *,struct timeval *);
265 
266 int ndo2db_open_debug_log(void);
267 int ndo2db_close_debug_log(void);
268 
269 void ndo2db_async_client_handle();
270 #endif
271