[Pkg-nagios-changes] [SCM] Debian packaging for mod gearman. branch, upstream, updated. e9a5a6997d9dd8b31b433b5bcbad495448db0131
Sven Nierlein
sven at nierlein.org
Thu Apr 7 08:06:37 UTC 2011
The following commit has been merged in the upstream branch:
commit b81f263a1c54a4d9194bbe8676688656ee079693
Author: Sven Nierlein <sven at nierlein.org>
Date: Sun Mar 13 16:24:22 2011 +0100
use names for nebcallbacks too
diff --git a/Makefile.am b/Makefile.am
index 2cf9571..b05bc8f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,7 @@ DOS2UNIX=$(shell which dos2unix || which fromdos)
.PHONY: docs
# -g adds debug symbols, -s strips
-CFLAGS=-Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -g -O -fPIC
+CFLAGS=-Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -s -O -fPIC
# for debugging
#CFLAGS=-pedantic -Wfatal-errors -Wall -W -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -g3 -O -fPIC
AM_CPPFLAGS=-Iinclude
diff --git a/common/utils.c b/common/utils.c
index 72b2fbe..6c085f1 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -245,9 +245,12 @@ 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;
+ for(i=0;i<=GM_NEBTYPESSIZE;i++) {
+ mod_gm_exp_t *mod_gm_exp;
+ mod_gm_exp = malloc(sizeof(mod_gm_exp_t));
+ mod_gm_exp->elem_number = 0;
+ opt->exports[i] = mod_gm_exp;
+ }
return(GM_OK);
}
@@ -612,21 +615,34 @@ 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 *export_queue;
+ export_queue = strsep( &value, ":" );
+ export_queue = trim(export_queue);
char *return_code = strsep( &value, ":" );
- mod_gm_exp->return_code = atoi(return_code);
- char *callbacks = strsep( &value, ":" );
- mod_gm_exp->callbacks_num = 0;
+ int return_code_num = atoi(return_code);
+ char *callbacks = strsep( &value, ":" );
while ( (callback = strsep( &callbacks, "," )) != NULL ) {
- mod_gm_exp->callbacks[mod_gm_exp->callbacks_num] = atoi(callback);
- mod_gm_exp->callbacks_num++;
+ int callback_num = atoi(trim(callback));
+ if(index(callback, 'N') != NULL) {
+ /* 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);
+ }
+
+ int number = opt->exports[callback_num]->elem_number;
+ opt->exports[callback_num]->name[number] = strdup(export_queue);
+ opt->exports[callback_num]->return_code[number] = return_code_num;
+ opt->exports[callback_num]->elem_number++;
}
- opt->exports[opt->exports_num] = mod_gm_exp;
- opt->exports_num++;
+ opt->exports_count++;
}
else {
@@ -687,8 +703,6 @@ int read_config_file(mod_gm_opt_t *opt, char*filename, int recursion_level) {
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);
@@ -741,16 +755,10 @@ void dumpconfig(mod_gm_opt_t *opt, int mode) {
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);
+ for(i=0;i<=GM_NEBTYPESSIZE;i++) {
+ char * type = event_type2str(i);
+ for(j=0;j<opt->exports[i]->elem_number;j++)
+ gm_log( GM_LOG_DEBUG, "export: %-45s -> %s\n", type, opt->exports[i]->name[j]);
}
}
@@ -774,7 +782,7 @@ void dumpconfig(mod_gm_opt_t *opt, int mode) {
/* free options structure */
void mod_gm_free_opt(mod_gm_opt_t *opt) {
- int i;
+ int i,j;
for(i=0;i<opt->server_num;i++)
free(opt->server_list[i]);
for(i=0;i<opt->dupserver_num;i++)
@@ -787,9 +795,10 @@ 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);
+ for(i=0;i<=GM_NEBTYPESSIZE;i++) {
+ for(j=0;j<opt->exports[i]->elem_number;j++) {
+ free(opt->exports[i]->name[j]);
+ }
free(opt->exports[i]);
}
free(opt->crypt_key);
@@ -1362,8 +1371,8 @@ void escape(char *out, int ch) {
}
-/* return human readable name for type int */
-char * type2str(int i) {
+/* return human readable name for event type int */
+char * neb_type2str(int i) {
switch(i) {
case 0:
return strdup("NEBTYPE_NONE"); break;
@@ -1510,3 +1519,77 @@ char * type2str(int i) {
}
return strdup("UNKNOWN");
}
+
+
+/* return human readable name for event type int */
+char * event_type2str(int i) {
+ switch(i) {
+ case 0:
+ return strdup("NEBCALLBACK_RESERVED0"); break;
+ case 1:
+ return strdup("NEBCALLBACK_RESERVED1"); break;
+ case 2:
+ return strdup("NEBCALLBACK_RESERVED2"); break;
+ case 3:
+ return strdup("NEBCALLBACK_RESERVED3"); break;
+ case 4:
+ return strdup("NEBCALLBACK_RESERVED4"); break;
+ case 5:
+ return strdup("NEBCALLBACK_RAW_DATA"); break;
+ case 6:
+ return strdup("NEBCALLBACK_NEB_DATA"); break;
+ case 7:
+ return strdup("NEBCALLBACK_PROCESS_DATA"); break;
+ case 8:
+ return strdup("NEBCALLBACK_TIMED_EVENT_DATA"); break;
+ case 9:
+ return strdup("NEBCALLBACK_LOG_DATA"); break;
+ case 10:
+ return strdup("NEBCALLBACK_SYSTEM_COMMAND_DATA"); break;
+ case 11:
+ return strdup("NEBCALLBACK_EVENT_HANDLER_DATA"); break;
+ case 12:
+ return strdup("NEBCALLBACK_NOTIFICATION_DATA"); break;
+ case 13:
+ return strdup("NEBCALLBACK_SERVICE_CHECK_DATA"); break;
+ case 14:
+ return strdup("NEBCALLBACK_HOST_CHECK_DATA"); break;
+ case 15:
+ return strdup("NEBCALLBACK_COMMENT_DATA"); break;
+ case 16:
+ return strdup("NEBCALLBACK_DOWNTIME_DATA"); break;
+ case 17:
+ return strdup("NEBCALLBACK_FLAPPING_DATA"); break;
+ case 18:
+ return strdup("NEBCALLBACK_PROGRAM_STATUS_DATA"); break;
+ case 19:
+ return strdup("NEBCALLBACK_HOST_STATUS_DATA"); break;
+ case 20:
+ return strdup("NEBCALLBACK_SERVICE_STATUS_DATA"); break;
+ case 21:
+ return strdup("NEBCALLBACK_ADAPTIVE_PROGRAM_DATA"); break;
+ case 22:
+ return strdup("NEBCALLBACK_ADAPTIVE_HOST_DATA"); break;
+ case 23:
+ return strdup("NEBCALLBACK_ADAPTIVE_SERVICE_DATA"); break;
+ case 24:
+ return strdup("NEBCALLBACK_EXTERNAL_COMMAND_DATA"); break;
+ case 25:
+ return strdup("NEBCALLBACK_AGGREGATED_STATUS_DATA"); break;
+ case 26:
+ return strdup("NEBCALLBACK_RETENTION_DATA"); break;
+ case 27:
+ return strdup("NEBCALLBACK_CONTACT_NOTIFICATION_DATA"); break;
+ case 28:
+ return strdup("NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA"); break;
+ case 29:
+ return strdup("NEBCALLBACK_ACKNOWLEDGEMENT_DATA"); break;
+ case 30:
+ return strdup("NEBCALLBACK_STATE_CHANGE_DATA"); break;
+ case 31:
+ return strdup("NEBCALLBACK_CONTACT_STATUS_DATA"); break;
+ case 32:
+ return strdup("NEBCALLBACK_ADAPTIVE_CONTACT_DATA"); break;
+ }
+ return strdup("UNKNOWN");
+}
diff --git a/include/common.h b/include/common.h
index 52e36cf..649d720 100644
--- a/include/common.h
+++ b/include/common.h
@@ -58,6 +58,7 @@
#define GM_BUFFERSIZE 98304
#define GM_MAX_OUTPUT 65536 /* must be ~30% below GM_BUFFERSIZE for base64/encryption */
#define GM_LISTSIZE 512
+#define GM_NEBTYPESSIZE 32 /* maximum number of neb types */
#define GM_MIN_LIB_GEARMAN_VERSION 0.14
#define GM_SERVER_DEFAULT_PORT 4730
@@ -133,10 +134,9 @@
*
*/
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 */
+ char * name[GM_LISTSIZE]; /**< list of queue names to export into */
+ int return_code[GM_LISTSIZE]; /**< list of return codes which should be returned to nagios */
+ int elem_number; /**< number of elements */
} mod_gm_exp_t;
/** options structure
@@ -175,8 +175,8 @@ typedef struct mod_gm_opt_struct {
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 */
int do_hostchecks; /**< flag whether mod-gearman will process hostchecks at all */
- mod_gm_exp_t * exports[GM_LISTSIZE]; /**< list of exporter queues */
- int exports_num; /**< number of elements in exports */
+ mod_gm_exp_t * exports[GM_NEBTYPESSIZE]; /**< list of exporter queues */
+ int exports_count; /**< number of export queues */
/* worker */
char * identifier; /**< identifier for this worker */
char * pidfile; /**< path to a pidfile */
diff --git a/include/utils.h b/include/utils.h
index 5fbec74..42f2375 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -398,15 +398,28 @@ int escaped(int ch);
void escape(char *out, int ch);
/**
- * type2str
+ * neb_type2str
*
- * get human readable name for eventbroker type int
+ * get human readable name for neb type int
*
* @param[in] i - integer to translate
*
* @return the human readable string
*/
-char * type2str(int i);
+char * neb_type2str(int i);
+
+
+/**
+ * event_type2str
+ *
+ * get human readable name for event type int
+ *
+ * @param[in] i - integer to translate
+ *
+ * @return the human readable string
+ */
+char * event_type2str(int i);
+
/**
* @}
diff --git a/neb_module/mod_gearman.c b/neb_module/mod_gearman.c
index 17d54ff..0d0d8fa 100644
--- a/neb_module/mod_gearman.c
+++ b/neb_module/mod_gearman.c
@@ -71,7 +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;
+ int i;
int broker_option_errors = 0;
/* save our handle */
@@ -151,10 +151,9 @@ int nebmodule_init( int flags, char *args, nebmodule *handle ) {
}
/* 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 );
- }
+ 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 */
@@ -722,13 +721,13 @@ static int verify_options(mod_gm_opt_t *opt) {
if( opt->servicegroups_num == 0
&& opt->hostgroups_num == 0
- && opt->exports_num == 0
+ && opt->exports_count == 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" );
+ gm_log( GM_LOG_ERROR, "loading Mod-Gearman NEB module without any queues is useless\n" );
return(GM_ERROR);
}
@@ -955,6 +954,7 @@ int handle_perfdata(int event_type, void *data) {
/* handle generic exports */
int handle_export(int event_type, void *data) {
+ int i;
char * buffer;
char * type;
nebstruct_log_data * nld;
@@ -985,9 +985,9 @@ int handle_export(int event_type, void *data) {
case NEBCALLBACK_TIMED_EVENT_DATA: /* 8 */
break;
case NEBCALLBACK_LOG_DATA: /* 9 */
- nld = (nebstruct_log_data *)data;
+ nld = (nebstruct_log_data *)data;
buffer = escapestring(nld->data);
- type = type2str(nld->type);
+ type = neb_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,
@@ -1048,27 +1048,30 @@ int handle_export(int event_type, void *data) {
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 );
+ gm_log( GM_LOG_DEBUG, "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" );
+
+ 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" );
+ }
}
} else {
gm_log( GM_LOG_TRACE, "handle_export() finished\n" );
--
Debian packaging for mod gearman.
More information about the Pkg-nagios-changes
mailing list