From a407ce8e018fdc980841ccae69f608bcc1140934 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Sun, 8 Oct 2017 13:41:29 +0700 Subject: [PATCH] ipmi plugin: Notify about IPMI connection state change --- src/collectd.conf.in | 2 ++ src/collectd.conf.pod | 5 +++++ src/ipmi.c | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/collectd.conf.in b/src/collectd.conf.in index b229f019..5f58a6e9 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -683,6 +683,7 @@ # NotifySensorAdd false # NotifySensorRemove true # NotifySensorNotPresent false +# NotifyIPMIConnectionState false # SELEnabled false # SELClearEvent false # @@ -698,6 +699,7 @@ # NotifySensorAdd false # NotifySensorRemove true # NotifySensorNotPresent false +# NotifyIPMIConnectionState false # SELEnabled false # SELClearEvent false # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 746829c4..53e15387 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -3409,6 +3409,11 @@ If a sensor disappears a notification is sent. If you have for example dual power supply and one of them is (un)plugged then a notification is sent. +=item B I|I + +If a IPMI connection state changes after initialization time of a minute +a notification is sent. Defaults to B. + =item B I|I If system event log (SEL) is enabled, plugin will listen for sensor threshold diff --git a/src/ipmi.c b/src/ipmi.c index 7b22bc26..32d6e510 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -50,6 +50,7 @@ struct c_ipmi_instance_s { _Bool notify_add; _Bool notify_remove; _Bool notify_notpresent; + _Bool notify_conn; _Bool sel_enabled; _Bool sel_clear_event; @@ -828,10 +829,32 @@ static void domain_connection_change_handler(ipmi_domain_t *domain, int 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)); + + plugin_dispatch_notification(&n); + } + st->connected = 0; return; } + 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( @@ -1016,6 +1039,9 @@ static int c_ipmi_config_add_instance(oconfig_item_t *ci) { ignorelist_set_invert(st->ignorelist, /* invert = */ 0); else ignorelist_set_invert(st->ignorelist, /* invert = */ 1); + } else if (strcasecmp("NotifyIPMIConnectionState", child->key) == 0) { + if (ci->values[0].value.boolean) + st->notify_conn = 1; } else if (strcasecmp("NotifySensorAdd", child->key) == 0) { if (ci->values[0].value.boolean) st->notify_add = 1; -- 2.11.0