Regex in MQTT broker topics

I am trying to read multiple topics from the MQTT broker using [[inputs.mqtt_consumer]] but I don’t want to read all the topics from the broker using topics = ["#"].

My topic names like this:


like this, I have hundreds of topics that have the data of multiple devices.

Now, I want to process the data from the topic which contains ReportCumKpi and ReportNonCumKpi and exclude everything.
I tried using wildcard + and # but I am not able to exclude other topics.

Is there any way I can exclude the rest of the topics and process interesting topics?

I have followed this blog as well but I am not able to identify the topics of my interest.

@Jay_Clifford Any chance you can help here?
Thank you!

Hi @Ravikant_Gautam,
So you should be able to do something like this:

 topics = [

In short + and # are the primary wildcards supported by most brokers conforming to the MQTT standard. Your other option is to subscribe a wider range of topics:

 topics = [

    topic = "broker.1/0/+"
    tags = "_/_/name"

Then use Telegraf to filter out the topics you do not want with something like tagpass:

# Parse a complete file each interval
    name = [ "0.ReportCumKpi.2819", "0.ReportNonCumKpi.2819" ]
  files = ["./tmp/metrics.out"]
  data_format = "json"

1 Like

topics = [

@Jay_Clifford suppose If I have to ignore the number as well then what will be the pattern

I have tried

 topics = [

but it’s giving the error.

when I tried this no error is coming but telegraf not able to read the data

topics = [

Can you please help me with it?

Hi @Ravikant_Gautam,
Based on your topic names this is not possible. Topic hierarchy is defined by / . In your case . does not confirm to the MQTT specification that I know of. You would have to look at post-processing to filter. Perhaps through the Starlark processor plugin.