Example #1
0
void  self_statement_If(If *v2548,OID v1741,OID v332)
{ GC_BIND;
  if (c_func_any(GC_OID(v2548->test)) == CTRUE)
   { princ_string(copy_string("if "));
    (*Optimize.bool_exp)(GC_OID(v2548->test),
      Kernel.ctrue,
      v332);
    princ_string(copy_string(""));
    breakline_void();
    princ_string(copy_string(" "));
    if (INHERIT(OWNER(v2548->arg),Language._If))
     new_block_void();
    statement_any(GC_OID(v2548->arg),v1741,v332);
    if (INHERIT(OWNER(v2548->arg),Language._If))
     close_block_void();
    if ((Kernel._string == OWNER(v1741)) || 
        (boolean_I_any(v2548->other) == CTRUE))
     { OID  v5013 = GC_OID(v2548->other);
      if (inherit_ask_class(OWNER(v5013),Language._If) != CTRUE)
       (Optimize.OPT->level = (Optimize.OPT->level+1));
      princ_string(copy_string("else "));
      statement_any(v5013,v1741,v332);
      princ_string(copy_string(""));
      if (inherit_ask_class(OWNER(v5013),Language._If) != CTRUE)
       (Optimize.OPT->level = (Optimize.OPT->level-1));
      } 
    } 
  else { OID  v1743 = GC_OID((*Generate.c_string)(Generate.PRODUCER->value,
        _oid_(append_symbol(gensym_void(),_string_(copy_string("I"))))));
      new_block_void();
      interface_I_class(Kernel._boolean);
      princ_string(copy_string(" "));
      princ_string(string_v(v1743));
      princ_string(copy_string(";"));
      breakline_void();
      statement_any(GC_OID(v2548->test),v1743,v332);
      princ_string(copy_string(""));
      breakline_void();
      (Optimize.OPT->level = (Optimize.OPT->level+1));
      princ_string(copy_string("if ("));
      princ_string(string_v(v1743));
      princ_string(copy_string(" == "));
      (*Generate.produce)(Generate.PRODUCER->value,
        Kernel.ctrue);
      princ_string(copy_string(") "));
      statement_any(GC_OID(v2548->arg),v1741,v332);
      princ_string(copy_string(""));
      (Optimize.OPT->level = (Optimize.OPT->level-1));
      if ((Kernel._string == OWNER(v1741)) || 
          (boolean_I_any(v2548->other) == CTRUE))
       { princ_string(copy_string("else "));
        statement_any(GC_OID(v2548->other),v1741,v332);
        princ_string(copy_string(""));
        } 
      close_block_void();
      } 
    GC_UNBIND;} 
Example #2
0
void StartStopCut::configure() {
  _sampleRate = parameter("sampleRate").toReal();
  _frameSize = parameter("frameSize").toInt();
  _hopSize = parameter("hopSize").toInt();
  _maximumStartTime = parameter("maximumStartTime").toReal() / 1000.f;
  _maximumStopTime = parameter("maximumStopTime").toReal() / 1000.f;
  _threshold = db2pow(parameter("threshold").toReal());

  if (_frameSize < _hopSize)
    throw(EssentiaException(
        "StartStopCut: hopSize has to be smaller or equal than the input "
        "frame size"));

  _maximumStartSamples = (uint)(_maximumStartTime * _sampleRate) + _frameSize;  
  _maximumStopSamples = (uint)(_maximumStopTime * _sampleRate) + _frameSize;  

  _frameCutter->configure(INHERIT("frameSize"), INHERIT("hopSize"),
                          INHERIT("frameSize"), "startFromZero", true);
};
Example #3
0
/* The c++ function for: string2module(s:string) [NEW_ALLOC] */
module * string2module_string(char *s)
{ { module *Result ;
    { ClaireObject *V_CC ;
      { OID  m = value_string(s);
        if (INHERIT(OWNER(m),Kernel._module))
         V_CC = OBJECT(module,m);
        else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("~A is not a module")),
            _oid_(list::alloc(1,_string_(s))))));
          } 
      Result= (module *) V_CC;} 
    return (Result);} 
  } 
Example #4
0
File: key.cpp Project: MTG/essentia
void Key::configure() {
  _keyAlgo->configure(INHERIT("usePolyphony"),
                      INHERIT("useThreeChords"),
                      INHERIT("numHarmonics"),
                      INHERIT("slope"),
                      INHERIT("profileType"),
                      INHERIT("pcpSize"),
                      INHERIT("useMajMin"));

  _averageDetuningCorrection = parameter("averageDetuningCorrection").toBool();
  _pcpThreshold = parameter("pcpThreshold").toReal();
}
Example #5
0
void  self_statement_Assign(Assign *v2548,OID v1741,OID v332)
{ GC_BIND;
  { OID  v1743 = GC_OID(v2548->var);
    OID  v1744 = GC_OID(v2548->arg);
    ClaireBoolean * v2454 = ((boolean_I_any(v332) == CTRUE) ? ((Optimize.OPT->loop_gc == CTRUE) ? ((inner2outer_ask_any(v1744) == CTRUE) ? CTRUE: CFALSE): CFALSE): CFALSE);
    OID  v1745;
    { if ((v2454 == CTRUE) && 
          (INHERIT(OWNER(v1744),Optimize._to_protect)))
       v1745 = (*Kernel.arg)(v1744);
      else v1745 = v1744;
        GC_OID(v1745);} 
    if (Kernel._string == OWNER(v1741))
     { new_block_void();
      statement_any(v1745,v1741,v332);
      princ_string(copy_string(" "));
      if (v2454 == CTRUE)
       (*Generate.gc_protection_exp)(Generate.PRODUCER->value,
        v1743,
        Kernel.cfalse,
        v1741,
        v332);
      else { ident_symbol(OBJECT(Variable,v1743)->pname);
          princ_string(copy_string(" = "));
          (*Kernel.c_princ)(v1741);
          princ_string(copy_string(""));
          } 
        princ_string(copy_string(";"));
      close_block_void();
      princ_string(copy_string(""));
      } 
    else if (v2454 == CTRUE)
     { new_block_void();
      statement_any(v1745,GC_OID((*Generate.c_string)(Generate.PRODUCER->value,
        v1743)),v332);
      princ_string(copy_string(" "));
      (*Generate.gc_protection_exp)(Generate.PRODUCER->value,
        v1743,
        Kernel.ctrue,
        v1743,
        v332);
      princ_string(copy_string(";"));
      close_block_void();
      princ_string(copy_string(""));
      } 
    else statement_any(v1744,GC_OID((*Generate.c_string)(Generate.PRODUCER->value,
        v1743)),v332);
      } 
  GC_UNBIND;} 
