Merge branch 'collectd-5.3' into collectd-5.4
authorFlorian Forster <octo@collectd.org>
Sat, 6 Sep 2014 09:27:56 +0000 (11:27 +0200)
committerFlorian Forster <octo@collectd.org>
Sat, 6 Sep 2014 09:27:56 +0000 (11:27 +0200)
Conflicts:
src/curl.c

1  2 
src/curl.c

diff --combined src/curl.c
@@@ -26,7 -26,6 +26,7 @@@
  #include "plugin.h"
  #include "configfile.h"
  #include "utils_match.h"
 +#include "utils_time.h"
  
  #include <curl/curl.h>
  
@@@ -64,7 -63,6 +64,7 @@@ struct web_page_s /* {{{ *
    struct curl_slist *headers;
    char *post_body;
    _Bool response_time;
 +  _Bool response_code;
  
    CURL *curl;
    char curl_errbuf[CURL_ERROR_SIZE];
@@@ -91,7 -89,7 +91,7 @@@ static size_t cc_curl_callback (void *b
  {
    web_page_t *wp;
    size_t len;
 -  
 +
    len = size * nmemb;
    if (len <= 0)
      return (len);
@@@ -429,7 -427,6 +429,7 @@@ static int cc_config_add_page (oconfig_
    page->verify_peer = 1;
    page->verify_host = 1;
    page->response_time = 0;
 +  page->response_code = 0;
  
    page->instance = strdup (ci->values[0].value.string);
    if (page->instance == NULL)
        status = cf_util_get_boolean (child, &page->verify_host);
      else if (strcasecmp ("MeasureResponseTime", child->key) == 0)
        status = cf_util_get_boolean (child, &page->response_time);
 +    else if (strcasecmp ("MeasureResponseCode", child->key) == 0)
 +      status = cf_util_get_boolean (child, &page->response_code);
      else if (strcasecmp ("CACert", child->key) == 0)
        status = cf_util_get_string (child, &page->cacert);
      else if (strcasecmp ("Match", child->key) == 0)
        status = -1;
      }
  
 -    if (page->matches == NULL && !page->response_time)
 +    if (page->matches == NULL && !page->response_time && !page->response_code)
      {
        assert (page->instance != NULL);
        WARNING ("curl plugin: No (valid) `Match' block "
 -          "or MeasureResponseTime within `Page' block `%s'.", page->instance);
 +          "or MeasureResponseTime or MeasureResponseCode within "
 +          "`Page' block `%s'.", page->instance);
        status = -1;
      }
  
@@@ -593,30 -587,12 +593,30 @@@ static void cc_submit (const web_page_
    plugin_dispatch_values (&vl);
  } /* }}} void cc_submit */
  
 -static void cc_submit_response_time (const web_page_t *wp, double seconds) /* {{{ */
 +static void cc_submit_response_code (const web_page_t *wp, long code) /* {{{ */
  {
    value_t values[1];
    value_list_t vl = VALUE_LIST_INIT;
  
 -  values[0].gauge = seconds;
 +  values[0].gauge = code;
 +
 +  vl.values = values;
 +  vl.values_len = 1;
 +  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
 +  sstrncpy (vl.plugin, "curl", sizeof (vl.plugin));
 +  sstrncpy (vl.plugin_instance, wp->instance, sizeof (vl.plugin_instance));
 +  sstrncpy (vl.type, "response_code", sizeof (vl.type));
 +
 +  plugin_dispatch_values (&vl);
 +} /* }}} void cc_submit_response_code */
 +
 +static void cc_submit_response_time (const web_page_t *wp, /* {{{ */
 +    cdtime_t response_time)
 +{
 +  value_t values[1];
 +  value_list_t vl = VALUE_LIST_INIT;
 +
 +  values[0].gauge = CDTIME_T_TO_DOUBLE (response_time);
  
    vl.values = values;
    vl.values_len = 1;
@@@ -632,10 -608,10 +632,10 @@@ static int cc_read_page (web_page_t *wp
  {
    web_match_t *wm;
    int status;
 -  struct timeval start, end;
 +  cdtime_t start = 0;
  
    if (wp->response_time)
 -    gettimeofday (&start, NULL);
 +    start = cdtime ();
  
    wp->buffer_fill = 0;
    status = curl_easy_perform (wp->curl);
    }
  
    if (wp->response_time)
 +    cc_submit_response_time (wp, cdtime() - start);
 +
 +  if(wp->response_code)
    {
 -    double secs = 0;
 -    gettimeofday (&end, NULL);
 -    secs += end.tv_sec - start.tv_sec;
 -    secs += (end.tv_usec - start.tv_usec) / 1000000.0;
 -    cc_submit_response_time (wp, secs);
 +    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 staus %i: %s",
 +        status, wp->curl_errbuf);
 +    } else {
 +      cc_submit_response_code(wp, response_code);
 +    }
    }
  
    for (wm = wp->matches; wm != NULL; wm = wm->next)
      }
  
      cc_submit (wp, wm, mv);
+     match_value_reset (mv);
    } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */
  
    return (0);