[Pkg-nagios-changes] [SCM] Debian packaging for mod gearman. branch, upstream, updated. e9a5a6997d9dd8b31b433b5bcbad495448db0131

Sven Nierlein sven at nierlein.org
Thu Apr 7 08:06:34 UTC 2011


The following commit has been merged in the upstream branch:
commit ae57adc1c1cce4e9661340d66f7d5b0dc5cf826c
Merge: e3d56af2c60342262da5773425495f5e3ad555a7 9cd2d750d3e56e0a2beffa481f9e347199cd8bca
Author: Sven Nierlein <sven at nierlein.org>
Date:   Fri Mar 11 18:50:31 2011 +0100

    Merge branch 'master' into exporter
    
    Conflicts:
    	Changes
    	configure.ac
    	include/common.h
    	neb_module/mod_gearman.c

diff --combined common/utils.c
index fcb0eef,a6966a0..72b2fbe
--- a/common/utils.c
+++ b/common/utils.c
@@@ -204,6 -204,8 +204,8 @@@ int set_default_options(mod_gm_opt_t *o
      opt->timeout            = 10;
      opt->debug_level        = GM_LOG_INFO;
      opt->perfdata           = GM_DISABLED;
+     opt->perfdata_mode      = GM_PERFDATA_OVERWRITE;
+     opt->do_hostchecks      = GM_ENABLED;
      opt->hosts              = GM_DISABLED;
      opt->services           = GM_DISABLED;
      opt->events             = GM_DISABLED;
@@@ -219,6 -221,7 +221,7 @@@
      opt->fork_on_exec       = GM_ENABLED;
      opt->idle_timeout       = GM_DEFAULT_IDLE_TIMEOUT;
      opt->max_jobs           = GM_DEFAULT_MAX_JOBS;
+     opt->spawn_rate         = GM_DEFAULT_SPAWN_RATE;
      opt->identifier         = NULL;
  
      opt->host               = NULL;
@@@ -242,9 -245,6 +245,9 @@@
      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);
  }
@@@ -353,6 -353,12 +356,12 @@@ int parse_args_line(mod_gm_opt_t *opt, 
          return(GM_OK);
      }
  
+     /* do_hostchecks */
+     else if ( !strcmp( key, "do_hostchecks" ) ) {
+         opt->do_hostchecks = 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);
@@@ -506,6 -512,21 +515,21 @@@
          if(opt->max_jobs < 0) { opt->max_jobs = GM_DEFAULT_MAX_JOBS; }
      }
  
+     /* spawn-rate */
+     else if ( !strcmp( key, "spawn-rate" ) ) {
+         opt->spawn_rate = atoi( value );
+         if(opt->spawn_rate < 0) { opt->spawn_rate = GM_DEFAULT_SPAWN_RATE; }
+     }
+ 
+     /* perfdata_mode */
+     else if ( !strcmp( key, "perfdata_mode" ) ) {
+         opt->perfdata_mode = atoi( value );
+         if(opt->perfdata_mode < 0 || opt->perfdata_mode > 2) {
+             gm_log( GM_LOG_INFO, "Warning: unknown perfdata_mode: %d\n", opt->perfdata_mode );
+             opt->perfdata_mode = GM_PERFDATA_OVERWRITE;
+         }
+     }
+ 
      /* server */
      else if ( !strcmp( key, "server" ) ) {
          char *servername;
@@@ -585,30 -606,9 +609,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);
  }
  
@@@ -662,9 -662,6 +686,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);
@@@ -677,11 -674,13 +701,13 @@@
          gm_log( GM_LOG_DEBUG, "job timeout:         %d\n", opt->job_timeout);
          gm_log( GM_LOG_DEBUG, "min worker:          %d\n", opt->min_worker);
          gm_log( GM_LOG_DEBUG, "max worker:          %d\n", opt->max_worker);