Example #6
0
void  self_statement_to_protect(Compile_to_protect *v2548,OID v1741,OID v332)
{ GC_BIND;
  if ((Optimize.OPT->protection == CTRUE) && 
      (Kernel._string == OWNER(v1741)))
   { ClaireClass * v1723 = OBJECT(ClaireClass,(*Optimize.c_sort)(GC_OID(v2548->arg)));
    new_block_void();
    (OBJECT(Generate_producer,Generate.PRODUCER->value)->stat = (OBJECT(Generate_producer,Generate.PRODUCER->value)->stat+1));
    statement_any(GC_OID(v2548->arg),v1741,v332);
    princ_string(gc_protect_class(v1723));
    princ_string(copy_string("("));
    if (INHERIT(v1723,Kernel._object))
     { class_princ_class(psort_any(GC_OID((*Optimize.c_type)(GC_OID(v2548->arg)))));
      princ_string(copy_string(","));
      } 
    (*Kernel.c_princ)(v1741);
    princ_string(copy_string(");"));
    close_block_void();
    } 
  else statement_any(GC_OID(v2548->arg),v1741,v332);
    GC_UNBIND;} 
Example #7
0
void  inner_statement_any(OID v2548,OID v1741,OID v332)
{ GC_BIND;
  if (INHERIT(OWNER(v2548),Language._Do))
   { list * v1732 = GC_OBJECT(list,OBJECT(Do,v2548)->args);
    int  v1733 = v1732->length;
    ClaireBoolean * v1722 = Optimize.OPT->alloc_stack;
    int  v1734 = 0;
    (Optimize.OPT->alloc_stack = CFALSE);
    { ITERATE(v1744);
      for (START(v1732); NEXT(v1744);)
      { ++v1734;
        if (v1734 == v1733)
         { (Optimize.OPT->alloc_stack = v1722);
          inner_statement_any(v1744,v1741,v332);
          } 
        else if (boolean_I_any(v1744) == CTRUE)
         inner_statement_any(v1744,_oid_(Kernel.emptySet),v332);
        } 
      } 
    } 
  else statement_any(v2548,v1741,v332);
    GC_UNBIND;} 
Example #8
0
static int
noit_console_show_check(noit_console_closure_t ncct,
                        int argc, char **argv,
                        noit_console_state_t *state, void *closure) {
  int i, cnt;
  noit_conf_t_userdata_t *info;
  char xpath[1024];
  xmlXPathObjectPtr pobj = NULL;
  xmlXPathContextPtr xpath_ctxt = NULL;

  noit_conf_xml_xpath(NULL, &xpath_ctxt);
  if(argc > 1) {
    nc_printf(ncct, "requires zero or one arguments\n");
    return -1;
  }

  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
  /* We many not be in conf-t mode -- that's fine */
  if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info,
                                argc ? argv[0] : NULL)) {
    nc_printf(ncct, "could not find check '%s'\n", argv[0]);
    return -1;
  }

  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
  if(!pobj || pobj->type != XPATH_NODESET ||
     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {
    nc_printf(ncct, "no checks found\n");
    goto out;
  }
  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
  if(info && cnt != 1) {
    nc_printf(ncct, "Ambiguous check specified\n");
    goto out;
  }
  for(i=0; i<cnt; i++) {
    noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
    const char *k;
    int klen;
    void *data;
    uuid_t checkid;
    noit_check_t *check;
    noit_hash_table *config;
    xmlNodePtr node, anode, mnode = NULL;
    char *uuid_conf;
    char *module, *value;

    node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
    uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
    if(!uuid_conf || uuid_parse(uuid_conf, checkid)) {
      nc_printf(ncct, "%s has invalid or missing UUID!\n",
                (char *)xmlGetNodePath(node) + strlen("/noit"));
      continue;
    }
    nc_printf(ncct, "==== %s ====\n", uuid_conf);

#define MYATTR(a,n,b) _noit_conf_get_string(node, &(n), "@" #a, &(b))
#define INHERIT(a,n,b) \
  _noit_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b))
