X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fnginx.c;h=88118b9b7044e3ad5d008b914596731b5e9b1599;hp=ffc545c42770846d084220f6da86dff0812bcdbf;hb=7111bb6df7628edce3a8e538b386fbe27633a191;hpb=ffaf9b893b6042a76e1c0dadd83ce06904fcc89a diff --git a/src/nginx.c b/src/nginx.c index ffc545c4..88118b9b 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -62,13 +62,13 @@ static size_t nginx_curl_callback(void *buf, size_t size, size_t nmemb, } if (len == 0) - return (len); + return len; memcpy(&nginx_buffer[nginx_buffer_len], buf, len); nginx_buffer_len += len; nginx_buffer[nginx_buffer_len] = 0; - return (len); + return len; } static int config_set(char **var, const char *value) { @@ -78,28 +78,28 @@ static int config_set(char **var, const char *value) { } if ((*var = strdup(value)) == NULL) - return (1); + return 1; else - return (0); + return 0; } static int config(const char *key, const char *value) { if (strcasecmp(key, "url") == 0) - return (config_set(&url, value)); + return config_set(&url, value); else if (strcasecmp(key, "user") == 0) - return (config_set(&user, value)); + return config_set(&user, value); else if (strcasecmp(key, "password") == 0) - return (config_set(&pass, value)); + return config_set(&pass, value); else if (strcasecmp(key, "verifypeer") == 0) - return (config_set(&verify_peer, value)); + return config_set(&verify_peer, value); else if (strcasecmp(key, "verifyhost") == 0) - return (config_set(&verify_host, value)); + return config_set(&verify_host, value); else if (strcasecmp(key, "cacert") == 0) - return (config_set(&cacert, value)); + return config_set(&cacert, value); else if (strcasecmp(key, "timeout") == 0) - return (config_set(&timeout, value)); + return config_set(&timeout, value); else - return (-1); + return -1; } /* int config */ static int init(void) { @@ -108,7 +108,7 @@ static int init(void) { if ((curl = curl_easy_init()) == NULL) { ERROR("nginx plugin: curl_easy_init failed."); - return (-1); + return -1; } curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L); @@ -122,21 +122,17 @@ static int init(void) { curl_easy_setopt(curl, CURLOPT_PASSWORD, (pass == NULL) ? "" : pass); #else static char credentials[1024]; - int status = ssnprintf(credentials, sizeof(credentials), "%s:%s", user, - pass == NULL ? "" : pass); + int status = snprintf(credentials, sizeof(credentials), "%s:%s", user, + pass == NULL ? "" : pass); if ((status < 0) || ((size_t)status >= sizeof(credentials))) { ERROR("nginx plugin: Credentials would have been truncated."); - return (-1); + return -1; } curl_easy_setopt(curl, CURLOPT_USERPWD, credentials); #endif } - if (url != NULL) { - curl_easy_setopt(curl, CURLOPT_URL, url); - } - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L); @@ -165,7 +161,7 @@ static int init(void) { } #endif - return (0); + return 0; } /* void init */ static void submit(const char *type, const char *inst, long long value) { @@ -202,14 +198,17 @@ static int nginx_read(void) { int fields_num; if (curl == NULL) - return (-1); + return -1; if (url == NULL) - return (-1); + return -1; nginx_buffer_len = 0; + + curl_easy_setopt(curl, CURLOPT_URL, url); + if (curl_easy_perform(curl) != CURLE_OK) { WARNING("nginx plugin: curl_easy_perform failed: %s", nginx_curl_error); - return (-1); + return -1; } ptr = nginx_buffer; @@ -259,7 +258,7 @@ static int nginx_read(void) { nginx_buffer_len = 0; - return (0); + return 0; } /* int nginx_read */ void module_register(void) { @@ -267,7 +266,3 @@ void module_register(void) { plugin_register_init("nginx", init); plugin_register_read("nginx", nginx_read); } /* void module_register */ - -/* - * vim: set shiftwidth=2 softtabstop=2 tabstop=8 : - */