ipmi plugin: Notify about IPMI connection state change
authorPavel Rochnyack <pavel2000@ngs.ru>
Sun, 8 Oct 2017 06:41:29 +0000 (13:41 +0700)
committerPavel Rochnyack <pavel2000@ngs.ru>
Mon, 9 Oct 2017 06:01:36 +0000 (13:01 +0700)
src/collectd.conf.in
src/collectd.conf.pod
src/ipmi.c

index b229f01..5f58a6e 100644 (file)
 #              NotifySensorAdd false
 #              NotifySensorRemove true
 #              NotifySensorNotPresent false
+#              NotifyIPMIConnectionState false
 #              SELEnabled false
 #              SELClearEvent false
 #      </Instance>
 #              NotifySensorAdd false
 #              NotifySensorRemove true
 #              NotifySensorNotPresent false
+#              NotifyIPMIConnectionState false
 #              SELEnabled false
 #              SELClearEvent false
 #      </Instance>
index 746829c..53e1538 100644 (file)
@@ -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<NotifyIPMIConnectionState> I<true>|I<false>
+
+If a IPMI connection state changes after initialization time of a minute
+a notification is sent. Defaults to B<false>.
+
 =item B<SELEnabled> I<true>|I<false>
 
 If system event log (SEL) is enabled, plugin will listen for sensor threshold
index 7b22bc2..32d6e51 100644 (file)
@@ -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;