1 /**
2 * @file ndomod.c Nagios Data Output Event Broker Module
3 */
4 /*
5 * Copyright 2009-2014 Nagios Core Development Team and Community Contributors
6 * Copyright 2005-2009 Ethan Galstad
7 *
8 * Last Modified: 2017-04-13
9 *
10 * This file is part of NDOUtils.
11 *
12 * First Written: 05-19-2005
13 * Last Modified: 2017-04-13
14 *
15 *****************************************************************************
16 * NDOUtils is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
19 *
20 * NDOUtils is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with NDOUtils. If not, see <http://www.gnu.org/licenses/>.
27 */
28 /**
29 * @todo Add service parents
30 * @todo hourly value (hosts / services)
31 * @todo minimum value (contacts)
32 */
33
34 /* include our project's header files */
35 #include "../include/common.h"
36 #include "../include/io.h"
37 #include "../include/utils.h"
38 #include "../include/protoapi.h"
39 #include "../include/ndomod.h"
40
41 #include <pthread.h>
42
43 /* include (minimum required) event broker header files */
44 #ifdef BUILD_NAGIOS_2X
45 #include "../include/nagios-2x/nebstructs.h"
46 #include "../include/nagios-2x/nebmodules.h"
47 #include "../include/nagios-2x/nebcallbacks.h"
48 #include "../include/nagios-2x/broker.h"
49 #endif
50 #ifdef BUILD_NAGIOS_3X
51 #include "../include/nagios-3x/nebstructs.h"
52 #include "../include/nagios-3x/nebmodules.h"
53 #include "../include/nagios-3x/nebcallbacks.h"
54 #include "../include/nagios-3x/broker.h"
55 #endif
56 #ifdef BUILD_NAGIOS_4X
57 #include "../include/nagios-4x/nebstructs.h"
58 #include "../include/nagios-4x/nebmodules.h"
59 #include "../include/nagios-4x/nebcallbacks.h"
60 #include "../include/nagios-4x/broker.h"
61 #endif
62
63 /* include other Nagios header files for access to functions, data structs, etc. */
64 #ifdef BUILD_NAGIOS_2X
65 #include "../include/nagios-2x/common.h"
66 #include "../include/nagios-2x/nagios.h"
67 #include "../include/nagios-2x/downtime.h"
68 #include "../include/nagios-2x/comments.h"
69 #endif
70 #ifdef BUILD_NAGIOS_3X
71 #include "../include/nagios-3x/common.h"
72 #include "../include/nagios-3x/nagios.h"
73 #include "../include/nagios-3x/downtime.h"
74 #include "../include/nagios-3x/comments.h"
75 #include "../include/nagios-3x/macros.h"
76 #endif
77 #ifdef BUILD_NAGIOS_4X
78 #include "../include/nagios-4x/common.h"
79 #include "../include/nagios-4x/nagios.h"
80 #include "../include/nagios-4x/downtime.h"
81 #include "../include/nagios-4x/comments.h"
82 #include "../include/nagios-4x/macros.h"
83 #endif
84
85 /* specify event broker API version (required) */
86 NEB_API_VERSION(CURRENT_NEB_API_VERSION)
87
88
89 #define NDOMOD_VERSION "2.1.3"
90 #define NDOMOD_NAME "NDOMOD"
91 #define NDOMOD_DATE "2017-04-13"
92
93 #define BD_INT 0
94 #define BD_TIMEVAL 1
95 #define BD_STRING 2
96 #define BD_UNSIGNED_LONG 3
97 #define BD_FLOAT 4
98
99 struct ndo_broker_data {
100 int key;
101 int datatype;
102 union {
103 int integer;
104 struct timeval timestamp;
105 char *string;
106 unsigned long unsigned_long;
107 double floating_point;
108 } value;
109 };
110
111 void *ndomod_module_handle=NULL;
112 char *ndomod_instance_name=NULL;
113 char *ndomod_buffer_file=NULL;
114 char *ndomod_sink_name=NULL;
115 int ndomod_sink_type=NDO_SINK_UNIXSOCKET;
116 int ndomod_sink_tcp_port=NDO_DEFAULT_TCP_PORT;
117 int ndomod_sink_is_open=NDO_FALSE;
118 int ndomod_sink_previously_open=NDO_FALSE;
119 int ndomod_sink_fd=-1;
120 time_t ndomod_sink_last_reconnect_attempt=0L;
121 time_t ndomod_sink_last_reconnect_warning=0L;
122 unsigned long ndomod_sink_connect_attempt=0L;
123 unsigned long ndomod_sink_reconnect_interval=15;
124 unsigned long ndomod_sink_reconnect_warning_interval=900;
125 unsigned long ndomod_sink_rotation_interval=3600;
126 char *ndomod_sink_rotation_command=NULL;
127 int ndomod_sink_rotation_timeout=60;
128 int ndomod_allow_sink_activity=NDO_TRUE;
129 unsigned long ndomod_process_options=0;
130 int ndomod_config_output_options=NDOMOD_CONFIG_DUMP_ALL;
131 unsigned long ndomod_sink_buffer_slots=5000;
132 ndomod_sink_buffer sinkbuf;
133 int has_ver403_long_output = (CURRENT_OBJECT_STRUCTURE_VERSION >= 403);
134
135 extern int errno;
136
137 /**** NAGIOS VARIABLES ****/
138 extern command *command_list;
139 extern timeperiod *timeperiod_list;
140 extern contact *contact_list;
141 extern contactgroup *contactgroup_list;
142 extern host *host_list;
143 extern hostgroup *hostgroup_list;
144 extern service *service_list;
145 extern servicegroup *servicegroup_list;
146 extern hostescalation *hostescalation_list;
147 extern serviceescalation *serviceescalation_list;
148 extern hostdependency *hostdependency_list;
149 extern servicedependency *servicedependency_list;
150 #ifdef BUILD_NAGIOS_2X
151 extern hostextinfo *hostextinfo_list;
152 extern serviceextinfo *serviceextinfo_list;
153 #endif
154
155 extern char *config_file;
156 extern sched_info scheduling_info;
157 extern char *global_host_event_handler;
158 extern char *global_service_event_handler;
159
160 extern int __nagios_object_structure_version;
161
162 extern int use_ssl;
163
164 static inline void ndomod_free_esc_buffers(char **ary, int num);
165
166 #define DEBUG_NDO 1
167
168
169
170 /* this function gets called when the module is loaded by the event broker */
nebmodule_init(int flags,char * args,void * handle)171 int nebmodule_init(int flags, char *args, void *handle){
172 char temp_buffer[NDOMOD_MAX_BUFLEN];
173
174 /* save our handle */
175 ndomod_module_handle=handle;
176
177 /* log module info to the Nagios log file */
178 snprintf(temp_buffer,sizeof(temp_buffer)-1,"ndomod: %s %s (%s) Copyright (c) 2009 Nagios Core Development Team and Community Contributors",NDOMOD_NAME,NDOMOD_VERSION,NDOMOD_DATE);
179 temp_buffer[sizeof(temp_buffer)-1]='\x0';
180 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
181
182 /* check Nagios object structure version */
183 if(ndomod_check_nagios_object_version()==NDO_ERROR)
184 return -1;
185
186 /* process arguments */
187 if(ndomod_process_module_args(args)==NDO_ERROR){
188 ndomod_write_to_logs("ndomod: An error occurred while attempting to process module arguments.",NSLOG_INFO_MESSAGE);
189 return -1;
190 }
191
192 /* do some initialization stuff... */
193 if(ndomod_init()==NDO_ERROR){
194 ndomod_write_to_logs("ndomod: An error occurred while attempting to initialize.",NSLOG_INFO_MESSAGE);
195 return -1;
196 }
197
198 return 0;
199 }
200
201
202 /* Shutdown and release our resources when the module is unloaded. */
nebmodule_deinit(int flags,int reason)203 int nebmodule_deinit(int flags, int reason) {
204 char msg[] = "ndomod: Shutdown complete."; /* A message for the core log. */
205 ndomod_deinit();
206 ndomod_write_to_logs(msg, NSLOG_INFO_MESSAGE);
207 return 0;
208 }
209
210
211
212 /****************************************************************************/
213 /* INIT/DEINIT FUNCTIONS */
214 /****************************************************************************/
215
216 /* checks to make sure Nagios object version matches what we know about */
ndomod_check_nagios_object_version(void)217 int ndomod_check_nagios_object_version(void){
218 char temp_buffer[NDOMOD_MAX_BUFLEN];
219
220 if(__nagios_object_structure_version!=CURRENT_OBJECT_STRUCTURE_VERSION){
221 /* Temporary special case so newer ndomod can be used with slightly
222 * older nagios in order to get longoutput on state changes */
223 if (CURRENT_OBJECT_STRUCTURE_VERSION >= 403 && __nagios_object_structure_version == 402) {
224 has_ver403_long_output = 0;
225 return NDO_OK;
226 }
227 snprintf(temp_buffer,sizeof(temp_buffer)-1,"ndomod: I've been compiled with support for revision %d of the internal Nagios object structures, but the Nagios daemon is currently using revision %d. I'm going to unload so I don't cause any problems...\n",CURRENT_OBJECT_STRUCTURE_VERSION,__nagios_object_structure_version);
228 temp_buffer[sizeof(temp_buffer)-1]='\x0';
229 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
230
231 return NDO_ERROR;
232 }
233
234 return NDO_OK;
235 }
236
237
238 /* performs some initialization stuff */
ndomod_init(void)239 int ndomod_init(void){
240 char temp_buffer[NDOMOD_MAX_BUFLEN];
241 time_t current_time;
242
243 /* initialize some vars (needed for restarts of daemon - why, if the module gets reloaded ???) */
244 ndomod_sink_is_open=NDO_FALSE;
245 ndomod_sink_previously_open=NDO_FALSE;
246 ndomod_sink_fd=-1;
247 ndomod_sink_last_reconnect_attempt=0L;
248 ndomod_sink_last_reconnect_warning=0L;
249 ndomod_allow_sink_activity=NDO_TRUE;
250
251 /* initialize data sink buffer */
252 ndomod_sink_buffer_init(&sinkbuf,ndomod_sink_buffer_slots);
253
254 /* read unprocessed data from buffer file */
255 ndomod_load_unprocessed_data(ndomod_buffer_file);
256
257 /* open data sink and say hello */
258 /* 05/04/06 - modified to flush buffer items that may have been read in from file */
259 ndomod_write_to_sink("\n",NDO_FALSE,NDO_TRUE);
260
261 /* register callbacks */
262 if(ndomod_register_callbacks()==NDO_ERROR)
263 return NDO_ERROR;
264
265 if(ndomod_sink_type==NDO_SINK_FILE){
266
267 /* make sure we have a rotation command defined... */
268 if(ndomod_sink_rotation_command==NULL){
269
270 /* log an error message to the Nagios log file */
271 snprintf(temp_buffer,sizeof(temp_buffer)-1,"ndomod: Warning - No file rotation command defined.\n");
272 temp_buffer[sizeof(temp_buffer)-1]='\x0';
273 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
274 }
275
276 /* schedule a file rotation event */
277 else{
278 time(¤t_time);
279 #ifdef BUILD_NAGIOS_2X
280 schedule_new_event(EVENT_USER_FUNCTION,TRUE,current_time+ndomod_sink_rotation_interval,TRUE,ndomod_sink_rotation_interval,NULL,TRUE,(void *)ndomod_rotate_sink_file,NULL);
281 #else
282 schedule_new_event(EVENT_USER_FUNCTION,TRUE,current_time+ndomod_sink_rotation_interval,TRUE,ndomod_sink_rotation_interval,NULL,TRUE,(void *)ndomod_rotate_sink_file,NULL,0);
283 #endif
284 }
285
286 }
287
288 return NDO_OK;
289 }
290
291
292 /* Shutdown and release our resources when the module is unloaded. */
ndomod_deinit(void)293 int ndomod_deinit(void) {
294 ndomod_deregister_callbacks();
295
296 ndomod_save_unprocessed_data(ndomod_buffer_file);
297 ndomod_sink_buffer_deinit(&sinkbuf);
298 ndomod_goodbye_sink();
299 ndomod_close_sink();
300
301 ndomod_free_config_memory();
302
303 return NDO_OK;
304 }
305
306
307
308 /****************************************************************************/
309 /* CONFIG FUNCTIONS */
310 /****************************************************************************/
311
312 /* process arguments that were passed to the module at startup */
ndomod_process_module_args(char * args)313 int ndomod_process_module_args(char *args){
314 char *ptr=NULL;
315 char **arglist=NULL;
316 char **newarglist=NULL;
317 int argcount=0;
318 int memblocks=64;
319 int arg=0;
320
321 if(args==NULL)
322 return NDO_OK;
323
324
325 /* get all the var/val argument pairs */
326
327 /* allocate some memory */
328 if((arglist=(char **)malloc(memblocks*sizeof(char **)))==NULL)
329 return NDO_ERROR;
330
331 /* process all args */
332 ptr=strtok(args,",");
333 while(ptr){
334
335 /* save the argument */
336 arglist[argcount++]=strdup(ptr);
337
338 /* allocate more memory if needed */
339 if(!(argcount%memblocks)){
340 if((newarglist=(char **)realloc(arglist,(argcount+memblocks)*sizeof(char **)))==NULL){
341 for(arg=0;arg<argcount;arg++)
342 free(arglist[argcount]);
343 free(arglist);
344 return NDO_ERROR;
345 }
346 else
347 arglist=newarglist;
348 }
349
350 ptr=strtok(NULL,",");
351 }
352
353 /* terminate the arg list */
354 arglist[argcount]='\x0';
355
356
357 /* process each argument */
358 for(arg=0;arg<argcount;arg++){
359 if(ndomod_process_config_var(arglist[arg])==NDO_ERROR){
360 for(arg=0;arg<argcount;arg++)
361 free(arglist[arg]);
362 free(arglist);
363 return NDO_ERROR;
364 }
365 }
366
367 /* free allocated memory */
368 for(arg=0;arg<argcount;arg++)
369 free(arglist[arg]);
370 free(arglist);
371
372 return NDO_OK;
373 }
374
375
376 /* process all config vars in a file */
ndomod_process_config_file(char * filename)377 int ndomod_process_config_file(char *filename){
378 ndo_mmapfile *thefile=NULL;
379 char *buf=NULL;
380 int result=NDO_OK;
381
382 /* open the file */
383 if((thefile=ndo_mmap_fopen(filename))==NULL)
384 return NDO_ERROR;
385
386 /* process each line of the file */
387 while((buf=ndo_mmap_fgets(thefile))){
388
389 /* skip comments */
390 if(buf[0]=='#'){
391 free(buf);
392 continue;
393 }
394
395 /* skip blank lines */
396 if(!strcmp(buf,"")){
397 free(buf);
398 continue;
399 }
400
401 /* process the variable */
402 result=ndomod_process_config_var(buf);
403
404 /* free memory */
405 free(buf);
406
407 if(result!=NDO_OK)
408 break;
409 }
410
411 /* close the file */
412 ndo_mmap_fclose(thefile);
413
414 return result;
415 }
416
417
418 /* process a single module config variable */
ndomod_process_config_var(char * arg)419 int ndomod_process_config_var(char *arg){
420 char *var=NULL;
421 char *val=NULL;
422
423 /* split var/val */
424 var=strtok(arg,"=");
425 val=strtok(NULL,"\n");
426
427 /* skip incomplete var/val pairs */
428 if(var==NULL || val==NULL)
429 return NDO_OK;
430
431 /* strip var/val */
432 ndomod_strip(var);
433 ndomod_strip(val);
434
435 /* process the variable... */
436
437 if(!strcmp(var,"config_file"))
438 ndomod_process_config_file(val);
439
440 else if(!strcmp(var,"instance_name"))
441 ndomod_instance_name=strdup(val);
442
443 else if(!strcmp(var,"output"))
444 ndomod_sink_name=strdup(val);
445
446 else if(!strcmp(var,"output_type")){
447 if(!strcmp(val,"file"))
448 ndomod_sink_type=NDO_SINK_FILE;
449 else if(!strcmp(val,"tcpsocket"))
450 ndomod_sink_type=NDO_SINK_TCPSOCKET;
451 else
452 ndomod_sink_type=NDO_SINK_UNIXSOCKET;
453 }
454
455 else if(!strcmp(var,"tcp_port"))
456 ndomod_sink_tcp_port=atoi(val);
457
458 else if(!strcmp(var,"output_buffer_items"))
459 ndomod_sink_buffer_slots=strtoul(val,NULL,0);
460
461 else if(!strcmp(var,"reconnect_interval"))
462 ndomod_sink_reconnect_interval=strtoul(val,NULL,0);
463
464 else if(!strcmp(var,"reconnect_warning_interval"))
465 ndomod_sink_reconnect_warning_interval=strtoul(val,NULL,0);
466
467 else if(!strcmp(var,"file_rotation_interval"))
468 ndomod_sink_rotation_interval=strtoul(val,NULL,0);
469
470 else if(!strcmp(var,"file_rotation_command"))
471 ndomod_sink_rotation_command=strdup(val);
472
473 else if(!strcmp(var,"file_rotation_timeout"))
474 ndomod_sink_rotation_timeout=atoi(val);
475
476 /* add bitwise processing opts */
477 else if(!strcmp(var,"process_data") && atoi(val)==1)
478 ndomod_process_options |= NDOMOD_PROCESS_PROCESS_DATA;
479 else if(!strcmp(var,"timed_event_data") && atoi(val)==1)
480 ndomod_process_options |= NDOMOD_PROCESS_TIMED_EVENT_DATA;
481 else if(!strcmp(var,"log_data") && atoi(val)==1)
482 ndomod_process_options |= NDOMOD_PROCESS_LOG_DATA;
483 else if(!strcmp(var,"system_command_data") && atoi(val)==1)
484 ndomod_process_options |= NDOMOD_PROCESS_SYSTEM_COMMAND_DATA;
485 else if(!strcmp(var,"event_handler_data") && atoi(val)==1)
486 ndomod_process_options |= NDOMOD_PROCESS_EVENT_HANDLER_DATA;
487 else if(!strcmp(var,"notification_data") && atoi(val)==1)
488 ndomod_process_options |= NDOMOD_PROCESS_NOTIFICATION_DATA;
489 else if(!strcmp(var,"service_check_data") && atoi(val)==1)
490 ndomod_process_options |= NDOMOD_PROCESS_SERVICE_CHECK_DATA ;
491 else if(!strcmp(var,"host_check_data") && atoi(val)==1)
492 ndomod_process_options |= NDOMOD_PROCESS_HOST_CHECK_DATA;
493 else if(!strcmp(var,"comment_data") && atoi(val)==1)
494 ndomod_process_options |= NDOMOD_PROCESS_COMMENT_DATA;
495 else if(!strcmp(var,"downtime_data") && atoi(val)==1)
496 ndomod_process_options |= NDOMOD_PROCESS_DOWNTIME_DATA;
497 else if(!strcmp(var,"flapping_data") && atoi(val)==1)
498 ndomod_process_options |= NDOMOD_PROCESS_FLAPPING_DATA;
499 else if(!strcmp(var,"program_status_data") && atoi(val)==1)
500 ndomod_process_options |= NDOMOD_PROCESS_PROGRAM_STATUS_DATA;
501 else if(!strcmp(var,"host_status_data") && atoi(val)==1)
502 ndomod_process_options |= NDOMOD_PROCESS_HOST_STATUS_DATA;
503 else if(!strcmp(var,"service_status_data") && atoi(val)==1)
504 ndomod_process_options |= NDOMOD_PROCESS_SERVICE_STATUS_DATA;
505 else if(!strcmp(var,"adaptive_program_data") && atoi(val)==1)
506 ndomod_process_options |= NDOMOD_PROCESS_ADAPTIVE_PROGRAM_DATA;
507 else if(!strcmp(var,"adaptive_host_data") && atoi(val)==1)
508 ndomod_process_options |= NDOMOD_PROCESS_ADAPTIVE_HOST_DATA;
509 else if(!strcmp(var,"adaptive_service_data") && atoi(val)==1)
510 ndomod_process_options |= NDOMOD_PROCESS_ADAPTIVE_SERVICE_DATA;
511 else if(!strcmp(var,"external_command_data") && atoi(val)==1)
512 ndomod_process_options |= NDOMOD_PROCESS_EXTERNAL_COMMAND_DATA;
513 else if(!strcmp(var,"object_config_data") && atoi(val)==1)
514 ndomod_process_options |= NDOMOD_PROCESS_OBJECT_CONFIG_DATA;
515 else if(!strcmp(var,"main_config_data") && atoi(val)==1)
516 ndomod_process_options |= NDOMOD_PROCESS_MAIN_CONFIG_DATA;
517 else if(!strcmp(var,"aggregated_status_data") && atoi(val)==1)
518 ndomod_process_options |= NDOMOD_PROCESS_AGGREGATED_STATUS_DATA;
519 else if(!strcmp(var,"retention_data") && atoi(val)==1)
520 ndomod_process_options |= NDOMOD_PROCESS_RETENTION_DATA;
521 else if(!strcmp(var,"acknowledgement_data") && atoi(val)==1)
522 ndomod_process_options |= NDOMOD_PROCESS_ACKNOWLEDGEMENT_DATA;
523 else if(!strcmp(var,"statechange_data") && atoi(val)==1)
524 ndomod_process_options |= NDOMOD_PROCESS_STATECHANGE_DATA ;
525 else if(!strcmp(var,"state_change_data") && atoi(val)==1)
526 ndomod_process_options |= NDOMOD_PROCESS_STATECHANGE_DATA ;
527 else if(!strcmp(var,"contact_status_data") && atoi(val)==1)
528 ndomod_process_options |= NDOMOD_PROCESS_CONTACT_STATUS_DATA;
529 else if(!strcmp(var,"adaptive_contact_data") && atoi(val)==1)
530 ndomod_process_options |= NDOMOD_PROCESS_ADAPTIVE_CONTACT_DATA ;
531
532 /* data_processing_options will override individual values if set */
533 else if(!strcmp(var,"data_processing_options")){
534 if(!strcmp(val,"-1"))
535 ndomod_process_options=NDOMOD_PROCESS_EVERYTHING;
536 else
537 ndomod_process_options=strtoul(val,NULL,0);
538 }
539
540 else if(!strcmp(var,"config_output_options"))
541 ndomod_config_output_options=atoi(val);
542
543 else if(!strcmp(var,"buffer_file"))
544 ndomod_buffer_file=strdup(val);
545
546 else if(!strcmp(var,"use_ssl")){
547 if (strlen(val) == 1) {
548 if (isdigit((int)val[strlen(val)-1]) != NDO_FALSE)
549 use_ssl = atoi(val);
550 else
551 use_ssl = 0;
552 }
553 }
554
555 /* new processing options will be skipped if they're set to 0
556 else {
557 printf("Invalid ndomod config option: %s\n",var);
558 return NDO_ERROR;
559 } */
560
561 return NDO_OK;
562 }
563
564 /* Frees any memory allocated for config options. */
ndomod_free_config_memory(void)565 static void ndomod_free_config_memory(void) {
566 my_free(ndomod_instance_name);
567 my_free(ndomod_sink_name);
568 my_free(ndomod_sink_rotation_command);
569 my_free(ndomod_buffer_file);
570 }
571
572
573 /****************************************************************************/
574 /* UTILITY FUNCTIONS */
575 /****************************************************************************/
576
577 /* writes a string to Nagios logs */
ndomod_write_to_logs(char * buf,int flags)578 int ndomod_write_to_logs(char *buf, int flags){
579
580 if(buf==NULL)
581 return NDO_ERROR;
582
583 return write_to_all_logs(buf,flags);
584 }
585
586
587
588 /****************************************************************************/
589 /* DATA SINK FUNCTIONS */
590 /****************************************************************************/
591
592 /* (re)open data sink */
ndomod_open_sink(void)593 int ndomod_open_sink(void){
594 int flags=0;
595
596 /* sink is already open... */
597 if(ndomod_sink_is_open==NDO_TRUE)
598 return ndomod_sink_fd;
599
600 /* try and open sink */
601 if(ndomod_sink_type==NDO_SINK_FILE)
602 flags=O_WRONLY|O_CREAT|O_APPEND;
603 if(ndo_sink_open(ndomod_sink_name,0,ndomod_sink_type,ndomod_sink_tcp_port,flags,&ndomod_sink_fd)==NDO_ERROR)
604 return NDO_ERROR;
605
606 /* mark the sink as being open */
607 ndomod_sink_is_open=NDO_TRUE;
608
609 /* mark the sink as having once been open */
610 ndomod_sink_previously_open=NDO_TRUE;
611
612 return NDO_OK;
613 }
614
615
616 /* (re)open data sink */
ndomod_close_sink(void)617 int ndomod_close_sink(void){
618
619 /* sink is already closed... */
620 if(ndomod_sink_is_open==NDO_FALSE)
621 return NDO_OK;
622
623 /* flush sink */
624 ndo_sink_flush(ndomod_sink_fd);
625
626 /* close sink */
627 ndo_sink_close(ndomod_sink_fd);
628
629 /* mark the sink as being closed */
630 ndomod_sink_is_open=NDO_FALSE;
631
632 return NDO_OK;
633 }
634
635
636 /* say hello */
ndomod_hello_sink(int reconnect,int problem_disconnect)637 int ndomod_hello_sink(int reconnect, int problem_disconnect){
638 char temp_buffer[NDOMOD_MAX_BUFLEN];
639 char *connection_type=NULL;
640 char *connect_type=NULL;
641
642 /* get the connection type string */
643 if(ndomod_sink_type==NDO_SINK_FD || ndomod_sink_type==NDO_SINK_FILE)
644 connection_type=NDO_API_CONNECTION_FILE;
645 else if(ndomod_sink_type==NDO_SINK_TCPSOCKET)
646 connection_type=NDO_API_CONNECTION_TCPSOCKET;
647 else
648 connection_type=NDO_API_CONNECTION_UNIXSOCKET;
649
650 /* get the connect type string */
651 if(reconnect==TRUE && problem_disconnect==TRUE)
652 connect_type=NDO_API_CONNECTTYPE_RECONNECT;
653 else
654 connect_type=NDO_API_CONNECTTYPE_INITIAL;
655
656 snprintf(temp_buffer,sizeof(temp_buffer)-1
657 ,"\n\n%s\n%s: %d\n%s: %s\n%s: %s\n%s: %lu\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s\n\n"
658 ,NDO_API_HELLO
659 ,NDO_API_PROTOCOL
660 ,NDO_API_PROTOVERSION
661 ,NDO_API_AGENT
662 ,NDOMOD_NAME
663 ,NDO_API_AGENTVERSION
664 ,NDOMOD_VERSION
665 ,NDO_API_STARTTIME
666 ,(unsigned long)time(NULL)
667 ,NDO_API_DISPOSITION
668 ,NDO_API_DISPOSITION_REALTIME
669 ,NDO_API_CONNECTION
670 ,connection_type
671 ,NDO_API_CONNECTTYPE
672 ,connect_type
673 ,NDO_API_INSTANCENAME
674 ,(ndomod_instance_name==NULL)?"default":ndomod_instance_name
675 ,NDO_API_STARTDATADUMP
676 );
677
678 temp_buffer[sizeof(temp_buffer)-1]='\x0';
679
680 ndomod_write_to_sink(temp_buffer,NDO_FALSE,NDO_FALSE);
681
682 return NDO_OK;
683 }
684
685
686 /* say goodbye */
ndomod_goodbye_sink(void)687 int ndomod_goodbye_sink(void){
688 char temp_buffer[NDOMOD_MAX_BUFLEN];
689
690 snprintf(temp_buffer,sizeof(temp_buffer)-1
691 ,"\n%d\n%s: %lu\n%s\n\n"
692 ,NDO_API_ENDDATADUMP
693 ,NDO_API_ENDTIME
694 ,(unsigned long)time(NULL)
695 ,NDO_API_GOODBYE
696 );
697
698 temp_buffer[sizeof(temp_buffer)-1]='\x0';
699
700 ndomod_write_to_sink(temp_buffer,NDO_FALSE,NDO_TRUE);
701
702 return NDO_OK;
703 }
704
705
706 /* used to rotate data sink file on a regular basis */
ndomod_rotate_sink_file(void * args)707 int ndomod_rotate_sink_file(void *args){
708 #ifdef BUILD_NAGIOS_2X
709 char raw_command_line[MAX_COMMAND_BUFFER];
710 char processed_command_line[MAX_COMMAND_BUFFER];
711 #else
712 char *raw_command_line_3x=NULL;
713 char *processed_command_line_3x=NULL;
714 #endif
715 int early_timeout=FALSE;
716 double exectime;
717
718 /* close sink */
719 ndomod_goodbye_sink();
720 ndomod_close_sink();
721
722 /* we shouldn't write any data to the sink while we're rotating it... */
723 ndomod_allow_sink_activity=NDO_FALSE;
724
725
726 /****** ROTATE THE FILE *****/
727
728 /* get the raw command line */
729 #ifdef BUILD_NAGIOS_2X
730 get_raw_command_line(ndomod_sink_rotation_command,raw_command_line,sizeof(raw_command_line),STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS);
731 strip(raw_command_line);
732 #else
733 get_raw_command_line(find_command(ndomod_sink_rotation_command),ndomod_sink_rotation_command,&raw_command_line_3x,STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS);
734 strip(raw_command_line_3x);
735 #endif
736
737 /* process any macros in the raw command line */
738 #ifdef BUILD_NAGIOS_2X
739 process_macros(raw_command_line,processed_command_line,(int)sizeof(processed_command_line),STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS);
740 #else
741 process_macros(raw_command_line_3x,&processed_command_line_3x,STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS);
742 #endif
743
744 /* run the command */
745 #ifdef BUILD_NAGIOS_2X
746 my_system(processed_command_line,ndomod_sink_rotation_timeout,&early_timeout,&exectime,NULL,0);
747 #else
748 my_system(processed_command_line_3x,ndomod_sink_rotation_timeout,&early_timeout,&exectime,NULL,0);
749 #endif
750
751
752 /* allow data to be written to the sink */
753 ndomod_allow_sink_activity=NDO_TRUE;
754
755 /* re-open sink */
756 ndomod_open_sink();
757 ndomod_hello_sink(TRUE,FALSE);
758
759 return NDO_OK;
760 }
761
762
763 /* writes data to sink */
ndomod_write_to_sink(char * buf,int buffer_write,int flush_buffer)764 int ndomod_write_to_sink(char *buf, int buffer_write, int flush_buffer){
765 char *temp_buffer=NULL;
766 char *sbuf=NULL;
767 int buflen=0;
768 int result=NDO_OK;
769 time_t current_time;
770 int reconnect=NDO_FALSE;
771 unsigned long items_to_flush=0L;
772
773 /* we have nothing to write... */
774 if(buf==NULL)
775 return NDO_OK;
776
777 /* we shouldn't be messing with things... */
778 if(ndomod_allow_sink_activity==NDO_FALSE)
779 return NDO_ERROR;
780
781 /* open the sink if necessary... */
782 if(ndomod_sink_is_open==NDO_FALSE){
783
784 time(¤t_time);
785
786 /* are we reopening the sink? */
787 if(ndomod_sink_previously_open==NDO_TRUE)
788 reconnect=NDO_TRUE;
789
790 /* (re)connect to the sink if its time */
791 if((unsigned long)((unsigned long)current_time-ndomod_sink_reconnect_interval)>(unsigned long)ndomod_sink_last_reconnect_attempt){
792
793 result=ndomod_open_sink();
794
795 ndomod_sink_last_reconnect_attempt=current_time;
796
797 ndomod_sink_connect_attempt++;
798
799 /* sink was (re)opened... */
800 if(result==NDO_OK){
801
802 if(reconnect==NDO_TRUE){
803 asprintf(&temp_buffer,"ndomod: Successfully reconnected to data sink! %lu items lost, %lu queued items to flush.",sinkbuf.overflow,sinkbuf.items);
804 ndomod_hello_sink(TRUE,TRUE);
805 }
806 else{
807 if(sinkbuf.overflow==0L)
808 asprintf(&temp_buffer,"ndomod: Successfully connected to data sink. %lu queued items to flush.",sinkbuf.items);
809 else
810 asprintf(&temp_buffer,"ndomod: Successfully connected to data sink. %lu items lost, %lu queued items to flush.",sinkbuf.overflow,sinkbuf.items);
811 ndomod_hello_sink(FALSE,FALSE);
812 }
813
814 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
815 free(temp_buffer);
816 temp_buffer=NULL;
817
818 /* reset sink overflow */
819 sinkbuf.overflow=0L;
820 }
821
822 /* sink could not be (re)opened... */
823 else{
824
825 if((unsigned long)((unsigned long)current_time-ndomod_sink_reconnect_warning_interval)>(unsigned long)ndomod_sink_last_reconnect_warning){
826 if(reconnect==NDO_TRUE)
827 asprintf(&temp_buffer,"ndomod: Still unable to reconnect to data sink. %lu items lost, %lu queued items to flush.",sinkbuf.overflow,sinkbuf.items);
828 else if(ndomod_sink_connect_attempt==1)
829 asprintf(&temp_buffer,"ndomod: Could not open data sink! I'll keep trying, but some output may get lost...");
830 else
831 asprintf(&temp_buffer,"ndomod: Still unable to connect to data sink. %lu items lost, %lu queued items to flush.",sinkbuf.overflow,sinkbuf.items);
832 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
833 free(temp_buffer);
834 temp_buffer=NULL;
835
836 ndomod_sink_last_reconnect_warning=current_time;
837 }
838 }
839 }
840 }
841
842 /* we weren't able to (re)connect */
843 if(ndomod_sink_is_open==NDO_FALSE){
844
845 /***** BUFFER OUTPUT FOR LATER *****/
846
847 if(buffer_write==NDO_TRUE)
848 ndomod_sink_buffer_push(&sinkbuf,buf);
849
850 return NDO_ERROR;
851 }
852
853
854 /***** FLUSH BUFFERED DATA FIRST *****/
855
856 if(flush_buffer==NDO_TRUE && (items_to_flush=ndomod_sink_buffer_items(&sinkbuf))>0){
857
858 while(ndomod_sink_buffer_items(&sinkbuf)>0){
859
860 /* get next item from buffer */
861 sbuf=ndomod_sink_buffer_peek(&sinkbuf);
862
863 buflen=strlen(sbuf);
864 result=ndo_sink_write(ndomod_sink_fd,sbuf,buflen);
865
866 /* an error occurred... */
867 if(result<0){
868
869 /* sink problem! */
870 if(errno!=EAGAIN){
871
872 /* close the sink */
873 ndomod_close_sink();
874
875 asprintf(&temp_buffer,"ndomod: Error writing to data sink! Some output may get lost. %lu queued items to flush.",sinkbuf.items);
876 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
877 free(temp_buffer);
878 temp_buffer=NULL;
879
880 time(¤t_time);
881 ndomod_sink_last_reconnect_attempt=current_time;
882 ndomod_sink_last_reconnect_warning=current_time;
883 }
884
885 /***** BUFFER ORIGINAL OUTPUT FOR LATER *****/
886
887 if(buffer_write==NDO_TRUE)
888 ndomod_sink_buffer_push(&sinkbuf,buf);
889
890 return NDO_ERROR;
891 }
892
893 /* buffer was written okay, so remove it from buffer */
894 ndomod_sink_buffer_pop(&sinkbuf);
895 }
896
897 asprintf(&temp_buffer,"ndomod: Successfully flushed %lu queued items to data sink.",items_to_flush);
898 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
899 free(temp_buffer);
900 temp_buffer=NULL;
901 }
902
903
904 /***** WRITE ORIGINAL DATA *****/
905
906 /* write the data */
907 buflen=strlen(buf);
908 result=ndo_sink_write(ndomod_sink_fd,buf,buflen);
909
910 /* an error occurred... */
911 if(result<0){
912
913 /* sink problem! */
914 if(errno!=EAGAIN){
915
916 /* close the sink */
917 ndomod_close_sink();
918
919 time(¤t_time);
920 ndomod_sink_last_reconnect_attempt=current_time;
921 ndomod_sink_last_reconnect_warning=current_time;
922
923 asprintf(&temp_buffer,"ndomod: Error writing to data sink! Some output may get lost...");
924 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
925 free(temp_buffer);
926 asprintf(&temp_buffer,"ndomod: Please check remote ndo2db log, database connection or SSL Parameters");
927 ndomod_write_to_logs(temp_buffer,NSLOG_INFO_MESSAGE);
928 free(temp_buffer);
929
930 temp_buffer=NULL;
931 }
932
933 /***** BUFFER OUTPUT FOR LATER *****/
934
935 if(buffer_write==NDO_TRUE)
936 ndomod_sink_buffer_push(&sinkbuf,buf);
937
938 return NDO_ERROR;
939 }
940
941 return NDO_OK;
942 }
943
944
945
946 /* save unprocessed data to buffer file */
ndomod_save_unprocessed_data(char * f)947 int ndomod_save_unprocessed_data(char *f){
948 FILE *fp=NULL;
949 char *buf=NULL;
950 char *ebuf=NULL;
951
952 /* no file */
953 if(f==NULL)
954 return NDO_OK;
955
956 /* open the file for writing */
957 if((fp=fopen(f,"w"))==NULL)
958 return NDO_ERROR;
959
960 /* save all buffered items */
961 while(ndomod_sink_buffer_items(&sinkbuf)>0){
962
963 /* get next item from buffer */
964 buf=ndomod_sink_buffer_pop(&sinkbuf);
965
966 /* escape the string */
967 ebuf=ndo_escape_buffer(buf);
968
969 /* write string to file */
970 fputs(ebuf,fp);
971 fputs("\n",fp);
972
973 /* free memory */
974 free(buf);
975 buf=NULL;
976 free(ebuf);
977 ebuf=NULL;
978 }
979
980 fclose(fp);
981
982 return NDO_OK;
983 }
984
985
986
987 /* load unprocessed data from buffer file */
ndomod_load_unprocessed_data(char * f)988 int ndomod_load_unprocessed_data(char *f){
989 ndo_mmapfile *thefile=NULL;
990 char *ebuf=NULL;
991 char *buf=NULL;
992
993 /* open the file */
994 if((thefile=ndo_mmap_fopen(f))==NULL)
995 return NDO_ERROR;
996
997 /* process each line of the file */
998 while((ebuf=ndo_mmap_fgets(thefile))){
999
1000 /* unescape string */
1001 buf=ndo_unescape_buffer(ebuf);
1002
1003 /* save the data to the sink buffer */
1004 ndomod_sink_buffer_push(&sinkbuf,buf);
1005
1006 /* free memory */
1007 free(ebuf);
1008 }
1009
1010 /* close the file */
1011 ndo_mmap_fclose(thefile);
1012
1013 /* remove the file so we don't process it again in the future */
1014 unlink(f);
1015
1016 return NDO_OK;
1017 }
1018
1019
1020
1021 /* initializes sink buffer */
ndomod_sink_buffer_init(ndomod_sink_buffer * sbuf,unsigned long maxitems)1022 int ndomod_sink_buffer_init(ndomod_sink_buffer *sbuf,unsigned long maxitems){
1023 unsigned long x;
1024
1025 if(sbuf==NULL || maxitems<=0)
1026 return NDO_ERROR;
1027
1028 /* allocate memory for the buffer */
1029 if((sbuf->buffer=(char **)malloc(sizeof(char *)*maxitems))){
1030 for(x=0;x<maxitems;x++)
1031 sbuf->buffer[x]=NULL;
1032 }
1033
1034 sbuf->size=0L;
1035 sbuf->head=0L;
1036 sbuf->tail=0L;
1037 sbuf->items=0L;
1038 sbuf->maxitems=maxitems;
1039 sbuf->overflow=0L;
1040
1041 return NDO_OK;
1042 }
1043
1044
1045 /* deinitializes sink buffer */
ndomod_sink_buffer_deinit(ndomod_sink_buffer * sbuf)1046 int ndomod_sink_buffer_deinit(ndomod_sink_buffer *sbuf){
1047 unsigned long x;
1048
1049 if(sbuf==NULL)
1050 return NDO_ERROR;
1051
1052 /* free any allocated memory */
1053 for(x=0;x<sbuf->maxitems;x++)
1054 free(sbuf->buffer[x]);
1055
1056 free(sbuf->buffer);
1057 sbuf->buffer=NULL;
1058
1059 return NDO_OK;
1060 }
1061
1062
1063 /* buffers output */
ndomod_sink_buffer_push(ndomod_sink_buffer * sbuf,char * buf)1064 int ndomod_sink_buffer_push(ndomod_sink_buffer *sbuf,char *buf){
1065
1066 if(sbuf==NULL || buf==NULL)
1067 return NDO_ERROR;
1068
1069 /* no space to store buffer */
1070 if(sbuf->buffer==NULL || sbuf->items==sbuf->maxitems){
1071 sbuf->overflow++;
1072 return NDO_ERROR;
1073 }
1074
1075 /* store buffer */
1076 sbuf->buffer[sbuf->head]=strdup(buf);
1077 sbuf->head=(sbuf->head+1)%sbuf->maxitems;
1078 sbuf->items++;
1079
1080 return NDO_OK;
1081 }
1082
1083
1084 /* gets and removes next item from buffer */
ndomod_sink_buffer_pop(ndomod_sink_buffer * sbuf)1085 char *ndomod_sink_buffer_pop(ndomod_sink_buffer *sbuf){
1086 char *buf=NULL;
1087
1088 if(sbuf==NULL)
1089 return NULL;
1090
1091 if(sbuf->buffer==NULL)
1092 return NULL;
1093
1094 if(sbuf->items==0)
1095 return NULL;
1096
1097 /* remove item from buffer */
1098 buf=sbuf->buffer[sbuf->tail];
1099 sbuf->buffer[sbuf->tail]=NULL;
1100 sbuf->tail=(sbuf->tail+1)%sbuf->maxitems;
1101 sbuf->items--;
1102
1103 return buf;
1104 }
1105
1106
1107 /* gets next items from buffer */
ndomod_sink_buffer_peek(ndomod_sink_buffer * sbuf)1108 char *ndomod_sink_buffer_peek(ndomod_sink_buffer *sbuf){
1109 char *buf=NULL;
1110
1111 if(sbuf==NULL)
1112 return NULL;
1113
1114 if(sbuf->buffer==NULL)
1115 return NULL;
1116
1117 buf=sbuf->buffer[sbuf->tail];
1118
1119 return buf;
1120 }
1121
1122
1123 /* returns number of items buffered */
ndomod_sink_buffer_items(ndomod_sink_buffer * sbuf)1124 int ndomod_sink_buffer_items(ndomod_sink_buffer *sbuf){
1125
1126 if(sbuf==NULL)
1127 return 0;
1128 else
1129 return sbuf->items;
1130 }
1131
1132
1133 /* gets number of items lost due to buffer overflow */
ndomod_sink_buffer_get_overflow(ndomod_sink_buffer * sbuf)1134 unsigned long ndomod_sink_buffer_get_overflow(ndomod_sink_buffer *sbuf){
1135
1136 if(sbuf==NULL)
1137 return 0;
1138 else
1139 return sbuf->overflow;
1140 }
1141
1142
1143 /* sets number of items lost due to buffer overflow */
ndomod_sink_buffer_set_overflow(ndomod_sink_buffer * sbuf,unsigned long num)1144 int ndomod_sink_buffer_set_overflow(ndomod_sink_buffer *sbuf, unsigned long num){
1145
1146 if(sbuf==NULL)
1147 return 0;
1148 else
1149 sbuf->overflow=num;
1150
1151 return sbuf->overflow;
1152 }
1153
1154
1155 /****************************************************************************/
1156 /* CALLBACK FUNCTIONS */
1157 /****************************************************************************/
1158
1159 /* registers for callbacks */
ndomod_register_callbacks(void)1160 int ndomod_register_callbacks(void){
1161 int priority=0;
1162 int result=NDO_OK;
1163 char *msg=NULL;
1164
1165 //only register for events that we're going to process
1166 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_PROCESS_DATA)) {
1167 result=neb_register_callback(NEBCALLBACK_PROCESS_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1168 asprintf(&msg,"ndomod registered for process data\n");
1169 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1170 }
1171 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_TIMED_EVENT_DATA)) {
1172 result=neb_register_callback(NEBCALLBACK_TIMED_EVENT_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1173 asprintf(&msg,"ndomod registered for timed event data\n");
1174 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1175 }
1176 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_LOG_DATA)){
1177 result=neb_register_callback(NEBCALLBACK_LOG_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1178 asprintf(&msg,"ndomod registered for log data\'");
1179 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1180 }
1181 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_SYSTEM_COMMAND_DATA)) {
1182 result=neb_register_callback(NEBCALLBACK_SYSTEM_COMMAND_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1183 asprintf(&msg,"ndomod registered for system command data\'");
1184 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1185 }
1186 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_EVENT_HANDLER_DATA)) {
1187 result=neb_register_callback(NEBCALLBACK_EVENT_HANDLER_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1188 asprintf(&msg,"ndomod registered for event handler data\'");
1189 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1190 }
1191 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_NOTIFICATION_DATA)) {
1192 result=neb_register_callback(NEBCALLBACK_NOTIFICATION_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1193 asprintf(&msg,"ndomod registered for notification data\'");
1194 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1195 }
1196 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_SERVICE_CHECK_DATA)){
1197 result=neb_register_callback(NEBCALLBACK_SERVICE_CHECK_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1198 asprintf(&msg,"ndomod registered for service check data\'");
1199 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1200 }
1201 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_HOST_CHECK_DATA)) {
1202 result=neb_register_callback(NEBCALLBACK_HOST_CHECK_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1203 asprintf(&msg,"ndomod registered for host check data\'");
1204 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1205 }
1206 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_COMMENT_DATA)) {
1207 result=neb_register_callback(NEBCALLBACK_COMMENT_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1208 asprintf(&msg,"ndomod registered for comment data\'");
1209 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1210 }
1211 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_DOWNTIME_DATA)) {
1212 result=neb_register_callback(NEBCALLBACK_DOWNTIME_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1213 asprintf(&msg,"ndomod registered for downtime data\'");
1214 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1215 }
1216 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_FLAPPING_DATA)) {
1217 result=neb_register_callback(NEBCALLBACK_FLAPPING_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1218 asprintf(&msg,"ndomod registered for flapping data\'");
1219 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1220 }
1221 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_PROGRAM_STATUS_DATA)) {
1222 result=neb_register_callback(NEBCALLBACK_PROGRAM_STATUS_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1223 asprintf(&msg,"ndomod registered for program status data\'");
1224 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1225 }
1226 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_HOST_STATUS_DATA)) {
1227 result=neb_register_callback(NEBCALLBACK_HOST_STATUS_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1228 asprintf(&msg,"ndomod registered for host status data\'");
1229 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1230 }
1231 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_SERVICE_STATUS_DATA)) {
1232 result=neb_register_callback(NEBCALLBACK_SERVICE_STATUS_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1233 asprintf(&msg,"ndomod registered for service status data\'");
1234 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1235 }
1236 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_ADAPTIVE_PROGRAM_DATA)) {
1237 result=neb_register_callback(NEBCALLBACK_ADAPTIVE_PROGRAM_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1238 asprintf(&msg,"ndomod registered for adaptive program data\'");
1239 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1240 }
1241 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_ADAPTIVE_HOST_DATA)) {
1242 result=neb_register_callback(NEBCALLBACK_ADAPTIVE_HOST_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1243 asprintf(&msg,"ndomod registered for adaptive host data\'");
1244 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1245 }
1246 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_ADAPTIVE_SERVICE_DATA)) {
1247 result=neb_register_callback(NEBCALLBACK_ADAPTIVE_SERVICE_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1248 asprintf(&msg,"ndomod registered for adaptive service data\'");
1249 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1250 }
1251 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_EXTERNAL_COMMAND_DATA)) {
1252 result=neb_register_callback(NEBCALLBACK_EXTERNAL_COMMAND_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1253 asprintf(&msg,"ndomod registered for external command data\'");
1254 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1255 }
1256 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_AGGREGATED_STATUS_DATA)) {
1257 result=neb_register_callback(NEBCALLBACK_AGGREGATED_STATUS_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1258 asprintf(&msg,"ndomod registered for aggregated status data\'");
1259 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1260 }
1261 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_RETENTION_DATA)) {
1262 result=neb_register_callback(NEBCALLBACK_RETENTION_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1263 asprintf(&msg,"ndomod registered for retention data\'");
1264 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1265 }
1266 if(result==NDO_OK) { //no current option for this
1267 result=neb_register_callback(NEBCALLBACK_CONTACT_NOTIFICATION_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1268 asprintf(&msg,"ndomod registered for contact data\'");
1269 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1270 }
1271 if(result==NDO_OK) { //no current option for this
1272 result=neb_register_callback(NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1273 asprintf(&msg,"ndomod registered for contact notification data\'");
1274 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1275 }
1276 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_ACKNOWLEDGEMENT_DATA)) {
1277 result=neb_register_callback(NEBCALLBACK_ACKNOWLEDGEMENT_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1278 asprintf(&msg,"ndomod registered for acknowledgement data\'");
1279 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1280 }
1281 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_STATECHANGE_DATA)) {
1282 result=neb_register_callback(NEBCALLBACK_STATE_CHANGE_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1283 asprintf(&msg,"ndomod registered for state change data\'");
1284 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1285 }
1286 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
1287 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_CONTACT_STATUS_DATA)) {
1288 result=neb_register_callback(NEBCALLBACK_CONTACT_STATUS_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1289 asprintf(&msg,"ndomod registered for contact status data\'");
1290 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1291 }
1292 if(result==NDO_OK && (ndomod_process_options & NDOMOD_PROCESS_ADAPTIVE_CONTACT_DATA)) {
1293 result=neb_register_callback(NEBCALLBACK_ADAPTIVE_CONTACT_DATA,ndomod_module_handle,priority,ndomod_broker_data);
1294 asprintf(&msg,"ndomod registered for adaptive contact data\'");
1295 ndomod_write_to_logs(msg,NSLOG_INFO_MESSAGE);
1296 }
1297 #endif
1298
1299 free(msg);
1300
1301 return result;
1302 }
1303
1304
1305 /* deregisters callbacks */
ndomod_deregister_callbacks(void)1306 int ndomod_deregister_callbacks(void){
1307
1308 neb_deregister_callback(NEBCALLBACK_PROCESS_DATA,ndomod_broker_data);
1309 neb_deregister_callback(NEBCALLBACK_TIMED_EVENT_DATA,ndomod_broker_data);
1310 neb_deregister_callback(NEBCALLBACK_LOG_DATA,ndomod_broker_data);
1311 neb_deregister_callback(NEBCALLBACK_SYSTEM_COMMAND_DATA,ndomod_broker_data);
1312 neb_deregister_callback(NEBCALLBACK_EVENT_HANDLER_DATA,ndomod_broker_data);
1313 neb_deregister_callback(NEBCALLBACK_NOTIFICATION_DATA,ndomod_broker_data);
1314 neb_deregister_callback(NEBCALLBACK_SERVICE_CHECK_DATA,ndomod_broker_data);
1315 neb_deregister_callback(NEBCALLBACK_HOST_CHECK_DATA,ndomod_broker_data);
1316 neb_deregister_callback(NEBCALLBACK_COMMENT_DATA,ndomod_broker_data);
1317 neb_deregister_callback(NEBCALLBACK_DOWNTIME_DATA,ndomod_broker_data);
1318 neb_deregister_callback(NEBCALLBACK_FLAPPING_DATA,ndomod_broker_data);
1319 neb_deregister_callback(NEBCALLBACK_PROGRAM_STATUS_DATA,ndomod_broker_data);
1320 neb_deregister_callback(NEBCALLBACK_HOST_STATUS_DATA,ndomod_broker_data);
1321 neb_deregister_callback(NEBCALLBACK_SERVICE_STATUS_DATA,ndomod_broker_data);
1322 neb_deregister_callback(NEBCALLBACK_ADAPTIVE_PROGRAM_DATA,ndomod_broker_data);
1323 neb_deregister_callback(NEBCALLBACK_ADAPTIVE_HOST_DATA,ndomod_broker_data);
1324 neb_deregister_callback(NEBCALLBACK_ADAPTIVE_SERVICE_DATA,ndomod_broker_data);
1325 neb_deregister_callback(NEBCALLBACK_EXTERNAL_COMMAND_DATA,ndomod_broker_data);
1326 neb_deregister_callback(NEBCALLBACK_AGGREGATED_STATUS_DATA,ndomod_broker_data);
1327 neb_deregister_callback(NEBCALLBACK_RETENTION_DATA,ndomod_broker_data);
1328 neb_deregister_callback(NEBCALLBACK_CONTACT_NOTIFICATION_DATA,ndomod_broker_data);
1329 neb_deregister_callback(NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA,ndomod_broker_data);
1330 neb_deregister_callback(NEBCALLBACK_ACKNOWLEDGEMENT_DATA,ndomod_broker_data);
1331 neb_deregister_callback(NEBCALLBACK_STATE_CHANGE_DATA,ndomod_broker_data);
1332 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
1333 neb_deregister_callback(NEBCALLBACK_CONTACT_STATUS_DATA,ndomod_broker_data);
1334 neb_deregister_callback(NEBCALLBACK_ADAPTIVE_CONTACT_DATA,ndomod_broker_data);
1335 #endif
1336
1337 return NDO_OK;
1338 }
1339
ndomod_enddata_serialize(ndo_dbuf * dbufp)1340 static void ndomod_enddata_serialize(ndo_dbuf *dbufp) {
1341
1342 char temp[64];
1343
1344 snprintf(temp, sizeof(temp)-1, "\n%d\n\n", NDO_API_ENDDATA);
1345 temp[sizeof(temp)-1] = '\x0';
1346 ndo_dbuf_strcat(dbufp, temp);
1347 }
1348
ndomod_broker_data_serialize(ndo_dbuf * dbufp,int datatype,struct ndo_broker_data * bd,size_t bdsize,int add_enddata)1349 static void ndomod_broker_data_serialize(ndo_dbuf *dbufp, int datatype,
1350 struct ndo_broker_data *bd, size_t bdsize, int add_enddata) {
1351
1352 size_t bufused = 0;
1353 char temp[64];
1354 int x;
1355 struct ndo_broker_data *bdp;
1356
1357 /* Start everything out with the broker data type */
1358 snprintf(temp, sizeof(temp)-1, "\n%d:", datatype);
1359 temp[sizeof(temp)-1]='\x0';
1360 ndo_dbuf_strcat(dbufp, temp);
1361
1362 /* Add each value */
1363 for(x = 0, bdp = bd; x < bdsize; x++, bdp++) {
1364 switch(bdp->datatype) {
1365 case BD_INT:
1366 snprintf(temp, sizeof(temp)-1, "\n%d=%d", bdp->key,
1367 bdp->value.integer);
1368 temp[sizeof(temp)-1]='\x0';
1369 ndo_dbuf_strcat(dbufp, temp);
1370 break;
1371 case BD_TIMEVAL:
1372 snprintf(temp, sizeof(temp)-1, "\n%d=%ld.%06ld", bdp->key,
1373 bdp->value.timestamp.tv_sec, bdp->value.timestamp.tv_usec);
1374 temp[sizeof(temp)-1]='\x0';
1375 ndo_dbuf_strcat(dbufp, temp);
1376 break;
1377 case BD_STRING:
1378 snprintf(temp, sizeof(temp)-1, "\n%d=", bdp->key);
1379 temp[sizeof(temp)-1]='\x0';
1380 ndo_dbuf_strcat(dbufp, temp);
1381 ndo_dbuf_strcat(dbufp, bdp->value.string);
1382 break;
1383 case BD_UNSIGNED_LONG:
1384 snprintf(temp, sizeof(temp)-1, "\n%d=%lu", bdp->key,
1385 bdp->value.unsigned_long);
1386 temp[sizeof(temp)-1]='\x0';
1387 ndo_dbuf_strcat(dbufp, temp);
1388 break;
1389 case BD_FLOAT:
1390 snprintf(temp, sizeof(temp)-1, "\n%d=%.5lf", bdp->key,
1391 bdp->value.floating_point);
1392 temp[sizeof(temp)-1]='\x0';
1393 ndo_dbuf_strcat(dbufp, temp);
1394 break;
1395 }
1396 }
1397
1398 /* Close everything out with an NDO_API_ENDDATA marker */
1399 if(FALSE != add_enddata) {
1400 ndomod_enddata_serialize(dbufp);
1401 }
1402
1403 }
1404
1405 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
ndomod_customvars_serialize(customvariablesmember * customvars,ndo_dbuf * dbufp)1406 static void ndomod_customvars_serialize(customvariablesmember *customvars,
1407 ndo_dbuf *dbufp) {
1408
1409 customvariablesmember *temp_customvar = NULL;
1410 char * cvname;
1411 char * cvvalue;
1412 char temp_buffer[NDOMOD_MAX_BUFLEN];
1413
1414 for(temp_customvar = customvars; temp_customvar != NULL;
1415 temp_customvar = temp_customvar->next) {
1416
1417 cvname = ndo_escape_buffer(temp_customvar->variable_name);
1418 cvvalue = ndo_escape_buffer(temp_customvar->variable_value);
1419
1420 snprintf(temp_buffer, sizeof(temp_buffer)-1, "\n%d=%s:%d:%s",
1421 NDO_DATA_CUSTOMVARIABLE, (NULL == cvname) ? "" : cvname,
1422 temp_customvar->has_been_modified,
1423 (NULL == cvvalue ) ? "" : cvvalue);
1424
1425 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1426 ndo_dbuf_strcat(dbufp, temp_buffer);
1427
1428 if(NULL != cvname) free(cvname);
1429 if(NULL != cvvalue) free(cvvalue);
1430 }
1431 }
1432 #endif
1433
ndomod_contactgroups_serialize(contactgroupsmember * contactgroups,ndo_dbuf * dbufp)1434 static void ndomod_contactgroups_serialize(contactgroupsmember *contactgroups,
1435 ndo_dbuf *dbufp) {
1436
1437 contactgroupsmember *temp_contactgroupsmember = NULL;
1438 char *groupname;
1439 char temp_buffer[NDOMOD_MAX_BUFLEN];
1440
1441 for(temp_contactgroupsmember = contactgroups;
1442 temp_contactgroupsmember != NULL;
1443 temp_contactgroupsmember = temp_contactgroupsmember->next) {
1444
1445 groupname = ndo_escape_buffer(temp_contactgroupsmember->group_name);
1446
1447 snprintf(temp_buffer, sizeof(temp_buffer)-1,"\n%d=%s",
1448 NDO_DATA_CONTACTGROUP ,(NULL == groupname) ? "" : groupname);
1449 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1450 ndo_dbuf_strcat(dbufp, temp_buffer);
1451
1452 if(NULL != groupname) free(groupname);
1453 }
1454 }
1455
1456 #ifdef BUILD_NAGIOS_2X
ndomod_contacts_serialize(contactgroupmember * contacts,ndo_dbuf * dbufp,int varnum)1457 static void ndomod_contacts_serialize(contactgroupmember *contacts,
1458 ndo_dbuf *dbufp, int varnum) {
1459
1460 contactgroupmember *temp_contactgroupmember = NULL;
1461 char *contact_name;
1462 char temp_buffer[NDOMOD_MAX_BUFLEN];
1463
1464 for(temp_contactgroupmember = contacts; temp_contactgroupmember != NULL;
1465 temp_contactgroupmember=temp_contactgroupmember->next) {
1466
1467 contact_name = ndo_escape_buffer(temp_contactgroupmember->contact_name);
1468
1469 snprintf(temp_buffer, sizeof(temp_buffer)-1, "\n%d=%s", varnum,
1470 (NULL == contact_name) ? "" : contact_name);
1471 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1472 ndo_dbuf_strcat(dbufp, temp_buffer);
1473
1474 if(NULL != contact_name) free(contact_name);
1475 }
1476 }
1477
1478 #else
ndomod_contacts_serialize(contactsmember * contacts,ndo_dbuf * dbufp,int varnum)1479 static void ndomod_contacts_serialize(contactsmember *contacts,
1480 ndo_dbuf *dbufp, int varnum) {
1481
1482 contactsmember *temp_contactsmember = NULL;
1483 char *contact_name;
1484 char temp_buffer[NDOMOD_MAX_BUFLEN];
1485
1486 for(temp_contactsmember = contacts; temp_contactsmember != NULL;
1487 temp_contactsmember = temp_contactsmember->next) {
1488
1489 contact_name = ndo_escape_buffer(temp_contactsmember->contact_name);
1490
1491 snprintf(temp_buffer, sizeof(temp_buffer)-1, "\n%d=%s", varnum,
1492 (NULL == contact_name) ? "" : contact_name);
1493 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1494 ndo_dbuf_strcat(dbufp, temp_buffer);
1495
1496 if(NULL != contact_name) free(contact_name);
1497 }
1498 }
1499 #endif
1500
1501 #ifdef BUILD_NAGIOS_2X
ndomod_hosts_serialize_2x(hostgroupmember * hosts,ndo_dbuf * dbufp,int varnum)1502 static void ndomod_hosts_serialize_2x(hostgroupmember *hosts, ndo_dbuf *dbufp,
1503 int varnum) {
1504
1505 hostgroupmember *temp_hostgroupmember=NULL;
1506 char *host_name;
1507 char temp_buffer[NDOMOD_MAX_BUFLEN];
1508
1509 for(temp_hostgroupmember = hosts; temp_hostgroupmember != NULL;
1510 temp_hostgroupmember = temp_hostgroupmember->next) {
1511
1512 host_name = ndo_escape_buffer(temp_hostgroupmember->host_name);
1513
1514 snprintf(temp_buffer, sizeof(temp_buffer)-1, "\n%d=%s", varnum,
1515 (NULL == host_name) ? "" : host_name);
1516 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1517 ndo_dbuf_strcat(dbufp, temp_buffer);
1518
1519 if(NULL != host_name) free(host_name);
1520 }
1521 }
1522 #endif
1523
ndomod_hosts_serialize(hostsmember * hosts,ndo_dbuf * dbufp,int varnum)1524 static void ndomod_hosts_serialize(hostsmember *hosts, ndo_dbuf *dbufp,
1525 int varnum) {
1526
1527 hostsmember *temp_hostsmember = NULL;
1528 char *host_name;
1529 char temp_buffer[NDOMOD_MAX_BUFLEN];
1530
1531 for(temp_hostsmember = hosts; temp_hostsmember != NULL;
1532 temp_hostsmember = temp_hostsmember->next) {
1533
1534 host_name = ndo_escape_buffer(temp_hostsmember->host_name);
1535
1536 snprintf(temp_buffer, sizeof(temp_buffer)-1, "\n%d=%s", varnum,
1537 (NULL == host_name) ? "" : host_name);
1538 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1539 ndo_dbuf_strcat(dbufp, temp_buffer);
1540
1541 if(NULL != host_name) free(host_name);
1542 }
1543 }
1544
1545 #ifdef BUILD_NAGIOS_2X
ndomod_services_serialize(servicegroupmember * services,ndo_dbuf * dbufp,int varnum)1546 static void ndomod_services_serialize(servicegroupmember *services,
1547 ndo_dbuf *dbufp, int varnum) {
1548
1549 servicegroupmember *temp_servicegroupmember = NULL;
1550 char *host_name;
1551 char *service_description;
1552 char temp_buffer[NDOMOD_MAX_BUFLEN];
1553
1554 for(temp_servicegroupmember = services; temp_servicegroupmember != NULL;
1555 temp_servicegroupmember = temp_servicegroupmember->next) {
1556
1557 host_name = ndo_escape_buffer(temp_servicegroupmember->host_name);
1558 service_description = ndo_escape_buffer(temp_servicegroupmember->service_description);
1559
1560 snprintf(temp_buffer, sizeof(temp_buffer)-1, "\n%d=%s;%s", varnum,
1561 (NULL == host_name) ? "" : host_name,
1562 (NULL == service_description) ? "" : service_description);
1563 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1564 ndo_dbuf_strcat(dbufp, temp_buffer);
1565
1566 if(NULL != host_name) free(host_name);
1567 if(NULL != service_description) free(service_description);
1568 }
1569 }
1570 #else
ndomod_services_serialize(servicesmember * services,ndo_dbuf * dbufp,int varnum)1571 static void ndomod_services_serialize(servicesmember *services, ndo_dbuf *dbufp,
1572 int varnum) {
1573
1574 servicesmember *temp_servicesmember = NULL;
1575 char *host_name;
1576 char *service_description;
1577 char temp_buffer[NDOMOD_MAX_BUFLEN];
1578
1579 for(temp_servicesmember = services; temp_servicesmember != NULL;
1580 temp_servicesmember=temp_servicesmember->next) {
1581
1582 host_name = ndo_escape_buffer(temp_servicesmember->host_name);
1583 service_description = ndo_escape_buffer(temp_servicesmember->service_description);
1584
1585 snprintf(temp_buffer, sizeof(temp_buffer)-1, "\n%d=%s;%s", varnum,
1586 (NULL == host_name) ? "" : host_name,
1587 (NULL == service_description) ? "" : service_description);
1588 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1589 ndo_dbuf_strcat(dbufp, temp_buffer);
1590
1591 if(NULL != host_name) free(host_name);
1592 if(NULL != service_description) free(service_description);
1593 }
1594 }
1595 #endif
1596
ndomod_commands_serialize(commandsmember * commands,ndo_dbuf * dbufp,int varnum)1597 static void ndomod_commands_serialize(commandsmember *commands, ndo_dbuf *dbufp,
1598 int varnum) {
1599
1600 commandsmember *temp_commandsmember = NULL;
1601 char *command;
1602 char temp_buffer[NDOMOD_MAX_BUFLEN];
1603
1604 for(temp_commandsmember = commands; temp_commandsmember != NULL;
1605 temp_commandsmember=temp_commandsmember->next){
1606
1607 command = ndo_escape_buffer(temp_commandsmember->command);
1608
1609 snprintf(temp_buffer, sizeof(temp_buffer)-1, "\n%d=%s", varnum,
1610 (command == NULL) ? "" : command);
1611 temp_buffer[sizeof(temp_buffer)-1] = '\x0';
1612 ndo_dbuf_strcat(dbufp, temp_buffer);
1613
1614 if(NULL != command) free(command);
1615 }
1616 }
1617
1618 /* handles brokered event data */
ndomod_broker_data(int event_type,void * data)1619 int ndomod_broker_data(int event_type, void *data){
1620 char temp_buffer[NDOMOD_MAX_BUFLEN];
1621 size_t tbsize = sizeof(temp_buffer);
1622 ndo_dbuf dbuf;
1623 int write_to_sink=NDO_TRUE;
1624 host *temp_host=NULL;
1625 service *temp_service=NULL;
1626 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
1627 contact *temp_contact=NULL;
1628 #endif
1629 char *es[9];
1630 int x=0;
1631 scheduled_downtime *temp_downtime=NULL;
1632 #if ( defined( BUILD_NAGIOS_2X) || defined( BUILD_NAGIOS_3X))
1633 comment *temp_comment=NULL;
1634 #else
1635 nagios_comment *temp_comment=NULL;
1636 #endif
1637 nebstruct_process_data *procdata=NULL;
1638 nebstruct_timed_event_data *eventdata=NULL;
1639 nebstruct_log_data *logdata=NULL;
1640 nebstruct_system_command_data *cmddata=NULL;
1641 nebstruct_event_handler_data *ehanddata=NULL;
1642 nebstruct_notification_data *notdata=NULL;
1643 nebstruct_service_check_data *scdata=NULL;
1644 nebstruct_host_check_data *hcdata=NULL;
1645 nebstruct_comment_data *comdata=NULL;
1646 nebstruct_downtime_data *downdata=NULL;
1647 nebstruct_flapping_data *flapdata=NULL;
1648 nebstruct_program_status_data *psdata=NULL;
1649 nebstruct_host_status_data *hsdata=NULL;
1650 nebstruct_service_status_data *ssdata=NULL;
1651 nebstruct_adaptive_program_data *apdata=NULL;
1652 nebstruct_adaptive_host_data *ahdata=NULL;
1653 nebstruct_adaptive_service_data *asdata=NULL;
1654 nebstruct_external_command_data *ecdata=NULL;
1655 nebstruct_aggregated_status_data *agsdata=NULL;
1656 nebstruct_retention_data *rdata=NULL;
1657 nebstruct_contact_notification_data *cnotdata=NULL;
1658 nebstruct_contact_notification_method_data *cnotmdata=NULL;
1659 nebstruct_acknowledgement_data *ackdata=NULL;
1660 nebstruct_statechange_data *schangedata=NULL;
1661 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
1662 nebstruct_contact_status_data *csdata=NULL;
1663 nebstruct_adaptive_contact_data *acdata=NULL;
1664 #endif
1665 double retry_interval=0.0;
1666 int last_state=-1;
1667 int last_hard_state=-1;
1668 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
1669 customvariablesmember *temp_customvar=NULL;
1670 #endif
1671
1672 if(data==NULL)
1673 return 0;
1674
1675 /* should we handle this type of data? */
1676 switch(event_type){
1677
1678 case NEBCALLBACK_PROCESS_DATA:
1679 if(!(ndomod_process_options & NDOMOD_PROCESS_PROCESS_DATA))
1680 return 0;
1681 break;
1682 case NEBCALLBACK_TIMED_EVENT_DATA:
1683 if(!(ndomod_process_options & NDOMOD_PROCESS_TIMED_EVENT_DATA))
1684 return 0;
1685 break;
1686 case NEBCALLBACK_LOG_DATA:
1687 if(!(ndomod_process_options & NDOMOD_PROCESS_LOG_DATA))
1688 return 0;
1689 break;
1690 case NEBCALLBACK_SYSTEM_COMMAND_DATA:
1691 if(!(ndomod_process_options & NDOMOD_PROCESS_SYSTEM_COMMAND_DATA))
1692 return 0;
1693 break;
1694 case NEBCALLBACK_EVENT_HANDLER_DATA:
1695 if(!(ndomod_process_options & NDOMOD_PROCESS_EVENT_HANDLER_DATA))
1696 return 0;
1697 break;
1698 case NEBCALLBACK_NOTIFICATION_DATA:
1699 if(!(ndomod_process_options & NDOMOD_PROCESS_NOTIFICATION_DATA))
1700 return 0;
1701 break;
1702 case NEBCALLBACK_SERVICE_CHECK_DATA:
1703 if(!(ndomod_process_options & NDOMOD_PROCESS_SERVICE_CHECK_DATA))
1704 return 0;
1705 break;
1706 case NEBCALLBACK_HOST_CHECK_DATA:
1707 if(!(ndomod_process_options & NDOMOD_PROCESS_HOST_CHECK_DATA))
1708 return 0;
1709 break;
1710 case NEBCALLBACK_COMMENT_DATA:
1711 if(!(ndomod_process_options & NDOMOD_PROCESS_COMMENT_DATA))
1712 return 0;
1713 break;
1714 case NEBCALLBACK_DOWNTIME_DATA:
1715 if(!(ndomod_process_options & NDOMOD_PROCESS_DOWNTIME_DATA))
1716 return 0;
1717 break;
1718 case NEBCALLBACK_FLAPPING_DATA:
1719 if(!(ndomod_process_options & NDOMOD_PROCESS_FLAPPING_DATA))
1720 return 0;
1721 break;
1722 case NEBCALLBACK_PROGRAM_STATUS_DATA:
1723 if(!(ndomod_process_options & NDOMOD_PROCESS_PROGRAM_STATUS_DATA))
1724 return 0;
1725 break;
1726 case NEBCALLBACK_HOST_STATUS_DATA:
1727 if(!(ndomod_process_options & NDOMOD_PROCESS_HOST_STATUS_DATA))
1728 return 0;
1729 break;
1730 case NEBCALLBACK_SERVICE_STATUS_DATA:
1731 if(!(ndomod_process_options & NDOMOD_PROCESS_SERVICE_STATUS_DATA))
1732 return 0;
1733 break;
1734 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
1735 case NEBCALLBACK_CONTACT_STATUS_DATA:
1736 if(!(ndomod_process_options & NDOMOD_PROCESS_CONTACT_STATUS_DATA))
1737 return 0;
1738 break;
1739 #endif
1740 case NEBCALLBACK_ADAPTIVE_PROGRAM_DATA:
1741 if(!(ndomod_process_options & NDOMOD_PROCESS_ADAPTIVE_PROGRAM_DATA))
1742 return 0;
1743 break;
1744 case NEBCALLBACK_ADAPTIVE_HOST_DATA:
1745 if(!(ndomod_process_options & NDOMOD_PROCESS_ADAPTIVE_HOST_DATA))
1746 return 0;
1747 break;
1748 case NEBCALLBACK_ADAPTIVE_SERVICE_DATA:
1749 if(!(ndomod_process_options & NDOMOD_PROCESS_ADAPTIVE_SERVICE_DATA))
1750 return 0;
1751 break;
1752 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
1753 case NEBCALLBACK_ADAPTIVE_CONTACT_DATA:
1754 if(!(ndomod_process_options & NDOMOD_PROCESS_ADAPTIVE_CONTACT_DATA))
1755 return 0;
1756 break;
1757 #endif
1758 case NEBCALLBACK_EXTERNAL_COMMAND_DATA:
1759 if(!(ndomod_process_options & NDOMOD_PROCESS_EXTERNAL_COMMAND_DATA))
1760 return 0;
1761 break;
1762 case NEBCALLBACK_AGGREGATED_STATUS_DATA:
1763 if(!(ndomod_process_options & NDOMOD_PROCESS_AGGREGATED_STATUS_DATA))
1764 return 0;
1765 break;
1766 case NEBCALLBACK_RETENTION_DATA:
1767 if(!(ndomod_process_options & NDOMOD_PROCESS_RETENTION_DATA))
1768 return 0;
1769 break;
1770 case NEBCALLBACK_CONTACT_NOTIFICATION_DATA:
1771 if(!(ndomod_process_options & NDOMOD_PROCESS_NOTIFICATION_DATA))
1772 return 0;
1773 break;
1774 case NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA:
1775 if(!(ndomod_process_options & NDOMOD_PROCESS_NOTIFICATION_DATA))
1776 return 0;
1777 break;
1778 case NEBCALLBACK_ACKNOWLEDGEMENT_DATA:
1779 if(!(ndomod_process_options & NDOMOD_PROCESS_ACKNOWLEDGEMENT_DATA))
1780 return 0;
1781 break;
1782 case NEBCALLBACK_STATE_CHANGE_DATA:
1783 if(!(ndomod_process_options & NDOMOD_PROCESS_STATECHANGE_DATA))
1784 return 0;
1785 break;
1786 default:
1787 break;
1788 }
1789
1790
1791 /* initialize escaped buffers */
1792 for(x=0;x<8;x++)
1793 es[x]=NULL;
1794
1795 /* initialize dynamic buffer (2KB chunk size) */
1796 ndo_dbuf_init(&dbuf,2048);
1797
1798 /* handle the event */
1799 switch(event_type){
1800
1801 case NEBCALLBACK_PROCESS_DATA:
1802
1803 procdata=(nebstruct_process_data *)data;
1804 if (procdata->type == NEBTYPE_PROCESS_START)
1805 ndomod_write_active_objects();
1806
1807 {
1808 struct ndo_broker_data process_data[] = {
1809 { NDO_DATA_TYPE, BD_INT, { .integer = procdata->type }},
1810 { NDO_DATA_FLAGS, BD_INT, { .integer = procdata->flags }},
1811 { NDO_DATA_ATTRIBUTES, BD_INT, { .integer = procdata->attr }},
1812 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
1813 { .timestamp = procdata->timestamp }},
1814 { NDO_DATA_PROGRAMNAME, BD_STRING, { .string = "Nagios" }},
1815 { NDO_DATA_PROGRAMVERSION, BD_STRING,
1816 { .string = get_program_version() }},
1817 { NDO_DATA_PROGRAMDATE, BD_STRING,
1818 { .string = get_program_modification_date() }},
1819 { NDO_DATA_PROCESSID, BD_UNSIGNED_LONG,
1820 { .unsigned_long = (unsigned long)getpid() }}
1821 };
1822
1823 ndomod_broker_data_serialize(&dbuf, NDO_API_PROCESSDATA,
1824 process_data,
1825 sizeof(process_data) / sizeof(process_data[ 0]), TRUE);
1826 }
1827
1828 break;
1829
1830 case NEBCALLBACK_TIMED_EVENT_DATA:
1831
1832 eventdata=(nebstruct_timed_event_data *)data;
1833
1834 switch(eventdata->event_type){
1835
1836 case EVENT_SERVICE_CHECK:
1837 temp_service=(service *)eventdata->event_data;
1838
1839 es[0]=ndo_escape_buffer(temp_service->host_name);
1840 es[1]=ndo_escape_buffer(temp_service->description);
1841
1842 {
1843 struct ndo_broker_data timed_event_data[] = {
1844 { NDO_DATA_TYPE, BD_INT, { .integer = eventdata->type }},
1845 { NDO_DATA_FLAGS, BD_INT, { .integer = eventdata->flags }},
1846 { NDO_DATA_ATTRIBUTES, BD_INT,
1847 { .integer = eventdata->attr }},
1848 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
1849 { .timestamp = eventdata->timestamp }},
1850 { NDO_DATA_EVENTTYPE, BD_INT,
1851 { .integer = eventdata->event_type }},
1852 { NDO_DATA_RECURRING, BD_INT,
1853 { .integer = eventdata->recurring }},
1854 { NDO_DATA_RUNTIME, BD_UNSIGNED_LONG, { .unsigned_long =
1855 (unsigned long)eventdata->run_time }},
1856 { NDO_DATA_HOST, BD_STRING,
1857 { .string = (es[0]==NULL) ? "" : es[0] }},
1858 { NDO_DATA_SERVICE, BD_STRING,
1859 { .string = (es[1]==NULL) ? "" : es[1] }}
1860 };
1861
1862 ndomod_broker_data_serialize(&dbuf, NDO_API_TIMEDEVENTDATA,
1863 timed_event_data,
1864 sizeof(timed_event_data) / sizeof(timed_event_data[ 0]),
1865 TRUE);
1866 }
1867
1868 break;
1869
1870 case EVENT_HOST_CHECK:
1871 temp_host=(host *)eventdata->event_data;
1872
1873 es[0]=ndo_escape_buffer(temp_host->name);
1874
1875 {
1876 struct ndo_broker_data timed_event_data[] = {
1877 { NDO_DATA_TYPE, BD_INT, { .integer = eventdata->type }},
1878 { NDO_DATA_FLAGS, BD_INT, { .integer = eventdata->flags }},
1879 { NDO_DATA_ATTRIBUTES, BD_INT,
1880 { .integer = eventdata->attr }},
1881 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
1882 { .timestamp = eventdata->timestamp }},
1883 { NDO_DATA_EVENTTYPE, BD_INT,
1884 { .integer = eventdata->event_type }},
1885 { NDO_DATA_RECURRING, BD_INT,
1886 { .integer = eventdata->recurring }},
1887 { NDO_DATA_RUNTIME, BD_UNSIGNED_LONG, { .unsigned_long =
1888 (unsigned long)eventdata->run_time }},
1889 { NDO_DATA_HOST, BD_STRING,
1890 { .string = (es[0]==NULL) ? "" : es[0] }}
1891 };
1892
1893 ndomod_broker_data_serialize(&dbuf, NDO_API_TIMEDEVENTDATA,
1894 timed_event_data,
1895 sizeof(timed_event_data) / sizeof(timed_event_data[ 0]),
1896 TRUE);
1897 }
1898
1899 break;
1900
1901 case EVENT_SCHEDULED_DOWNTIME:
1902 temp_downtime=find_downtime(ANY_DOWNTIME,(unsigned long)eventdata->event_data);
1903
1904 if(temp_downtime!=NULL){
1905 es[0]=ndo_escape_buffer(temp_downtime->host_name);
1906 es[1]=ndo_escape_buffer(temp_downtime->service_description);
1907 }
1908
1909 {
1910 struct ndo_broker_data timed_event_data[] = {
1911 { NDO_DATA_TYPE, BD_INT, { .integer = eventdata->type }},
1912 { NDO_DATA_FLAGS, BD_INT, { .integer = eventdata->flags }},
1913 { NDO_DATA_ATTRIBUTES, BD_INT,
1914 { .integer = eventdata->attr }},
1915 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
1916 { .timestamp = eventdata->timestamp }},
1917 { NDO_DATA_EVENTTYPE, BD_INT,
1918 { .integer = eventdata->event_type }},
1919 { NDO_DATA_RECURRING, BD_INT,
1920 { .integer = eventdata->recurring }},
1921 { NDO_DATA_RUNTIME, BD_UNSIGNED_LONG, { .unsigned_long =
1922 (unsigned long)eventdata->run_time }},
1923 { NDO_DATA_HOST, BD_STRING,
1924 { .string = (es[0]==NULL) ? "" : es[0] }},
1925 { NDO_DATA_SERVICE, BD_STRING,
1926 { .string = (es[1]==NULL) ? "" : es[1] }}
1927 };
1928
1929 ndomod_broker_data_serialize(&dbuf, NDO_API_TIMEDEVENTDATA,
1930 timed_event_data,
1931 sizeof(timed_event_data) / sizeof(timed_event_data[ 0]),
1932 TRUE);
1933 }
1934
1935 break;
1936
1937 default:
1938
1939 {
1940 struct ndo_broker_data timed_event_data[] = {
1941 { NDO_DATA_TYPE, BD_INT, { .integer = eventdata->type }},
1942 { NDO_DATA_FLAGS, BD_INT, { .integer = eventdata->flags }},
1943 { NDO_DATA_ATTRIBUTES, BD_INT,
1944 { .integer = eventdata->attr }},
1945 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
1946 { .timestamp = eventdata->timestamp }},
1947 { NDO_DATA_EVENTTYPE, BD_INT,
1948 { .integer = eventdata->event_type }},
1949 { NDO_DATA_RECURRING, BD_INT,
1950 { .integer = eventdata->recurring }},
1951 { NDO_DATA_RUNTIME, BD_UNSIGNED_LONG, { .unsigned_long =
1952 (unsigned long)eventdata->run_time }}
1953 };
1954
1955 ndomod_broker_data_serialize(&dbuf, NDO_API_TIMEDEVENTDATA,
1956 timed_event_data,
1957 sizeof(timed_event_data) / sizeof(timed_event_data[ 0]),
1958 TRUE);
1959 }
1960
1961 break;
1962 }
1963
1964 break;
1965
1966 case NEBCALLBACK_LOG_DATA:
1967
1968 logdata=(nebstruct_log_data *)data;
1969
1970 {
1971 struct ndo_broker_data log_data[] = {
1972 { NDO_DATA_TYPE, BD_INT, { .integer = logdata->type }},
1973 { NDO_DATA_FLAGS, BD_INT, { .integer = logdata->flags }},
1974 { NDO_DATA_ATTRIBUTES, BD_INT,
1975 { .integer = logdata->attr }},
1976 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
1977 { .timestamp = logdata->timestamp }},
1978 { NDO_DATA_LOGENTRYTIME, BD_UNSIGNED_LONG,
1979 { .unsigned_long = logdata->entry_time }},
1980 { NDO_DATA_LOGENTRYTYPE, BD_INT,
1981 { .integer = logdata->data_type }},
1982 { NDO_DATA_LOGENTRY, BD_STRING, { .string = logdata->data }}
1983 };
1984
1985 ndomod_broker_data_serialize(&dbuf, NDO_API_LOGDATA, log_data,
1986 sizeof(log_data) / sizeof(log_data[ 0]), TRUE);
1987 }
1988
1989 break;
1990
1991 case NEBCALLBACK_SYSTEM_COMMAND_DATA:
1992
1993 cmddata=(nebstruct_system_command_data *)data;
1994
1995 es[0]=ndo_escape_buffer(cmddata->command_line);
1996 es[1]=ndo_escape_buffer(cmddata->output);
1997 es[2]=ndo_escape_buffer(cmddata->output);
1998
1999 {
2000 struct ndo_broker_data system_command_data[] = {
2001 { NDO_DATA_TYPE, BD_INT, { .integer = cmddata->type }},
2002 { NDO_DATA_FLAGS, BD_INT, { .integer = cmddata->flags }},
2003 { NDO_DATA_ATTRIBUTES, BD_INT,
2004 { .integer = cmddata->attr }},
2005 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2006 { .timestamp = cmddata->timestamp }},
2007 { NDO_DATA_STARTTIME, BD_TIMEVAL,
2008 { .timestamp = cmddata->start_time }},
2009 { NDO_DATA_ENDTIME, BD_TIMEVAL,
2010 { .timestamp = cmddata->end_time }},
2011 { NDO_DATA_TIMEOUT, BD_INT, { .integer = cmddata->timeout }},
2012 { NDO_DATA_COMMANDLINE, BD_STRING,
2013 { .string = (es[0]==NULL) ? "" : es[0] }},
2014 { NDO_DATA_EARLYTIMEOUT, BD_INT,
2015 { .integer = cmddata->early_timeout }},
2016 { NDO_DATA_EXECUTIONTIME, BD_FLOAT,
2017 { .floating_point = cmddata->execution_time }},
2018 { NDO_DATA_RETURNCODE, BD_INT,
2019 { .integer = cmddata->return_code }},
2020 { NDO_DATA_OUTPUT, BD_STRING,
2021 { .string = (es[1]==NULL) ? "" : es[1] }},
2022 { NDO_DATA_LONGOUTPUT, BD_STRING,
2023 { .string = (es[2]==NULL) ? "" : es[2] }}
2024 };
2025
2026 ndomod_broker_data_serialize(&dbuf, NDO_API_SYSTEMCOMMANDDATA,
2027 system_command_data, sizeof(system_command_data) /
2028 sizeof(system_command_data[ 0]), TRUE);
2029 }
2030
2031 break;
2032
2033 case NEBCALLBACK_EVENT_HANDLER_DATA:
2034
2035 ehanddata=(nebstruct_event_handler_data *)data;
2036
2037 es[0]=ndo_escape_buffer(ehanddata->host_name);
2038 es[1]=ndo_escape_buffer(ehanddata->service_description);
2039 es[2]=ndo_escape_buffer(ehanddata->command_name);
2040 es[3]=ndo_escape_buffer(ehanddata->command_args);
2041 es[4]=ndo_escape_buffer(ehanddata->command_line);
2042 es[5]=ndo_escape_buffer(ehanddata->output);
2043 /* Preparing if eventhandler will have long_output in the future */
2044 es[6]=ndo_escape_buffer(ehanddata->output);
2045
2046 {
2047 struct ndo_broker_data event_handler_data[] = {
2048 { NDO_DATA_TYPE, BD_INT, { .integer = ehanddata->type }},
2049 { NDO_DATA_FLAGS, BD_INT, { .integer = ehanddata->flags }},
2050 { NDO_DATA_ATTRIBUTES, BD_INT,
2051 { .integer = ehanddata->attr }},
2052 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2053 { .timestamp = ehanddata->timestamp }},
2054 { NDO_DATA_HOST, BD_STRING,
2055 { .string = (es[0]==NULL) ? "" : es[0] }},
2056 { NDO_DATA_SERVICE, BD_STRING,
2057 { .string = (es[1]==NULL) ? "" : es[1] }},
2058 { NDO_DATA_STATETYPE, BD_INT,
2059 { .integer = ehanddata->state_type }},
2060 { NDO_DATA_STATE, BD_INT, { .integer = ehanddata->state }},
2061 { NDO_DATA_STARTTIME, BD_TIMEVAL,
2062 { .timestamp = ehanddata->start_time }},
2063 { NDO_DATA_ENDTIME, BD_TIMEVAL,
2064 { .timestamp = ehanddata->end_time }},
2065 { NDO_DATA_TIMEOUT, BD_INT, { .integer = ehanddata->timeout }},
2066 { NDO_DATA_COMMANDNAME, BD_STRING,
2067 { .string = (es[2]==NULL) ? "" : es[2] }},
2068 { NDO_DATA_COMMANDARGS, BD_STRING,
2069 { .string = (es[3]==NULL) ? "" : es[3] }},
2070 { NDO_DATA_COMMANDLINE, BD_STRING,
2071 { .string = (es[4]==NULL) ? "" : es[4] }},
2072 { NDO_DATA_EARLYTIMEOUT, BD_INT,
2073 { .integer = ehanddata->early_timeout }},
2074 { NDO_DATA_EXECUTIONTIME, BD_FLOAT,
2075 { .floating_point = ehanddata->execution_time }},
2076 { NDO_DATA_RETURNCODE, BD_INT,
2077 { .integer = ehanddata->return_code }},
2078 { NDO_DATA_OUTPUT, BD_STRING,
2079 { .string = (es[5]==NULL) ? "" : es[5] }},
2080 { NDO_DATA_LONGOUTPUT, BD_STRING,
2081 { .string = (es[6]==NULL) ? "" : es[6] }}
2082 };
2083
2084 ndomod_broker_data_serialize(&dbuf, NDO_API_EVENTHANDLERDATA,
2085 event_handler_data,
2086 sizeof(event_handler_data) / sizeof(event_handler_data[ 0]),
2087 TRUE);
2088 }
2089
2090 break;
2091
2092 case NEBCALLBACK_NOTIFICATION_DATA:
2093
2094 notdata=(nebstruct_notification_data *)data;
2095
2096 es[0]=ndo_escape_buffer(notdata->host_name);
2097 es[1]=ndo_escape_buffer(notdata->service_description);
2098 es[2]=ndo_escape_buffer(notdata->output);
2099 /* Preparing if notifications will have long_output in the future */
2100 es[3]=ndo_escape_buffer(notdata->output);
2101 es[4]=ndo_escape_buffer(notdata->ack_author);
2102 es[5]=ndo_escape_buffer(notdata->ack_data);
2103
2104 {
2105 struct ndo_broker_data notification_data[] = {
2106 { NDO_DATA_TYPE, BD_INT, { .integer = notdata->type }},
2107 { NDO_DATA_FLAGS, BD_INT, { .integer = notdata->flags }},
2108 { NDO_DATA_ATTRIBUTES, BD_INT,
2109 { .integer = notdata->attr }},
2110 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2111 { .timestamp = notdata->timestamp }},
2112 { NDO_DATA_NOTIFICATIONTYPE, BD_INT,
2113 { .integer = notdata->notification_type }},
2114 { NDO_DATA_STARTTIME, BD_TIMEVAL,
2115 { .timestamp = notdata->start_time }},
2116 { NDO_DATA_ENDTIME, BD_TIMEVAL,
2117 { .timestamp = notdata->end_time }},
2118 { NDO_DATA_HOST, BD_STRING,
2119 { .string = (es[0]==NULL) ? "" : es[0] }},
2120 { NDO_DATA_SERVICE, BD_STRING,
2121 { .string = (es[1]==NULL) ? "" : es[1] }},
2122 { NDO_DATA_NOTIFICATIONREASON, BD_INT,
2123 { .integer = notdata->reason_type }},
2124 { NDO_DATA_STATE, BD_INT, { .integer = notdata->state }},
2125 { NDO_DATA_OUTPUT, BD_STRING,
2126 { .string = (es[2]==NULL) ? "" : es[2] }},
2127 { NDO_DATA_LONGOUTPUT, BD_STRING,
2128 { .string = (es[3]==NULL) ? "" : es[3] }},
2129 { NDO_DATA_ACKAUTHOR, BD_STRING,
2130 { .string = (es[4]==NULL) ? "" : es[4] }},
2131 { NDO_DATA_ACKDATA, BD_STRING,
2132 { .string = (es[5]==NULL) ? "" : es[5] }},
2133 { NDO_DATA_ESCALATED, BD_INT,
2134 { .integer = notdata->escalated }},
2135 { NDO_DATA_CONTACTSNOTIFIED, BD_INT,
2136 { .integer = notdata->contacts_notified }}
2137 };
2138
2139 ndomod_broker_data_serialize(&dbuf, NDO_API_NOTIFICATIONDATA,
2140 notification_data,
2141 sizeof(notification_data) / sizeof(notification_data[ 0]),
2142 TRUE);
2143 }
2144
2145 break;
2146
2147 case NEBCALLBACK_SERVICE_CHECK_DATA:
2148
2149 scdata=(nebstruct_service_check_data *)data;
2150
2151 /* Nagios XI MOD */
2152 /* send only the data we really use */
2153 if(scdata->type!=NEBTYPE_SERVICECHECK_PROCESSED)
2154 break;
2155
2156 es[0]=ndo_escape_buffer(scdata->host_name);
2157 es[1]=ndo_escape_buffer(scdata->service_description);
2158 es[2]=ndo_escape_buffer(scdata->command_name);
2159 es[3]=ndo_escape_buffer(scdata->command_args);
2160 es[4]=ndo_escape_buffer(scdata->command_line);
2161 es[5]=ndo_escape_buffer(scdata->output);
2162 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2163 es[6]=ndo_escape_buffer(scdata->long_output);
2164 #endif
2165 es[7]=ndo_escape_buffer(scdata->perf_data);
2166
2167 {
2168 struct ndo_broker_data service_check_data[] = {
2169 { NDO_DATA_TYPE, BD_INT, { .integer = scdata->type }},
2170 { NDO_DATA_FLAGS, BD_INT, { .integer = scdata->flags }},
2171 { NDO_DATA_ATTRIBUTES, BD_INT,
2172 { .integer = scdata->attr }},
2173 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2174 { .timestamp = scdata->timestamp }},
2175 { NDO_DATA_HOST, BD_STRING,
2176 { .string = (es[0]==NULL) ? "" : es[0] }},
2177 { NDO_DATA_SERVICE, BD_STRING,
2178 { .string = (es[1]==NULL) ? "" : es[1] }},
2179 { NDO_DATA_CHECKTYPE, BD_INT,
2180 { .integer = scdata->check_type }},
2181 { NDO_DATA_CURRENTCHECKATTEMPT, BD_INT,
2182 { .integer = scdata->current_attempt }},
2183 { NDO_DATA_MAXCHECKATTEMPTS, BD_INT,
2184 { .integer = scdata->max_attempts }},
2185 { NDO_DATA_STATETYPE, BD_INT,
2186 { .integer = scdata->state_type }},
2187 { NDO_DATA_STATE, BD_INT, { .integer = scdata->state }},
2188 { NDO_DATA_TIMEOUT, BD_INT, { .integer = scdata->timeout }},
2189 { NDO_DATA_COMMANDNAME, BD_STRING,
2190 { .string = (es[2]==NULL) ? "" : es[2] }},
2191 { NDO_DATA_COMMANDARGS, BD_STRING,
2192 { .string = (es[3]==NULL) ? "" : es[3] }},
2193 { NDO_DATA_COMMANDLINE, BD_STRING,
2194 { .string = (es[4]==NULL) ? "" : es[4] }},
2195 { NDO_DATA_STARTTIME, BD_TIMEVAL,
2196 { .timestamp = scdata->start_time }},
2197 { NDO_DATA_ENDTIME, BD_TIMEVAL,
2198 { .timestamp = scdata->end_time }},
2199 { NDO_DATA_EARLYTIMEOUT, BD_INT,
2200 { .integer = scdata->early_timeout }},
2201 { NDO_DATA_EXECUTIONTIME, BD_FLOAT,
2202 { .floating_point = scdata->execution_time }},
2203 { NDO_DATA_LATENCY, BD_FLOAT,
2204 { .floating_point = scdata->latency }},
2205 { NDO_DATA_RETURNCODE, BD_INT,
2206 { .integer = scdata->return_code }},
2207 { NDO_DATA_OUTPUT, BD_STRING,
2208 { .string = (es[5]==NULL) ? "" : es[5] }},
2209 { NDO_DATA_LONGOUTPUT, BD_STRING,
2210 { .string = (es[6]==NULL) ? "" : es[6] }},
2211 { NDO_DATA_PERFDATA, BD_STRING,
2212 { .string = (es[7]==NULL) ? "" : es[7] }}
2213 };
2214
2215 ndomod_broker_data_serialize(&dbuf, NDO_API_SERVICECHECKDATA,
2216 service_check_data,
2217 sizeof(service_check_data) / sizeof(service_check_data[ 0]),
2218 TRUE);
2219 }
2220
2221 break;
2222
2223 case NEBCALLBACK_HOST_CHECK_DATA:
2224
2225 hcdata=(nebstruct_host_check_data *)data;
2226
2227 /* Nagios XI MOD */
2228 /* send only the data we really use */
2229 if(hcdata->type!=NEBTYPE_HOSTCHECK_PROCESSED)
2230 break;
2231
2232 es[0]=ndo_escape_buffer(hcdata->host_name);
2233 es[1]=ndo_escape_buffer(hcdata->command_name);
2234 es[2]=ndo_escape_buffer(hcdata->command_args);
2235 es[3]=ndo_escape_buffer(hcdata->command_line);
2236 es[4]=ndo_escape_buffer(hcdata->output);
2237 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2238 es[5]=ndo_escape_buffer(hcdata->long_output);
2239 #endif
2240 es[6]=ndo_escape_buffer(hcdata->perf_data);
2241
2242 {
2243 struct ndo_broker_data host_check_data[] = {
2244 { NDO_DATA_TYPE, BD_INT, { .integer = hcdata->type }},
2245 { NDO_DATA_FLAGS, BD_INT, { .integer = hcdata->flags }},
2246 { NDO_DATA_ATTRIBUTES, BD_INT,
2247 { .integer = hcdata->attr }},
2248 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2249 { .timestamp = hcdata->timestamp }},
2250 { NDO_DATA_HOST, BD_STRING,
2251 { .string = (es[0]==NULL) ? "" : es[0] }},
2252 { NDO_DATA_CHECKTYPE, BD_INT,
2253 { .integer = hcdata->check_type }},
2254 { NDO_DATA_CURRENTCHECKATTEMPT, BD_INT,
2255 { .integer = hcdata->current_attempt }},
2256 { NDO_DATA_MAXCHECKATTEMPTS, BD_INT,
2257 { .integer = hcdata->max_attempts }},
2258 { NDO_DATA_STATETYPE, BD_INT,
2259 { .integer = hcdata->state_type }},
2260 { NDO_DATA_STATE, BD_INT, { .integer = hcdata->state }},
2261 { NDO_DATA_TIMEOUT, BD_INT, { .integer = hcdata->timeout }},
2262 { NDO_DATA_COMMANDNAME, BD_STRING,
2263 { .string = (es[1]==NULL) ? "" : es[1] }},
2264 { NDO_DATA_COMMANDARGS, BD_STRING,
2265 { .string = (es[2]==NULL) ? "" : es[2] }},
2266 { NDO_DATA_COMMANDLINE, BD_STRING,
2267 { .string = (es[3]==NULL) ? "" : es[3] }},
2268 { NDO_DATA_STARTTIME, BD_TIMEVAL,
2269 { .timestamp = hcdata->start_time }},
2270 { NDO_DATA_ENDTIME, BD_TIMEVAL,
2271 { .timestamp = hcdata->end_time }},
2272 { NDO_DATA_EARLYTIMEOUT, BD_INT,
2273 { .integer = hcdata->early_timeout }},
2274 { NDO_DATA_EXECUTIONTIME, BD_FLOAT,
2275 { .floating_point = hcdata->execution_time }},
2276 { NDO_DATA_LATENCY, BD_FLOAT,
2277 { .floating_point = hcdata->latency }},
2278 { NDO_DATA_RETURNCODE, BD_INT,
2279 { .integer = hcdata->return_code }},
2280 { NDO_DATA_OUTPUT, BD_STRING,
2281 { .string = (es[4]==NULL) ? "" : es[4] }},
2282 { NDO_DATA_LONGOUTPUT, BD_STRING,
2283 { .string = (es[5]==NULL) ? "" : es[5] }},
2284 { NDO_DATA_PERFDATA, BD_STRING,
2285 { .string = (es[6]==NULL) ? "" : es[6] }}
2286 };
2287
2288 ndomod_broker_data_serialize(&dbuf, NDO_API_HOSTCHECKDATA,
2289 host_check_data,
2290 sizeof(host_check_data) / sizeof(host_check_data[ 0]),
2291 TRUE);
2292 }
2293
2294 break;
2295
2296 case NEBCALLBACK_COMMENT_DATA:
2297
2298 comdata=(nebstruct_comment_data *)data;
2299
2300 es[0]=ndo_escape_buffer(comdata->host_name);
2301 es[1]=ndo_escape_buffer(comdata->service_description);
2302 es[2]=ndo_escape_buffer(comdata->author_name);
2303 es[3]=ndo_escape_buffer(comdata->comment_data);
2304
2305 {
2306 struct ndo_broker_data comment_data[] = {
2307 { NDO_DATA_TYPE, BD_INT, { .integer = comdata->type }},
2308 { NDO_DATA_FLAGS, BD_INT, { .integer = comdata->flags }},
2309 { NDO_DATA_ATTRIBUTES, BD_INT,
2310 { .integer = comdata->attr }},
2311 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2312 { .timestamp = comdata->timestamp }},
2313 { NDO_DATA_COMMENTTYPE, BD_INT,
2314 { .integer = comdata->comment_type }},
2315 { NDO_DATA_HOST, BD_STRING,
2316 { .string = (es[0]==NULL) ? "" : es[0] }},
2317 { NDO_DATA_SERVICE, BD_STRING,
2318 { .string = (es[1]==NULL) ? "" : es[1] }},
2319 { NDO_DATA_ENTRYTIME, BD_UNSIGNED_LONG, { .unsigned_long =
2320 (unsigned long)comdata->entry_time }},
2321 { NDO_DATA_AUTHORNAME, BD_STRING,
2322 { .string = (es[2]==NULL) ? "" : es[2] }},
2323 { NDO_DATA_COMMENT, BD_STRING,
2324 { .string = (es[3]==NULL) ? "" : es[3] }},
2325 { NDO_DATA_PERSISTENT, BD_INT,
2326 { .integer = comdata->persistent }},
2327 { NDO_DATA_SOURCE, BD_INT,
2328 { .integer = comdata->source }},
2329 { NDO_DATA_ENTRYTYPE, BD_INT,
2330 { .integer = comdata->entry_type }},
2331 { NDO_DATA_EXPIRES, BD_INT,
2332 { .integer = comdata->expires }},
2333 { NDO_DATA_EXPIRATIONTIME, BD_UNSIGNED_LONG, { .unsigned_long =
2334 (unsigned long)comdata->expire_time }},
2335 { NDO_DATA_COMMENTID, BD_UNSIGNED_LONG,
2336 { .unsigned_long = comdata->comment_id }}
2337 };
2338
2339 ndomod_broker_data_serialize(&dbuf, NDO_API_COMMENTDATA,
2340 comment_data,
2341 sizeof(comment_data) / sizeof(comment_data[ 0]), TRUE);
2342 }
2343
2344 break;
2345
2346 case NEBCALLBACK_DOWNTIME_DATA:
2347
2348 downdata=(nebstruct_downtime_data *)data;
2349
2350 es[0]=ndo_escape_buffer(downdata->host_name);
2351 es[1]=ndo_escape_buffer(downdata->service_description);
2352 es[2]=ndo_escape_buffer(downdata->author_name);
2353 es[3]=ndo_escape_buffer(downdata->comment_data);
2354
2355 {
2356 struct ndo_broker_data downtime_data[] = {
2357 { NDO_DATA_TYPE, BD_INT, { .integer = downdata->type }},
2358 { NDO_DATA_FLAGS, BD_INT, { .integer = downdata->flags }},
2359 { NDO_DATA_ATTRIBUTES, BD_INT,
2360 { .integer = downdata->attr }},
2361 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2362 { .timestamp = downdata->timestamp }},
2363 { NDO_DATA_DOWNTIMETYPE, BD_INT,
2364 { .integer = downdata->downtime_type }},
2365 { NDO_DATA_HOST, BD_STRING,
2366 { .string = (es[0]==NULL) ? "" : es[0] }},
2367 { NDO_DATA_SERVICE, BD_STRING,
2368 { .string = (es[1]==NULL) ? "" : es[1] }},
2369 { NDO_DATA_ENTRYTIME, BD_UNSIGNED_LONG, { .unsigned_long =
2370 (unsigned long)downdata->entry_time }},
2371 { NDO_DATA_AUTHORNAME, BD_STRING,
2372 { .string = (es[2]==NULL) ? "" : es[2] }},
2373 { NDO_DATA_COMMENT, BD_STRING,
2374 { .string = (es[3]==NULL) ? "" : es[3] }},
2375 { NDO_DATA_STARTTIME, BD_UNSIGNED_LONG, { .unsigned_long =
2376 (unsigned long)downdata->start_time }},
2377 { NDO_DATA_ENDTIME, BD_UNSIGNED_LONG, { .unsigned_long =
2378 (unsigned long)downdata->end_time }},
2379 { NDO_DATA_FIXED, BD_INT, { .integer = downdata->fixed }},
2380 { NDO_DATA_DURATION, BD_UNSIGNED_LONG, { .unsigned_long =
2381 (unsigned long)downdata->duration }},
2382 { NDO_DATA_TRIGGEREDBY, BD_UNSIGNED_LONG, { .unsigned_long =
2383 (unsigned long)downdata->triggered_by }},
2384 { NDO_DATA_DOWNTIMEID, BD_UNSIGNED_LONG, { .unsigned_long =
2385 (unsigned long)downdata->downtime_id }}
2386 };
2387
2388 ndomod_broker_data_serialize(&dbuf, NDO_API_DOWNTIMEDATA,
2389 downtime_data,
2390 sizeof(downtime_data) / sizeof(downtime_data[ 0]), TRUE);
2391 }
2392
2393 break;
2394
2395 case NEBCALLBACK_FLAPPING_DATA:
2396
2397 flapdata=(nebstruct_flapping_data *)data;
2398
2399 es[0]=ndo_escape_buffer(flapdata->host_name);
2400 es[1]=ndo_escape_buffer(flapdata->service_description);
2401
2402 if(flapdata->flapping_type==HOST_FLAPPING)
2403 temp_comment=find_host_comment(flapdata->comment_id);
2404 else
2405 temp_comment=find_service_comment(flapdata->comment_id);
2406
2407 {
2408 struct ndo_broker_data flapping_data[] = {
2409 { NDO_DATA_TYPE, BD_INT, { .integer = flapdata->type }},
2410 { NDO_DATA_FLAGS, BD_INT, { .integer = flapdata->flags }},
2411 { NDO_DATA_ATTRIBUTES, BD_INT,
2412 { .integer = flapdata->attr }},
2413 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2414 { .timestamp = flapdata->timestamp }},
2415 { NDO_DATA_FLAPPINGTYPE, BD_INT,
2416 { .integer = flapdata->flapping_type }},
2417 { NDO_DATA_HOST, BD_STRING,
2418 { .string = (es[0]==NULL) ? "" : es[0] }},
2419 { NDO_DATA_SERVICE, BD_STRING,
2420 { .string = (es[1]==NULL) ? "" : es[1] }},
2421 { NDO_DATA_PERCENTSTATECHANGE, BD_FLOAT,
2422 { .floating_point = flapdata->percent_change }},
2423 { NDO_DATA_HIGHTHRESHOLD, BD_FLOAT,
2424 { .floating_point = flapdata->high_threshold }},
2425 { NDO_DATA_LOWTHRESHOLD, BD_FLOAT,
2426 { .floating_point = flapdata->low_threshold }},
2427 { NDO_DATA_COMMENTTIME, BD_UNSIGNED_LONG, { .unsigned_long =
2428 (temp_comment==NULL) ? 0L :
2429 (unsigned long)temp_comment->entry_time }},
2430 { NDO_DATA_COMMENTID, BD_UNSIGNED_LONG,
2431 { .unsigned_long = flapdata->comment_id }}
2432 };
2433
2434 ndomod_broker_data_serialize(&dbuf, NDO_API_FLAPPINGDATA,
2435 flapping_data,
2436 sizeof(flapping_data) / sizeof(flapping_data[ 0]), TRUE);
2437 }
2438
2439 break;
2440
2441 case NEBCALLBACK_PROGRAM_STATUS_DATA:
2442
2443 psdata=(nebstruct_program_status_data *)data;
2444
2445 es[0]=ndo_escape_buffer(psdata->global_host_event_handler);
2446 es[1]=ndo_escape_buffer(psdata->global_service_event_handler);
2447
2448 {
2449 struct ndo_broker_data program_status_data[] = {
2450 { NDO_DATA_TYPE, BD_INT, { .integer = psdata->type }},
2451 { NDO_DATA_FLAGS, BD_INT, { .integer = psdata->flags }},
2452 { NDO_DATA_ATTRIBUTES, BD_INT,
2453 { .integer = psdata->attr }},
2454 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2455 { .timestamp = psdata->timestamp }},
2456 { NDO_DATA_PROGRAMSTARTTIME, BD_UNSIGNED_LONG,
2457 { .unsigned_long =
2458 (unsigned long)psdata->program_start }},
2459 { NDO_DATA_PROCESSID, BD_INT,
2460 { .integer = psdata->pid }},
2461 { NDO_DATA_DAEMONMODE, BD_INT,
2462 { .integer = psdata->daemon_mode }},
2463 { NDO_DATA_LASTCOMMANDCHECK, BD_UNSIGNED_LONG,
2464 { .unsigned_long =
2465 #ifdef BUILD_NAGIOS_4X
2466 0L
2467 #else
2468 (unsigned long)psdata->last_command_check
2469 #endif
2470 }},
2471 { NDO_DATA_LASTLOGROTATION, BD_UNSIGNED_LONG,
2472 { .unsigned_long = psdata->last_log_rotation }},
2473 { NDO_DATA_NOTIFICATIONSENABLED, BD_INT,
2474 { .integer = psdata->notifications_enabled }},
2475 { NDO_DATA_ACTIVESERVICECHECKSENABLED, BD_INT,
2476 { .integer = psdata->active_service_checks_enabled }},
2477 { NDO_DATA_PASSIVESERVICECHECKSENABLED, BD_INT,
2478 { .integer = psdata->passive_service_checks_enabled }},
2479 { NDO_DATA_ACTIVEHOSTCHECKSENABLED, BD_INT,
2480 { .integer = psdata->active_host_checks_enabled }},
2481 { NDO_DATA_PASSIVEHOSTCHECKSENABLED, BD_INT,
2482 { .integer = psdata->passive_host_checks_enabled }},
2483 { NDO_DATA_EVENTHANDLERSENABLED, BD_INT,
2484 { .integer = psdata->event_handlers_enabled }},
2485 { NDO_DATA_FLAPDETECTIONENABLED, BD_INT,
2486 { .integer = psdata->flap_detection_enabled }},
2487 { NDO_DATA_FAILUREPREDICTIONENABLED, BD_INT, { .integer =
2488 #ifdef BUILD_NAGIOS_4X
2489 0L
2490 #else
2491 psdata->failure_prediction_enabled
2492 #endif
2493 }},
2494 { NDO_DATA_PROCESSPERFORMANCEDATA, BD_INT,
2495 { .integer = psdata->process_performance_data }},
2496 { NDO_DATA_OBSESSOVERHOSTS, BD_INT,
2497 { .integer = psdata->obsess_over_hosts }},
2498 { NDO_DATA_OBSESSOVERSERVICES, BD_INT,
2499 { .integer = psdata->obsess_over_services }},
2500 { NDO_DATA_MODIFIEDHOSTATTRIBUTES, BD_UNSIGNED_LONG,
2501 { .unsigned_long = psdata->modified_host_attributes }},
2502 { NDO_DATA_MODIFIEDSERVICEATTRIBUTES, BD_UNSIGNED_LONG,
2503 { .unsigned_long =
2504 psdata->modified_service_attributes }},
2505 { NDO_DATA_GLOBALHOSTEVENTHANDLER, BD_STRING,
2506 { .string = (es[0]==NULL) ? "" : es[0] }},
2507 { NDO_DATA_GLOBALSERVICEEVENTHANDLER, BD_STRING,
2508 { .string = (es[1]==NULL) ? "" : es[1] }},
2509 };
2510
2511 ndomod_broker_data_serialize(&dbuf, NDO_API_PROGRAMSTATUSDATA,
2512 program_status_data,
2513 sizeof(program_status_data) /
2514 sizeof(program_status_data[ 0]), TRUE);
2515 }
2516
2517 break;
2518
2519 case NEBCALLBACK_HOST_STATUS_DATA:
2520
2521 hsdata=(nebstruct_host_status_data *)data;
2522
2523 if((temp_host=(host *)hsdata->object_ptr)==NULL){
2524 ndo_dbuf_free(&dbuf);
2525 return 0;
2526 }
2527
2528 es[0]=ndo_escape_buffer(temp_host->name);
2529 es[1]=ndo_escape_buffer(temp_host->plugin_output);
2530 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2531 es[2]=ndo_escape_buffer(temp_host->long_plugin_output);
2532 #endif
2533 es[3]=ndo_escape_buffer(temp_host->perf_data);
2534 es[4]=ndo_escape_buffer(temp_host->event_handler);
2535 #ifdef BUILD_NAGIOS_4X
2536 es[5]=ndo_escape_buffer(temp_host->check_command);
2537 #else
2538 es[5]=ndo_escape_buffer(temp_host->host_check_command);
2539 #endif
2540 es[6]=ndo_escape_buffer(temp_host->check_period);
2541
2542 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2543 retry_interval=temp_host->retry_interval;
2544 #endif
2545 #ifdef BUILD_NAGIOS_2X
2546 retry_interval=0.0;
2547 #endif
2548
2549 {
2550 struct ndo_broker_data host_status_data[] = {
2551 { NDO_DATA_TYPE, BD_INT, { .integer = hsdata->type }},
2552 { NDO_DATA_FLAGS, BD_INT, { .integer = hsdata->flags }},
2553 { NDO_DATA_ATTRIBUTES, BD_INT,
2554 { .integer = hsdata->attr }},
2555 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2556 { .timestamp = hsdata->timestamp }},
2557 { NDO_DATA_HOST, BD_STRING,
2558 { .string = (es[0]==NULL) ? "" : es[0] }},
2559 { NDO_DATA_OUTPUT, BD_STRING,
2560 { .string = (es[1]==NULL) ? "" : es[1] }},
2561 { NDO_DATA_LONGOUTPUT, BD_STRING,
2562 { .string = (es[2]==NULL) ? "" : es[2] }},
2563 { NDO_DATA_PERFDATA, BD_STRING,
2564 { .string = (es[3]==NULL) ? "" : es[3] }},
2565 { NDO_DATA_CURRENTSTATE, BD_INT,
2566 { .integer = temp_host->current_state }},
2567 { NDO_DATA_HASBEENCHECKED, BD_INT,
2568 { .integer = temp_host->has_been_checked }},
2569 { NDO_DATA_SHOULDBESCHEDULED, BD_INT,
2570 { .integer = temp_host->should_be_scheduled }},
2571 { NDO_DATA_CURRENTCHECKATTEMPT, BD_INT,
2572 { .integer = temp_host->current_attempt }},
2573 { NDO_DATA_MAXCHECKATTEMPTS, BD_INT,
2574 { .integer = temp_host->max_attempts }},
2575 { NDO_DATA_LASTHOSTCHECK, BD_UNSIGNED_LONG, { .unsigned_long =
2576 (unsigned long)temp_host->last_check }},
2577 { NDO_DATA_NEXTHOSTCHECK, BD_UNSIGNED_LONG, { .unsigned_long =
2578 (unsigned long)temp_host->next_check }},
2579 { NDO_DATA_CHECKTYPE, BD_INT,
2580 { .integer = temp_host->check_type }},
2581 { NDO_DATA_LASTSTATECHANGE, BD_UNSIGNED_LONG,
2582 { .unsigned_long =
2583 (unsigned long)temp_host->last_state_change }},
2584 { NDO_DATA_LASTHARDSTATECHANGE, BD_UNSIGNED_LONG,
2585 { .unsigned_long =
2586 (unsigned long)temp_host->last_hard_state_change }},
2587 { NDO_DATA_LASTHARDSTATE, BD_INT,
2588 { .integer = temp_host->last_hard_state }},
2589 { NDO_DATA_LASTTIMEUP, BD_UNSIGNED_LONG,
2590 { .unsigned_long =
2591 (unsigned long)temp_host->last_time_up }},
2592 { NDO_DATA_LASTTIMEDOWN, BD_UNSIGNED_LONG,
2593 { .unsigned_long =
2594 (unsigned long)temp_host->last_time_down }},
2595 { NDO_DATA_LASTTIMEUNREACHABLE, BD_UNSIGNED_LONG,
2596 { .unsigned_long =
2597 (unsigned long)temp_host->last_time_unreachable }},
2598 { NDO_DATA_STATETYPE, BD_INT,
2599 { .integer = temp_host->state_type }},
2600 { NDO_DATA_LASTHOSTNOTIFICATION, BD_UNSIGNED_LONG,
2601 { .unsigned_long =
2602 #ifdef BUILD_NAGIOS_4X
2603 (unsigned long)temp_host->last_notification
2604 #else
2605 (unsigned long)temp_host->last_host_notification
2606 #endif
2607 }},
2608 { NDO_DATA_NEXTHOSTNOTIFICATION, BD_UNSIGNED_LONG,
2609 { .unsigned_long =
2610 #ifdef BUILD_NAGIOS_4X
2611 (unsigned long)temp_host->next_notification
2612 #else
2613 (unsigned long)temp_host->next_host_notification
2614 #endif
2615 }},
2616 { NDO_DATA_NOMORENOTIFICATIONS, BD_INT,
2617 { .integer = temp_host->no_more_notifications }},
2618 { NDO_DATA_NOTIFICATIONSENABLED, BD_INT,
2619 { .integer = temp_host->notifications_enabled }},
2620 { NDO_DATA_PROBLEMHASBEENACKNOWLEDGED, BD_INT,
2621 { .integer =
2622 temp_host->problem_has_been_acknowledged }},
2623 { NDO_DATA_ACKNOWLEDGEMENTTYPE, BD_INT,
2624 { .integer = temp_host->acknowledgement_type }},
2625 { NDO_DATA_CURRENTNOTIFICATIONNUMBER, BD_INT,
2626 { .integer = temp_host->current_notification_number }},
2627 { NDO_DATA_PASSIVEHOSTCHECKSENABLED, BD_INT,
2628 { .integer =
2629 #ifdef BUILD_NAGIOS_4X
2630 temp_host->accept_passive_checks
2631 #else
2632 temp_host->accept_passive_host_checks
2633 #endif
2634 }},
2635 { NDO_DATA_EVENTHANDLERENABLED, BD_INT,
2636 { .integer = temp_host->event_handler_enabled }},
2637 { NDO_DATA_ACTIVEHOSTCHECKSENABLED, BD_INT,
2638 { .integer = temp_host->checks_enabled }},
2639 { NDO_DATA_FLAPDETECTIONENABLED, BD_INT,
2640 { .integer = temp_host->flap_detection_enabled }},
2641 { NDO_DATA_ISFLAPPING, BD_INT,
2642 { .integer = temp_host->is_flapping }},
2643 { NDO_DATA_PERCENTSTATECHANGE, BD_FLOAT,
2644 { .floating_point = temp_host->percent_state_change }},
2645 { NDO_DATA_LATENCY, BD_FLOAT,
2646 { .floating_point = temp_host->latency }},
2647 { NDO_DATA_EXECUTIONTIME, BD_FLOAT,
2648 { .floating_point = temp_host->execution_time }},
2649 { NDO_DATA_SCHEDULEDDOWNTIMEDEPTH, BD_INT,
2650 { .integer = temp_host->scheduled_downtime_depth }},
2651 { NDO_DATA_FAILUREPREDICTIONENABLED, BD_INT,
2652 { .integer =
2653 #ifdef BUILD_NAGIOS_4X
2654 0
2655 #else
2656 temp_host->failure_prediction_enabled
2657 #endif
2658 }},
2659 { NDO_DATA_PROCESSPERFORMANCEDATA, BD_INT,
2660 { .integer = temp_host->process_performance_data }},
2661 { NDO_DATA_OBSESSOVERHOST, BD_INT,
2662 { .integer =
2663 #ifdef BUILD_NAGIOS_4X
2664 temp_host->obsess
2665 #else
2666 temp_host->obsess_over_host
2667 #endif
2668 }},
2669 { NDO_DATA_MODIFIEDHOSTATTRIBUTES, BD_UNSIGNED_LONG,
2670 { .unsigned_long = temp_host->modified_attributes }},
2671 { NDO_DATA_EVENTHANDLER, BD_STRING,
2672 { .string = (es[4]==NULL) ? "" : es[4] }},
2673 { NDO_DATA_CHECKCOMMAND, BD_STRING,
2674 { .string = (es[5]==NULL) ? "" : es[5] }},
2675 { NDO_DATA_NORMALCHECKINTERVAL, BD_FLOAT,
2676 { .floating_point =
2677 (double)temp_host->check_interval }},
2678 { NDO_DATA_RETRYCHECKINTERVAL, BD_FLOAT,
2679 { .floating_point = (double)retry_interval }},
2680 { NDO_DATA_HOSTCHECKPERIOD, BD_STRING,
2681 { .string = (es[6]==NULL) ? "" : es[6] }}
2682 };
2683
2684 ndomod_broker_data_serialize(&dbuf, NDO_API_HOSTSTATUSDATA,
2685 host_status_data,
2686 sizeof(host_status_data) / sizeof(host_status_data[ 0]),
2687 FALSE);
2688 }
2689
2690 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2691 ndomod_customvars_serialize(temp_host->custom_variables, &dbuf);
2692 #endif
2693
2694 ndomod_enddata_serialize(&dbuf);
2695
2696 break;
2697
2698 case NEBCALLBACK_SERVICE_STATUS_DATA:
2699
2700 ssdata=(nebstruct_service_status_data *)data;
2701
2702 if((temp_service=(service *)ssdata->object_ptr)==NULL){
2703 ndo_dbuf_free(&dbuf);
2704 return 0;
2705 }
2706
2707 es[0]=ndo_escape_buffer(temp_service->host_name);
2708 es[1]=ndo_escape_buffer(temp_service->description);
2709 es[2]=ndo_escape_buffer(temp_service->plugin_output);
2710 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2711 es[3]=ndo_escape_buffer(temp_service->long_plugin_output);
2712 #endif
2713 es[4]=ndo_escape_buffer(temp_service->perf_data);
2714 es[5]=ndo_escape_buffer(temp_service->event_handler);
2715 #ifdef BUILD_NAGIOS_4X
2716 es[6]=ndo_escape_buffer(temp_service->check_command);
2717 #else
2718 es[6]=ndo_escape_buffer(temp_service->service_check_command);
2719 #endif
2720 es[7]=ndo_escape_buffer(temp_service->check_period);
2721
2722 {
2723 struct ndo_broker_data service_status_data[] = {
2724 { NDO_DATA_TYPE, BD_INT, { .integer = ssdata->type }},
2725 { NDO_DATA_FLAGS, BD_INT, { .integer = ssdata->flags }},
2726 { NDO_DATA_ATTRIBUTES, BD_INT,
2727 { .integer = ssdata->attr }},
2728 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2729 { .timestamp = ssdata->timestamp }},
2730 { NDO_DATA_HOST, BD_STRING,
2731 { .string = (es[0]==NULL) ? "" : es[0] }},
2732 { NDO_DATA_SERVICE, BD_STRING,
2733 { .string = (es[1]==NULL) ? "" : es[1] }},
2734 { NDO_DATA_OUTPUT, BD_STRING,
2735 { .string = (es[2]==NULL) ? "" : es[2] }},
2736 { NDO_DATA_LONGOUTPUT, BD_STRING,
2737 { .string = (es[3]==NULL) ? "" : es[3] }},
2738 { NDO_DATA_PERFDATA, BD_STRING,
2739 { .string = (es[4]==NULL) ? "" : es[4] }},
2740 { NDO_DATA_CURRENTSTATE, BD_INT,
2741 { .integer = temp_service->current_state }},
2742 { NDO_DATA_HASBEENCHECKED, BD_INT,
2743 { .integer = temp_service->has_been_checked }},
2744 { NDO_DATA_SHOULDBESCHEDULED, BD_INT,
2745 { .integer = temp_service->should_be_scheduled }},
2746 { NDO_DATA_CURRENTCHECKATTEMPT, BD_INT,
2747 { .integer = temp_service->current_attempt }},
2748 { NDO_DATA_MAXCHECKATTEMPTS, BD_INT,
2749 { .integer = temp_service->max_attempts }},
2750 { NDO_DATA_LASTSERVICECHECK, BD_UNSIGNED_LONG,
2751 { .unsigned_long =
2752 (unsigned long)temp_service->last_check }},
2753 { NDO_DATA_NEXTSERVICECHECK, BD_UNSIGNED_LONG,
2754 { .unsigned_long =
2755 (unsigned long)temp_service->next_check }},
2756 { NDO_DATA_CHECKTYPE, BD_INT,
2757 { .integer = temp_service->check_type }},
2758 { NDO_DATA_LASTSTATECHANGE, BD_UNSIGNED_LONG,
2759 { .unsigned_long =
2760 (unsigned long)temp_service->last_state_change }},
2761 { NDO_DATA_LASTHARDSTATECHANGE, BD_UNSIGNED_LONG,
2762 { .unsigned_long =
2763 (unsigned long)temp_service->last_hard_state_change }},
2764 { NDO_DATA_LASTHARDSTATE, BD_INT,
2765 { .integer = temp_service->last_hard_state }},
2766 { NDO_DATA_LASTTIMEOK, BD_UNSIGNED_LONG,
2767 { .unsigned_long =
2768 (unsigned long)temp_service->last_time_ok }},
2769 { NDO_DATA_LASTTIMEWARNING, BD_UNSIGNED_LONG,
2770 { .unsigned_long =
2771 (unsigned long)temp_service->last_time_warning }},
2772 { NDO_DATA_LASTTIMEUNKNOWN, BD_UNSIGNED_LONG,
2773 { .unsigned_long =
2774 (unsigned long)temp_service->last_time_unknown }},
2775 { NDO_DATA_LASTTIMECRITICAL, BD_UNSIGNED_LONG,
2776 { .unsigned_long =
2777 (unsigned long)temp_service->last_time_critical }},
2778 { NDO_DATA_STATETYPE, BD_INT,
2779 { .integer = temp_service->state_type }},
2780 { NDO_DATA_LASTSERVICENOTIFICATION, BD_UNSIGNED_LONG,
2781 { .unsigned_long =
2782 (unsigned long)temp_service->last_notification }},
2783 { NDO_DATA_NEXTSERVICENOTIFICATION, BD_UNSIGNED_LONG,
2784 { .unsigned_long =
2785 (unsigned long)temp_service->next_notification }},
2786 { NDO_DATA_NOMORENOTIFICATIONS, BD_INT,
2787 { .integer = temp_service->no_more_notifications }},
2788 { NDO_DATA_NOTIFICATIONSENABLED, BD_INT,
2789 { .integer = temp_service->notifications_enabled }},
2790 { NDO_DATA_PROBLEMHASBEENACKNOWLEDGED, BD_INT,
2791 { .integer =
2792 temp_service->problem_has_been_acknowledged }},
2793 { NDO_DATA_ACKNOWLEDGEMENTTYPE, BD_INT,
2794 { .integer = temp_service->acknowledgement_type }},
2795 { NDO_DATA_CURRENTNOTIFICATIONNUMBER, BD_INT,
2796 { .integer =
2797 temp_service->current_notification_number }},
2798 { NDO_DATA_PASSIVESERVICECHECKSENABLED, BD_INT,
2799 { .integer =
2800 #ifdef BUILD_NAGIOS_4X
2801 temp_service->accept_passive_checks
2802 #else
2803 temp_service->accept_passive_service_checks
2804 #endif
2805 }},
2806 { NDO_DATA_EVENTHANDLERENABLED, BD_INT,
2807 { .integer = temp_service->event_handler_enabled }},
2808 { NDO_DATA_ACTIVESERVICECHECKSENABLED, BD_INT,
2809 { .integer = temp_service->checks_enabled }},
2810 { NDO_DATA_FLAPDETECTIONENABLED, BD_INT,
2811 { .integer = temp_service->flap_detection_enabled }},
2812 { NDO_DATA_ISFLAPPING, BD_INT,
2813 { .integer = temp_service->is_flapping }},
2814 { NDO_DATA_PERCENTSTATECHANGE, BD_FLOAT,
2815 { .floating_point =
2816 temp_service->percent_state_change }},
2817 { NDO_DATA_LATENCY, BD_FLOAT,
2818 { .floating_point = temp_service->latency }},
2819 { NDO_DATA_EXECUTIONTIME, BD_FLOAT,
2820 { .floating_point = temp_service->execution_time }},
2821 { NDO_DATA_SCHEDULEDDOWNTIMEDEPTH, BD_INT,
2822 { .integer = temp_service->scheduled_downtime_depth }},
2823 { NDO_DATA_FAILUREPREDICTIONENABLED, BD_INT,
2824 { .integer =
2825 #ifdef BUILD_NAGIOS_4X
2826 0
2827 #else
2828 temp_service->failure_prediction_enabled
2829 #endif
2830 }},
2831 { NDO_DATA_PROCESSPERFORMANCEDATA, BD_INT,
2832 { .integer = temp_service->process_performance_data }},
2833 { NDO_DATA_OBSESSOVERSERVICE, BD_INT,
2834 { .integer =
2835 #ifdef BUILD_NAGIOS_4X
2836 temp_service->obsess
2837 #else
2838 temp_service->obsess_over_service
2839 #endif
2840 }},
2841 { NDO_DATA_MODIFIEDSERVICEATTRIBUTES, BD_UNSIGNED_LONG,
2842 { .unsigned_long = temp_service->modified_attributes }},
2843 { NDO_DATA_EVENTHANDLER, BD_STRING,
2844 { .string = (es[5]==NULL) ? "" : es[5] }},
2845 { NDO_DATA_CHECKCOMMAND, BD_STRING,
2846 { .string = (es[6]==NULL) ? "" : es[6] }},
2847 { NDO_DATA_NORMALCHECKINTERVAL, BD_FLOAT,
2848 { .floating_point =
2849 (double)temp_service->check_interval }},
2850 { NDO_DATA_RETRYCHECKINTERVAL, BD_FLOAT,
2851 { .floating_point =
2852 (double)temp_service->retry_interval }},
2853 { NDO_DATA_SERVICECHECKPERIOD, BD_STRING,
2854 { .string = (es[7]==NULL) ? "" : es[7] }}
2855 };
2856
2857 ndomod_broker_data_serialize(&dbuf, NDO_API_SERVICESTATUSDATA,
2858 service_status_data, sizeof(service_status_data) /
2859 sizeof(service_status_data[ 0]), FALSE);
2860 }
2861
2862 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2863 ndomod_customvars_serialize(temp_service->custom_variables, &dbuf);
2864 #endif
2865
2866 ndomod_enddata_serialize(&dbuf);
2867
2868 break;
2869
2870 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2871 case NEBCALLBACK_CONTACT_STATUS_DATA:
2872
2873 csdata=(nebstruct_contact_status_data *)data;
2874
2875 if((temp_contact=(contact *)csdata->object_ptr)==NULL){
2876 ndo_dbuf_free(&dbuf);
2877 return 0;
2878 }
2879
2880 es[0]=ndo_escape_buffer(temp_contact->name);
2881
2882 {
2883 struct ndo_broker_data contact_status_data[] = {
2884 { NDO_DATA_TYPE, BD_INT, { .integer = csdata->type }},
2885 { NDO_DATA_FLAGS, BD_INT, { .integer = csdata->flags }},
2886 { NDO_DATA_ATTRIBUTES, BD_INT,
2887 { .integer = csdata->attr }},
2888 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2889 { .timestamp = csdata->timestamp }},
2890 { NDO_DATA_CONTACTNAME, BD_STRING,
2891 { .string = (es[0]==NULL) ? "" : es[0] }},
2892 { NDO_DATA_HOSTNOTIFICATIONSENABLED, BD_INT,
2893 { .integer =
2894 temp_contact->host_notifications_enabled }},
2895 { NDO_DATA_SERVICENOTIFICATIONSENABLED, BD_INT,
2896 { .integer =
2897 temp_contact->service_notifications_enabled }},
2898 { NDO_DATA_LASTHOSTNOTIFICATION, BD_UNSIGNED_LONG,
2899 { .unsigned_long =
2900 (unsigned long)temp_contact->last_host_notification }},
2901 { NDO_DATA_LASTSERVICENOTIFICATION, BD_UNSIGNED_LONG,
2902 { .unsigned_long =
2903 (unsigned long)temp_contact->last_service_notification }},
2904 { NDO_DATA_MODIFIEDCONTACTATTRIBUTES, BD_UNSIGNED_LONG,
2905 { .unsigned_long = temp_contact->modified_attributes }},
2906 { NDO_DATA_MODIFIEDHOSTATTRIBUTES, BD_UNSIGNED_LONG,
2907 { .unsigned_long =
2908 temp_contact->modified_host_attributes }},
2909 { NDO_DATA_MODIFIEDSERVICEATTRIBUTES, BD_UNSIGNED_LONG,
2910 { .unsigned_long =
2911 temp_contact->modified_service_attributes }}
2912 };
2913
2914 ndomod_broker_data_serialize(&dbuf, NDO_API_CONTACTSTATUSDATA,
2915 contact_status_data, sizeof(contact_status_data) /
2916 sizeof(contact_status_data[ 0]), FALSE);
2917 }
2918
2919 /* dump customvars */
2920 ndomod_customvars_serialize(temp_contact->custom_variables, &dbuf);
2921
2922 ndomod_enddata_serialize(&dbuf);
2923
2924 break;
2925 #endif
2926
2927 case NEBCALLBACK_ADAPTIVE_PROGRAM_DATA:
2928
2929 apdata=(nebstruct_adaptive_program_data *)data;
2930
2931 es[0]=ndo_escape_buffer(global_host_event_handler);
2932 es[1]=ndo_escape_buffer(global_service_event_handler);
2933
2934 {
2935 struct ndo_broker_data adaptive_program_data[] = {
2936 { NDO_DATA_TYPE, BD_INT, { .integer = apdata->type }},
2937 { NDO_DATA_FLAGS, BD_INT, { .integer = apdata->flags }},
2938 { NDO_DATA_ATTRIBUTES, BD_INT,
2939 { .integer = apdata->attr }},
2940 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2941 { .timestamp = apdata->timestamp }},
2942 { NDO_DATA_COMMANDTYPE, BD_INT,
2943 { .integer = apdata->command_type }},
2944 { NDO_DATA_MODIFIEDHOSTATTRIBUTE, BD_UNSIGNED_LONG,
2945 { .unsigned_long = apdata->modified_host_attribute }},
2946 { NDO_DATA_MODIFIEDHOSTATTRIBUTES, BD_UNSIGNED_LONG,
2947 { .unsigned_long = apdata->modified_host_attributes }},
2948 { NDO_DATA_MODIFIEDSERVICEATTRIBUTE, BD_UNSIGNED_LONG,
2949 { .unsigned_long =
2950 apdata->modified_service_attribute }},
2951 { NDO_DATA_MODIFIEDSERVICEATTRIBUTES, BD_UNSIGNED_LONG,
2952 { .unsigned_long =
2953 apdata->modified_service_attributes }},
2954 { NDO_DATA_GLOBALHOSTEVENTHANDLER, BD_STRING,
2955 { .string = (es[0]==NULL) ? "" : es[0] }},
2956 { NDO_DATA_GLOBALSERVICEEVENTHANDLER, BD_STRING,
2957 { .string = (es[1]==NULL) ? "" : es[1] }},
2958 };
2959
2960 ndomod_broker_data_serialize(&dbuf, NDO_API_ADAPTIVEPROGRAMDATA,
2961 adaptive_program_data, sizeof(adaptive_program_data) /
2962 sizeof(adaptive_program_data[ 0]), TRUE);
2963 }
2964
2965 break;
2966
2967 case NEBCALLBACK_ADAPTIVE_HOST_DATA:
2968
2969 ahdata=(nebstruct_adaptive_host_data *)data;
2970
2971 if((temp_host=(host *)ahdata->object_ptr)==NULL){
2972 ndo_dbuf_free(&dbuf);
2973 return 0;
2974 }
2975
2976 #ifdef BUILD_NAGIOS_2X
2977 retry_interval=0.0;
2978 #endif
2979 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
2980 retry_interval=temp_host->retry_interval;
2981 #endif
2982
2983 es[0]=ndo_escape_buffer(temp_host->name);
2984 es[1]=ndo_escape_buffer(temp_host->event_handler);
2985 #ifdef BUILD_NAGIOS_4X
2986 es[2]=ndo_escape_buffer(temp_host->check_command);
2987 #else
2988 es[2]=ndo_escape_buffer(temp_host->host_check_command);
2989 #endif
2990
2991 {
2992 struct ndo_broker_data adaptive_host_data[] = {
2993 { NDO_DATA_TYPE, BD_INT, { .integer = ahdata->type }},
2994 { NDO_DATA_FLAGS, BD_INT, { .integer = ahdata->flags }},
2995 { NDO_DATA_ATTRIBUTES, BD_INT,
2996 { .integer = ahdata->attr }},
2997 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
2998 { .timestamp = ahdata->timestamp }},
2999 { NDO_DATA_COMMANDTYPE, BD_INT,
3000 { .integer = ahdata->command_type }},
3001 { NDO_DATA_MODIFIEDHOSTATTRIBUTE, BD_UNSIGNED_LONG,
3002 { .unsigned_long = ahdata->modified_attribute }},
3003 { NDO_DATA_MODIFIEDHOSTATTRIBUTES, BD_UNSIGNED_LONG,
3004 { .unsigned_long = ahdata->modified_attributes }},
3005 { NDO_DATA_HOST, BD_STRING,
3006 { .string = (es[0]==NULL) ? "" : es[0] }},
3007 { NDO_DATA_EVENTHANDLER, BD_STRING,
3008 { .string = (es[1]==NULL) ? "" : es[1] }},
3009 { NDO_DATA_CHECKCOMMAND, BD_STRING,
3010 { .string = (es[2]==NULL) ? "" : es[2] }},
3011 { NDO_DATA_NORMALCHECKINTERVAL, BD_FLOAT,
3012 { .floating_point = temp_host->check_interval }},
3013 { NDO_DATA_RETRYCHECKINTERVAL, BD_FLOAT,
3014 { .floating_point = retry_interval }},
3015 { NDO_DATA_MAXCHECKATTEMPTS, BD_INT,
3016 { .integer = temp_host->max_attempts }},
3017 };
3018
3019 ndomod_broker_data_serialize(&dbuf, NDO_API_ADAPTIVEHOSTDATA,
3020 adaptive_host_data,
3021 sizeof(adaptive_host_data) / sizeof(adaptive_host_data[ 0]),
3022 TRUE);
3023 }
3024
3025 break;
3026
3027 case NEBCALLBACK_ADAPTIVE_SERVICE_DATA:
3028
3029 asdata=(nebstruct_adaptive_service_data *)data;
3030
3031 if((temp_service=(service *)asdata->object_ptr)==NULL){
3032 ndo_dbuf_free(&dbuf);
3033 return 0;
3034 }
3035
3036 es[0]=ndo_escape_buffer(temp_service->host_name);
3037 es[1]=ndo_escape_buffer(temp_service->description);
3038 es[2]=ndo_escape_buffer(temp_service->event_handler);
3039 #ifdef BUILD_NAGIOS_4X
3040 es[3]=ndo_escape_buffer(temp_service->check_command);
3041 #else
3042 es[3]=ndo_escape_buffer(temp_service->service_check_command);
3043 #endif
3044
3045 {
3046 struct ndo_broker_data adaptive_service_data[] = {
3047 { NDO_DATA_TYPE, BD_INT, { .integer = asdata->type }},
3048 { NDO_DATA_FLAGS, BD_INT, { .integer = asdata->flags }},
3049 { NDO_DATA_ATTRIBUTES, BD_INT,
3050 { .integer = asdata->attr }},
3051 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3052 { .timestamp = asdata->timestamp }},
3053 { NDO_DATA_COMMANDTYPE, BD_INT,
3054 { .integer = asdata->command_type }},
3055 { NDO_DATA_MODIFIEDSERVICEATTRIBUTE, BD_UNSIGNED_LONG,
3056 { .unsigned_long = asdata->modified_attribute }},
3057 { NDO_DATA_MODIFIEDSERVICEATTRIBUTES, BD_UNSIGNED_LONG,
3058 { .unsigned_long = asdata->modified_attributes }},
3059 { NDO_DATA_HOST, BD_STRING,
3060 { .string = (es[0]==NULL) ? "" : es[0] }},
3061 { NDO_DATA_SERVICE, BD_STRING,
3062 { .string = (es[1]==NULL) ? "" : es[1] }},
3063 { NDO_DATA_EVENTHANDLER, BD_STRING,
3064 { .string = (es[2]==NULL) ? "" : es[2] }},
3065 { NDO_DATA_CHECKCOMMAND, BD_STRING,
3066 { .string = (es[3]==NULL) ? "" : es[3] }},
3067 { NDO_DATA_NORMALCHECKINTERVAL, BD_FLOAT,
3068 { .floating_point =
3069 (double)temp_service->check_interval }},
3070 { NDO_DATA_RETRYCHECKINTERVAL, BD_FLOAT,
3071 { .floating_point =
3072 (double)temp_service->retry_interval }},
3073 { NDO_DATA_MAXCHECKATTEMPTS, BD_INT,
3074 { .integer = temp_service->max_attempts }},
3075 };
3076
3077 ndomod_broker_data_serialize(&dbuf, NDO_API_ADAPTIVESERVICEDATA,
3078 adaptive_service_data, sizeof(adaptive_service_data) /
3079 sizeof(adaptive_service_data[ 0]), TRUE);
3080 }
3081
3082 break;
3083
3084 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
3085 case NEBCALLBACK_ADAPTIVE_CONTACT_DATA:
3086
3087 acdata=(nebstruct_adaptive_contact_data *)data;
3088
3089 if((temp_contact=(contact *)acdata->object_ptr)==NULL){
3090 ndo_dbuf_free(&dbuf);
3091 return 0;
3092 }
3093
3094 es[0]=ndo_escape_buffer(temp_contact->name);
3095
3096 {
3097 struct ndo_broker_data adaptive_contact_data[] = {
3098 { NDO_DATA_TYPE, BD_INT, { .integer = acdata->type }},
3099 { NDO_DATA_FLAGS, BD_INT, { .integer = acdata->flags }},
3100 { NDO_DATA_ATTRIBUTES, BD_INT,
3101 { .integer = acdata->attr }},
3102 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3103 { .timestamp = acdata->timestamp }},
3104 { NDO_DATA_COMMANDTYPE, BD_INT,
3105 { .integer = acdata->command_type }},
3106 { NDO_DATA_MODIFIEDCONTACTATTRIBUTE, BD_UNSIGNED_LONG,
3107 { .unsigned_long = acdata->modified_attribute }},
3108 { NDO_DATA_MODIFIEDCONTACTATTRIBUTES, BD_UNSIGNED_LONG,
3109 { .unsigned_long = acdata->modified_attributes }},
3110 { NDO_DATA_MODIFIEDHOSTATTRIBUTE, BD_UNSIGNED_LONG,
3111 { .unsigned_long = acdata->modified_host_attribute }},
3112 { NDO_DATA_MODIFIEDHOSTATTRIBUTES, BD_UNSIGNED_LONG,
3113 { .unsigned_long = acdata->modified_host_attributes }},
3114 { NDO_DATA_MODIFIEDSERVICEATTRIBUTE, BD_UNSIGNED_LONG,
3115 { .unsigned_long =
3116 acdata->modified_service_attribute }},
3117 { NDO_DATA_MODIFIEDSERVICEATTRIBUTES, BD_UNSIGNED_LONG,
3118 { .unsigned_long =
3119 acdata->modified_service_attributes }},
3120 { NDO_DATA_CONTACTNAME, BD_STRING,
3121 { .string = (es[0]==NULL) ? "" : es[0] }},
3122 { NDO_DATA_HOSTNOTIFICATIONSENABLED, BD_INT,
3123 { .integer =
3124 temp_contact->host_notifications_enabled }},
3125 { NDO_DATA_SERVICENOTIFICATIONSENABLED, BD_INT,
3126 { .integer =
3127 temp_contact->service_notifications_enabled }},
3128 };
3129
3130 ndomod_broker_data_serialize(&dbuf, NDO_API_ADAPTIVECONTACTDATA,
3131 adaptive_contact_data, sizeof(adaptive_contact_data) /
3132 sizeof(adaptive_contact_data[ 0]), TRUE);
3133 }
3134
3135 break;
3136 #endif
3137
3138 case NEBCALLBACK_EXTERNAL_COMMAND_DATA:
3139
3140 ecdata=(nebstruct_external_command_data *)data;
3141
3142 es[0]=ndo_escape_buffer(ecdata->command_string);
3143 es[1]=ndo_escape_buffer(ecdata->command_args);
3144
3145 {
3146 struct ndo_broker_data external_command_data[] = {
3147 { NDO_DATA_TYPE, BD_INT, { .integer = ecdata->type }},
3148 { NDO_DATA_FLAGS, BD_INT, { .integer = ecdata->flags }},
3149 { NDO_DATA_ATTRIBUTES, BD_INT,
3150 { .integer = ecdata->attr }},
3151 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3152 { .timestamp = ecdata->timestamp }},
3153 { NDO_DATA_COMMANDTYPE, BD_INT,
3154 { .integer = ecdata->command_type }},
3155 { NDO_DATA_ENTRYTIME, BD_UNSIGNED_LONG,
3156 { .unsigned_long = (unsigned long)ecdata->entry_time }},
3157 { NDO_DATA_COMMANDSTRING, BD_STRING,
3158 { .string = (es[0]==NULL) ? "" : es[0] }},
3159 { NDO_DATA_COMMANDARGS, BD_STRING,
3160 { .string = (es[1]==NULL) ? "" : es[1] }},
3161 };
3162
3163 ndomod_broker_data_serialize(&dbuf, NDO_API_EXTERNALCOMMANDDATA,
3164 external_command_data, sizeof(external_command_data) /
3165 sizeof(external_command_data[ 0]), TRUE);
3166 }
3167
3168 break;
3169
3170 case NEBCALLBACK_AGGREGATED_STATUS_DATA:
3171
3172 agsdata=(nebstruct_aggregated_status_data *)data;
3173
3174 {
3175 struct ndo_broker_data aggregated_status_data[] = {
3176 { NDO_DATA_TYPE, BD_INT, { .integer = agsdata->type }},
3177 { NDO_DATA_FLAGS, BD_INT, { .integer = agsdata->flags }},
3178 { NDO_DATA_ATTRIBUTES, BD_INT,
3179 { .integer = agsdata->attr }},
3180 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3181 { .timestamp = agsdata->timestamp }},
3182 };
3183
3184 ndomod_broker_data_serialize(&dbuf, NDO_API_AGGREGATEDSTATUSDATA,
3185 aggregated_status_data, sizeof(aggregated_status_data) /
3186 sizeof(aggregated_status_data[ 0]), TRUE);
3187 }
3188
3189 break;
3190
3191 case NEBCALLBACK_RETENTION_DATA:
3192
3193 rdata=(nebstruct_retention_data *)data;
3194
3195 {
3196 struct ndo_broker_data retention_data[] = {
3197 { NDO_DATA_TYPE, BD_INT, { .integer = rdata->type }},
3198 { NDO_DATA_FLAGS, BD_INT, { .integer = rdata->flags }},
3199 { NDO_DATA_ATTRIBUTES, BD_INT,
3200 { .integer = rdata->attr }},
3201 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3202 { .timestamp = rdata->timestamp }},
3203 };
3204
3205 ndomod_broker_data_serialize(&dbuf, NDO_API_RETENTIONDATA,
3206 retention_data,
3207 sizeof(retention_data) / sizeof(retention_data[ 0]), TRUE);
3208 }
3209
3210 break;
3211
3212 case NEBCALLBACK_CONTACT_NOTIFICATION_DATA:
3213
3214 cnotdata=(nebstruct_contact_notification_data *)data;
3215
3216 es[0]=ndo_escape_buffer(cnotdata->host_name);
3217 es[1]=ndo_escape_buffer(cnotdata->service_description);
3218 es[2]=ndo_escape_buffer(cnotdata->output);
3219 /* Preparing long output for the future */
3220 es[3]=ndo_escape_buffer(cnotdata->output);
3221 /* Preparing for long_output in the future */
3222 es[4]=ndo_escape_buffer(cnotdata->output);
3223 es[5]=ndo_escape_buffer(cnotdata->ack_author);
3224 es[6]=ndo_escape_buffer(cnotdata->ack_data);
3225 es[7]=ndo_escape_buffer(cnotdata->contact_name);
3226
3227 {
3228 struct ndo_broker_data contact_notification_data[] = {
3229 { NDO_DATA_TYPE, BD_INT, { .integer = cnotdata->type }},
3230 { NDO_DATA_FLAGS, BD_INT, { .integer = cnotdata->flags }},
3231 { NDO_DATA_ATTRIBUTES, BD_INT,
3232 { .integer = cnotdata->attr }},
3233 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3234 { .timestamp = cnotdata->timestamp }},
3235 { NDO_DATA_NOTIFICATIONTYPE, BD_INT,
3236 { .integer = cnotdata->notification_type }},
3237 { NDO_DATA_STARTTIME, BD_TIMEVAL,
3238 { .timestamp = cnotdata->start_time }},
3239 { NDO_DATA_ENDTIME, BD_TIMEVAL,
3240 { .timestamp = cnotdata->end_time }},
3241 { NDO_DATA_HOST, BD_STRING,
3242 { .string = (es[0]==NULL) ? "" : es[0] }},
3243 { NDO_DATA_SERVICE, BD_STRING,
3244 { .string = (es[1]==NULL) ? "" : es[1] }},
3245 { NDO_DATA_CONTACTNAME, BD_STRING,
3246 { .string = (es[7]==NULL) ? "" : es[7] }},
3247 { NDO_DATA_NOTIFICATIONREASON, BD_INT,
3248 { .integer = cnotdata->reason_type }},
3249 { NDO_DATA_STATE, BD_INT, { .integer = cnotdata->state }},
3250 { NDO_DATA_OUTPUT, BD_STRING,
3251 { .string = (es[2]==NULL) ? "" : es[2] }},
3252 { NDO_DATA_LONGOUTPUT, BD_STRING,
3253 { .string = (es[3]==NULL) ? "" : es[3] }},
3254 { NDO_DATA_OUTPUT, BD_STRING,
3255 { .string = (es[4]==NULL) ? "" : es[4] }},
3256 { NDO_DATA_ACKAUTHOR, BD_STRING,
3257 { .string = (es[5]==NULL) ? "" : es[5] }},
3258 { NDO_DATA_ACKDATA, BD_STRING,
3259 { .string = (es[6]==NULL) ? "" : es[6] }},
3260 };
3261
3262 ndomod_broker_data_serialize(&dbuf,
3263 NDO_API_CONTACTNOTIFICATIONDATA, contact_notification_data,
3264 sizeof(contact_notification_data) /
3265 sizeof(contact_notification_data[ 0]), TRUE);
3266 }
3267
3268 break;
3269
3270 case NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA:
3271
3272 cnotmdata=(nebstruct_contact_notification_method_data *)data;
3273
3274 es[0]=ndo_escape_buffer(cnotmdata->host_name);
3275 es[1]=ndo_escape_buffer(cnotmdata->service_description);
3276 es[2]=ndo_escape_buffer(cnotmdata->output);
3277 es[3]=ndo_escape_buffer(cnotmdata->ack_author);
3278 es[4]=ndo_escape_buffer(cnotmdata->ack_data);
3279 es[5]=ndo_escape_buffer(cnotmdata->contact_name);
3280 es[6]=ndo_escape_buffer(cnotmdata->command_name);
3281 es[7]=ndo_escape_buffer(cnotmdata->command_args);
3282
3283 {
3284 struct ndo_broker_data contact_notification_method_data[] = {
3285 { NDO_DATA_TYPE, BD_INT, { .integer = cnotmdata->type }},
3286 { NDO_DATA_FLAGS, BD_INT, { .integer = cnotmdata->flags }},
3287 { NDO_DATA_ATTRIBUTES, BD_INT,
3288 { .integer = cnotmdata->attr }},
3289 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3290 { .timestamp = cnotmdata->timestamp }},
3291 { NDO_DATA_NOTIFICATIONTYPE, BD_INT,
3292 { .integer = cnotmdata->notification_type }},
3293 { NDO_DATA_STARTTIME, BD_TIMEVAL,
3294 { .timestamp = cnotmdata->start_time }},
3295 { NDO_DATA_ENDTIME, BD_TIMEVAL,
3296 { .timestamp = cnotmdata->end_time }},
3297 { NDO_DATA_HOST, BD_STRING,
3298 { .string = (es[0]==NULL) ? "" : es[0] }},
3299 { NDO_DATA_SERVICE, BD_STRING,
3300 { .string = (es[1]==NULL) ? "" : es[1] }},
3301 { NDO_DATA_CONTACTNAME, BD_STRING,
3302 { .string = (es[5]==NULL) ? "" : es[5] }},
3303 { NDO_DATA_COMMANDNAME, BD_STRING,
3304 { .string = (es[6]==NULL) ? "" : es[6] }},
3305 { NDO_DATA_COMMANDARGS, BD_STRING,
3306 { .string = (es[7]==NULL) ? "" : es[7] }},
3307 { NDO_DATA_NOTIFICATIONREASON, BD_INT,
3308 { .integer = cnotmdata->reason_type }},
3309 { NDO_DATA_STATE, BD_INT, { .integer = cnotmdata->state }},
3310 { NDO_DATA_OUTPUT, BD_STRING,
3311 { .string = (es[2]==NULL) ? "" : es[2] }},
3312 { NDO_DATA_ACKAUTHOR, BD_STRING,
3313 { .string = (es[3]==NULL) ? "" : es[3] }},
3314 { NDO_DATA_ACKDATA, BD_STRING,
3315 { .string = (es[4]==NULL) ? "" : es[4] }},
3316 };
3317
3318 ndomod_broker_data_serialize(&dbuf,
3319 NDO_API_CONTACTNOTIFICATIONMETHODDATA,
3320 contact_notification_method_data,
3321 sizeof(contact_notification_method_data) /
3322 sizeof(contact_notification_method_data[ 0]), TRUE);
3323 }
3324
3325 break;
3326
3327 case NEBCALLBACK_ACKNOWLEDGEMENT_DATA:
3328
3329 ackdata=(nebstruct_acknowledgement_data *)data;
3330
3331 es[0]=ndo_escape_buffer(ackdata->host_name);
3332 es[1]=ndo_escape_buffer(ackdata->service_description);
3333 es[2]=ndo_escape_buffer(ackdata->author_name);
3334 es[3]=ndo_escape_buffer(ackdata->comment_data);
3335
3336 {
3337 struct ndo_broker_data acknowledgement_data[] = {
3338 { NDO_DATA_TYPE, BD_INT, { .integer = ackdata->type }},
3339 { NDO_DATA_FLAGS, BD_INT, { .integer = ackdata->flags }},
3340 { NDO_DATA_ATTRIBUTES, BD_INT,
3341 { .integer = ackdata->attr }},
3342 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3343 { .timestamp = ackdata->timestamp }},
3344 { NDO_DATA_ACKNOWLEDGEMENTTYPE, BD_INT,
3345 { .integer = ackdata->acknowledgement_type }},
3346 { NDO_DATA_HOST, BD_STRING,
3347 { .string = (es[0]==NULL) ? "" : es[0] }},
3348 { NDO_DATA_SERVICE, BD_STRING,
3349 { .string = (es[1]==NULL) ? "" : es[1] }},
3350 { NDO_DATA_AUTHORNAME, BD_STRING,
3351 { .string = (es[2]==NULL) ? "" : es[2] }},
3352 { NDO_DATA_COMMENT, BD_STRING,
3353 { .string = (es[3]==NULL) ? "" : es[3] }},
3354 { NDO_DATA_STATE, BD_INT, { .integer = ackdata->state }},
3355 { NDO_DATA_STICKY, BD_INT, { .integer = ackdata->is_sticky }},
3356 { NDO_DATA_PERSISTENT, BD_INT,
3357 { .integer = ackdata->persistent_comment }},
3358 { NDO_DATA_NOTIFYCONTACTS, BD_INT,
3359 { .integer = ackdata->notify_contacts }},
3360 };
3361
3362 ndomod_broker_data_serialize(&dbuf, NDO_API_ACKNOWLEDGEMENTDATA,
3363 acknowledgement_data, sizeof(acknowledgement_data) /
3364 sizeof(acknowledgement_data[ 0]), TRUE);
3365 }
3366
3367 break;
3368
3369 case NEBCALLBACK_STATE_CHANGE_DATA:
3370
3371 schangedata=(nebstruct_statechange_data *)data;
3372
3373 #ifdef BUILD_NAGIOS_2X
3374 /* find host/service and get last state info */
3375 if(schangedata->service_description==NULL){
3376 if((temp_host=find_host(schangedata->host_name))==NULL){
3377 ndo_dbuf_free(&dbuf);
3378 return 0;
3379 }
3380 }
3381 else{
3382 if((temp_service=find_service(schangedata->host_name,schangedata->service_description))==NULL){
3383 ndo_dbuf_free(&dbuf);
3384 return 0;
3385 }
3386 last_state=temp_service->last_state;
3387 last_hard_state=temp_service->last_hard_state;
3388 }
3389 #else
3390 /* get the last state info */
3391 if(schangedata->service_description==NULL){
3392 if((temp_host=(host *)schangedata->object_ptr)==NULL){
3393 ndo_dbuf_free(&dbuf);
3394 return 0;
3395 }
3396 last_state=temp_host->last_state;
3397 last_state=temp_host->last_hard_state;
3398 }
3399 else{
3400 if((temp_service=(service *)schangedata->object_ptr)==NULL){
3401 ndo_dbuf_free(&dbuf);
3402 return 0;
3403 }
3404 last_state=temp_service->last_state;
3405 last_hard_state=temp_service->last_hard_state;
3406 }
3407 #endif
3408
3409 es[0]=ndo_escape_buffer(schangedata->host_name);
3410 es[1]=ndo_escape_buffer(schangedata->service_description);
3411 es[2]=ndo_escape_buffer(schangedata->output);
3412 #ifdef BUILD_NAGIOS_4X
3413 if (CURRENT_OBJECT_STRUCTURE_VERSION >= 403 && has_ver403_long_output)
3414 es[3]=ndo_escape_buffer(schangedata->longoutput);
3415 else
3416 es[3]=ndo_escape_buffer(schangedata->output);
3417 #else
3418 es[3]=ndo_escape_buffer(schangedata->output);
3419 #endif
3420
3421 {
3422 struct ndo_broker_data state_change_data[] = {
3423 { NDO_DATA_TYPE, BD_INT, { .integer = schangedata->type }},
3424 { NDO_DATA_FLAGS, BD_INT, { .integer = schangedata->flags }},
3425 { NDO_DATA_ATTRIBUTES, BD_INT,
3426 { .integer = schangedata->attr }},
3427 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3428 { .timestamp = schangedata->timestamp }},
3429 { NDO_DATA_STATECHANGETYPE, BD_INT,
3430 { .integer = schangedata->statechange_type }},
3431 { NDO_DATA_HOST, BD_STRING,
3432 { .string = (es[0]==NULL) ? "" : es[0] }},
3433 { NDO_DATA_SERVICE, BD_STRING,
3434 { .string = (es[1]==NULL) ? "" : es[1] }},
3435 { NDO_DATA_STATECHANGE, BD_INT, { .integer = TRUE }},
3436 { NDO_DATA_STATE, BD_INT, { .integer = schangedata->state }},
3437 { NDO_DATA_STATETYPE, BD_INT,
3438 { .integer = schangedata->state_type }},
3439 { NDO_DATA_CURRENTCHECKATTEMPT, BD_INT,
3440 { .integer = schangedata->current_attempt }},
3441 { NDO_DATA_MAXCHECKATTEMPTS, BD_INT,
3442 { .integer = schangedata->max_attempts }},
3443 { NDO_DATA_LASTSTATE, BD_INT, { .integer = last_state }},
3444 { NDO_DATA_LASTHARDSTATE, BD_INT,
3445 { .integer = last_hard_state }},
3446 { NDO_DATA_OUTPUT, BD_STRING,
3447 { .string = (es[2]==NULL) ? "" : es[2] }},
3448 { NDO_DATA_LONGOUTPUT, BD_STRING,
3449 { .string = (es[3]==NULL) ? "" : es[3] }},
3450 };
3451
3452 ndomod_broker_data_serialize(&dbuf, NDO_API_STATECHANGEDATA,
3453 state_change_data,
3454 sizeof(state_change_data) / sizeof(state_change_data[ 0]),
3455 TRUE);
3456 }
3457
3458 break;
3459
3460 default:
3461 ndo_dbuf_free(&dbuf);
3462 return 0;
3463 break;
3464 }
3465
3466 /* free escaped buffers */
3467 for(x=0;x<8;x++){
3468 free(es[x]);
3469 es[x]=NULL;
3470 }
3471
3472 /* write data to sink */
3473 if(write_to_sink==NDO_TRUE)
3474 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3475
3476 /* free dynamic buffer */
3477 ndo_dbuf_free(&dbuf);
3478
3479
3480
3481 /* POST PROCESSING... */
3482
3483 switch(event_type){
3484
3485 case NEBCALLBACK_PROCESS_DATA:
3486
3487 procdata=(nebstruct_process_data *)data;
3488
3489 /* process has passed pre-launch config verification, so dump original config */
3490 if(procdata->type==NEBTYPE_PROCESS_START){
3491 ndomod_write_config_files();
3492 ndomod_write_config(NDOMOD_CONFIG_DUMP_ORIGINAL);
3493 }
3494
3495 /* process is starting the event loop, so dump runtime vars */
3496 if(procdata->type==NEBTYPE_PROCESS_EVENTLOOPSTART){
3497 ndomod_write_runtime_variables();
3498 }
3499
3500 break;
3501
3502 case NEBCALLBACK_RETENTION_DATA:
3503
3504 rdata=(nebstruct_retention_data *)data;
3505
3506 /* retained config was just read, so dump it */
3507 if(rdata->type==NEBTYPE_RETENTIONDATA_ENDLOAD)
3508 ndomod_write_config(NDOMOD_CONFIG_DUMP_RETAINED);
3509
3510 break;
3511
3512 default:
3513 break;
3514 }
3515
3516 return 0;
3517 }
3518
3519
3520
3521 /****************************************************************************/
3522 /* CONFIG OUTPUT FUNCTIONS */
3523 /****************************************************************************/
3524
3525 /* dumps all configuration data to sink */
ndomod_write_config(int config_type)3526 int ndomod_write_config(int config_type){
3527 char temp_buffer[NDOMOD_MAX_BUFLEN];
3528 struct timeval now;
3529 int result;
3530
3531 if(!(ndomod_config_output_options & config_type))
3532 return NDO_OK;
3533
3534 gettimeofday(&now,NULL);
3535
3536 /* record start of config dump */
3537 snprintf(temp_buffer,sizeof(temp_buffer)-1
3538 ,"\n\n%d:\n%d=%s\n%d=%ld.%06ld\n%d\n\n"
3539 ,NDO_API_STARTCONFIGDUMP
3540 ,NDO_DATA_CONFIGDUMPTYPE
3541 ,(config_type==NDOMOD_CONFIG_DUMP_ORIGINAL)?NDO_API_CONFIGDUMP_ORIGINAL:NDO_API_CONFIGDUMP_RETAINED
3542 ,NDO_DATA_TIMESTAMP
3543 ,now.tv_sec
3544 ,now.tv_usec
3545 ,NDO_API_ENDDATA
3546 );
3547 temp_buffer[sizeof(temp_buffer)-1]='\x0';
3548 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
3549
3550 /* ndomod_write_active_objects(); */
3551
3552 /* dump object config info */
3553 result=ndomod_write_object_config(config_type);
3554 if(result!=NDO_OK)
3555 return result;
3556
3557 /* record end of config dump */
3558 snprintf(temp_buffer,sizeof(temp_buffer)-1
3559 ,"\n\n%d:\n%d=%ld.%06ld\n%d\n\n"
3560 ,NDO_API_ENDCONFIGDUMP
3561 ,NDO_DATA_TIMESTAMP
3562 ,now.tv_sec
3563 ,now.tv_usec
3564 ,NDO_API_ENDDATA
3565 );
3566 temp_buffer[sizeof(temp_buffer)-1]='\x0';
3567 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
3568
3569 return result;
3570 }
3571
3572
3573 /*************************************************************
3574 * Get a list of all active objects, so the "is_active" flag *
3575 * can be set on them in batches, instead of one at a time. *
3576 *************************************************************/
ndomod_write_active_objects()3577 void ndomod_write_active_objects()
3578 {
3579 command *temp_command;
3580 timeperiod *temp_timeperiod;
3581 contact *temp_contact;
3582 contactgroup *temp_contactgroup;
3583 host *temp_host;
3584 hostgroup *temp_hostgroup;
3585 service *temp_service;
3586 servicegroup *temp_servicegroup;
3587 ndo_dbuf dbuf;
3588 struct ndo_broker_data active_objects[256];
3589 struct timeval now;
3590 int i, obj_count;
3591 char *name1, *name2;
3592
3593 gettimeofday(&now,NULL); /* get current time */
3594 ndo_dbuf_init(&dbuf, 2048); /* initialize dynamic buffer (2KB chunk size) */
3595
3596
3597 active_objects[0].key = NDO_DATA_ACTIVEOBJECTSTYPE;
3598 active_objects[0].datatype = BD_INT;
3599
3600 active_objects[0].value.integer = NDO_API_COMMANDDEFINITION;
3601 obj_count = 1;
3602 for (temp_command = command_list; temp_command != NULL; temp_command = temp_command->next) {
3603 name1 = ndo_escape_buffer(temp_command->name);
3604 active_objects[obj_count].key = obj_count;
3605 active_objects[obj_count].datatype = BD_STRING;
3606 active_objects[obj_count].value.string = (name1 == NULL) ? "" : name1;
3607 if (++obj_count > 250) {
3608 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3609 active_objects, obj_count, TRUE);
3610 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3611 ndo_dbuf_free(&dbuf);
3612 while (--obj_count)
3613 free(active_objects[obj_count].value.string);
3614 obj_count = 1;
3615 }
3616 }
3617 if (obj_count > 1) {
3618 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3619 active_objects, obj_count, TRUE);
3620 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3621 ndo_dbuf_free(&dbuf);
3622 while (--obj_count)
3623 free(active_objects[obj_count].value.string);
3624 }
3625
3626
3627 active_objects[0].value.integer = NDO_API_TIMEPERIODDEFINITION;
3628 obj_count = 1;
3629 for (temp_timeperiod = timeperiod_list; temp_timeperiod != NULL; temp_timeperiod = temp_timeperiod->next) {
3630 name1 = ndo_escape_buffer(temp_timeperiod->name);
3631 active_objects[obj_count].key = obj_count;
3632 active_objects[obj_count].datatype = BD_STRING;
3633 active_objects[obj_count].value.string = (name1 == NULL) ? "" : name1;
3634 if (++obj_count > 250) {
3635 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3636 active_objects, obj_count, TRUE);
3637 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3638 ndo_dbuf_free(&dbuf);
3639 while (--obj_count)
3640 free(active_objects[obj_count].value.string);
3641 obj_count = 1;
3642 }
3643 }
3644 if (obj_count > 1) {
3645 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3646 active_objects, obj_count, TRUE);
3647 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3648 ndo_dbuf_free(&dbuf);
3649 while (--obj_count)
3650 free(active_objects[obj_count].value.string);
3651 }
3652
3653
3654 active_objects[0].value.integer = NDO_API_CONTACTDEFINITION;
3655 obj_count = 1;
3656 for (temp_contact = contact_list; temp_contact != NULL; temp_contact = temp_contact->next) {
3657 name1 = ndo_escape_buffer(temp_contact->name);
3658 active_objects[obj_count].key = obj_count;
3659 active_objects[obj_count].datatype = BD_STRING;
3660 active_objects[obj_count].value.string = (name1 == NULL) ? "" : name1;
3661 if (++obj_count > 250) {
3662 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3663 active_objects, obj_count, TRUE);
3664 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3665 ndo_dbuf_free(&dbuf);
3666 while (--obj_count)
3667 free(active_objects[obj_count].value.string);
3668 obj_count = 1;
3669 }
3670 }
3671 if (obj_count > 1) {
3672 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3673 active_objects, obj_count, TRUE);
3674 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3675 ndo_dbuf_free(&dbuf);
3676 while (--obj_count)
3677 free(active_objects[obj_count].value.string);
3678 }
3679
3680
3681 active_objects[0].value.integer = NDO_API_CONTACTGROUPDEFINITION;
3682 obj_count = 1;
3683 for (temp_contactgroup = contactgroup_list; temp_contactgroup != NULL; temp_contactgroup = temp_contactgroup->next) {
3684 name1 = ndo_escape_buffer(temp_contactgroup->group_name);
3685 active_objects[obj_count].key = obj_count;
3686 active_objects[obj_count].datatype = BD_STRING;
3687 active_objects[obj_count].value.string = (name1 == NULL) ? "" : name1;
3688 if (++obj_count > 250) {
3689 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3690 active_objects, obj_count, TRUE);
3691 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3692 ndo_dbuf_free(&dbuf);
3693 while (--obj_count)
3694 free(active_objects[obj_count].value.string);
3695 obj_count = 1;
3696 }
3697 }
3698 if (obj_count > 1) {
3699 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3700 active_objects, obj_count, TRUE);
3701 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3702 ndo_dbuf_free(&dbuf);
3703 while (--obj_count)
3704 free(active_objects[obj_count].value.string);
3705 }
3706
3707
3708 active_objects[0].value.integer = NDO_API_HOSTDEFINITION;
3709 obj_count = 1;
3710 for (temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
3711 name1 = ndo_escape_buffer(temp_host->name);
3712 active_objects[obj_count].key = obj_count;
3713 active_objects[obj_count].datatype = BD_STRING;
3714 active_objects[obj_count].value.string = (name1 == NULL) ? "" : name1;
3715 if (++obj_count > 250) {
3716 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3717 active_objects, obj_count, TRUE);
3718 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3719 ndo_dbuf_free(&dbuf);
3720 while (--obj_count)
3721 free(active_objects[obj_count].value.string);
3722 obj_count = 1;
3723 }
3724 }
3725 if (obj_count > 1) {
3726 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3727 active_objects, obj_count, TRUE);
3728 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3729 ndo_dbuf_free(&dbuf);
3730 while (--obj_count)
3731 free(active_objects[obj_count].value.string);
3732 }
3733
3734
3735 active_objects[0].value.integer = NDO_API_HOSTGROUPDEFINITION;
3736 obj_count = 1;
3737 for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
3738 name1 = ndo_escape_buffer(temp_hostgroup->group_name);
3739 active_objects[obj_count].key = obj_count;
3740 active_objects[obj_count].datatype = BD_STRING;
3741 active_objects[obj_count].value.string = (name1 == NULL) ? "" : name1;
3742 if (++obj_count > 250) {
3743 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3744 active_objects, obj_count, TRUE);
3745 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3746 ndo_dbuf_free(&dbuf);
3747 while (--obj_count)
3748 free(active_objects[obj_count].value.string);
3749 obj_count = 1;
3750 }
3751 }
3752 if (obj_count > 1) {
3753 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3754 active_objects, obj_count, TRUE);
3755 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3756 ndo_dbuf_free(&dbuf);
3757 while (--obj_count)
3758 free(active_objects[obj_count].value.string);
3759 }
3760
3761
3762 active_objects[0].value.integer = NDO_API_SERVICEDEFINITION;
3763 obj_count = 1;
3764 for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
3765 name1 = ndo_escape_buffer(temp_service->host_name);
3766 name2 = ndo_escape_buffer(temp_service->description);
3767 active_objects[obj_count].key = obj_count;
3768 active_objects[obj_count].datatype = BD_STRING;
3769 active_objects[obj_count].value.string = (name1 == NULL) ? "" : name1;
3770 ++obj_count;
3771 active_objects[obj_count].key = obj_count;
3772 active_objects[obj_count].datatype = BD_STRING;
3773 active_objects[obj_count].value.string = (name2 == NULL) ? "" : name2;
3774 if (++obj_count > 250) {
3775 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3776 active_objects, obj_count, TRUE);
3777 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3778 ndo_dbuf_free(&dbuf);
3779 while (--obj_count)
3780 free(active_objects[obj_count].value.string);
3781 obj_count = 1;
3782 }
3783 }
3784 if (obj_count > 1) {
3785 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3786 active_objects, obj_count, TRUE);
3787 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3788 ndo_dbuf_free(&dbuf);
3789 while (--obj_count)
3790 free(active_objects[obj_count].value.string);
3791 }
3792
3793
3794 active_objects[0].value.integer = NDO_API_SERVICEGROUPDEFINITION;
3795 obj_count = 1;
3796 for (temp_servicegroup = servicegroup_list; temp_servicegroup !=NULL ; temp_servicegroup = temp_servicegroup->next) {
3797 name1 = ndo_escape_buffer(temp_servicegroup->group_name);
3798 active_objects[obj_count].key = obj_count;
3799 active_objects[obj_count].datatype = BD_STRING;
3800 active_objects[obj_count].value.string = (name1 == NULL) ? "" : name1;
3801 if (++obj_count > 250) {
3802 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3803 active_objects, obj_count, TRUE);
3804 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3805 ndo_dbuf_free(&dbuf);
3806 while (--obj_count)
3807 free(active_objects[obj_count].value.string);
3808 obj_count = 1;
3809 }
3810 }
3811 if (obj_count > 1) {
3812 ndomod_broker_data_serialize(&dbuf, NDO_API_ACTIVEOBJECTSLIST,
3813 active_objects, obj_count, TRUE);
3814 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3815 ndo_dbuf_free(&dbuf);
3816 while (--obj_count)
3817 free(active_objects[obj_count].value.string);
3818 }
3819 }
3820
3821
ndomod_free_esc_buffers(char ** ary,int num)3822 static inline void ndomod_free_esc_buffers(char **ary, int num) {
3823 int i = (num < 0 ? 0 : num);
3824 while (i--) {
3825 free(ary[i]);
3826 ary[i] = NULL;
3827 }
3828 }
3829
3830 #define OBJECTCONFIG_ES_ITEMS 16
3831
3832 /* dumps object configuration data to sink */
ndomod_write_object_config(int config_type)3833 int ndomod_write_object_config(int config_type){
3834 char temp_buffer[NDOMOD_MAX_BUFLEN];
3835 ndo_dbuf dbuf;
3836 struct timeval now;
3837 int x=0;
3838 char *es[OBJECTCONFIG_ES_ITEMS];
3839 command *temp_command=NULL;
3840 timeperiod *temp_timeperiod=NULL;
3841 timerange *temp_timerange=NULL;
3842 contact *temp_contact=NULL;
3843 commandsmember *temp_commandsmember=NULL;
3844 contactgroup *temp_contactgroup=NULL;
3845 host *temp_host=NULL;
3846 hostsmember *temp_hostsmember=NULL;
3847 contactgroupsmember *temp_contactgroupsmember=NULL;
3848 hostgroup *temp_hostgroup=NULL;
3849 service *temp_service=NULL;
3850 servicegroup *temp_servicegroup=NULL;
3851 hostescalation *temp_hostescalation=NULL;
3852 serviceescalation *temp_serviceescalation=NULL;
3853 hostdependency *temp_hostdependency=NULL;
3854 servicedependency *temp_servicedependency=NULL;
3855 #ifdef BUILD_NAGIOS_2X
3856 hostextinfo *temp_hostextinfo=NULL;
3857 serviceextinfo *temp_serviceextinfo=NULL;
3858 contactgroupmember *temp_contactgroupmember=NULL;
3859 hostgroupmember *temp_hostgroupmember=NULL;
3860 servicegroupmember *temp_servicegroupmember=NULL;
3861 #endif
3862 int have_2d_coords=FALSE;
3863 int x_2d=0;
3864 int y_2d=0;
3865 int have_3d_coords=FALSE;
3866 double x_3d=0.0;
3867 double y_3d=0.0;
3868 double z_3d=0.0;
3869 double first_notification_delay=0.0;
3870 double retry_interval=0.0;
3871 int notify_on_host_downtime=0;
3872 int notify_on_service_downtime=0;
3873 int host_notifications_enabled=0;
3874 int service_notifications_enabled=0;
3875 int can_submit_commands=0;
3876 int flap_detection_on_up=0;
3877 int flap_detection_on_down=0;
3878 int flap_detection_on_unreachable=0;
3879 int flap_detection_on_ok=0;
3880 int flap_detection_on_warning=0;
3881 int flap_detection_on_unknown=0;
3882 int flap_detection_on_critical=0;
3883 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
3884 customvariablesmember *temp_customvar=NULL;
3885 contactsmember *temp_contactsmember=NULL;
3886 servicesmember *temp_servicesmember=NULL;
3887 #endif
3888
3889
3890 if(!(ndomod_process_options & NDOMOD_PROCESS_OBJECT_CONFIG_DATA))
3891 return NDO_OK;
3892
3893 if(!(ndomod_config_output_options & config_type))
3894 return NDO_OK;
3895
3896 /* get current time */
3897 gettimeofday(&now,NULL);
3898
3899 /* initialize dynamic buffer (2KB chunk size) */
3900 ndo_dbuf_init(&dbuf,2048);
3901
3902 /* initialize buffers */
3903 for(x=0;x<OBJECTCONFIG_ES_ITEMS;x++)
3904 es[x]=NULL;
3905
3906 /****** dump command config ******/
3907 for(temp_command=command_list;temp_command!=NULL;temp_command=temp_command->next){
3908
3909 es[0]=ndo_escape_buffer(temp_command->name);
3910 es[1]=ndo_escape_buffer(temp_command->command_line);
3911
3912 {
3913 struct ndo_broker_data command_definition[] = {
3914 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3915 { .timestamp = now }},
3916 { NDO_DATA_COMMANDNAME, BD_STRING,
3917 { .string = (es[0]==NULL) ? "" : es[0] }},
3918 { NDO_DATA_COMMANDLINE, BD_STRING,
3919 { .string = (es[1]==NULL) ? "" : es[1] }},
3920 };
3921
3922 ndomod_broker_data_serialize(&dbuf, NDO_API_COMMANDDEFINITION,
3923 command_definition,
3924 sizeof(command_definition) / sizeof(command_definition[ 0]),
3925 TRUE);
3926 }
3927
3928 /* write data to sink */
3929 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3930 ndo_dbuf_free(&dbuf);
3931
3932 /* free buffers */
3933 ndomod_free_esc_buffers(es, 2);
3934 }
3935
3936 /****** dump timeperiod config ******/
3937 for(temp_timeperiod=timeperiod_list;temp_timeperiod!=NULL;temp_timeperiod=temp_timeperiod->next){
3938
3939 es[0]=ndo_escape_buffer(temp_timeperiod->name);
3940 es[1]=ndo_escape_buffer(temp_timeperiod->alias);
3941
3942 {
3943 struct ndo_broker_data timeperiod_definition[] = {
3944 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
3945 { .timestamp = now }},
3946 { NDO_DATA_TIMEPERIODNAME, BD_STRING,
3947 { .string = (es[0]==NULL) ? "" : es[0] }},
3948 { NDO_DATA_TIMEPERIODALIAS, BD_STRING,
3949 { .string = (es[1]==NULL) ? "" : es[1] }},
3950 };
3951
3952 ndomod_broker_data_serialize(&dbuf, NDO_API_TIMEPERIODDEFINITION,
3953 timeperiod_definition, sizeof(timeperiod_definition) /
3954 sizeof(timeperiod_definition[ 0]), FALSE);
3955 }
3956
3957 ndomod_free_esc_buffers(es, 2);
3958
3959 /* dump timeranges for each day */
3960 for(x=0;x<7;x++){
3961 for(temp_timerange=temp_timeperiod->days[x];temp_timerange!=NULL;temp_timerange=temp_timerange->next){
3962
3963 snprintf(temp_buffer,sizeof(temp_buffer)-1
3964 ,"\n%d=%d:%lu-%lu"
3965 ,NDO_DATA_TIMERANGE
3966 ,x
3967 ,temp_timerange->range_start
3968 ,temp_timerange->range_end
3969 );
3970 temp_buffer[sizeof(temp_buffer)-1]='\x0';
3971 ndo_dbuf_strcat(&dbuf,temp_buffer);
3972 }
3973 }
3974
3975 ndomod_enddata_serialize(&dbuf);
3976
3977 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
3978
3979 ndo_dbuf_free(&dbuf);
3980 }
3981
3982
3983 /* free buffers */
3984 for(x=0;x<OBJECTCONFIG_ES_ITEMS;x++){
3985 free(es[x]);
3986 es[x]=NULL;
3987 }
3988
3989 /****** dump contact config ******/
3990 for(temp_contact=contact_list;temp_contact!=NULL;temp_contact=temp_contact->next){
3991
3992 es[0]=ndo_escape_buffer(temp_contact->name);
3993 es[1]=ndo_escape_buffer(temp_contact->alias);
3994 es[2]=ndo_escape_buffer(temp_contact->email);
3995 es[3]=ndo_escape_buffer(temp_contact->pager);
3996 es[4]=ndo_escape_buffer(temp_contact->host_notification_period);
3997 es[5]=ndo_escape_buffer(temp_contact->service_notification_period);
3998
3999 #ifdef BUILD_NAGIOS_4X
4000 notify_on_service_downtime=flag_isset(temp_contact->service_notification_options,OPT_DOWNTIME);
4001 notify_on_host_downtime=flag_isset(temp_contact->host_notification_options,OPT_DOWNTIME);
4002 host_notifications_enabled=temp_contact->host_notifications_enabled;
4003 service_notifications_enabled=temp_contact->service_notifications_enabled;
4004 can_submit_commands=temp_contact->can_submit_commands;
4005 #endif
4006 #ifdef BUILD_NAGIOS_3X
4007 notify_on_service_downtime=temp_contact->notify_on_service_downtime;
4008 notify_on_host_downtime=temp_contact->notify_on_host_downtime;
4009 host_notifications_enabled=temp_contact->host_notifications_enabled;
4010 service_notifications_enabled=temp_contact->service_notifications_enabled;
4011 can_submit_commands=temp_contact->can_submit_commands;
4012 #endif
4013 #ifdef BUILD_NAGIOS_2X
4014 notify_on_service_downtime=0;
4015 notify_on_host_downtime=0;
4016 host_notifications_enabled=1;
4017 service_notifications_enabled=1;
4018 can_submit_commands=1;
4019 #endif
4020
4021 {
4022 struct ndo_broker_data contact_definition[] = {
4023 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
4024 { .timestamp = now }},
4025 { NDO_DATA_CONTACTNAME, BD_STRING,
4026 { .string = (es[0]==NULL) ? "" : es[0] }},
4027 { NDO_DATA_CONTACTALIAS, BD_STRING,
4028 { .string = (es[1]==NULL) ? "" : es[1] }},
4029 { NDO_DATA_EMAILADDRESS, BD_STRING,
4030 { .string = (es[2]==NULL) ? "" : es[2] }},
4031 { NDO_DATA_PAGERADDRESS, BD_STRING,
4032 { .string = (es[3]==NULL) ? "" : es[3] }},
4033 { NDO_DATA_HOSTNOTIFICATIONPERIOD, BD_STRING,
4034 { .string = (es[4]==NULL) ? "" : es[4] }},
4035 { NDO_DATA_SERVICENOTIFICATIONPERIOD, BD_STRING,
4036 { .string = (es[5]==NULL) ? "" : es[5] }},
4037 { NDO_DATA_SERVICENOTIFICATIONSENABLED, BD_INT,
4038 { .integer = service_notifications_enabled }},
4039 { NDO_DATA_HOSTNOTIFICATIONSENABLED, BD_INT,
4040 { .integer = host_notifications_enabled }},
4041 { NDO_DATA_CANSUBMITCOMMANDS, BD_INT,
4042 { .integer = can_submit_commands }},
4043 { NDO_DATA_NOTIFYSERVICEUNKNOWN, BD_INT,
4044 { .integer =
4045 #ifdef BUILD_NAGIOS_4X
4046 flag_isset(temp_contact->service_notification_options,OPT_UNKNOWN)
4047 #else
4048 temp_contact->notify_on_service_unknown
4049 #endif
4050 }},
4051 { NDO_DATA_NOTIFYSERVICEWARNING, BD_INT,
4052 { .integer =
4053 #ifdef BUILD_NAGIOS_4X
4054 flag_isset(temp_contact->service_notification_options,OPT_WARNING)
4055 #else
4056 temp_contact->notify_on_service_warning
4057 #endif
4058 }},
4059 { NDO_DATA_NOTIFYSERVICECRITICAL, BD_INT,
4060 { .integer =
4061 #ifdef BUILD_NAGIOS_4X
4062 flag_isset(temp_contact->service_notification_options,OPT_CRITICAL)
4063 #else
4064 temp_contact->notify_on_service_critical
4065 #endif
4066 }},
4067 { NDO_DATA_NOTIFYSERVICERECOVERY, BD_INT,
4068 { .integer =
4069 #ifdef BUILD_NAGIOS_4X
4070 flag_isset(temp_contact->service_notification_options,OPT_RECOVERY)
4071 #else
4072 temp_contact->notify_on_service_recovery
4073 #endif
4074 }},
4075 { NDO_DATA_NOTIFYSERVICEFLAPPING, BD_INT,
4076 { .integer =
4077 #ifdef BUILD_NAGIOS_4X
4078 flag_isset(temp_contact->service_notification_options,OPT_FLAPPING)
4079 #else
4080 temp_contact->notify_on_service_flapping
4081 #endif
4082 }},
4083 { NDO_DATA_NOTIFYSERVICEDOWNTIME, BD_INT,
4084 { .integer = notify_on_service_downtime }},
4085 { NDO_DATA_NOTIFYHOSTDOWN, BD_INT,
4086 { .integer =
4087 #ifdef BUILD_NAGIOS_4X
4088 flag_isset(temp_contact->host_notification_options,
4089 OPT_DOWN)
4090 #else
4091 temp_contact->notify_on_host_down
4092 #endif
4093 }},
4094 { NDO_DATA_NOTIFYHOSTUNREACHABLE, BD_INT,
4095 { .integer =
4096 #ifdef BUILD_NAGIOS_4X
4097 flag_isset(temp_contact->host_notification_options,
4098 OPT_UNREACHABLE)
4099 #else
4100 temp_contact->notify_on_host_unreachable
4101 #endif
4102 }},
4103 { NDO_DATA_NOTIFYHOSTRECOVERY, BD_INT,
4104 { .integer =
4105 #ifdef BUILD_NAGIOS_4X
4106 flag_isset(temp_contact->host_notification_options,
4107 OPT_RECOVERY)
4108 #else
4109 temp_contact->notify_on_host_recovery
4110 #endif
4111 }},
4112 { NDO_DATA_NOTIFYHOSTFLAPPING, BD_INT,
4113 { .integer =
4114 #ifdef BUILD_NAGIOS_4X
4115 flag_isset(temp_contact->host_notification_options,
4116 OPT_FLAPPING)
4117 #else
4118 temp_contact->notify_on_host_flapping
4119 #endif
4120 }},
4121 { NDO_DATA_NOTIFYHOSTDOWNTIME, BD_INT,
4122 { .integer = notify_on_host_downtime }},
4123 #ifdef BUILD_NAGIOS_4X
4124 { NDO_DATA_MINIMUMIMPORTANCE, BD_INT,
4125 { .integer = temp_contact->minimum_value }},
4126 #endif
4127 };
4128
4129 ndomod_broker_data_serialize(&dbuf, NDO_API_CONTACTDEFINITION,
4130 contact_definition, sizeof(contact_definition) /
4131 sizeof(contact_definition[ 0]), FALSE);
4132 }
4133
4134 ndomod_free_esc_buffers(es, 6);
4135
4136 /* dump addresses for each contact */
4137 for(x=0;x<MAX_CONTACT_ADDRESSES;x++){
4138
4139 es[0]=ndo_escape_buffer(temp_contact->address[x]);
4140
4141 snprintf(temp_buffer,sizeof(temp_buffer)-1
4142 ,"\n%d=%d:%s"
4143 ,NDO_DATA_CONTACTADDRESS
4144 ,x+1
4145 ,(es[0]==NULL)?"":es[0]
4146 );
4147 temp_buffer[sizeof(temp_buffer)-1]='\x0';
4148 ndo_dbuf_strcat(&dbuf,temp_buffer);
4149
4150 ndomod_free_esc_buffers(es, 1);
4151 }
4152
4153 /* dump host notification commands for each contact */
4154 ndomod_commands_serialize(temp_contact->host_notification_commands,
4155 &dbuf, NDO_DATA_HOSTNOTIFICATIONCOMMAND);
4156
4157 /* dump service notification commands for each contact */
4158 ndomod_commands_serialize(temp_contact->service_notification_commands,
4159 &dbuf, NDO_DATA_SERVICENOTIFICATIONCOMMAND);
4160
4161 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
4162 /* dump customvars */
4163 ndomod_customvars_serialize(temp_contact->custom_variables, &dbuf);
4164 #endif
4165
4166 ndomod_enddata_serialize(&dbuf);
4167
4168 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
4169
4170 ndo_dbuf_free(&dbuf);
4171 }
4172
4173
4174 /* free buffers */
4175 ndomod_free_esc_buffers(es, OBJECTCONFIG_ES_ITEMS);
4176
4177 /****** dump contactgroup config ******/
4178 for(temp_contactgroup=contactgroup_list;temp_contactgroup!=NULL;temp_contactgroup=temp_contactgroup->next){
4179
4180 es[0]=ndo_escape_buffer(temp_contactgroup->group_name);
4181 es[1]=ndo_escape_buffer(temp_contactgroup->alias);
4182
4183 {
4184 struct ndo_broker_data contactgroup_definition[] = {
4185 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
4186 { .timestamp = now }},
4187 { NDO_DATA_CONTACTGROUPNAME, BD_STRING,
4188 { .string = (es[0]==NULL) ? "" : es[0] }},
4189 { NDO_DATA_CONTACTGROUPALIAS, BD_STRING,
4190 { .string = (es[1]==NULL) ? "" : es[1] }},
4191 };
4192
4193 ndomod_broker_data_serialize(&dbuf, NDO_API_CONTACTGROUPDEFINITION,
4194 contactgroup_definition, sizeof(contactgroup_definition) /
4195 sizeof(contactgroup_definition[ 0]), FALSE);
4196 }
4197
4198 ndomod_free_esc_buffers(es, 2);
4199
4200 /* dump members for each contactgroup */
4201 ndomod_contacts_serialize(temp_contactgroup->members, &dbuf,
4202 NDO_DATA_CONTACTGROUPMEMBER);
4203
4204 ndomod_enddata_serialize(&dbuf);
4205
4206 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
4207
4208 ndo_dbuf_free(&dbuf);
4209 }
4210
4211
4212 /* free buffers */
4213 ndomod_free_esc_buffers(es, OBJECTCONFIG_ES_ITEMS);
4214
4215 /****** dump host config ******/
4216 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
4217
4218 es[0]=ndo_escape_buffer(temp_host->name);
4219 es[1]=ndo_escape_buffer(temp_host->alias);
4220 es[2]=ndo_escape_buffer(temp_host->address);
4221 #ifdef BUILD_NAGIOS_4X
4222 es[3]=ndo_escape_buffer(temp_host->check_command);
4223 #else
4224 es[3]=ndo_escape_buffer(temp_host->host_check_command);
4225 #endif
4226 es[4]=ndo_escape_buffer(temp_host->event_handler);
4227 es[5]=ndo_escape_buffer(temp_host->notification_period);
4228 es[6]=ndo_escape_buffer(temp_host->check_period);
4229 #ifdef BUILD_NAGIOS_4X
4230 es[7]=ndo_escape_buffer("");
4231 #else
4232 es[7]=ndo_escape_buffer(temp_host->failure_prediction_options);
4233 #endif
4234
4235 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
4236 es[8]=ndo_escape_buffer(temp_host->notes);
4237 es[9]=ndo_escape_buffer(temp_host->notes_url);
4238 es[10]=ndo_escape_buffer(temp_host->action_url);
4239 es[11]=ndo_escape_buffer(temp_host->icon_image);
4240 es[12]=ndo_escape_buffer(temp_host->icon_image_alt);
4241 es[13]=ndo_escape_buffer(temp_host->vrml_image);
4242 es[14]=ndo_escape_buffer(temp_host->statusmap_image);
4243 have_2d_coords=temp_host->have_2d_coords;
4244 x_2d=temp_host->x_2d;
4245 y_2d=temp_host->y_2d;
4246 have_3d_coords=temp_host->have_3d_coords;
4247 x_3d=temp_host->x_3d;
4248 y_3d=temp_host->y_3d;
4249 z_3d=temp_host->z_3d;
4250
4251 first_notification_delay=temp_host->first_notification_delay;
4252 retry_interval=temp_host->retry_interval;
4253 #ifdef BUILD_NAGIOS_4X
4254 notify_on_host_downtime=flag_isset(temp_host->notification_options,OPT_DOWNTIME);
4255 flap_detection_on_up=flag_isset(temp_host->flap_detection_options,OPT_UP);
4256 flap_detection_on_down=flag_isset(temp_host->flap_detection_options,OPT_DOWN);
4257 flap_detection_on_unreachable=flag_isset(temp_host->flap_detection_options,OPT_UNREACHABLE);
4258 #else
4259 notify_on_host_downtime=temp_host->notify_on_downtime;
4260 flap_detection_on_up=temp_host->flap_detection_on_up;
4261 flap_detection_on_down=temp_host->flap_detection_on_down;
4262 flap_detection_on_unreachable=temp_host->flap_detection_on_unreachable;
4263 #endif
4264 es[15]=ndo_escape_buffer(temp_host->display_name);
4265 #endif
4266 #ifdef BUILD_NAGIOS_2X
4267 if((temp_hostextinfo=find_hostextinfo(temp_host->name))!=NULL){
4268 es[8]=ndo_escape_buffer(temp_hostextinfo->notes);
4269 es[9]=ndo_escape_buffer(temp_hostextinfo->notes_url);
4270 es[10]=ndo_escape_buffer(temp_hostextinfo->action_url);
4271 es[11]=ndo_escape_buffer(temp_hostextinfo->icon_image);
4272 es[12]=ndo_escape_buffer(temp_hostextinfo->icon_image_alt);
4273 es[13]=ndo_escape_buffer(temp_hostextinfo->vrml_image);
4274 es[14]=ndo_escape_buffer(temp_hostextinfo->statusmap_image);
4275 have_2d_coords=temp_hostextinfo->have_2d_coords;
4276 x_2d=temp_hostextinfo->x_2d;
4277 y_2d=temp_hostextinfo->y_2d;
4278 have_3d_coords=temp_hostextinfo->have_3d_coords;
4279 x_3d=temp_hostextinfo->x_3d;
4280 y_3d=temp_hostextinfo->y_3d;
4281 z_3d=temp_hostextinfo->z_3d;
4282 }
4283 else{
4284 es[8]=NULL;
4285 es[9]=NULL;
4286 es[10]=NULL;
4287 es[11]=NULL;
4288 es[12]=NULL;
4289 es[13]=NULL;
4290 es[14]=NULL;
4291 have_2d_coords=FALSE;
4292 x_2d=0;
4293 y_2d=0;
4294 have_3d_coords=FALSE;
4295 x_3d=0.0;
4296 y_3d=0.0;
4297 z_3d=0.0;
4298 }
4299
4300 first_notification_delay=0.0;
4301 retry_interval=0.0;
4302 notify_on_host_downtime=0;
4303 flap_detection_on_up=1;
4304 flap_detection_on_down=1;
4305 flap_detection_on_unreachable=1;
4306 es[15]=ndo_escape_buffer(temp_host->name);
4307 #endif
4308
4309 {
4310 struct ndo_broker_data host_definition[] = {
4311 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
4312 { .timestamp = now }},
4313 { NDO_DATA_HOSTNAME, BD_STRING,
4314 { .string = (es[0]==NULL) ? "" : es[0] }},
4315 { NDO_DATA_DISPLAYNAME, BD_STRING,
4316 { .string = (es[15]==NULL) ? "" : es[15] }},
4317 { NDO_DATA_HOSTALIAS, BD_STRING,
4318 { .string = (es[1]==NULL) ? "" : es[1] }},
4319 { NDO_DATA_HOSTADDRESS, BD_STRING,
4320 { .string = (es[2]==NULL) ? "" : es[2] }},
4321 { NDO_DATA_HOSTCHECKCOMMAND, BD_STRING,
4322 { .string = (es[3]==NULL) ? "" : es[3] }},
4323 { NDO_DATA_HOSTEVENTHANDLER, BD_STRING,
4324 { .string = (es[4]==NULL) ? "" : es[4] }},
4325 { NDO_DATA_HOSTNOTIFICATIONPERIOD, BD_STRING,
4326 { .string = (es[5]==NULL) ? "" : es[5] }},
4327 { NDO_DATA_HOSTCHECKPERIOD, BD_STRING,
4328 { .string = (es[6]==NULL) ? "" : es[6] }},
4329 { NDO_DATA_HOSTFAILUREPREDICTIONOPTIONS, BD_STRING,
4330 { .string = (es[7]==NULL) ? "" : es[7] }},
4331 { NDO_DATA_HOSTCHECKINTERVAL, BD_FLOAT,
4332 { .floating_point =
4333 (double)temp_host->check_interval }},
4334 { NDO_DATA_HOSTRETRYINTERVAL, BD_FLOAT,
4335 { .floating_point = (double)retry_interval }},
4336 { NDO_DATA_HOSTMAXCHECKATTEMPTS, BD_INT,
4337 { .integer = temp_host->max_attempts }},
4338 { NDO_DATA_FIRSTNOTIFICATIONDELAY, BD_FLOAT,
4339 { .floating_point = first_notification_delay }},
4340 { NDO_DATA_HOSTNOTIFICATIONINTERVAL, BD_FLOAT,
4341 { .floating_point =
4342 (double)temp_host->notification_interval }},
4343 { NDO_DATA_NOTIFYHOSTDOWN, BD_INT,
4344 { .integer =
4345 #ifdef BUILD_NAGIOS_4X
4346 flag_isset(temp_host->notification_options,
4347 OPT_DOWN)
4348 #else
4349 temp_host->notify_on_down
4350 #endif
4351 }},
4352 { NDO_DATA_NOTIFYHOSTUNREACHABLE, BD_INT,
4353 { .integer =
4354 #ifdef BUILD_NAGIOS_4X
4355 flag_isset(temp_host->notification_options,
4356 OPT_UNREACHABLE)
4357 #else
4358 temp_host->notify_on_unreachable
4359 #endif
4360 }},
4361 { NDO_DATA_NOTIFYHOSTRECOVERY, BD_INT,
4362 { .integer =
4363 #ifdef BUILD_NAGIOS_4X
4364 flag_isset(temp_host->notification_options,
4365 OPT_RECOVERY)
4366 #else
4367 temp_host->notify_on_recovery
4368 #endif
4369 }},
4370 { NDO_DATA_NOTIFYHOSTFLAPPING, BD_INT,
4371 { .integer =
4372 #ifdef BUILD_NAGIOS_4X
4373 flag_isset(temp_host->notification_options,
4374 OPT_FLAPPING)
4375 #else
4376 temp_host->notify_on_flapping
4377 #endif
4378 }},
4379 { NDO_DATA_NOTIFYHOSTDOWNTIME, BD_INT,
4380 { .integer = notify_on_host_downtime }},
4381 { NDO_DATA_HOSTFLAPDETECTIONENABLED, BD_INT,
4382 { .integer = temp_host->flap_detection_enabled }},
4383 { NDO_DATA_FLAPDETECTIONONUP, BD_INT,
4384 { .integer = flap_detection_on_up }},
4385 { NDO_DATA_FLAPDETECTIONONDOWN, BD_INT,
4386 { .integer = flap_detection_on_down }},
4387 { NDO_DATA_FLAPDETECTIONONUNREACHABLE, BD_INT,
4388 { .integer = flap_detection_on_unreachable }},
4389 { NDO_DATA_LOWHOSTFLAPTHRESHOLD, BD_FLOAT,
4390 { .floating_point = temp_host->low_flap_threshold }},
4391 { NDO_DATA_HIGHHOSTFLAPTHRESHOLD, BD_FLOAT,
4392 { .floating_point = temp_host->high_flap_threshold }},
4393 { NDO_DATA_STALKHOSTONUP, BD_INT,
4394 { .integer =
4395 #ifdef BUILD_NAGIOS_4X
4396 flag_isset(temp_host->stalking_options,
4397 OPT_UP)
4398 #else
4399 temp_host->stalk_on_up
4400 #endif
4401 }},
4402 { NDO_DATA_STALKHOSTONDOWN, BD_INT,
4403 { .integer =
4404 #ifdef BUILD_NAGIOS_4X
4405 flag_isset(temp_host->stalking_options,
4406 OPT_DOWN)
4407 #else
4408 temp_host->stalk_on_down
4409 #endif
4410 }},
4411 { NDO_DATA_STALKHOSTONUNREACHABLE, BD_INT,
4412 { .integer =
4413 #ifdef BUILD_NAGIOS_4X
4414 flag_isset(temp_host->stalking_options,
4415 OPT_UNREACHABLE)
4416 #else
4417 temp_host->stalk_on_unreachable
4418 #endif
4419 }},
4420 { NDO_DATA_HOSTFRESHNESSCHECKSENABLED, BD_INT,
4421 { .integer = temp_host->check_freshness }},
4422 { NDO_DATA_HOSTFRESHNESSTHRESHOLD, BD_INT,
4423 { .integer = temp_host->freshness_threshold }},
4424 { NDO_DATA_PROCESSHOSTPERFORMANCEDATA, BD_INT,
4425 { .integer = temp_host->process_performance_data }},
4426 { NDO_DATA_ACTIVEHOSTCHECKSENABLED, BD_INT,
4427 { .integer = temp_host->checks_enabled }},
4428 { NDO_DATA_PASSIVEHOSTCHECKSENABLED, BD_INT,
4429 { .integer =
4430 #ifdef BUILD_NAGIOS_4X
4431 temp_host->accept_passive_checks
4432 #else
4433 temp_host->accept_passive_host_checks
4434 #endif
4435 }},
4436 { NDO_DATA_HOSTEVENTHANDLERENABLED, BD_INT,
4437 { .integer = temp_host->event_handler_enabled }},
4438 { NDO_DATA_RETAINHOSTSTATUSINFORMATION, BD_INT,
4439 { .integer = temp_host->retain_status_information }},
4440 { NDO_DATA_RETAINHOSTNONSTATUSINFORMATION, BD_INT,
4441 { .integer = temp_host->retain_nonstatus_information }},
4442 { NDO_DATA_HOSTNOTIFICATIONSENABLED, BD_INT,
4443 { .integer = temp_host->notifications_enabled }},
4444 { NDO_DATA_HOSTFAILUREPREDICTIONENABLED, BD_INT,
4445 { .integer =
4446 #ifdef BUILD_NAGIOS_4X
4447 0
4448 #else
4449 temp_host->failure_prediction_enabled
4450 #endif
4451 }},
4452 { NDO_DATA_OBSESSOVERHOST, BD_INT,
4453 { .integer =
4454 #ifdef BUILD_NAGIOS_4X
4455 temp_host->obsess
4456 #else
4457 temp_host->obsess_over_host
4458 #endif
4459 }},
4460 { NDO_DATA_NOTES, BD_STRING,
4461 { .string = (es[8]==NULL) ? "" : es[8] }},
4462 { NDO_DATA_NOTESURL, BD_STRING,
4463 { .string = (es[9]==NULL) ? "" : es[9] }},
4464 { NDO_DATA_ACTIONURL, BD_STRING,
4465 { .string = (es[10]==NULL) ? "" : es[10] }},
4466 { NDO_DATA_ICONIMAGE, BD_STRING,
4467 { .string = (es[11]==NULL) ? "" : es[11] }},
4468 { NDO_DATA_ICONIMAGEALT, BD_STRING,
4469 { .string = (es[12]==NULL) ? "" : es[12] }},
4470 { NDO_DATA_VRMLIMAGE, BD_STRING,
4471 { .string = (es[13]==NULL) ? "" : es[13] }},
4472 { NDO_DATA_STATUSMAPIMAGE, BD_STRING,
4473 { .string = (es[14]==NULL) ? "" : es[14] }},
4474 { NDO_DATA_HAVE2DCOORDS, BD_INT, { .integer = have_2d_coords }},
4475 { NDO_DATA_X2D, BD_INT, { .integer = x_2d }},
4476 { NDO_DATA_Y2D, BD_INT, { .integer = y_2d }},
4477 { NDO_DATA_HAVE3DCOORDS, BD_INT, { .integer = have_3d_coords }},
4478 { NDO_DATA_X3D, BD_FLOAT, { .floating_point = x_3d }},
4479 { NDO_DATA_Y3D, BD_FLOAT, { .floating_point = y_3d }},
4480 { NDO_DATA_Z3D, BD_FLOAT, { .floating_point = z_3d }},
4481 #ifdef BUILD_NAGIOS_4X
4482 { NDO_DATA_IMPORTANCE, BD_INT,
4483 { .integer = temp_host->hourly_value }},
4484 #endif
4485 };
4486
4487 ndomod_broker_data_serialize(&dbuf, NDO_API_HOSTDEFINITION,
4488 host_definition, sizeof(host_definition) /
4489 sizeof(host_definition[ 0]), FALSE);
4490 }
4491
4492 ndomod_free_esc_buffers(es, OBJECTCONFIG_ES_ITEMS);
4493
4494 /* dump parent hosts */
4495 ndomod_hosts_serialize(temp_host->parent_hosts, &dbuf,
4496 NDO_DATA_PARENTHOST);
4497
4498 /* dump contactgroups */
4499 ndomod_contactgroups_serialize(temp_host->contact_groups, &dbuf);
4500
4501 /* dump individual contacts (not supported in Nagios 2.x) */
4502 #ifndef BUILD_NAGIOS_2X
4503 ndomod_contacts_serialize(temp_host->contacts, &dbuf, NDO_DATA_CONTACT);
4504 #endif
4505
4506 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
4507 /* dump customvars */
4508 ndomod_customvars_serialize(temp_host->custom_variables, &dbuf);
4509 #endif
4510
4511 ndomod_enddata_serialize(&dbuf);
4512
4513 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
4514
4515 ndo_dbuf_free(&dbuf);
4516 }
4517
4518
4519 /* free buffers */
4520 ndomod_free_esc_buffers(es, OBJECTCONFIG_ES_ITEMS);
4521
4522 /****** dump hostgroup config ******/
4523 for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
4524
4525 es[0]=ndo_escape_buffer(temp_hostgroup->group_name);
4526 es[1]=ndo_escape_buffer(temp_hostgroup->alias);
4527
4528 {
4529 struct ndo_broker_data hostgroup_definition[] = {
4530 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
4531 { .timestamp = now }},
4532 { NDO_DATA_HOSTGROUPNAME, BD_STRING,
4533 { .string = (es[0]==NULL) ? "" : es[0] }},
4534 { NDO_DATA_HOSTGROUPALIAS, BD_STRING,
4535 { .string = (es[1]==NULL) ? "" : es[1] }},
4536 };
4537
4538 ndomod_broker_data_serialize(&dbuf, NDO_API_HOSTGROUPDEFINITION,
4539 hostgroup_definition, sizeof(hostgroup_definition) /
4540 sizeof(hostgroup_definition[ 0]), FALSE);
4541 }
4542
4543 ndomod_free_esc_buffers(es, 2);
4544
4545 /* dump members for each hostgroup */
4546 #ifdef BUILD_NAGIOS_2X
4547 ndomod_hosts_serialize_2x(temp_hostgroup->members, &dbuf,
4548 NDO_DATA_HOSTGROUPMEMBER);
4549 #else
4550 ndomod_hosts_serialize(temp_hostgroup->members, &dbuf,
4551 NDO_DATA_HOSTGROUPMEMBER);
4552 #endif
4553
4554 ndomod_enddata_serialize(&dbuf);
4555
4556 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
4557
4558 ndo_dbuf_free(&dbuf);
4559 }
4560
4561 /****** dump service config ******/
4562 for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){
4563
4564 es[0]=ndo_escape_buffer(temp_service->host_name);
4565 es[1]=ndo_escape_buffer(temp_service->description);
4566 #ifdef BUILD_NAGIOS_4X
4567 es[2]=ndo_escape_buffer(temp_service->check_command);
4568 #else
4569 es[2]=ndo_escape_buffer(temp_service->service_check_command);
4570 #endif
4571 es[3]=ndo_escape_buffer(temp_service->event_handler);
4572 es[4]=ndo_escape_buffer(temp_service->notification_period);
4573 es[5]=ndo_escape_buffer(temp_service->check_period);
4574 #ifdef BUILD_NAGIOS_4X
4575 es[6]=ndo_escape_buffer("");
4576 #else
4577 es[6]=ndo_escape_buffer(temp_service->failure_prediction_options);
4578 #endif
4579 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
4580 es[7]=ndo_escape_buffer(temp_service->notes);
4581 es[8]=ndo_escape_buffer(temp_service->notes_url);
4582 es[9]=ndo_escape_buffer(temp_service->action_url);
4583 es[10]=ndo_escape_buffer(temp_service->icon_image);
4584 es[11]=ndo_escape_buffer(temp_service->icon_image_alt);
4585
4586 first_notification_delay=temp_service->first_notification_delay;
4587 #ifdef BUILD_NAGIOS_4X
4588 notify_on_service_downtime=flag_isset(temp_service->notification_options,OPT_DOWNTIME);
4589 flap_detection_on_ok=flag_isset(temp_service->flap_detection_options,OPT_OK);
4590 flap_detection_on_warning=flag_isset(temp_service->flap_detection_options,OPT_WARNING);
4591 flap_detection_on_unknown=flag_isset(temp_service->flap_detection_options,OPT_UNKNOWN);
4592 flap_detection_on_critical=flag_isset(temp_service->flap_detection_options,OPT_CRITICAL);
4593 #else
4594 notify_on_service_downtime=temp_service->notify_on_downtime;
4595 flap_detection_on_ok=temp_service->flap_detection_on_ok;
4596 flap_detection_on_warning=temp_service->flap_detection_on_warning;
4597 flap_detection_on_unknown=temp_service->flap_detection_on_unknown;
4598 flap_detection_on_critical=temp_service->flap_detection_on_critical;
4599 #endif
4600 es[12]=ndo_escape_buffer(temp_service->display_name);
4601 #endif
4602 #ifdef BUILD_NAGIOS_2X
4603 if((temp_serviceextinfo=find_serviceextinfo(temp_service->host_name,temp_service->description))!=NULL){
4604 es[7]=ndo_escape_buffer(temp_serviceextinfo->notes);
4605 es[8]=ndo_escape_buffer(temp_serviceextinfo->notes_url);
4606 es[9]=ndo_escape_buffer(temp_serviceextinfo->action_url);
4607 es[10]=ndo_escape_buffer(temp_serviceextinfo->icon_image);
4608 es[11]=ndo_escape_buffer(temp_serviceextinfo->icon_image_alt);
4609 }
4610 else{
4611 es[7]=NULL;
4612 es[8]=NULL;
4613 es[9]=NULL;
4614 es[10]=NULL;
4615 es[11]=NULL;
4616 }
4617
4618 first_notification_delay=0.0;
4619 notify_on_service_downtime=0;
4620 flap_detection_on_ok=1;
4621 flap_detection_on_warning=1;
4622 flap_detection_on_unknown=1;
4623 flap_detection_on_critical=1;
4624 es[12]=ndo_escape_buffer(temp_service->description);
4625 #endif
4626
4627 {
4628 struct ndo_broker_data service_definition[] = {
4629 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
4630 { .timestamp = now }},
4631 { NDO_DATA_HOSTNAME, BD_STRING,
4632 { .string = (es[0]==NULL) ? "" : es[0] }},
4633 { NDO_DATA_DISPLAYNAME, BD_STRING,
4634 { .string = (es[12]==NULL) ? "" : es[12] }},
4635 { NDO_DATA_SERVICEDESCRIPTION, BD_STRING,
4636 { .string = (es[1]==NULL) ? "" : es[1] }},
4637 { NDO_DATA_SERVICECHECKCOMMAND, BD_STRING,
4638 { .string = (es[2]==NULL) ? "" : es[2] }},
4639 { NDO_DATA_SERVICEEVENTHANDLER, BD_STRING,
4640 { .string = (es[3]==NULL) ? "" : es[3] }},
4641 { NDO_DATA_SERVICENOTIFICATIONPERIOD, BD_STRING,
4642 { .string = (es[4]==NULL) ? "" : es[4] }},
4643 { NDO_DATA_SERVICECHECKPERIOD, BD_STRING,
4644 { .string = (es[5]==NULL) ? "" : es[5] }},
4645 { NDO_DATA_SERVICEFAILUREPREDICTIONOPTIONS, BD_STRING,
4646 { .string = (es[6]==NULL) ? "" : es[6] }},
4647 { NDO_DATA_SERVICECHECKINTERVAL, BD_FLOAT,
4648 { .floating_point =
4649 (double)temp_service->check_interval }},
4650 { NDO_DATA_SERVICERETRYINTERVAL, BD_FLOAT,
4651 { .floating_point =
4652 (double)temp_service->retry_interval }},
4653 { NDO_DATA_MAXSERVICECHECKATTEMPTS, BD_INT,
4654 { .integer = temp_service->max_attempts }},
4655 { NDO_DATA_FIRSTNOTIFICATIONDELAY, BD_FLOAT,
4656 { .floating_point = first_notification_delay }},
4657 { NDO_DATA_SERVICENOTIFICATIONINTERVAL, BD_FLOAT,
4658 { .floating_point =
4659 (double)temp_service->notification_interval }},
4660 { NDO_DATA_NOTIFYSERVICEUNKNOWN, BD_INT,
4661 { .integer =
4662 #ifdef BUILD_NAGIOS_4X
4663 flag_isset(temp_service->notification_options,
4664 OPT_UNKNOWN)
4665 #else
4666 temp_service->notify_on_unknown
4667 #endif
4668 }},
4669 { NDO_DATA_NOTIFYSERVICEWARNING, BD_INT,
4670 { .integer =
4671 #ifdef BUILD_NAGIOS_4X
4672 flag_isset(temp_service->notification_options,
4673 OPT_WARNING)
4674 #else
4675 temp_service->notify_on_warning
4676 #endif
4677 }},
4678 { NDO_DATA_NOTIFYSERVICECRITICAL, BD_INT,
4679 { .integer =
4680 #ifdef BUILD_NAGIOS_4X
4681 flag_isset(temp_service->notification_options,
4682 OPT_CRITICAL)
4683 #else
4684 temp_service->notify_on_critical
4685 #endif
4686 }},
4687 { NDO_DATA_NOTIFYSERVICERECOVERY, BD_INT,
4688 { .integer =
4689 #ifdef BUILD_NAGIOS_4X
4690 flag_isset(temp_service->notification_options,
4691 OPT_RECOVERY)
4692 #else
4693 temp_service->notify_on_recovery
4694 #endif
4695 }},
4696 { NDO_DATA_NOTIFYSERVICEFLAPPING, BD_INT,
4697 { .integer =
4698 #ifdef BUILD_NAGIOS_4X
4699 flag_isset(temp_service->notification_options,
4700 OPT_FLAPPING)
4701 #else
4702 temp_service->notify_on_flapping
4703 #endif
4704 }},
4705 { NDO_DATA_NOTIFYSERVICEDOWNTIME, BD_INT,
4706 { .integer = notify_on_service_downtime }},
4707 { NDO_DATA_STALKSERVICEONOK, BD_INT,
4708 { .integer =
4709 #ifdef BUILD_NAGIOS_4X
4710 flag_isset(temp_service->stalking_options,
4711 OPT_OK)
4712 #else
4713 temp_service->stalk_on_ok
4714 #endif
4715 }},
4716 { NDO_DATA_STALKSERVICEONWARNING, BD_INT,
4717 { .integer =
4718 #ifdef BUILD_NAGIOS_4X
4719 flag_isset(temp_service->stalking_options,
4720 OPT_WARNING)
4721 #else
4722 temp_service->stalk_on_warning
4723 #endif
4724 }},
4725 { NDO_DATA_STALKSERVICEONUNKNOWN, BD_INT,
4726 { .integer =
4727 #ifdef BUILD_NAGIOS_4X
4728 flag_isset(temp_service->stalking_options,
4729 OPT_UNKNOWN)
4730 #else
4731 temp_service->stalk_on_unknown
4732 #endif
4733 }},
4734 { NDO_DATA_STALKSERVICEONCRITICAL, BD_INT,
4735 { .integer =
4736 #ifdef BUILD_NAGIOS_4X
4737 flag_isset(temp_service->stalking_options,
4738 OPT_CRITICAL)
4739 #else
4740 temp_service->stalk_on_critical
4741 #endif
4742 }},
4743 { NDO_DATA_SERVICEISVOLATILE, BD_INT,
4744 { .integer = temp_service->is_volatile }},
4745 { NDO_DATA_SERVICEFLAPDETECTIONENABLED, BD_INT,
4746 { .integer = temp_service->flap_detection_enabled }},
4747 { NDO_DATA_FLAPDETECTIONONOK, BD_INT,
4748 { .integer = flap_detection_on_ok }},
4749 { NDO_DATA_FLAPDETECTIONONWARNING, BD_INT,
4750 { .integer = flap_detection_on_warning }},
4751 { NDO_DATA_FLAPDETECTIONONUNKNOWN, BD_INT,
4752 { .integer = flap_detection_on_unknown }},
4753 { NDO_DATA_FLAPDETECTIONONCRITICAL, BD_INT,
4754 { .integer = flap_detection_on_critical }},
4755 { NDO_DATA_LOWSERVICEFLAPTHRESHOLD, BD_FLOAT,
4756 { .floating_point = temp_service->low_flap_threshold }},
4757 { NDO_DATA_HIGHSERVICEFLAPTHRESHOLD, BD_FLOAT,
4758 { .floating_point =
4759 temp_service->high_flap_threshold }},
4760 { NDO_DATA_PROCESSSERVICEPERFORMANCEDATA, BD_INT,
4761 { .integer = temp_service->process_performance_data }},
4762 { NDO_DATA_SERVICEFRESHNESSCHECKSENABLED, BD_INT,
4763 { .integer = temp_service->check_freshness }},
4764 { NDO_DATA_SERVICEFRESHNESSTHRESHOLD, BD_INT,
4765 { .integer = temp_service->freshness_threshold }},
4766 { NDO_DATA_PASSIVESERVICECHECKSENABLED, BD_INT,
4767 { .integer =
4768 #ifdef BUILD_NAGIOS_4X
4769 temp_service->accept_passive_checks
4770 #else
4771 temp_service->accept_passive_service_checks
4772 #endif
4773 }},
4774 { NDO_DATA_SERVICEEVENTHANDLERENABLED, BD_INT,
4775 { .integer = temp_service->event_handler_enabled }},
4776 { NDO_DATA_ACTIVESERVICECHECKSENABLED, BD_INT,
4777 { .integer = temp_service->checks_enabled }},
4778 { NDO_DATA_RETAINSERVICESTATUSINFORMATION, BD_INT,
4779 { .integer = temp_service->retain_status_information }},
4780 { NDO_DATA_RETAINSERVICENONSTATUSINFORMATION, BD_INT,
4781 { .integer =
4782 temp_service->retain_nonstatus_information }},
4783 { NDO_DATA_SERVICENOTIFICATIONSENABLED, BD_INT,
4784 { .integer = temp_service->notifications_enabled }},
4785 { NDO_DATA_OBSESSOVERSERVICE, BD_INT,
4786 { .integer =
4787 #ifdef BUILD_NAGIOS_4X
4788 temp_service->obsess
4789 #else
4790 temp_service->obsess_over_service
4791 #endif
4792 }},
4793 { NDO_DATA_FAILUREPREDICTIONENABLED, BD_INT,
4794 { .integer =
4795 #ifdef BUILD_NAGIOS_4X
4796 0
4797 #else
4798 temp_service->failure_prediction_enabled
4799 #endif
4800 }},
4801 { NDO_DATA_NOTES, BD_STRING,
4802 { .string = (es[7]==NULL) ? "" : es[7] }},
4803 { NDO_DATA_NOTESURL, BD_STRING,
4804 { .string = (es[8]==NULL) ? "" : es[8] }},
4805 { NDO_DATA_ACTIONURL, BD_STRING,
4806 { .string = (es[9]==NULL) ? "" : es[9] }},
4807 { NDO_DATA_ICONIMAGE, BD_STRING,
4808 { .string = (es[10]==NULL) ? "" : es[10] }},
4809 { NDO_DATA_ICONIMAGEALT, BD_STRING,
4810 { .string = (es[11]==NULL) ? "" : es[11] }},
4811 #ifdef BUILD_NAGIOS_4X
4812 { NDO_DATA_IMPORTANCE, BD_INT,
4813 { .integer = temp_service->hourly_value }},
4814 #endif
4815 };
4816
4817 ndomod_broker_data_serialize(&dbuf, NDO_API_SERVICEDEFINITION,
4818 service_definition, sizeof(service_definition) /
4819 sizeof(service_definition[ 0]), FALSE);
4820 }
4821
4822 ndomod_free_esc_buffers(es, OBJECTCONFIG_ES_ITEMS);
4823
4824 #ifdef BUILD_NAGIOS_4X
4825 /* dump parent services */
4826 ndomod_services_serialize(temp_service->parents, &dbuf,
4827 NDO_DATA_PARENTSERVICE);
4828 #endif
4829
4830 /* dump contactgroups */
4831 ndomod_contactgroups_serialize(temp_service->contact_groups, &dbuf);
4832
4833 /* dump individual contacts (not supported in Nagios 2.x) */
4834 #ifndef BUILD_NAGIOS_2X
4835 ndomod_contacts_serialize(temp_service->contacts, &dbuf,
4836 NDO_DATA_CONTACT);
4837 #endif
4838
4839 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
4840 /* dump customvars */
4841 ndomod_customvars_serialize(temp_service->custom_variables, &dbuf);
4842 #endif
4843
4844 ndomod_enddata_serialize(&dbuf);
4845
4846 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
4847
4848 ndo_dbuf_free(&dbuf);
4849 }
4850
4851
4852 /****** dump servicegroup config ******/
4853 for(temp_servicegroup=servicegroup_list;temp_servicegroup!=NULL;temp_servicegroup=temp_servicegroup->next){
4854
4855 es[0]=ndo_escape_buffer(temp_servicegroup->group_name);
4856 es[1]=ndo_escape_buffer(temp_servicegroup->alias);
4857
4858 {
4859 struct ndo_broker_data servicegroup_definition[] = {
4860 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
4861 { .timestamp = now }},
4862 { NDO_DATA_SERVICEGROUPNAME, BD_STRING,
4863 { .string = (es[0]==NULL) ? "" : es[0] }},
4864 { NDO_DATA_SERVICEGROUPALIAS, BD_STRING,
4865 { .string = (es[1]==NULL) ? "" : es[1] }},
4866 };
4867
4868 ndomod_broker_data_serialize(&dbuf, NDO_API_SERVICEGROUPDEFINITION,
4869 servicegroup_definition, sizeof(servicegroup_definition) /
4870 sizeof(servicegroup_definition[ 0]), FALSE);
4871 }
4872
4873 ndomod_free_esc_buffers(es, 2);
4874
4875 /* dump members for each servicegroup */
4876 ndomod_services_serialize(temp_servicegroup->members, &dbuf,
4877 NDO_DATA_SERVICEGROUPMEMBER);
4878
4879 ndomod_enddata_serialize(&dbuf);
4880
4881 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
4882
4883 ndo_dbuf_free(&dbuf);
4884 }
4885
4886
4887 /****** dump host escalation config ******/
4888 #ifdef BUILD_NAGIOS_4X
4889 for(x=0; x<num_objects.hostescalations; x++) {
4890 temp_hostescalation=hostescalation_ary[ x];
4891 #else
4892 for(temp_hostescalation=hostescalation_list;temp_hostescalation!=NULL;temp_hostescalation=temp_hostescalation->next){
4893 #endif
4894 es[0]=ndo_escape_buffer(temp_hostescalation->host_name);
4895 es[1]=ndo_escape_buffer(temp_hostescalation->escalation_period);
4896
4897 {
4898 struct ndo_broker_data hostescalation_definition[] = {
4899 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
4900 { .timestamp = now }},
4901 { NDO_DATA_HOSTNAME, BD_STRING,
4902 { .string = (es[0]==NULL) ? "" : es[0] }},
4903 { NDO_DATA_ESCALATIONPERIOD, BD_STRING,
4904 { .string = (es[1]==NULL) ? "" : es[1] }},
4905 { NDO_DATA_FIRSTNOTIFICATION, BD_INT,
4906 { .integer = temp_hostescalation->first_notification }},
4907 { NDO_DATA_LASTNOTIFICATION, BD_INT,
4908 { .integer = temp_hostescalation->last_notification }},
4909 { NDO_DATA_NOTIFICATIONINTERVAL, BD_FLOAT,
4910 { .floating_point =
4911 (double)temp_hostescalation->notification_interval }},
4912 { NDO_DATA_ESCALATEONRECOVERY, BD_INT,
4913 { .integer =
4914 #ifdef BUILD_NAGIOS_4X
4915 flag_isset(temp_hostescalation->escalation_options,
4916 OPT_RECOVERY)
4917 #else
4918 temp_hostescalation->escalate_on_recovery
4919 #endif
4920 }},
4921 { NDO_DATA_ESCALATEONDOWN, BD_INT,
4922 { .integer =
4923 #ifdef BUILD_NAGIOS_4X
4924 flag_isset(temp_hostescalation->escalation_options,
4925 OPT_DOWN)
4926 #else
4927 temp_hostescalation->escalate_on_down
4928 #endif
4929 }},
4930 { NDO_DATA_ESCALATEONUNREACHABLE, BD_INT,
4931 { .integer =
4932 #ifdef BUILD_NAGIOS_4X
4933 flag_isset(temp_hostescalation->escalation_options,
4934 OPT_UNREACHABLE)
4935 #else
4936 temp_hostescalation->escalate_on_unreachable
4937 #endif
4938 }},
4939 };
4940
4941 ndomod_broker_data_serialize(&dbuf,
4942 NDO_API_HOSTESCALATIONDEFINITION,
4943 hostescalation_definition,
4944 sizeof(hostescalation_definition) /
4945 sizeof(hostescalation_definition[ 0]), FALSE);
4946 }
4947
4948 ndomod_free_esc_buffers(es, 2);
4949
4950 /* dump contactgroups */
4951 ndomod_contactgroups_serialize(temp_hostescalation->contact_groups,
4952 &dbuf);
4953
4954 /* dump individual contacts (not supported in Nagios 2.x) */
4955 #ifndef BUILD_NAGIOS_2X
4956 ndomod_contacts_serialize(temp_hostescalation->contacts, &dbuf,
4957 NDO_DATA_CONTACT);
4958 #endif
4959
4960 ndomod_enddata_serialize(&dbuf);
4961
4962 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
4963
4964 ndo_dbuf_free(&dbuf);
4965 }
4966
4967
4968 /****** dump service escalation config ******/
4969 #ifdef BUILD_NAGIOS_4X
4970 for(x=0; x<num_objects.serviceescalations; x++) {
4971 temp_serviceescalation=serviceescalation_ary[ x];
4972 #else
4973 for(temp_serviceescalation=serviceescalation_list;temp_serviceescalation!=NULL;temp_serviceescalation=temp_serviceescalation->next){
4974 #endif
4975
4976 es[0]=ndo_escape_buffer(temp_serviceescalation->host_name);
4977 es[1]=ndo_escape_buffer(temp_serviceescalation->description);
4978 es[2]=ndo_escape_buffer(temp_serviceescalation->escalation_period);
4979
4980 {
4981 struct ndo_broker_data serviceescalation_definition[] = {
4982 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
4983 { .timestamp = now }},
4984 { NDO_DATA_HOSTNAME, BD_STRING,
4985 { .string = (es[0]==NULL) ? "" : es[0] }},
4986 { NDO_DATA_SERVICEDESCRIPTION, BD_STRING,
4987 { .string = (es[1]==NULL) ? "" : es[1] }},
4988 { NDO_DATA_ESCALATIONPERIOD, BD_STRING,
4989 { .string = (es[2]==NULL) ? "" : es[2] }},
4990 { NDO_DATA_FIRSTNOTIFICATION, BD_INT,
4991 { .integer =
4992 temp_serviceescalation->first_notification }},
4993 { NDO_DATA_LASTNOTIFICATION, BD_INT,
4994 { .integer =
4995 temp_serviceescalation->last_notification }},
4996 { NDO_DATA_NOTIFICATIONINTERVAL, BD_FLOAT,
4997 { .floating_point =
4998 (double)temp_serviceescalation->notification_interval }},
4999 { NDO_DATA_ESCALATEONRECOVERY, BD_INT,
5000 { .integer =
5001 #ifdef BUILD_NAGIOS_4X
5002 flag_isset(temp_serviceescalation->escalation_options,
5003 OPT_RECOVERY)
5004 #else
5005 temp_serviceescalation->escalate_on_recovery
5006 #endif
5007 }},
5008 { NDO_DATA_ESCALATEONWARNING, BD_INT,
5009 { .integer =
5010 #ifdef BUILD_NAGIOS_4X
5011 flag_isset(temp_serviceescalation->escalation_options,
5012 OPT_WARNING)
5013 #else
5014 temp_serviceescalation->escalate_on_warning
5015 #endif
5016 }},
5017
5018 { NDO_DATA_ESCALATEONUNKNOWN, BD_INT,
5019 { .integer =
5020 #ifdef BUILD_NAGIOS_4X
5021 flag_isset(temp_serviceescalation->escalation_options,
5022 OPT_UNKNOWN)
5023 #else
5024 temp_serviceescalation->escalate_on_unknown
5025 #endif
5026 }},
5027 { NDO_DATA_ESCALATEONCRITICAL, BD_INT,
5028 { .integer =
5029 #ifdef BUILD_NAGIOS_4X
5030 flag_isset(temp_serviceescalation->escalation_options,
5031 OPT_CRITICAL)
5032 #else
5033 temp_serviceescalation->escalate_on_critical
5034 #endif
5035 }},
5036 };
5037
5038 ndomod_broker_data_serialize(&dbuf,
5039 NDO_API_SERVICEESCALATIONDEFINITION,
5040 serviceescalation_definition,
5041 sizeof(serviceescalation_definition) /
5042 sizeof(serviceescalation_definition[ 0]), FALSE);
5043
5044 ndomod_free_esc_buffers(es, 3);
5045 }
5046
5047 free(es[0]);
5048 es[0]=NULL;
5049
5050 /* dump contactgroups */
5051 ndomod_contactgroups_serialize(temp_serviceescalation->contact_groups,
5052 &dbuf);
5053
5054 /* dump individual contacts (not supported in Nagios 2.x) */
5055 #ifndef BUILD_NAGIOS_2X
5056 ndomod_contacts_serialize(temp_serviceescalation->contacts, &dbuf,
5057 NDO_DATA_CONTACT);
5058 #endif
5059
5060 ndomod_enddata_serialize(&dbuf);
5061
5062 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
5063
5064 ndo_dbuf_free(&dbuf);
5065 }
5066
5067
5068 /****** dump host dependency config ******/
5069 #ifdef BUILD_NAGIOS_4X
5070 for(x=0; x<num_objects.hostdependencies; x++) {
5071 temp_hostdependency=hostdependency_ary[ x];
5072 #else
5073 for(temp_hostdependency=hostdependency_list;temp_hostdependency!=NULL;temp_hostdependency=temp_hostdependency->next){
5074 #endif
5075
5076 es[0]=ndo_escape_buffer(temp_hostdependency->host_name);
5077 es[1]=ndo_escape_buffer(temp_hostdependency->dependent_host_name);
5078
5079 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
5080 es[2]=ndo_escape_buffer(temp_hostdependency->dependency_period);
5081 #endif
5082 #ifdef BUILD_NAGIOS_2X
5083 es[2]=NULL;
5084 #endif
5085
5086 {
5087 struct ndo_broker_data hostdependency_definition[] = {
5088 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
5089 { .timestamp = now }},
5090 { NDO_DATA_HOSTNAME, BD_STRING,
5091 { .string = (es[0]==NULL) ? "" : es[0] }},
5092 { NDO_DATA_DEPENDENTHOSTNAME, BD_STRING,
5093 { .string = (es[1]==NULL) ? "" : es[1] }},
5094 { NDO_DATA_DEPENDENCYTYPE, BD_INT,
5095 { .integer = temp_hostdependency->dependency_type }},
5096 { NDO_DATA_INHERITSPARENT, BD_INT,
5097 { .integer = temp_hostdependency->inherits_parent }},
5098 { NDO_DATA_DEPENDENCYPERIOD, BD_STRING,
5099 { .string = (es[2]==NULL) ? "" : es[2] }},
5100 { NDO_DATA_FAILONUP, BD_INT,
5101 { .integer =
5102 #ifdef BUILD_NAGIOS_4X
5103 flag_isset(temp_hostdependency->failure_options,
5104 OPT_UP)
5105 #else
5106 temp_hostdependency->fail_on_up
5107 #endif
5108 }},
5109 { NDO_DATA_FAILONDOWN, BD_INT,
5110 { .integer =
5111 #ifdef BUILD_NAGIOS_4X
5112 flag_isset(temp_hostdependency->failure_options,
5113 OPT_DOWN)
5114 #else
5115 temp_hostdependency->fail_on_down
5116 #endif
5117 }},
5118 { NDO_DATA_FAILONUNREACHABLE, BD_INT,
5119 { .integer =
5120 #ifdef BUILD_NAGIOS_4X
5121 flag_isset(temp_hostdependency->failure_options,
5122 OPT_UNREACHABLE)
5123 #else
5124 temp_hostdependency->fail_on_unreachable
5125 #endif
5126 }},
5127 };
5128
5129 ndomod_broker_data_serialize(&dbuf,
5130 NDO_API_HOSTDEPENDENCYDEFINITION,
5131 hostdependency_definition,
5132 sizeof(hostdependency_definition) /
5133 sizeof(hostdependency_definition[ 0]), TRUE);
5134
5135 ndomod_free_esc_buffers(es, 3);
5136 }
5137
5138 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
5139
5140 ndo_dbuf_free(&dbuf);
5141 }
5142
5143
5144 /****** dump service dependency config ******/
5145 #ifdef BUILD_NAGIOS_4X
5146 for(x=0; x<num_objects.servicedependencies; x++) {
5147 temp_servicedependency=servicedependency_ary[ x];
5148 #else
5149 for(temp_servicedependency=servicedependency_list;temp_servicedependency!=NULL;temp_servicedependency=temp_servicedependency->next){
5150 #endif
5151
5152 es[0]=ndo_escape_buffer(temp_servicedependency->host_name);
5153 es[1]=ndo_escape_buffer(temp_servicedependency->service_description);
5154 es[2]=ndo_escape_buffer(temp_servicedependency->dependent_host_name);
5155 es[3]=ndo_escape_buffer(temp_servicedependency->dependent_service_description);
5156
5157 #if ( defined( BUILD_NAGIOS_3X) || defined( BUILD_NAGIOS_4X))
5158 es[4]=ndo_escape_buffer(temp_servicedependency->dependency_period);
5159 #endif
5160 #ifdef BUILD_NAGIOS_2X
5161 es[4]=NULL;
5162 #endif
5163
5164 {
5165 struct ndo_broker_data servicedependency_definition[] = {
5166 { NDO_DATA_TIMESTAMP, BD_TIMEVAL,
5167 { .timestamp = now }},
5168 { NDO_DATA_HOSTNAME, BD_STRING,
5169 { .string = (es[0]==NULL) ? "" : es[0] }},
5170 { NDO_DATA_SERVICEDESCRIPTION, BD_STRING,
5171 { .string = (es[1]==NULL) ? "" : es[1] }},
5172 { NDO_DATA_DEPENDENTHOSTNAME, BD_STRING,
5173 { .string = (es[2]==NULL) ? "" : es[2] }},
5174 { NDO_DATA_DEPENDENTSERVICEDESCRIPTION, BD_STRING,
5175 { .string = (es[3]==NULL) ? "" : es[3] }},
5176 { NDO_DATA_DEPENDENCYTYPE, BD_INT,
5177 { .integer = temp_servicedependency->dependency_type }},
5178 { NDO_DATA_INHERITSPARENT, BD_INT,
5179 { .integer = temp_servicedependency->inherits_parent }},
5180 { NDO_DATA_DEPENDENCYPERIOD, BD_STRING,
5181 { .string = (es[4]==NULL) ? "" : es[4] }},
5182 { NDO_DATA_FAILONOK, BD_INT,
5183 { .integer =
5184 #ifdef BUILD_NAGIOS_4X
5185 flag_isset(temp_servicedependency->failure_options,
5186 OPT_OK)
5187 #else
5188 temp_servicedependency->fail_on_ok
5189 #endif
5190 }},
5191 { NDO_DATA_FAILONWARNING, BD_INT,
5192 { .integer =
5193 #ifdef BUILD_NAGIOS_4X
5194 flag_isset(temp_servicedependency->failure_options,
5195 OPT_WARNING)
5196 #else
5197 temp_servicedependency->fail_on_warning
5198 #endif
5199 }},
5200 { NDO_DATA_FAILONUNKNOWN, BD_INT,
5201 { .integer =
5202 #ifdef BUILD_NAGIOS_4X
5203 flag_isset(temp_servicedependency->failure_options,
5204 OPT_UNKNOWN)
5205 #else
5206 temp_servicedependency->fail_on_unknown
5207 #endif
5208 }},
5209 { NDO_DATA_FAILONCRITICAL, BD_INT,
5210 { .integer =
5211 #ifdef BUILD_NAGIOS_4X
5212 flag_isset(temp_servicedependency->failure_options,
5213 OPT_CRITICAL)
5214 #else
5215 temp_servicedependency->fail_on_critical
5216 #endif
5217 }},
5218 };
5219
5220 ndomod_broker_data_serialize(&dbuf,
5221 NDO_API_SERVICEDEPENDENCYDEFINITION,
5222 servicedependency_definition,
5223 sizeof(servicedependency_definition) /
5224 sizeof(servicedependency_definition[ 0]), TRUE);
5225
5226 ndomod_free_esc_buffers(es, 5);
5227 }
5228
5229 ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);
5230
5231 ndo_dbuf_free(&dbuf);
5232 }
5233
5234
5235 return NDO_OK;
5236 }
5237
5238
5239
5240 /* Dumps config files to the data sink. */
5241 int ndomod_write_config_files(void) {
5242 return ndomod_write_main_config_file();
5243 }
5244
5245
5246 /* dumps main config file data to sink */
5247 int ndomod_write_main_config_file(void){
5248 char fbuf[NDOMOD_MAX_BUFLEN];
5249 char *temp_buffer;
5250 struct timeval now;
5251 FILE *fp;
5252 char *var=NULL;
5253 char *val=NULL;
5254
5255 /* get current time */
5256 gettimeofday(&now,NULL);
5257
5258 asprintf(&temp_buffer
5259 ,"\n%d:\n%d=%ld.%06ld\n%d=%s\n"
5260 ,NDO_API_MAINCONFIGFILEVARIABLES
5261 ,NDO_DATA_TIMESTAMP
5262 ,now.tv_sec
5263 ,now.tv_usec
5264 ,NDO_DATA_CONFIGFILENAME
5265 ,config_file
5266 );
5267 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
5268 free(temp_buffer);
5269 temp_buffer=NULL;
5270
5271 /* write each var/val pair from config file */
5272 if((fp=fopen(config_file,"r"))){
5273
5274 while((fgets(fbuf,sizeof(fbuf),fp))){
5275
5276 /* skip blank lines */
5277 if(fbuf[0]=='\x0' || fbuf[0]=='\n' || fbuf[0]=='\r')
5278 continue;
5279
5280 strip(fbuf);
5281
5282 /* skip comments */
5283 if(fbuf[0]=='#' || fbuf[0]==';')
5284 continue;
5285
5286 if((var=strtok(fbuf,"="))==NULL)
5287 continue;
5288 val=strtok(NULL,"\n");
5289
5290 asprintf(&temp_buffer
5291 ,"%d=%s=%s\n"
5292 ,NDO_DATA_CONFIGFILEVARIABLE
5293 ,var
5294 ,(val==NULL)?"":val
5295 );
5296 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
5297 free(temp_buffer);
5298 temp_buffer=NULL;
5299 }
5300
5301 fclose(fp);
5302 }
5303
5304 asprintf(&temp_buffer
5305 ,"%d\n\n"
5306 ,NDO_API_ENDDATA
5307 );
5308 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
5309 free(temp_buffer);
5310 temp_buffer=NULL;
5311
5312 return NDO_OK;
5313 }
5314
5315
5316
5317 /* dumps runtime variables to sink */
5318 int ndomod_write_runtime_variables(void){
5319 char *temp_buffer=NULL;
5320 struct timeval now;
5321
5322 /* get current time */
5323 gettimeofday(&now,NULL);
5324
5325 asprintf(&temp_buffer
5326 ,"\n%d:\n%d=%ld.%06ld\n"
5327 ,NDO_API_RUNTIMEVARIABLES
5328 ,NDO_DATA_TIMESTAMP
5329 ,now.tv_sec
5330 ,now.tv_usec
5331 );
5332 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
5333 free(temp_buffer);
5334 temp_buffer=NULL;
5335
5336 /* write out main config file name */
5337 asprintf(&temp_buffer
5338 ,"%d=%s=%s\n"
5339 ,NDO_DATA_RUNTIMEVARIABLE
5340 ,"config_file"
5341 ,config_file
5342 );
5343 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
5344 free(temp_buffer);
5345 temp_buffer=NULL;
5346
5347 /* write out vars determined after startup */
5348 asprintf(&temp_buffer
5349 ,"%d=%s=%d\n%d=%s=%d\n%d=%s=%d\n%d=%s=%d\n%d=%s=%lf\n%d=%s=%lf\n%d=%s=%lu\n%d=%s=%lu\n%d=%s=%lf\n%d=%s=%lf\n%d=%s=%lf\n%d=%s=%lf\n%d=%s=%lf\n%d=%s=%lf\n%d=%s=%d\n%d=%s=%d\n%d=%s=%d\n"
5350 ,NDO_DATA_RUNTIMEVARIABLE
5351 ,"total_services"
5352 ,scheduling_info.total_services
5353 ,NDO_DATA_RUNTIMEVARIABLE
5354 ,"total_scheduled_services"
5355 ,scheduling_info.total_scheduled_services
5356 ,NDO_DATA_RUNTIMEVARIABLE
5357 ,"total_hosts"
5358 ,scheduling_info.total_hosts
5359 ,NDO_DATA_RUNTIMEVARIABLE
5360 ,"total_scheduled_hosts"
5361 ,scheduling_info.total_scheduled_hosts
5362 ,NDO_DATA_RUNTIMEVARIABLE
5363 ,"average_services_per_host"
5364 ,scheduling_info.average_services_per_host
5365 ,NDO_DATA_RUNTIMEVARIABLE
5366 ,"average_scheduled_services_per_host"
5367 ,scheduling_info.average_scheduled_services_per_host
5368 ,NDO_DATA_RUNTIMEVARIABLE
5369 ,"service_check_interval_total"
5370 ,scheduling_info.service_check_interval_total
5371 ,NDO_DATA_RUNTIMEVARIABLE
5372 ,"host_check_interval_total"
5373 ,scheduling_info.host_check_interval_total
5374 ,NDO_DATA_RUNTIMEVARIABLE
5375 ,"average_service_check_interval"
5376 ,scheduling_info.average_service_check_interval
5377 ,NDO_DATA_RUNTIMEVARIABLE
5378 ,"average_host_check_interval"
5379 ,scheduling_info.average_host_check_interval
5380 ,NDO_DATA_RUNTIMEVARIABLE
5381 ,"average_service_inter_check_delay"
5382 ,scheduling_info.average_service_inter_check_delay
5383 ,NDO_DATA_RUNTIMEVARIABLE
5384 ,"average_host_inter_check_delay"
5385 ,scheduling_info.average_host_inter_check_delay
5386 ,NDO_DATA_RUNTIMEVARIABLE
5387 ,"service_inter_check_delay"
5388 ,scheduling_info.service_inter_check_delay
5389 ,NDO_DATA_RUNTIMEVARIABLE
5390 ,"host_inter_check_delay"
5391 ,scheduling_info.host_inter_check_delay
5392 ,NDO_DATA_RUNTIMEVARIABLE
5393 ,"service_interleave_factor"
5394 ,scheduling_info.service_interleave_factor
5395 ,NDO_DATA_RUNTIMEVARIABLE
5396 ,"max_service_check_spread"
5397 ,scheduling_info.max_service_check_spread
5398 ,NDO_DATA_RUNTIMEVARIABLE
5399 ,"max_host_check_spread"
5400 ,scheduling_info.max_host_check_spread
5401 );
5402 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
5403 free(temp_buffer);
5404 temp_buffer=NULL;
5405
5406 asprintf(&temp_buffer
5407 ,"%d\n\n"
5408 ,NDO_API_ENDDATA
5409 );
5410 ndomod_write_to_sink(temp_buffer,NDO_TRUE,NDO_TRUE);
5411 free(temp_buffer);
5412 temp_buffer=NULL;
5413
5414 return NDO_OK;
5415 }
5416
5417
5418
5419