[Nagios-devel] add eventhandler override

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] add eventhandler override

Post by Guest »

This is a multi-part message in MIME format.
--------------090608080508050006060301
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hi,

Currently eventhandlers are executed in the main thread of nagios and block the core until the eventhandler is finished.
Attached is a patch, which makes it possible for eventhandling neb modules to cancel/override the execution of eventhandlers.
This is currently only possible with service and host checks. This patch would allow neb modules to stack eventhandlers on
external queues or even distribute execution of eventhandler.
This patch should not break the behavior of current neb modules, because their return value is currently ignored and
execution of eventhandler will only be canceled on returning "NEBERROR_CALLBACKOVERRIDE".

Regards,
Sven

--------------090608080508050006060301
Content-Type: text/x-patch;
name="0001-use_return_values_from_eventhandler_broker.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="0001-use_return_values_from_eventhandler_broker.patch"

diff --git a/base/broker.c b/base/broker.c
index 329543f..8f5bc88 100644
--- a/base/broker.c
+++ b/base/broker.c
@@ -174,13 +174,14 @@ void broker_system_command(int type, int flags, int attr, struct timeval start_t


/* send event handler data to broker */
-void 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){
+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){
service *temp_service=NULL;
host *temp_host=NULL;
char *command_buf=NULL;
char *command_name=NULL;
char *command_args=NULL;
nebstruct_event_handler_data ds;
+ int return_code=OK;

if(!(event_broker_options & BROKER_EVENT_HANDLERS))
return;
@@ -227,12 +228,12 @@ void broker_event_handler(int type, int flags, int attr, int eventhandler_type,
ds.output=output;

/* make callbacks */
- neb_make_callbacks(NEBCALLBACK_EVENT_HANDLER_DATA,(void *)&ds);
+ return_code=neb_make_callbacks(NEBCALLBACK_EVENT_HANDLER_DATA,(void *)&ds);

/* free memory */
my_free(command_buf);

- return;
+ return return_code;
}


@@ -1010,4 +1011,3 @@ struct timeval get_broker_timestamp(struct timeval *timestamp){


#endif
-
diff --git a/base/sehandlers.c b/base/sehandlers.c
index 6def42e..a53d99f 100644
--- a/base/sehandlers.c
+++ b/base/sehandlers.c
@@ -32,6 +32,9 @@
#include "../include/perfdata.h"
#include "../include/broker.h"

+#ifdef USE_EVENT_BROKER
+#include "../include/neberrors.h"
+#endif

extern int enable_event_handlers;
extern int obsess_over_services;
@@ -251,6 +254,7 @@ int run_global_service_event_handler(service *svc){
#ifdef USE_EVENT_BROKER
struct timeval start_time;
struct timeval end_time;
+ int neb_result=OK;
#endif
int macro_options=STRIP_ILLEGAL_MACRO_CHARS|ESCAPE_MACRO_CHARS;

@@ -275,13 +279,6 @@ int run_global_service_event_handler(service *svc){
gettimeofday(&start_time,NULL);
#endif

-#ifdef USE_EVENT_BROKER
- /* send event data to broker */
- end_time.tv_sec=0L;
- end_time.tv_usec=0L;
- broker_event_handler(NEBTYPE_EVENTHANDLER_START,NEBFLAG_NONE,NEBATTR_NONE,GLOBAL_SERVICE_EVENTHANDLER,(void *)svc,svc->current_state,svc->state_type,start_time,end_time,exectime,event_handler_timeout,early_timeout,result,global_service_event_handler,NULL,NULL,NULL);
-#endif
-
/* get the raw command line */
get_raw_command_line(global_service_event_handler_ptr,global_service_event_handler,&raw_command,macro_options);
if(raw_command==NULL)
@@ -302,6 +299,22 @@ int run_global_service_event_handler(service *svc){
logit(NSLOG_EVENT_HANDLER,FALSE,processed_logentry);
}

+#ifdef USE_EVENT_BROKER
+ /* send event data to broker

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked