Various plugins: Use the IS_TRUE and IS_FALSE macros everywhere.
[collectd.git] / src / ipmi.c
index 95f32bc..95b3dbf 100644 (file)
@@ -1,7 +1,8 @@
 /**
  * collectd - src/ipmi.c
- * Copyright (C) 2008  Florian octo Forster
- * Copyright (C) 2008  Peter Holik
+ * Copyright (C) 2008-2009  Florian octo Forster
+ * Copyright (C) 2008       Peter Holik
+ * Copyright (C) 2009       Bruno PrĂ©mont
  *
  * 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
@@ -19,6 +20,7 @@
  * Authors:
  *   Florian octo Forster <octo at verplant.org>
  *   Peter Holik <peter at holik.at>
+ *   Bruno PrĂ©mont <bonbons at linux-vserver.org>
  **/
 
 #include "collectd.h"
@@ -111,9 +113,9 @@ static int sensor_list_remove (ipmi_sensor_t *sensor);
 static void sensor_read_handler (ipmi_sensor_t *sensor,
     int err,
     enum ipmi_value_present_e value_present,
-    unsigned int raw_value,
+    unsigned int __attribute__((unused)) raw_value,
     double value,
-    ipmi_states_t *states,
+    ipmi_states_t __attribute__((unused)) *states,
     void *user_data)
 {
   value_t values[1];
@@ -148,11 +150,33 @@ static void sensor_read_handler (ipmi_sensor_t *sensor,
         }
       }
     }
+    else if (IPMI_IS_IPMI_ERR(err) && IPMI_GET_IPMI_ERR(err) == IPMI_NOT_SUPPORTED_IN_PRESENT_STATE_CC)
+    {
+      INFO ("ipmi plugin: sensor_read_handler: Sensor %s not ready",
+          list_item->sensor_name);
+    }
     else
     {
-      INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
-          "because it failed with status %#x.",
-          list_item->sensor_name, err);
+      if (IPMI_IS_IPMI_ERR(err))
+        INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
+            "because it failed with IPMI error %#x.",
+            list_item->sensor_name, IPMI_GET_IPMI_ERR(err));
+      else if (IPMI_IS_OS_ERR(err))
+        INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
+            "because it failed with OS error %#x.",
+            list_item->sensor_name, IPMI_GET_OS_ERR(err));
+      else if (IPMI_IS_RMCPP_ERR(err))
+        INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
+            "because it failed with RMCPP error %#x.",
+            list_item->sensor_name, IPMI_GET_RMCPP_ERR(err));
+      else if (IPMI_IS_SOL_ERR(err))
+        INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
+            "because it failed with RMCPP error %#x.",
+            list_item->sensor_name, IPMI_GET_SOL_ERR(err));
+      else
+        INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
+            "because it failed with error %#x. of class %#x",
+            list_item->sensor_name, err & 0xff, err & 0xffffff00);
       sensor_list_remove (sensor);
     }
     return;
@@ -197,7 +221,6 @@ static void sensor_read_handler (ipmi_sensor_t *sensor,
 
   vl.values = values;
   vl.values_len = 1;
-  vl.time = time (NULL);
 
   sstrncpy (vl.host, hostname_g, sizeof (vl.host));
   sstrncpy (vl.plugin, "ipmi", sizeof (vl.plugin));
@@ -457,9 +480,9 @@ static int sensor_list_remove_all (void)
  * Entity handlers
  */
 static void entity_sensor_update_handler (enum ipmi_update_e op,
-    ipmi_entity_t *entity,
+    ipmi_entity_t __attribute__((unused)) *entity,
     ipmi_sensor_t *sensor,
-    void *user_data)
+    void __attribute__((unused)) *user_data)
 {
   /* TODO: Ignore sensors we cannot read */
 
@@ -478,9 +501,9 @@ static void entity_sensor_update_handler (enum ipmi_update_e op,
  * Domain handlers
  */
 static void domain_entity_update_handler (enum ipmi_update_e op,
-    ipmi_domain_t *domain,
+    ipmi_domain_t __attribute__((unused)) *domain,
     ipmi_entity_t *entity,
-    void *user_data)
+    void __attribute__((unused)) *user_data)
 {
   int status;
 
@@ -572,7 +595,7 @@ static int thread_init (os_handler_t **ret_os_handler)
   return (0);
 } /* int thread_init */
 
-static void *thread_main (void *user_data)
+static void *thread_main (void __attribute__((unused)) *user_data)
 {
   int status;
   os_handler_t *os_handler = NULL;
@@ -609,31 +632,23 @@ static int c_ipmi_config (const char *key, const char *value)
   else if (strcasecmp ("IgnoreSelected", key) == 0)
   {
     int invert = 1;
-    if ((strcasecmp ("True", value) == 0)
-        || (strcasecmp ("Yes", value) == 0)
-        || (strcasecmp ("On", value) == 0))
+    if (IS_TRUE (value))
       invert = 0;
     ignorelist_set_invert (ignorelist, invert);
   }
   else if (strcasecmp ("NotifySensorAdd", key) == 0)
   {
-    if ((strcasecmp ("True", value) == 0)
-        || (strcasecmp ("Yes", value) == 0)
-        || (strcasecmp ("On", value) == 0))
+    if (IS_TRUE (value))
       c_ipmi_nofiy_add = 1;
   }
   else if (strcasecmp ("NotifySensorRemove", key) == 0)
   {
-    if ((strcasecmp ("True", value) == 0)
-        || (strcasecmp ("Yes", value) == 0)
-        || (strcasecmp ("On", value) == 0))
+    if (IS_TRUE (value))
       c_ipmi_nofiy_remove = 1;
   }
   else if (strcasecmp ("NotifySensorNotPresent", key) == 0)
   {
-    if ((strcasecmp ("True", value) == 0)
-        || (strcasecmp ("Yes", value) == 0)
-        || (strcasecmp ("On", value) == 0))
+    if (IS_TRUE (value))
       c_ipmi_nofiy_notpresent = 1;
   }
   else