Пример #1
0
static int
json_check_accum(noit_check_t *check, void *closure) {
  struct json_object *cobj, *doc = closure;
  char id_str[UUID_STR_LEN+1];
  uuid_unparse_lower(check->checkid, id_str);
  cobj = noit_check_state_as_json(check, 0);
  json_object_object_del(cobj, "id");
  json_object_object_add(doc, id_str, cobj);
  return 1;
}
Пример #2
0
static void
rest_test_check_result(struct check_test_closure *cl) {
  mtev_http_session_ctx *ctx = cl->restc->http_ctx;

  mtevL(nlerr, "Flushing check test result\n");

  if(cl->restc->call_closure_free)
    cl->restc->call_closure_free(cl->restc->call_closure);
  cl->restc->call_closure_free = NULL;
  cl->restc->call_closure = NULL;
  cl->restc->fastpath = NULL;

  if(ctx) {
    eventer_t conne;

    if(cl->output == WANTS_JSON) {
      struct json_object *doc;
      const char *jsonstr;

      doc = noit_check_state_as_json(cl->check, 1);
      mtev_http_response_ok(ctx, "application/json");
      jsonstr = json_object_to_json_string(doc);
      mtev_http_response_append(ctx, jsonstr, strlen(jsonstr));
      mtev_http_response_append(ctx, "\n", 1);
      json_object_put(doc);
    } else {
      xmlDocPtr doc = NULL;
      xmlNodePtr root, state;
  
      doc = xmlNewDoc((xmlChar *)"1.0");
      root = xmlNewDocNode(doc, NULL, (xmlChar *)"check", NULL);
      xmlDocSetRootElement(doc, root);
      state = noit_check_state_as_xml(cl->check, 1);
      xmlAddChild(root, state);
      mtev_http_response_ok(ctx, "text/xml");
      mtev_http_response_xml(ctx, doc);
      xmlFreeDoc(doc);
    }
    mtev_http_response_end(ctx);
  
    conne = mtev_http_connection_event(mtev_http_session_connection(ctx));
    if(conne) {
      // The event already exists, why re-add it?  Did we want to update it?
      //eventer_add(conne);
      eventer_trigger(conne, EVENTER_READ | EVENTER_WRITE);
    }
  }

  noit_poller_free_check(cl->check);
  free(cl);
}
Пример #3
0
static int
rest_show_check_json(mtev_http_rest_closure_t *restc,
                     uuid_t checkid) {
  noit_check_t *check;
  struct json_object *doc;
  const char *jsonstr;
  check = noit_poller_lookup(checkid);
  if(!check) {
    mtev_http_response_not_found(restc->http_ctx, "application/json");
    mtev_http_response_end(restc->http_ctx);
    return 0;
  }

  doc = noit_check_state_as_json(check, 1);
  
  mtev_http_response_ok(restc->http_ctx, "application/json");
  jsonstr = json_object_to_json_string(doc);
  mtev_http_response_append(restc->http_ctx, jsonstr, strlen(jsonstr));
  mtev_http_response_append(restc->http_ctx, "\n", 1);
  json_object_put(doc);
  mtev_http_response_end(restc->http_ctx);
  return 0;
}