/* * Private functions */ static int simple_submit_match(cu_match_t *match, void *user_data) { cu_tail_match_simple_t *data = (cu_tail_match_simple_t *)user_data; cu_match_value_t *match_value; value_list_t vl = VALUE_LIST_INIT; value_t values[1]; match_value = (cu_match_value_t *)match_get_user_data(match); if (match_value == NULL) return (-1); if ((match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) && (match_value->values_num == 0)) values[0].gauge = NAN; else values[0] = match_value->value; vl.values = values; vl.values_len = 1; sstrncpy(vl.plugin, data->plugin, sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, data->plugin_instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, data->type, sizeof(vl.type)); sstrncpy(vl.type_instance, data->type_instance, sizeof(vl.type_instance)); vl.interval = data->interval; plugin_dispatch_values(&vl); match_value_reset(match_value); return (0); } /* int simple_submit_match */
static int cc_read_page (web_page_t *wp) /* {{{ */ { int status; cdtime_t start = 0; if (wp->response_time) start = cdtime (); wp->buffer_fill = 0; status = curl_easy_perform (wp->curl); if (status != CURLE_OK) { ERROR ("curl plugin: curl_easy_perform failed with status %i: %s", status, wp->curl_errbuf); return (-1); } if (wp->response_time) cc_submit_response_time (wp, cdtime() - start); if (wp->stats != NULL) curl_stats_dispatch (wp->stats, wp->curl, hostname_g, "curl", wp->instance); if(wp->response_code) { long response_code = 0; status = curl_easy_getinfo(wp->curl, CURLINFO_RESPONSE_CODE, &response_code); if(status != CURLE_OK) { ERROR ("curl plugin: Fetching response code failed with status %i: %s", status, wp->curl_errbuf); } else { cc_submit_response_code(wp, response_code); } } for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next) { cu_match_value_t *mv; status = match_apply (wm->match, wp->buffer); if (status != 0) { WARNING ("curl plugin: match_apply failed."); continue; } mv = match_get_user_data (wm->match); if (mv == NULL) { WARNING ("curl plugin: match_get_user_data returned NULL."); continue; } cc_submit (wp, wm, mv); match_value_reset (mv); } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */ return (0); } /* }}} int cc_read_page */
static int cmc_read_page (web_page_t *wp) /* {{{ */ { web_match_t *wm; memcached_return rc; size_t string_length; uint32_t flags; int status; if (wp->memc == NULL) return (-1); wp->buffer = memcached_get (wp->memc, wp->key, strlen (wp->key), &string_length, &flags, &rc); if (rc != MEMCACHED_SUCCESS) { ERROR ("memcachec plugin: memcached_get failed: %s", memcached_strerror (wp->memc, rc)); return (-1); } for (wm = wp->matches; wm != NULL; wm = wm->next) { cu_match_value_t *mv; status = match_apply (wm->match, wp->buffer); if (status != 0) { WARNING ("memcachec plugin: match_apply failed."); continue; } mv = match_get_user_data (wm->match); if (mv == NULL) { WARNING ("memcachec plugin: match_get_user_data returned NULL."); continue; } cmc_submit (wp, wm, mv); match_value_reset (mv); } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */ sfree (wp->buffer); return (0); } /* }}} int cmc_read_page */