UniverseDevel / zabbix-templates

Collection of Zabbix templates grouped by brand.
MIT License
2 stars 0 forks source link

mqtt announce #1

Closed Elbandi closed 3 years ago

Elbandi commented 3 years ago

Hi,

my shelly plug is behind a home router, no direct access from internet and i can setup a zabbix proxy. So i have to use the mqtt templates. but

Template requires regular publishing of payload "announce" to topic "shellies/command" for Shelly devices to collect their data and publish them to broker in "shellies/*/info" topic.

First i wanted to solve this by a cron. simply... Later i got an idea how to use zabbix for this. I added a custom "fake" check to send the announce message:

UserParameter=mqtt.pub[*],/usr/bin/mosquitto_pub -h mqtt_server_ip -t "$2" -u "$3" -p "$4" -m "$5" && echo "OK"

(currently the mqtt server ip is hardcoded. The $1 paramter is mqtt broker host from zabbix, but need to convert the right format... i skipped this, because i have one mqtt server)

And created a dummy item to call this "check" (X sec update interval, 0 history/trend):

mqtt.pub[{$MQTT_BROKER_HOST},shellies/{$MQTT_DEVICE_ID}/command,{$MQTT_BROKER_USER},{$MQTT_BROKER_PASS},announce]

With this, i can configure the update interval in zabbix, and no need a third party (=cron) to send the command.

UniverseDevel commented 3 years ago

Hi,

Your solution is one of many and it is good. I currently use cron and I tried also solution that you mentioned before. When distributing templates I did not want them to contain any custom solutions/external scripts or dependencies, and your solution has a prerequisite of mosquito binaries installed and user parameters configured.

Anyway it is a good solution and is worth noting, but I find Issue to be a wrong place to do so. I unlocked a Wiki section so you can add your solution there and I will link it from readme file.

UniverseDevel commented 3 years ago

Also just for information, in the feature MQTT template will be discarded and new templates will contain a simple change in one item to choose between HTTP or MQTT monitoring. I am testing this way now and it will allow to maintain single template for both of solutions to avoid duplicate work and differences.

UniverseDevel commented 3 years ago

Your suggestion was added to Wiki and I linked it from readme file.