X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnginx.c;h=8cb762859b9a1f2bdafb521250c1d0b3fff0c664;hb=bc7992ed0693313a2b1fe282a5bf23f1cc9f8e42;hp=a44e8a5778bb9de85802c599a91574745048458e;hpb=4a5e97d6e317ee050b0a942e50159473a7d144dc;p=collectd.git diff --git a/src/nginx.c b/src/nginx.c index a44e8a57..8cb76285 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -27,10 +27,12 @@ #include -static char *url = NULL; -static char *user = NULL; -static char *pass = NULL; -static char *cacert = NULL; +static char *url = NULL; +static char *user = NULL; +static char *pass = NULL; +static char *verify_peer = NULL; +static char *verify_host = NULL; +static char *cacert = NULL; static CURL *curl = NULL; @@ -44,6 +46,8 @@ static const char *config_keys[] = "URL", "User", "Password", + "VerifyPeer", + "VerifyHost", "CACert" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -89,6 +93,10 @@ static int config (const char *key, const char *value) return (config_set (&user, value)); else if (strcasecmp (key, "password") == 0) return (config_set (&pass, value)); + else if (strcasecmp (key, "verifypeer") == 0) + return (config_set (&verify_peer, value)); + else if (strcasecmp (key, "verifyhost") == 0) + return (config_set (&verify_host, value)); else if (strcasecmp (key, "cacert") == 0) return (config_set (&cacert, value)); else @@ -114,7 +122,8 @@ static int init (void) if (user != NULL) { - if (snprintf (credentials, 1024, "%s:%s", user, pass == NULL ? "" : pass) >= 1024) + if (ssnprintf (credentials, sizeof (credentials), + "%s:%s", user, pass == NULL ? "" : pass) >= sizeof (credentials)) { ERROR ("nginx plugin: Credentials would have been truncated."); return (-1); @@ -128,6 +137,24 @@ static int init (void) curl_easy_setopt (curl, CURLOPT_URL, url); } + if ((verify_peer == NULL) || (strcmp (verify_peer, "true") == 0)) + { + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1); + } + else + { + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0); + } + + if ((verify_host == NULL) || (strcmp (verify_host, "true") == 0)) + { + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2); + } + else + { + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0); + } + if (cacert != NULL) { curl_easy_setopt (curl, CURLOPT_CAINFO, cacert); @@ -150,18 +177,15 @@ static void submit (char *type, char *inst, long long value) vl.values = values; vl.values_len = 1; - vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "nginx"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "nginx", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (inst != NULL) - { - strncpy (vl.type_instance, inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void submit */ static int nginx_read (void) @@ -171,6 +195,7 @@ static int nginx_read (void) char *ptr; char *lines[16]; int lines_num = 0; + char *saveptr; char *fields[16]; int fields_num; @@ -188,7 +213,8 @@ static int nginx_read (void) } ptr = nginx_buffer; - while ((lines[lines_num] = strtok (ptr, "\n\r")) != NULL) + saveptr = NULL; + while ((lines[lines_num] = strtok_r (ptr, "\n\r", &saveptr)) != NULL) { ptr = NULL; lines_num++;