From f8ce6e1a9f5d02e43e2c97dc810c40f39e3b6e72 Mon Sep 17 00:00:00 2001 From: Mariusz Bialonczyk Date: Fri, 25 Sep 2015 11:44:37 +0200 Subject: [PATCH] routeros: add support for collecting health data It includes the voltage and temperature data on supported hardware. --- src/routeros.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/routeros.c b/src/routeros.c index c0d5ef7f..7f5e6083 100644 --- a/src/routeros.c +++ b/src/routeros.c @@ -45,6 +45,7 @@ struct cr_data_s { bool collect_memory; bool collect_df; bool collect_disk; + bool collect_health; }; typedef struct cr_data_s cr_data_t; @@ -212,6 +213,22 @@ static int handle_system_resource(__attribute__((unused)) return 0; } /* }}} int handle_system_resource */ + +static int handle_system_health(__attribute__((unused)) + ros_connection_t *c, /* {{{ */ + const ros_system_health_t *r, + __attribute__((unused)) void *user_data) { + cr_data_t *rd; + + if ((r == NULL) || (user_data == NULL)) + return (EINVAL); + rd = user_data; + + cr_submit_gauge(rd, "gauge", "voltage", (gauge_t)r->voltage); + cr_submit_gauge(rd, "gauge", "temperature", (gauge_t)r->temperature); + + return (0); +} /* }}} int handle_system_health */ #endif static int cr_read(user_data_t *user_data) /* {{{ */ @@ -272,6 +289,19 @@ static int cr_read(user_data_t *user_data) /* {{{ */ return -1; } } + + if (rd->collect_health) { + status = ros_system_health(rd->connection, handle_system_health, + /* user data = */ rd); + if (status != 0) { + char errbuf[128]; + ERROR("routeros plugin: ros_system_health failed: %s", + sstrerror(status, errbuf, sizeof(errbuf))); + ros_disconnect(rd->connection); + rd->connection = NULL; + return (-1); + } + } #endif return 0; @@ -333,6 +363,8 @@ static int cr_config_router(oconfig_item_t *ci) /* {{{ */ cf_util_get_boolean(child, &router_data->collect_df); else if (strcasecmp("CollectDisk", child->key) == 0) cf_util_get_boolean(child, &router_data->collect_disk); + else if (strcasecmp("CollectHealth", child->key) == 0) + cf_util_get_boolean(child, &router_data->collect_health); #endif else { WARNING("routeros plugin: Unknown config option `%s'.", child->key); -- 2.11.0