src/Makefile.am: Add `postgresql_default.conf' to `EXTRA_DIST'.
[collectd.git] / src / ipmi.c
index 5e4a6ad..b9cfa19 100644 (file)
@@ -22,6 +22,7 @@
 #include "collectd.h"
 #include "common.h"
 #include "plugin.h"
+#include "utils_ignorelist.h"
 
 #include <pthread.h>
 
@@ -52,6 +53,15 @@ static c_ipmi_sensor_list_t *sensor_list = NULL;
 static int c_ipmi_active = 0;
 static pthread_t thread_id = (pthread_t) 0;
 
+static const char *config_keys[] =
+{
+       "Sensor",
+       "IgnoreSelected"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static ignorelist_t *ignorelist = NULL;
+
 /*
  * Misc private functions
  */
@@ -63,7 +73,7 @@ static void c_ipmi_error (const char *func, int status)
 
   if (IPMI_IS_OS_ERR (status))
   {
-    sstrerror_r (IPMI_GET_OS_ERR (status), errbuf, sizeof (errbuf));
+    sstrerror (IPMI_GET_OS_ERR (status), errbuf, sizeof (errbuf));
   }
   else if (IPMI_IS_IPMI_ERR (status))
   {
@@ -114,17 +124,17 @@ static void sensor_read_handler (ipmi_sensor_t *sensor,
   if (err != 0)
   {
     INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
-        "because it failed with status %#x. If you need this sensor, "
-        "please file a bug report.",
+        "because it failed with status %#x.",
         sensor_name_ptr, err);
     sensor_list_remove (sensor);
     return;
   }
 
-  if (value_present != IPMI_RAW_VALUE_PRESENT)
+  if (value_present != IPMI_BOTH_VALUES_PRESENT)
   {
     INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
-        "because it provides %s.",
+        "because it provides %s. If you need this sensor, "
+        "please file a bug report.",
         sensor_name_ptr,
         (value_present == IPMI_RAW_VALUE_PRESENT)
         ? "only the raw value"
@@ -133,6 +143,13 @@ static void sensor_read_handler (ipmi_sensor_t *sensor,
     return;
   }
 
+  /* Both `ignorelist' and `plugin_instance' may be NULL. */
+  if (ignorelist_match (ignorelist, sensor_name_ptr) != 0)
+  {
+    sensor_list_remove (sensor);
+    return;
+  }
+
   /* FIXME: Use rate unit or base unit to scale the value */
 
   sensor_type = ipmi_sensor_get_sensor_type (sensor);
@@ -160,7 +177,8 @@ static void sensor_read_handler (ipmi_sensor_t *sensor,
         
         sensor_type_str = ipmi_sensor_get_sensor_type_string (sensor);
         INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
-            "because I don't know how to handle its type (%#x, %s).",
+            "because I don't know how to handle its type (%#x, %s). "
+            "If you need this sensor, please file a bug report.",
             sensor_name_ptr, sensor_type, sensor_type_str);
         sensor_list_remove (sensor);
         return;
@@ -175,9 +193,10 @@ static void sensor_read_handler (ipmi_sensor_t *sensor,
 
   sstrncpy (vl.host, hostname_g, sizeof (vl.host));
   sstrncpy (vl.plugin, "ipmi", sizeof (vl.plugin));
+  sstrncpy (vl.type, type, sizeof (vl.type));
   sstrncpy (vl.type_instance, sensor_name_ptr, sizeof (vl.type_instance));
 
-  plugin_dispatch_values (type, &vl);
+  plugin_dispatch_values (&vl);
 } /* void sensor_read_handler */
 
 static int sensor_list_add (ipmi_sensor_t *sensor)
@@ -449,6 +468,34 @@ static void *thread_main (void *user_data)
   return ((void *) 0);
 } /* void *thread_main */
 
+static int c_ipmi_config (const char *key, const char *value)
+{
+  if (ignorelist == NULL)
+    ignorelist = ignorelist_create (/* invert = */ 1);
+  if (ignorelist == NULL)
+    return (1);
+
+  if (strcasecmp ("Sensor", key) == 0)
+  {
+    ignorelist_add (ignorelist, value);
+  }
+  else if (strcasecmp ("IgnoreSelected", key) == 0)
+  {
+    int invert = 1;
+    if ((strcasecmp ("True", value) == 0)
+       || (strcasecmp ("Yes", value) == 0)
+       || (strcasecmp ("On", value) == 0))
+      invert = 0;
+    ignorelist_set_invert (ignorelist, invert);
+  }
+  else
+  {
+    return (-1);
+  }
+
+  return (0);
+} /* int c_ipmi_config */
+
 static int c_ipmi_init (void)
 {
   int status;
@@ -498,6 +545,8 @@ static int c_ipmi_shutdown (void)
 
 void module_register (void)
 {
+  plugin_register_config ("ipmi", c_ipmi_config,
+      config_keys, config_keys_num);
   plugin_register_init ("ipmi", c_ipmi_init);
   plugin_register_read ("ipmi", c_ipmi_read);
   plugin_register_shutdown ("ipmi", c_ipmi_shutdown);