#include "collectd.h"
-#include "common.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include <curl/curl.h>
#include <libxml/parser.h>
#define PLAYER_INFO_STATIC_INIT \
{ -1, -1, -1, -1, -1 }
-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 char *url;
+static char *user;
+static char *pass;
+static char *verify_peer;
+static char *verify_host;
+static char *cacert;
+static char *timeout;
-static CURL *curl = NULL;
+static CURL *curl;
-static char *ascent_buffer = NULL;
-static size_t ascent_buffer_size = 0;
-static size_t ascent_buffer_fill = 0;
+static char *ascent_buffer;
+static size_t ascent_buffer_size;
+static size_t ascent_buffer_fill;
static char ascent_curl_error[CURL_ERROR_SIZE];
static const char *config_keys[] = {
static int ascent_submit_gauge(const char *plugin_instance, /* {{{ */
const char *type, const char *type_instance,
gauge_t value) {
- value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
- values[0].gauge = value;
-
- vl.values = values;
+ vl.values = &(value_t){.gauge = value};
vl.values_len = 1;
- sstrncpy(vl.host, hostname_g, sizeof(vl.host));
sstrncpy(vl.plugin, "ascent", sizeof(vl.plugin));
if (plugin_instance != NULL)
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
plugin_dispatch_values(&vl);
- return (0);
+ return 0;
} /* }}} int ascent_submit_gauge */
static size_t ascent_curl_callback(void *buf, size_t size,
size_t len = size * nmemb;
if (len == 0)
- return (len);
+ return len;
if ((ascent_buffer_fill + len) >= ascent_buffer_size) {
char *temp;
temp = realloc(ascent_buffer, ascent_buffer_fill + len + 1);
if (temp == NULL) {
ERROR("ascent plugin: realloc failed.");
- return (0);
+ return 0;
}
ascent_buffer = temp;
ascent_buffer_size = ascent_buffer_fill + len + 1;
ascent_buffer_fill += len;
ascent_buffer[ascent_buffer_fill] = 0;
- return (len);
+ return len;
} /* }}} size_t ascent_curl_callback */
static int ascent_submit_players(player_stats_t *ps) /* {{{ */
value = ((double)ps->latency_sum) / (1000.0 * ((double)ps->latency_num));
ascent_submit_gauge(NULL, "latency", "average", value);
- return (0);
+ return 0;
} /* }}} int ascent_submit_players */
static int ascent_account_player(player_stats_t *ps, /* {{{ */
ps->latency_num++;
}
- return (0);
+ return 0;
} /* }}} int ascent_account_player */
static int ascent_xml_submit_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
if (str_ptr == NULL) {
ERROR(
"ascent plugin: ascent_xml_submit_gauge: xmlNodeListGetString failed.");
- return (-1);
+ return -1;
}
if (strcasecmp("N/A", str_ptr) == 0)
if (str_ptr == end_ptr) {
xmlFree(str_ptr);
ERROR("ascent plugin: ascent_xml_submit_gauge: strtod failed.");
- return (-1);
+ return -1;
}
}
xmlFree(str_ptr);
- return (ascent_submit_gauge(plugin_instance, type, type_instance, value));
+ return ascent_submit_gauge(plugin_instance, type, type_instance, value);
} /* }}} int ascent_xml_submit_gauge */
static int ascent_xml_read_int(xmlDoc *doc, xmlNode *node, /* {{{ */
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("ascent plugin: ascent_xml_read_int: xmlNodeListGetString failed.");
- return (-1);
+ return -1;
}
if (strcasecmp("N/A", str_ptr) == 0)
if (str_ptr == end_ptr) {
xmlFree(str_ptr);
ERROR("ascent plugin: ascent_xml_read_int: strtol failed.");
- return (-1);
+ return -1;
}
}
xmlFree(str_ptr);
*ret_value = value;
- return (0);
+ return 0;
} /* }}} int ascent_xml_read_int */
static int ascent_xml_sessions_plr(xmlDoc *doc, xmlNode *node, /* {{{ */
}
} /* for (child) */
- return (0);
+ return 0;
} /* }}} int ascent_xml_sessions_plr */
static int ascent_xml_sessions(xmlDoc *doc, xmlNode *node) /* {{{ */
ascent_submit_players(&ps);
- return (0);
+ return 0;
} /* }}} int ascent_xml_sessions */
static int ascent_xml_status(xmlDoc *doc, xmlNode *node) /* {{{ */
}
} /* for (child) */
- return (0);
+ return 0;
} /* }}} int ascent_xml_status */
static int ascent_xml(const char *data) /* {{{ */
#endif
if (doc == NULL) {
ERROR("ascent plugin: xmlParseMemory failed.");
- return (-1);
+ return -1;
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
ERROR("ascent plugin: XML document is empty.");
xmlFreeDoc(doc);
- return (-1);
+ return -1;
}
if (xmlStrcmp((const xmlChar *)"serverpage", cur->name) != 0) {
ERROR("ascent plugin: XML root element is not \"serverpage\".");
xmlFreeDoc(doc);
- return (-1);
+ return -1;
}
for (xmlNode *child = cur->xmlChildrenNode; child != NULL;
} /* for (child) */
xmlFreeDoc(doc);
- return (0);
+ return 0;
} /* }}} int ascent_xml */
static int config_set(char **var, const char *value) /* {{{ */
}
if ((*var = strdup(value)) == NULL)
- return (1);
+ return 1;
else
- return (0);
+ return 0;
} /* }}} int config_set */
static int ascent_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 ascent_config */
static int ascent_init(void) /* {{{ */
if (url == NULL) {
WARNING("ascent plugin: ascent_init: No URL configured, "
"returning an error.");
- return (-1);
+ return -1;
}
if (curl != NULL) {
if ((curl = curl_easy_init()) == NULL) {
ERROR("ascent plugin: ascent_init: curl_easy_init failed.");
- return (-1);
+ return -1;
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
static char credentials[1024];
int status;
- status = ssnprintf(credentials, sizeof(credentials), "%s:%s", user,
- (pass == NULL) ? "" : pass);
+ status = snprintf(credentials, sizeof(credentials), "%s:%s", user,
+ (pass == NULL) ? "" : pass);
if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
ERROR("ascent plugin: ascent_init: Returning an error because the "
"credentials have been truncated.");
- return (-1);
+ return -1;
}
curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
- return (0);
+ return 0;
} /* }}} int ascent_init */
static int ascent_read(void) /* {{{ */
if (curl == NULL) {
ERROR("ascent plugin: I don't have a CURL object.");
- return (-1);
+ return -1;
}
if (url == NULL) {
ERROR("ascent plugin: No URL has been configured.");
- return (-1);
+ return -1;
}
ascent_buffer_fill = 0;
if (curl_easy_perform(curl) != CURLE_OK) {
ERROR("ascent plugin: curl_easy_perform failed: %s", ascent_curl_error);
- return (-1);
+ return -1;
}
status = ascent_xml(ascent_buffer);
if (status != 0)
- return (-1);
+ return -1;
else
- return (0);
+ return 0;
} /* }}} int ascent_read */
void module_register(void) {
plugin_register_init("ascent", ascent_init);
plugin_register_read("ascent", ascent_read);
} /* void module_register */
-
-/* vim: set sw=2 sts=2 ts=8 et fdm=marker : */