Merge branch 'collectd-4.4' into collectd-4.5
[collectd.git] / src / mysql.c
index fccaedb..4e72b5b 100644 (file)
 #include "plugin.h"
 #include "configfile.h"
 
-#ifdef HAVE_MYSQL_MYSQL_H
+#ifdef HAVE_MYSQL_H
+#include <mysql.h>
+#elif defined(HAVE_MYSQL_MYSQL_H)
 #include <mysql/mysql.h>
 #endif
 
-#if COLLECT_LIBMYSQL
-# define MYSQL_HAVE_READ 1
-#else
-# define MYSQL_HAVE_READ 0
-#endif
-
 /* TODO: Understand `Select_*' and possibly do that stuff as well.. */
 
-#if MYSQL_HAVE_READ
 static const char *config_keys[] =
 {
        "Host",
@@ -133,11 +128,12 @@ static void counter_submit (const char *type, const char *type_instance,
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname_g);
-       strcpy (vl.plugin, "mysql");
-       strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
-       plugin_dispatch_values (type, &vl);
+       plugin_dispatch_values (&vl);
 } /* void counter_submit */
 
 static void qcache_submit (counter_t hits, counter_t inserts,
@@ -156,10 +152,11 @@ static void qcache_submit (counter_t hits, counter_t inserts,
        vl.values = values;
        vl.values_len = 5;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname_g);
-       strcpy (vl.plugin, "mysql");
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+       sstrncpy (vl.type, "mysql_qcache", sizeof (vl.type));
 
-       plugin_dispatch_values ("mysql_qcache", &vl);
+       plugin_dispatch_values (&vl);
 } /* void qcache_submit */
 
 static void threads_submit (gauge_t running, gauge_t connected, gauge_t cached,
@@ -176,10 +173,11 @@ static void threads_submit (gauge_t running, gauge_t connected, gauge_t cached,
        vl.values = values;
        vl.values_len = 4;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname_g);
-       strcpy (vl.plugin, "mysql");
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+       sstrncpy (vl.type, "mysql_threads", sizeof (vl.type));
 
-       plugin_dispatch_values ("mysql_threads", &vl);
+       plugin_dispatch_values (&vl);
 } /* void threads_submit */
 
 static void traffic_submit (counter_t rx, counter_t tx)
@@ -193,10 +191,11 @@ static void traffic_submit (counter_t rx, counter_t tx)
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname_g);
-       strcpy (vl.plugin, "mysql");
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+       sstrncpy (vl.type, "mysql_octets", sizeof (vl.type));
 
-       plugin_dispatch_values ("mysql_octets", &vl);
+       plugin_dispatch_values (&vl);
 } /* void traffic_submit */
 
 static int mysql_read (void)
@@ -322,12 +321,9 @@ static int mysql_read (void)
 
        return (0);
 } /* int mysql_read */
-#endif /* MYSQL_HAVE_READ */
 
 void module_register (void)
 {
-#if MYSQL_HAVE_READ
        plugin_register_config ("mysql", config, config_keys, config_keys_num);
        plugin_register_read ("mysql", mysql_read);
-#endif /* MYSQL_HAVE_READ */
 } /* void module_register */