Ad Widget

Collapse

MQTT Configuration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • p8mty
    Junior Member
    • Dec 2021
    • 2

    #1

    MQTT Configuration

    I can't seem to get MQTT working with Zabbix and I'm sure it must be something simple.

    My setup is reasonably large (400+ hosts, ~50k items, Zabbix 5.4). It's all working fine.

    I used to have MQTT working via external checks, but I thought that since it is now integrated into Zabbix, I would use that instead.

    I have a Mosquito broker running on a host - that's working, I can see devices publishing data to it, I can see test devices subscribing and receiving data from it.

    The host that the broker is running on is monitored by Zabbix and I've added to that host the following MQTT Master item:
    Name: MQTT Master
    Type: Zabbix Agent (active)
    Key: mqtt.get["localhost","mr/esp8266/192.168.1.151/#"]
    Type: Text

    And I've added a dependent item
    Name: Temp151
    Type: Dependent Item
    key: temperature
    Master Item: MQTT Master

    (the topic is published as mr/esp8266/192.168.1.151/temperature)

    But I can see no indication that the topic is being subscribed to - there has been no contact with the broker from the host. I've tried different forms of the broker URI: IP address, FQDN, adding tcp://, adding the port. I can subscribe from other external hosts so there's no firewall in the way. zabbix_agent2 is running on the broker and all other system data is being collected.

    The logs for zabbix_agent2 have no mention of MQTT in them other than "using plugin 'MQTT' providing following interfaces: watcher, configurator" whenever it is restarted.

    So what am I missing?
    Is the broker host the correct Zabbix host to be adding the MQTT monitoring to?
    Do I need to do any configuring in zabbix_agent2.conf?

    Thanks for any insight from anyone.
  • p8mty
    Junior Member
    • Dec 2021
    • 2

    #2
    No replies, but I have worked out what was wrong.

    The fundamental issue was that zabbix-agent2 was not configured properly to receive configuration from the server. I needed to set both "Server" and "ServerActive" in the config file and the "Hostname" needs to match (exactly) the hostname in the server config. After setting all those correctly, it started contacting my MQTT broker.

    To answer some of my questions:

    It doesn't matter which host the active checks are being done on - the MQTT Master item just needs to point to the correct place and be able to subscribe to the topic. It is convenient to use the same host and then use "localhost" as the broker URI.

    I've changed the MQTT topic format (I was concerned the IP address in the topic was confusing some of the post processing), so it now just has the last part of the IP as identifier. So my MQTT Master item key is now

    mqtt.get["localhost","mr/esp8266/#"]

    I've configured the dependent item with a key of

    mr.esp8266.151.temperature

    and a preprocessing of

    JSONPath : $["mr/esp8266/151/temperature"]

    The value of the key is irrelevant, it's an identifier and needs to be present so it should probably be something sensible.
    The JSONPath parameter is the topic you need the value from.

    Hope this is some help to someone.

    Comment

    • Michael Wulz
      Junior Member
      • Mar 2023
      • 3

      #3
      Hello,
      do you know is there a possiblilty to test this from commandline? Like on passive checks...

      I have some trouble with the MQTT plugin and it's hard to find the problem.

      in Log on debug mode (loglevel=5) this output is coming, but no data in Zabbix:
      Code:
      2023/03/28 19:48:58.615423 [102] created watcher task for plugin MQTT
      2023/03/28 19:48:58.615582 plugin MQTT: executing watcher task
      2023/03/28 19:48:58.617312 [104] created watcher task for plugin MQTT
      2023/03/28 19:48:58.617427 plugin MQTT: executing watcher task
      2023/03/28 19:48:58.617727 [106] created watcher task for plugin MQTT
      2023/03/28 19:48:58.617832 plugin MQTT: executing watcher task
      2023/03/28 19:50:59.614647 [104] created watcher task for plugin MQTT
      2023/03/28 19:50:59.614800 plugin MQTT: executing watcher task
      2023/03/28 19:50:59.617014 [106] created watcher task for plugin MQTT
      2023/03/28 19:50:59.617129 plugin MQTT: executing watcher task
      2023/03/28 19:50:59.619212 [102] created watcher task for plugin MQTT
      2023/03/28 19:50:59.619324 plugin MQTT: executing watcher task
      regards
      Michael​

      Comment

      • Theo63
        Junior Member
        • Aug 2021
        • 8

        #4
        Hi Michael,

        Zabbix 6.2

        This is my setup for MQTT (not MQTTS!) and what I see:

        Marco's on Host:
        {$MQTT.SERVER.TCP} 192.168.77.2
        {$MQTT.TOPIC} msr/#

        Item Type: Zabbix agent (active)
        Key: mqtt.get[{$MQTT.SERVER.TCP},{$MQTT.TOPIC}]

        Agent2 logging with debug level 5
        2023-05-06 12:28:12 2023/05/06 10:28:12.771926 plugin MQTT: executing configurator task
        2023-05-06 12:28:12 2023/05/06 10:28:12.772043 plugin MQTT: executing watcher task
        2023-05-06 12:28:12 2023/05/06 10:28:12.772137 [MQTT] creating client for [tcp://192.168.77.2:1883]
        2023-05-06 12:28:12 2023/05/06 10:28:12.772190 [MQTT] creating new subscriber on topic 'msr/#' for [tcp://192.168.77.2:1883]
        2023-05-06 12:28:12 2023/05/06 10:28:12.772197 [MQTT] establishing connection to [tcp://192.168.77.2:1883]
        2023-05-06 12:33:20 2023/05/06 10:33:20.831343 [MQTT] received publish from [tcp://192.168.77.2:1883] on topic 'msr/0 001 454' got: 0 001 454


        ​Are you sure your item is defined properly?

        Theo

        Comment

        • roteki
          Junior Member
          • Oct 2024
          • 11

          #5
          i have found this file /etc/zabbix/zabbix_agent2.d/plugins.d/mqtt.conf in which i have configured the options, then idk how to continue the configuration, I have read https://www.zabbix.com/fr/integrations/mqtt#mqtt but I couldn't understand quite well what must I do next
          if you can tell me please in details how to configure the plugin
          I'm using zabbix 7.0.5 btw
          Last edited by roteki; 03-12-2024, 18:05.

          Comment

          • roteki
            Junior Member
            • Oct 2024
            • 11

            #6
            i have found this file /etc/zabbix/zabbix_agent2.d/plugins.d/mqtt.conf in which i have configured the options, then idk how to continue the configuration, I have read https://www.zabbix.com/fr/integrations/mqtt#mqtt but I couldn't understand quite well what must I do next
            if you can tell me please in details how to configure the plugin
            I'm using zabbix 7.0.5 btw

            Comment

            • Theo63
              Junior Member
              • Aug 2021
              • 8

              #7
              Create a host pointing to the host where the zabbix agent is running
              Create an item for the host
              type: Zabbix-agent (active)
              key: mqtt.get["tcp://host:1883","path/to/topic"]

              Example:
              key: mqtt.get["tcp://192.168.20.10:1883","tele/tasmota_printers_6F5EEC/SENSOR"]

              Hope this helps.

              Comment

              Working...