Пример #1
0
static int
httptrap_yajl_cb_boolean(void *ctx, int boolVal) {
  int ival, rv;
  struct rest_json_payload *json = ctx;
  if(json->depth<0) {
    _YD("[%3d] cb_boolean [BAD]\n", json->depth);
    return 0;
  }
  rv = set_array_key(json);
  if(json->last_special_key == HT_EX_VALUE) {
    NEW_LV(json, strdup(boolVal ? "1" : "0"));
    _YD("[%3d]*cb_boolean -> %s\n", json->depth, boolVal ? "true" : "false");
    return 1;
  }
  if(json->last_special_key) return 0;
  if(rv) return 1;
  if(json->keys[json->depth]) {
    ival = boolVal ? 1 : 0;
    _YD("[%3d] cb_boolean -> %s\n", json->depth, boolVal ? "true" : "false");
    noit_stats_set_metric(json->check,
        json->keys[json->depth], METRIC_INT32, &ival);
    if(json->immediate)
      noit_stats_log_immediate_metric(json->check,
          json->keys[json->depth], METRIC_INT32, &ival);
    json->cnt++;
  }
  return 1;
}
Пример #2
0
static int
httptrap_yajl_cb_number(void *ctx, const char * numberVal,
                        size_t numberLen) {
  char val[128];
  struct rest_json_payload *json = ctx;
  int rv;
  if(json->depth<0) return 0;
  rv = set_array_key(json);
  if(json->last_special_key == 0x2) {
    char *str;
    str = malloc(numberLen+1);
    memcpy(str, numberVal, numberLen);
    str[numberLen] = '\0';
    NEW_LV(json, str);
    return 1;
  }
  if(rv) return 1;
  if(json->last_special_key) return 0;
  if(json->keys[json->depth]) {
    if(numberLen > sizeof(val)-1) numberLen = sizeof(val)-1;
    memcpy(val, numberVal, numberLen);
    val[numberLen] = '\0';
    noit_stats_set_metric(json->check,
        json->keys[json->depth], METRIC_GUESS, val);
    if(json->immediate)
      noit_stats_log_immediate_metric(json->check,
          json->keys[json->depth], METRIC_GUESS, val);
    json->cnt++;
  }
  return 1;
}
Пример #3
0
static int
httptrap_yajl_cb_null(void *ctx) {
  struct rest_json_payload *json = ctx;
  int rv;
  if(json->depth<0) {
    _YD("[%3d] cb_null [BAD]\n", json->depth);
    return 0;
  }
  rv = set_array_key(json);
  if(json->last_special_key == HT_EX_VALUE) {
    _YD("[%3d]*cb_null\n", json->depth);
    NEW_LV(json, NULL);
    return 1;
  }
  if(json->last_special_key) return 0;
  if(rv) return 1;
  if(json->keys[json->depth]) {
    _YD("[%3d] cb_null\n", json->depth);
    noit_stats_set_metric(json->check,
        json->keys[json->depth], METRIC_INT32, NULL);
    if(json->immediate)
      noit_stats_log_immediate_metric(json->check,
          json->keys[json->depth], METRIC_INT32, NULL);
    json->cnt++;
  }
  return 1;
}
Пример #4
0
static int
httptrap_yajl_cb_end_map(void *ctx) {
  struct value_list *p, *last_p = NULL;
  struct rest_json_payload *json = ctx;
  _YD("[%3d]%-.*s cb_end_map\n", json->depth, json->depth, "");
  json->depth--;
  if(json->saw_complex_type == 0x3) {
    long double total = 0, cnt = 0;
    mtev_boolean use_avg = mtev_false;
    for(p=json->last_value;p;p=p->next) {
      noit_stats_set_metric_coerce(json->check,
          json->keys[json->depth], json->last_type, p->v);
      last_p = p;
      if(p->v != NULL &&
         (json->last_type == 'L' || json->last_type == 'l' ||
          json->last_type == 'I' || json->last_type == 'i' ||
          json->last_type == 'n')) {
        total += strtold(p->v, NULL);
        cnt = cnt + 1;
        use_avg = mtev_true;
      }
      json->cnt++;
    }
    if(json->immediate && last_p != NULL) {
      if(use_avg) {
        double avg = total / cnt;
        noit_stats_log_immediate_metric(json->check,
            json->keys[json->depth], 'n', &avg);
      }
      else {
        noit_stats_log_immediate_metric(json->check,
            json->keys[json->depth], json->last_type, last_p->v);
      }
    }
  }
  json->saw_complex_type = 0;
  for(p=json->last_value;p;) {
    struct value_list *savenext;
    savenext = p->next;
    if(p->v) free(p->v);
    savenext = p->next;
    free(p);
    p = savenext;
  }
  json->last_value = NULL;
  return 1;
}
Пример #5
0
static int
httptrap_yajl_cb_string(void *ctx, const unsigned char * stringVal,
                        size_t stringLen) {
  struct rest_json_payload *json = ctx;
  char val[4096];
  int rv;
  if(json->depth<0) {
    _YD("[%3d] cb_string [BAD]\n", json->depth);
    return 0;
  }
  if(json->last_special_key == HT_EX_TS) /* handle ts */
    return 1;
  if(json->last_special_key == HT_EX_TAGS) /* handle tag */
    return 1;
  rv = set_array_key(json);
  if(json->last_special_key == HT_EX_TYPE) {
    if(stringLen != 1) return 0;
    if(*stringVal == 'L' || *stringVal == 'l' ||
        *stringVal == 'I' || *stringVal == 'i' ||
        *stringVal == 'n' || *stringVal == 's') {
      json->last_type = *stringVal;
      json->saw_complex_type |= HT_EX_TYPE;
      _YD("[%3d] cb_string { _type: %c }\n", json->depth, *stringVal);
      return 1;
    }
    _YD("[%3d] cb_string { bad _type: %.*s }\n", json->depth,
        (int)stringLen, stringVal);
    return 0;
  }
  else if(json->last_special_key == HT_EX_VALUE) {
    char *str;
    str = malloc(stringLen+1);
    memcpy(str, stringVal, stringLen);
    str[stringLen] = '\0';
    NEW_LV(json, str);
    _YD("[%3d] cb_string { _value: %s }\n", json->depth, str);
    json->saw_complex_type |= HT_EX_VALUE;
    return 1;
  }
  else if(json->last_special_key == HT_EX_TS) return 1;
  else if(json->last_special_key == HT_EX_TAGS) return 1;
  if(rv) return 1;
  if(json->keys[json->depth]) {
    if(stringLen > sizeof(val)-1) stringLen = sizeof(val)-1;
    memcpy(val, stringVal, stringLen);
    val[stringLen] = '\0';
    _YD("[%3d] cb_string %s\n", json->depth, val);
    noit_stats_set_metric(json->check,
        json->keys[json->depth], METRIC_GUESS, val);
    if(json->immediate)
      noit_stats_log_immediate_metric(json->check,
          json->keys[json->depth], METRIC_GUESS, val);
    json->cnt++;
  }
  return 1;
}
Пример #6
0
static int
httptrap_yajl_cb_string(void *ctx, const unsigned char * stringVal,
                        size_t stringLen) {
  struct rest_json_payload *json = ctx;
  char val[4096];
  int rv;
  if(json->depth<0) return 0;
  rv = set_array_key(json);
  if(json->last_special_key == 0x1) {
    if(stringLen != 1) return 0;
    if(*stringVal == 'L' || *stringVal == 'l' ||
        *stringVal == 'I' || *stringVal == 'i' ||
        *stringVal == 'n' || *stringVal == 's') {
      json->last_type = *stringVal;
      json->saw_complex_type |= 0x1;
      return 1;
    }
    return 0;
  }
  else if(json->last_special_key == 0x2) {
    char *str;
    str = malloc(stringLen+1);
    memcpy(str, stringVal, stringLen);
    str[stringLen] = '\0';
    NEW_LV(json, str);
    json->saw_complex_type |= 0x2;
    return 1;
  }
  if(rv) return 1;
  if(json->keys[json->depth]) {
    if(stringLen > sizeof(val)-1) stringLen = sizeof(val)-1;
    memcpy(val, stringVal, stringLen);
    val[stringLen] = '\0';
    noit_stats_set_metric(json->check,
        json->keys[json->depth], METRIC_GUESS, val);
    if(json->immediate)
      noit_stats_log_immediate_metric(json->check,
          json->keys[json->depth], METRIC_GUESS, val);
    json->cnt++;
  }
  return 1;
}
Пример #7
0
static int
httptrap_yajl_cb_null(void *ctx) {
  struct rest_json_payload *json = ctx;
  int rv;
  if(json->depth<0) return 0;
  rv = set_array_key(json);
  if(json->last_special_key == 0x2) {
    NEW_LV(json, NULL);
    return 1;
  }
  if(json->last_special_key) return 0;
  if(rv) return 1;
  if(json->keys[json->depth]) {
    noit_stats_set_metric(json->check,
        json->keys[json->depth], METRIC_INT32, NULL);
    if(json->immediate)
      noit_stats_log_immediate_metric(json->check,
          json->keys[json->depth], METRIC_INT32, NULL);
    json->cnt++;
  }
  return 1;
}
Пример #8
0
static int
httptrap_yajl_cb_boolean(void *ctx, int boolVal) {
  int ival, rv;
  struct rest_json_payload *json = ctx;
  mtevL(mtev_error, "BOOL\n");
  if(json->depth<0) return 0;
  rv = set_array_key(json);
  if(json->last_special_key == 0x2) {
    NEW_LV(json, strdup(boolVal ? "1" : "0"));
    return 1;
  }
  if(json->last_special_key) return 0;
  if(rv) return 1;
  if(json->keys[json->depth]) {
    ival = boolVal ? 1 : 0;
    noit_stats_set_metric(json->check,
        json->keys[json->depth], METRIC_INT32, &ival);
    if(json->immediate)
      noit_stats_log_immediate_metric(json->check,
          json->keys[json->depth], METRIC_INT32, &ival);
    json->cnt++;
  }
  return 1;
}