Merge remote-tracking branch 'github/pr/2091'
[collectd.git] / src / ipmi.c
index ad62299..87f8b44 100644 (file)
 #include "plugin.h"
 #include "utils_ignorelist.h"
 
-#include <OpenIPMI/ipmiif.h>
+#include <OpenIPMI/ipmi_conn.h>
 #include <OpenIPMI/ipmi_err.h>
 #include <OpenIPMI/ipmi_posix.h>
-#include <OpenIPMI/ipmi_conn.h>
 #include <OpenIPMI/ipmi_smi.h>
+#include <OpenIPMI/ipmiif.h>
 
 /*
  * Private data types
@@ -41,8 +41,7 @@
 struct c_ipmi_sensor_list_s;
 typedef struct c_ipmi_sensor_list_s c_ipmi_sensor_list_t;
 
-struct c_ipmi_sensor_list_s
-{
+struct c_ipmi_sensor_list_s {
   ipmi_sensor_id_t sensor_id;
   char sensor_name[DATA_MAX_NAME_LEN];
   char sensor_type[DATA_MAX_NAME_LEN];
@@ -58,347 +57,321 @@ static c_ipmi_sensor_list_t *sensor_list = NULL;
 
 static int c_ipmi_init_in_progress = 0;
 static int c_ipmi_active = 0;
-static pthread_t thread_id = (pthread_t) 0;
-
-static const char *config_keys[] =
-{
-       "Sensor",
-       "IgnoreSelected",
-       "NotifySensorAdd",
-       "NotifySensorRemove",
-       "NotifySensorNotPresent"
-};
-static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+static pthread_t thread_id = (pthread_t)0;
+
+static const char *config_keys[] = {"Sensor",
+                                    "IgnoreSelected",
+                                    "NotifySensorAdd",
+                                    "NotifySensorRemove",
+                                    "NotifySensorNotPresent",
+                                    "SELEnabled",
+                                    "SELClearEvent"};
+static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
 
 static ignorelist_t *ignorelist = NULL;
 
-static int c_ipmi_nofiy_add = 0;
-static int c_ipmi_nofiy_remove = 0;
-static int c_ipmi_nofiy_notpresent = 0;
+static _Bool c_ipmi_notify_add = 0;
+static _Bool c_ipmi_notify_remove = 0;
+static _Bool c_ipmi_notify_notpresent = 0;
+static _Bool c_ipmi_sel_enabled = 0;
+static _Bool c_ipmi_sel_clear_event = 0;
 
 /*
  * Misc private functions
  */
