static int
noit_console_show_rabbitmq(mtev_console_closure_t ncct,
                           int argc, char **argv,
                           mtev_console_state_t *dstate,
                           void *closure) {
  int i;
  nc_printf(ncct, " == RabbitMQ ==\n");
  nc_printf(ncct, " Concurrency:           %llu\n", stats.concurrency);
  nc_printf(ncct, " Connects:              %llu\n", stats.connects);
  nc_printf(ncct, " AMQP basic returns:    %llu\n", stats.basic_returns);
  nc_printf(ncct, " AMQP methods (in):     %llu\n", stats.inbound_methods);
  nc_printf(ncct, " AMQP heartbeats (in):  %llu\n", stats.inbound_heartbeats);
  nc_printf(ncct, " AMQP basic publish:    %llu\n", stats.publications);
  pthread_mutex_lock(&driver_lock);
  for(i=0;i<MAX_HOSTS;i++) {
    struct amqp_driver *dr;
    if(!stats.thread_states[i].owner) continue;
    dr = &stats.thread_states[i];
    nc_printf(ncct, "   == connection: %p ==\n", (void *)(vpsized_int)dr->owner);
    if(dr->connection)
      nc_printf(ncct, "     %s@%s:%d (vhost: %s, exchange: %s)\n",
                dr->username, dr->hostname[dr->hostidx], dr->port, dr->vhost,
                dr->exchange);
    else
      nc_printf(ncct, "     not connected\n");
  }
  pthread_mutex_unlock(&driver_lock);
  return 1;
}
Exemple #2
0
int
noit_conf_check_set_attr(noit_console_closure_t ncct,
                         int argc, char **argv,
                         noit_console_state_t *state, void *closure) {
  struct _valid_attr_t *attrinfo = closure;
  noit_conf_t_userdata_t *info;

  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
  if(!info || validate_attr_set_scope(info, attrinfo)) {
    nc_printf(ncct, "'%s' attribute only valid in %s scope\n",
              attrinfo->name, attrinfo->scope);
    return -1;
  }

  if(argc != 1) {
    nc_printf(ncct, "set requires exactly one value\n");
    return -1;
  }
  /* Okay, we have an attribute and it should be set/replaced on the
   * current path.
   */
  if(replace_attr(ncct, info, attrinfo, argv[0])) {
    return -1;
  }

  /* So, we updated an attribute, so we need to reload all checks
   * that are descendent-or-self of this node.
   */
  if(!strncmp(info->path, "/checks", strlen("/checks")))
    refresh_subchecks(ncct, info);
  if(!strncmp(info->path, "/filtersets", strlen("/filtersets")))
    noit_refresh_filtersets(ncct, info);
  return 0;
}
Exemple #3
0
static int
noit_console_show_watchlist(noit_console_closure_t ncct,
                            int argc, char **argv,
                            noit_console_state_t *dstate,
                            void *closure) {
  noit_skiplist_node *iter, *fiter;
  nc_printf(ncct, "%d active watches.\n", watchlist.size);
  for(iter = noit_skiplist_getlist(&watchlist); iter;
      noit_skiplist_next(&watchlist, &iter)) {
    char uuid_str[UUID_STR_LEN + 1];
    noit_check_t *check = iter->data;

    uuid_unparse_lower(check->checkid, uuid_str);
    nc_printf(ncct, "%s:\n\t[%s`%s`%s]\n\tPeriod: %dms\n\tFeeds[%d]:\n",
              uuid_str, check->target, check->module, check->name,
              check->period, check->feeds ? check->feeds->size : 0);
    if(check->feeds && check->feeds->size) {
      for(fiter = noit_skiplist_getlist(check->feeds); fiter;
          noit_skiplist_next(check->feeds, &fiter)) {
        nc_printf(ncct, "\t\t%s\n", (const char *)fiter->data);
      }
    }
  }
  return 0;
}
Exemple #4
0
static int
mtev_console_lua_repl_execute(mtev_console_closure_t ncct,
                              int argc, char **argv,
                              mtev_console_state_t *state, void *closure) {
  lua_State *L;
  mtev_lua_repl_userdata_t *info;
  lua_general_conf_t *conf = NULL;
  lua_module_closure_t *lmc = NULL;
  char *buff;
  int i, rv;

  info = mtev_console_userdata_get(ncct, MTEV_LUA_REPL_USERDATA);
  if(info) {
    conf = get_config(info->self);
    lmc = pthread_getspecific(conf->key);
  }
  if(!lmc) {
    nc_printf(ncct, "Internal error, cannot find lua state.\n");
    return -1;
  }
#define EVALSIZE (1<<15)
  buff = malloc(EVALSIZE);
  buff[0] = '\0';
  for(i=0;i<argc;i++) {
    if(i) strlcat(buff, " ", EVALSIZE);
    strlcat(buff, argv[i], EVALSIZE);
  }

  L = lmc->lua_state;
  lua_pushConsole(L, ncct);
  lua_getglobal(L, "mtev");
  lua_getfield(L, -1, "extras");
  lua_remove(L, -2);  /* pop mtev */
  lua_getfield(L, -1, "repl_eval");
  lua_remove(L, -2);  /* pop extras */
  lua_pushstring(L, buff);
  lua_pushConsole(L, ncct);
  rv = lua_pcall(L, 2, LUA_MULTRET, -4);
  if(rv) {
    int i;
    i = lua_gettop(L);
    if(i>0) {
      if(lua_isstring(L, i)) {
        const char *err;
        size_t len;
        err = lua_tolstring(L, i, &len);
        nc_printf(ncct, "eval failed: %s\n", err);
      }
    }
    lua_pop(L, i);
    return -1;
  }
  lua_pop(L, lua_gettop(L));

  free(buff);
#undef EVALSIZE
  return 0;
}
int
_noit_console_state_do(noit_console_closure_t ncct,
                       noit_console_state_stack_t *stack,
                       int argc, char **argv) {
  noit_skiplist_node *next, *amb = NULL;
  cmd_info_t *cmd;

  if(!argc) {
    noit_console_render_help(ncct, stack->state);
    nc_printf(ncct, "arguments expected\n");
    return -1;
  }
  cmd = noit_skiplist_find_neighbors(&stack->state->cmds, argv[0],
                                     NULL, NULL, &next);
  if(!cmd) {
    int ambiguous = 0;
    if(next) {
      cmd_info_t *pcmd = NULL;
      cmd = next->data;
      amb = next;
      noit_skiplist_next(&stack->state->cmds, &amb);
      if(amb) pcmd = amb->data;
      /* So cmd is the next in line... pcmd is the one after that.
       * If they both strncasecmp to 0, we're ambiguous,
       *    neither, then we're not found.
       *    only cmd, then we've found a partial, unambiguous.
       */
      if(strncasecmp(cmd->name, argv[0], strlen(argv[0])) == 0) {
        if(pcmd && strncasecmp(pcmd->name, argv[0], strlen(argv[0])) == 0) {
          cmd = NULL;
          ambiguous = 1;
        }
      }
      else
        cmd = NULL;
    }
    if(!cmd) {
      if(ambiguous || !strcmp(argv[0], "?")) {
        char *partial = ambiguous ? argv[0] : "";
        if(ambiguous) nc_printf(ncct, "Ambiguous command: '%s'\n", argv[0]);
        amb = ambiguous ? next : noit_skiplist_getlist(&stack->state->cmds);
        for(; amb; noit_skiplist_next(&stack->state->cmds, &amb)) {
          cmd = amb->data;
          if(!strlen(partial) || strncasecmp(cmd->name, partial, strlen(partial)) == 0)
            nc_printf(ncct, "\t%s\n", cmd->name);
          else
            break;
        }
      }
      else
        nc_printf(ncct, "No such command: '%s'\n", argv[0]);
      return -1;
    }
  }
  if(ncct->state_stack->name) free(ncct->state_stack->name);
  ncct->state_stack->name = strdup(cmd->name);
  return cmd->func(ncct, argc-1, argv+1, cmd->dstate, cmd->closure);
}
void
mtev_capabilities_features_ncprint(mtev_console_closure_t ncct) {
  mtev_hash_iter iter = MTEV_HASH_ITER_ZERO;
  while(mtev_hash_adv(&features, &iter)) {
    if(iter.value.str)
      nc_printf(ncct, "feature:\t%s:%s\n", iter.key.str, iter.value.str);
    else
      nc_printf(ncct, "feature:\t%s\n", iter.key.str);
  }
}
static int
nc_print_dns_cache_node(mtev_console_closure_t ncct,
                        const char *target, dns_cache_node *n) {
  nc_printf(ncct, "==== %s ====\n", target);
  if(!n) nc_printf(ncct, "NOT FOUND\n");
  else {
    int i;
    char buff[INET6_ADDRSTRLEN];
    time_t now = time(NULL);
    nc_printf(ncct, "%16s: %ds ago\n", "last needed", now - n->last_needed);
    nc_printf(ncct, "%16s: %ds ago\n", "resolved", now - n->last_updated);
    nc_printf(ncct, "%16s: %ds\n", "ttl", n->ttl);
    if(n->lookup_inflight_v4) nc_printf(ncct, "actively resolving A RRs\n");
    if(n->lookup_inflight_v6) nc_printf(ncct, "actively resolving AAAA RRs\n");
    for(i=0;i<n->ip4_cnt;i++) {
      inet_ntop(AF_INET, &n->ip4[i], buff, sizeof(buff));
      nc_printf(ncct, "%17s %s\n", i?"":"IPv4:", buff);
    }
    for(i=0;i<n->ip6_cnt;i++) {
      inet_ntop(AF_INET6, &n->ip6[i], buff, sizeof(buff));
      nc_printf(ncct, "%17s %s\n", i?"":"IPv6:", buff);
    }
  }
  return 0;
}
Exemple #8
0
static void
nc_printf_check_brief(noit_console_closure_t ncct,
                      noit_check_t *check) {
  char out[512];
  char uuid_str[37];
  snprintf(out, sizeof(out), "%s`%s", check->target, check->name);
  uuid_unparse_lower(check->checkid, uuid_str);
  nc_printf(ncct, "%s %s\n", uuid_str, out);
  if(check->stats.current.status)
    nc_printf(ncct, "\t%s\n", check->stats.current.status);
}
static void
noit_console_spit_jobq(eventer_jobq_t *jobq, void *c) {
  noit_console_closure_t ncct = c;
  int qlen = 0;
  const char *bqn = "(undefined)";
  if(jobq->backq && jobq->backq->queue_name) bqn = jobq->backq->queue_name;
  nc_printf(ncct, "=== %s ===\n", jobq->queue_name);
  nc_printf(ncct, " concurrency: %d\n", jobq->concurrency);
  nc_printf(ncct, " backq: %s\n", bqn);
  sem_getvalue(&jobq->semaphore, &qlen);
  nc_printf(ncct, " queue size: %d\n", qlen);
}
Exemple #10
0
static int
mtev_lua_ncct_print(lua_State *L) {
  mtev_console_closure_t ncct;
  int i;
  ncct = lua_touserdata(L, lua_upvalueindex(1));
  for(i=1; i<=lua_gettop(L); i++) {
    if(i>1) nc_printf(ncct, "\t");
    nc_printf(ncct, "%s", lua_tostring(L,1));
  }
  nc_printf(ncct, "\n");
  return 0;
}
Exemple #11
0
static void
nc_printf_dns_handle_brief(noit_console_closure_t ncct,
                           dns_ctx_handle_t *h) {
  nc_printf(ncct, "== %s ==\n", h->hkey);
  nc_printf(ncct, " ns: %s\n refcnt: %d\n", h->ns, h->refcnt);
  nc_printf(ncct, " e: %d\n", h->e ? h->e->fd : -1);
  if(h->timeout) {
    struct timeval now, diff;
    gettimeofday(&now, NULL);
    sub_timeval(h->timeout->whence, now, &diff);
    nc_printf(ncct, " timeout: %f\n",
              diff.tv_sec + (double)diff.tv_usec/1000000.0);
  }
}
Exemple #12
0
static int
noit_console_filter_show(mtev_console_closure_t ncct,
                         int argc, char **argv,
                         mtev_console_state_t *state,
                         void *closure) {
  mtev_conf_t_userdata_t *info;
  char xpath[1024];
  xmlNodePtr fsnode;
  mtev_conf_section_t *rules;
  int i, rulecnt;

  info = mtev_console_userdata_get(ncct, MTEV_CONF_T_USERDATA);
  snprintf(xpath, sizeof(xpath), "/%s",
           info->path);
  fsnode = mtev_conf_get_section(NULL, xpath);
  if(!fsnode) {
    nc_printf(ncct, "internal error\n");
    return -1;
  }
  rules = mtev_conf_get_sections(fsnode, "rule", &rulecnt);
  for(i=0; i<rulecnt; i++) {
    char val[256];
    val[0] = '\0';
    mtev_conf_get_stringbuf(rules[i], "@type", val, sizeof(val));
    nc_printf(ncct, "Rule %d [%s]:\n", i+1, val);
#define DUMP_ATTR(a) do { \
  char *vstr; \
  mtev_conf_section_t ht; \
  int cnt; \
  ht = mtev_conf_get_sections(rules[i], #a, &cnt); \
  if(ht && cnt) { \
    nc_printf(ncct, "\t%s: hash match of %d items\n", #a, cnt); \
  } \
  else if(mtev_conf_get_string(rules[i], "@" #a, &vstr)) { \
    nc_printf(ncct, "\t%s: /%s/\n", #a, val); \
    free(vstr); \
  } \
  free(ht); \
} while(0)
    DUMP_ATTR(target);
    DUMP_ATTR(module);
    DUMP_ATTR(name);
    DUMP_ATTR(metric);
    DUMP_ATTR(id);
    DUMP_ATTR(skipto);
  }
  if(rules) free(rules);
  return 0;
}
int
noit_console_render_help(noit_console_closure_t ncct,
                         noit_console_state_t *dstate) {
  noit_skiplist_node *iter = NULL;
  if(!dstate) {
    nc_printf(ncct, "No help available.\n");
    return -1;
  }
  for(iter = noit_skiplist_getlist(&dstate->cmds); iter;
      noit_skiplist_next(&dstate->cmds,&iter)) {
    cmd_info_t *cmd = iter->data;
    if(strcmp(cmd->name, "help")) nc_printf(ncct, "  ==> '%s'\n", cmd->name);
  }
  return 0;
}
Exemple #14
0
void
noit_refresh_filtersets(noit_console_closure_t ncct,
                        noit_conf_t_userdata_t *info) {
  noit_filters_from_conf();
  nc_printf(ncct, "Reloaded %d filtersets.\n",
            filtersets ? filtersets->size : 0);
}
Exemple #15
0
void
noit_refresh_filtersets(mtev_console_closure_t ncct,
                        mtev_conf_t_userdata_t *info) {
  noit_filters_from_conf();
  nc_printf(ncct, "Reloaded %d filtersets.\n",
            filtersets ? mtev_hash_size(filtersets) : 0);
}
static void
noit_console_spit_event(eventer_t e, void *c) {
  struct timeval now, diff;
  noit_console_closure_t ncct = c;
  char fdstr[12];
  char wfn[42];
  char funcptr[20];
  const char *cname;

  cname = eventer_name_for_callback(e->callback);
  snprintf(fdstr, sizeof(fdstr), " fd: %d", e->fd);
  gettimeofday(&now, NULL);
  sub_timeval(e->whence, now, &diff);
  snprintf(wfn, sizeof(wfn), " fires: %lld.%06ds", (long long)diff.tv_sec, (int)diff.tv_usec);
  snprintf(funcptr, sizeof(funcptr), "%p", e->callback);
  nc_printf(ncct, "  [%p]%s%s [%c%c%c%c] -> %s(%p)\n",
            e,
            e->mask & (EVENTER_READ | EVENTER_WRITE | EVENTER_EXCEPTION) ? fdstr : "",
            e->mask & (EVENTER_TIMER) ?  wfn : "",
            e->mask & EVENTER_READ ? 'r' : '-',
            e->mask & EVENTER_WRITE ? 'w' : '-',
            e->mask & EVENTER_EXCEPTION ? 'e' : '-',
            e->mask & EVENTER_TIMER ? 't' : '-',
            cname ? cname : funcptr, e->closure);
}
Exemple #17
0
int
noit_console_config_unsetconfig(noit_console_closure_t ncct,
                                int argc, char **argv,
                                noit_console_state_t *state, void *closure) {
  noit_conf_t_userdata_t *info;

  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);

  if(argc != 1) {
    nc_printf(ncct, "one argument required.\n");
    return -1;
  }
  /* Okay, we have an child name and it should be culled from
   * current path/config.
   */
  if(replace_config(ncct, info, argv[0], NULL)) {
    return -1;
  }

  /* So, we updated an attribute, so we need to reload all checks
   * that are descendent-or-self of this node.
   */
  refresh_subchecks(ncct, info);
  return 0;
}
static int
noit_console_version(noit_console_closure_t ncct, int argc, char **argv,
                     noit_console_state_t *dstate, void *unused) {
  char buff[256];
  noit_build_version(buff, sizeof(buff));
  nc_printf(ncct, "version: %s\n", buff);
  return 0;
}
Exemple #19
0
void
noit_console_motd(eventer_t e, acceptor_closure_t *ac,
                  noit_console_closure_t ncct) {
  int ssl;
  ssl = eventer_get_eventer_ssl_ctx(e) ? 1 : 0;
  nc_printf(ncct, "noitd%s: %s\n",
            ssl ? "(secure)" : "",
            ac->remote_cn ? ac->remote_cn : "(no auth)");
}
Exemple #20
0
void
noit_console_dispatch(eventer_t e, const char *buffer,
                      noit_console_closure_t ncct) {
  char **cmds;
  HistEvent ev;
  int i, cnt = 32;

  cmds = alloca(32 * sizeof(*cmds));
  i = noit_tokenize(buffer, cmds, &cnt);

  /* < 0 is an error, that's fine.  We want it in the history to "fix" */
  /* > 0 means we had arguments, so let's put it in the history */
  /* 0 means nothing -- and that isn't worthy of history inclusion */
  if(i) history(ncct->hist, &ev, H_ENTER, buffer);

  if(i>cnt) nc_printf(ncct, "Command length too long.\n");
  else if(i<0) nc_printf(ncct, "Error at offset: %d\n", 0-i);
  else noit_console_state_do(ncct, cnt, cmds);
}
int
noit_console_state_delegate(noit_console_closure_t ncct,
                            int argc, char **argv,
                            noit_console_state_t *dstate,
                            void *closure) {
  noit_console_state_stack_t tmps = { 0 };

  if(argc == 0) {
    noit_console_render_help(ncct, dstate);
    nc_printf(ncct, "incomplete command.\n");
    return -1;
  }
  if(!dstate) {
    nc_printf(ncct, "internal error: no delegate state\n");
    return -1;
  }
  tmps.state = dstate;
  return _noit_console_state_do(ncct, &tmps, argc, argv);
}
static void
nc_print_stat_metrics(mtev_console_closure_t ncct,
                      noit_check_t *check, stats_t *c) {
  int mcount=0, cnt=0;
  const char **sorted_keys;
  char buff[256];
  mtev_boolean filtered;
  mtev_hash_table *metrics;
  mtev_hash_iter iter = MTEV_HASH_ITER_ZERO;
  const char *k;
  int klen;
  void *data;

  metrics = noit_check_stats_metrics(c);
  memset(&iter, 0, sizeof(iter));
  while(mtev_hash_next(metrics, &iter, &k, &klen, &data)) cnt++;
  sorted_keys = malloc(cnt * sizeof(*sorted_keys));
  memset(&iter, 0, sizeof(iter));
  while(mtev_hash_next(metrics, &iter, &k, &klen, &data)) {
    if(sorted_keys && mcount < cnt) sorted_keys[mcount++] = k;
    else {
      noit_stats_snprint_metric(buff, sizeof(buff), (metric_t *)data);
      filtered = !noit_apply_filterset(check->filterset, check, (metric_t *)data);
      nc_printf(ncct, "  %c%s\n", filtered ? '*' : ' ', buff);
    }
  }
  if(sorted_keys) {
    int j;
    qsort(sorted_keys, mcount, sizeof(*sorted_keys),
          _qsort_string_compare);
    for(j=0;j<mcount;j++) {
      if(mtev_hash_retrieve(metrics,
                            sorted_keys[j], strlen(sorted_keys[j]),
                            &data)) {
        noit_stats_snprint_metric(buff, sizeof(buff), (metric_t *)data);
        filtered = !noit_apply_filterset(check->filterset, check, (metric_t *)data);
        nc_printf(ncct, "  %c%s\n", filtered ? '*' : ' ', buff);
      }
    }
    free(sorted_keys);
  }
}
int
noit_console_generic_apply(noit_console_closure_t ncct,
                           int argc, char **argv,
                           noit_console_state_t *dstate,
                           void *closure) {
  int i, j, count;
  char *name, *range;
  char **nargv, **expanded = NULL;
  const char *err;
  int problems = 0;
  if(argc < 3) {
    nc_printf(ncct, "apply <name> <range> cmd ...\n");
    return -1;
  }
  name = argv[0];
  range = argv[1];
  argc -= 2;
  argv += 2;

  count = expand_range(range, &expanded, 256, &err);
  if(!count) {
    nc_printf(ncct, "apply error: '%s' range produced nothing [%s]\n",
              range, err ? err : "unknown error");
    assert(expanded == NULL);
    return -1;
  }
  if(count < 0) {
    nc_printf(ncct, "apply error: '%s' range would produce %d items.\n",
              range, count);
    return -1;
  }
  nargv = malloc(argc * sizeof(*nargv));
  for(i=0; i<count; i++) {
    for(j=0; j<argc; j++) nargv[j] = apply_replace(argv[j], name, expanded[i]);
    if(noit_console_state_do(ncct, argc, nargv)) problems = -1;
    for(j=0; j<argc; j++) free(nargv[j]);
    free(expanded[i]);
  }
  free(nargv);
  free(expanded);
  return problems;
}
Exemple #24
0
static void
nc_attr_show(noit_console_closure_t ncct, const char *name, xmlNodePtr cnode,
             xmlNodePtr anode, const char *value) {
  const char *cpath, *apath;
  cpath = cnode ? (char *)xmlGetNodePath(cnode) : "";
  apath = anode ? (char *)xmlGetNodePath(anode) : "";
  nc_printf(ncct, " %s: %s", name, value ? value : "[undef]");
  if(value && cpath && apath) {
    int clen = strlen(cpath);
    int plen = strlen("/noit/checks/");
    if(!strncmp(cpath, apath, clen) && apath[clen] == '/') {
      /* we have a match, which means it isn't inherited */
    }
    else {
      nc_printf(ncct, " [inherited from %s]",
                strlen(apath) > plen ? apath + plen : apath);
    }
  }
  nc_write(ncct, "\n", 1);
}
static void
noit_console_spit_jobq(eventer_jobq_t *jobq, void *c) {
  noit_console_closure_t ncct = c;
  int qlen = 0;
  const char *bqn = "(undefined)";
  if(jobq->backq && jobq->backq->queue_name) bqn = jobq->backq->queue_name;
  nc_printf(ncct, "=== %s ===\n", jobq->queue_name);
  nc_printf(ncct, " concurrency: %d/%d\n", jobq->concurrency, jobq->desired_concurrency);
  nc_printf(ncct, " backq: %s\n", bqn);
  sem_getvalue(&jobq->semaphore, &qlen);
  nc_printf(ncct, " total jobs: %lld\n", (long long int)jobq->total_jobs);
  nc_printf(ncct, " backlog: %d\n", jobq->backlog);
  nc_printf(ncct, " inflight: %d\n", jobq->inflight);
  nc_printf(ncct, " timeouts: %lld\n", (long long int)jobq->timeouts);
  nc_printf(ncct, " avg_wait_ms: %f\n", (double)jobq->avg_wait_ns/1000000.0);
  nc_printf(ncct, " avg_run_ms: %f\n", (double)jobq->avg_run_ns/1000000.0);
}
static int
noit_console_version(noit_console_closure_t ncct, int argc, char **argv,
                     noit_console_state_t *dstate, void *unused) {
  char buff[256];
  struct utsname utsn;
  nc_printf(ncct,   "build sysname:\t%s\nbuild nodename:\t%s\n"
                    "build release:\t%s\nbuild version:\t%s\n"
                    "build machine:\t%s\n",
            UNAME_S, UNAME_N, UNAME_R, UNAME_V, UNAME_M);
  if(uname(&utsn) < 0)
    nc_printf(ncct, "run:\terror; %s\n", strerror(errno));
  else
    nc_printf(ncct, "run sysname:\t%s\nrun nodename:\t%s\n"
                    "run release:\t%s\nrun version:\t%s\n"
                    "run machine:\t%s\n",
              utsn.sysname, utsn.nodename, utsn.release, utsn.version, utsn.machine);
  nc_printf(ncct, "bitwidth:\t%dbit\n", (int)sizeof(void *)*8);
  noit_build_version(buff, sizeof(buff));
  nc_printf(ncct, "version:\t%s\n", buff);
  return 0;
}
int
noit_console_help(noit_console_closure_t ncct, int argc, char **argv,
                  noit_console_state_t *dstate, void *unused) {
  noit_console_state_stack_t *current;
  current = ncct->state_stack;

  if(!argc) {
    noit_console_state_stack_t *i;
    if(!current) {
      nc_printf(ncct, "no state!\n");
      return -1;
    }
    for(i=current;i;i=i->last) {
      if(i != current)
        nc_printf(ncct, " -> '%s'\n", i->name ? i->name : "(null)");
    }
    if(dstate) {
      nc_printf(ncct, "= Topics =\n");
      noit_console_render_help(ncct, dstate);
    }
    if(current->state) {
      nc_printf(ncct, "\n= Commands =\n");
      noit_console_render_help(ncct, current->state);
    }
    return 0;
  }
  else if(argc > 0) {
    nc_printf(ncct, "Help for '%s':\n", argv[0]);
    if(noit_console_state_delegate(ncct, argc, argv, dstate, NULL) == 0)
      return 0;
  }
  nc_printf(ncct, "command not understood.\n");
  return -1;
}
Exemple #28
0
static int
noit_console_filter_cull(mtev_console_closure_t ncct,
                         int argc, char **argv,
                         mtev_console_state_t *state,
                         void *closure) {
  int rv = 0;
  mtev_conf_t_userdata_t *info;

  info = mtev_console_userdata_get(ncct, MTEV_CONF_T_USERDATA);
  if(!info) {
    nc_printf(ncct, "internal error\n");
    return -1;
  }
  if(strncmp(info->path, "/filtersets/", strlen("/filtersets/")) &&
     strcmp(info->path, "/filtersets")) {
    nc_printf(ncct, "filterset only allows inside /filtersets (not %s)\n",
              info->path);
    return -1;
  }
  rv = noit_filtersets_cull_unused();
  nc_printf(ncct, "Culled %d unused filtersets\n", rv);
  return 0;
}
static int
nc_print_dns_cache_node(noit_console_closure_t ncct,
                        const char *target, dns_cache_node *n) {
  nc_printf(ncct, "==== %s ====\n", target);
  if(!n) nc_printf(ncct, "NOT FOUND\n");
  else {
    int i;
    time_t now = time(NULL);
    nc_printf(ncct, "%16s: %ds ago\n", "last needed", now - n->last_needed);
    nc_printf(ncct, "%16s: %ds ago\n", "resolved", now - n->last_updated);
    nc_printf(ncct, "%16s: %ds\n", "ttl", n->ttl);
    if(n->lookup_inflight_v4) nc_printf(ncct, "actively resolving A RRs\n");
    if(n->lookup_inflight_v6) nc_printf(ncct, "actively resolving AAAA RRs\n");
    for(i=0;i<n->ip4_cnt;i++)
      nc_printf(ncct, "%17s %s\n", i?"":"IPv4:", n->ip4[i]);
    for(i=0;i<n->ip6_cnt;i++)
      nc_printf(ncct, "%17s %s\n", i?"":"IPv6:", n->ip6[i]);
  }
  return 0;
}
static int
noit_console_eventer_jobq(noit_console_closure_t ncct, int argc, char **argv,
                             noit_console_state_t *dstate, void *unused) {
  eventer_jobq_t *jobq;
  if(argc != 1) {
    eventer_jobq_process_each(noit_console_spit_jobq, (void *)ncct);
    return 0;
  }
  jobq = eventer_jobq_retrieve(argv[0]);
  if(!jobq) {
    nc_printf(ncct, "no jobq found for '%s'\n", argv[0] ? argv[0] : "");
    return 0;
  }
  noit_console_spit_jobq(jobq, ncct);
  return 0;
}