#define SHOW_ATTR(a) do { \
  anode = NULL; \
  value = NULL; \
  INHERIT(a, anode, value); \
  nc_attr_show(ncct, #a, node, anode, value); \
} while(0)

    if(!INHERIT(module, mnode, module)) module = NULL;
    if(MYATTR(name, anode, value))
      nc_printf(ncct, " name: %s\n", value);
    else
      nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]");
    nc_attr_show(ncct, "module", node, mnode, module);
    SHOW_ATTR(target);
    SHOW_ATTR(period);
    SHOW_ATTR(timeout);
    SHOW_ATTR(oncheck);
    SHOW_ATTR(filterset);
    SHOW_ATTR(disable);
    /* Print out all the config settings */
    config = noit_conf_get_hash(node, "config");
    while(noit_hash_next(config, &iter, &k, &klen, &data)) {
      nc_printf(ncct, " config::%s: %s\n", k, (const char *)data);
    }
    noit_hash_destroy(config, free, free);
    free(config);

    check = noit_poller_lookup(checkid);
    if(!check) {
      nc_printf(ncct, " ERROR: not in running system\n");
    }
    else {
      int idx = 0;
      nc_printf(ncct, " currently: ");
      if(NOIT_CHECK_RUNNING(check)) nc_printf(ncct, "%srunning", idx++?",":"");
      if(NOIT_CHECK_KILLED(check)) nc_printf(ncct, "%skilled", idx++?",":"");
      if(!NOIT_CHECK_CONFIGURED(check)) nc_printf(ncct, "%sunconfig", idx++?",":"");
      if(NOIT_CHECK_DISABLED(check)) nc_printf(ncct, "%sdisabled", idx++?",":"");
      if(!idx) nc_printf(ncct, "idle");
      nc_write(ncct, "\n", 1);
      if(check->stats.current.whence.tv_sec == 0) {
        nc_printf(ncct, " last run: never\n");
      }
      else {
        stats_t *c = &check->stats.current;
        struct timeval now, diff;
        gettimeofday(&now, NULL);
        sub_timeval(now, c->whence, &diff);
        nc_printf(ncct, " last run: %0.3f seconds ago\n",
                  diff.tv_sec + (diff.tv_usec / 1000000.0));
        nc_printf(ncct, " availability/state: %s/%s\n",
                  noit_check_available_string(c->available),
                  noit_check_state_string(c->state));
        nc_printf(ncct, " status: %s\n", c->status ? c->status : "[[null]]");
        nc_printf(ncct, " metrics:\n");
        memset(&iter, 0, sizeof(iter));
        while(noit_hash_next(&c->metrics, &iter, &k, &klen, &data)) {
          char buff[256];
          noit_boolean filtered;
          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);
        }
      }
    }
  }
 out:
  if(pobj) xmlXPathFreeObject(pobj);
  return 0;
}
Example #9
0
static int
rest_show_check(mtev_http_rest_closure_t *restc,
                int npats, char **pats) {
  mtev_http_session_ctx *ctx = restc->http_ctx;
  xmlXPathObjectPtr pobj = NULL;
  xmlXPathContextPtr xpath_ctxt = NULL;
  xmlDocPtr doc = NULL;
  xmlNodePtr node, root, attr, config, state, tmp, anode;
  uuid_t checkid;
  noit_check_t *check;
  char xpath[1024], *uuid_conf, *module = NULL, *value = NULL;
  int rv, mod, mod_cnt, cnt, error_code = 500;
  mtev_hash_iter iter = MTEV_HASH_ITER_ZERO;
  const char *k;
  int klen;
  void *data;
  mtev_hash_table *configh;

  if(npats != 2 && npats != 3) goto error;

  rv = noit_check_xpath(xpath, sizeof(xpath), pats[0], pats[1]);
  if(rv == 0) goto not_found;
  if(rv < 0) goto error;

  mtev_conf_xml_xpath(NULL, &xpath_ctxt);
  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
  if(!pobj || pobj->type != XPATH_NODESET ||
     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) goto not_found;
  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
  if(cnt != 1) goto error;

  node = (mtev_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
  uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
  if(!uuid_conf || uuid_parse(uuid_conf, checkid)) goto error;

  if(npats == 3 && !strcmp(pats[2], ".json")) {
    return rest_show_check_json(restc, checkid);
  }

  doc = xmlNewDoc((xmlChar *)"1.0");
  root = xmlNewDocNode(doc, NULL, (xmlChar *)"check", NULL);
  xmlDocSetRootElement(doc, root);

#define MYATTR(node,a,n,b) _mtev_conf_get_string(node, &(n), "@" #a, &(b))
#define INHERIT(node,a,n,b) \
  _mtev_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b))
