struct curl_slist *headers;
char *post_body;
int response_time;
+ int response_code;
CURL *curl;
char curl_errbuf[CURL_ERROR_SIZE];
{
web_page_t *wp;
size_t len;
-
+
len = size * nmemb;
if (len <= 0)
return (len);
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 = cc_config_set_boolean ("VerifyHost", &page->verify_host, child);
else if (strcasecmp ("MeasureResponseTime", child->key) == 0)
status = cc_config_set_boolean (child->key, &page->response_time, child);
+ else if (strcasecmp ("MeasureResponseCode", child->key) == 0)
+ status = cc_config_set_boolean (child->key, &page->response_code, child);
else if (strcasecmp ("CACert", child->key) == 0)
status = cc_config_add_string ("CACert", &page->cacert, child);
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;
}
plugin_dispatch_values (&vl);
} /* }}} void cc_submit */
+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 = 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, double seconds) /* {{{ */
{
value_t values[1];
return (-1);
}
+ if(wp->response_code)
+ {
+ long *response_code;
+ status = curl_easy_getinfo(wp->curl, CURLINFO_RESPONSE_CODE, &response_code);
+ if(status != CURLE_OK) {
+ ERROR ("curl plugin: curl_easy_getinfo failed with staus %i: %s",
+ status, wp->curl_errbuf);
+ return (-1); // TODO: do we need to return in here? this is nonfatal error
+ }
+ cc_submit_response_code(wp, response_code);
+ }
+
if (wp->response_time)
{
double secs = 0;