コード例 #1
0
ファイル: httptrap.c プロジェクト: edwardt/reconnoiter
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;
}
コード例 #2
0
ファイル: httptrap.c プロジェクト: maier/reconnoiter
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;
}
コード例 #3
0
ファイル: httptrap.c プロジェクト: maier/reconnoiter
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
ファイル: httptrap.c プロジェクト: maier/reconnoiter
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;
}
コード例 #5
0
ファイル: httptrap.c プロジェクト: edwardt/reconnoiter
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;
}
コード例 #6
0
ファイル: httptrap.c プロジェクト: edwardt/reconnoiter
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;
}
コード例 #7
0
ファイル: httptrap.c プロジェクト: edwardt/reconnoiter
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;
}