]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
mqtt plugin: add SendNotifications config, default false
authorMark Ferry <mark@markferry.net>
Fri, 10 Oct 2025 16:04:36 +0000 (17:04 +0100)
committerMark Ferry <mark@markferry.net>
Mon, 24 Nov 2025 14:11:19 +0000 (14:11 +0000)
src/collectd.conf.in
src/collectd.conf.pod
src/mqtt.c

index dbefc9cd66142d2a447fa5f6781ac2bdcf4660ac..77e7028879572490ea6908ccbb88dfb5a97fe799 100644 (file)
 #              Prefix "collectd"
 #              StoreRates true
 #              Retain false
+#              SendNotifications false
 #              CACert "/etc/ssl/ca.crt"
 #              CertificateFile "/etc/ssl/client.crt"
 #              CertificateKeyFile "/etc/ssl/client.pem"
index 3566605ce7442e7c7a5deb9020db75b8546b9960..7ae344ac7b3107d042ca50411171a5fd80d0af75 100644 (file)
@@ -5464,6 +5464,16 @@ sent to each topic and deliver it to new subscribers. Defaults to B<false>.
 Controls whether C<DERIVE> and C<COUNTER> metrics are converted to a I<rate>
 before sending. Defaults to B<true>.
 
+=item B<SendNotifications> B<true>|B<false> (Publish only)
+
+Controls whether notifications are sent. Defaults to B<false>.
+
+Notifications are published to an C<event> subtopic for each type instance.
+
+Example:
+
+ collectd/host/interface-eth0/if_octets/event
+
 =item B<CleanSession> B<true>|B<false> (Subscribe only)
 
 Controls whether the MQTT "cleans" the session up after the subscriber
index fec95c33e829d52d1281b1857db22b3a1b7c9101..f26b8cd27b958fd35515d827d1d586307464d1c9 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "plugin.h"
 #include "utils/common/common.h"
+
 #include "utils/format_json/format_json.h"
 #include "utils_complain.h"
 
@@ -77,6 +78,7 @@ struct mqtt_client_conf {
   char *topic_prefix;
   bool store_rates;
   bool retain;
+  bool send_notifications;
 
   /* For subscribing */
   pthread_t thread;
@@ -615,6 +617,7 @@ static int mqtt_notification(const notification_t *n,
  *   Prefix "collectd"
  *   StoreRates true
  *   Retain false
+ *   SendNotifications false
  *   QoS 0
  *   CACert "ca.pem"                      Enables TLS if set
  *   CertificateFile "client-cert.pem"   optional
@@ -685,6 +688,8 @@ static int mqtt_config_publisher(oconfig_item_t *ci) {
       cf_util_get_boolean(child, &conf->store_rates);
     else if (strcasecmp("Retain", child->key) == 0)
       cf_util_get_boolean(child, &conf->retain);
+    else if (strcasecmp("SendNotifications", child->key) == 0)
+      cf_util_get_boolean(child, &conf->send_notifications);
     else if (strcasecmp("CACert", child->key) == 0)
       cf_util_get_string(child, &conf->cacertificatefile);
     else if (strcasecmp("CertificateFile", child->key) == 0)
@@ -704,10 +709,14 @@ static int mqtt_config_publisher(oconfig_item_t *ci) {
                         &(user_data_t){
                             .data = conf,
                         });
-  plugin_register_notification(cb_name, mqtt_notification,
-                               &(user_data_t){
-                                   .data = conf,
-                               });
+
+  if (conf->send_notifications) {
+    plugin_register_notification(cb_name, mqtt_notification,
+                                 &(user_data_t){
+                                     .data = conf,
+                                 });
+  }
+
   return 0;
 } /* mqtt_config_publisher */