X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnginx.c;h=4de59f3752b8827f28bf8885ec2f3c9073dd6c5d;hb=2c8470d917b2f0a17326ee1336081dcffbd6a347;hp=a44e8a5778bb9de85802c599a91574745048458e;hpb=79dab1613955126520ab36e772f0afb596fd51dc;p=collectd.git diff --git a/src/nginx.c b/src/nginx.c index a44e8a57..4de59f37 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); @@ -154,14 +181,12 @@ static void submit (char *type, char *inst, long long value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "nginx"); strcpy (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)