#include <OpenIPMI/ipmi_smi.h>
#include <OpenIPMI/ipmiif.h>
+#define ERR_BUF_SIZE 1024
+
/*
* Private data types
*/
_Bool notify_add;
_Bool notify_remove;
_Bool notify_notpresent;
+ _Bool notify_conn;
_Bool sel_enabled;
_Bool sel_clear_event;
char *password;
unsigned int authtype;
+ _Bool connected;
ipmi_con_t *connection;
pthread_mutex_t sensor_list_lock;
c_ipmi_sensor_list_t *sensor_list;
/*
* Misc private functions
*/
-static void c_ipmi_error(const char *func, int status) {
- char errbuf[4096] = {0};
+static void c_ipmi_error(c_ipmi_instance_t *st, const char *func, int status) {
+ char errbuf[ERR_BUF_SIZE] = {0};
if (IPMI_IS_OS_ERR(status) || IPMI_IS_RMCPP_ERR(status) ||
IPMI_IS_IPMI_ERR(status)) {
}
errbuf[sizeof(errbuf) - 1] = 0;
- ERROR("ipmi plugin: %s failed: %s", func, errbuf);
+ ERROR("ipmi plugin: %s failed for `%s`: %s", func, st->name, errbuf);
} /* void c_ipmi_error */
static void c_ipmi_log(os_handler_t *handler, const char *format,
enum ipmi_log_type_e log_type, va_list ap) {
- char msg[1024];
+ char msg[ERR_BUF_SIZE];
vsnprintf(msg, sizeof(msg), format, ap);
INFO("ipmi plugin: sensor_read_handler: Sensor `%s` of `%s` timed out.",
list_item->sensor_name, st->name);
} else {
- char errbuf[128] = {0};
+ char errbuf[ERR_BUF_SIZE] = {0};
ipmi_get_error_string(err, errbuf, sizeof(errbuf) - 1);
if (IPMI_IS_IPMI_ERR(err))
status = ipmi_entity_add_sensor_update_handler(
entity, entity_sensor_update_handler, /* user data = */ (void *)st);
if (status != 0) {
- c_ipmi_error("ipmi_entity_add_sensor_update_handler", status);
+ c_ipmi_error(st, "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 = */ (void *)st);
if (status != 0) {
- c_ipmi_error("ipmi_entity_remove_sensor_update_handler", status);
+ c_ipmi_error(st, "ipmi_entity_remove_sensor_update_handler", status);
}
}
} /* void domain_entity_update_handler */
"user_data = %p);",
(void *)domain, err, conn_num, port_num, still_connected, user_data);
+ c_ipmi_instance_t *st = (c_ipmi_instance_t *)user_data;
+
if (err != 0)
- c_ipmi_error("domain_connection_change_handler", err);
+ c_ipmi_error(st, "domain_connection_change_handler", err);
+
+ if (!still_connected) {
+
+ if (st->notify_conn && st->connected && st->init_in_progress == 0) {
+ notification_t n = {NOTIF_FAILURE, cdtime(), "", "", "ipmi", "", "", "",
+ NULL};
+
+ sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g,
+ sizeof(n.host));
+ sstrncpy(n.message, "IPMI connection lost", sizeof(n.plugin));
- if (!still_connected)
+ plugin_dispatch_notification(&n);
+ }
+
+ st->connected = 0;
return;
+ }
- c_ipmi_instance_t *st = (c_ipmi_instance_t *)user_data;
+ if (st->notify_conn && !st->connected && st->init_in_progress == 0) {
+ notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi", "", "", "", NULL};
+
+ sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g,
+ sizeof(n.host));
+ sstrncpy(n.message, "IPMI connection restored", sizeof(n.plugin));
+
+ plugin_dispatch_notification(&n);
+ }
+
+ st->connected = 1;
int status = ipmi_domain_add_entity_update_handler(
domain, domain_entity_update_handler, /* user data = */ st);
if (status != 0) {
- c_ipmi_error("ipmi_domain_add_entity_update_handler", status);
+ c_ipmi_error(st, "ipmi_domain_add_entity_update_handler", status);
}
status = st->connection->add_event_handler(st->connection, smi_event_handler,
(void *)domain);
if (status != 0)
- c_ipmi_error("Failed to register smi event handler", status);
+ c_ipmi_error(st, "Failed to register smi event handler", status);
} /* void domain_connection_change_handler */
static int c_ipmi_thread_init(c_ipmi_instance_t *st) {
strlen(st->password), os_handler,
/* user data = */ NULL, &st->connection);
if (status != 0) {
- c_ipmi_error("ipmi_ip_setup_con", status);
+ c_ipmi_error(st, "ipmi_ip_setup_con", status);
return -1;
}
} else {
status = ipmi_smi_setup_con(/* if_num = */ 0, os_handler,
/* user data = */ NULL, &st->connection);
if (status != 0) {
- c_ipmi_error("ipmi_smi_setup_con", status);
+ c_ipmi_error(st, "ipmi_smi_setup_con", status);
return -1;
}
}
/* domain_fully_up_handler = */ NULL, /* user data = */ NULL, open_option,
open_option_num, &domain_id);
if (status != 0) {
- c_ipmi_error("ipmi_open_domain", status);
+ c_ipmi_error(st, "ipmi_open_domain", status);
return -1;
}
} /* int c_ipmi_thread_init */
static void *c_ipmi_thread_main(void *user_data) {
- int status;
c_ipmi_instance_t *st = (c_ipmi_instance_t *)user_data;
- status = c_ipmi_thread_init(st);
+ int status = c_ipmi_thread_init(st);
if (status != 0) {
ERROR("ipmi plugin: c_ipmi_thread_init failed.");
st->active = 0;
sfree(st);
} /* void c_ipmi_free_instance */
-void c_ipmi_add_instance(c_ipmi_instance_t *instance) {
+static void c_ipmi_add_instance(c_ipmi_instance_t *instance) {
if (instances == NULL) {
instances = instance;
return;
last = last->next;
last->next = instance;
-
- return;
} /* void c_ipmi_add_instance */
static int c_ipmi_config_add_instance(oconfig_item_t *ci) {
if (strcasecmp("Sensor", child->key) == 0)
ignorelist_add(st->ignorelist, ci->values[0].value.string);
else if (strcasecmp("IgnoreSelected", child->key) == 0) {
- if (ci->values[0].value.boolean)
+ _Bool t;
+ status = cf_util_get_boolean(child, &t);
+ if (status != 0)
+ break;
+ if (t)
ignorelist_set_invert(st->ignorelist, /* invert = */ 0);
else
ignorelist_set_invert(st->ignorelist, /* invert = */ 1);
+ } else if (strcasecmp("NotifyIPMIConnectionState", child->key) == 0) {
+ status = cf_util_get_boolean(child, &st->notify_conn);
} else if (strcasecmp("NotifySensorAdd", child->key) == 0) {
- if (ci->values[0].value.boolean)
- st->notify_add = 1;
+ status = cf_util_get_boolean(child, &st->notify_add);
} else if (strcasecmp("NotifySensorRemove", child->key) == 0) {
- if (ci->values[0].value.boolean)
- st->notify_remove = 1;
+ status = cf_util_get_boolean(child, &st->notify_remove);
} else if (strcasecmp("NotifySensorNotPresent", child->key) == 0) {
- if (ci->values[0].value.boolean)
- st->notify_notpresent = 1;
+ status = cf_util_get_boolean(child, &st->notify_notpresent);
} else if (strcasecmp("SELEnabled", child->key) == 0) {
- if (ci->values[0].value.boolean)
- st->sel_enabled = 1;
+ status = cf_util_get_boolean(child, &st->sel_enabled);
} else if (strcasecmp("SELClearEvent", child->key) == 0) {
- if (ci->values[0].value.boolean)
- st->sel_clear_event = 1;
+ status = cf_util_get_boolean(child, &st->sel_clear_event);
} else if (strcasecmp("Host", child->key) == 0)
status = cf_util_get_string(child, &st->host);
else if (strcasecmp("Address", child->key) == 0)
oconfig_item_t *child = ci->children + i;
if (strcasecmp("Instance", child->key) == 0) {
- c_ipmi_config_add_instance(child);
+ int status = c_ipmi_config_add_instance(child);
+ if (status != 0)
+ return status;
+
have_instance_block = 1;
} else if (!have_instance_block) {
/* Non-instance option: Assume legacy configuration (without <Instance />
} /* int c_ipmi_config */
static int c_ipmi_read(user_data_t *user_data) {
- c_ipmi_instance_t *st;
- st = user_data->data;
+ c_ipmi_instance_t *st = user_data->data;
if ((st->active == 0) || (st->thread_id == (pthread_t)0)) {
INFO("ipmi plugin: c_ipmi_read: I'm not active, returning false.");
return -1;
}
+ if (st->connected == 0)
+ return 0;
+
sensor_list_read_all(st);
if (st->init_in_progress > 0)