Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,11 @@ All data received from the sensor is stored in a list and transmitted sequential

## Send metrics to Prometheus

[Read instruction about integartion with Prometheus Push Gateway](./prometheus/README.md)
[Read instruction about integration with Prometheus Push Gateway](./prometheus/README.md)

## Send metrics to Zabbix

[Read instruction about integration with Zabbix](sendToZabbix.README.md)

## Node-RED flows
Finally there are flows for Node-RED. Especially if you have multiple receivers this is quite comfortable to manage the name and calibration data of your sensors at one place in Node-Red. No need to change configuration in any of your receivers. Note: If you use encrypted mode you need to provide the decryption key in a device list file on every receiver. Tip: Use Ansible to deploy updated lists on all receivers.
Expand Down
59 changes: 59 additions & 0 deletions sendToZabbix.README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Callback - sendToZabbix.sh

## Configuration
Script uses default values if no configuration file was found.
Options:

| Option | Default | Comments |
|---|---|---|
| ZBX_ADDRESS | localhost | Zabbix Server/Proxy IP/FQDN |
| ZBX_PORT | 10051 | Zabbix Server/Proxy Port |
| TLS_CONNECT | | TLS Settings - currently only **psk** supported<br />if this option exists, all other PSK Options also needed |
| TLS_PSK_IDENTITY | | PSK identity name which is used in Zabbix |
| TLS_PSK_FILE | | Path to PSK key file<br />The file may only contain the psk secret/password. See *zabbix_sender --help* |

### Example sendToZabbix.conf

ZBX_ADDRESS=zbx.domain.tld
ZBX_PORT=10051
TLS_CONNECT=psk
TLS_PSK_IDENTITY=MiTemperature2
TLS_PSK_FILE=sendToZabbix.psk

## Zabbix Template
sendToZabbix.sh uses the sensor name as host name in Zabbix. If there is no devicelistfile defined the MAC address is used as host name. But Zabbix don't allow ':' in host names. So the script strip them out.
Sensor Name "aa:bb:cc:dd:ee:ff" is changed to "**aabbccddeeff**".

[YAML Export of Template](sendToZabbix.template.yaml)

### Items

* Sensor - Battery - Level
* Sensor - Battery - Voltage
* Sensor - Humidity
* Sensor - Temperature

### Triggers

* based on Item values
* Battery level < {$BATTERY_LEVEL_MIN}%
* based on nodata()
* Missing data - battery level
* Missing data - battery voltage
* Missing data - humidity
* Missing data - temperature

#### Macros are defined on template level
* {$BATTERY_LEVEL_MIN} - 20
* {$NODATA_DELAY} - 900
* context sensitive macros possible like
* {$NODATA_DELAY:battery_level}
* {$NODATA_DELAY:battery_voltage}
* {$NODATA_DELAY:humidity}
* {$NODATA_DELAY:temperature}

### Graphs

* Temperature & Humidity
* Temperature as Line with axis on the left
* Humidity as filled region with axis on the right
53 changes: 44 additions & 9 deletions sendToZabbix.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
#!/bin/bash

# Zabbix Server or Proxy Address
zabbix_address=127.0.0.1
item_key=LYWSD03MMC.callback
set -e

host=$2
temp=$3
hum=$4
bat_vol=$5
bat_lvl=$6
##################################################### Config

# Default values if no config exists
ZBX_ADDRESS=localhost
ZBX_PORT=10051

SCRIPT_DIR=$(dirname ${0})
if [[ -f ${SCRIPT_DIR}/sendToZabbix.conf ]]; then
. ${SCRIPT_DIR}/sendToZabbix.conf
fi

##################################################### TLS

TLS_PARAMS=''
if [[ "${TLS_CONNECT}" == "psk" ]]; then
if [[ ! -f ${TLS_PSK_FILE} ]]; then
if [[ -f ${SCRIPT_DIR}/${TLS_PSK_FILE} ]]; then
TLS_PSK_FILE=${SCRIPT_DIR}/${TLS_PSK_FILE}
else
echo "File not found: ${TLS_PSK_FILE}"
exit 1
fi
fi
TLS_PARAMS=(--tls-connect psk --tls-psk-identity ${TLS_PSK_IDENTITY} --tls-psk-file ${TLS_PSK_FILE})
fi

##################################################### Data preparation

