[Pkg-nagios-changes] [SCM] Debian packaging for mod gearman. branch, upstream, updated. e9a5a6997d9dd8b31b433b5bcbad495448db0131
Sven Nierlein
sven at nierlein.org
Thu Apr 7 08:06:04 UTC 2011
The following commit has been merged in the upstream branch:
commit a61c1b724d3e7a26fd25826b42faec2514aa9803
Author: Sven Nierlein <sven at nierlein.org>
Date: Sat Jan 29 23:17:03 2011 +0100
added first version of exporter
diff --git a/common/utils.c b/common/utils.c
index c988774..4a70591 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -241,6 +241,9 @@ int set_default_options(mod_gm_opt_t *opt) {
opt->local_servicegroups_num = 0;
for(i=0;i<=GM_LISTSIZE;i++)
opt->local_servicegroups_list[i] = NULL;
+ opt->exports_num = 0;
+ for(i=0;i<=GM_LISTSIZE;i++)
+ opt->exports[i] = NULL;
return(GM_OK);
}
@@ -568,6 +571,26 @@ int parse_args_line(mod_gm_opt_t *opt, char * arg, int recursion_level) {
}
}
}
+
+ /* export queues */
+ else if ( !strcmp( key, "export" ) ) {
+ mod_gm_exp_t *mod_gm_exp;
+ char *callback;
+ mod_gm_exp = malloc(sizeof(mod_gm_exp_t));
+ mod_gm_exp->name = strsep( &value, ":" );
+ mod_gm_exp->name = trim(mod_gm_exp->name);
+ char *return_code = strsep( &value, ":" );
+ mod_gm_exp->return_code = atoi(return_code);
+ char *callbacks = strsep( &value, ":" );
+ mod_gm_exp->callbacks_num = 0;
+ while ( (callback = strsep( &callbacks, "," )) != NULL ) {
+ mod_gm_exp->callbacks[mod_gm_exp->callbacks_num] = atoi(callback);
+ mod_gm_exp->callbacks_num++;
+ }
+ opt->exports[opt->exports_num] = mod_gm_exp;
+ opt->exports_num++;
+ }
+
return(GM_OK);
}
@@ -621,6 +644,9 @@ int read_config_file(mod_gm_opt_t *opt, char*filename, int recursion_level) {
/* dump config */
void dumpconfig(mod_gm_opt_t *opt, int mode) {
int i=0;
+ int j=0;
+ char temp_buffer[GM_BUFFERSIZE];
+ char callbacks[GM_BUFFERSIZE];
gm_log( GM_LOG_DEBUG, "--------------------------------\n" );
gm_log( GM_LOG_DEBUG, "configuration:\n" );
gm_log( GM_LOG_DEBUG, "log level: %d\n", opt->debug_level);
@@ -669,6 +695,18 @@ void dumpconfig(mod_gm_opt_t *opt, int mode) {
gm_log( GM_LOG_DEBUG, "local_hostgroups: %s\n", opt->local_hostgroups_list[i]);
for(i=0;i<opt->local_servicegroups_num;i++)
gm_log( GM_LOG_DEBUG, "local_servicegroups: %s\n", opt->local_servicegroups_list[i]);
+ /* export queues*/
+ for(i=0;i<opt->exports_num;i++) {
+ callbacks[0]='\x0';
+ for(j=0;j<opt->exports[i]->callbacks_num;j++) {
+ temp_buffer[0]='\x0';
+ snprintf( temp_buffer,sizeof( temp_buffer )-1, "%d", opt->exports[i]->callbacks[j]);
+ strcat(callbacks, temp_buffer );
+ if(j < opt->exports[i]->callbacks_num-1)
+ strcat(callbacks, ",");
+ }
+ gm_log( GM_LOG_DEBUG, "export: %s -> %s\n", opt->exports[i]->name, callbacks);
+ }
}
/* encryption */
@@ -704,6 +742,11 @@ void mod_gm_free_opt(mod_gm_opt_t *opt) {
free(opt->local_hostgroups_list[i]);
for(i=0;i<opt->local_servicegroups_num;i++)
free(opt->local_servicegroups_list[i]);
+ for(i=0;i<opt->exports_num;i++) {
+ free(opt->exports[i]->name);
+ free(opt->exports[i]->callbacks);
+ free(opt->exports[i]);
+ }
free(opt->crypt_key);
free(opt->keyfile);
free(opt->message);
@@ -981,3 +1024,227 @@ int pid_alive(int pid) {
return FALSE;
}
+
+
+
+/* escapes newlines in a string */
+char *escapestring(char *rawbuf) {
+ char *newbuf=NULL;
+ char buff[64];
+ register int x,y;
+
+ if(rawbuf==NULL)
+ return NULL;
+
+ /* allocate enough memory to escape all chars if necessary */
+ if((newbuf=malloc((strlen(rawbuf)*2)+1))==NULL)
+ return NULL;
+
+ for(x=0,y=0;rawbuf[x]!=(char)'\x0';x++){
+
+ if(escaped(rawbuf[x])) {
+ escape(buff, rawbuf[x]);
+ newbuf[y++]=buff[0];
+ if(buff[1] != 0)
+ newbuf[y++]=buff[1];
+ }
+
+ else
+ newbuf[y++]=rawbuf[x];
+ }
+ newbuf[y]='\x0';
+
+ return newbuf;
+}
+
+/*
+is a character escaped?
+Params: ch - character to test
+Returns: 1 if escaped, 0 if normal
+*/
+int escaped(int ch) {
+ return strchr("\\\a\b\n\r\t\"\f\v", ch) ? 1 : 0;
+}
+
+/*
+get the escape sequence for a character
+Params: out - output buffer (currently max 2 + nul but allow for more)
+ch - the character to escape
+*/
+void escape(char *out, int ch) {
+ switch(ch) {
+ case '\n':
+ strcpy(out, "\\n"); break;
+ case '\t':
+ strcpy(out, "\\t"); break;
+ case '\v':
+ strcpy(out, "\\v"); break;
+ case '\b':
+ strcpy(out, "\\b"); break;
+ case '\r':
+ strcpy(out, "\\r"); break;
+ case '\f':
+ strcpy(out, "\\f"); break;
+ case '\a':
+ strcpy(out, "\\a"); break;
+ case '\\':
+ strcpy(out, "\\\\"); break;
+ //case '\'':
+ // strcpy(out, "\\\'"); break;
+ case '\"':
+ strcpy(out, "\\\""); break;
+ default:
+ out[0] = (char) ch; break;
+ out[1] = 0;
+ }
+}
+
+
+/* return human readable name for type int */
+char * type2str(int i) {
+ switch(i) {
+ case 0:
+ return strdup("NEBTYPE_NONE"); break;
+ case 1:
+ return strdup("NEBTYPE_HELLO"); break;
+ case 2:
+ return strdup("NEBTYPE_GOODBYE"); break;
+ case 3:
+ return strdup("NEBTYPE_INFO"); break;
+ case 100:
+ return strdup("NEBTYPE_PROCESS_START"); break;
+ case 101:
+ return strdup("NEBTYPE_PROCESS_DAEMONIZE"); break;
+ case 102:
+ return strdup("NEBTYPE_PROCESS_RESTART"); break;
+ case 103:
+ return strdup("NEBTYPE_PROCESS_SHUTDOWN"); break;
+ case 104:
+ return strdup("NEBTYPE_PROCESS_PRELAUNCH"); break;
+ case 105:
+ return strdup("NEBTYPE_PROCESS_EVENTLOOPSTART"); break;
+ case 106:
+ return strdup("NEBTYPE_PROCESS_EVENTLOOPEND"); break;
+ case 200:
+ return strdup("NEBTYPE_TIMEDEVENT_ADD"); break;
+ case 201:
+ return strdup("NEBTYPE_TIMEDEVENT_REMOVE"); break;
+ case 202:
+ return strdup("NEBTYPE_TIMEDEVENT_EXECUTE"); break;
+ case 203:
+ return strdup("NEBTYPE_TIMEDEVENT_DELAY"); break;
+ case 204:
+ return strdup("NEBTYPE_TIMEDEVENT_SKIP"); break;
+ case 205:
+ return strdup("NEBTYPE_TIMEDEVENT_SLEEP"); break;
+ case 300:
+ return strdup("NEBTYPE_LOG_DATA"); break;
+ case 301:
+ return strdup("NEBTYPE_LOG_ROTATION"); break;
+ case 400:
+ return strdup("NEBTYPE_SYSTEM_COMMAND_START"); break;
+ case 401:
+ return strdup("NEBTYPE_SYSTEM_COMMAND_END"); break;
+ case 500:
+ return strdup("NEBTYPE_EVENTHANDLER_START"); break;
+ case 501:
+ return strdup("NEBTYPE_EVENTHANDLER_END"); break;
+ case 600:
+ return strdup("NEBTYPE_NOTIFICATION_START"); break;
+ case 601:
+ return strdup("NEBTYPE_NOTIFICATION_END"); break;
+ case 602:
+ return strdup("NEBTYPE_CONTACTNOTIFICATION_START"); break;
+ case 603:
+ return strdup("NEBTYPE_CONTACTNOTIFICATION_END"); break;
+ case 604:
+ return strdup("NEBTYPE_CONTACTNOTIFICATIONMETHOD_START"); break;
+ case 605:
+ return strdup("NEBTYPE_CONTACTNOTIFICATIONMETHOD_END"); break;
+ case 700:
+ return strdup("NEBTYPE_SERVICECHECK_INITIATE"); break;
+ case 701:
+ return strdup("NEBTYPE_SERVICECHECK_PROCESSED"); break;
+ case 702:
+ return strdup("NEBTYPE_SERVICECHECK_RAW_START"); break;
+ case 703:
+ return strdup("NEBTYPE_SERVICECHECK_RAW_END"); break;
+ case 704:
+ return strdup("NEBTYPE_SERVICECHECK_ASYNC_PRECHECK"); break;
+ case 800:
+ return strdup("NEBTYPE_HOSTCHECK_INITIATE"); break;
+ case 801:
+ return strdup("NEBTYPE_HOSTCHECK_PROCESSED"); break;
+ case 802:
+ return strdup("NEBTYPE_HOSTCHECK_RAW_START"); break;
+ case 803:
+ return strdup("NEBTYPE_HOSTCHECK_RAW_END"); break;
+ case 804:
+ return strdup("NEBTYPE_HOSTCHECK_ASYNC_PRECHECK"); break;
+ case 805:
+ return strdup("NEBTYPE_HOSTCHECK_SYNC_PRECHECK"); break;
+ case 900:
+ return strdup("NEBTYPE_COMMENT_ADD"); break;
+ case 901:
+ return strdup("NEBTYPE_COMMENT_DELETE"); break;
+ case 902:
+ return strdup("NEBTYPE_COMMENT_LOAD"); break;
+ case 1000:
+ return strdup("NEBTYPE_FLAPPING_START"); break;
+ case 1001:
+ return strdup("NEBTYPE_FLAPPING_STOP"); break;
+ case 1100:
+ return strdup("NEBTYPE_DOWNTIME_ADD"); break;
+ case 1101:
+ return strdup("NEBTYPE_DOWNTIME_DELETE"); break;
+ case 1102:
+ return strdup("NEBTYPE_DOWNTIME_LOAD"); break;
+ case 1103:
+ return strdup("NEBTYPE_DOWNTIME_START"); break;
+ case 1104:
+ return strdup("NEBTYPE_DOWNTIME_STOP"); break;
+ case 1200:
+ return strdup("NEBTYPE_PROGRAMSTATUS_UPDATE"); break;
+ case 1201:
+ return strdup("NEBTYPE_HOSTSTATUS_UPDATE"); break;
+ case 1202:
+ return strdup("NEBTYPE_SERVICESTATUS_UPDATE"); break;
+ case 1203:
+ return strdup("NEBTYPE_CONTACTSTATUS_UPDATE"); break;
+ case 1300:
+ return strdup("NEBTYPE_ADAPTIVEPROGRAM_UPDATE"); break;
+ case 1301:
+ return strdup("NEBTYPE_ADAPTIVEHOST_UPDATE"); break;
+ case 1302:
+ return strdup("NEBTYPE_ADAPTIVESERVICE_UPDATE"); break;
+ case 1303:
+ return strdup("NEBTYPE_ADAPTIVECONTACT_UPDATE"); break;
+ case 1400:
+ return strdup("NEBTYPE_EXTERNALCOMMAND_START"); break;
+ case 1401:
+ return strdup("NEBTYPE_EXTERNALCOMMAND_END"); break;
+ case 1500:
+ return strdup("NEBTYPE_AGGREGATEDSTATUS_STARTDUMP"); break;
+ case 1501:
+ return strdup("NEBTYPE_AGGREGATEDSTATUS_ENDDUMP"); break;
+ case 1600:
+ return strdup("NEBTYPE_RETENTIONDATA_STARTLOAD"); break;
+ case 1601:
+ return strdup("NEBTYPE_RETENTIONDATA_ENDLOAD"); break;
+ case 1602:
+ return strdup("NEBTYPE_RETENTIONDATA_STARTSAVE"); break;
+ case 1603:
+ return strdup("NEBTYPE_RETENTIONDATA_ENDSAVE"); break;
+ case 1700:
+ return strdup("NEBTYPE_ACKNOWLEDGEMENT_ADD"); break;
+ case 1701:
+ return strdup("NEBTYPE_ACKNOWLEDGEMENT_REMOVE"); break;
+ case 1702:
+ return strdup("NEBTYPE_ACKNOWLEDGEMENT_LOAD"); break;
+ case 1800:
+ return strdup("NEBTYPE_STATECHANGE_START"); break;
+ case 1801:
+ return strdup("NEBTYPE_STATECHANGE_END"); break;
+ }
+ return strdup("UNKNOWN");
+}
\ No newline at end of file
diff --git a/include/common.h b/include/common.h
index 5cb0107..1e9e764 100644
--- a/include/common.h
+++ b/include/common.h
@@ -122,6 +122,18 @@
#define GM_SHM_SIZE 4096 /**< size of the shared memory segment */
+/** options exports structure
+ *
+ * structure for export definition
+ *
+ */
+typedef struct mod_gm_export {
+ char * name; /**< queue name to export into */
+ int return_code; /**< return code which should be returned to nagios */
+ int callbacks[GM_LISTSIZE]; /**< list of callbacks */
+ int callbacks_num; /**< number of callbacks elements */
+} mod_gm_exp_t;
+
/** options structure
*
* structure union for all components
@@ -156,6 +168,8 @@ typedef struct mod_gm_opt_struct {
int local_hostgroups_num; /**< number of elements in local_hostgroups_list */
char * local_servicegroups_list[GM_LISTSIZE]; /**< list of group which will not be distributed */
int local_servicegroups_num; /**< number of elements in local_servicegroups_list */
+ mod_gm_exp_t * exports[GM_LISTSIZE]; /**< list of exporter queues */
+ int exports_num; /**< number of elements in exports */
/* worker */
char * identifier; /**< identifier for this worker */
char * pidfile; /**< path to a pidfile */
@@ -196,6 +210,7 @@ typedef struct mod_gm_opt_struct {
*/
void gm_log( int lvl, const char *text, ... );
+
/*
* @}
*/
diff --git a/include/utils.h b/include/utils.h
index a5b3379..763c1b7 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -313,5 +313,50 @@ int run_check(char *processed_command, char **plugin_output);
int pid_alive(int pid);
/**
+ * escapestring
+ *
+ * escape quotes and newlines
+ *
+ * @param[in] rawbuf - text to escape
+ *
+ * @return the escaped string
+ */
+char *escapestring(char *rawbuf);
+
+/**
+ * escaped
+ *
+ * checks wheter a char has to be escaped or not
+ *
+ * @param[in] ch - char to check
+ *
+ * @return true if char has to be escaped
+ */
+int escaped(int ch);
+
+/**
+ * escape
+ *
+ * return escaped variant of char
+ *
+ * @param[out] out - escaped char
+ * @param[in] ch - char to escape
+ *
+ * @return the escaped string
+ */
+void escape(char *out, int ch);
+
+/**
+ * type2str
+ *
+ * get human readable name for eventbroker type int
+ *
+ * @param[in] i - integer to translate
+ *
+ * @return the human readable string
+ */
+char * type2str(int i);
+
+/**
* @}
*/
\ No newline at end of file
diff --git a/neb_module/mod_gearman.c b/neb_module/mod_gearman.c
index ffc10c1..f217538 100644
--- a/neb_module/mod_gearman.c
+++ b/neb_module/mod_gearman.c
@@ -62,6 +62,7 @@ static int handle_host_check( int,void * );
static int handle_svc_check( int,void * );
static int handle_eventhandler( int,void * );
static int handle_perfdata(int e, void *);
+static int handle_export(int e, void *);
static void set_target_queue( host *, service * );
static int handle_process_events( int, void * );
static int handle_timed_events( int, void * );
@@ -70,6 +71,7 @@ static check_result * merge_result_lists(check_result * lista, check_result * li
static void move_results_to_core(void);
int nebmodule_init( int flags, char *args, nebmodule *handle ) {
+ int i,j;
/* save our handle */
gearman_module_handle=handle;
@@ -145,6 +147,13 @@ int nebmodule_init( int flags, char *args, nebmodule *handle ) {
return NEB_ERROR;
}
+ /* register export callbacks */
+ for(i=0;i<mod_gm_opt->exports_num;i++) {
+ for(j=0;j<mod_gm_opt->exports[i]->callbacks_num;j++) {
+ neb_register_callback( mod_gm_opt->exports[i]->callbacks[j], 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 );
@@ -692,6 +701,9 @@ static int verify_options(mod_gm_opt_t *opt) {
return(GM_ERROR);
}
+ if ( mod_gm_opt->result_queue == NULL )
+ mod_gm_opt->result_queue = GM_DEFAULT_RESULT_QUEUE;
+
/* nothing set by hand -> defaults */
if( opt->set_queues_by_hand == 0 ) {
gm_log( GM_LOG_DEBUG, "starting client with default queues\n" );
@@ -702,18 +714,16 @@ static int verify_options(mod_gm_opt_t *opt) {
if( opt->servicegroups_num == 0
&& opt->hostgroups_num == 0
- && opt->hosts == GM_DISABLED
- && opt->services == GM_DISABLED
- && opt->events == GM_DISABLED
- && opt->perfdata == GM_DISABLED
+ && opt->exports_num == 0
+ && opt->hosts == GM_DISABLED
+ && opt->services == GM_DISABLED
+ && opt->events == GM_DISABLED
+ && opt->perfdata == GM_DISABLED
) {
gm_log( GM_LOG_ERROR, "starting worker without any queues is useless\n" );
return(GM_ERROR);
}
- if ( mod_gm_opt->result_queue == NULL )
- mod_gm_opt->result_queue = GM_DEFAULT_RESULT_QUEUE;
-
/* do we need a result thread? */
if( opt->servicegroups_num == 0
&& opt->hostgroups_num == 0
@@ -927,3 +937,128 @@ int handle_perfdata(int event_type, void *data) {
return 0;
}
+
+
+/* handle generic exports */
+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';
+
+ /* what type of event/data do we have? */
+ switch (event_type) {
+ case NEBCALLBACK_RESERVED0: /* 0 */
+ break;
+ case NEBCALLBACK_RESERVED1: /* 1 */
+ break;
+ case NEBCALLBACK_RESERVED2: /* 2 */
+ break;
+ case NEBCALLBACK_RESERVED3: /* 3 */
+ break;
+ case NEBCALLBACK_RESERVED4: /* 4 */
+ break;
+ case NEBCALLBACK_RAW_DATA: /* 5 */
+ break;
+ case NEBCALLBACK_NEB_DATA: /* 6 */
+ break;
+ case NEBCALLBACK_PROCESS_DATA: /* 7 */
+ break;
+ case NEBCALLBACK_TIMED_EVENT_DATA: /* 8 */
+ break;
+ case NEBCALLBACK_LOG_DATA: /* 9 */
+ nld = (nebstruct_log_data *)data;
+ buffer = escapestring(nld->data);
+ type = type2str(nld->type);
+ snprintf( temp_buffer,sizeof( temp_buffer )-1, "{\"event_type\":\"%s\",\"type\":\"%s\",\"flags\":%d,\"attr\":%d,\"timestamp\":%d.%d,\"entry_time\":%d,\"data_type\":%d,\"data\":\"%s\"}",
+ "NEBCALLBACK_LOG_DATA",
+ type,
+ nld->flags,
+ nld->attr,
+ (int)nld->timestamp.tv_sec, (int)nld->timestamp.tv_usec,
+ (int)nld->entry_time,
+ nld->data_type,
+ buffer);
+ free(type);
+ free(buffer);
+ break;
+ case NEBCALLBACK_SYSTEM_COMMAND_DATA: /* 10 */
+ break;
+ case NEBCALLBACK_EVENT_HANDLER_DATA: /* 11 */
+ break;
+ case NEBCALLBACK_NOTIFICATION_DATA: /* 12 */
+ break;
+ case NEBCALLBACK_SERVICE_CHECK_DATA: /* 13 */
+ break;
+ case NEBCALLBACK_HOST_CHECK_DATA: /* 14 */
+ break;
+ case NEBCALLBACK_COMMENT_DATA: /* 15 */
+ break;
+ case NEBCALLBACK_DOWNTIME_DATA: /* 16 */
+ break;
+ case NEBCALLBACK_FLAPPING_DATA: /* 17 */
+ break;
+ case NEBCALLBACK_PROGRAM_STATUS_DATA: /* 18 */
+ break;
+ case NEBCALLBACK_HOST_STATUS_DATA: /* 19 */
+ break;
+ case NEBCALLBACK_SERVICE_STATUS_DATA: /* 20 */
+ break;
+ case NEBCALLBACK_ADAPTIVE_PROGRAM_DATA: /* 21 */
+ break;
+ case NEBCALLBACK_ADAPTIVE_HOST_DATA: /* 22 */
+ break;
+ case NEBCALLBACK_ADAPTIVE_SERVICE_DATA: /* 23 */
+ break;
+ case NEBCALLBACK_EXTERNAL_COMMAND_DATA: /* 24 */
+ break;
+ case NEBCALLBACK_AGGREGATED_STATUS_DATA: /* 25 */
+ break;
+ case NEBCALLBACK_RETENTION_DATA: /* 26 */
+ break;
+ case NEBCALLBACK_CONTACT_NOTIFICATION_DATA: /* 27 */
+ break;
+ case NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA: /* 28 */
+ break;
+ case NEBCALLBACK_ACKNOWLEDGEMENT_DATA: /* 29 */
+ break;
+ case NEBCALLBACK_STATE_CHANGE_DATA: /* 30 */
+ break;
+ case NEBCALLBACK_CONTACT_STATUS_DATA: /* 31 */
+ break;
+ case NEBCALLBACK_ADAPTIVE_CONTACT_DATA: /* 32 */
+ break;
+ default:
+ if(event_type != NEBCALLBACK_LOG_DATA || mod_gm_opt->debug_level >= 3)
+ gm_log( GM_LOG_ERROR, "handle_export() unknown export type: %d\n", event_type );
+ return 0;
+ }
+
+ temp_buffer[sizeof( temp_buffer )-1]='\x0';
+ if(temp_buffer[0] != '\x0') {
+ if(add_job_to_queue( &client,
+ mod_gm_opt->server_list,
+ "log",
+ 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() finished successfully\n" );
+ }
+ else {
+ if(event_type != NEBCALLBACK_LOG_DATA || mod_gm_opt->debug_level >= 3)
+ gm_log( GM_LOG_TRACE, "handle_export() finished unsuccessfully\n" );
+ }
+ } else {
+ gm_log( GM_LOG_TRACE, "handle_export() finished\n" );
+ }
+
+ return 0;
+}
diff --git a/tools/perl/dump_queue.pl b/tools/perl/dump_queue.pl
new file mode 100755
index 0000000..8598895
--- /dev/null
+++ b/tools/perl/dump_queue.pl
@@ -0,0 +1,134 @@
+#!/usr/bin/perl
+
+
+=head1 NAME
+
+dump_queue.pl
+
+=head1 SYNOPSIS
+
+./dump_queue.pl [ -v ]
+ [ -h ]
+ [ -H=hostname:port ]
+ [ -q=queue ]
+ [ -c=configfile ]
+
+=head1 DESCRIPTION
+
+This worker connects to your gearman server and dumps data for given queues
+
+=head1 ARGUMENTS
+
+script has the following arguments
+
+=head2 help
+
+ -h
+
+display the help and exit
+
+=head2 verbose
+
+ -v
+
+enable verbose mode
+
+=head2 hostname
+
+ -H=hostname:port
+
+hostname to connect to. Defaults to localhost:4731
+
+=head2 queue
+
+ -q=queue
+
+which queue to dump
+
+=head2 configfile
+
+ -c=configfile
+
+read config from config file
+
+=head1 EXAMPLE
+
+ ./dump_queue.pl -H localhost:4731 -q log
+
+=head1 AUTHOR
+
+2011, Sven Nierlein, <sven.nierlein at consol.de>
+
+=cut
+
+use warnings;
+use strict;
+use Getopt::Long;
+use Data::Dumper;
+use Pod::Usage;
+use Gearman::Worker;
+use MIME::Base64;
+use Crypt::Rijndael;
+use JSON::XS;
+
+################################################################################
+# read options
+my($opt_h, $opt_v, $opt_H, @opt_q, $opt_p);
+Getopt::Long::Configure('no_ignore_case');
+if(!GetOptions(
+ "v" => \$opt_v,
+ "h" => \$opt_h,
+ "H=s" => \$opt_H,
+ "q=s" => \@opt_q,
+ "p=s" => \$opt_p,
+ "v" => \$opt_v,
+)) {
+ pod2usage( { -verbose => 1, -message => "error in options" } );
+ exit 3;
+}
+
+if(defined $opt_h) {
+ pod2usage( { -verbose => 1 } );
+ exit 3;
+}
+if(scalar @opt_q == 0) {
+ pod2usage( { -verbose => 1, -message => "please specify at least one queue." } );
+ exit 3;
+}
+$opt_H = "localhost:4730" unless defined $opt_H;
+
+################################################################################
+# use encryption
+my $cypher;
+if(defined $opt_p) {
+ my $key = substr($opt_p,0,32) . chr(0) x ( 32 - length( $opt_p ) );
+ $cypher = Crypt::Rijndael->new( $key, Crypt::Rijndael::MODE_ECB() );
+}
+
+################################################################################
+# create gearman worker
+my $worker = Gearman::Worker->new;
+$worker->job_servers($opt_H);
+for my $queue (@opt_q) {
+ $worker->register_function($queue, 2, sub { return dump_job(@_); });
+ print "registered queue: $queue\n" if $opt_v;
+}
+my $req = 0;
+print "starting to work\n" if $opt_v;
+$worker->work();
+print "work finished\n" if $opt_v;
+
+################################################################################
+# print job via Data::Dumper
+sub dump_job {
+ my $job = shift;
+ my $data = decode_base64($job->arg);
+ if(defined $cypher) {
+ $data = $cypher->decrypt($data);
+ }
+ print "###################\n";
+ print Dumper($data);
+ $data = decode_json($data);
+ #print Dumper($data);
+ return 1;
+}
\ No newline at end of file
--
Debian packaging for mod gearman.
More information about the Pkg-nagios-changes
mailing list