#define SHOW_ATTR(parent, node, a) do { \
  char *_value = NULL; \
  INHERIT(node, a, anode, _value); \
  if(_value != NULL) { \
    int clen, plen;\
    char *_cpath, *_apath; \
    xmlNodePtr child; \
    _cpath = node ? (char *)xmlGetNodePath(node) : strdup(""); \
    _apath = anode ? (char *)xmlGetNodePath(anode) : strdup(""); \
    clen = strlen(_cpath); \
    plen = strlen("/noit/checks"); \
    child = xmlNewNode(NULL, (xmlChar *)#a); \
    xmlNodeAddContent(child, (xmlChar *)_value); \
    if(!strncmp(_cpath, _apath, clen) && _apath[clen] == '/') { \
    } \
    else { \
      xmlSetProp(child, (xmlChar *)"inherited", (xmlChar *)_apath+plen); \
    } \
    xmlAddChild(parent, child); \
    free(_cpath); \
    free(_apath); \
    free(_value); \
  } \
} while(0)

  attr = xmlNewNode(NULL, (xmlChar *)"attributes");
  xmlAddChild(root, attr);

  SHOW_ATTR(attr,node,uuid);
  SHOW_ATTR(attr,node,seq);

  /* Name is odd, it falls back transparently to module */
  if(!INHERIT(node, module, tmp, module)) module = NULL;
  xmlAddChild(attr, (tmp = xmlNewNode(NULL, (xmlChar *)"name")));
  if(MYATTR(node, name, anode, value))
    xmlNodeAddContent(tmp, (xmlChar *)value);
  else if(module)
    xmlNodeAddContent(tmp, (xmlChar *)module);
  if(value) free(value);
  if(module) free(module);

  SHOW_ATTR(attr,node,module);
  SHOW_ATTR(attr,node,target);
  SHOW_ATTR(attr,node,resolve_rtype);
  SHOW_ATTR(attr,node,seq);
  SHOW_ATTR(attr,node,period);
  SHOW_ATTR(attr,node,timeout);
  SHOW_ATTR(attr,node,oncheck);
  SHOW_ATTR(attr,node,filterset);
  SHOW_ATTR(attr,node,disable);

  /* Add the config */
  config = xmlNewNode(NULL, (xmlChar *)"config");
  configh = mtev_conf_get_hash(node, "config");
  while(mtev_hash_next(configh, &iter, &k, &klen, &data))
    NODE_CONTENT(config, k, data);
  mtev_hash_destroy(configh, free, free);
  free(configh);

  mod_cnt = noit_check_registered_module_cnt();
  for(mod=0; mod<mod_cnt; mod++) {
    xmlNsPtr ns;
    const char *nsname;
    char buff[256];

    nsname = noit_check_registered_module(mod);
 
    snprintf(buff, sizeof(buff), "noit://module/%s", nsname);
    ns = xmlSearchNs(root->doc, root, (xmlChar *)nsname);
    if(!ns) ns = xmlNewNs(root, (xmlChar *)buff, (xmlChar *)nsname);
    if(ns) {
      configh = mtev_conf_get_namespaced_hash(node, "config", nsname);
      if(configh) {
        memset(&iter, 0, sizeof(iter));
        while(mtev_hash_next(configh, &iter, &k, &klen, &data)) {
          NS_NODE_CONTENT(config, ns, "value", data,
            xmlSetProp(tmp, (xmlChar *)"name", (xmlChar *)k);
          );
        }
        mtev_hash_destroy(configh, free, free);
        free(configh);
      }
    }
  }
