AM_CONDITIONAL(BUILD_WITH_LIBPTHREAD, test "x$with_libpthread" = "xyes")
# }}}
+# --with-librouteros {{{
+AC_ARG_WITH(librouteros, [AS_HELP_STRING([--with-librouteros@<:@=PREFIX@:>@], [Path to librouteros.])],
+[
+ if test "x$withval" = "xyes"
+ then
+ with_librouteros="yes"
+ else if test "x$withval" = "xno"
+ then
+ with_librouteros="no"
+ else
+ with_librouteros="yes"
+ LIBROUTEROS_CPPFLAGS="$LIBROUTEROS_CPPFLAGS -I$withval/include"
+ LIBROUTEROS_LDFLAGS="$LIBROUTEROS_LDFLAGS -L$withval/lib"
+ fi; fi
+],
+[with_librouteros="yes"])
+
+SAVE_CPPFLAGS="$CPPFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
+
+CPPFLAGS="$CPPFLAGS $LIBROUTEROS_CPPFLAGS"
+LDFLAGS="$LDFLAGS $LIBROUTEROS_LDFLAGS"
+
+if test "x$with_librouteros" = "xyes"
+then
+ if test "x$LIBROUTEROS_CPPFLAGS" != "x"
+ then
+ AC_MSG_NOTICE([librouteros CPPFLAGS: $LIBROUTEROS_CPPFLAGS])
+ fi
+ AC_CHECK_HEADERS(routeros_api.h,
+ [with_librouteros="yes"],
+ [with_librouteros="no ('routeros_api.h' not found)"])
+fi
+if test "x$with_librouteros" = "xyes"
+then
+ if test "x$LIBROUTEROS_LDFLAGS" != "x"
+ then
+ AC_MSG_NOTICE([librouteros LDFLAGS: $LIBROUTEROS_LDFLAGS])
+ fi
+ AC_CHECK_LIB(routeros, ros_interface,
+ [with_librouteros="yes"],
+ [with_librouteros="no (symbol 'ros_interface' not found)"])
+fi
+
+CPPFLAGS="$SAVE_CPPFLAGS"
+LDFLAGS="$SAVE_LDFLAGS"
+
+if test "x$with_librouteros" = "xyes"
+then
+ BUILD_WITH_LIBROUTEROS_CPPFLAGS="$LIBROUTEROS_CPPFLAGS"
+ BUILD_WITH_LIBROUTEROS_LDFLAGS="$LIBROUTEROS_LDFLAGS"
+ AC_SUBST(BUILD_WITH_LIBROUTEROS_CPPFLAGS)
+ AC_SUBST(BUILD_WITH_LIBROUTEROS_LDFLAGS)
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBROUTEROS, test "x$with_librouteros" = "xyes")
+# }}}
+
# --with-librrd {{{
# AC_ARG_WITH (package, help-string, [action-if-given], [action-if-not-given])
librrd_cflags=""
AC_PLUGIN([powerdns], [yes], [PowerDNS statistics])
AC_PLUGIN([processes], [$plugin_processes], [Process statistics])
AC_PLUGIN([protocols], [$plugin_protocols], [Protocol (IP, TCP, ...) statistics])
+AC_PLUGIN([routeros], [$with_librouteros], [RouterOS plugin])
AC_PLUGIN([rrdcached], [$librrd_rrdc_update], [RRDTool output plugin])
AC_PLUGIN([rrdtool], [$with_librrd], [RRDTool output plugin])
AC_PLUGIN([sensors], [$with_libsensors], [lm_sensors statistics])
libperl . . . . . . . $with_libperl
libpq . . . . . . . . $with_libpq
libpthread . . . . . $with_libpthread
+ librouteros . . . . . $with_librouteros
librrd . . . . . . . $with_librrd
libsensors . . . . . $with_libsensors
libstatgrab . . . . . $with_libstatgrab
powerdns . . . . . . $enable_powerdns
processes . . . . . . $enable_processes
protocols . . . . . . $enable_protocols
+ routeros . . . . . . $enable_routeros
rrdcached . . . . . . $enable_rrdcached
rrdtool . . . . . . . $enable_rrdtool
sensors . . . . . . . $enable_sensors
--- /dev/null
+/**
+ * collectd - src/load.c
+ * Copyright (C) 2009 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.
+ *
+ * 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.
+ *
+ * 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
+ *
+ * Authors:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <routeros_api.h>
+
+static ros_connection_t *connection = NULL;
+
+static char *conf_node = "router.example.com";
+static char *conf_service = NULL;
+static char *conf_username = "collectd";
+static char *conf_password = "secret";
+
+static void cr_submit_io (const char *type, const char *type_instance, /* {{{ */
+ counter_t rx, counter_t tx)
+{
+ value_t values[2];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].counter = rx;
+ values[1].counter = tx;
+
+ vl.values = values;
+ vl.values_len = STATIC_ARRAY_SIZE (values);
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "routeros", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+
+ plugin_dispatch_values (&vl);
+} /* }}} void cr_submit_io */
+
+static void submit_interface (const ros_interface_t *i) /* {{{ */
+{
+ if (i == NULL)
+ return;
+
+ if (!i->running)
+ {
+ submit_interface (i->next);
+ return;
+ }
+
+ cr_submit_io ("if_packets", i->name,
+ (counter_t) i->rx_packets, (counter_t) i->tx_packets);
+ cr_submit_io ("if_octets", i->name,
+ (counter_t) i->rx_bytes, (counter_t) i->tx_bytes);
+ cr_submit_io ("if_errors", i->name,
+ (counter_t) i->rx_errors, (counter_t) i->tx_errors);
+ cr_submit_io ("if_dropped", i->name,
+ (counter_t) i->rx_drops, (counter_t) i->tx_drops);
+
+ submit_interface (i->next);
+} /* }}} void submit_interface */
+
+static int handle_interface (__attribute__((unused)) ros_connection_t *c, /* {{{ */
+ const ros_interface_t *i, __attribute__((unused)) void *user_data)
+{
+ submit_interface (i);
+ return (0);
+} /* }}} int handle_interface */
+
+static int cr_read (void) /* {{{ */
+{
+ int status;
+
+ if (connection == NULL)
+ {
+ connection = ros_connect (conf_node, conf_service,
+ conf_username, conf_password);
+ if (connection == NULL)
+ {
+ char errbuf[128];
+ ERROR ("routeros plugin: ros_connect failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
+ }
+ assert (connection != NULL);
+
+ status = ros_interface (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 (connection);
+ connection = NULL;
+ return (-1);
+ }
+
+ return (0);
+} /* }}} int cr_read */
+
+void module_register (void)
+{
+ plugin_register_read ("routeros", cr_read);
+} /* void module_register */
+
+/* vim: set sw=2 noet fdm=marker : */