write this information because i don’t find some solution by searching over internet. I don’t know if there is some solution to fix this.
Actually, I try to connect to one Azure IoT Hub by using its MQTT broker feature. Any Azure IoT Hub can be converted into a general MQTT broker with these parameters:
[[outputs.mqtt]]
servers= [“tcp://{iotHubName}.azure-devices.net:8883”]
topic_prefix = “devices/{clientID}/messages/events/”
username=“{iotHubName}.azure-devices.net/{clientID}/?api-version=2021-04-12”
password = “{SAS}”
client_id = "{clientID}
tls_ca = “/etc/telegraf/IoTHubRootCA_Baltimore.pem”
insecure_skip_verify
data_format = “json”
Note: SAS is generated using some kind of script or in Azure Portal, you must indicate number of seconds of validity for TLS connection.
Example: az iot hub generate-sas-token -n {iotHubName} --duration 36000
tls_ca is required for server authentication from client side. You can find CA certificate here: GitHub - Azure-Samples/IoTMQTTSample: MQTT samples for Azure IoT
Issue is following:
telegraf connects OK with Azure IoT Hub, but I do not see any message. After some tests and researching I have thought problem is the topic. Azure requires topic to publish from any client fits to this schema: “devices/{clientID}/messages/events/” and following telegraf guide por outputs.mqtt, it says that other subtopics are added to main publishing topic:
MQTT Topic for Producer Messages
MQTT outputs send metrics to this topic format:
<topic_prefix> / <hostname> / <pluginname>/ (
e.g. prefix/web01.example.com/mem).
Then, when apply complete topic we would have:
devices/{clientID}/messages/events/{hostname}/{pluginname}
It seems there is a limitation in Azure topics hierarchy, Azure allows only one level more in publishing topics, at least , in my tests it seems problem is that. I have checked with mosquitto_pub.
If I try:
mosquitto_pub -d -h {iotHubName}.azures-devices.net -p 8883 -i {clientID} -u “{iotHubName}.azure-devices.net/{clientID}/?api-version=2018-06-30” -P “$SAS_TOKEN” -t “devices/{clientID}/messages/events/” -m “Testing from mosquitto_pub” -V mqttv311 -q 1
It works and I see message inside portal. Mosquitto_pub client gives me this log:
Client testInfluxDB sending CONNECT
Client testInfluxDB received CONNACK (0)
Client testInfluxDB sending PUBLISH (d0, q1, r0, m1, ‘devices/{clientID}/messages/events/’, … (X bytes))
Client testInfluxDB received PUBACK (Mid: 1, RC:0)
Client testInfluxDB sending DISCONNECT
If a try with a first sublevel at MQTT topic, it continues working:
mosquitto_pub -d -h {iotHubName}.azures-devices.net -p 8883 -i {clientID} -u “{iotHubName}.azure-devices.net/{clientID}/?api-version=2018-06-30” -P “$SAS_TOKEN” -t “devices/{clientID}/messages/events/level1/” -m “Testing from mosquitto_pub” -V mqttv311 -q 1
Client testInfluxDB sending CONNECT
Client testInfluxDB received CONNACK (0)
Client testInfluxDB sending PUBLISH (d0, q1, r0, m1, ‘devices/{clientID}/messages/events/level1/’, … (X bytes))
Client testInfluxDB received PUBACK (Mid: 1, RC:0)
Client testInfluxDB sending DISCONNECT
But If I try with a second sublevel at MQTT topic, it fails:
mosquitto_pub -d -h {iotHubName}.azures-devices.net -p 8883 -i {clientID} -u “{iotHubName}.azure-devices.net/{clientID}/?api-version=2018-06-30” -P “$SAS_TOKEN” -t “devices/{clientID}/messages/events/level1/level2/” -m “Testing from mosquitto_pub” -V mqttv311 -q 1
Client testInfluxDB sending CONNECT
Client testInfluxDB received CONNACK (0)
Client testInfluxDB sending PUBLISH (d0, q1, r0, m1, ‘devices/{clientID}/messages/events/level1/level2/’, … (X bytes))
OpenSSL Error[0]: error:0A000126:SSL routines::unexpected eof while reading
Error: The connection was lost.
Maybe I don’t know complete method to use outputs.mqtt to use with IoT Hub MQTT broker or, is there some workaround to fix this?