Example #10
0
static int
noit_console_show_check(mtev_console_closure_t ncct,
                        int argc, char **argv,
                        mtev_console_state_t *state, void *closure) {
  int i, cnt;
  mtev_conf_t_userdata_t *info;
  char xpath[1024];
  xmlXPathObjectPtr pobj = NULL;
  xmlXPathContextPtr xpath_ctxt = NULL;

  mtev_conf_xml_xpath(NULL, &xpath_ctxt);
  if(argc > 1) {
    nc_printf(ncct, "requires zero or one arguments\n");
    return -1;
  }

  info = mtev_console_userdata_get(ncct, MTEV_CONF_T_USERDATA);
  /* We many not be in conf-t mode -- that's fine */
  if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info,
                                argc ? argv[0] : NULL)) {
    nc_printf(ncct, "could not find check '%s'\n", argv[0]);
    return -1;
  }

  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
  if(!pobj || pobj->type != XPATH_NODESET ||
     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {
    nc_printf(ncct, "no checks found\n");
    goto out;
  }
  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
  if(info && cnt != 1) {
    nc_printf(ncct, "Ambiguous check specified\n");
    goto out;
  }
  for(i=0; i<cnt; i++) {
    mtev_hash_iter iter = MTEV_HASH_ITER_ZERO;
    const char *k;
    int klen;
    void *data;
    uuid_t checkid;
    noit_check_t *check;
    mtev_hash_table *config;
    xmlNodePtr node, anode, mnode = NULL;
    char *uuid_conf;
    char *module, *value;

    node = (mtev_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
    uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
    if(!uuid_conf || uuid_parse(uuid_conf, checkid)) {
      nc_printf(ncct, "%s has invalid or missing UUID!\n",
                (char *)xmlGetNodePath(node) + strlen("/noit"));
      continue;
    }
    nc_printf(ncct, "==== %s ====\n", uuid_conf);
    xmlFree(uuid_conf);

#define MYATTR(a,n,b) _mtev_conf_get_string(node, &(n), "@" #a, &(b))
#define INHERIT(a,n,b) \
  _mtev_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b))
#define SHOW_ATTR(a) do { \
  anode = NULL; \
  value = NULL; \
  INHERIT(a, anode, value); \
  nc_attr_show(ncct, #a, node, anode, value); \
  if(value != NULL) free(value); \
} while(0)

    if(!INHERIT(module, mnode, module)) module = NULL;
    if(MYATTR(name, anode, value)) {
      nc_printf(ncct, " name: %s\n", value);
      free(value);
    }
    else
      nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]");
    nc_attr_show(ncct, "module", node, mnode, module);
    if(module) free(module);
    SHOW_ATTR(target);
    SHOW_ATTR(seq);
    SHOW_ATTR(resolve_rtype);
    SHOW_ATTR(period);
    SHOW_ATTR(timeout);
    SHOW_ATTR(oncheck);
    SHOW_ATTR(filterset);
    SHOW_ATTR(disable);
    /* Print out all the config settings */
    config = mtev_conf_get_hash(node, "config");
    while(mtev_hash_next(config, &iter, &k, &klen, &data)) {
      nc_printf(ncct, " config::%s: %s\n", k, (const char *)data);
    }
    mtev_hash_destroy(config, free, free);
    free(config);

    check = noit_poller_lookup(checkid);
    if(!check) {
      nc_printf(ncct, " ERROR: not in running system\n");
    }
    else {
      int idx = 0;
      stats_t *c;
      struct timeval *whence;
      mtev_hash_table *metrics;
      nc_printf(ncct, " target_ip: %s\n", check->target_ip);
      nc_printf(ncct, " currently: %08x ", check->flags);
      if(NOIT_CHECK_RUNNING(check)) { nc_printf(ncct, "running"); idx++; }
      if(NOIT_CHECK_KILLED(check)) nc_printf(ncct, "%skilled", idx++?",":"");
      if(!NOIT_CHECK_CONFIGURED(check)) nc_printf(ncct, "%sunconfig", idx++?",":"");
      if(NOIT_CHECK_DISABLED(check)) nc_printf(ncct, "%sdisabled", idx++?",":"");
      if(!idx) nc_printf(ncct, "idle");
      nc_write(ncct, "\n", 1);
      if (check->fire_event != NULL) {
        struct timeval now, diff;
        mtev_gettimeofday(&now, NULL);
        sub_timeval(check->fire_event->whence, now, &diff);
        nc_printf(ncct, " next run: %0.3f seconds\n",
                diff.tv_sec + (diff.tv_usec / 1000000.0));
      }
      else {
        nc_printf(ncct, " next run: unscheduled\n");
      }

      c = noit_check_get_stats_current(check);
      whence = noit_check_stats_whence(c, NULL);
      if(whence->tv_sec == 0) {
        nc_printf(ncct, " last run: never\n");
      }
      else {
        const char *status;
        struct timeval now, *then, diff;
        mtev_gettimeofday(&now, NULL);
        then = noit_check_stats_whence(c, NULL);
        sub_timeval(now, *then, &diff);
        nc_printf(ncct, " last run: %0.3f seconds ago\n",
                  diff.tv_sec + (diff.tv_usec / 1000000.0));
        nc_printf(ncct, " availability/state: %s/%s\n",
                  noit_check_available_string(noit_check_stats_available(c, NULL)),
                  noit_check_state_string(noit_check_stats_state(c, NULL)));
        status = noit_check_stats_status(c, NULL);
        nc_printf(ncct, " status: %s\n", status);
        nc_printf(ncct, " feeds: %d\n", check->feeds ? check->feeds->size : 0);
      }

      c = noit_check_get_stats_inprogress(check);
      metrics = noit_check_stats_metrics(c);
      if(mtev_hash_size(metrics) > 0) {
        nc_printf(ncct, " metrics (inprogress):\n");
        nc_print_stat_metrics(ncct, check, c);
      }
      c = noit_check_get_stats_current(check);
      metrics = noit_check_stats_metrics(c);
      if(mtev_hash_size(metrics)) {
        nc_printf(ncct, " metrics (current):\n");
        nc_print_stat_metrics(ncct, check, c);
      }
      c = noit_check_get_stats_previous(check);
      metrics = noit_check_stats_metrics(c);
      if(mtev_hash_size(metrics) > 0) {
        nc_printf(ncct, " metrics (previous):\n");
        nc_print_stat_metrics(ncct, check, c);
      }
    }
  }
 out:
  if(pobj) xmlXPathFreeObject(pobj);
  return 0;
}
Example #11
0
void
noit_poller_process_checks(const char *xpath) {
  int i, flags, cnt = 0;
  noit_conf_section_t *sec;
  __config_load_generation++;
  sec = noit_conf_get_sections(NULL, xpath, &cnt);
  for(i=0; i<cnt; i++) {
    void *vcheck;
    char uuid_str[37];
    char target[256] = "";
    char module[256] = "";
    char name[256] = "";
    char filterset[256] = "";
    char oncheck[1024] = "";
    int no_period = 0;
    int no_oncheck = 0;
    int period = 0, timeout = 0;
    noit_boolean disabled = noit_false, busted = noit_false;
    uuid_t uuid, out_uuid;
    noit_hash_table *options;

#define NEXT(...) noitL(noit_stderr, __VA_ARGS__); continue
#define MYATTR(type,a,...) noit_conf_get_##type(sec[i], "@" #a, __VA_ARGS__)
#define INHERIT(type,a,...) \
  noit_conf_get_##type(sec[i], "ancestor-or-self::node()/@" #a, __VA_ARGS__)

    if(!MYATTR(stringbuf, uuid, uuid_str, sizeof(uuid_str))) {
      noitL(noit_stderr, "check %d has no uuid\n", i+1);
      continue;
    }

    if(uuid_parse(uuid_str, uuid)) {
      noitL(noit_stderr, "check uuid: '%s' is invalid\n", uuid_str);
      continue;
    }

    if(!INHERIT(stringbuf, target, target, sizeof(target))) {
      noitL(noit_stderr, "check uuid: '%s' has no target\n", uuid_str);
      busted = noit_true;
    }
    if(!INHERIT(stringbuf, module, module, sizeof(module))) {
      noitL(noit_stderr, "check uuid: '%s' has no module\n", uuid_str);
      busted = noit_true;
    }

    if(!INHERIT(stringbuf, filterset, filterset, sizeof(filterset)))
      filterset[0] = '\0';

    if(!MYATTR(stringbuf, name, name, sizeof(name)))
      strlcpy(name, module, sizeof(name));

    if(!INHERIT(int, period, &period) || period == 0)
      no_period = 1;

    if(!INHERIT(stringbuf, oncheck, oncheck, sizeof(oncheck)) || !oncheck[0])
      no_oncheck = 1;

    if(no_period && no_oncheck) {
      noitL(noit_stderr, "check uuid: '%s' has neither period nor oncheck\n",
            uuid_str);
      busted = noit_true;
    }
    if(!(no_period || no_oncheck)) {
      noitL(noit_stderr, "check uuid: '%s' has oncheck and period.\n",
            uuid_str);
      busted = noit_true;
    }
    if(!INHERIT(int, timeout, &timeout)) {
      noitL(noit_stderr, "check uuid: '%s' has no timeout\n", uuid_str);
      busted = noit_true;
    }
    if(!no_period && timeout >= period) {
      noitL(noit_stderr, "check uuid: '%s' timeout > period\n", uuid_str);
      timeout = period/2;
    }
    options = noit_conf_get_hash(sec[i], "config");

    INHERIT(boolean, disable, &disabled);
    flags = 0;
    if(busted) flags |= (NP_UNCONFIG|NP_DISABLED);
    else if(disabled) flags |= NP_DISABLED;

    if(noit_hash_retrieve(&polls, (char *)uuid, UUID_SIZE,
                          &vcheck)) {
      noit_check_t *existing_check = (noit_check_t *)vcheck;
      /* Once set, we can never change it. */
      assert(!existing_check->module || !existing_check->module[0] ||
             !strcmp(existing_check->module, module));
      /* Only set it if it is not yet set */
      if(!existing_check->module || !existing_check->module[0]) {
        if(existing_check->module) free(existing_check->module);
        existing_check->module = strdup(module);
      }
      noit_check_update(existing_check, target, name, filterset, options,
                           period, timeout, oncheck[0] ? oncheck : NULL,
                           flags);
      noitL(noit_debug, "reloaded uuid: %s\n", uuid_str);
    }
    else {
      noit_poller_schedule(target, module, name, filterset, options,
                           period, timeout, oncheck[0] ? oncheck : NULL,
                           flags, uuid, out_uuid);
      noitL(noit_debug, "loaded uuid: %s\n", uuid_str);
    }

    noit_hash_destroy(options, free, free);
    free(options);
  }
  if(sec) free(sec);
}
Example #12
0
static int
rest_show_check(noit_http_rest_closure_t *restc,
                int npats, char **pats) {
  noit_http_session_ctx *ctx = restc->http_ctx;
  xmlXPathObjectPtr pobj = NULL;
  xmlXPathContextPtr xpath_ctxt = NULL;
  xmlDocPtr doc = NULL;
  xmlNodePtr node, root, attr, config, state, tmp, anode;
  uuid_t checkid;
  noit_check_t *check;
  char xpath[1024], *uuid_conf, *module, *value;
  int rv, cnt, error_code = 500;
  noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
  const char *k;
  int klen;
  void *data;
  noit_hash_table *configh;

  if(npats != 2) goto error;

  rv = noit_check_xpath(xpath, sizeof(xpath), pats[0], pats[1]);
  if(rv == 0) goto not_found;
  if(rv < 0) goto error;

  noit_conf_xml_xpath(NULL, &xpath_ctxt);
  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
  if(!pobj || pobj->type != XPATH_NODESET ||
     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) goto not_found;
  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
  if(cnt != 1) goto error;

  node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
  uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
  if(!uuid_conf || uuid_parse(uuid_conf, checkid)) goto error;

  doc = xmlNewDoc((xmlChar *)"1.0");
  root = xmlNewDocNode(doc, NULL, (xmlChar *)"check", NULL);
  xmlDocSetRootElement(doc, root);

#define MYATTR(node,a,n,b) _noit_conf_get_string(node, &(n), "@" #a, &(b))
#define INHERIT(node,a,n,b) \
  _noit_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b))
