AC_PLUGIN([ntpd], [yes], [NTPd statistics])
AC_PLUGIN([nut], [$with_libupsclient], [Network UPS tools statistics])
AC_PLUGIN([onewire], [$with_libowcapi], [OneWire sensor statistics])
+AC_PLUGIN([openvpn], [yes], [OpenVPN client statistics])
AC_PLUGIN([oracle], [$with_oracle], [Oracle plugin])
AC_PLUGIN([perl], [$plugin_perl], [Embed a Perl interpreter])
AC_PLUGIN([ping], [$with_liboping], [Network latency statistics])
ntpd . . . . . . . . $enable_ntpd
nut . . . . . . . . . $enable_nut
onewire . . . . . . . $enable_onewire
+ openvpn . . . . . . . $enable_openvpn
oracle . . . . . . . $enable_oracle
perl . . . . . . . . $enable_perl
ping . . . . . . . . $enable_ping
--- /dev/null
+/**
+ * collectd - src/openvpn.c
+ * Copyright (C) 2008 Doug MacEachern
+ * Copyright (C) 2008 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:
+ * Doug MacEachern <dougm at hyperic.com>
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+static char *status_file = "/etc/openvpn/openvpn-status.log";
+
+static const char *config_keys[] =
+{
+ "StatusFile"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+/* copy-n-pasted from common.c - changed delim to "," */
+static int openvpn_strsplit (char *string, char **fields, size_t size)
+{
+ size_t i;
+ char *ptr;
+ char *saveptr;
+
+ i = 0;
+ ptr = string;
+ saveptr = NULL;
+ while ((fields[i] = strtok_r (ptr, ",", &saveptr)) != NULL)
+ {
+ ptr = NULL;
+ i++;
+
+ if (i >= size)
+ break;
+ }
+
+ return (i);
+} /* int openvpn_strsplit */
+
+static void openvpn_submit (char *name, 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);
+ vl.time = time (NULL);
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
+ sstrncpy (vl.type_instance, name, sizeof (vl.type_instance));
+ sstrncpy (vl.type, "if_octets", sizeof (vl.type));
+
+ plugin_dispatch_values (&vl);
+} /* void openvpn_submit */
+
+static int openvpn_read (void)
+{
+ char *name;
+ counter_t rx, tx;
+ FILE *fh;
+ char buffer[1024];
+ char *fields[8];
+ const int max_fields = sizeof(fields)/sizeof(fields[0]);
+ int fields_num;
+ static const char *prefix = "CLIENT_LIST,";
+
+ fh = fopen (status_file, "r");
+ if (fh == NULL)
+ return (-1);
+
+ /* status file is generated by openvpn/multi.c:multi_print_status()
+ * this plugin requires server.conf: "status-version 2"
+ * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
+ */
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ {
+ if (strncmp(buffer, prefix, strlen(prefix)) != 0)
+ {
+ continue;
+ }
+
+ fields_num = openvpn_strsplit (buffer, fields, max_fields);
+ if (fields_num != max_fields)
+ {
+ continue;
+ }
+ name = fields[1]; /* "Common Name" */
+ rx = atoll (fields[4]); /* "Bytes Received */
+ tx = atoll (fields[5]); /* "Bytes Sent" */
+ openvpn_submit (name, rx, tx);
+ }
+ fclose (fh);
+
+ return (0);
+} /* int openvpn_read */
+
+static int openvpn_config (const char *key, const char *value)
+{
+ if (strcasecmp ("StatusFile", key) == 0)
+ {
+ status_file = strdup(value);
+ }
+ else
+ {
+ return (-1);
+ }
+ return (0);
+} /* int openvpn_config */
+
+void module_register (void)
+{
+ plugin_register_config ("openvpn", openvpn_config,
+ config_keys, config_keys_num);
+ plugin_register_read ("openvpn", openvpn_read);
+} /* void module_register */