-static void c_ipmi_error (const char *func, int status)
-{
-  char errbuf[4096] = { 0 };
+static void c_ipmi_error(const char *func, int status) {
+  char errbuf[4096] = {0};
 
-  if (IPMI_IS_OS_ERR (status))
-  {
-    sstrerror (IPMI_GET_OS_ERR (status), errbuf, sizeof (errbuf));
-  }
-  else if (IPMI_IS_IPMI_ERR (status))
-  {
-    ipmi_get_error_string (IPMI_GET_IPMI_ERR (status), errbuf, sizeof (errbuf));
+  if (IPMI_IS_OS_ERR(status)) {
+    sstrerror(IPMI_GET_OS_ERR(status), errbuf, sizeof(errbuf));
+  } else if (IPMI_IS_IPMI_ERR(status)) {
+    ipmi_get_error_string(IPMI_GET_IPMI_ERR(status), errbuf, sizeof(errbuf));
   }
 
-  if (errbuf[0] == 0)
-  {
-    ssnprintf (errbuf, sizeof (errbuf), "Unknown error %#x", status);
+  if (errbuf[0] == 0) {
+    snprintf(errbuf, sizeof(errbuf), "Unknown error %#x", status);
   }
-  errbuf[sizeof (errbuf) - 1] = 0;
+  errbuf[sizeof(errbuf) - 1] = 0;
 
-  ERROR ("ipmi plugin: %s failed: %s", func, errbuf);
+  ERROR("ipmi plugin: %s failed: %s", func, errbuf);
 } /* void c_ipmi_error */
 
 /*
  * Sensor handlers
  */
 /* Prototype for sensor_list_remove, so sensor_read_handler can call it. */
-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 __attribute__((unused)) raw_value,
-    double value,
-    ipmi_states_t __attribute__((unused)) *states,
-    void *user_data)
-{
-  value_t values[1];
+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 __attribute__((unused)) raw_value,
+                                double value,
+                                ipmi_states_t __attribute__((unused)) * states,
+                                void *user_data) {
   value_list_t vl = VALUE_LIST_INIT;
 
   c_ipmi_sensor_list_t *list_item = (c_ipmi_sensor_list_t *)user_data;
 
-  if (err != 0)
-  {
-    if ((err & 0xff) == IPMI_NOT_PRESENT_CC)
-    {
-      if (list_item->sensor_not_present == 0)
-      {
+  if (err != 0) {
+    if ((err & 0xff) == IPMI_NOT_PRESENT_CC) {
+      if (list_item->sensor_not_present == 0) {
         list_item->sensor_not_present = 1;
 
-        INFO ("ipmi plugin: sensor_read_handler: sensor %s "
-            "not present.", list_item->sensor_name);
+        INFO("ipmi plugin: sensor_read_handler: sensor %s "
+             "not present.",
+             list_item->sensor_name);
 
-        if (c_ipmi_nofiy_notpresent)
-        {
-          notification_t n = { NOTIF_WARNING, cdtime (), "", "", "ipmi",
-            "", "", "", NULL };
+        if (c_ipmi_notify_notpresent) {
+          notification_t n = {
+              NOTIF_WARNING, cdtime(), "", "", "ipmi", "", "", "", NULL};
 
-          sstrncpy (n.host, hostname_g, sizeof (n.host));
-          sstrncpy (n.type_instance, list_item->sensor_name,
-              sizeof (n.type_instance));
-          sstrncpy (n.type, list_item->sensor_type, sizeof (n.type));
-          ssnprintf (n.message, sizeof (n.message),
-              "sensor %s not present", list_item->sensor_name);
+          sstrncpy(n.host, hostname_g, sizeof(n.host));
+          sstrncpy(n.type_instance, list_item->sensor_name,
+                   sizeof(n.type_instance));
+          sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
+          snprintf(n.message, sizeof(n.message), "sensor %s not present",
+                   list_item->sensor_name);
 
-          plugin_dispatch_notification (&n);
+          plugin_dispatch_notification(&n);
         }
       }
-    }
-    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
-    {
+    } 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 {
       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));
+        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));
+        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));
+        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));
+        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);
+        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;
-  }
-  else if (list_item->sensor_not_present == 1)
-  {
+  } else if (list_item->sensor_not_present == 1) {
     list_item->sensor_not_present = 0;
 
-    INFO ("ipmi plugin: sensor_read_handler: sensor %s present.",
-        list_item->sensor_name);
+    INFO("ipmi plugin: sensor_read_handler: sensor %s present.",
+         list_item->sensor_name);
 
-    if (c_ipmi_nofiy_notpresent)
-    {
-      notification_t n = { NOTIF_OKAY, cdtime (), "", "", "ipmi",
-        "", "", "", NULL };
+    if (c_ipmi_notify_notpresent) {
+      notification_t n = {NOTIF_OKAY, cdtime(), "", "",  "ipmi",
+                          "",         "",       "", NULL};
 
-      sstrncpy (n.host, hostname_g, sizeof (n.host));
-      sstrncpy (n.type_instance, list_item->sensor_name,
-          sizeof (n.type_instance));
-      sstrncpy (n.type, list_item->sensor_type, sizeof (n.type));
-      ssnprintf (n.message, sizeof (n.message),
-          "sensor %s present", list_item->sensor_name);
+      sstrncpy(n.host, hostname_g, sizeof(n.host));
+      sstrncpy(n.type_instance, list_item->sensor_name,
+               sizeof(n.type_instance));
+      sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
+      snprintf(n.message, sizeof(n.message), "sensor %s present",
+               list_item->sensor_name);
 
-      plugin_dispatch_notification (&n);
+      plugin_dispatch_notification(&n);
     }
   }
 
-  if (value_present != IPMI_BOTH_VALUES_PRESENT)
-  {
-    INFO ("ipmi plugin: sensor_read_handler: Removing sensor %s, "
-        "because it provides %s. If you need this sensor, "
-        "please file a bug report.",
-        list_item->sensor_name,
-        (value_present == IPMI_RAW_VALUE_PRESENT)
-        ? "only the raw value"
-        : "no value");
-    sensor_list_remove (sensor);
+  if (value_present != IPMI_BOTH_VALUES_PRESENT) {
+    INFO("ipmi plugin: sensor_read_handler: Removing sensor %s, "
+         "because it provides %s. If you need this sensor, "
+         "please file a bug report.",
+         list_item->sensor_name,
+         (value_present == IPMI_RAW_VALUE_PRESENT) ? "only the raw value"
+                                                   : "no value");
+    sensor_list_remove(sensor);
     return;
   }
 
-  values[0].gauge = value;
-
-  vl.values = values;
+  vl.values = &(value_t){.gauge = value};
   vl.values_len = 1;
 
-  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
-  sstrncpy (vl.plugin, "ipmi", sizeof (vl.plugin));
-  sstrncpy (vl.type, list_item->sensor_type, sizeof (vl.type));
-  sstrncpy (vl.type_instance, list_item->sensor_name, sizeof (vl.type_instance));
+  sstrncpy(vl.plugin, "ipmi", sizeof(vl.plugin));
+  sstrncpy(vl.type, list_item->sensor_type, sizeof(vl.type));
+  sstrncpy(vl.type_instance, list_item->sensor_name, sizeof(vl.type_instance));
 
-  plugin_dispatch_values (&vl);
+  plugin_dispatch_values(&vl);
 } /* void sensor_read_handler */
 
-static int sensor_list_add (ipmi_sensor_t *sensor)
-{
-  ipmi_sensor_id_t sensor_id;
-  c_ipmi_sensor_list_t *list_item;
-  c_ipmi_sensor_list_t *list_prev;
-
-  char buffer[DATA_MAX_NAME_LEN] = { 0 };
-  const char *entity_id_string;
-  char sensor_name[DATA_MAX_NAME_LEN];
-  char *sensor_name_ptr;
-  int sensor_type;
-  const char *type;
+static void sensor_get_name(ipmi_sensor_t *sensor, char *buffer, int buf_len) {
+  char temp[DATA_MAX_NAME_LEN] = {0};
   ipmi_entity_t *ent = ipmi_sensor_get_entity(sensor);
+  const char *entity_id_string = ipmi_entity_get_entity_id_string(ent);
+  char sensor_name[DATA_MAX_NAME_LEN] = "";
+  char *sensor_name_ptr;
 
-  sensor_id = ipmi_sensor_convert_to_id (sensor);
-
-  ipmi_sensor_get_name (sensor, buffer, sizeof (buffer));
-  buffer[sizeof (buffer) - 1] = 0;
+  if ((buffer == NULL) || (buf_len == 0))
+    return;
 
-  entity_id_string = ipmi_entity_get_entity_id_string (ent);
+  ipmi_sensor_get_name(sensor, temp, sizeof(temp));
+  temp[sizeof(temp) - 1] = 0;
 
-  if (entity_id_string == NULL)
-    sstrncpy (sensor_name, buffer, sizeof (sensor_name));
+  if (entity_id_string != NULL && strlen(temp))
+    snprintf(sensor_name, sizeof(sensor_name), "%s %s", temp, entity_id_string);
+  else if (entity_id_string != NULL)
+    sstrncpy(sensor_name, entity_id_string, sizeof(sensor_name));
   else
-    ssnprintf (sensor_name, sizeof (sensor_name),
-        "%s %s", buffer, entity_id_string);
-
-  sstrncpy (buffer, sensor_name, sizeof (buffer));
-  sensor_name_ptr = strstr (buffer, ").");
-  if (sensor_name_ptr != NULL)
-  {
-    /* If name is something like "foo (123).bar",
-     * change that to "bar (123)".
-     * Both, sensor_name_ptr and sensor_id_ptr point to memory within the
-     * `buffer' array, which holds a copy of the current `sensor_name'. */
-    char *sensor_id_ptr;
-
-    /* `sensor_name_ptr' points to ").bar". */
-    sensor_name_ptr[1] = 0;
-    /* `buffer' holds "foo (123)\0bar\0". */
-    sensor_name_ptr += 2;
-    /* `sensor_name_ptr' now points to "bar". */
-
-    sensor_id_ptr = strstr (buffer, "(");
-    if (sensor_id_ptr != NULL)
-    {
-      /* `sensor_id_ptr' now points to "(123)". */
-      ssnprintf (sensor_name, sizeof (sensor_name),
-          "%s %s", sensor_name_ptr, sensor_id_ptr);
+    sstrncpy(sensor_name, temp, sizeof(sensor_name));
+
+  if (strlen(temp)) {
+    sstrncpy(temp, sensor_name, sizeof(temp));
+    sensor_name_ptr = strstr(temp, ").");
+    if (sensor_name_ptr != NULL) {
+      /* If name is something like "foo (123).bar",
+       * change that to "bar (123)".
+       * Both, sensor_name_ptr and sensor_id_ptr point to memory within the
+       * `temp' array, which holds a copy of the current `sensor_name'. */
+      char *sensor_id_ptr;
+
+      /* `sensor_name_ptr' points to ").bar". */
+      sensor_name_ptr[1] = 0;
+      /* `temp' holds "foo (123)\0bar\0". */
+      sensor_name_ptr += 2;
+      /* `sensor_name_ptr' now points to "bar". */
+
+      sensor_id_ptr = strstr(temp, "(");
+      if (sensor_id_ptr != NULL) {
+        /* `sensor_id_ptr' now points to "(123)". */
+        snprintf(sensor_name, sizeof(sensor_name), "%s %s", sensor_name_ptr,
+                 sensor_id_ptr);
+      }
+      /* else: don't touch sensor_name. */
     }
-    /* else: don't touch sensor_name. */
   }
-  sensor_name_ptr = sensor_name;
-
-  /* Both `ignorelist' and `plugin_instance' may be NULL. */
-  if (ignorelist_match (ignorelist, sensor_name_ptr) != 0)
-    return (0);
+  sstrncpy(buffer, sensor_name, buf_len);
+}
 
-  /* FIXME: Use rate unit or base unit to scale the value */
-
-  sensor_type = ipmi_sensor_get_sensor_type (sensor);
-  switch (sensor_type)
-  {
-    case IPMI_SENSOR_TYPE_TEMPERATURE:
-      type = "temperature";
-      break;
+static int sensor_list_add(ipmi_sensor_t *sensor) {
+  ipmi_sensor_id_t sensor_id;
+  c_ipmi_sensor_list_t *list_item;
+  c_ipmi_sensor_list_t *list_prev;
 
-    case IPMI_SENSOR_TYPE_VOLTAGE:
-      type = "voltage";
-      break;
+  char buffer[DATA_MAX_NAME_LEN] = {0};
+  char *sensor_name_ptr = buffer;
+  int sensor_type;
+  const char *type;
 
-    case IPMI_SENSOR_TYPE_CURRENT:
-      type = "current";
-      break;
+  sensor_id = ipmi_sensor_convert_to_id(sensor);
+  sensor_get_name(sensor, buffer, sizeof(buffer));
 
-    case IPMI_SENSOR_TYPE_FAN:
-      type = "fanspeed";
-      break;
+  /* Both `ignorelist' and `plugin_instance' may be NULL. */
+  if (ignorelist_match(ignorelist, sensor_name_ptr) != 0)
+    return 0;
 
-    default:
-      {
-        const char *sensor_type_str;
+  /* FIXME: Use rate unit or base unit to scale the value */
 
-        sensor_type_str = ipmi_sensor_get_sensor_type_string (sensor);
-        INFO ("ipmi plugin: sensor_list_add: Ignore sensor %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);
-        return (-1);
-      }
+  sensor_type = ipmi_sensor_get_sensor_type(sensor);
+  switch (sensor_type) {
+  case IPMI_SENSOR_TYPE_TEMPERATURE:
+    type = "temperature";
+    break;
+
+  case IPMI_SENSOR_TYPE_VOLTAGE:
+    type = "voltage";
+    break;
+
+  case IPMI_SENSOR_TYPE_CURRENT:
+    type = "current";
+    break;
+
+  case IPMI_SENSOR_TYPE_FAN:
+    type = "fanspeed";
+    break;
+
+  default: {
+    const char *sensor_type_str;
+
+    sensor_type_str = ipmi_sensor_get_sensor_type_string(sensor);
+    INFO("ipmi plugin: sensor_list_add: Ignore sensor %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);
+    return -1;
+  }
   } /* switch (sensor_type) */
 
-  pthread_mutex_lock (&sensor_list_lock);
+  pthread_mutex_lock(&sensor_list_lock);
 
   list_prev = NULL;
-  for (list_item = sensor_list;
-      list_item != NULL;
-      list_item = list_item->next)
-  {
-    if (ipmi_cmp_sensor_id (sensor_id, list_item->sensor_id) == 0)
+  for (list_item = sensor_list; list_item != NULL;
+       list_item = list_item->next) {
+    if (ipmi_cmp_sensor_id(sensor_id, list_item->sensor_id) == 0)
       break;
     list_prev = list_item;
   } /* for (list_item) */
 
-  if (list_item != NULL)
-  {
-    pthread_mutex_unlock (&sensor_list_lock);
-    return (0);
+  if (list_item != NULL) {
+    pthread_mutex_unlock(&sensor_list_lock);
+    return 0;
   }
 
-  list_item = (c_ipmi_sensor_list_t *) calloc (1, sizeof (c_ipmi_sensor_list_t));
-  if (list_item == NULL)
-  {
-    pthread_mutex_unlock (&sensor_list_lock);
-    return (-1);
+  list_item = (c_ipmi_sensor_list_t *)calloc(1, sizeof(c_ipmi_sensor_list_t));
+  if (list_item == NULL) {
+    pthread_mutex_unlock(&sensor_list_lock);
+    return -1;
   }
 
-  list_item->sensor_id = ipmi_sensor_convert_to_id (sensor);
+  list_item->sensor_id = ipmi_sensor_convert_to_id(sensor);
 
   if (list_prev != NULL)
     list_prev->next = list_item;
   else
     sensor_list = list_item;
 
-  sstrncpy (list_item->sensor_name, sensor_name_ptr,
-            sizeof (list_item->sensor_name));
-  sstrncpy (list_item->sensor_type, type, sizeof (list_item->sensor_type));
+  sstrncpy(list_item->sensor_name, sensor_name_ptr,
+           sizeof(list_item->sensor_name));
+  sstrncpy(list_item->sensor_type, type, sizeof(list_item->sensor_type));
 
-  pthread_mutex_unlock (&sensor_list_lock);
+  pthread_mutex_unlock(&sensor_list_lock);
 
-  if (c_ipmi_nofiy_add && (c_ipmi_init_in_progress == 0))
-  {
-    notification_t n = { NOTIF_OKAY, cdtime (), "", "", "ipmi",
-                         "", "", "", NULL };
+  if (c_ipmi_notify_add && (c_ipmi_init_in_progress == 0)) {
+    notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi", "", "", "", NULL};
 
-    sstrncpy (n.host, hostname_g, sizeof (n.host));
-    sstrncpy (n.type_instance, list_item->sensor_name,
-              sizeof (n.type_instance));
-    sstrncpy (n.type, list_item->sensor_type, sizeof (n.type));
-    ssnprintf (n.message, sizeof (n.message),
-              "sensor %s added", list_item->sensor_name);
+    sstrncpy(n.host, hostname_g, sizeof(n.host));
+    sstrncpy(n.type_instance, list_item->sensor_name, sizeof(n.type_instance));
+    sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
+    snprintf(n.message, sizeof(n.message), "sensor %s added",
+             list_item->sensor_name);
 
-    plugin_dispatch_notification (&n);
+    plugin_dispatch_notification(&n);
   }
 
-  return (0);
+  return 0;
 } /* int sensor_list_add */
 
-static int sensor_list_remove (ipmi_sensor_t *sensor)
-{
+static int sensor_list_remove(ipmi_sensor_t *sensor) {
   ipmi_sensor_id_t sensor_id;
   c_ipmi_sensor_list_t *list_item;
   c_ipmi_sensor_list_t *list_prev;
 
-  sensor_id = ipmi_sensor_convert_to_id (sensor);
+  sensor_id = ipmi_sensor_convert_to_id(sensor);
 
-  pthread_mutex_lock (&sensor_list_lock);
+  pthread_mutex_lock(&sensor_list_lock);
 
   list_prev = NULL;
-  for (list_item = sensor_list;
-      list_item != NULL;
-      list_item = list_item->next)
-  {
-    if (ipmi_cmp_sensor_id (sensor_id, list_item->sensor_id) == 0)
+  for (list_item = sensor_list; list_item != NULL;
+       list_item = list_item->next) {
+    if (ipmi_cmp_sensor_id(sensor_id, list_item->sensor_id) == 0)
       break;
     list_prev = list_item;
   } /* for (list_item) */
 
-  if (list_item == NULL)
-  {
-    pthread_mutex_unlock (&sensor_list_lock);
-    return (-1);
+  if (list_item == NULL) {
+    pthread_mutex_unlock(&sensor_list_lock);
+    return -1;
   }
 
   if (list_prev == NULL)
@@ -409,315 +382,466 @@ static int sensor_list_remove (ipmi_sensor_t *sensor)
   list_prev = NULL;
   list_item->next = NULL;
 
-  pthread_mutex_unlock (&sensor_list_lock);
+  pthread_mutex_unlock(&sensor_list_lock);
 
-  if (c_ipmi_nofiy_remove && c_ipmi_active)
-  {
-    notification_t n = { NOTIF_WARNING, cdtime (), "", "",
-                         "ipmi", "", "", "", NULL };
+  if (c_ipmi_notify_remove && c_ipmi_active) {
+    notification_t n = {NOTIF_WARNING, cdtime(), "", "", "ipmi", "", "", "",
+                        NULL};
 
-    sstrncpy (n.host, hostname_g, sizeof (n.host));
-    sstrncpy (n.type_instance, list_item->sensor_name,
-              sizeof (n.type_instance));
-    sstrncpy (n.type, list_item->sensor_type, sizeof (n.type));
-    ssnprintf (n.message, sizeof (n.message),
-              "sensor %s removed", list_item->sensor_name);
+    sstrncpy(n.host, hostname_g, sizeof(n.host));
+    sstrncpy(n.type_instance, list_item->sensor_name, sizeof(n.type_instance));
+    sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
+    snprintf(n.message, sizeof(n.message), "sensor %s removed",
+             list_item->sensor_name);
 
-    plugin_dispatch_notification (&n);
+    plugin_dispatch_notification(&n);
   }
 
-  free (list_item);
-  return (0);
+  free(list_item);
+  return 0;
 } /* int sensor_list_remove */
 
-static int sensor_list_read_all (void)
-{
-  pthread_mutex_lock (&sensor_list_lock);
+static int sensor_list_read_all(void) {
+  pthread_mutex_lock(&sensor_list_lock);
 
-  for (c_ipmi_sensor_list_t *list_item = sensor_list;
-      list_item != NULL;
-      list_item = list_item->next)
-  {
-    ipmi_sensor_id_get_reading (list_item->sensor_id,
-        sensor_read_handler, /* user data = */ list_item);
+  for (c_ipmi_sensor_list_t *list_item = sensor_list; list_item != NULL;
+       list_item = list_item->next) {
+    ipmi_sensor_id_get_reading(list_item->sensor_id, sensor_read_handler,
+                               /* user data = */ list_item);
   } /* for (list_item) */
 
-  pthread_mutex_unlock (&sensor_list_lock);
+  pthread_mutex_unlock(&sensor_list_lock);
 
-  return (0);
+  return 0;
 } /* int sensor_list_read_all */
 
-static int sensor_list_remove_all (void)
-{
+static int sensor_list_remove_all(void) {
   c_ipmi_sensor_list_t *list_item;
 
-  pthread_mutex_lock (&sensor_list_lock);
+  pthread_mutex_lock(&sensor_list_lock);
 
   list_item = sensor_list;
   sensor_list = NULL;
 
-  pthread_mutex_unlock (&sensor_list_lock);
+  pthread_mutex_unlock(&sensor_list_lock);
 
-  while (list_item != NULL)
-  {
+  while (list_item != NULL) {
     c_ipmi_sensor_list_t *list_next = list_item->next;
 
-    free (list_item);
+    free(list_item);
 
     list_item = list_next;
   } /* while (list_item) */
 
-  return (0);
+  return 0;
 } /* int sensor_list_remove_all */
 
+static int sensor_convert_threshold_severity(enum ipmi_thresh_e severity) {
+  switch (severity) {
+  case IPMI_LOWER_NON_CRITICAL:
+  case IPMI_UPPER_NON_CRITICAL:
+    return NOTIF_OKAY;
+  case IPMI_LOWER_CRITICAL:
+  case IPMI_UPPER_CRITICAL:
+    return NOTIF_WARNING;
+  case IPMI_LOWER_NON_RECOVERABLE:
+  case IPMI_UPPER_NON_RECOVERABLE:
+    return NOTIF_FAILURE;
+  default:
+    return NOTIF_OKAY;
+  } /* switch (severity) */
+} /* int sensor_convert_threshold_severity */
+
+static void add_event_common_data(notification_t *n, ipmi_sensor_t *sensor,
+                                  enum ipmi_event_dir_e dir,
+                                  ipmi_event_t *event) {
+  ipmi_entity_t *ent = ipmi_sensor_get_entity(sensor);
+
+  plugin_notification_meta_add_string(n, "entity_name",
+                                      ipmi_entity_get_entity_id_string(ent));
+  plugin_notification_meta_add_signed_int(n, "entity_id",
+                                          ipmi_entity_get_entity_id(ent));
+  plugin_notification_meta_add_signed_int(n, "entity_instance",
+                                          ipmi_entity_get_entity_instance(ent));
+  plugin_notification_meta_add_boolean(n, "assert", dir == IPMI_ASSERTION);
+
+  if (event)
+    plugin_notification_meta_add_signed_int(n, "event_type",
+                                            ipmi_event_get_type(event));
+} /* void add_event_sensor_meta_data */
+
+static int sensor_threshold_event_handler(
+    ipmi_sensor_t *sensor, enum ipmi_event_dir_e dir,
+    enum ipmi_thresh_e threshold, enum ipmi_event_value_dir_e high_low,
+    enum ipmi_value_present_e value_present, unsigned int raw_value,
+    double value, void *cb_data, ipmi_event_t *event) {
+
+  /* From the IPMI specification Chapter 2: Events.
+   * If a callback handles the event, then all future callbacks called due to
+   * the event will receive a NULL for the event. So be ready to handle a NULL
+   * event in all your event handlers. A NULL may also be passed to an event
+   * handler if the callback was not due to an event. */
+  if (event == NULL)
+    return IPMI_EVENT_NOT_HANDLED;
+
+  /* offset is a table index and it's represented as enum of strings that are
+     organized in the way - high and low for each threshold severity level */
+  notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi", "", "", "", NULL};
+  unsigned int offset = (2 * threshold) + high_low;
+  unsigned int event_type = ipmi_sensor_get_event_reading_type(sensor);
+  unsigned int sensor_type = ipmi_sensor_get_sensor_type(sensor);
+  const char *event_state =
+      ipmi_get_reading_name(event_type, sensor_type, offset);
+  sensor_get_name(sensor, n.type_instance, sizeof(n.type_instance));
+  if (value_present != IPMI_NO_VALUES_PRESENT)
+    snprintf(n.message, sizeof(n.message),
+             "sensor %s received event: %s, value is %f", n.type_instance,
+             event_state, value);
+  else
+    snprintf(n.message, sizeof(n.message),
+             "sensor %s received event: %s, value not provided",
+             n.type_instance, event_state);
+
+  DEBUG("Threshold event received for sensor %s", n.type_instance);
+
+  sstrncpy(n.host, hostname_g, sizeof(n.host));
+  sstrncpy(n.type, ipmi_sensor_get_sensor_type_string(sensor), sizeof(n.type));
+  n.severity = sensor_convert_threshold_severity(threshold);
+  n.time = NS_TO_CDTIME_T(ipmi_event_get_timestamp(event));
+
+  plugin_notification_meta_add_string(&n, "severity",
+                                      ipmi_get_threshold_string(threshold));
+  plugin_notification_meta_add_string(&n, "direction",
+                                      ipmi_get_value_dir_string(high_low));
+
+  switch (value_present) {
+  case IPMI_BOTH_VALUES_PRESENT:
+    plugin_notification_meta_add_double(&n, "val", value);
+  /* both values present, so fall-through to add raw value too */
+  case IPMI_RAW_VALUE_PRESENT: {
+    char buf[DATA_MAX_NAME_LEN] = {0};
+    snprintf(buf, sizeof(buf), "0x%2.2x", raw_value);
+    plugin_notification_meta_add_string(&n, "raw", buf);
+  } break;
+  default:
+    break;
+  } /* switch (value_present) */
+
+  add_event_common_data(&n, sensor, dir, event);
+
+  plugin_dispatch_notification(&n);
+  plugin_notification_meta_free(n.meta);
+
+  /* Delete handled ipmi event from the list */
+  if (c_ipmi_sel_clear_event) {
+    ipmi_event_delete(event, NULL, NULL);
+    return IPMI_EVENT_HANDLED;
+  }
+
+  return IPMI_EVENT_NOT_HANDLED;
+} /* int sensor_threshold_event_handler */
+
+static int sensor_discrete_event_handler(ipmi_sensor_t *sensor,
+                                         enum ipmi_event_dir_e dir, int offset,
+                                         int severity, int prev_severity,
+                                         void *cb_data, ipmi_event_t *event) {
+  /* From the IPMI specification Chapter 2: Events.
+   * If a callback handles the event, then all future callbacks called due to
+   * the event will receive a NULL for the event. So be ready to handle a NULL
+   * event in all your event handlers. A NULL may also be passed to an event
+   * handler if the callback was not due to an event. */
+  if (event == NULL)
+    return IPMI_EVENT_NOT_HANDLED;
+
+  notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi", "", "", "", NULL};
+  unsigned int event_type = ipmi_sensor_get_event_reading_type(sensor);
+  unsigned int sensor_type = ipmi_sensor_get_sensor_type(sensor);
+  const char *event_state =
+      ipmi_get_reading_name(event_type, sensor_type, offset);
+  sensor_get_name(sensor, n.type_instance, sizeof(n.type_instance));
+  snprintf(n.message, sizeof(n.message), "sensor %s received event: %s",
+           n.type_instance, event_state);
+
+  DEBUG("Discrete event received for sensor %s", n.type_instance);
+
+  sstrncpy(n.host, hostname_g, sizeof(n.host));
+  sstrncpy(n.type, ipmi_sensor_get_sensor_type_string(sensor), sizeof(n.type));
+  n.time = NS_TO_CDTIME_T(ipmi_event_get_timestamp(event));
+
+  plugin_notification_meta_add_signed_int(&n, "offset", offset);
+
+  if (severity != -1)
+    plugin_notification_meta_add_signed_int(&n, "severity", severity);
+
+  if (prev_severity != -1)
+    plugin_notification_meta_add_signed_int(&n, "prevseverity", prev_severity);
+
+  add_event_common_data(&n, sensor, dir, event);
+
+  plugin_dispatch_notification(&n);
+  plugin_notification_meta_free(n.meta);
+
+  /* Delete handled ipmi event from the list */
+  if (c_ipmi_sel_clear_event) {
+    ipmi_event_delete(event, NULL, NULL);
+    return IPMI_EVENT_HANDLED;
+  }
+
+  return IPMI_EVENT_NOT_HANDLED;
+} /* int sensor_discrete_event_handler */
+
 /*
  * Entity handlers
  */
-static void entity_sensor_update_handler (enum ipmi_update_e op,
-    ipmi_entity_t __attribute__((unused)) *entity,
-    ipmi_sensor_t *sensor,
-    void __attribute__((unused)) *user_data)
-{
+static void entity_sensor_update_handler(
+    enum ipmi_update_e op, ipmi_entity_t __attribute__((unused)) * entity,
+    ipmi_sensor_t *sensor, void __attribute__((unused)) * user_data) {
   /* TODO: Ignore sensors we cannot read */
 
-  if ((op == IPMI_ADDED) || (op == IPMI_CHANGED))
-  {
+  if ((op == IPMI_ADDED) || (op == IPMI_CHANGED)) {
     /* Will check for duplicate entries.. */
-    sensor_list_add (sensor);
-  }
-  else if (op == IPMI_DELETED)
-  {
-    sensor_list_remove (sensor);
+    sensor_list_add(sensor);
+
+    if (c_ipmi_sel_enabled) {
+      int status = 0;
+      /* register threshold event if threshold sensor support events */
+      if ((ipmi_sensor_get_event_reading_type(sensor) ==
+           IPMI_EVENT_READING_TYPE_THRESHOLD) &&
+          (ipmi_sensor_get_threshold_access(sensor) !=
+           IPMI_THRESHOLD_ACCESS_SUPPORT_NONE))
+        status = ipmi_sensor_add_threshold_event_handler(
+            sensor, sensor_threshold_event_handler, NULL);
+      /* register discrete handler if discrete/specific sensor support events */
+      else if (ipmi_sensor_get_event_support(sensor) != IPMI_EVENT_SUPPORT_NONE)
+        status = ipmi_sensor_add_discrete_event_handler(
+            sensor, sensor_discrete_event_handler, NULL);
+
+      if (status) {
+        char buf[DATA_MAX_NAME_LEN] = {0};
+        sensor_get_name(sensor, buf, sizeof(buf));
+        ERROR("Unable to add sensor %s event handler, status: %d", buf, status);
+      }
+    }
+  } else if (op == IPMI_DELETED) {
+    sensor_list_remove(sensor);
+
+    if (c_ipmi_sel_enabled) {
+      if (ipmi_sensor_get_event_reading_type(sensor) ==
+          IPMI_EVENT_READING_TYPE_THRESHOLD)
+        ipmi_sensor_remove_threshold_event_handler(
+            sensor, sensor_threshold_event_handler, NULL);
+      else
+        ipmi_sensor_remove_discrete_event_handler(
+            sensor, sensor_discrete_event_handler, NULL);
+    }
   }
 } /* void entity_sensor_update_handler */
 
 /*
  * Domain handlers
  */
-static void domain_entity_update_handler (enum ipmi_update_e op,
-    ipmi_domain_t __attribute__((unused)) *domain,
-    ipmi_entity_t *entity,
-    void __attribute__((unused)) *user_data)
-{
+static void domain_entity_update_handler(
+    enum ipmi_update_e op, ipmi_domain_t __attribute__((unused)) * domain,
+    ipmi_entity_t *entity, void __attribute__((unused)) * user_data) {
   int status;
 
-  if (op == IPMI_ADDED)
-  {
-    status = ipmi_entity_add_sensor_update_handler (entity,
-        entity_sensor_update_handler, /* user data = */ NULL);
-    if (status != 0)
-    {
-      c_ipmi_error ("ipmi_entity_add_sensor_update_handler", status);
+  if (op == IPMI_ADDED) {
+    status = ipmi_entity_add_sensor_update_handler(
+        entity, entity_sensor_update_handler, /* user data = */ NULL);
+    if (status != 0) {
+      c_ipmi_error("ipmi_entity_add_sensor_update_handler", status);
     }
-  }
-  else if (op == IPMI_DELETED)
-  {
-    status = ipmi_entity_remove_sensor_update_handler (entity,
-        entity_sensor_update_handler, /* user data = */ NULL);
-    if (status != 0)
-    {
-      c_ipmi_error ("ipmi_entity_remove_sensor_update_handler", status);
+  } else if (op == IPMI_DELETED) {
+    status = ipmi_entity_remove_sensor_update_handler(
+        entity, entity_sensor_update_handler, /* user data = */ NULL);
+    if (status != 0) {
+      c_ipmi_error("ipmi_entity_remove_sensor_update_handler", status);
     }
   }
 } /* void domain_entity_update_handler */
 
-static void domain_connection_change_handler (ipmi_domain_t *domain,
-    int err,
-    unsigned int conn_num,
-    unsigned int port_num,
-    int still_connected,
-    void *user_data)
-{
+static void smi_event_handler(ipmi_con_t __attribute__((unused)) * ipmi,
+                              const ipmi_addr_t __attribute__((unused)) * addr,
+                              unsigned int __attribute__((unused)) addr_len,
+                              ipmi_event_t *event, void *cb_data) {
+  unsigned int type = ipmi_event_get_type(event);
+  ipmi_domain_t *domain = cb_data;
+
+  DEBUG("%s: Event received: type %u", __FUNCTION__, type);
+
+  if (type != 0x02)
+    /* It's not a standard IPMI event. */
+    return;
+
+  /* force domain to reread SELs */
+  ipmi_domain_reread_sels(domain, NULL, NULL);
+}
+
+static void domain_connection_change_handler(ipmi_domain_t *domain, int err,
+                                             unsigned int conn_num,
+                                             unsigned int port_num,
+                                             int still_connected,
+                                             void *user_data) {
   int status;
 
-  DEBUG ("domain_connection_change_handler (domain = %p, err = %i, "
-      "conn_num = %u, port_num = %u, still_connected = %i, "
-      "user_data = %p);\n",
-      (void *) domain, err, conn_num, port_num, still_connected, user_data);
+  DEBUG("domain_connection_change_handler (domain = %p, err = %i, "
+        "conn_num = %u, port_num = %u, still_connected = %i, "
+        "user_data = %p);\n",
+        (void *)domain, err, conn_num, port_num, still_connected, user_data);
 
-  status = ipmi_domain_add_entity_update_handler (domain,
-      domain_entity_update_handler, /* user data = */ NULL);
-  if (status != 0)
-  {
-    c_ipmi_error ("ipmi_domain_add_entity_update_handler", status);
+  status = ipmi_domain_add_entity_update_handler(
+      domain, domain_entity_update_handler, /* user data = */ NULL);
+  if (status != 0) {
+    c_ipmi_error("ipmi_domain_add_entity_update_handler", status);
   }
+
+  ipmi_con_t *smi_connection = user_data;
+  status = smi_connection->add_event_handler(smi_connection, smi_event_handler,
+                                             (void *)domain);
+
+  if (status != 0)
+    c_ipmi_error("Failed to register smi event handler", status);
 } /* void domain_connection_change_handler */
 
-static int thread_init (os_handler_t **ret_os_handler)
-{
+static int thread_init(os_handler_t **ret_os_handler) {
   os_handler_t *os_handler;
   ipmi_con_t *smi_connection = NULL;
   ipmi_domain_id_t domain_id;
   int status;
 
-  os_handler = ipmi_posix_thread_setup_os_handler (SIGIO);
-  if (os_handler == NULL)
-  {
-    ERROR ("ipmi plugin: ipmi_posix_thread_setup_os_handler failed.");
-    return (-1);
+  os_handler = ipmi_posix_thread_setup_os_handler(SIGIO);
+  if (os_handler == NULL) {
+    ERROR("ipmi plugin: ipmi_posix_thread_setup_os_handler failed.");
+    return -1;
   }
 
-  ipmi_init (os_handler);
+  ipmi_init(os_handler);
 
-  status = ipmi_smi_setup_con (/* if_num = */ 0,
-      os_handler,
-      /* user data = */ NULL,
-      &smi_connection);
-  if (status != 0)
-  {
-    c_ipmi_error ("ipmi_smi_setup_con", status);
-    return (-1);
+  status = ipmi_smi_setup_con(/* if_num = */ 0, os_handler,
+                              /* user data = */ NULL, &smi_connection);
+  if (status != 0) {
+    c_ipmi_error("ipmi_smi_setup_con", status);
+    return -1;
   }
 
-  ipmi_open_option_t open_option[1] = {
-    [0] = {
-      .option = IPMI_OPEN_OPTION_ALL,
-      { .ival = 1 }
-    }
-  };
-
-  status = ipmi_open_domain ("mydomain", &smi_connection, /* num_con = */ 1,
-      domain_connection_change_handler, /* user data = */ NULL,
-      /* domain_fully_up_handler = */ NULL, /* user data = */ NULL,
-      open_option, sizeof (open_option) / sizeof (open_option[0]),
-      &domain_id);
-  if (status != 0)
-  {
-    c_ipmi_error ("ipmi_open_domain", status);
-    return (-1);
+  ipmi_open_option_t open_option[1] = {[0] = {.option = IPMI_OPEN_OPTION_ALL,
+                                              {.ival = 1}}};
+
+  status = ipmi_open_domain(
+      "mydomain", &smi_connection, /* num_con = */ 1,
+      domain_connection_change_handler,
+      /* user data = */ (void *)smi_connection,
+      /* domain_fully_up_handler = */ NULL, /* user data = */ NULL, open_option,
+      sizeof(open_option) / sizeof(open_option[0]), &domain_id);
+  if (status != 0) {
+    c_ipmi_error("ipmi_open_domain", status);
+    return -1;
   }
 
   *ret_os_handler = os_handler;
-  return (0);
+  return 0;
 } /* int thread_init */
 
-static void *thread_main (void __attribute__((unused)) *user_data)
-{
+static void *thread_main(void __attribute__((unused)) * user_data) {
   int status;
   os_handler_t *os_handler = NULL;
 
-  status = thread_init (&os_handler);
-  if (status != 0)
-  {
-    ERROR ("ipmi plugin: thread_init failed.\n");
-    return ((void *) -1);
+  status = thread_init(&os_handler);
+  if (status != 0) {
+    ERROR("ipmi plugin: thread_init failed.\n");
+    return (void *)-1;
   }
 
-  while (c_ipmi_active != 0)
-  {
-    struct timeval tv = { 1, 0 };
-    os_handler->perform_one_op (os_handler, &tv);
+  while (c_ipmi_active != 0) {
+    struct timeval tv = {1, 0};
+    os_handler->perform_one_op(os_handler, &tv);
   }
 
-  ipmi_posix_thread_free_os_handler (os_handler);
+  ipmi_posix_thread_free_os_handler(os_handler);
 
-  return ((void *) 0);
+  return (void *)0;
 } /* void *thread_main */
 
-static int c_ipmi_config (const char *key, const char *value)
-{
+static int c_ipmi_config(const char *key, const char *value) {
   if (ignorelist == NULL)
-    ignorelist = ignorelist_create (/* invert = */ 1);
+    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 (IS_TRUE (value))
-      invert = 0;
-    ignorelist_set_invert (ignorelist, invert);
-  }
-  else if (strcasecmp ("NotifySensorAdd", key) == 0)
-  {
-    if (IS_TRUE (value))
-      c_ipmi_nofiy_add = 1;
-  }
-  else if (strcasecmp ("NotifySensorRemove", key) == 0)
-  {
-    if (IS_TRUE (value))
-      c_ipmi_nofiy_remove = 1;
-  }
-  else if (strcasecmp ("NotifySensorNotPresent", key) == 0)
-  {
-    if (IS_TRUE (value))
-      c_ipmi_nofiy_notpresent = 1;
-  }
-  else
-  {
-    return (-1);
+    return 1;
+
+  if (strcasecmp("Sensor", key) == 0) {
+    ignorelist_add(ignorelist, value);
+  } else if (strcasecmp("IgnoreSelected", key) == 0) {
+    ignorelist_set_invert(ignorelist, !IS_TRUE(value));
+  } else if (strcasecmp("NotifySensorAdd", key) == 0) {
+    c_ipmi_notify_add = IS_TRUE(value);
+  } else if (strcasecmp("NotifySensorRemove", key) == 0) {
+    c_ipmi_notify_remove = IS_TRUE(value);
+  } else if (strcasecmp("NotifySensorNotPresent", key) == 0) {
+    c_ipmi_notify_notpresent = IS_TRUE(value);
+  } else if (strcasecmp("SELEnabled", key) == 0) {
+    c_ipmi_sel_enabled = IS_TRUE(value);
+  } else if (strcasecmp("SELClearEvent", key) == 0) {
+    c_ipmi_sel_clear_event = IS_TRUE(value);
+  } else {
+    return -1;
   }
 
-  return (0);
+  return 0;
 } /* int c_ipmi_config */
 
-static int c_ipmi_init (void)
-{
+static int c_ipmi_init(void) {
   int status;
 
   /* Don't send `ADD' notifications during startup (~ 1 minute) */
-  time_t iv = CDTIME_T_TO_TIME_T (plugin_get_interval ());
+  time_t iv = CDTIME_T_TO_TIME_T(plugin_get_interval());
   c_ipmi_init_in_progress = 1 + (60 / iv);
 
   c_ipmi_active = 1;
 
-  status = plugin_thread_create (&thread_id, /* attr = */ NULL, thread_main,
-      /* user data = */ NULL);
-  if (status != 0)
-  {
+  status = plugin_thread_create(&thread_id, /* attr = */ NULL, thread_main,
+                                /* user data = */ NULL, "ipmi");
+  if (status != 0) {
     c_ipmi_active = 0;
-    thread_id = (pthread_t) 0;
-    ERROR ("ipmi plugin: pthread_create failed.");
-    return (-1);
+    thread_id = (pthread_t)0;
+    ERROR("ipmi plugin: pthread_create failed.");
+    return -1;
   }
 
-  return (0);
+  return 0;
 } /* int c_ipmi_init */
 
-static int c_ipmi_read (void)
-{
-  if ((c_ipmi_active == 0) || (thread_id == (pthread_t) 0))
-  {
-    INFO ("ipmi plugin: c_ipmi_read: I'm not active, returning false.");
-    return (-1);
+static int c_ipmi_read(void) {
+  if ((c_ipmi_active == 0) || (thread_id == (pthread_t)0)) {
+    INFO("ipmi plugin: c_ipmi_read: I'm not active, returning false.");
+    return -1;
   }
 
-  sensor_list_read_all ();
+  sensor_list_read_all();
 
   if (c_ipmi_init_in_progress > 0)
     c_ipmi_init_in_progress--;
   else
     c_ipmi_init_in_progress = 0;
 
-  return (0);
+  return 0;
 } /* int c_ipmi_read */
 
-static int c_ipmi_shutdown (void)
-{
+static int c_ipmi_shutdown(void) {
   c_ipmi_active = 0;
 
-  if (thread_id != (pthread_t) 0)
-  {
-    pthread_join (thread_id, NULL);
-    thread_id = (pthread_t) 0;
+  if (thread_id != (pthread_t)0) {
+    pthread_join(thread_id, NULL);
+    thread_id = (pthread_t)0;
   }
 
-  sensor_list_remove_all ();
+  sensor_list_remove_all();
 
-  return (0);
+  return 0;
 } /* int c_ipmi_shutdown */
 
-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);
+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);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 ts=8 fdm=marker et : */