Example #1
0
static iep_thread_driver_t *noit_fq_allocate(noit_conf_section_t conf) {
  char *hostname, *cp, *brk;
  int i;

#define GETCONFSTR(w) noit_conf_get_stringbuf(conf, #w, global_fq_ctx.w, sizeof(global_fq_ctx.w))
  snprintf(global_fq_ctx.exchange, sizeof(global_fq_ctx.exchange), "%s",
           "noit.firehose");
  GETCONFSTR(exchange);
  if(!GETCONFSTR(routingkey))
    snprintf(global_fq_ctx.routingkey, sizeof(global_fq_ctx.routingkey), "%s", "check");
  snprintf(global_fq_ctx.username, sizeof(global_fq_ctx.username), "%s", "guest");
  GETCONFSTR(username);
  snprintf(global_fq_ctx.password, sizeof(global_fq_ctx.password), "%s", "guest");
  GETCONFSTR(password);
  if(!noit_conf_get_int(conf, "heartbeat", &global_fq_ctx.heartbeat))
    global_fq_ctx.heartbeat = 2000;
  if(!noit_conf_get_int(conf, "backlog", &global_fq_ctx.backlog))
    global_fq_ctx.backlog = 2000;
  if(!noit_conf_get_int(conf, "port", &global_fq_ctx.port))
    global_fq_ctx.port = 8765;
  (void)noit_conf_get_string(conf, "hostname", &hostname);
  if(!hostname) hostname = strdup("127.0.0.1");
  for(cp = hostname; cp; cp = strchr(cp+1, ',')) global_fq_ctx.nhosts++;
  if(global_fq_ctx.nhosts > MAX_HOSTS) global_fq_ctx.nhosts = MAX_HOSTS;
  for(i = 0, cp = strtok_r(hostname, ",", &brk);
      cp; cp = strtok_r(NULL, ",", &brk), i++) {
    char *pcp;
    fq_client *c = &global_fq_ctx.client[i];

    global_fq_ctx.ports[i] = global_fq_ctx.port;
    strlcpy(global_fq_ctx.hostname[i], cp, sizeof(global_fq_ctx.hostname[i]));
    pcp = strchr(global_fq_ctx.hostname[i], ':');
    if(pcp) {
      *pcp++ = '\0';
      global_fq_ctx.ports[i] = atoi(pcp);
    }
    fq_client_init(c, 0, fq_logger);
    fq_client_creds(*c, global_fq_ctx.hostname[i], global_fq_ctx.ports[i],
                    global_fq_ctx.username, global_fq_ctx.password);
    fq_client_heartbeat(*c, global_fq_ctx.heartbeat);
    fq_client_set_nonblock(*c, 1);
    fq_client_set_backlog(*c, global_fq_ctx.backlog, 0);
    fq_client_connect(*c);
  }
  free(hostname);

  return (iep_thread_driver_t *)&global_fq_ctx;
}
Example #2
0
int
noit_check_max_initial_stutter() {
  int stutter;
  if(!noit_conf_get_int(NULL, "/noit/checks/@max_initial_stutter", &stutter))
    stutter = MAX_INITIAL_STUTTER;
  return stutter;
}
Example #3
0
noit_check_t *
noit_check_watch(uuid_t in, int period) {
  /* First look for a copy that is being watched */
  int minimum_pi = 1000, granularity_pi = 500;
  noit_conf_section_t check_node;
  char uuid_str[UUID_STR_LEN + 1];
  char xpath[1024];
  noit_check_t n, *f;

  uuid_unparse_lower(in, uuid_str);
  /* Find the check */
  snprintf(xpath, sizeof(xpath), "//checks//check[@uuid=\"%s\"]", uuid_str);
  check_node = noit_conf_get_section(NULL, xpath);
  noit_conf_get_int(NULL, "//checks/@transient_min_period", &minimum_pi);
  noit_conf_get_int(NULL, "//checks/@transient_period_granularity", &granularity_pi);
  if(check_node) {
    noit_conf_get_int(check_node,
                      "ancestor-or-self::node()/@transient_min_period",
                      &minimum_pi);
    noit_conf_get_int(check_node,
                      "ancestor-or-self::node()/@transient_period_granularity",
                      &granularity_pi);
  }

  /* apply the bounds */
  period /= granularity_pi;
  period *= granularity_pi;
  period = MAX(period, minimum_pi);

  uuid_copy(n.checkid, in);
  n.period = period;

  f = noit_skiplist_find(&watchlist, &n, NULL);
  if(f) return f;
  f = noit_check_clone(in);
  if(!f) return NULL;
  f->period = period;
  f->timeout = period - 10;
  f->flags |= NP_TRANSIENT;
  noitL(noit_debug, "Watching %s@%d\n", uuid_str, period);
  noit_skiplist_insert(&watchlist, f);
  return f;
}
Example #4
0
static iep_thread_driver_t *noit_rabbimq_allocate() {
  char *hostname, *cp, *brk;
  struct amqp_driver *dr = NULL;
  int i;

  pthread_mutex_lock(&driver_lock);
  for(i=0; i<MAX_HOSTS; i++) {
    if(stats.thread_states[i].owner == (pthread_t)NULL) {
      stats.thread_states[i].owner = pthread_self();
      dr = &stats.thread_states[i];
      break;
    }
  }
  pthread_mutex_unlock(&driver_lock);
  if(!dr) return NULL;
  dr->nconnects = rand();
#define GETCONFSTR(w) noit_conf_get_stringbuf(NULL, "/stratcon/iep/mq/" #w, dr->w, sizeof(dr->w))
  GETCONFSTR(exchange);
  if(!GETCONFSTR(routingkey))
    dr->routingkey[0] = '\0';
  GETCONFSTR(username);
  GETCONFSTR(password);
  if(!GETCONFSTR(vhost)) { dr->vhost[0] = '/'; dr->vhost[1] = '\0'; }
  if(!noit_conf_get_int(NULL, "/stratcon/iep/mq/heartbeat", &dr->heartbeat))
    dr->heartbeat = 5000;
  dr->heartbeat = (dr->heartbeat + 999) / 1000;

  noit_conf_get_string(NULL, "/stratcon/iep/mq/hostname", &hostname);
  if(!hostname) hostname = strdup("127.0.0.1");
  for(cp = hostname; cp; cp = strchr(cp+1, ',')) dr->nhosts++;
  if(dr->nhosts > MAX_HOSTS) dr->nhosts = MAX_HOSTS;
  for(i = 0, cp = strtok_r(hostname, ",", &brk);
      cp; cp = strtok_r(NULL, ",", &brk), i++)
    strlcpy(dr->hostname[i], cp, sizeof(dr->hostname[i]));
  free(hostname);

  if(!noit_conf_get_int(NULL, "/stratcon/iep/mq/port", &dr->port))
    dr->port = 5672;
  noit_atomic_inc64(&stats.concurrency);
  return (iep_thread_driver_t *)dr;
}
Example #5
0
static iep_thread_driver_t *noit_stomp_allocate(noit_conf_section_t conf) {
  struct stomp_driver *dr;
  dr = calloc(1, sizeof(*dr));
  if(apr_pool_create(&dr->pool, NULL) != APR_SUCCESS) {
    free(dr);
    return NULL;
  }
  (void)noit_conf_get_string(conf, "exchange", &dr->exchange);
  if(!noit_conf_get_string(conf, "destination", &dr->destination))
  if(!dr->destination) dr->destination = strdup("/queue/noit.firehose");
  (void)noit_conf_get_string(conf, "username", &dr->user);
  (void)noit_conf_get_string(conf, "password", &dr->pass);
  (void)noit_conf_get_string(conf, "hostname", &dr->hostname);
  if(!dr->hostname) dr->hostname = strdup("127.0.0.1");
  if(!noit_conf_get_int(conf, "port", &dr->port))
    dr->port = 61613;
  return (iep_thread_driver_t *)dr;
}
Example #6
0
void
noit_listener_reconfig(const char *toplevel) {
  int i, cnt = 0;
  noit_conf_section_t *listener_configs;
  char path[256];

  snprintf(path, sizeof(path), "/%s/listeners//listener",
           toplevel ? toplevel : "*");
  listener_configs = noit_conf_get_sections(NULL, path, &cnt);
  noitL(noit_debug, "Found %d %s stanzas\n", cnt, path);
  for(i=0; i<cnt; i++) {
    char address[256];
    char type[256];
    unsigned short port;
    int portint;
    int backlog;
    eventer_func_t f;
    noit_boolean ssl;
    noit_hash_table *sslconfig, *config;

    if(!noit_conf_get_stringbuf(listener_configs[i],
                                "ancestor-or-self::node()/@type",
                                type, sizeof(type))) {
      noitL(noit_error, "No type specified in listener stanza %d\n", i+1);
      continue;
    }
    f = eventer_callback_for_name(type);
    if(!f) {
      noitL(noit_error,
            "Cannot find handler for listener type: '%s'\n", type);
      continue;
    }
    if(!noit_conf_get_stringbuf(listener_configs[i],
                                "ancestor-or-self::node()/@address",
                                address, sizeof(address))) {
      address[0] = '*';
      address[1] = '\0';
    }
    if(!noit_conf_get_int(listener_configs[i],
                          "ancestor-or-self::node()/@port", &portint))
      portint = 0;
    port = (unsigned short) portint;
    if(address[0] != '/' && (portint == 0 || (port != portint))) {
      /* UNIX sockets don't require a port (they'll ignore it if specified */
      noitL(noit_error,
            "Invalid port [%d] specified in stanza %d\n", port, i+1);
      continue;
    }
    if(noit_listener_should_skip(address, port)) {
      if(port)
        noitL(noit_error, "Operator forced skipping listener %s:%d\n", address, port);
      else
        noitL(noit_error, "Operator forced skipping listener %s\n", address);
      continue;
    }
    if(!noit_conf_get_int(listener_configs[i],
                          "ancestor-or-self::node()/@backlog", &backlog))
      backlog = 5;

    if(!noit_conf_get_boolean(listener_configs[i],
                              "ancestor-or-self::node()/@ssl", &ssl))
     ssl = noit_false;

    sslconfig = ssl ?
                  noit_conf_get_hash(listener_configs[i], "sslconfig") :
                  NULL;
    config = noit_conf_get_hash(listener_configs[i], "config");

    if(noit_listener(address, port, SOCK_STREAM, backlog,
                     sslconfig, config, f, NULL) != 0) {
      noit_hash_destroy(config,free,free);
      free(config);
    }
    if(sslconfig) {
      /* A copy of this is made within noit_listener */
      noit_hash_destroy(sslconfig,free,free);
      free(sslconfig);
    }
  }
  free(listener_configs);
}