Munin IOT4SH01DS

From IOT4 Ltd
Jump to: navigation, search

Munin plugin

#!/bin/sh
#
# Copyright (C) 2017 Robert Juhasz IOT4 Ltd. All rights reserved.
#
# munin plugin that logs temperature from Iot4SH01DS https://www.iot4.eu/
#
# To install the plugin, copy or move the plugin to /usr/share/munin/plugins/ set
# the chmod to 755 and create a symbolic link:
# ln -s /usr/share/munin/plugins/iot4sh01ds_ /etc/munin/plugins/iot4sh01ds_
#
# Configuration variables:
#
#       host    - host (default "localhost")
#       port    - port (default "80")
#       apikey  - apikey (default "111111111111")
#       name    - name (default "IOT4SH01DS")
#
# If your environment has a average temperature which differs from the default
# waring and critical value than feel free to configure the warning and critical value
#
#
#  Author
#  Robert Juhasz
#
# Version 1.0
# April 25, 2017
#
#
#%# family=auto
#%# capabilities=autoconf

# These variables are defined in /etc/munin/plugin-conf.d/munin-node
# Define the host (hostname or IP) and the port
# env.host 192.168.10.1
# env.apikey 8937198372198
# env.name Living room



host=${host:-192.168.10.1}
port=${port:-80}
apikey=${apikey:-111111111111}
name=${name:-IOT4SH01DS}

# Configuration of Munin for graphs and fetching data
if [ "$1" = "config" ]; then
    echo "graph_title IOT4SH01DS Websensor $name"
    echo "graph_info This graph shows the temperature"
    echo "graph_category sensors"
#    echo "graph_args -l 0 -u 100 -r"
    echo "graph_vlabel C"
    echo "tempsens.label Temperature"
    echo "tempsens.warning 19:24"
    echo "tempsens.critical 18:25"
    exit 0
fi

# HTTP GET REQUEST to retrieve the data from the WebSensor
WEBSENS_DATA_FULL=$(printf "GET /api/temperature?apikey=$apikey HTTP/1.1\n Host:$host \n\n" | nc $host $port )

# Selecting line of output (in this case body)
WEBSENS_DATA=$(echo "$WEBSENS_DATA_FULL" | tail -1)

# Custom formatting for each type to trace only necessary
WEBSENS_TEMP=$(echo "$WEBSENS_DATA" | cut -d ' ' -f11 | cut -d 'H' -f1)

# Sending custom formatted data to munin to create the graphs
echo "tempsens.value $WEBSENS_TEMP"

Configuration in the /etc/munin/plugin-conf.d/munin-node file

[iot4sh01ds_dori]
env.host 192.168.10.60
env.apikey 2281D16354422179
env.name Dori


[iot4sh01ds_nappali]
env.host 192.168.10.61
env.apikey 5404851B694FE1DA
env.name Nappali