Giter Site home page Giter Site logo

zbx_plugin_mqtt's Introduction

Zabbix agent2 MQTT subscriber plugin

Zabbix agent2 plugin(watcher) implementing MQTT.

image

Build

Make sure golang is installed and properly configured.

Checkout zabbix:
git clone https://git.zabbix.com/scm/zbx/zabbix.git --depth 1 zabbix-agent2
cd zabbix-agent2
Checkout this plugin repo:
git submodule add https://github.com/v-zhuravlev/zbx_plugin_mqtt.git src/go/plugins/mqtt

Edit file src/go/plugins/plugins.go by appending _ "zabbix.com/plugins/mqtt":

package plugins

import (
	_ "zabbix.com/plugins/log"
	_ "zabbix.com/plugins/systemrun"
	_ "zabbix.com/plugins/zabbix/async"
	_ "zabbix.com/plugins/zabbix/stats"
	_ "zabbix.com/plugins/zabbix/sync"
	_ "zabbix.com/plugins/mqtt"
)

./bootstrap.sh
pushd .
cd src/go/
go mod vendor
popd
Apply patches:
git apply src/go/plugins/mqtt/patches/manager.patch
(see this upstream PR):
git apply src/go/plugins/mqtt/patches/router.patch
./configure --enable-agent2 --enable-static
make

You will then find new agent with plugin included in src/go/bin dir

Test it by running ./zabbix-agent2 -t agent.ping -c ../conf/zabbix_agent2.conf

Configuration

In zabbix_agent2.conf:

  • set ServerActive= to IP of your Zabbix server or proxy
  • set Hostname= to host name you will use in Zabbix.
  • (optional) set MQTT name and password, if required by your broker:
Plugins.MQTTSubscribe.Username=<username here>
Plugins.MQTTSubscribe.Password=<password here>
  • (optional) set MQTT ClientID. If not set, ClientID will be generated automatically.
Plugins.MQTTSubscribe.ClientID=zabbix-agent2-mqtt-client
  • (optional) set MQTT Connection timeout in seconds. If not set, global Zabbix agent Timeout= will be used.
Plugins.MQTTSubscribe.Timeout=5

Supported keys

mqtt.subscribe

mqtt.subscribe[<MQTT broker URL>,<MQTT topic>]

for example:

mqtt.subscribe[tcp://192.168.1.1:1883,devices/+/values]

Item must be of type Zabbix agent(active).
Also note, that update interval is ignored, values will be received once published to the MQTT broker. Still, try to set update interval as closer as possible to the data update frequency, so you get proper graphs in Zabbix.

image

Troubleshooting

Change LogType=console and DebugLevel=4 in config file.

Known problems and limitations

  • Only Zabbix agent (active) is supported, thus impossible to use single Zabbix agent2 with multiple hosts. Waiting for Passive bulk implementation in Zabbix.
  • Global timeout is ignored if there are no plugin specific options are defined https://support.zabbix.com/browse/ZBX-17070

Next steps

  • disconnect MQTT clients when there is no active mqtt.subscribe
  • move mqtt.get to separate plugin so no Exporter invocation
  • make user + password configurable in config file
  • validate item params

and perhaps...

Changelog

v0.1

Initial version

Read more

https://medium.com/@zhuravlev.vitaly/writing-watcher-zabbix-agent2-mqtt-plugin-in-go-e00067ea1990

zbx_plugin_mqtt's People

Contributors

v-zhuravlev avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.