#define SHOW_ATTR(parent, node, a) do { \
  xmlNodePtr anode = NULL; \
  char *value = NULL; \
  INHERIT(node, a, anode, value); \
  if(value != NULL) { \
    int clen, plen;\
    const char *cpath, *apath; \
    xmlNodePtr child; \
    cpath = node ? (char *)xmlGetNodePath(node) : ""; \
    apath = anode ? (char *)xmlGetNodePath(anode) : ""; \
    clen = strlen(cpath); \
    plen = strlen("/noit/checks"); \
    child = xmlNewNode(NULL, (xmlChar *)#a); \
    xmlNodeAddContent(child, (xmlChar *)value); \
    if(!strncmp(cpath, apath, clen) && apath[clen] == '/') { \
    } \
    else { \
      xmlSetProp(child, (xmlChar *)"inherited", (xmlChar *)apath+plen); \
    } \
    xmlAddChild(parent, child); \
  } \
} while(0)

  attr = xmlNewNode(NULL, (xmlChar *)"attributes");
  xmlAddChild(root, attr);

  SHOW_ATTR(attr,node,uuid);

  /* Name is odd, it falls back transparently to module */
  if(!INHERIT(node, module, tmp, module)) module = NULL;
  xmlAddChild(attr, (tmp = xmlNewNode(NULL, (xmlChar *)"name")));
  if(MYATTR(node, name, anode, value))
    xmlNodeAddContent(tmp, (xmlChar *)value);
  else if(module)
    xmlNodeAddContent(tmp, (xmlChar *)module);

  SHOW_ATTR(attr,node,module);
  SHOW_ATTR(attr,node,target);
  SHOW_ATTR(attr,node,period);
  SHOW_ATTR(attr,node,timeout);
  SHOW_ATTR(attr,node,oncheck);
  SHOW_ATTR(attr,node,filterset);
  SHOW_ATTR(attr,node,disable);

  /* Add the config */
  config = xmlNewNode(NULL, (xmlChar *)"config");
  configh = noit_conf_get_hash(node, "config");
  while(noit_hash_next(configh, &iter, &k, &klen, &data))
    NODE_CONTENT(config, k, data);
  noit_hash_destroy(configh, free, free);
  free(configh);
  xmlAddChild(root, config);

  /* Add the state */
  check = noit_poller_lookup(checkid);
  if(!check) {
    state = xmlNewNode(NULL, (xmlChar *)"state");
    xmlSetProp(state, (xmlChar *)"error", (xmlChar *)"true");
  }
  else
    state = noit_check_state_as_xml(check);
  xmlAddChild(root, state);
  noit_http_response_ok(ctx, "text/xml");
  noit_http_response_xml(ctx, doc);
  noit_http_response_end(ctx);
  goto cleanup;

 not_found:
  noit_http_response_not_found(ctx, "text/html");
  noit_http_response_end(ctx);
  goto cleanup;

 error:
  noit_http_response_standard(ctx, error_code, "ERROR", "text/html");
  noit_http_response_end(ctx);
  goto cleanup;

 cleanup:
  if(pobj) xmlXPathFreeObject(pobj);
  if(doc) xmlFreeDoc(doc);
  return 0;
}
Example #13
0
void  self_statement_Update(Update *v2548,OID v1741,OID v332)
{ GC_BIND;
  { OID  v1712 = GC_OID(v2548->var);
    OID  v1736 = GC_OID(v2548->selector);
    ClaireType * v4806;
    { if (INHERIT(OWNER(v1712),Language._Call_slot))
       v4806 = domain_I_restriction(OBJECT(Call_slot,v1712)->selector);
      else if (INHERIT(OWNER(v1712),Language._Call_array))
       v4806 = Kernel._integer;
      else v4806 = U_type(Kernel._any,GC_OBJECT(ClaireType,OBJECT(ClaireType,(*Kernel.domain)(v1736))));
        GC_OBJECT(ClaireType,v4806);} 
    ClaireType * v4807;
    { if (INHERIT(OWNER(v1712),Language._Call_slot))
       { v4807 = ((v2548->arg == _oid_(Kernel.add)) ?
          member_type(OBJECT(Call_slot,v1712)->selector->range) :
          OBJECT(Call_slot,v1712)->selector->range );
        } 
      else if (INHERIT(OWNER(v1712),Language._Call_array))
       { v4807 = (((OBJECT(ClaireBoolean,(*Core._inf_equalt)(GC_OID(OBJECT(Call_array,v1712)->test),
          _oid_(Kernel._float)))) == CTRUE) ?
          Kernel._float :
          Kernel._any );
        } 
      else v4807 = U_type(Kernel._any,GC_OBJECT(ClaireType,((v2548->arg == _oid_(Kernel.add)) ?
          member_type(GC_OBJECT(ClaireType,OBJECT(ClaireType,(*Kernel.range)(v1736)))) :
          OBJECT(ClaireType,(*Kernel.range)(v1736)) )));
        GC_OBJECT(ClaireType,v4807);} 
    ClaireClass * v3625 = stupid_t_any1(GC_OID((*Kernel.arg)(v2548->var)));
    ClaireClass * v3626 = stupid_t_any1(GC_OID(v2548->value));
    OID  v1721;
    { if ((_inf_equalt_class(v3625,psort_any(_oid_(v4806))) != CTRUE) && 
          (_inf_equalt_class(v3625,Kernel._object) == CTRUE))
       { Compile_C_cast * v2072 = ((Compile_C_cast *) GC_OBJECT(Compile_C_cast,new_object_class(Optimize._C_cast)));
        (v2072->arg = (*Kernel.arg)(GC_OID(v2548->var)));
        (v2072->set_arg = psort_any(_oid_(v4806)));
        add_I_property(Kernel.instances,Optimize._C_cast,11,_oid_(v2072));
        v1721 = _oid_(v2072);
        } 
      else v1721 = (*Kernel.arg)(GC_OID(v2548->var));
        GC_OID(v1721);} 
    OID  v4372;
    { if ((_inf_equalt_class(v3626,psort_any(_oid_(v4807))) != CTRUE) && 
          (_inf_equalt_class(v3626,Kernel._object) == CTRUE))
       { Compile_C_cast * v2072 = ((Compile_C_cast *) GC_OBJECT(Compile_C_cast,new_object_class(Optimize._C_cast)));
        (v2072->arg = v2548->value);
        (v2072->set_arg = psort_any(_oid_(v4807)));
        add_I_property(Kernel.instances,Optimize._C_cast,11,_oid_(v2072));
        v4372 = _oid_(v2072);
        } 
      else v4372 = v2548->value;
        GC_OID(v4372);} 
    Variable * v105 = GC_OBJECT(Variable,Variable_I_symbol(gensym_void(),0,v4806));
    Variable * v106 = GC_OBJECT(Variable,Variable_I_symbol(gensym_void(),0,v4807));
    ClaireBoolean * v4279 = c_func_any(v1721);
    new_block_void();
    interface_I_class(psort_any(_oid_(v4806)));
    princ_string(copy_string(" "));
    expression_Variable(v105,_oid_(Kernel.emptySet));
    princ_string(copy_string(" "));
    if (v4279 == CTRUE)
     { princ_string(copy_string("= "));
      (*Generate.expression)(v1721,
        _oid_(Kernel.emptySet));
      princ_string(copy_string(""));
      } 
    princ_string(copy_string("; "));
    breakline_void();
    interface_I_class(psort_any(_oid_(v4807)));
    princ_string(copy_string(" "));
    expression_Variable(v106,_oid_(Kernel.emptySet));
    princ_string(copy_string(";"));
    breakline_void();
    if (v4279 != CTRUE)
     statement_any(v1721,GC_OID((*Generate.c_string)(Generate.PRODUCER->value,
      _oid_(v105))),v332);
    statement_any(v4372,GC_OID((*Generate.c_string)(Generate.PRODUCER->value,
      _oid_(v106))),v332);
    if (Kernel._string == OWNER(v1741))
     { c_princ_string(string_v(v1741));
      princ_string(copy_string(" = "));
      } 
    { Update * v2367;
      { Update * v2072 = ((Update *) GC_OBJECT(Update,new_object_class(Language._Update)));
        (v2072->selector = v1736);
        { Update * v6754 = v2072; 
          OID  v6755;
          if (v2548->arg == _oid_(Kernel.add))
           v6755 = _oid_(Kernel.add);
          else if (sort_Variable(v105) == Kernel._any)
           v6755 = _oid_(v105);
          else { Compile_to_CL * v2072 = ((Compile_to_CL *) GC_OBJECT(Compile_to_CL,new_object_class(Optimize._to_CL)));
              (v2072->arg = _oid_(v105));
              (v2072->set_arg = sort_Variable(v105));
              add_I_property(Kernel.instances,Optimize._to_CL,11,_oid_(v2072));
              v6755 = _oid_(v2072);
              } 
            (v6754->arg = v6755);} 
        (v2072->value = _oid_(v106));
        { Update * v6758 = v2072; 
          OID  v6759;
          { OID  v5032 = GC_OID((*Kernel.copy)(v1712));
            put_property2(Kernel.arg,OBJECT(ClaireObject,v5032),_oid_(v105));
            v6759 = v5032;
            } 
          (v6758->var = v6759);} 
        add_I_property(Kernel.instances,Language._Update,11,_oid_(v2072));
        v2367 = v2072;
        } 
      expression_Update(v2367,v332);
      } 
    princ_string(copy_string(";"));
    close_block_void();
    } 
  GC_UNBIND;} 
