#!/bin/bash # -*- sh -*- : << =cut =head1 NAME switchbotmeter_multi - Munin plugin to monitor temperature and humidity with SwitchBot Meter =head1 CONFIGURATION Obtain a token, secret and deviceid for SwitchBot API. See the following website. https://github.com/OpenWonderLabs/SwitchBotAPI =head1 ENVIRONMENT VARIABLES env.token : Token to access SwitchBot API. (Required) env.secret : Secret to access SwitchBot API. (Required) env.deviceid : Device ID(s) of SwitchBot Meter separated by white space. (Required) env.interval : Interval in seconds for API access. (Optional, default is 0) =head1 NOTES The amount of SwitchBot API calls per day is limited to 10000 times. If munin-node executes this plugin every 5 minutes, the API will be called 288 times a day. You can use env.interval parameter to prevent frequent API access. For example, if you set env.interval 900, the API response will be cached to local file for 900 seconds(15 minutes). =head1 AUTHOR K.Cima https://github.com/shakemid =head1 LICENSE GPLv2 SPDX-License-Identifier: GPL-2.0-only =head1 Magic markers #%# family=contrib #%# capabilities= =cut . "${MUNIN_LIBDIR}/plugins/plugin.sh" set -o nounset set -o pipefail # Token to access SwitchBot API token=${token:?} # Secret to access SwitchBot API secret=${secret:?} # Device ID of SwitchBot Meter deviceids=${deviceid:?} # Interval for API access (second) interval=${interval:-0} # Plugin Name pluginname=$( basename "$0" ) config() { local deviceid cat <&2 exit 1 fi temperature=$( echo "${response}" | jq '.body.temperature' ) humidity=$( echo "${response}" | jq '.body.humidity' ) battery=$( echo "${response}" | jq '.body.battery' ) echo temperature_${deviceid}=${temperature} humidity_${deviceid}=${humidity} battery_${deviceid}=${battery} } # Main case ${1:-} in config) config if [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ]; then fetch fi ;; *) fetch ;; esac exit 0