+         gm_log( GM_LOG_DEBUG, "spawn rate:          %d\n", opt->spawn_rate);
          gm_log( GM_LOG_DEBUG, "fork on exec:        %s\n", opt->fork_on_exec == GM_ENABLED ? "yes" : "no");
      }
      if(mode == GM_NEB_MODE) {
          gm_log( GM_LOG_DEBUG, "debug result:        %s\n", opt->debug_result == GM_ENABLED ? "yes" : "no");
          gm_log( GM_LOG_DEBUG, "result_worker:       %d\n", opt->result_workers);
+         gm_log( GM_LOG_DEBUG, "do_hostchecks:       %s\n", opt->do_hostchecks == GM_ENABLED ? "yes" : "no");
      }
      if(mode == GM_NEB_MODE || mode == GM_SEND_GEARMAN_MODE) {
          gm_log( GM_LOG_DEBUG, "result_queue:        %s\n", opt->result_queue);
@@@ -696,7 -695,8 +722,8 @@@
          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");
+         gm_log( GM_LOG_DEBUG, "perfdata:            %s\n", opt->perfdata      == GM_ENABLED ? "yes" : "no");
+         gm_log( GM_LOG_DEBUG, "perfdata mode:       %s\n", opt->perfdata_mode == GM_PERFDATA_OVERWRITE ? "overwrite" : "append");
      }
      if(mode == GM_NEB_MODE || mode == GM_WORKER_MODE) {
          gm_log( GM_LOG_DEBUG, "hosts:               %s\n", opt->hosts        == GM_ENABLED ? "yes" : "no");
@@@ -713,18 -713,6 +740,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 */
@@@ -760,11 -748,6 +787,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);
@@@ -780,7 -763,6 +807,6 @@@
  /* read keyfile */
  int read_keyfile(mod_gm_opt_t *opt) {
      FILE *fp;
-     int i;
  
      if(opt->keyfile == NULL)
          return(GM_ERROR);
@@@ -794,9 -776,11 +820,11 @@@
      if(opt->crypt_key != NULL)
          free(opt->crypt_key);
      opt->crypt_key = malloc(GM_BUFFERSIZE);
-     for(i=0;i<32;i++)
-         opt->crypt_key[i] = fgetc(fp);
+ 
+     fgets(opt->crypt_key, 33, fp);
      fclose(fp);
+     rtrim(opt->crypt_key);
+ 
      return(GM_OK);
  }
  
@@@ -1258,227 -1242,3 +1286,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");
 +}
diff --combined include/common.h
index 0bb64fa,bb1f580..52e36cf
--- a/include/common.h
+++ b/include/common.h
@@@ -52,7 -52,7 +52,7 @@@
  #define MOD_GM_COMMON_H
  
  /* constants */
- #define GM_VERSION                   "1.1"
+ #define GM_VERSION                 "1.0.2"
  #define GM_ENABLED                      1
  #define GM_DISABLED                     0
  #define GM_BUFFERSIZE               98304
@@@ -86,9 -86,10 +86,10 @@@
  #define MAX_CMD_ARGS                 4096
  
  /* worker */
- #define GM_DEFAULT_MIN_WORKER           1      /**< minumum number of worker            */
- #define GM_DEFAULT_MAX_WORKER          20      /**< maximum number of concurrent worker */
- #define GM_DEFAULT_JOB_MAX_AGE        600      /**< discard jobs older than that        */
+ #define GM_DEFAULT_MIN_WORKER           1      /**< minumum number of worker             */
+ #define GM_DEFAULT_MAX_WORKER          20      /**< maximum number of concurrent worker  */
+ #define GM_DEFAULT_JOB_MAX_AGE        600      /**< discard jobs older than that         */
+ #define GM_DEFAULT_SPAWN_RATE           1      /**< number of spawned worker per seconds */
  
  /* transport modes */
  #define GM_ENCODE_AND_ENCRYPT           1
@@@ -103,6 -104,10 +104,10 @@@
  #define GM_WORKER_STOP                  1
  #define GM_WORKER_RESTART               2
  
+ /* perfdata modes */
+ #define GM_PERFDATA_OVERWRITE           1
+ #define GM_PERFDATA_APPEND              2
+ 
  
  #ifndef TRUE
  #define TRUE                            1
@@@ -122,18 -127,6 +127,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
@@@ -163,13 -156,13 +168,15 @@@ typedef struct mod_gm_opt_struct 
  /* neb module */
      char         * result_queue;                            /**< name of the result queue used by the neb module */
      int            result_workers;                          /**< number of result worker threads started */
-     int            perfdata;                                /**< flag whether perfdata are distributed or not */
+     int            perfdata;                                /**< flag whether perfdata will be distributed or not */
+     int            perfdata_mode;                           /**< flag whether perfdata will be sent with/without uniq set */
      char         * local_hostgroups_list[GM_LISTSIZE];      /**< list of hostgroups which will not be distributed */
      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 */
