summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5a47432)
raw | patch | inline | side by side (parent: 5a47432)
author | Florian Forster <octo@collectd.org> | |
Thu, 20 Nov 2014 19:05:50 +0000 (20:05 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 6 Jul 2015 12:07:10 +0000 (14:07 +0200) |
src/mqtt.c | patch | blob | history |
diff --git a/src/mqtt.c b/src/mqtt.c
index fffa8fadd3115bff298ba97c23f16e8030847bf9..d1d22054880648c6d3ce2f5872c254c803acbc8f 100644 (file)
--- a/src/mqtt.c
+++ b/src/mqtt.c
return (status);
} /* mqtt_write */
+/*
+ * <Plugin mqtt>
+ * Host "example.com"
+ * Port 1883
+ * Prefix "collectd"
+ * ClientId "collectd"
+ * </Plugin>
+ */
static int mqtt_config (oconfig_item_t *ci)
{
mqtt_client_conf_t *conf;
user_data_t user_data;
int status;
+ int i;
conf = calloc (1, sizeof (*conf));
if (conf == NULL)
}
conf->connected = false;
- conf->host = MQTT_DEFAULT_HOST;
+ conf->host = strdup (MQTT_DEFAULT_HOST);
conf->port = MQTT_DEFAULT_PORT;
- conf->client_id = MQTT_DEFAULT_CLIENT_ID;
- conf->topic_prefix = MQTT_DEFAULT_TOPIC_PREFIX;
+ conf->client_id = strdup (MQTT_DEFAULT_CLIENT_ID);
+ conf->topic_prefix = strdup (MQTT_DEFAULT_TOPIC_PREFIX);
C_COMPLAIN_INIT (&conf->complaint_cantpublish);
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+ if (strcasecmp ("Host", child->key) == 0)
+ cf_util_get_string (child, &conf->host);
+ else if (strcasecmp ("Port", child->key) == 0)
+ {
+ int tmp = cf_util_get_port_number (child);
+ if (tmp < 0)
+ {
+ ERROR ("mqtt plugin: Invalid port number.");
+ continue;
+ }
+ conf->port = tmp;
+ }
+ else if (strcasecmp ("Prefix", child->key) == 0)
+ cf_util_get_string (child, &conf->topic_prefix);
+ else if (strcasecmp ("ClientId", child->key) == 0)
+ cf_util_get_string (child, &conf->client_id);
+ else
+ ERROR ("mqtt plugin: Unknown config option: %s", child->key);
+ }
+
memset (&user_data, 0, sizeof (user_data));
user_data.data = conf;