# removes ':' from sensor name in caseof MAC address is used
ZBX_HOST=${2//:/}

# value mapping
TEMPERATURE=${3}
HUMIDITY=${4}
BATTERY_VOLTAGE=${5}
BATTERY_LEVEL=${6}

##################################################### Transfer

echo "${ZBX_HOST} MiTemperature2.battery_level ${BATTERY_LEVEL}
${ZBX_HOST} MiTemperature2.battery_voltage ${BATTERY_VOLTAGE}
${ZBX_HOST} MiTemperature2.humidity ${HUMIDITY}
${ZBX_HOST} MiTemperature2.temperature ${TEMPERATURE}" | zabbix_sender -z ${ZBX_ADDRESS} -p ${ZBX_PORT} -s - -i - ${TLS_PARAMS[@]}

echo $host $item_key "Temperature: $temp; Humidity: $hum; Battery voltage: $bat_vol V; Battery level: $bat_lvl" | zabbix_sender -z $zabbix_address -r -i -
132 changes: 132 additions & 0 deletions sendToZabbix.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
zabbix_export:
version: '6.0'
date: '2022-03-27T21:00:48Z'
groups:
-
uuid: 7df96b18c230490a9a0a9e2307226338
name: Templates
templates:
-
uuid: d9debf65f58141a8ae09d6d87dad3b5c
template: trapper.mitemperature2
name: trapper.mitemperature2
groups:
-
name: Templates
items:
-
uuid: 70e54948a8924d1a8a175e0a1aea48b7
name: 'Sensor - Battery - Level'
type: TRAP
key: MiTemperature2.battery_level
delay: '0'
history: 7d
value_type: FLOAT
units: '%'
preprocessing:
-
type: DISCARD_UNCHANGED_HEARTBEAT
parameters:
- '300'
triggers:
-
uuid: e4bfa31cccae490cac0840e92def4b07
expression: 'max(/trapper.mitemperature2/MiTemperature2.battery_level,900)<{$BATTERY_LEVEL_MIN}'
recovery_mode: RECOVERY_EXPRESSION
recovery_expression: 'min(/trapper.mitemperature2/MiTemperature2.battery_level,900)>{$BATTERY_LEVEL_MIN}'
name: 'Battery level < {$BATTERY_LEVEL_MIN}%'
priority: WARNING
-
uuid: b79d0cdfccfe4cd4a5d215ba3997e6f8
expression: 'nodata(/trapper.mitemperature2/MiTemperature2.battery_level,{$NODATA_DELAY:battery_level})=1'
name: 'Missing data - battery level'
priority: WARNING
-
uuid: ec0e2009c76448c8a1b9b3cb8c0cb114
name: 'Sensor - Battery - Voltage'
type: TRAP
key: MiTemperature2.battery_voltage
delay: '0'
history: 7d
value_type: FLOAT
units: V
preprocessing:
-
type: DISCARD_UNCHANGED_HEARTBEAT
parameters:
- '300'
triggers:
-
uuid: df7d62e0eeb848b2ade6b5d577744f95
expression: 'nodata(/trapper.mitemperature2/MiTemperature2.battery_voltage,{$NODATA_DELAY:battery_voltage})=1'
name: 'Missing data - battery voltage'
priority: WARNING
-
uuid: e635c65ae1d24b09880413f785870331
name: 'Sensor - Humidity'
type: TRAP
key: MiTemperature2.humidity
delay: '0'
history: 7d
value_type: FLOAT
units: '%'
preprocessing:
-
type: DISCARD_UNCHANGED_HEARTBEAT
parameters:
- '300'
triggers:
-
uuid: fa180292fe044fbb8765ea413043c6b7
expression: 'nodata(/trapper.mitemperature2/MiTemperature2.humidity,{$NODATA_DELAY:humidity})=1'
name: 'Missing data - humidity'
priority: WARNING
-
uuid: 6b271c67ceda4b1ebdfd827104ad4f44
name: 'Sensor - Temperature'
type: TRAP
key: MiTemperature2.temperature
delay: '0'
history: 7d
value_type: FLOAT
units: °C
preprocessing:
-
type: DISCARD_UNCHANGED_HEARTBEAT
parameters:
- '300'
triggers:
-
uuid: 65138c7a29ad4c82ac9bf75aca5af711
expression: 'nodata(/trapper.mitemperature2/MiTemperature2.temperature,{$NODATA_DELAY:temperature})=1'
name: 'Missing data - temperature'
priority: WARNING
macros:
-
macro: '{$BATTERY_LEVEL_MIN}'
value: '20'
description: 'Minimum battery level'
-
macro: '{$NODATA_DELAY}'
value: '900'
description: 'Seconds of delay for sensor nodata triggers'
graphs:
-
uuid: 304656eb8cf64917a0c778518595b241
name: 'Temperature & Humidity'
graph_items:
-
drawtype: FILLED_REGION
color: 29B6F6
yaxisside: RIGHT
item:
host: trapper.mitemperature2
key: MiTemperature2.humidity
-
sortorder: '1'
drawtype: BOLD_LINE
color: F63100
item:
host: trapper.mitemperature2
key: MiTemperature2.temperature