Example #14
0
void  statement_any(OID v2548,OID v1741,OID v332)
{ GC_BIND;
  { ClaireBoolean * v1722 = Optimize.OPT->alloc_stack;
    if ((((INHERIT(OWNER(v2548),Language._Tuple)) || 
        (INHERIT(OWNER(v2548),Language._Do))) ? CTRUE : ((INHERIT(OWNER(v2548),Language._Let)) ? CTRUE : CFALSE)) != CTRUE)
     (Optimize.OPT->alloc_stack = CFALSE);
    if (c_func_any(v2548) == CTRUE)
     { { ClaireBoolean * g0032I;
        { ClaireBoolean *v_and;
          { v_and = ((Kernel._string == OWNER(v1741)) ? CTRUE : CFALSE);
            if (v_and == CFALSE) g0032I =CFALSE; 
            else { { OID  v6399;
                { OID  v7360;
                  { if (INHERIT(OWNER(v2548),Optimize._to_CL))
                     v7360 = OBJECT(Compile_to_CL,v2548)->arg;
                    else v7360 = v2548;
                      GC_OID(v7360);} 
                  v6399 = (*Optimize.c_sort)(v7360);
                  } 
                v_and = ((v6399 != _oid_(Kernel._void)) ? CTRUE : CFALSE);
                } 
              if (v_and == CFALSE) g0032I =CFALSE; 
              else g0032I = CTRUE;} 
            } 
          } 
        
        if (g0032I == CTRUE) { (*Kernel.c_princ)(v1741);
            princ_string(copy_string(" = "));
            if (bool_exp_ask_any(v2548) == CTRUE)
             (*Generate.bool_exp_I)(Generate.PRODUCER->value,
              v2548,
              v332);
            else (*Generate.expression)(v2548,
                v332);
              princ_string(copy_string(";"));
            breakline_void();
            princ_string(copy_string(""));
            } 
          else if (INHERIT(OWNER(v2548),Language._If))
         (*Generate.self_statement)(v2548,
          v1741,
          v332);
        else if (INHERIT(OWNER(v2548),Reader._delimiter))
         close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("[201] Loose delimiter in program: ~S")),
          _oid_(list::alloc(1,v2548)))));
        else (*Generate.stat_exp)(Generate.PRODUCER->value,
            v2548,
            v332);
          } 
      } 
    else if ((INHERIT(OWNER(v2548),Language._Call_method)) && 
        (((*Kernel.arg)(v2548) == Generate._starclose_exception_star->value) && 
          (c_func_any(GC_OID((*(OBJECT(bag,(*Core.args)(v2548))))[1])) == CTRUE)))
     { (*Generate.expression)(v2548,
        v332);
      princ_string(copy_string(";"));
      breakline_void();
      princ_string(copy_string(""));
      } 
    else (*Generate.self_statement)(v2548,
        v1741,
        v332);
      (Optimize.OPT->alloc_stack = v1722);
    } 
  GC_UNBIND;}