netapp plugin: Fix a typo.
[collectd.git] / src / wireless.c
index 1067549..f7ba735 100644 (file)
 #include "common.h"
 #include "plugin.h"
 
-#if defined(KERNEL_LINUX)
-# define WIRELESS_HAVE_READ 1
-#else
-# define WIRELESS_HAVE_READ 0
+#if !KERNEL_LINUX
+# error "No applicable input method."
 #endif
 
 #define WIRELESS_PROC_FILE "/proc/net/wireless"
 
-#if WIRELESS_HAVE_READ
 #if 0
 static double wireless_dbm_to_watt (double dbm)
 {
@@ -58,13 +55,13 @@ static void wireless_submit (const char *plugin_instance, const char *type,
 
        vl.values = values;
        vl.values_len = 1;
-       vl.time = time (NULL);
-       strcpy (vl.host, hostname_g);
-       strcpy (vl.plugin, "wireless");
-       strncpy (vl.plugin_instance, plugin_instance,
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "wireless", sizeof (vl.plugin));
+       sstrncpy (vl.plugin_instance, plugin_instance,
                        sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, type, sizeof (vl.type));
 
-       plugin_dispatch_values (type, &vl);
+       plugin_dispatch_values (&vl);
 } /* void wireless_submit */
 
 #define POWER_MIN -90.0
@@ -131,16 +128,20 @@ static int wireless_read (void)
                        power = 1.0; /* invalid */
                else if ((power >= 0.0) && (power <= 100.0))
                        power = wireless_percent_to_power (power);
-               else if (power > 100.0)
+               else if ((power > 100.0) && (power <= 256.0))
+                       power = power - 256.0;
+               else if (power > 0.0)
                        power = 1.0; /* invalid */
 
                /* noise [dBm] < 0.0 */
-               noise = strtod (fields[3], &endptr);
-               if (fields[3] == endptr)
+               noise = strtod (fields[4], &endptr);
+               if (fields[4] == endptr)
                        noise = 1.0; /* invalid */
                else if ((noise >= 0.0) && (noise <= 100.0))
                        noise = wireless_percent_to_power (noise);
-               else if (noise > 100.0)
+               else if ((noise > 100.0) && (noise <= 256.0))
+                       noise = noise - 256.0;
+               else if (noise > 0.0)
                        noise = 1.0; /* invalid */
 
                wireless_submit (device, "signal_quality", quality);
@@ -160,11 +161,8 @@ static int wireless_read (void)
 
        return (0);
 } /* int wireless_read */
-#endif /* WIRELESS_HAVE_READ */
 
 void module_register (void)
 {
-#if WIRELESS_HAVE_READ
        plugin_register_read ("wireless", wireless_read);
-#endif /* WIRELESS_HAVE_READ */
 } /* void module_register */