„Let me subscribe“Zabbix masters IoT Topics

Contact: Wolfgang AlperIntelliTrend IT-Services GmbHwolfgang.alper@intellitrend.deOtto-Brenner-Strasse 119
D-33607 Bielefeld, Germany© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.dewww.intellitrend.de„Let me subscribe“
What is this all about

https://support.zabbix.com/browse/ZBXNEXT-3950
For „Modbus“ support, see also:
https://support.zabbix.com/browse/ZBXNEXT-6090
https://support.zabbix.com/browse/ZBXNEXT-6093© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de2„Let me subscribe“
What is this all about
Cool, but what is MQTT?

© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de3„Let me subscribe“
MQTT basics
MQTT = „Message Queuing Telemetry Transport“.

Invented in 1999, designed to be bandwidth-efficient andlightweight, thus battery efficient.
ISO standard: ISO/IEC 20922. (https://www.iso.org/standard/69466.html)
Rapidly increasing adoption because of its suitability forInternet of Things (IoT), sensor networks, home automation,machine-to-machine (M2M) and mobile applications.
Usually runs over TCP/IP, Ports 1883 / 8883 (encrypted).
Encryption requires TLS transport.
© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de4„Let me subscribe“
MQTT basics
Variation MQTT-SN (MQTT for Sensor Networks):
Variant for non-TCP/IP networks like Zigbee (IEEE 80215.4
radio based protocol) or other UDP / Bluetooth based
implementations.
Based on a „publish“ / „subscribe“ to „topic“ mechanism.
2 types of network entities: „Message broker“ and „Clients“.
Supports 3 QoS levels:●0: At most once – „Fire and forget“.
●
1: At least once – Could be sent/delivered multiple times.
●
2: Exactly once – Safest and slowest service.
© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de5„Let me subscribe“Publish / subscribe
Subscribe
office/temp
office/hum

Client-1
Client-1

Client-2
Client-2

Publishoffice/temp:25

PublishClient-3
Client-3

Publish

MQTT
MQTT
Message
Message
BrokerBrokeroffice/hum:42
office/iaq:110

office/temp:25
office/hum:42

Subscribe
office/hum
office/iaq

Client-4
Client-4Publish

Topic 1 (2 levels): office/temp
Topic 2 (2 levels): office/hum© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.deoffice/hum:42
office/iaq:110

6„Let me subscribe“
Combined pub/sub
Subscribe

Client-1
Client-1

Client-2
Client-2

Publishoffice/brightness:1500

MQTT
MQTT
Message
Message
BrokerBrokerSubscribe
office/lightctr

office/brightness
PublishClient-3
Client-3

office/brightness:1500
Publishoffice/lightctr:incr

Publishoffice/lightctr:incr© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de7„Let me subscribe“
Wildcards subs

Subscribe
office/+/brightness/
PublishClient-1
Client-1

Client-2
Client-2

office/confroom/brightness:1500

Publishoffice/confroom/brightness:1500

Publish

MQTT
MQTT
Message
Message
BrokerBrokeroffice/kitchen/brightness:1600
Subscribe
office/kitchen/#office/kitchen/brightness:1600
office/kitchen/
temp:24

Client-3
Client-3

Publish+ = single level# = multi level© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.deoffice/kitchen/brightness:1600

Client-4
Client-4

office/kitchen/
temp:24
8

„Let me subscribe“
MQTT - Summary
Clients can publish and subscribe to one or more topics.
One client can publish and subscribe at the same time.

Clients can subscribe using single/multi level wildcards.

Clients can choose between three different QoS levels.
Advanced features:
Messages can be retained on the broker for new subscribers.

Clients can provide a “last will and testament” that will be
published by the broker when the client “dies”.
© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de9„Let me subscribe“
What is this all aboutOk, but where does
Zabbix come into play?

© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de10„Let me subscribe“Real world example – Simple Setup
Server Room

Training Room

office/bielefeld/serverroom
office/bielefeld/trainingroom
Published Topics

Publishoffice/bielefeld/salesroom
office/bielefeld/supportroom
MQTT
Message Broker

Sales RoomSupport Roommosquitto: https://mosquitto.org/© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de

Subscribe

HomeAutomation
11

„Let me subscribe“Real world example – Simple Setup
Server Room

Training RoomSubscribe

office/bielefeld/serverroom
office/bielefeld/trainingroom

Zabbix 5.2 Agent 2

Published Topics

Publishoffice/bielefeld/salesroom
office/bielefeld/supportroom
MQTT
Message Broker

Sales RoomSupport Room

Zabbix as a subscriber© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de12„Let me subscribe“Real world example – Simple Setup
Server Room

Training Room
Subscribe

office/bielefeld/serverroom
office/bielefeld/trainingroom

Zabbix 5.2 Agent 2

Published Topics

Publishoffice/bielefeld/salesroom
office/bielefeld/supportroom
MQTTMessage Broker

Sales RoomSupport RoomMultiple clients© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de

Subscribe

HomeAutomation
13

„Let me subscribe“Real world example – Flow handlingServer Room

Training Room

PublishSubscribe
Subscribe

office/bielefeld/serverroom
office/bielefeld/trainingroom

Zabbix 5.2 Agent 2

Published Topics

office/bielefeld/salesroom
office/bielefeld/supportroom
MQTT
Message Broker

Flow-based
programming tool

PublishSales RoomSupport Room

Data Processing in Node-RED© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.deSubscribe

HomeAutomation
14

„Let me subscribe“Real world example – Flow handlingServer Room

Training Room

PublishSubscribe
Subscribe
Publishoffice/bielefeld/serverroom
office/bielefeld/trainingroom

Zabbix 5.2 Agent 2

Published Topics

office/bielefeld/salesroom
office/bielefeld/supportroom
MQTT
Message Broker

Flow-based
programming tool

PublishSales RoomSupport Room

Zabbix publishes data to broker© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de

Subscribe

HomeAutomation
15

„Let me subscribe“Real world example – Flow handlingServer Room

Training RoomPublish
Subscribe
Subscribe

office/bielefeld/serverroom
office/bielefeld/trainingroom

Zabbix 5.2 Agent 2

Published Topics

office/bielefeld/salesroom
office/bielefeld/supportroom
MQTT
Message Broker

Flow-based
programming tool

PublishSales Room

Subscribe

Support RoomMultiple Zabbix servers share same data
© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.deZabbix 5.2 Agent 216

„Let me subscribe“
What is Node-RED?
Construction kit for the Internet of Things and home automation.
Acts as MQTT client, can publish and subscribe.
Flow-based tool for visual programming based on Node.js.
Graphical web editor.
Supports input, processing and output nodes.
Extensible with plugins and custom function nodes.
© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de17„Let me subscribe“
Node-RED – Simple Subscription

Node-RED: https://nodered.org/© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de18

„Let me subscribe“Sensor data
Raw JSON string

Parsed JSON object

Multiple metrics in one message© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de19„Let me subscribe“
Options to process multiple metrics

Split on MQTT level:
Use Node-RED to split metrics and then publish them in theirown topics. Good if there are other clients that can handle
only a single metric at a time.
Split on Zabbix level:
Use Zabbix JSON pre-processing with corresponding
dependant items. Zabbix would just need one subscription.
Combine both methods:
Let other clients subscribe to a single metric using their
specific topic, but also publish all sensor data for Zabbix inone topic.
© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de20

„Let me subscribe“
Split metrics on MQTT level
Node setup●●●

Node properties (temperature)

Debug output

Using JSONata expressions to extract metrics.
Append sensor name to original topic.
Publish to new topic in node message.

Splitting data in Node-RED© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de21

„Let me subscribe“
Implementation
Zabbix side of things ...

© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de22

„Let me subscribe“
How to use the new MQTT keymqtt.get[<broker_url>,topic,<username>,<password>]
Requires Agent 2.
Requires active checks.
Broker URL default is localhost.
User name and password are optional.
Uses Eclipse Paho Go client library.
© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de23

„Let me subscribe“
Agent active - send to multiple hosts
One Zabbix agent active needs to send data to multiple hosts ...
Mapping: Topics to Zabbix hosts

Zabbix 5.2 Agent 2

office/bielefeld/salesroom
office/bielefeld/serverroomoffice/bielefeld/supportroom
office/bielefeld/trainingroom

im.ims-040B0BBF713C
im.ims-603E9BC40A24
im.ims-80D478BF713C
im.ims-94B71112CFA4Zabbix 5.2 Server

Hostname=im.ims-040B0BBF713C,im.ims-603E9BC40A24,im.ims-80D478BF713C,im.ims-94B71112CFA4© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de24

„Let me subscribe“
Split metrics on Zabbix level
Master Item

Dependent Item

Dependent Item Preprocessing© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de25

„Let me subscribe“Master item and dependent items© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de26

„Let me subscribe“Sensor data dashboard© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de27

„Let me subscribe“Publish from Zabbix
Bonus:
Publish the outcome of a Zabbix trigger,
so it can be consumed by other
MQTT based devices© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de28

„Let me subscribe“Publish from Zabbix
Simple media type to send
problems to the topic:#!/bin/sh
mosquitto_pub -h yourbroker.io -m "$1" -t "zabbix/problems/$2"

zabbix/problems/<user>© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de29

„Let me subscribe“Publish from Zabbix
JSON problem template:

JSON problem recovery template:{{}"type": "problem","start-date": "{EVENT.DATE}","start-time": "{EVENT.TIME}","name": "{EVENT.NAME}","host": "{HOST.NAME}","severity": "{EVENT.SEVERITY}","opdata": "{EVENT.OPDATA}","event-id": {EVENT.ID},"trigger-url": "{TRIGGER.URL}"}"type": "recovery","recovery-date": "{EVENT.RECOVERY.DATE}","recovery-time": "{EVENT.RECOVERY.TIME}","name": "{EVENT.NAME}","duration": "{EVENT.DURATION}","host": "{HOST.NAME}","severity": "{EVENT.SEVERITY}","opdata": "{EVENT.OPDATA}","event-id": {EVENT.ID},"trigger-url": "{TRIGGER.URL}"© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de30

„Let me subscribe“Publish from Zabbix
Zabbix problems are now published via MQTT.

Publishzabbix/problems/admin

Any MQTT subscriber, like Node-RED, receives the alert.
© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de31

„Let me subscribe“Publish from Zabbix
IoT devices and other subscribers can react to issues detected by Zabbix using Node-RED!

© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de32„Let me subscribe“
Try it out – Live broker available
https://github.com/intellitrend/zabbix-iot-mqtt© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.de33

„Let me subscribe“Zabbix masters IoT Topics

Thank You!

Contact: Wolfgang AlperIntelliTrend IT-Services GmbHwolfgang.alper@intellitrend.deOtto-Brenner-Strasse 119
D-33607 Bielefeld, Germany© Copyright 2020 IntelliTrend GmbH ● Germany ● www.intellitrend.dewww.intellitrend.de