Hello, I’m configuring Telegraf and InfluxDB to monitor irrigation valves via MQTT. Each irrigation controller (
device tag), has 4 switches (
switch tag) that I’d like rename to something meaningful.
My current Telegraf configuration looks like:
[[inputs.mqtt_consumer]] alias = "mqtt.irrigation" servers = ["tcp://mosquitto:1883"] topics = [ "irrigation/+/relay/#" ] data_format = "value" data_type = "integer" [[inputs.mqtt_consumer.topic_parsing]] topic = "irrigation/+/relay/+" tags = "_/device/relay/switch"
And my output (to Influxdb or stdout) is in the form:
mqtt_consumer,device=bees-knees,ip_addr=402c3b0e020e,relay=relay,switch=1,topic=irrigation/bees-knees/relay/1 value=0i 1685298970699514515 mqtt_consumer,device=bees-knees,ip_addr=402c3b0e020e,relay=relay,switch=2,topic=irrigation/bees-knees/relay/2 value=1i 1685298970699536329 mqtt_consumer,device=bees-knees,ip_addr=402c3b0e020e,relay=relay,switch=3,topic=irrigation/bees-knees/relay/3 value=0i 1685298970699693583 mqtt_consumer,device=cats-meow,ip_addr=402c3b0e020e,relay=relay,switch=0,topic=irrigation/cats-meow/relay/0 value=0i 1685298970699710860 mqtt_consumer,device=cats-meow,ip_addr=402c3b0e020e,relay=relay,switch=1,topic=irrigation/cats-meow/relay/1 value=0i 168529897069972519
What I’d like to accomplish is renaming the
switch tag from
switch=0 to “Sprinkler_A” if
device=bees-knees, and “0” becomes
I know that
processors.strings.replace and some form of
tagpass is what’s needed, but I haven’t succeeded in getting this to work. If it would make more sense to do this transformation in InfluxDB, rather than Telegraf, I suppose that’s an option too. Thanks!