[Pkg-nagios-changes] [SCM] Debian packaging for mod gearman. branch, master, updated. f5edd3e88aa2138dcf6d044c835fbd0ada944168
Mark Clarkson (none)
mclarkson at hptm2.
Fri Feb 11 11:17:41 UTC 2011
The following commit has been merged in the master branch:
commit 3fc5dd0267d82d7425463d45c7680a6497106cf3
Author: Mark Clarkson <mark.clarkson at smorg.co.uk>
Date: Thu Jan 13 00:51:25 2011 +0000
Added new configuration option 'dupserver'. This allows the check results to also be sent to a second gearman job server, or pool of job servers. Useful for sending results from many nagios servers to a single 'collector' nagios server, or maybe for creating some failover solution.
diff --git a/common/gearman.c b/common/gearman.c
index 5a20980..91fe02d 100644
--- a/common/gearman.c
+++ b/common/gearman.c
@@ -78,6 +78,43 @@ int worker_add_function( gearman_worker_st * worker, char * queue, gearman_worke
}
+/* create the gearman duplicate client */
+int create_client_dup( char ** server_list, gearman_client_st *client ) {
+ gearman_return_t ret;
+ int x = 0;
+
+ gm_log( GM_LOG_TRACE, "create_gearman_client_dup()\n" );
+
+ signal(SIGPIPE, SIG_IGN);
+
+ client = gearman_client_create(client);
+ if ( client == NULL ) {
+ gm_log( GM_LOG_ERROR, "Memory allocation failure on client creation\n" );
+ return GM_ERROR;
+ }
+
+ while ( server_list[x] != NULL ) {
+ char * server = strdup( server_list[x] );
+ char * server_c = server;
+ char * host = strsep( &server, ":" );
+ char * port_val = strsep( &server, "\x0" );
+ in_port_t port = GM_SERVER_DEFAULT_PORT;
+ if(port_val != NULL) {
+ port = ( in_port_t ) atoi( port_val );
+ }
+ ret = gearman_client_add_server( client, host, port );
+ if ( ret != GEARMAN_SUCCESS ) {
+ gm_log( GM_LOG_ERROR, "client error: %s\n", gearman_client_error( client ) );
+ free(server_c);
+ return GM_ERROR;
+ }
+ free(server_c);
+ x++;
+ }
+
+ return GM_OK;
+}
+
/* create the gearman client */
int create_client( char ** server_list, gearman_client_st *client ) {
gearman_return_t ret;
diff --git a/common/utils.c b/common/utils.c
index 967e8d3..d8a9ed3 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -226,6 +226,9 @@ int set_default_options(mod_gm_opt_t *opt) {
opt->server_num = 0;
for(i=0;i<=GM_LISTSIZE;i++)
opt->server_list[i] = NULL;
+ opt->dupserver_num = 0;
+ for(i=0;i<=GM_LISTSIZE;i++)
+ opt->dupserver_list[i] = NULL;
opt->hostgroups_num = 0;
for(i=0;i<=GM_LISTSIZE;i++)
opt->hostgroups_list[i] = NULL;
@@ -498,6 +501,18 @@ int parse_args_line(mod_gm_opt_t *opt, char * arg, int recursion_level) {
}
}
+ /* duplicate server */
+ else if ( !strcmp( key, "dupserver" ) ) {
+ char *servername;
+ while ( (servername = strsep( &value, "," )) != NULL ) {
+ servername = trim(servername);
+ if ( strcmp( servername, "" ) ) {
+ opt->dupserver_list[opt->dupserver_num] = strdup(servername);
+ opt->dupserver_num++;
+ }
+ }
+ }
+
/* servicegroups */
else if ( !strcmp( key, "servicegroups" )
|| !strcmp( key, "servicegroup" )
@@ -633,6 +648,9 @@ void dumpconfig(mod_gm_opt_t *opt, int mode) {
for(i=0;i<opt->server_num;i++)
gm_log( GM_LOG_DEBUG, "server: %s\n", opt->server_list[i]);
gm_log( GM_LOG_DEBUG, "\n" );
+ for(i=0;i<opt->dupserver_num;i++)
+ gm_log( GM_LOG_DEBUG, "dupserver: %s\n", opt->dupserver_list[i]);
+ gm_log( GM_LOG_DEBUG, "\n" );
if(mode == GM_NEB_MODE) {
gm_log( GM_LOG_DEBUG, "perfdata: %s\n", opt->perfdata == GM_ENABLED ? "yes" : "no");
}
@@ -676,6 +694,8 @@ void mod_gm_free_opt(mod_gm_opt_t *opt) {
int i;
for(i=0;i<opt->server_num;i++)
free(opt->server_list[i]);
+ for(i=0;i<opt->dupserver_num;i++)
+ free(opt->dupserver_list[i]);
for(i=0;i<opt->hostgroups_num;i++)
free(opt->hostgroups_list[i]);
for(i=0;i<opt->servicegroups_num;i++)
diff --git a/etc/mod_gearman.conf.in b/etc/mod_gearman.conf.in
index 807a1e3..d0f4979 100644
--- a/etc/mod_gearman.conf.in
+++ b/etc/mod_gearman.conf.in
@@ -23,6 +23,11 @@ debug=0
server=localhost:4730
+# sets the address of your 2nd (duplicate) gearman job server. Can
+# be specified more than once o add more servers.
+#dupserver=<host>:<port>
+
+
# defines if the module should distribute execution of
# eventhandlers.
eventhandler=yes
@@ -146,4 +151,4 @@ idle-timeout=30
# Controls the amount of jobs a worker will do before he exits
# Use this to control how fast the amount of workers will go down
# after high load times
-max-jobs=50
\ No newline at end of file
+max-jobs=50
diff --git a/include/common.h b/include/common.h
index 6618fbf..8a27d20 100644
--- a/include/common.h
+++ b/include/common.h
@@ -107,6 +107,8 @@ typedef struct mod_gm_opt_struct {
char * keyfile;
char * server_list[GM_LISTSIZE];
int server_num;
+ char * dupserver_list[GM_LISTSIZE];
+ int dupserver_num;
char * hostgroups_list[GM_LISTSIZE];
int hostgroups_num;
char * servicegroups_list[GM_LISTSIZE];
diff --git a/include/gearman.h b/include/gearman.h
index 81f33e4..8857008 100644
--- a/include/gearman.h
+++ b/include/gearman.h
@@ -32,6 +32,7 @@
typedef void*( mod_gm_worker_fn)(gearman_job_st *job, void *context, size_t *result_size, gearman_return_t *ret_ptr);
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 worker_add_function( gearman_worker_st * worker, char * queue, gearman_worker_fn *function);
diff --git a/worker/worker.c b/worker/worker.c
index cf278ba..ef47cf0 100644
--- a/worker/worker.c
+++ b/worker/worker.c
@@ -342,6 +342,8 @@ void print_usage() {
printf("\n");
printf(" [ --server=<server> ]\n");
printf("\n");
+ printf(" [ --dupserver=<server> ]\n");
+ printf("\n");
printf(" [ --hosts ]\n");
printf(" [ --services ]\n");
printf(" [ --events ]\n");
diff --git a/worker/worker_client.c b/worker/worker_client.c
index e9caab6..f150270 100644
--- a/worker/worker_client.c
+++ b/worker/worker_client.c
@@ -35,6 +35,7 @@ char hostname[GM_BUFFERSIZE];
gearman_worker_st worker;
gearman_client_st client;
+gearman_client_st client_dup;
gm_job_t * current_job;
pid_t current_child_pid;
@@ -70,6 +71,12 @@ void worker_client(int worker_mode) {
exit( EXIT_FAILURE );
}
+ /* create duplicate client */
+ if ( create_client_dup( mod_gm_opt->dupserver_list, &client_dup ) != GM_OK ) {
+ gm_log( GM_LOG_ERROR, "cannot start client for duplicate server\n" );
+ exit( EXIT_FAILURE );
+ }
+
worker_loop();
return;
@@ -93,6 +100,7 @@ void worker_loop() {
gearman_job_free_all( &worker );
gearman_worker_free( &worker );
gearman_client_free( &client );
+ if( mod_gm_opt->dupserver_num ) gearman_client_free( &client_dup );
/* sleep on error to avoid cpu intensive infinite loops */
sleep(sleep_time_after_error);
@@ -103,6 +111,7 @@ void worker_loop() {
/* create new connections */
set_worker( &worker );
create_client( mod_gm_opt->server_list, &client );
+ create_client( mod_gm_opt->dupserver_list, &client_dup );
}
}
@@ -233,6 +242,7 @@ void *get_job( gearman_job_st *job, void *context, size_t *result_size, gearman_
gearman_worker_unregister_all(&worker);
gearman_job_free_all( &worker );
gearman_client_free( &client );
+ if( mod_gm_opt->dupserver_num ) gearman_client_free( &client_dup );
mod_gm_free_opt(mod_gm_opt);
exit( EXIT_SUCCESS );
}
@@ -507,6 +517,29 @@ void send_result_back() {
gm_log( GM_LOG_TRACE, "send_result_back() finished unsuccessfully\n" );
}
+ if( mod_gm_opt->dupserver_num ) {
+ strncpy(temp_buffer2, "type=passive\n", (sizeof(temp_buffer1)-2));
+ strncat(temp_buffer2, temp_buffer1, (sizeof(temp_buffer2)-2));
+ temp_buffer2[sizeof( temp_buffer2 )-1]='\x0';
+ if( add_job_to_queue( &client_dup,
+ mod_gm_opt->dupserver_list,
+ exec_job->result_queue,
+ NULL,
+ temp_buffer2,
+ GM_JOB_PRIO_NORMAL,
+ GM_DEFAULT_JOB_RETRIES,
+ mod_gm_opt->transportmode
+ ) == GM_OK) {
+ gm_log( GM_LOG_TRACE, "send_result_back() finished successfully for duplicate server.\n" );
+ }
+ else {
+ gm_log( GM_LOG_TRACE, "send_result_back() finished unsuccessfully for duplicate server\n" );
+ }
+ }
+ else {
+ gm_log( GM_LOG_TRACE, "send_result_back() has no duplicate servers to send to.\n" );
+ }
+
return;
}
--
Debian packaging for mod gearman.
More information about the Pkg-nagios-changes
mailing list