[Pkg-nagios-changes] [SCM] Debian packaging for mod gearman. branch, upstream, updated. e9a5a6997d9dd8b31b433b5bcbad495448db0131
Sven Nierlein
sven at nierlein.org
Thu Apr 7 08:06:40 UTC 2011
The following commit has been merged in the upstream branch:
commit cce60b25b2f52a9c74317f05e80a70935a80700a
Author: Sven Nierlein <sven at nierlein.org>
Date: Sun Mar 13 20:58:10 2011 +0100
delay sending exports right after startup
diff --git a/common/gearman.c b/common/gearman.c
index c9a25c0..cf681cd 100644
--- a/common/gearman.c
+++ b/common/gearman.c
@@ -155,7 +155,7 @@ int create_client( char ** server_list, gearman_client_st *client ) {
/* create a task and send it */
-int add_job_to_queue( gearman_client_st *client, char ** server_list, char * queue, char * uniq, char * data, int priority, int retries, int transport_mode ) {
+int add_job_to_queue( gearman_client_st *client, char ** server_list, char * queue, char * uniq, char * data, int priority, int retries, int transport_mode, int send_now ) {
gearman_task_st *task = NULL;
gearman_return_t ret1, ret2;
char * crypted_data;
@@ -164,7 +164,7 @@ int add_job_to_queue( gearman_client_st *client, char ** server_list, char * que
signal(SIGPIPE, SIG_IGN);
- gm_log( GM_LOG_TRACE, "add_job_to_queue(%s, %s, %d, %d, %d)\n", queue, uniq, priority, retries, transport_mode );
+ gm_log( GM_LOG_TRACE, "add_job_to_queue(%s, %s, %d, %d, %d, %d)\n", queue, uniq, priority, retries, transport_mode, send_now );
gm_log( GM_LOG_TRACE, "%d --->%s<---\n", strlen(data), data );
crypted_data = malloc(GM_BUFFERSIZE);
@@ -201,6 +201,9 @@ int add_job_to_queue( gearman_client_st *client, char ** server_list, char * que
gm_log( GM_LOG_ERROR, "add_job_to_queue() wrong priority: %d\n", priority );
}
+ if(send_now != TRUE)
+ return GM_OK;
+
ret2 = gearman_client_run_tasks( client );
gearman_client_task_free_all( client );
if( ret1 != GEARMAN_SUCCESS
@@ -233,7 +236,7 @@ int add_job_to_queue( gearman_client_st *client, char ** server_list, char * que
if(retries > 0) {
retries--;
gm_log( GM_LOG_TRACE, "add_job_to_queue() retrying... %d\n", retries );
- return(add_job_to_queue( client, server_list, queue, uniq, data, priority, retries, transport_mode));
+ return(add_job_to_queue( client, server_list, queue, uniq, data, priority, retries, transport_mode, send_now ));
}
/* no more retries... */
else {
diff --git a/common/utils.c b/common/utils.c
index 6c085f1..fdde1e9 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -625,16 +625,19 @@ int parse_args_line(mod_gm_opt_t *opt, char * arg, int recursion_level) {
while ( (callback = strsep( &callbacks, "," )) != NULL ) {
int callback_num = atoi(trim(callback));
if(index(callback, 'N') != NULL) {
+ callback_num = -1;
/* get neb callback number by name */
int i;
for(i=0;i<=GM_NEBTYPESSIZE;i++) {
char * type = event_type2str(i);
if(!strcmp(type, callback)) {
callback_num = i;
- break;
}
}
- gm_log( GM_LOG_ERROR, "unknown nebcallback : %s\n", callback);
+ if(callback_num == -1) {
+ gm_log( GM_LOG_ERROR, "unknown nebcallback : %s\n", callback);
+ continue;
+ }
}
int number = opt->exports[callback_num]->elem_number;
diff --git a/include/gearman.h b/include/gearman.h
index cb6942c..1e848e5 100644
--- a/include/gearman.h
+++ b/include/gearman.h
@@ -40,7 +40,7 @@ typedef void*( mod_gm_worker_fn)(gearman_job_st *job, void *context, size_t *res
int create_client( char ** server_list, gearman_client_st * client);
int create_client_dup( char ** server_list, gearman_client_st * client);
int create_worker( char ** server_list, gearman_worker_st * worker);
-int add_job_to_queue( gearman_client_st *client, char ** server_list, char * queue, char * uniq, char * data, int priority, int retries, int transport_mode );
+int add_job_to_queue( gearman_client_st *client, char ** server_list, char * queue, char * uniq, char * data, int priority, int retries, int transport_mode, int send_now );
int worker_add_function( gearman_worker_st * worker, char * queue, gearman_worker_fn *function);
void *dummy( gearman_job_st *, void *, size_t *, gearman_return_t * );
void free_client(gearman_client_st *client);
diff --git a/neb_module/gm_log.c b/neb_module/gm_log.c
index 0814533..cdc7b8d 100644
--- a/neb_module/gm_log.c
+++ b/neb_module/gm_log.c
@@ -30,9 +30,10 @@ void gm_log( int lvl, const char *text, ... ) {
va_list ap;
/* check log level */
- if ( lvl != GM_LOG_ERROR && lvl > mod_gm_opt->debug_level ) {
+ if ( mod_gm_opt->debug_level < 0 )
+ return;
+ if ( lvl != GM_LOG_ERROR && lvl > mod_gm_opt->debug_level )
return;
- }
if ( lvl == GM_LOG_ERROR ) {
snprintf( buffer, 22, "mod_gearman: ERROR - " );
diff --git a/neb_module/mod_gearman.c b/neb_module/mod_gearman.c
index 0d0d8fa..c1a1d9b 100644
--- a/neb_module/mod_gearman.c
+++ b/neb_module/mod_gearman.c
@@ -49,6 +49,7 @@ static pthread_mutex_t mod_gm_result_list_mutex = PTHREAD_MUTEX_INITIALIZER;
void *gearman_module_handle=NULL;
gearman_client_st client;
+int send_now = FALSE;
int result_threads_running = 0;
pthread_t result_thr[GM_LISTSIZE];
char target_queue[GM_BUFFERSIZE];
@@ -150,16 +151,16 @@ int nebmodule_init( int flags, char *args, nebmodule *handle ) {
return NEB_ERROR;
}
+ /* register callback for process event where everything else starts */
+ neb_register_callback( NEBCALLBACK_PROCESS_DATA, gearman_module_handle, 0, handle_process_events );
+ neb_register_callback( NEBCALLBACK_TIMED_EVENT_DATA, gearman_module_handle, 0, handle_timed_events );
+
/* register export callbacks */
for(i=0;i<=GM_NEBTYPESSIZE;i++) {
if(mod_gm_opt->exports[i]->elem_number > 0)
neb_register_callback( i, gearman_module_handle, 0, handle_export );
}
- /* register callback for process event where everything else starts */
- neb_register_callback( NEBCALLBACK_PROCESS_DATA, gearman_module_handle, 0, handle_process_events );
- neb_register_callback( NEBCALLBACK_TIMED_EVENT_DATA, gearman_module_handle, 0, handle_timed_events );
-
gm_log( GM_LOG_DEBUG, "finished initializing\n" );
return NEB_OK;
@@ -217,6 +218,14 @@ int nebmodule_deinit( int flags, int reason ) {
neb_deregister_callback( NEBCALLBACK_SERVICE_CHECK_DATA, gearman_module_handle );
}
+ /* register export callbacks */
+ for(x=0;x<=GM_NEBTYPESSIZE;x++) {
+ if(mod_gm_opt->exports[x]->elem_number > 0)
+ neb_deregister_callback( x, gearman_module_handle );
+ }
+
+ neb_deregister_callback( NEBCALLBACK_PROCESS_DATA, gearman_module_handle );
+
gm_log( GM_LOG_DEBUG, "deregistered callbacks\n" );
/* stop result threads */
@@ -314,10 +323,10 @@ static int handle_process_events( int event_type, void *data ) {
ps = ( struct nebstruct_process_struct * )data;
if ( ps->type == NEBTYPE_PROCESS_EVENTLOOPSTART ) {
+
register_neb_callbacks();
start_threads();
-
- neb_deregister_callback( NEBCALLBACK_PROCESS_DATA, gearman_module_handle );
+ send_now = TRUE;
/* verify names of supplied groups
* this cannot be done befor nagios has finished reading his config
@@ -391,7 +400,8 @@ static int handle_eventhandler( int event_type, void *data ) {
temp_buffer,
GM_JOB_PRIO_NORMAL,
GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
+ mod_gm_opt->transportmode,
+ FALSE
) == GM_OK) {
gm_log( GM_LOG_TRACE, "handle_eventhandler() finished successfully\n" );
}
@@ -505,7 +515,8 @@ static int handle_host_check( int event_type, void *data ) {
temp_buffer,
GM_JOB_PRIO_NORMAL,
GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
+ mod_gm_opt->transportmode,
+ TRUE
) == GM_OK) {
}
else {
@@ -638,7 +649,8 @@ static int handle_svc_check( int event_type, void *data ) {
temp_buffer,
prio,
GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
+ mod_gm_opt->transportmode,
+ TRUE
) == GM_OK) {
gm_log( GM_LOG_TRACE, "handle_svc_check() finished successfully\n" );
}
@@ -939,7 +951,8 @@ int handle_perfdata(int event_type, void *data) {
temp_buffer,
GM_JOB_PRIO_NORMAL,
GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
+ mod_gm_opt->transportmode,
+ TRUE
) == GM_OK) {
gm_log( GM_LOG_TRACE, "handle_perfdata() finished successfully\n" );
}
@@ -958,11 +971,10 @@ int handle_export(int event_type, void *data) {
char * buffer;
char * type;
nebstruct_log_data * nld;
-
- if(event_type != NEBCALLBACK_LOG_DATA || mod_gm_opt->debug_level >= 3)
- gm_log( GM_LOG_TRACE, "handle_export(%d)\n", event_type );
-
- temp_buffer[0]='\x0';
+ temp_buffer[0] = '\x0';
+ int debug_level_orig = mod_gm_opt->debug_level;
+ mod_gm_opt->debug_level = -1;
+ int return_code = 0;
/* what type of event/data do we have? */
switch (event_type) {
@@ -1047,8 +1059,8 @@ int handle_export(int event_type, void *data) {
case NEBCALLBACK_ADAPTIVE_CONTACT_DATA: /* 32 */
break;
default:
- if(event_type != NEBCALLBACK_LOG_DATA || mod_gm_opt->debug_level >= 3)
- gm_log( GM_LOG_DEBUG, "handle_export() unknown export type: %d\n", event_type );
+ gm_log( GM_LOG_ERROR, "handle_export() unknown export type: %d\n", event_type );
+ mod_gm_opt->debug_level = debug_level_orig;
return 0;
}
@@ -1056,26 +1068,20 @@ int handle_export(int event_type, void *data) {
if(temp_buffer[0] != '\x0') {
for(i=0;i<mod_gm_opt->exports[event_type]->elem_number;i++) {
- if(add_job_to_queue( &client,
- mod_gm_opt->server_list,
- mod_gm_opt->exports[event_type]->name[i], /* queue name */
- NULL,
- temp_buffer,
- GM_JOB_PRIO_NORMAL,
- GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
- ) == GM_OK) {
- if(event_type != NEBCALLBACK_LOG_DATA || mod_gm_opt->debug_level >= 3)
- gm_log( GM_LOG_TRACE, "handle_export() send successfully\n" );
- }
- else {
- if(event_type != NEBCALLBACK_LOG_DATA || mod_gm_opt->debug_level >= 3)
- gm_log( GM_LOG_TRACE, "handle_export() send failed\n" );
- }
+ return_code = mod_gm_opt->exports[event_type]->return_code[i];
+ add_job_to_queue( &client,
+ mod_gm_opt->server_list,
+ mod_gm_opt->exports[event_type]->name[i], /* queue name */
+ NULL,
+ temp_buffer,
+ GM_JOB_PRIO_NORMAL,
+ GM_DEFAULT_JOB_RETRIES,
+ mod_gm_opt->transportmode,
+ send_now
+ );
}
- } else {
- gm_log( GM_LOG_TRACE, "handle_export() finished\n" );
}
- return 0;
+ mod_gm_opt->debug_level = debug_level_orig;
+ return return_code;
}
diff --git a/t/02-full.c b/t/02-full.c
index 6f3405e..2ff8ba8 100644
--- a/t/02-full.c
+++ b/t/02-full.c
@@ -76,7 +76,7 @@ void *start_worker(void*data) {
void test_eventhandler(int transportmode);
void test_eventhandler(int transportmode) {
char * testdata = "type=eventhandler\ncommand_line=/bin/hostname\n\n\n";
- int rt = add_job_to_queue( &client, mod_gm_opt->server_list, "eventhandler", NULL, testdata, GM_JOB_PRIO_NORMAL, 1, transportmode);
+ int rt = add_job_to_queue( &client, mod_gm_opt->server_list, "eventhandler", NULL, testdata, GM_JOB_PRIO_NORMAL, 1, transportmode, TRUE );
ok(rt == GM_OK, "eventhandler sent successfully in mode %s", transportmode == GM_ENCODE_ONLY ? "base64" : "aes256");
return;
}
@@ -103,7 +103,7 @@ void test_servicecheck(int transportmode) {
"/bin/hostname"
);
temp_buffer[sizeof( temp_buffer )-1]='\x0';
- int rt = add_job_to_queue( &client, mod_gm_opt->server_list, "service", NULL, temp_buffer, GM_JOB_PRIO_NORMAL, 1, transportmode);
+ int rt = add_job_to_queue( &client, mod_gm_opt->server_list, "service", NULL, temp_buffer, GM_JOB_PRIO_NORMAL, 1, transportmode, TRUE );
ok(rt == GM_OK, "servicecheck sent successfully in mode %s", transportmode == GM_ENCODE_ONLY ? "base64" : "aes256");
return;
}
diff --git a/tools/send_gearman.c b/tools/send_gearman.c
index d8ebe3c..d05d168 100644
--- a/tools/send_gearman.c
+++ b/tools/send_gearman.c
@@ -251,7 +251,8 @@ int send_result() {
temp_buffer1,
GM_JOB_PRIO_NORMAL,
GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
+ mod_gm_opt->transportmode,
+ TRUE
) == GM_OK) {
gm_log( GM_LOG_TRACE, "send_result_back() finished successfully\n" );
}
diff --git a/tools/send_multi.c b/tools/send_multi.c
index 08ec197..13d905f 100644
--- a/tools/send_multi.c
+++ b/tools/send_multi.c
@@ -242,7 +242,8 @@ int send_result() {
temp_buffer1,
GM_JOB_PRIO_NORMAL,
GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
+ mod_gm_opt->transportmode,
+ TRUE
) == GM_OK) {
gm_log( GM_LOG_TRACE, "send_result_back() finished successfully\n" );
}
diff --git a/worker/worker_client.c b/worker/worker_client.c
index 38d8958..f3a9503 100644
--- a/worker/worker_client.c
+++ b/worker/worker_client.c
@@ -398,7 +398,8 @@ void send_result_back() {
temp_buffer1,
GM_JOB_PRIO_NORMAL,
GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
+ mod_gm_opt->transportmode,
+ TRUE
) == GM_OK) {
gm_log( GM_LOG_TRACE, "send_result_back() finished successfully\n" );
}
@@ -417,7 +418,8 @@ void send_result_back() {
temp_buffer2,
GM_JOB_PRIO_NORMAL,
GM_DEFAULT_JOB_RETRIES,
- mod_gm_opt->transportmode
+ mod_gm_opt->transportmode,
+ TRUE
) == GM_OK) {
gm_log( GM_LOG_TRACE, "send_result_back() finished successfully for duplicate server.\n" );
}
--
Debian packaging for mod gearman.
More information about the Pkg-nagios-changes
mailing list