| | 122 | |
|---|
| | 123 | /* Hack the output into metrics */ |
|---|
| | 124 | if(ci->output && ci->matcher) { |
|---|
| | 125 | int rc, len, startoffset = 0; |
|---|
| | 126 | int ovector[30]; |
|---|
| | 127 | len = strlen(ci->output); |
|---|
| | 128 | noitL(data->nldeb, "going to match output at %d/%d\n", startoffset, len); |
|---|
| | 129 | while((rc = pcre_exec(ci->matcher, NULL, ci->output, len, startoffset, 0, |
|---|
| | 130 | ovector, sizeof(ovector)/sizeof(*ovector))) > 0) { |
|---|
| | 131 | char metric[128]; |
|---|
| | 132 | char value[128]; |
|---|
| | 133 | startoffset = ovector[1]; |
|---|
| | 134 | noitL(data->nldeb, "matched at offset %d\n", rc); |
|---|
| | 135 | if(pcre_copy_named_substring(ci->matcher, ci->output, ovector, rc, |
|---|
| | 136 | "key", metric, sizeof(metric)) > 0 && |
|---|
| | 137 | pcre_copy_named_substring(ci->matcher, ci->output, ovector, rc, |
|---|
| | 138 | "value", value, sizeof(value)) > 0) { |
|---|
| | 139 | /* We're able to extract something... */ |
|---|
| | 140 | noit_stats_set_metric(¤t, metric, METRIC_GUESS, value); |
|---|
| | 141 | } |
|---|
| | 142 | noitL(data->nldeb, "going to match output at %d/%d\n", startoffset, len); |
|---|
| | 143 | } |
|---|
| | 144 | noitL(data->nldeb, "match failed.... %d\n", rc); |
|---|
| | 145 | } |
|---|
| | 146 | |
|---|
| | 452 | /* We might want to extract metrics */ |
|---|
| | 453 | if(noit_hash_retrieve(check->config, |
|---|
| | 454 | "output_extract", strlen("output_extract"), |
|---|
| | 455 | (void **)&value) != 0) { |
|---|
| | 456 | const char *error; |
|---|
| | 457 | int erroffset; |
|---|
| | 458 | ci->matcher = pcre_compile(value, 0, &error, &erroffset, NULL); |
|---|
| | 459 | if(!ci->matcher) { |
|---|
| | 460 | noitL(data->nlerr, "external pcre /%s/ failed @ %d: %s\n", |
|---|
| | 461 | value, erroffset, error); |
|---|
| | 462 | } |
|---|
| | 463 | } |
|---|
| | 464 | |
|---|