diff --git a/bundles/tasmota-charge/files/telegraf-plugin b/bundles/tasmota-charge/files/telegraf-plugin new file mode 100644 index 0000000..b062df7 --- /dev/null +++ b/bundles/tasmota-charge/files/telegraf-plugin @@ -0,0 +1,18 @@ +#!/bin/bash + +PLUG_IP=${plug_ip} + +PLUG_IS=$(curl -s "http://$PLUG_IP/cm?cmnd=Power" | jq -r .POWER) + +if [[ $PLUG_IS = ON ]] +then + STATE=1 +elif [[ $PLUG_IS = OFF ]] +then + STATE=0 +else + echo "unknown state: '$PLUG_IS'" + exit 1 +fi + +echo "tasmota_charge,host=${node.name} state=$STATE $(date --utc +%s%N)" diff --git a/bundles/tasmota-charge/items.py b/bundles/tasmota-charge/items.py index ce7f8d8..818d957 100644 --- a/bundles/tasmota-charge/items.py +++ b/bundles/tasmota-charge/items.py @@ -11,4 +11,12 @@ files = { 'max': node.metadata.get('tasmota-charge/plug/max'), } }, + '/usr/local/share/icinga/plugins/tasmota_charge': { + 'content_type': 'mako', + 'source': 'telegraf-plugin', + 'mode': '0755', + 'context': { + 'plug_ip': node.metadata.get('tasmota-charge/plug/ip'), + } + }, } diff --git a/bundles/tasmota-charge/metadata.py b/bundles/tasmota-charge/metadata.py index 9a438b5..4317ecf 100644 --- a/bundles/tasmota-charge/metadata.py +++ b/bundles/tasmota-charge/metadata.py @@ -9,5 +9,26 @@ defaults = { 'command': f'/usr/bin/sudo -u tasmota-charge /opt/tasmota-charge', 'when': 'minutely', }, - } + }, } + + +@metadata_reactor.provides( + 'telegraf/config/inpus/exec', +) +def telegraf(metadata): + return { + 'telegraf': { + 'config': { + 'inputs': { + 'exec': { + repo.libs.hashable.hashable({ + 'commands': ["/usr/local/share/icinga/plugins/tasmota_charge"], + 'name_override': "tasmota_charge", + 'data_format': "influx", + }), + }, + }, + }, + }, + }