diff --git a/src/ascent.c b/src/ascent.c
index b63f73e9539d9d8120825ecf9502712860b7263a..d38e85916e937468c13dfb1d33e6706991fd261b 100644 (file)
--- a/src/ascent.c
+++ b/src/ascent.c
/**
* collectd - src/ascent.c
- * Copyright (C) 2008 Florian octo Forster
+ * Copyright (C) 2008 Florian octo Forster
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
*
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <octo at collectd.org>
**/
#include "collectd.h"
#include <curl/curl.h>
#include <libxml/parser.h>
-static char *races_list[] = /* {{{ */
-{
- NULL,
- "Warrior", /* 1 */
- "Paladin", /* 2 */
- "Hunter", /* 3 */
- "Rogue", /* 4 */
- "Priest", /* 5 */
- NULL,
- "Shaman", /* 7 */
- "Mage", /* 8 */
- "Warlock", /* 9 */
- NULL,
- "Druid" /* 11 */
-}; /* }}} */
-#define RACES_LIST_LENGTH STATIC_ARRAY_SIZE (races_list)
-
-static char *classes_list[] = /* {{{ */
+static const char *races_list[] = /* {{{ */
{
NULL,
"Human", /* 1 */
"Bloodelf", /* 10 */
"Draenei" /* 11 */
}; /* }}} */
+#define RACES_LIST_LENGTH STATIC_ARRAY_SIZE (races_list)
+
+static const char *classes_list[] = /* {{{ */
+{
+ NULL,
+ "Warrior", /* 1 */
+ "Paladin", /* 2 */
+ "Hunter", /* 3 */
+ "Rogue", /* 4 */
+ "Priest", /* 5 */
+ NULL,
+ "Shaman", /* 7 */
+ "Mage", /* 8 */
+ "Warlock", /* 9 */
+ NULL,
+ "Druid" /* 11 */
+}; /* }}} */
#define CLASSES_LIST_LENGTH STATIC_ARRAY_SIZE (classes_list)
-static char *genders_list[] = /* {{{ */
+static const char *genders_list[] = /* {{{ */
{
"Male",
"Female"
typedef struct player_info_s player_info_t;
#define PLAYER_INFO_STATIC_INIT { -1, -1, -1, -1, -1 }
-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 char *timeout = NULL;
static CURL *curl = NULL;
"URL",
"User",
"Password",
- "CACert"
+ "VerifyPeer",
+ "VerifyHost",
+ "CACert",
+ "Timeout",
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
vl.values = values;
vl.values_len = 1;
- vl.time = time (NULL);
- strcpy (vl.host, hostname_g);
- strcpy (vl.plugin, "ascent");
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "ascent", sizeof (vl.plugin));
if (plugin_instance != NULL)
sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+
if (type_instance != NULL)
sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
return (0);
} /* }}} int ascent_submit_gauge */
static size_t ascent_curl_callback (void *buf, size_t size, size_t nmemb, /* {{{ */
- void *stream)
+ void __attribute__((unused)) *stream)
{
size_t len = size * nmemb;
@@ -169,7 +181,7 @@ static size_t ascent_curl_callback (void *buf, size_t size, size_t nmemb, /* {{{
static int ascent_submit_players (player_stats_t *ps) /* {{{ */
{
- int i;
+ size_t i;
gauge_t value;
for (i = 0; i < RACES_LIST_LENGTH; i++)
value = ((double) ps->level_sum) / ((double) ps->level_num);
ascent_submit_gauge (NULL, "gauge", "avg-level", value);
+ /* Latency is in ms, but we store seconds. */
if (ps->latency_num <= 0)
value = NAN;
else
- value = ((double) ps->latency_sum) / ((double) ps->latency_num);
- ascent_submit_gauge (NULL, "gauge", "avg-latency", value);
+ value = ((double) ps->latency_sum) / (1000.0 * ((double) ps->latency_num));
+ ascent_submit_gauge (NULL, "latency", "average", value);
return (0);
} /* }}} int ascent_submit_players */
{
if (pi->race >= 0)
{
- if ((pi->race >= RACES_LIST_LENGTH)
+ if (((size_t) pi->race >= RACES_LIST_LENGTH)
|| (races_list[pi->race] == NULL))
ERROR ("ascent plugin: Ignoring invalid numeric race %i.", pi->race);
else
if (pi->class >= 0)
{
- if ((pi->class >= CLASSES_LIST_LENGTH)
+ if (((size_t) pi->class >= CLASSES_LIST_LENGTH)
|| (classes_list[pi->class] == NULL))
ERROR ("ascent plugin: Ignoring invalid numeric class %i.", pi->class);
else
if (pi->gender >= 0)
{
- if ((pi->gender >= GENDERS_LIST_LENGTH)
+ if (((size_t) pi->gender >= GENDERS_LIST_LENGTH)
|| (genders_list[pi->gender] == NULL))
ERROR ("ascent plugin: Ignoring invalid numeric gender %i.",
pi->gender);
value = strtod (str_ptr, &end_ptr);
if (str_ptr == end_ptr)
{
+ xmlFree(str_ptr);
ERROR ("ascent plugin: ascent_xml_submit_gauge: strtod failed.");
return (-1);
}
}
+ xmlFree(str_ptr);
return (ascent_submit_gauge (plugin_instance, type, type_instance, value));
} /* }}} int ascent_xml_submit_gauge */
value = strtol (str_ptr, &end_ptr, 0);
if (str_ptr == end_ptr)
{
+ xmlFree(str_ptr);
ERROR ("ascent plugin: ascent_xml_read_int: strtol failed.");
return (-1);
}
}
+ xmlFree(str_ptr);
*ret_value = value;
return (0);
ascent_xml_submit_gauge (doc, child, NULL, "players", "horde");
else if (xmlStrcmp ((const xmlChar *) "qplayers", child->name) == 0)
ascent_xml_submit_gauge (doc, child, NULL, "players", "queued");
+ else if ((xmlStrcmp ((const xmlChar *) "acceptedconns", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "avglat", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "cdbquerysize", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "cpu", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "fthreads", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "gmcount", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "lastupdate", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "ontime", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "oplayers", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "peakcount", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "platform", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "ram", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "threads", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "uptime", child->name) == 0)
+ || (xmlStrcmp ((const xmlChar *) "wdbquerysize", child->name) == 0))
+ /* ignore */;
else
{
WARNING ("ascent plugin: ascent_xml_status: Unknown tag: %s", child->name);
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 if (strcasecmp (key, "Timeout") == 0)
+ return (config_set (&timeout, value));
else
return (-1);
} /* }}} int ascent_config */
static int ascent_init (void) /* {{{ */
{
- static char credentials[1024];
-
if (url == NULL)
{
WARNING ("ascent plugin: ascent_init: No URL configured, "
return (-1);
}
+ curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ascent_curl_callback);
- curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
+ curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, ascent_curl_error);
if (user != NULL)
{
+#ifdef HAVE_CURLOPT_USERNAME
+ curl_easy_setopt (curl, CURLOPT_USERNAME, user);
+ curl_easy_setopt (curl, CURLOPT_PASSWORD, (pass == NULL) ? "" : pass);
+#else
+ static char credentials[1024];
int status;
- status = snprintf (credentials, sizeof (credentials), "%s:%s",
+ status = ssnprintf (credentials, sizeof (credentials), "%s:%s",
user, (pass == NULL) ? "" : pass);
- if (status >= sizeof (credentials))
+ if ((status < 0) || ((size_t) status >= sizeof (credentials)))
{
ERROR ("ascent plugin: ascent_init: Returning an error because the "
"credentials have been truncated.");
return (-1);
}
- credentials[sizeof (credentials) - 1] = '\0';
curl_easy_setopt (curl, CURLOPT_USERPWD, credentials);
+#endif
}
curl_easy_setopt (curl, CURLOPT_URL, url);
+ curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
+
+ if ((verify_peer == NULL) || IS_TRUE (verify_peer))
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1L);
+ else
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L);
+
+ if ((verify_host == NULL) || IS_TRUE (verify_host))
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2L);
+ else
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L);
if (cacert != NULL)
curl_easy_setopt (curl, CURLOPT_CAINFO, cacert);
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+ if (timeout != NULL)
+ curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, atol(timeout));
+ else
+ curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval()));
+#endif
+
return (0);
} /* }}} int ascent_init */
}
ascent_buffer_fill = 0;
- if (curl_easy_perform (curl) != 0)
+ if (curl_easy_perform (curl) != CURLE_OK)
{
ERROR ("ascent plugin: curl_easy_perform failed: %s",
ascent_curl_error);