From 963e53d03f850556fa2c5ec5c60df2c1bab208ba Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 1 Dec 2009 12:07:57 +0100 Subject: [PATCH] =?utf8?q?routeros=20plugin:=20Add=20two=20=E2=80=9CCollec?= =?utf8?q?t*=E2=80=9D=20config=20options.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/collectd.conf.pod | 13 +++++++++++ src/routeros.c | 61 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 6609e692..d73d9fce 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -3294,11 +3294,14 @@ multiple routers: Host "router0.example.com" User "collectd" Password "secr3t" + CollectInterface true Host "router1.example.com" User "collectd" Password "5ecret" + CollectInterface true + CollectRegistrationTable true @@ -3326,6 +3329,16 @@ Use the user name I to authenticate. Defaults to "admin". Set the password used to authenticate. +=item B B|B + +When set to B, interface statistics will be collected for all interfaces +present on the device. Defaults to B. + +=item B B|B + +When set to B, information about wireless LAN connections will be +collected. Defaults to B. + =back =head2 Plugin C diff --git a/src/routeros.c b/src/routeros.c index 48333b5d..02c96d75 100644 --- a/src/routeros.c +++ b/src/routeros.c @@ -33,6 +33,9 @@ struct cr_data_s char *service; char *username; char *password; + + _Bool collect_interface; + _Bool collect_regtable; }; typedef struct cr_data_s cr_data_t; @@ -174,28 +177,34 @@ static int cr_read (user_data_t *user_data) /* {{{ */ } assert (rd->connection != NULL); - status = ros_interface (rd->connection, handle_interface, - /* user data = */ NULL); - if (status != 0) + if (rd->collect_interface) { - char errbuf[128]; - ERROR ("routeros plugin: ros_interface failed: %s", - sstrerror (status, errbuf, sizeof (errbuf))); - ros_disconnect (rd->connection); - rd->connection = NULL; - return (-1); + status = ros_interface (rd->connection, handle_interface, + /* user data = */ NULL); + if (status != 0) + { + char errbuf[128]; + ERROR ("routeros plugin: ros_interface failed: %s", + sstrerror (status, errbuf, sizeof (errbuf))); + ros_disconnect (rd->connection); + rd->connection = NULL; + return (-1); + } } - status = ros_registration_table (rd->connection, handle_regtable, - /* user data = */ NULL); - if (status != 0) + if (rd->collect_regtable) { - char errbuf[128]; - ERROR ("routeros plugin: ros_registration_table failed: %s", - sstrerror (status, errbuf, sizeof (errbuf))); - ros_disconnect (rd->connection); - rd->connection = NULL; - return (-1); + status = ros_registration_table (rd->connection, handle_regtable, + /* user data = */ NULL); + if (status != 0) + { + char errbuf[128]; + ERROR ("routeros plugin: ros_registration_table failed: %s", + sstrerror (status, errbuf, sizeof (errbuf))); + ros_disconnect (rd->connection); + rd->connection = NULL; + return (-1); + } } return (0); @@ -234,6 +243,8 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */ router_data->service = NULL; router_data->username = NULL; router_data->password = NULL; + router_data->collect_interface = false; + router_data->collect_regtable = false; status = 0; for (i = 0; i < ci->children_num; i++) @@ -247,7 +258,11 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */ else if (strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &router_data->username); else if (strcasecmp ("Password", child->key) == 0) - status = cf_util_get_string (child, &router_data->service); + status = cf_util_get_string (child, &router_data->password); + else if (strcasecmp ("CollectInterface", child->key) == 0) + cf_util_get_boolean (child, &router_data->collect_interface); + else if (strcasecmp ("CollectRegistrationTable", child->key) == 0) + cf_util_get_boolean (child, &router_data->collect_regtable); else { WARNING ("routeros plugin: Unknown config option `%s'.", child->key); @@ -272,6 +287,14 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */ "How should I authenticate?"); status = -1; } + + if (!router_data->collect_interface + && !router_data->collect_regtable) + { + ERROR ("routeros plugin: No `Collect*' option within a `Router' block. " + "What statistics should I collect?"); + status = -1; + } } if ((status == 0) && (router_data->username == NULL)) -- 2.11.0