Icinga-core 1.4.0
next gen monitoring
base/broker.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * BROKER.C - Event broker routines for Icinga
00004  *
00005  * Copyright (c) 2002-2008 Ethan Galstad (egalstad@nagios.org)
00006  * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
00007  * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
00008  *
00009  * License:
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License version 2 as
00013  * published by the Free Software Foundation.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023  *
00024  *****************************************************************************/
00025 
00026 #include "../include/config.h"
00027 #include "../include/common.h"
00028 
00029 #include "../include/icinga.h"
00030 #include "../include/broker.h"
00031 #include "../include/nebcallbacks.h"
00032 #include "../include/nebstructs.h"
00033 #include "../include/nebmods.h"
00034 
00035 extern unsigned long event_broker_options;
00036 
00037 extern time_t program_start;
00038 extern int nagios_pid;
00039 extern int daemon_mode;
00040 extern time_t last_command_check;
00041 extern time_t last_log_rotation;
00042 extern int enable_notifications;
00043 extern int execute_service_checks;
00044 extern int accept_passive_service_checks;
00045 extern int execute_host_checks;
00046 extern int accept_passive_host_checks;
00047 extern int enable_event_handlers;
00048 extern int obsess_over_services;
00049 extern int obsess_over_hosts;
00050 extern int enable_flap_detection;
00051 extern int enable_failure_prediction;
00052 extern int process_performance_data;
00053 extern int aggregate_status_updates;
00054 extern unsigned long modified_host_process_attributes;
00055 extern unsigned long modified_service_process_attributes;
00056 extern char *global_host_event_handler;
00057 extern char *global_service_event_handler;
00058 
00059 
00060 #ifdef USE_EVENT_BROKER
00061 
00062 
00063 
00064 /******************************************************************/
00065 /************************* EVENT FUNCTIONS ************************/
00066 /******************************************************************/
00067 
00068 
00069 /* sends program data (starts, restarts, stops, etc.) to broker */
00070 void broker_program_state(int type, int flags, int attr, struct timeval *timestamp){
00071         nebstruct_process_data ds;
00072 
00073         if(!(event_broker_options & BROKER_PROGRAM_STATE))
00074                 return;
00075 
00076         /* fill struct with relevant data */
00077         ds.type=type;
00078         ds.flags=flags;
00079         ds.attr=attr;
00080         ds.timestamp=get_broker_timestamp(timestamp);
00081 
00082         /* make callbacks */
00083         neb_make_callbacks(NEBCALLBACK_PROCESS_DATA,(void *)&ds);
00084 
00085         return;
00086         }
00087 
00088 
00089 /* send timed event data to broker */
00090 void broker_timed_event(int type, int flags, int attr, timed_event *event, struct timeval *timestamp){
00091         nebstruct_timed_event_data ds;
00092 
00093         if(!(event_broker_options & BROKER_TIMED_EVENTS))
00094                 return;
00095 
00096         if(event==NULL)
00097                 return;
00098 
00099         /* fill struct with relevant data */
00100         ds.type=type;
00101         ds.flags=flags;
00102         ds.attr=attr;
00103         ds.timestamp=get_broker_timestamp(timestamp);
00104 
00105         ds.event_type=event->event_type;
00106         ds.recurring=event->recurring;
00107         ds.run_time=event->run_time;
00108         ds.event_data=event->event_data;
00109         ds.event_ptr=(void *)event;
00110 
00111         /* make callbacks */
00112         neb_make_callbacks(NEBCALLBACK_TIMED_EVENT_DATA,(void *)&ds);
00113 
00114         return;
00115         }
00116 
00117 
00118 
00119 /* send log data to broker */
00120 void broker_log_data(int type, int flags, int attr, char *data, unsigned long data_type, time_t entry_time, struct timeval *timestamp){
00121         nebstruct_log_data ds;
00122 
00123         if(!(event_broker_options & BROKER_LOGGED_DATA))
00124                 return;
00125 
00126         /* fill struct with relevant data */
00127         ds.type=type;
00128         ds.flags=flags;
00129         ds.attr=attr;
00130         ds.timestamp=get_broker_timestamp(timestamp);
00131 
00132         ds.entry_time=entry_time;
00133         ds.data_type=data_type;
00134         ds.data=data;
00135 
00136         /* make callbacks */
00137         neb_make_callbacks(NEBCALLBACK_LOG_DATA,(void *)&ds);
00138 
00139         return;
00140         }
00141 
00142 
00143 
00144 /* send system command data to broker */
00145 void broker_system_command(int type, int flags, int attr, struct timeval start_time, struct timeval end_time, double exectime, int timeout, int early_timeout, int retcode, char *cmd, char *output, struct timeval *timestamp){
00146         nebstruct_system_command_data ds;
00147 
00148         if(!(event_broker_options & BROKER_SYSTEM_COMMANDS))
00149                 return;
00150         
00151         if(cmd==NULL)
00152                 return;
00153 
00154         /* fill struct with relevant data */
00155         ds.type=type;
00156         ds.flags=flags;
00157         ds.attr=attr;
00158         ds.timestamp=get_broker_timestamp(timestamp);
00159 
00160         ds.start_time=start_time;
00161         ds.end_time=end_time;
00162         ds.timeout=timeout;
00163         ds.command_line=cmd;
00164         ds.early_timeout=early_timeout;
00165         ds.execution_time=exectime;
00166         ds.return_code=retcode;
00167         ds.output=output;
00168 
00169         /* make callbacks */
00170         neb_make_callbacks(NEBCALLBACK_SYSTEM_COMMAND_DATA,(void *)&ds);
00171 
00172         return;
00173         }
00174 
00175 
00176 
00177 /* send event handler data to broker */
00178 int broker_event_handler(int type, int flags, int attr, int eventhandler_type, void *data, int state, int state_type, struct timeval start_time, struct timeval end_time, double exectime, int timeout, int early_timeout, int retcode, char *cmd, char *cmdline, char *output, struct timeval *timestamp){
00179         service *temp_service=NULL;
00180         host *temp_host=NULL;
00181         char *command_buf=NULL;
00182         char *command_name=NULL;
00183         char *command_args=NULL;
00184         nebstruct_event_handler_data ds;
00185         int return_code=OK;
00186 
00187         if(!(event_broker_options & BROKER_EVENT_HANDLERS))
00188                 return OK;
00189         
00190         if(data==NULL)
00191                 return ERROR;
00192 
00193         /* get command name/args */
00194         if(cmd!=NULL){
00195                 command_buf=(char *)strdup(cmd);
00196                 command_name=strtok(command_buf,"!");
00197                 command_args=strtok(NULL,"\x0");
00198                 }
00199 
00200         /* fill struct with relevant data */
00201         ds.type=type;
00202         ds.flags=flags;
00203         ds.attr=attr;
00204         ds.timestamp=get_broker_timestamp(timestamp);
00205 
00206         ds.eventhandler_type=eventhandler_type;
00207         if(eventhandler_type==SERVICE_EVENTHANDLER || eventhandler_type==GLOBAL_SERVICE_EVENTHANDLER){
00208                 temp_service=(service *)data;
00209                 ds.host_name=temp_service->host_name;
00210                 ds.service_description=temp_service->description;
00211                 }
00212         else{
00213                 temp_host=(host *)data;
00214                 ds.host_name=temp_host->name;
00215                 ds.service_description=NULL;
00216                 }
00217         ds.object_ptr=data;
00218         ds.state=state;
00219         ds.state_type=state_type;
00220         ds.start_time=start_time;
00221         ds.end_time=end_time;
00222         ds.timeout=timeout;
00223         ds.command_name=command_name;
00224         ds.command_args=command_args;
00225         ds.command_line=cmdline;
00226         ds.early_timeout=early_timeout;
00227         ds.execution_time=exectime;
00228         ds.return_code=retcode;
00229         ds.output=output;
00230 
00231         /* make callbacks */
00232         return_code=neb_make_callbacks(NEBCALLBACK_EVENT_HANDLER_DATA,(void *)&ds);
00233 
00234         /* free memory */
00235         my_free(command_buf);
00236 
00237         return return_code;
00238         }
00239 
00240 
00241 
00242 
00243 /* send host check data to broker */
00244 int broker_host_check(int type, int flags, int attr, host *hst, int check_type, int state, int state_type, struct timeval start_time, struct timeval end_time, char *cmd, double latency, double exectime, int timeout, int early_timeout, int retcode, char *cmdline, char *output, char *long_output, char *perfdata, struct timeval *timestamp){
00245         char *command_buf=NULL;
00246         char *command_name=NULL;
00247         char *command_args=NULL;
00248         nebstruct_host_check_data ds;
00249         int return_code=OK;
00250 
00251         if(!(event_broker_options & BROKER_HOST_CHECKS))
00252                 return OK;
00253         
00254         if(hst==NULL)
00255                 return ERROR;
00256 
00257         /* get command name/args */
00258         if(cmd!=NULL){
00259                 command_buf=(char *)strdup(cmd);
00260                 command_name=strtok(command_buf,"!");
00261                 command_args=strtok(NULL,"\x0");
00262                 }
00263 
00264         /* fill struct with relevant data */
00265         ds.type=type;
00266         ds.flags=flags;
00267         ds.attr=attr;
00268         ds.timestamp=get_broker_timestamp(timestamp);
00269 
00270         ds.host_name=hst->name;
00271         ds.object_ptr=(void *)hst;
00272         ds.check_type=check_type;
00273         ds.current_attempt=hst->current_attempt;
00274         ds.max_attempts=hst->max_attempts;
00275         ds.state=state;
00276         ds.state_type=state_type;
00277         ds.timeout=timeout;
00278         ds.command_name=command_name;
00279         ds.command_args=command_args;
00280         ds.command_line=cmdline;
00281         ds.start_time=start_time;
00282         ds.end_time=end_time;
00283         ds.early_timeout=early_timeout;
00284         ds.execution_time=exectime;
00285         ds.latency=latency;
00286         ds.return_code=retcode;
00287         ds.output=output;
00288         ds.long_output=long_output;
00289         ds.perf_data=perfdata;
00290 
00291         /* make callbacks */
00292         return_code=neb_make_callbacks(NEBCALLBACK_HOST_CHECK_DATA,(void *)&ds);
00293 
00294         /* free data */
00295         my_free(command_buf);
00296 
00297         return return_code;
00298         }
00299 
00300 
00301 
00302 /* send service check data to broker */
00303 int broker_service_check(int type, int flags, int attr, service *svc, int check_type, struct timeval start_time, struct timeval end_time, char *cmd, double latency, double exectime, int timeout, int early_timeout, int retcode, char *cmdline, struct timeval *timestamp){
00304         char *command_buf=NULL;
00305         char *command_name=NULL;
00306         char *command_args=NULL;
00307         nebstruct_service_check_data ds;
00308         int return_code=OK;
00309 
00310         if(!(event_broker_options & BROKER_SERVICE_CHECKS))
00311                 return OK;
00312         
00313         if(svc==NULL)
00314                 return ERROR;
00315 
00316         /* get command name/args */
00317         if(cmd!=NULL){
00318                 command_buf=(char *)strdup(cmd);
00319                 command_name=strtok(command_buf,"!");
00320                 command_args=strtok(NULL,"\x0");
00321                 }
00322 
00323         /* fill struct with relevant data */
00324         ds.type=type;
00325         ds.flags=flags;
00326         ds.attr=attr;
00327         ds.timestamp=get_broker_timestamp(timestamp);
00328 
00329         ds.host_name=svc->host_name;
00330         ds.service_description=svc->description;
00331         ds.object_ptr=(void *)svc;
00332         ds.check_type=check_type;
00333         ds.current_attempt=svc->current_attempt;
00334         ds.max_attempts=svc->max_attempts;
00335         ds.state=svc->current_state;
00336         ds.state_type=svc->state_type;
00337         ds.timeout=timeout;
00338         ds.command_name=command_name;
00339         ds.command_args=command_args;
00340         ds.command_line=cmdline;
00341         ds.start_time=start_time;
00342         ds.end_time=end_time;
00343         ds.early_timeout=early_timeout;
00344         ds.execution_time=exectime;
00345         ds.latency=latency;
00346         ds.return_code=retcode;
00347         ds.output=svc->plugin_output;
00348         ds.long_output=svc->long_plugin_output;
00349         ds.perf_data=svc->perf_data;
00350 
00351         /* make callbacks */
00352         return_code=neb_make_callbacks(NEBCALLBACK_SERVICE_CHECK_DATA,(void *)&ds);
00353 
00354         /* free data */
00355         my_free(command_buf);
00356 
00357         return return_code;
00358         }
00359 
00360 
00361 
00362 /* send comment data to broker */
00363 void broker_comment_data(int type, int flags, int attr, int comment_type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long comment_id, struct timeval *timestamp){
00364         nebstruct_comment_data ds;
00365 
00366         if(!(event_broker_options & BROKER_COMMENT_DATA))
00367                 return;
00368         
00369         /* fill struct with relevant data */
00370         ds.type=type;
00371         ds.flags=flags;
00372         ds.attr=attr;
00373         ds.timestamp=get_broker_timestamp(timestamp);
00374 
00375         ds.comment_type=comment_type;
00376         ds.entry_type=entry_type;
00377         ds.host_name=host_name;
00378         ds.service_description=svc_description;
00379         ds.object_ptr=NULL; /* not implemented yet */
00380         ds.entry_time=entry_time;
00381         ds.author_name=author_name;
00382         ds.comment_data=comment_data;
00383         ds.persistent=persistent;
00384         ds.source=source;
00385         ds.expires=expires;
00386         ds.expire_time=expire_time;
00387         ds.comment_id=comment_id;
00388 
00389         /* make callbacks */
00390         neb_make_callbacks(NEBCALLBACK_COMMENT_DATA,(void *)&ds);
00391 
00392         return;
00393         }
00394 
00395 
00396 
00397 /* send downtime data to broker */
00398 void broker_downtime_data(int type, int flags, int attr, int downtime_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, struct timeval *timestamp){
00399         nebstruct_downtime_data ds;
00400 
00401         if(!(event_broker_options & BROKER_DOWNTIME_DATA))
00402                 return;
00403         
00404         /* fill struct with relevant data */
00405         ds.type=type;
00406         ds.flags=flags;
00407         ds.attr=attr;
00408         ds.timestamp=get_broker_timestamp(timestamp);
00409 
00410         ds.downtime_type=downtime_type;
00411         ds.host_name=host_name;
00412         ds.service_description=svc_description;
00413         ds.object_ptr=NULL; /* not implemented yet */
00414         ds.entry_time=entry_time;
00415         ds.author_name=author_name;
00416         ds.comment_data=comment_data;
00417         ds.start_time=start_time;
00418         ds.end_time=end_time;
00419         ds.fixed=fixed;
00420         ds.duration=duration;
00421         ds.triggered_by=triggered_by;
00422         ds.downtime_id=downtime_id;
00423 
00424         /* make callbacks */
00425         neb_make_callbacks(NEBCALLBACK_DOWNTIME_DATA,(void *)&ds);
00426 
00427         return;
00428         }
00429 
00430 
00431 
00432 /* send flapping data to broker */
00433 void broker_flapping_data(int type, int flags, int attr, int flapping_type, void *data, double percent_change, double high_threshold, double low_threshold, struct timeval *timestamp){
00434         nebstruct_flapping_data ds;
00435         host *temp_host=NULL;
00436         service *temp_service=NULL;
00437 
00438         if(!(event_broker_options & BROKER_FLAPPING_DATA))
00439                 return;
00440 
00441         if(data==NULL)
00442                 return;
00443 
00444         /* fill struct with relevant data */
00445         ds.type=type;
00446         ds.flags=flags;
00447         ds.attr=attr;
00448         ds.timestamp=get_broker_timestamp(timestamp);
00449 
00450         ds.flapping_type=flapping_type;
00451         if(flapping_type==SERVICE_FLAPPING){
00452                 temp_service=(service *)data;
00453                 ds.host_name=temp_service->host_name;
00454                 ds.service_description=temp_service->description;
00455                 ds.comment_id=temp_service->flapping_comment_id;
00456                 }
00457         else{
00458                 temp_host=(host *)data;
00459                 ds.host_name=temp_host->name;
00460                 ds.service_description=NULL;
00461                 ds.comment_id=temp_host->flapping_comment_id;
00462                 }
00463         ds.object_ptr=data;
00464         ds.percent_change=percent_change;
00465         ds.high_threshold=high_threshold;
00466         ds.low_threshold=low_threshold;
00467 
00468         /* make callbacks */
00469         neb_make_callbacks(NEBCALLBACK_FLAPPING_DATA,(void *)&ds);
00470 
00471         return;
00472         }
00473 
00474 
00475 /* sends program status updates to broker */
00476 void broker_program_status(int type, int flags, int attr, struct timeval *timestamp){
00477         nebstruct_program_status_data ds;
00478 
00479         if(!(event_broker_options & BROKER_STATUS_DATA))
00480                 return;
00481 
00482         /* fill struct with relevant data */
00483         ds.type=type;
00484         ds.flags=flags;
00485         ds.attr=attr;
00486         ds.timestamp=get_broker_timestamp(timestamp);
00487 
00488         ds.program_start=program_start;
00489         ds.pid=nagios_pid;
00490         ds.daemon_mode=daemon_mode;
00491         ds.last_command_check=last_command_check;
00492         ds.last_log_rotation=last_log_rotation;
00493         ds.notifications_enabled=enable_notifications;
00494         ds.active_service_checks_enabled=execute_service_checks;
00495         ds.passive_service_checks_enabled=accept_passive_service_checks;
00496         ds.active_host_checks_enabled=execute_host_checks;
00497         ds.passive_host_checks_enabled=accept_passive_host_checks;
00498         ds.event_handlers_enabled=enable_event_handlers;
00499         ds.flap_detection_enabled=enable_flap_detection;
00500         ds.failure_prediction_enabled=enable_failure_prediction;
00501         ds.process_performance_data=process_performance_data;
00502         ds.obsess_over_hosts=obsess_over_hosts;
00503         ds.obsess_over_services=obsess_over_services;
00504         ds.modified_host_attributes=modified_host_process_attributes;
00505         ds.modified_service_attributes=modified_service_process_attributes;
00506         ds.global_host_event_handler=global_host_event_handler;
00507         ds.global_service_event_handler=global_service_event_handler;
00508 
00509         /* make callbacks */
00510         neb_make_callbacks(NEBCALLBACK_PROGRAM_STATUS_DATA,(void *)&ds);
00511 
00512         return;
00513         }
00514 
00515 
00516 
00517 /* sends host status updates to broker */
00518 void broker_host_status(int type, int flags, int attr, host *hst, struct timeval *timestamp){
00519         nebstruct_host_status_data ds;
00520 
00521         if(!(event_broker_options & BROKER_STATUS_DATA))
00522                 return;
00523 
00524         /* fill struct with relevant data */
00525         ds.type=type;
00526         ds.flags=flags;
00527         ds.attr=attr;
00528         ds.timestamp=get_broker_timestamp(timestamp);
00529 
00530         ds.object_ptr=(void *)hst;
00531 
00532         /* make callbacks */
00533         neb_make_callbacks(NEBCALLBACK_HOST_STATUS_DATA,(void *)&ds);
00534 
00535         return;
00536         }
00537 
00538 
00539 
00540 /* sends service status updates to broker */
00541 void broker_service_status(int type, int flags, int attr, service *svc, struct timeval *timestamp){
00542         nebstruct_service_status_data ds;
00543 
00544         if(!(event_broker_options & BROKER_STATUS_DATA))
00545                 return;
00546 
00547         /* fill struct with relevant data */
00548         ds.type=type;
00549         ds.flags=flags;
00550         ds.attr=attr;
00551         ds.timestamp=get_broker_timestamp(timestamp);
00552 
00553         ds.object_ptr=(void *)svc;
00554 
00555         /* make callbacks */
00556         neb_make_callbacks(NEBCALLBACK_SERVICE_STATUS_DATA,(void *)&ds);
00557 
00558         return;
00559         }
00560 
00561 
00562 
00563 /* sends contact status updates to broker */
00564 void broker_contact_status(int type, int flags, int attr, contact *cntct, struct timeval *timestamp){
00565         nebstruct_service_status_data ds;
00566 
00567         if(!(event_broker_options & BROKER_STATUS_DATA))
00568                 return;
00569 
00570         /* fill struct with relevant data */
00571         ds.type=type;
00572         ds.flags=flags;
00573         ds.attr=attr;
00574         ds.timestamp=get_broker_timestamp(timestamp);
00575 
00576         ds.object_ptr=(void *)cntct;
00577 
00578         /* make callbacks */
00579         neb_make_callbacks(NEBCALLBACK_CONTACT_STATUS_DATA,(void *)&ds);
00580 
00581         return;
00582         }
00583 
00584 
00585 
00586 /* send notification data to broker */
00587 int broker_notification_data(int type, int flags, int attr, int notification_type, int reason_type, struct timeval start_time, struct timeval end_time, void *data, char *ack_author, char *ack_data, int escalated, int contacts_notified, struct timeval *timestamp){
00588         nebstruct_notification_data ds;
00589         host *temp_host=NULL;
00590         service *temp_service=NULL;
00591         int return_code=OK;
00592 
00593         if(!(event_broker_options & BROKER_NOTIFICATIONS))
00594                 return return_code;
00595 
00596         /* fill struct with relevant data */
00597         ds.type=type;
00598         ds.flags=flags;
00599         ds.attr=attr;
00600         ds.timestamp=get_broker_timestamp(timestamp);
00601 
00602         ds.notification_type=notification_type;
00603         ds.start_time=start_time;
00604         ds.end_time=end_time;
00605         ds.reason_type=reason_type;
00606         if(notification_type==SERVICE_NOTIFICATION){
00607                 temp_service=(service *)data;
00608                 ds.host_name=temp_service->host_name;
00609                 ds.service_description=temp_service->description;
00610                 ds.state=temp_service->current_state;
00611                 ds.output=temp_service->plugin_output;
00612                 }
00613         else{
00614                 temp_host=(host *)data;
00615                 ds.host_name=temp_host->name;
00616                 ds.service_description=NULL;
00617                 ds.state=temp_host->current_state;
00618                 ds.output=temp_host->plugin_output;
00619                 }
00620         ds.object_ptr=data;
00621         ds.ack_author=ack_author;
00622         ds.ack_data=ack_data;
00623         ds.escalated=escalated;
00624         ds.contacts_notified=contacts_notified;
00625 
00626         /* make callbacks */
00627         return_code=neb_make_callbacks(NEBCALLBACK_NOTIFICATION_DATA,(void *)&ds);
00628 
00629         return return_code;
00630         }
00631 
00632 
00633 
00634 /* send contact notification data to broker */
00635 int broker_contact_notification_data(int type, int flags, int attr, int notification_type, int reason_type, struct timeval start_time, struct timeval end_time, void *data, contact *cntct, char *ack_author, char *ack_data, int escalated, struct timeval *timestamp){
00636         nebstruct_contact_notification_data ds;
00637         host *temp_host=NULL;
00638         service *temp_service=NULL;
00639         int return_code=OK;
00640 
00641         if(!(event_broker_options & BROKER_NOTIFICATIONS))
00642                 return return_code;
00643 
00644         /* fill struct with relevant data */
00645         ds.type=type;
00646         ds.flags=flags;
00647         ds.attr=attr;
00648         ds.timestamp=get_broker_timestamp(timestamp);
00649 
00650         ds.notification_type=notification_type;
00651         ds.start_time=start_time;
00652         ds.end_time=end_time;
00653         ds.reason_type=reason_type;
00654         ds.contact_name=cntct->name;
00655         if(notification_type==SERVICE_NOTIFICATION){
00656                 temp_service=(service *)data;
00657                 ds.host_name=temp_service->host_name;
00658                 ds.service_description=temp_service->description;
00659                 ds.state=temp_service->current_state;
00660                 ds.output=temp_service->plugin_output;
00661                 }
00662         else{
00663                 temp_host=(host *)data;
00664                 ds.host_name=temp_host->name;
00665                 ds.service_description=NULL;
00666                 ds.state=temp_host->current_state;
00667                 ds.output=temp_host->plugin_output;
00668                 }
00669         ds.object_ptr=data;
00670         ds.contact_ptr=(void *)cntct;
00671         ds.ack_author=ack_author;
00672         ds.ack_data=ack_data;
00673         ds.escalated=escalated;
00674 
00675         /* make callbacks */
00676         return_code=neb_make_callbacks(NEBCALLBACK_CONTACT_NOTIFICATION_DATA,(void *)&ds);
00677 
00678         return return_code;
00679         }
00680 
00681 
00682 /* send contact notification data to broker */
00683 int broker_contact_notification_method_data(int type, int flags, int attr, int notification_type, int reason_type, struct timeval start_time, struct timeval end_time, void *data, contact *cntct, char *cmd, char *ack_author, char *ack_data, int escalated, struct timeval *timestamp){
00684         nebstruct_contact_notification_method_data ds;
00685         host *temp_host=NULL;
00686         service *temp_service=NULL;
00687         char *command_buf=NULL;
00688         char *command_name=NULL;
00689         char *command_args=NULL;
00690         int return_code=OK;
00691 
00692         if(!(event_broker_options & BROKER_NOTIFICATIONS))
00693                 return return_code;
00694 
00695         /* get command name/args */
00696         if(cmd!=NULL){
00697                 command_buf=(char *)strdup(cmd);
00698                 command_name=strtok(command_buf,"!");
00699                 command_args=strtok(NULL,"\x0");
00700                 }
00701 
00702         /* fill struct with relevant data */
00703         ds.type=type;
00704         ds.flags=flags;
00705         ds.attr=attr;
00706         ds.timestamp=get_broker_timestamp(timestamp);
00707 
00708         ds.notification_type=notification_type;
00709         ds.start_time=start_time;
00710         ds.end_time=end_time;
00711         ds.reason_type=reason_type;
00712         ds.contact_name=cntct->name;
00713         ds.command_name=command_name;
00714         ds.command_args=command_args;
00715         if(notification_type==SERVICE_NOTIFICATION){
00716                 temp_service=(service *)data;
00717                 ds.host_name=temp_service->host_name;
00718                 ds.service_description=temp_service->description;
00719                 ds.state=temp_service->current_state;
00720                 ds.output=temp_service->plugin_output;
00721                 }
00722         else{
00723                 temp_host=(host *)data;
00724                 ds.host_name=temp_host->name;
00725                 ds.service_description=NULL;
00726                 ds.state=temp_host->current_state;
00727                 ds.output=temp_host->plugin_output;
00728                 }
00729         ds.object_ptr=data;
00730         ds.contact_ptr=(void *)cntct;
00731         ds.ack_author=ack_author;
00732         ds.ack_data=ack_data;
00733         ds.escalated=escalated;
00734 
00735         /* make callbacks */
00736         return_code=neb_make_callbacks(NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA,(void *)&ds);
00737 
00738         /* free memory */
00739         my_free(command_buf);
00740 
00741         return return_code;
00742         }
00743 
00744 
00745 /* sends adaptive programs updates to broker */
00746 void broker_adaptive_program_data(int type, int flags, int attr, int command_type, unsigned long modhattr, unsigned long modhattrs, unsigned long modsattr, unsigned long modsattrs, struct timeval *timestamp){
00747         nebstruct_adaptive_program_data ds;
00748 
00749         if(!(event_broker_options & BROKER_ADAPTIVE_DATA))
00750                 return;
00751 
00752         /* fill struct with relevant data */
00753         ds.type=type;
00754         ds.flags=flags;
00755         ds.attr=attr;
00756         ds.timestamp=get_broker_timestamp(timestamp);
00757 
00758         ds.command_type=command_type;
00759         ds.modified_host_attribute=modhattr;
00760         ds.modified_host_attributes=modhattrs;
00761         ds.modified_service_attribute=modsattr;
00762         ds.modified_service_attributes=modsattrs;
00763 
00764         /* make callbacks */
00765         neb_make_callbacks(NEBCALLBACK_ADAPTIVE_PROGRAM_DATA,(void *)&ds);
00766 
00767         return;
00768         }
00769 
00770 
00771 /* sends adaptive host updates to broker */
00772 void broker_adaptive_host_data(int type, int flags, int attr, host *hst, int command_type, unsigned long modattr, unsigned long modattrs, struct timeval *timestamp){
00773         nebstruct_adaptive_host_data ds;
00774 
00775         if(!(event_broker_options & BROKER_ADAPTIVE_DATA))
00776                 return;
00777 
00778         /* fill struct with relevant data */
00779         ds.type=type;
00780         ds.flags=flags;
00781         ds.attr=attr;
00782         ds.timestamp=get_broker_timestamp(timestamp);
00783 
00784         ds.command_type=command_type;
00785         ds.modified_attribute=modattr;
00786         ds.modified_attributes=modattrs;
00787         ds.object_ptr=(void *)hst;
00788 
00789         /* make callbacks */
00790         neb_make_callbacks(NEBCALLBACK_ADAPTIVE_HOST_DATA,(void *)&ds);
00791 
00792         return;
00793         }
00794 
00795 
00796 /* sends adaptive service updates to broker */
00797 void broker_adaptive_service_data(int type, int flags, int attr, service *svc, int command_type, unsigned long modattr, unsigned long modattrs, struct timeval *timestamp){
00798         nebstruct_adaptive_service_data ds;
00799 
00800         if(!(event_broker_options & BROKER_ADAPTIVE_DATA))
00801                 return;
00802 
00803         /* fill struct with relevant data */
00804         ds.type=type;
00805         ds.flags=flags;
00806         ds.attr=attr;
00807         ds.timestamp=get_broker_timestamp(timestamp);
00808 
00809         ds.command_type=command_type;
00810         ds.modified_attribute=modattr;
00811         ds.modified_attributes=modattrs;
00812         ds.object_ptr=(void *)svc;
00813 
00814         /* make callbacks */
00815         neb_make_callbacks(NEBCALLBACK_ADAPTIVE_SERVICE_DATA,(void *)&ds);
00816 
00817         return;
00818         }
00819 
00820 
00821 /* sends adaptive contact updates to broker */
00822 void broker_adaptive_contact_data(int type, int flags, int attr, contact *cntct, int command_type, unsigned long modattr, unsigned long modattrs, unsigned long modhattr, unsigned long modhattrs, unsigned long modsattr, unsigned long modsattrs, struct timeval *timestamp){
00823         nebstruct_adaptive_contact_data ds;
00824 
00825         if(!(event_broker_options & BROKER_ADAPTIVE_DATA))
00826                 return;
00827 
00828         /* fill struct with relevant data */
00829         ds.type=type;
00830         ds.flags=flags;
00831         ds.attr=attr;
00832         ds.timestamp=get_broker_timestamp(timestamp);
00833 
00834         ds.command_type=command_type;
00835         ds.modified_attribute=modattr;
00836         ds.modified_attributes=modattrs;
00837         ds.modified_host_attribute=modhattr;
00838         ds.modified_host_attributes=modhattrs;
00839         ds.modified_service_attribute=modsattr;
00840         ds.modified_service_attributes=modsattrs;
00841         ds.object_ptr=(void *)cntct;
00842 
00843         /* make callbacks */
00844         neb_make_callbacks(NEBCALLBACK_ADAPTIVE_CONTACT_DATA,(void *)&ds);
00845 
00846         return;
00847         }
00848 
00849 
00850 /* sends external commands to broker */
00851 void broker_external_command(int type, int flags, int attr, int command_type, time_t entry_time, char *command_string, char *command_args, struct timeval *timestamp){
00852         nebstruct_external_command_data ds;
00853 
00854         if(!(event_broker_options & BROKER_EXTERNALCOMMAND_DATA))
00855                 return;
00856 
00857         /* fill struct with relevant data */
00858         ds.type=type;
00859         ds.flags=flags;
00860         ds.attr=attr;
00861         ds.timestamp=get_broker_timestamp(timestamp);
00862 
00863         ds.command_type=command_type;
00864         ds.entry_time=entry_time;
00865         ds.command_string=command_string;
00866         ds.command_args=command_args;
00867 
00868         /* make callbacks */
00869         neb_make_callbacks(NEBCALLBACK_EXTERNAL_COMMAND_DATA,(void *)&ds);
00870 
00871         return;
00872         }
00873 
00874 
00875 /* brokers aggregated status dumps */
00876 void broker_aggregated_status_data(int type, int flags, int attr, struct timeval *timestamp){
00877         nebstruct_aggregated_status_data ds;
00878 
00879         if(!(event_broker_options & BROKER_STATUS_DATA))
00880                 return;
00881 
00882         /* fill struct with relevant data */
00883         ds.type=type;
00884         ds.flags=flags;
00885         ds.attr=attr;
00886         ds.timestamp=get_broker_timestamp(timestamp);
00887 
00888         /* make callbacks */
00889         neb_make_callbacks(NEBCALLBACK_AGGREGATED_STATUS_DATA,(void *)&ds);
00890 
00891         return;
00892         }
00893 
00894 
00895 /* brokers retention data */
00896 void broker_retention_data(int type, int flags, int attr, struct timeval *timestamp){
00897         nebstruct_retention_data ds;
00898 
00899         if(!(event_broker_options & BROKER_RETENTION_DATA))
00900                 return;
00901 
00902         /* fill struct with relevant data */
00903         ds.type=type;
00904         ds.flags=flags;
00905         ds.attr=attr;
00906         ds.timestamp=get_broker_timestamp(timestamp);
00907 
00908         /* make callbacks */
00909         neb_make_callbacks(NEBCALLBACK_RETENTION_DATA,(void *)&ds);
00910 
00911         return;
00912         }
00913 
00914 
00915 /* send acknowledgement data to broker */
00916 void broker_acknowledgement_data(int type, int flags, int attr, int acknowledgement_type, void *data, char *ack_author, char *ack_data, int subtype, int notify_contacts, int persistent_comment, struct timeval *timestamp){
00917         nebstruct_acknowledgement_data ds;
00918         host *temp_host=NULL;
00919         service *temp_service=NULL;
00920 
00921         if(!(event_broker_options & BROKER_ACKNOWLEDGEMENT_DATA))
00922                 return;
00923         
00924         /* fill struct with relevant data */
00925         ds.type=type;
00926         ds.flags=flags;
00927         ds.attr=attr;
00928         ds.timestamp=get_broker_timestamp(timestamp);
00929 
00930         ds.acknowledgement_type=acknowledgement_type;
00931         if(acknowledgement_type==SERVICE_ACKNOWLEDGEMENT){
00932                 temp_service=(service *)data;
00933                 ds.host_name=temp_service->host_name;
00934                 ds.service_description=temp_service->description;
00935                 ds.state=temp_service->current_state;
00936                 }
00937         else{
00938                 temp_host=(host *)data;
00939                 ds.host_name=temp_host->name;
00940                 ds.service_description=NULL;
00941                 ds.state=temp_host->current_state;
00942                 }
00943         ds.object_ptr=data;
00944         ds.author_name=ack_author;
00945         ds.comment_data=ack_data;
00946         ds.is_sticky=(subtype==ACKNOWLEDGEMENT_STICKY)?TRUE:FALSE;
00947         ds.notify_contacts=notify_contacts;
00948         ds.persistent_comment=persistent_comment;
00949 
00950         /* make callbacks */
00951         neb_make_callbacks(NEBCALLBACK_ACKNOWLEDGEMENT_DATA,(void *)&ds);
00952 
00953         return;
00954         }
00955 
00956 
00957 /* send state change data to broker */
00958 void broker_statechange_data(int type, int flags, int attr, int statechange_type, void *data, int state, int state_type, int current_attempt, int max_attempts, struct timeval *timestamp){
00959         nebstruct_statechange_data ds;
00960         host *temp_host=NULL;
00961         service *temp_service=NULL;
00962 
00963         if(!(event_broker_options & BROKER_STATECHANGE_DATA))
00964                 return;
00965         
00966         /* fill struct with relevant data */
00967         ds.type=type;
00968         ds.flags=flags;
00969         ds.attr=attr;
00970         ds.timestamp=get_broker_timestamp(timestamp);
00971 
00972         ds.statechange_type=statechange_type;
00973         if(statechange_type==SERVICE_STATECHANGE){
00974                 temp_service=(service *)data;
00975                 ds.host_name=temp_service->host_name;
00976                 ds.service_description=temp_service->description;
00977                 ds.output=temp_service->plugin_output;
00978                 }
00979         else{
00980                 temp_host=(host *)data;
00981                 ds.host_name=temp_host->name;
00982                 ds.service_description=NULL;
00983                 ds.output=temp_host->plugin_output;
00984                 }
00985         ds.object_ptr=data;
00986         ds.state=state;
00987         ds.state_type=state_type;
00988         ds.current_attempt=current_attempt;
00989         ds.max_attempts=max_attempts;
00990 
00991         /* make callbacks */
00992         neb_make_callbacks(NEBCALLBACK_STATE_CHANGE_DATA,(void *)&ds);
00993 
00994         return;
00995         }
00996 
00997 
00998 
00999 /******************************************************************/
01000 /************************ UTILITY FUNCTIONS ***********************/
01001 /******************************************************************/
01002 
01003 /* gets timestamp for use by broker */
01004 struct timeval get_broker_timestamp(struct timeval *timestamp){
01005         struct timeval tv;
01006 
01007         if(timestamp==NULL)
01008                 gettimeofday(&tv,NULL);
01009         else
01010                 tv=*timestamp;
01011 
01012         return tv;
01013         }
01014 
01015 
01016 
01017 #endif
01018 
 All Data Structures Files Functions Variables Typedefs Defines