From: Mark Ferry Date: Fri, 10 Oct 2025 16:04:36 +0000 (+0100) Subject: mqtt plugin: add SendNotifications config, default false X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5d3625b444e06c003b5928db05650630594c710;p=thirdparty%2Fcollectd.git mqtt plugin: add SendNotifications config, default false --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index dbefc9cd6..77e702887 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1095,6 +1095,7 @@ # Prefix "collectd" # StoreRates true # Retain false +# SendNotifications false # CACert "/etc/ssl/ca.crt" # CertificateFile "/etc/ssl/client.crt" # CertificateKeyFile "/etc/ssl/client.pem" diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 3566605ce..7ae344ac7 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -5464,6 +5464,16 @@ sent to each topic and deliver it to new subscribers. Defaults to B. Controls whether C and C metrics are converted to a I before sending. Defaults to B. +=item B B|B (Publish only) + +Controls whether notifications are sent. Defaults to B. + +Notifications are published to an C subtopic for each type instance. + +Example: + + collectd/host/interface-eth0/if_octets/event + =item B B|B (Subscribe only) Controls whether the MQTT "cleans" the session up after the subscriber diff --git a/src/mqtt.c b/src/mqtt.c index fec95c33e..f26b8cd27 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -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 */