{GPL, other}: Relicense to MIT license.
[collectd.git] / src / teamspeak2.c
index 5cd427a..201e182 100644 (file)
  *
  * Authors:
  *   Stefan Hacker <d0t at dbclan dot de>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
 #include "common.h"
 #include "plugin.h"
 
-#include <arpa/inet.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
@@ -129,7 +129,6 @@ static void tss2_submit_gauge (const char *plugin_instance,
 
        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));
 
@@ -147,7 +146,7 @@ static void tss2_submit_gauge (const char *plugin_instance,
 } /* void tss2_submit_gauge */
 
 static void tss2_submit_io (const char *plugin_instance, const char *type,
-               counter_t rx, counter_t tx)
+               derive_t rx, derive_t tx)
 {
        /*
         * Submits the io rx/tx tuple to the collectd daemon
@@ -155,12 +154,11 @@ static void tss2_submit_io (const char *plugin_instance, const char *type,
        value_t values[2];
        value_list_t vl = VALUE_LIST_INIT;
 
-       values[0].counter = rx;
-       values[1].counter = tx;
+       values[0].derive = rx;
+       values[1].derive = 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));
 
@@ -301,6 +299,13 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
                char *buffer_ptr;
 
                buffer_ptr = fgets (buffer, sizeof (buffer), global_read_fh);
+               if (buffer_ptr == NULL)
+               {
+                       WARNING ("teamspeak2 plugin: Unexpected EOF received "
+                                       "from remote host %s:%s.",
+                                       config_host ? config_host : DEFAULT_HOST,
+                                       config_port ? config_port : DEFAULT_PORT);
+               }
                buffer[sizeof (buffer) - 1] = 0;
 
                if (memcmp ("[TS]\r\n", buffer, 6) != 0)
@@ -408,7 +413,7 @@ static int tss2_select_vserver (FILE *read_fh, FILE *write_fh, vserver_list_t *v
 } /* int tss2_select_vserver */
 
 static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh,
-               vserver_list_t *vserver, gauge_t *ret_value)
+               gauge_t *ret_value)
 {
        /*
         * Reads the vserver's average packet loss and submits it to collectd.
@@ -434,7 +439,7 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh,
                status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
                if (status != 0)
                {
-                       /* Set to NULL just to make sure noone uses these FHs anymore. */
+                       /* Set to NULL just to make sure no one uses these FHs anymore. */
                        read_fh = NULL;
                        write_fh = NULL;
                        ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
@@ -500,10 +505,10 @@ static int tss2_read_vserver (vserver_list_t *vserver)
        gauge_t users = NAN;
        gauge_t channels = NAN;
        gauge_t servers = NAN;
-       counter_t rx_octets = 0;
-       counter_t tx_octets = 0;
-       counter_t rx_packets = 0;
-       counter_t tx_packets = 0;
+       derive_t rx_octets = 0;
+       derive_t tx_octets = 0;
+       derive_t rx_packets = 0;
+       derive_t tx_packets = 0;
        gauge_t packet_loss = NAN;
        int valid = 0;
 
@@ -559,7 +564,7 @@ static int tss2_read_vserver (vserver_list_t *vserver)
                status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
                if (status != 0)
                {
-                       /* Set to NULL just to make sure noone uses these FHs anymore. */
+                       /* Set to NULL just to make sure no one uses these FHs anymore. */
                        read_fh = NULL;
                        write_fh = NULL;
                        ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
@@ -679,7 +684,7 @@ static int tss2_read_vserver (vserver_list_t *vserver)
         * with an error. */
        if ((status == 0) && (vserver != NULL))
        {
-               status = tss2_vserver_gapl (read_fh, write_fh, vserver, &packet_loss);
+               status = tss2_vserver_gapl (read_fh, write_fh, &packet_loss);
                if (status == 0)
                {
                        valid |= 0x20;