Merge branch 'sh/teamspeak2'
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 13 Apr 2008 09:06:14 +0000 (11:06 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 13 Apr 2008 09:06:14 +0000 (11:06 +0200)
AUTHORS
configure.in
src/Makefile.am
src/collectd.conf.in
src/collectd.conf.pod
src/teamspeak2.c [new file with mode: 0644]
src/types.db

diff --git a/AUTHORS b/AUTHORS
index bd5daa4..2004dff 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -40,6 +40,9 @@ serial plugin by:
 tape plugin by:
   Scott Garrett <sgarrett at technomancer.com>
 
+teamspeak2 plugin by:
+  Stefan Hacker <stefan.hacker at web.de>
+
 users plugin by:
   Sebastian Harl <sh at tokkee.org>
 
index 095509a..fae9a99 100644 (file)
@@ -2326,6 +2326,7 @@ AC_PLUGIN([syslog],      [$have_syslog],       [Syslog logging plugin])
 AC_PLUGIN([tail],        [yes],                [Parsing of logfiles])
 AC_PLUGIN([tape],        [$plugin_tape],       [Tape drive statistics])
 AC_PLUGIN([tcpconns],    [$plugin_tcpconns],   [TCP connection statistics])
+AC_PLUGIN([teamspeak2],  [yes],                [TeamSpeak2 server statistics])
 AC_PLUGIN([unixsock],    [yes],                [Unixsock communication plugin])
 AC_PLUGIN([users],       [$plugin_users],      [User statistics])
 AC_PLUGIN([uuid],        [yes],                [UUID as hostname plugin])
@@ -2470,6 +2471,7 @@ Configuration:
     tail  . . . . . . . $enable_tail
     tape  . . . . . . . $enable_tape
     tcpconns  . . . . . $enable_tcpconns
+    teamspeak2  . . . . $enable_teamspeak2
     unixsock  . . . . . $enable_unixsock
     users . . . . . . . $enable_users
     uuid  . . . . . . . $enable_uuid
index 37bf6fc..e094c8f 100644 (file)
@@ -620,6 +620,14 @@ collectd_LDADD += "-dlopen" tcpconns.la
 collectd_DEPENDENCIES += tcpconns.la
 endif
 
+if BUILD_PLUGIN_TEAMSPEAK2
+pkglib_LTLIBRARIES += teamspeak2.la
+teamspeak2_la_SOURCES = teamspeak2.c
+teamspeak2_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" teamspeak2.la
+collectd_DEPENDENCIES += teamspeak2.la
+endif
+
 if BUILD_PLUGIN_UNIXSOCK
 pkglib_LTLIBRARIES += unixsock.la
 unixsock_la_SOURCES = unixsock.c \
index f9980f1..036916e 100644 (file)
@@ -58,6 +58,7 @@ FQDNLookup   true
 @BUILD_PLUGIN_SYSLOG_TRUE@LoadPlugin syslog
 @BUILD_PLUGIN_TAPE_TRUE@LoadPlugin tape
 @BUILD_PLUGIN_TCPCONNS_TRUE@LoadPlugin tcpconns
+@BUILD_PLUGIN_TEAMSPEAK2_TRUE@LoadPlugin teamspeak2
 @BUILD_PLUGIN_UNIXSOCK_TRUE@LoadPlugin unixsock
 @BUILD_PLUGIN_USERS_TRUE@LoadPlugin users
 @BUILD_PLUGIN_UUID_TRUE@LoadPlugin uuid
@@ -287,6 +288,12 @@ FQDNLookup   true
 #      RemotePort "25"
 #</Plugin>
 
+#<Plugin teamspeak2>
+#      Host "127.0.0.1"
+#      Port "51234"
+#      Server "8767"
+#</Plugin>
+
 #<Plugin unixsock>
 #      SocketFile "@prefix@/var/run/@PACKAGE_NAME@-unixsock"
 #      SocketGroup "collectd"
index e98860b..40c3158 100644 (file)
@@ -1159,6 +1159,37 @@ This optional setting sets the type instance to use.
 
 =back
 
+=head2 Plugin C<teamspeak2>
+
+The C<teamspeak2 plugin> connects to the query port of a teamspeak2 server and
+polls interesting global and virtual server data. The plugin can query only one
+physical server but unlimited virtual servers. You can use the following
+options to configure it:
+
+=over 4
+
+=item B<Host> I<hostname/ip>
+
+The hostname or ip which identifies the physical server.
+Default: 127.0.0.1
+
+=item B<Port> I<port>
+
+The query port of the physical server. This needs to be a string.
+Default: "51234"
+
+=item B<Server> I<port>
+
+This option has to be added once for every virtual server the plugin should
+query. If you want to query the virtual server on port 8767 this is what the
+option would look like:
+
+  Server "8767"
+
+This option, although numeric, needs to be a string, i.E<nbsp>e. you B<must>
+use quotes around it! If no such statement is given only global information
+will be collected.
+
 =head2 Plugin C<tcpconns>
 
 The C<tcpconns plugin> counts the number of currently established TCP
@@ -1169,6 +1200,8 @@ fine-tune the ports you are interested in:
 
 =over 4
 
+=back
+
 =item B<ListeningPorts> I<true>|I<false>
 
 If this option is set to I<true>, statistics for all local ports for which a
diff --git a/src/teamspeak2.c b/src/teamspeak2.c
new file mode 100644 (file)
index 0000000..e258645
--- /dev/null
@@ -0,0 +1,708 @@
+/**
+ * collectd - src/teamspeak2.c
+ * Copyright (C) 2008  Stefan Hacker
+ * Copyright (C) 2008  Florian 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:
+ *   Stefan Hacker <d0t at dbclan dot de>
+ *   Florian Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+/*
+ * Defines
+ */
+/* Default host and port */
+#define DEFAULT_HOST   "127.0.0.1"
+#define DEFAULT_PORT   "51234"
+
+/*
+ * Variables
+ */
+/* Server linked list structure */
+typedef struct vserver_list_s
+{
+       int port;
+       struct vserver_list_s *next;
+} vserver_list_t;
+static vserver_list_t *server_list = NULL;
+
+/* Host data */
+static char *config_host = NULL;
+static char *config_port = NULL;
+
+static FILE *global_read_fh = NULL;
+static FILE *global_write_fh = NULL;
+
+/* Config data */
+static const char *config_keys[] =
+{
+       "Host",
+       "Port",
+       "Server"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+/*
+ * Functions
+ */
+static int tss2_add_vserver (int vserver_port)
+{
+       /*
+        * Adds a new vserver to the linked list
+        */
+       vserver_list_t *entry;
+
+       /* Check port range */
+       if ((vserver_port <= 0) || (vserver_port > 65535))
+       {
+               ERROR ("teamspeak2 plugin: VServer port is invalid: %i",
+                               vserver_port);
+               return (-1);
+       }
+
+       /* Allocate memory */
+       entry = (vserver_list_t *) malloc (sizeof (vserver_list_t));
+       if (entry == NULL)
+       {
+               ERROR ("teamspeak2 plugin: malloc failed.");
+               return (-1);
+       }
+       memset (entry, 0, sizeof (vserver_list_t));
+
+       /* Save data */
+       entry->port = vserver_port;
+
+       /* Insert to list */
+       if(server_list == NULL) {
+               /* Add the server as the first element */
+               server_list = entry;
+       }
+       else {
+               vserver_list_t *prev;
+
+               /* Add the server to the end of the list */
+               prev = server_list;
+               while (prev->next != NULL)
+                       prev = prev->next;
+               prev->next = entry;
+       }
+
+       INFO ("teamspeak2 plugin: Registered new vserver: %i", vserver_port);
+
+       return (0);
+} /* int tss2_add_vserver */
+
+static void tss2_submit_gauge (const char *plugin_instance, const char *type,
+               gauge_t value)
+{
+       /*
+        * Submits a gauge value to the collectd daemon
+        */
+       value_t values[1];
+       value_list_t vl = VALUE_LIST_INIT;
+
+       values[0].gauge = value;
+
+       vl.values     = values;
+       vl.values_len = 1;
+       vl.time       = time (NULL);
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "teamspeak2", sizeof (vl.plugin));
+
+       if (plugin_instance != NULL)
+               sstrncpy (vl.plugin_instance, plugin_instance,
+                               sizeof (vl.plugin_instance));
+       
+       plugin_dispatch_values (type, &vl);
+} /* void tss2_submit_gauge */
+
+static void tss2_submit_io (const char *plugin_instance, const char *type,
+               counter_t rx, counter_t tx)
+{
+       /*
+        * Submits the io rx/tx tuple to the collectd daemon
+        */
+       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 = 2;
+       vl.time       = time (NULL);
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "teamspeak2", sizeof (vl.plugin));
+
+       if (plugin_instance != NULL)
+               sstrncpy (vl.plugin_instance, plugin_instance,
+                               sizeof (vl.plugin_instance));
+       
+       plugin_dispatch_values (type, &vl);
+} /* void tss2_submit_gauge */
+
+static void tss2_close_socket (void)
+{
+       /*
+        * Closes all sockets
+        */
+       if (global_write_fh != NULL)
+       {
+               fputs ("quit\r\n", global_write_fh);
+       }
+
+       if (global_read_fh != NULL)
+       {
+               fclose (global_read_fh);
+               global_read_fh = NULL;
+       }
+
+       if (global_write_fh != NULL)
+       {
+               fclose (global_write_fh);
+               global_write_fh = NULL;
+       }
+} /* void tss2_close_socket */
+
+static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
+{
+       /*
+        * Returns connected file objects or establishes the connection
+        * if it's not already present
+        */
+       struct addrinfo ai_hints;
+       struct addrinfo *ai_head;
+       struct addrinfo *ai_ptr;
+       int sd = -1;
+       int status;
+
+       /* Check if we already got opened connections */
+       if ((global_read_fh != NULL) && (global_write_fh != NULL))
+       {
+               /* If so, use them */
+               if (ret_read_fh != NULL)
+                       *ret_read_fh = global_read_fh;
+               if (ret_write_fh != NULL)
+                       *ret_write_fh = global_write_fh;
+               return (0);
+       }
+
+       /* Get all addrs for this hostname */
+       memset (&ai_hints, 0, sizeof (ai_hints));
+#ifdef AI_ADDRCONFIG
+       ai_hints.ai_flags |= AI_ADDRCONFIG;
+#endif
+       ai_hints.ai_family = AF_UNSPEC;
+       ai_hints.ai_socktype = SOCK_STREAM;
+
+       status = getaddrinfo ((config_host != NULL) ? config_host : DEFAULT_HOST,
+                       (config_port != NULL) ? config_port : DEFAULT_PORT,
+                       &ai_hints,
+                       &ai_head);
+       if (status != 0)
+       {
+               ERROR ("teamspeak2 plugin: getaddrinfo failed: %s",
+                               gai_strerror (status));
+               return (-1);
+       }
+
+       /* Try all given hosts until we can connect to one */
+       for (ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+       {
+               /* Create socket */
+               sd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
+                               ai_ptr->ai_protocol);
+               if (sd < 0)
+               {
+                       char errbuf[1024];
+                       WARNING ("teamspeak2 plugin: socket failed: %s",
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+                       continue;
+               }
+
+               /* Try to connect */
+               status = connect (sd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
+               if (status != 0)
+               {
+                       char errbuf[1024];
+                       WARNING ("teamspeak2 plugin: connect failed: %s",
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+                       close (sd);
+                       continue;
+               }
+
+               /*
+                * Success, we can break. Don't need more than one connection
+                */
+               break;
+       } /* for (ai_ptr) */
+
+       freeaddrinfo (ai_head);
+
+       /* Check if we really got connected */
+       if (sd < 0)
+               return (-1);
+
+       /* Create file objects from sockets */
+       global_read_fh = fdopen (sd, "r");
+       if (global_read_fh == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("teamspeak2 plugin: fdopen failed: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               close (sd);
+               return (-1);
+       }
+
+       global_write_fh = fdopen (sd, "w");
+       if (global_write_fh == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("teamspeak2 plugin: fdopen failed: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               tss2_close_socket ();
+               return (-1);
+       }
+
+       { /* Check that the server correctly identifies itself. */
+               char buffer[4096];
+               char *buffer_ptr;
+
+               buffer_ptr = fgets (buffer, sizeof (buffer), global_read_fh);
+               buffer[sizeof (buffer) - 1] = 0;
+
+               if (memcmp ("[TS]\r\n", buffer, 6) != 0)
+               {
+                       ERROR ("teamspeak2 plugin: Unexpected response when connecting "
+                                       "to server. Expected ``[TS]'', got ``%s''.",
+                                       buffer);
+                       tss2_close_socket ();
+                       return (-1);
+               }
+               DEBUG ("teamspeak2 plugin: Server send correct banner, connected!");
+       }
+
+       /* Copy the new filehandles to the given pointers */
+       if (ret_read_fh != NULL)
+               *ret_read_fh = global_read_fh;
+       if (ret_write_fh != NULL)
+               *ret_write_fh = global_write_fh;
+       return (0);
+} /* int tss2_get_socket */
+
+static int tss2_send_request (FILE *fh, const char *request)
+{
+       /*
+        * This function puts a request to the server socket
+        */
+       int status;
+
+       status = fputs (request, fh);
+       if (status < 0)
+       {
+               ERROR ("teamspeak2 plugin: fputs failed.");
+               tss2_close_socket ();
+               return (-1);
+       }
+       fflush (fh);
+
+       return (0);
+} /* int tss2_send_request */
+
+static int tss2_receive_line (FILE *fh, char *buffer, int buffer_size)
+{
+       /*
+        * Receive a single line from the given file object
+        */
+       char *temp;
+        
+       /*
+        * fgets is blocking but much easier then doing anything else
+        * TODO: Non-blocking Version would be safer
+        */
+       temp = fgets (buffer, buffer_size, fh);
+       if (temp == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("teamspeak2 plugin: fgets failed: %s",
+                               sstrerror (errno, errbuf, sizeof(errbuf)));
+               tss2_close_socket ();
+               return (-1);
+       }
+
+       buffer[buffer_size - 1] = 0;
+       return (0);
+} /* int tss2_receive_line */
+
+static int tss2_select_vserver (FILE *read_fh, FILE *write_fh, vserver_list_t *vserver)
+{
+       /*
+        * Tell the server to select the given vserver
+        */
+       char command[128];
+       char response[128];
+       int status;
+
+       DEBUG("teamspeak2 plugin: Select server %i", vserver->port);
+       
+       /* Send request */
+       snprintf (command, sizeof (command), "sel %i\r\n", vserver->port);
+       command[sizeof (command) - 1] = 0;
+
+       status = tss2_send_request (write_fh, command);
+       if (status != 0)
+       {
+               ERROR ("teamspeak2 plugin: tss2_send_request (%s) failed.", command);
+               return (-1);
+       }
+
+       /* Get answer */
+       status = tss2_receive_line (read_fh, response, sizeof (response));
+       if (status != 0)
+       {
+               ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
+               return (-1);
+       }
+       response[sizeof (response)] = 0;
+
+       /* Check answer */
+       if ((strncmp ("OK", response, 2) == 0)
+                       && ((response[2] == 0)
+                               || (response[2] == '\n')
+                               || (response[2] == '\r')))
+               return (0);
+
+       ERROR ("teamspeak2 plugin: Command ``%s'' failed. "
+                       "Response received from server was: ``%s''.",
+                       command, response);
+       return (-1);
+} /* int tss2_select_vserver */
+
+static int tss2_read_vserver (vserver_list_t *vserver)
+{
+       int status;
+
+       gauge_t users = NAN;
+       counter_t rx_octets = 0;
+       counter_t tx_octets = 0;
+       counter_t rx_packets = 0;
+       counter_t tx_packets = 0;
+       int valid = 0;
+
+       char plugin_instance[DATA_MAX_NAME_LEN];
+
+       FILE *read_fh;
+       FILE *write_fh;
+
+       /* Get the send/receive sockets */
+       status = tss2_get_socket (&read_fh, &write_fh);
+       if (status != 0)
+       {
+               ERROR ("teamspeak2 plugin: tss2_get_socket failed.");
+               return (-1);
+       }
+
+       if (vserver == NULL)
+       {
+               /* Request global information */
+               DEBUG("teamspeak2 plugin: Read global server information");
+       
+               memset (plugin_instance, 0, sizeof (plugin_instance));
+
+               status = tss2_send_request (write_fh, "gi\r\n");
+       }
+       else
+       {
+               /* Request server information */
+               DEBUG("teamspeak2 plugin: Read vserver's %i information!", vserver->port);
+       
+               snprintf (plugin_instance, sizeof (plugin_instance), "vserver%i",
+                               vserver->port);
+               plugin_instance[sizeof (plugin_instance) - 1] = 0;
+
+               /* Select the server */
+               status = tss2_select_vserver (read_fh, write_fh, vserver);
+               if (status != 0)
+                       return (status);
+
+               status = tss2_send_request (write_fh, "si\r\n");
+       }
+
+       if (status != 0)
+       {
+               ERROR ("teamspeak2 plugin: tss2_send_request failed.");
+               return (-1);
+       }
+
+       /* Loop until break */
+       while (42)
+       {
+               char buffer[4096];
+               char *key;
+               char *value;
+               char *endptr = NULL;
+               
+               /* Read one line of the server's answer */
+               status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
+               if (status != 0)
+               {
+                       /* Set to NULL just to make sure noone uses these FHs anymore. */
+                       read_fh = NULL;
+                       write_fh = NULL;
+                       ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
+                       break;
+               }
+
+               if (strncmp ("ERROR", buffer, 5) == 0)
+               {
+                       ERROR ("teamspeak2 plugin: Server returned an error: %s",
+                                       buffer);
+                       break;
+               }
+               else if (strncmp ("OK", buffer, 2) == 0)
+               {
+                       break;
+               }
+
+               /* Split line into key and value */
+               key = strchr (buffer, '_');
+               if (key == NULL)
+               {
+                       DEBUG ("teamspeak2 plugin: Cannot parse line: %s", buffer);
+                       continue;
+               }
+               key++;
+
+               /* Evaluate assignment */
+               value = strchr (key, '=');
+               if (value == NULL)
+               {
+                       DEBUG ("teamspeak2 plugin: Cannot parse line: %s", buffer);
+                       continue;
+               }
+               *value = 0;
+               value++;
+
+               /* Check for known key and save the given value */
+               if ((strcmp ("currentusers", key) == 0)
+                               || (strcmp ("users_online", key) == 0))
+               {
+                       users = strtod (value, &endptr);
+                       if (value != endptr)
+                               valid |= 0x01;
+               }
+               else if (strcmp ("bytesreceived", key) == 0)
+               {
+                       rx_octets = strtoll (value, &endptr, 0);
+                       if (value != endptr)
+                               valid |= 0x02;
+               }
+               else if (strcmp ("bytessend", key) == 0)
+               {
+                       tx_octets = strtoll (value, &endptr, 0);
+                       if (value != endptr)
+                               valid |= 0x04;
+               }
+               else if (strcmp ("packetsreceived", key) == 0)
+               {
+                       rx_packets = strtoll (value, &endptr, 0);
+                       if (value != endptr)
+                               valid |= 0x08;
+               }
+               else if (strcmp ("packetssend", key) == 0)
+               {
+                       tx_packets = strtoll (value, &endptr, 0);
+                       if (value != endptr)
+                               valid |= 0x10;
+               }
+               else if ((strncmp ("allow_codec_", key, strlen ("allow_codec_")) == 0)
+                               || (strncmp ("bwinlast", key, strlen ("bwinlast")) == 0)
+                               || (strncmp ("bwoutlast", key, strlen ("bwoutlast")) == 0)
+                               || (strncmp ("webpost_", key, strlen ("webpost_")) == 0)
+                               || (strcmp ("adminemail", key) == 0)
+                               || (strcmp ("clan_server", key) == 0)
+                               || (strcmp ("countrynumber", key) == 0)
+                               || (strcmp ("id", key) == 0)
+                               || (strcmp ("ispname", key) == 0)
+                               || (strcmp ("linkurl", key) == 0)
+                               || (strcmp ("maxusers", key) == 0)
+                               || (strcmp ("name", key) == 0)
+                               || (strcmp ("password", key) == 0)
+                               || (strcmp ("platform", key) == 0)
+                               || (strcmp ("server_platform", key) == 0)
+                               || (strcmp ("server_uptime", key) == 0)
+                               || (strcmp ("server_version", key) == 0)
+                               || (strcmp ("udpport", key) == 0)
+                               || (strcmp ("uptime", key) == 0)
+                               || (strcmp ("users_maximal", key) == 0)
+                               || (strcmp ("welcomemessage", key) == 0))
+                       /* ignore */;
+               else
+               {
+                       INFO ("teamspeak2 plugin: Unknown key-value-pair: "
+                                       "key = %s; value = %s;", key, value);
+               }
+       } /* while (42) */
+
+       if ((valid & 0x01) == 0x01)
+               tss2_submit_gauge (plugin_instance, "users", users);
+
+       if ((valid & 0x06) == 0x06)
+               tss2_submit_io (plugin_instance, "io_octets", rx_octets, tx_octets);
+
+       if ((valid & 0x18) == 0x18)
+               tss2_submit_io (plugin_instance, "io_packets", rx_packets, tx_packets);
+
+       if (valid == 0)
+               return (-1);
+       return (0);
+} /* int tss2_read_vserver */
+
+static int tss2_config (const char *key, const char *value)
+{
+       /*
+        * Interpret configuration values
+        */
+    if (strcasecmp ("Host", key) == 0)
+       {
+               char *temp;
+
+               temp = strdup (value);
+               if (temp == NULL)
+               {
+                       ERROR("teamspeak2 plugin: strdup failed.");
+                       return (1);
+               }
+               sfree (config_host);
+               config_host = temp;
+       }
+       else if (strcasecmp ("Port", key) == 0)
+       {
+               char *temp;
+
+               temp = strdup (value);
+               if (temp == NULL)
+               {
+                       ERROR("teamspeak2 plugin: strdup failed.");
+                       return (1);
+               }
+               sfree (config_port);
+               config_port = temp;
+       }
+       else if (strcasecmp ("Server", key) == 0)
+       {
+               /* Server variable found */
+               int status;
+               
+               status = tss2_add_vserver (atoi (value));
+               if (status != 0)
+                       return (1);
+       }
+       else
+       {
+               /* Unknown variable found */
+               return (-1);
+       }
+
+       return 0;
+} /* int tss2_config */
+
+static int tss2_read (void)
+{
+       vserver_list_t *vserver;
+       int success = 0;
+       int status;
+
+       /* Handle global server variables */
+       status = tss2_read_vserver (NULL);
+       if (status == 0)
+       {
+               success++;
+       }
+       else
+       {
+               WARNING ("teamspeak2 plugin: Reading global server variables failed.");
+       }
+
+       for (vserver = server_list; vserver != NULL; vserver = vserver->next)
+       {
+               status = tss2_read_vserver (vserver);
+               if (status == 0)
+               {
+                       success++;
+               }
+               else
+               {
+                       WARNING ("teamspeak2 plugin: Reading statistics "
+                                       "for vserver %i failed.", vserver->port);
+                       continue;
+               }
+       }
+       
+       if (success == 0)
+               return (-1);
+    return (0);
+} /* int tss2_read */
+
+static int tss2_shutdown(void)
+{
+       /*
+        * Shutdown handler
+        */
+       vserver_list_t *entry;
+
+       tss2_close_socket ();
+
+       entry = server_list;
+       server_list = NULL;
+       while (entry != NULL)
+       {
+               vserver_list_t *next;
+
+               next = entry->next;
+               sfree (entry);
+               entry = next;
+       }
+
+       /* Get rid of the configuration */
+       sfree (config_host);
+       sfree (config_port);
+       
+    return (0);
+} /* int tss2_shutdown */
+
+void module_register(void)
+{
+       /*
+        * Mandatory module_register function
+        */
+       plugin_register_config ("teamspeak2", tss2_config,
+                       config_keys, config_keys_num);
+       plugin_register_read ("teamspeak2", tss2_read);
+       plugin_register_shutdown ("teamspeak2", tss2_shutdown);
+} /* void module_register */
+
+/* vim: set sw=4 ts=4 : */
index dad7d45..97c170b 100644 (file)
@@ -40,6 +40,8 @@ if_octets             rx:COUNTER:0:4294967295, tx:COUNTER:0:4294967295
 if_packets             rx:COUNTER:0:4294967295, tx:COUNTER:0:4294967295
 if_rx_errors           value:COUNTER:0:4294967295
 if_tx_errors           value:COUNTER:0:4294967295
+io_octets              rx:COUNTER:0:4294967295, tx:COUNTER:0:4294967295
+io_packets             rx:COUNTER:0:4294967295, tx:COUNTER:0:4294967295
 ipt_bytes              value:COUNTER:0:134217728
 ipt_packets            value:COUNTER:0:134217728
 irq                    value:COUNTER:U:65535
@@ -84,9 +86,9 @@ users                 users:GAUGE:0:65535
 virt_cpu_total         ns:COUNTER:0:256000000000
 virt_vcpu              ns:COUNTER:0:1000000000
 vmpage_action          value:COUNTER:0:4294967295
-vmpage_number          value:GAUGE:0:4294967295
 vmpage_faults          minflt:COUNTER:0:9223372036854775807, majflt:COUNTER:0:9223372036854775807
 vmpage_io              in:COUNTER:0:4294967295, out:COUNTER:0:4294967295
+vmpage_number          value:GAUGE:0:4294967295
 voltage_threshold      value:GAUGE:U:U, threshold:GAUGE:U:U
 voltage                        value:GAUGE:U:U
 vs_memory              value:GAUGE:0:9223372036854775807