+     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 */
  /* worker */
      char         * identifier;                              /**< identifier for this worker */
      char         * pidfile;                                 /**< path to a pidfile */
@@@ -183,6 -176,7 +190,7 @@@
      int            fork_on_exec;                            /**< flag to disable additional forks for each job */
      int            idle_timeout;                            /**< number of seconds till a idle worker exits */
      int            max_jobs;                                /**< maximum number of jobs done after a worker exits */
+     int            spawn_rate;                              /**< number of spawned new worker */
  /* send_gearman */
      int            timeout;                                 /**< timeout for waiting reading on stdin */
      int            return_code;                             /**< return code */
@@@ -232,7 -226,6 +240,7 @@@ typedef struct gm_job_struct 
   */
  void gm_log( int lvl, const char *text, ... );
  
 +
  /*
   * @}
   */
diff --combined neb_module/mod_gearman.c
index f217538,53b9236..17d54ff
--- a/neb_module/mod_gearman.c
+++ b/neb_module/mod_gearman.c
@@@ -62,7 -62,6 +62,7 @@@ static int   handle_host_check( int,voi
  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 * );
@@@ -71,7 -70,7 +71,8 @@@ static check_result * merge_result_list
  static void move_results_to_core(void);
  
  int nebmodule_init( int flags, char *args, nebmodule *handle ) {
 +    int i,j;
+     int broker_option_errors = 0;
  
      /* save our handle */
      gearman_module_handle=handle;
@@@ -97,11 -96,11 +98,11 @@@
      /* check for minimum eventbroker options */
      if(!(event_broker_options & BROKER_PROGRAM_STATE)) {
          gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_PROGRAM_STATE (%i) event_broker_options enabled to work\n", BROKER_PROGRAM_STATE );
-         return NEB_ERROR;
+         broker_option_errors++;
      }
      if(!(event_broker_options & BROKER_TIMED_EVENTS)) {
          gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_TIMED_EVENTS (%i) event_broker_options enabled to work\n", BROKER_TIMED_EVENTS );
-         return NEB_ERROR;
+         broker_option_errors++;
      }
      if(    (    mod_gm_opt->perfdata == GM_ENABLED
               || mod_gm_opt->hostgroups_num > 0
@@@ -109,7 -108,7 +110,7 @@@
             )
          && !(event_broker_options & BROKER_HOST_CHECKS)) {
          gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_HOST_CHECKS (%i) event_broker_options enabled to work\n", BROKER_HOST_CHECKS );
-         return NEB_ERROR;
+         broker_option_errors++;
      }
      if(    (    mod_gm_opt->perfdata == GM_ENABLED
               || mod_gm_opt->servicegroups_num > 0
@@@ -117,12 -116,14 +118,14 @@@
             )
          && !(event_broker_options & BROKER_SERVICE_CHECKS)) {
          gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_SERVICE_CHECKS (%i) event_broker_options enabled to work\n", BROKER_SERVICE_CHECKS );
-         return NEB_ERROR;
+         broker_option_errors++;
      }
      if(mod_gm_opt->events == GM_ENABLED && !(event_broker_options & BROKER_EVENT_HANDLERS)) {
          gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_EVENT_HANDLERS (%i) event_broker option enabled to work\n", BROKER_EVENT_HANDLERS );
-         return NEB_ERROR;
+         broker_option_errors++;
      }
+     if(broker_option_errors > 0)
+         return NEB_ERROR;
  
      /* check the minimal gearman version */
      if((float)atof(gearman_version()) < (float)GM_MIN_LIB_GEARMAN_VERSION) {
@@@ -147,13 -148,6 +150,13 @@@
          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 );
@@@ -168,7 -162,7 +171,7 @@@
  static void register_neb_callbacks(void) {
  
      /* only if we have hostgroups defined or general hosts enabled */
-     if ( mod_gm_opt->hostgroups_num > 0 || mod_gm_opt->hosts == GM_ENABLED )
+     if ( mod_gm_opt->do_hostchecks == GM_ENABLED && ( mod_gm_opt->hostgroups_num > 0 || mod_gm_opt->hosts == GM_ENABLED ))
          neb_register_callback( NEBCALLBACK_HOST_CHECK_DATA,    gearman_module_handle, 0, handle_host_check );
  
      /* only if we have groups defined or general services enabled */
@@@ -179,6 -173,8 +182,8 @@@
          neb_register_callback( NEBCALLBACK_EVENT_HANDLER_DATA, gearman_module_handle, 0, handle_eventhandler );
  
      if ( mod_gm_opt->perfdata == GM_ENABLED ) {
+         if(process_performance_data == 0)
+             gm_log( GM_LOG_INFO, "Warning: process_performance_data is disabled globally, cannot process performance data\n" );
          neb_register_callback( NEBCALLBACK_HOST_CHECK_DATA, gearman_module_handle, 0, handle_perfdata );
          neb_register_callback( NEBCALLBACK_SERVICE_CHECK_DATA, gearman_module_handle, 0, handle_perfdata );
      }
@@@ -198,7 -194,7 +203,7 @@@ int nebmodule_deinit( int flags, int re
      neb_deregister_callback( NEBCALLBACK_TIMED_EVENT_DATA, gearman_module_handle );
  
      /* only if we have hostgroups defined or general hosts enabled */
-     if ( mod_gm_opt->hostgroups_num > 0 || mod_gm_opt->hosts == GM_ENABLED )
+     if ( mod_gm_opt->do_hostchecks == GM_ENABLED && ( mod_gm_opt->hostgroups_num > 0 || mod_gm_opt->hosts == GM_ENABLED ))
          neb_deregister_callback( NEBCALLBACK_HOST_CHECK_DATA, gearman_module_handle );
  
      /* only if we have groups defined or general services enabled */
@@@ -410,6 -406,9 +415,9 @@@ static int handle_host_check( int event
  
      gm_log( GM_LOG_TRACE, "handle_host_check(%i)\n", event_type );
  
+     if ( mod_gm_opt->do_hostchecks != GM_ENABLED )
+         return NEB_OK;
+ 
      hostdata = ( nebstruct_host_check_data * )data;
  
      gm_log( GM_LOG_TRACE, "---------------\nhost Job -> %i, %i\n", event_type, hostdata->type );
@@@ -565,9 -564,9 +573,9 @@@ static int handle_svc_check( int event_
          return NEB_OK;
      }
  
-     /* as we have to intercept host checks so early
+     /* as we have to intercept service checks so early
       * (we cannot cancel checks otherwise)
-      * we have to do some host check logic here
+      * we have to do some service check logic here
       * taken from checks.c:
       */
      /* clear check options - we don't want old check options retained */
@@@ -701,9 -700,6 +709,9 @@@ static int verify_options(mod_gm_opt_t 
          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" );
@@@ -714,16 -710,18 +722,16 @@@
  
      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
@@@ -861,6 -859,9 +869,9 @@@ int handle_perfdata(int event_type, voi
                      break;
                  }
  
+                 uniq[0]='\x0';
+                 snprintf( uniq,sizeof( temp_buffer )-1,"%s", hostchkdata->host_name);
+ 
                  temp_buffer[0]='\x0';
                  snprintf( temp_buffer,sizeof( temp_buffer )-1,
                              "DATATYPE::HOSTPERFDATA\t"
@@@ -894,6 -895,9 +905,9 @@@
                      break;
                  }
  
+                 uniq[0]='\x0';
+                 snprintf( uniq,sizeof( temp_buffer )-1,"%s-%s", srvchkdata->host_name, srvchkdata->service_description);
+ 
                  temp_buffer[0]='\x0';
                  snprintf( temp_buffer,sizeof( temp_buffer )-1,
                              "DATATYPE::SERVICEPERFDATA\t"
@@@ -922,7 -926,7 +936,7 @@@
          if(add_job_to_queue( &client,
                               mod_gm_opt->server_list,
                               GM_PERFDATA_QUEUE,
-                              NULL,
+                              (mod_gm_opt->perfdata_mode == GM_PERFDATA_OVERWRITE ? uniq : NULL),
                               temp_buffer,
                               GM_JOB_PRIO_NORMAL,
                               GM_DEFAULT_JOB_RETRIES,
@@@ -937,128 -941,3 +951,128 @@@
  
      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;
 +}

-- 
Debian packaging for mod gearman.



More information about the Pkg-nagios-changes mailing list