summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e7bac61)
raw | patch | inline | side by side (parent: e7bac61)
author | Jan (yac) Matějka <JMatejka@suse.cz> | |
Mon, 13 May 2013 13:55:59 +0000 (15:55 +0200) | ||
committer | Jan (yac) Matějka <JMatejka@suse.cz> | |
Mon, 13 May 2013 15:55:59 +0000 (17:55 +0200) |
src/curl.c | patch | blob | history | |
src/types.db | patch | blob | history |
diff --git a/src/curl.c b/src/curl.c
index c6e2ae9c1f521350db159dc2922dafcb6fb54f41..3e5c578e4ef5b0de858f0d43d9ae6d9d8c91d06f 100644 (file)
--- a/src/curl.c
+++ b/src/curl.c
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;
diff --git a/src/types.db b/src/types.db
index 3358f5df59e82c4b1b3a55b7c74239159f804edf..fa24e6e2c002e96d71f950aeb8e820c345bccd94 100644 (file)
--- a/src/types.db
+++ b/src/types.db
records value:GAUGE:0:U
requests value:GAUGE:0:U
response_time value:GAUGE:0:U
+response_code value:GAUGE:0:U
route_etx value:GAUGE:0:U
route_metric value:GAUGE:0:U
routes value:GAUGE:0:U