[Pkg-nagios-changes] [SCM] Debian packaging for mod gearman. branch, upstream, updated. e9a5a6997d9dd8b31b433b5bcbad495448db0131
Sven Nierlein
sven at nierlein.org
Thu Apr 7 08:06:15 UTC 2011
The following commit has been merged in the upstream branch:
commit 8cdede8404cd15fdfb73e61170b9ad477f6328b9
Merge: e5a4d6c2b51b90d76a6203dcf16ccf6431b5489f 0983ff1bd6d7e8fcd6df84e7863d46ceb0dceeb5
Author: Sven Nierlein <sven at nierlein.org>
Date: Sat Feb 19 21:45:40 2011 +0100
Merge branch 'master' into exporter
Conflicts:
common/utils.c
diff --combined common/utils.c
index 4a70591,3991cfe..fcb0eef
--- a/common/utils.c
+++ b/common/utils.c
@@@ -26,6 -26,7 +26,7 @@@
#include "crypt.h"
#include "base64.h"
+ pid_t current_child_pid = 0;
/* escapes newlines in a string */
char *escape_newlines(char *rawbuf) {
@@@ -241,9 -242,6 +242,9 @@@ int set_default_options(mod_gm_opt_t *o
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);
}
@@@ -301,52 -299,65 +302,65 @@@ int parse_args_line(mod_gm_opt_t *opt,
/* daemon mode */
if ( !strcmp( key, "daemon" ) || !strcmp( key, "d" ) ) {
opt->daemon_mode = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
}
/* perfdata */
else if ( !strcmp( key, "perfdata" ) ) {
opt->set_queues_by_hand++;
opt->perfdata = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
}
/* hosts */
else if ( !strcmp( key, "hosts" ) ) {
opt->set_queues_by_hand++;
opt->hosts = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
}
/* services */
else if ( !strcmp( key, "services" ) ) {
opt->set_queues_by_hand++;
opt->services = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
}
/* eventhandler */
- else if ( !strcmp( key, "events" )
- || !strcmp( key, "eventhandlers" )
+ else if ( !strcmp( key, "eventhandlers" )
+ || !strcmp( key, "eventhandler" )
) {
opt->set_queues_by_hand++;
opt->events = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
}
/* debug-result */
else if ( !strcmp( key, "debug-result" ) ) {
opt->debug_result = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
}
/* encryption */
else if ( !strcmp( key, "encryption" ) ) {
opt->encryption = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
}
/* fork_on_exec */
else if ( !strcmp( key, "fork_on_exec" ) ) {
opt->fork_on_exec = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
}
/* active */
else if ( !strcmp( key, "active" ) ) {
opt->active = parse_yes_or_no(value, GM_ENABLED);
+ return(GM_OK);
+ }
+ else if ( value == NULL ) {
+ gm_log( GM_LOG_ERROR, "unknown switch '%s'\n", key );
+ return(GM_OK);
}
if ( value == NULL )
@@@ -571,26 -582,9 +585,30 @@@
}
}
}
+
+ /* 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++;
+ }
+
+ else {
+ gm_log( GM_LOG_ERROR, "unknown option '%s'\n", key );
+ }
++
return(GM_OK);
}
@@@ -644,9 -638,6 +662,9 @@@ int read_config_file(mod_gm_opt_t *opt
/* 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);
@@@ -695,18 -686,6 +713,18 @@@
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 */
@@@ -742,11 -721,6 +760,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);
@@@ -970,7 -944,12 +988,12 @@@ int run_check(char *processed_command,
parse_command_line(processed_command,argv);
if(!argv[0])
_exit(STATE_UNKNOWN);
+ current_child_pid = getpid();
execvp(argv[0], argv);
+ if(errno == 2)
+ _exit(127);
+ if(errno == 13)
+ _exit(126);
_exit(STATE_UNKNOWN);
}
@@@ -992,6 -971,7 +1015,7 @@@
retval=-1;
}
else {
+ current_child_pid = getpid();
gm_log( GM_LOG_TRACE, "using popen\n" );
fp=popen(processed_command,"r");
if(fp==NULL)
@@@ -1009,6 -989,216 +1033,216 @@@
}
+ /* execute this command with given timeout */
+ int execute_safe_command(gm_job_t * exec_job, int fork_exec, char * hostname) {
+ int pdes[2];
+ int return_code;
+ int pclose_result;
+ char *plugin_output;
+ char buffer[GM_BUFFERSIZE];
+ sigset_t mask;
+ struct timeval start_time,end_time;
+ pid_t pid = 0;
+
+ gm_log( GM_LOG_TRACE, "execute_safe_command()\n" );
+
+ if(exec_job->start_time.tv_sec == 0) {
+ gettimeofday(&start_time,NULL);
+ exec_job->start_time = start_time;
+ }
+
+ /* fork a child process */
+ if(fork_exec == GM_ENABLED) {
+ if(pipe(pdes) != 0)
+ perror("pipe");
+
+ pid=fork();
+
+ /*fork error */
+ if( pid == -1 ) {
+ exec_job->output = strdup("(Error On Fork)");
+ exec_job->return_code = 3;
+ return(GM_ERROR);
+ }
+ }
+
+ /* we are in the child process */
+ if( fork_exec == GM_DISABLED || pid == 0 ) {
+
+ /* become the process group leader */
+ setpgid(0,0);
+ pid = getpid();
+
+ /* remove all customn signal handler */
+ sigfillset(&mask);
+ sigprocmask(SIG_UNBLOCK, &mask, NULL);
+
+ if( fork_exec == GM_ENABLED )
+ close(pdes[0]);
+ signal(SIGALRM, check_alarm_handler);
+ alarm(exec_job->timeout);
+
+ /* run the plugin check command */
+ pclose_result = run_check(exec_job->command_line, &plugin_output);
+ return_code = pclose_result;
+
+ if(fork_exec == GM_ENABLED) {
+ if(write(pdes[1], plugin_output, strlen(plugin_output)+1) <= 0)
+ perror("write");
+
+ if(pclose_result == -1) {
+ char error[GM_BUFFERSIZE];
+ snprintf(error, sizeof(error), "error on %s: %s", hostname, strerror(errno));
+ if(write(pdes[1], error, strlen(error)+1) <= 0)
+ perror("write");
+ }
+
+ return_code = real_exit_code(pclose_result);
+ exit(return_code);
+ }
+ else {
+ snprintf( buffer, sizeof( buffer )-1, "%s", plugin_output );
+ }
+ }
+
+ /* we are the parent */
+ if( fork_exec == GM_DISABLED || pid > 0 ){
+
+ gm_log( GM_LOG_TRACE, "started check with pid: %d\n", pid);
+
+ if( fork_exec == GM_ENABLED) {
+ close(pdes[1]);
+
+ waitpid(pid, &return_code, 0);
+ gm_log( GM_LOG_TRACE, "finished check from pid: %d with status: %d\n", pid, return_code);
+ /* get all lines of plugin output */
+ if(read(pdes[0], buffer, sizeof(buffer)-1) < 0)
+ perror("read");
+ }
+ return_code = real_exit_code(return_code);
+
+ /* file not executable? */
+ if(return_code == 126) {
+ return_code = STATE_CRITICAL;
+ snprintf( buffer, sizeof( buffer )-1, "CRITICAL: Return code of 126 is out of bounds. Make sure the plugin you're trying to run is executable. (worker: %s)", hostname);
+ }
+ /* file not found errors? */
+ else if(return_code == 127) {
+ return_code = STATE_CRITICAL;
+ snprintf( buffer, sizeof( buffer )-1, "CRITICAL: Return code of 127 is out of bounds. Make sure the plugin you're trying to run actually exists. (worker: %s)", hostname);
+ }
+ /* signaled */
+ else if(return_code >= 128 && return_code < 256) {
+ char * signame = nr2signal((int)(return_code-128));
+ snprintf( buffer, sizeof( buffer )-1, "CRITICAL: Return code of %d is out of bounds. Plugin exited by signal %s. (worker: %s)", (int)(return_code), signame, hostname);
+ return_code = STATE_CRITICAL;
+ free(signame);
+ }
+ /* other error codes > 3 */
+ else if(return_code > 3) {
+ snprintf( buffer, sizeof( buffer )-1, "CRITICAL: Return code of %d is out of bounds. (worker: %s)", (int)(return_code), hostname);
+ return_code = STATE_CRITICAL;
+ }
+
+ exec_job->output = strdup(buffer);
+ exec_job->return_code = return_code;
+ if( fork_exec == GM_ENABLED) {
+ close(pdes[0]);
+ }
+ }
+ alarm(0);
+ current_child_pid = 0;
+ pid = 0;
+
+ /* record check result info */
+ gettimeofday(&end_time, NULL);
+ exec_job->finish_time = end_time;
+
+ /* did we have a timeout? */
+ if(exec_job->timeout < ((int)end_time.tv_sec - (int)exec_job->start_time.tv_sec)) {
+ exec_job->return_code = 2;
+ exec_job->early_timeout = 1;
+ if ( !strcmp( exec_job->type, "service" ) )
+ snprintf( buffer, sizeof( buffer ) -1, "(Service Check Timed Out On Worker: %s)", hostname);
+ if ( !strcmp( exec_job->type, "host" ) )
+ snprintf( buffer, sizeof( buffer ) -1, "(Host Check Timed Out On Worker: %s)", hostname);
+ exec_job->output = strdup( buffer );
+ }
+
+ return(GM_OK);
+ }
+
+
+ /* set empty default job */
+ int set_default_job(gm_job_t *job, mod_gm_opt_t *mod_gm_opt) {
+
+ job->type = NULL;
+ job->host_name = NULL;
+ job->service_description = NULL;
+ job->result_queue = NULL;
+ job->command_line = NULL;
+ job->output = NULL;
+ job->exited_ok = TRUE;
+ job->scheduled_check = TRUE;
+ job->reschedule_check = TRUE;
+ job->return_code = STATE_OK;
+ job->latency = 0.0;
+ job->timeout = mod_gm_opt->job_timeout;
+ job->start_time.tv_sec = 0L;
+ job->start_time.tv_usec = 0L;
+
+ return(GM_OK);
+ }
+
+
+ /* free the job structure */
+ int free_job(gm_job_t *job) {
+
+ free(job->type);
+ free(job->host_name);
+ free(job->service_description);
+ free(job->result_queue);
+ free(job->command_line);
+ free(job->output);
+ free(job);
+
+ return(GM_OK);
+ }
+
+
+
+ /* called when check runs into timeout */
+ void check_alarm_handler(int sig) {
+ int retval;
+ pid_t pid = getpid();
+
+ gm_log( GM_LOG_TRACE, "check_alarm_handler(%i)\n", sig );
+
+ if(current_child_pid > 0) {
+ gm_log( GM_LOG_TRACE, "send SIGINT to %d\n", current_child_pid);
+ signal(SIGINT, SIG_IGN);
+ kill(-current_child_pid, SIGINT);
+ sleep(1);
+ if(waitpid(pid,&retval,0)!=pid)
+ return;
+ if(pid_alive(current_child_pid)) {
+ gm_log( GM_LOG_TRACE, "send SIGKILL to %d\n", current_child_pid);
+ kill(-current_child_pid, SIGKILL);
+ }
+ } else {
+ signal(SIGINT, SIG_IGN);
+ gm_log( GM_LOG_TRACE, "send SIGINT to %d\n", pid);
+ kill(-pid, SIGINT);
+ signal(SIGINT, SIG_DFL);
+ sleep(1);
+ gm_log( GM_LOG_TRACE, "send SIGKILL to %d\n", pid);
+ kill(-pid, SIGKILL);
+ }
+
+ return;
+ }
+
+
/* verify if a pid is alive */
int pid_alive(int pid) {
if(pid < 0) { pid = -pid; }
@@@ -1024,227 -1214,3 +1258,227 @@@
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");
- }
++}
diff --combined include/common.h
index 1e9e764,cd60ed9..55c9972
--- a/include/common.h
+++ b/include/common.h
@@@ -52,7 -52,7 +52,7 @@@
#define MOD_GM_COMMON_H
/* constants */
- #define GM_VERSION "1.0"
+ #define GM_VERSION "1.0"
#define GM_ENABLED 1
#define GM_DISABLED 0
#define GM_BUFFERSIZE 98304
@@@ -122,18 -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
@@@ -168,8 -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 -182,28 +196,28 @@@
} mod_gm_opt_t;
+ /** structure for jobs to execute */
+ typedef struct gm_job_struct {
+ char * host_name; /**< hostname for this job */
+ char * service_description; /**< service description for this job or NULL */
+ char * command_line; /**< command line to execute */
+ char * type; /**< type of this job */
+ char * result_queue; /**< name of the result queue */
+ char * output; /**< output from the executed command line */
+ int return_code; /**< return code for this job */
+ int early_timeout; /**< did the check run into a timeout */
+ int check_options; /**< check_options given from the core */
+ int scheduled_check; /**< normal scheduled check? */
+ int reschedule_check; /**< rescheduled check? */
+ int exited_ok; /**< did the plugin exit normally? */
+ int timeout; /**< timeout for this job */
+ double latency; /**< latency for from this job */
+ struct timeval core_start_time; /**< time when the core started the job */
+ struct timeval start_time; /**< time when the job really started */
+ struct timeval finish_time; /**< time when the job was finished */
+ } gm_job_t;
+
+
/**
* general logger
*
@@@ -210,7 -218,6 +232,7 @@@
*/
void gm_log( int lvl, const char *text, ... );
+
/*
* @}
*/
diff --combined include/utils.h
index 763c1b7,ba35da3..5fbec74
--- a/include/utils.h
+++ b/include/utils.h
@@@ -302,6 -302,57 +302,57 @@@ int parse_command_line(char *cmd, char
int run_check(char *processed_command, char **plugin_output);
/**
+ *
+ * execute_safe_command
+ *
+ * execute command and fill the exec job structure
+ *
+ * @param[in] exec_job - job structure
+ * @param[in] fork_exec - fork or not before exec
+ * @param[in] hostname - current worker hostname
+ *
+ * @return true on success
+ */
+ int execute_safe_command(gm_job_t * exec_job, int fork_exec, char * hostname);
+
+ /**
+ *
+ * check_alarm_handler
+ *
+ * called when a check runs into the timeout
+ *
+ * @param[in] sig - signal number
+ *
+ * @return nothing
+ */
+ void check_alarm_handler(int sig);
+
+ /**
+ *
+ * set_default_job
+ *
+ * fill defaults into job structure
+ *
+ * @param[in] job - job structure to be filled
+ * @param[in] mod_gm_opt - options structure
+ *
+ * @return true on success
+ */
+ int set_default_job(gm_job_t *job, mod_gm_opt_t *mod_gm_opt);
+
+ /**
+ *
+ * free_job
+ *
+ * free job structure
+ *
+ * @param[in] job - job structure to be freed
+ *
+ * @return true on success
+ */
+ int free_job(gm_job_t *job);
+
+ /**
* pid_alive
*
* check if a pid is alive
@@@ -313,50 -364,5 +364,50 @@@
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);
+
+/**
* @}
*/
--
Debian packaging for mod gearman.
More information about the Pkg-nagios-changes
mailing list