Doing this kind of monitoring through a shell environment does create
significant overhead, and bdsm is not recommended any production uses.
It may be useful for certain niche hardware and software applications,
-and as an experiment in shell scripting.
+and as an experiment in shell scripting. It also isn't quite functional
+yet....
0) PREREQUISITES
1) INSTALLATION INSTRUCTIONS
-Create a new user named bdsm and clone the repository into this user's home
-directory.
+Create a new user named 'bdsm' and extract the latest bdsm snapshot to this
+user's home directory:
+
+useradd bdsm
+sudo su - bdsm
+wget -O bdsm.tar.gz "https://git.slightlycyberpunk.com/?p=bdsm.git;a=snapshot;h=HEAD;sf=tgz"
+
+mv bdsm*/* .
+rmdir bdsm*
+
2) CONFIGURATION
Login as the bdsm user
Configure your infrastructure with:
-~/bdsm.sh configure
+~/bin/bdsm.sh configure
Then deploy the required components to all downstream hosts with:
-~/bdsm.sh deploy
+~/bin/bdsm.sh deploy
3) USAGE
--- /dev/null
+#!/bin/bash
+################################################################################
+#
+# DS18B20.raspi
+# Bash Daemon for System Monitoring
+# Plugin for monitoring DS18B20 temperature sensors connected to a Raspberry Pi
+# Hardware should be connected and configured as described at:
+# https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/overview
+#
+#
+###############################################################################
+
+# TRAP UNKNOWN ERRORS
+###############################################################################
+trap failure SIGTERM SIGINT SIGFPE
+
+failure()
+{
+ error "Something has gone SERIOUSLY wrong! (Received signal $?)"
+ return 255
+}
+
+error()
+{
+ printf "\e[41m" 1>&2
+ printf "ERROR: $1" 1>&2
+ printf "\e[0m\n" 1>&2
+}
+
+# VARIABLES
+###############################################################################
+SCRIPT=$0
+HOSTNAME=$2
+DELAY=$3
+SENSOR-ID="${4}"
+OUTPATH=/home/bdsm/out.fifo
+
+# MAIN FUNCTIONS
+###############################################################################
+help()
+{
+ echo "DS18B20 temperature monitoring for Raspberry Pi systems"
+ echo "USAGE: $0 [FUNCTION] [HOSTNAME] [DELAY] [SENSOR-ID]"
+ echo "FUNCTION -- start/stop/status/help"
+ echo "HOSTNAME -- the hostname to monitor"
+ echo "::DELAY -- seconds between measurements"
+ echo "::SENSOR-ID -- the serial number of the sensor to read"
+ exit 0
+}
+
+start()
+{
+ running=`ssh -q $HOSTNAME "cat /home/bdsm/pids/DS18B20.pid 2>/dev/null | \
+ xargs ps -p 2>/dev/null | \
+ grep -v PID | \
+ wc -l"` 2>/dev/null
+
+ if [ $running -eq 0 ] || [ $running -gt 5 ]; then
+ # Check if the hardware is installed
+ installed=`ssh -q $HOSTNAME "cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves | grep '^28' | wc -l"`
+ if [ $installed == 0 ]; then
+ echo "" > $OUTPATH
+ return 1
+ fi
+
+ ssh -q $HOSTNAME <<EOF
+ while [ 1 ]; do
+ ts=\`date '+%s'\`
+
+ awk -v ts="\$ts" -v host="\$HOSTNAME" \
+ '/t=/ { split(FILENAME, filearr, "[/-]"); split(\$10, temparr, "");
+ print ts "|" host "|" filearr[7] "|" temparr[3] temparr[4] "." temparr[5] }' \
+ /sys/bus/w1/devices/28-*/w1_slave
+ sleep $DELAY
+ done >> $OUTPATH &
+ echo \$! > /home/bdsm/pids/DS18B20.pid
+EOF
+ else
+ echo "Already Running"
+ fi
+}
+
+stop()
+{
+ ssh $HOSTNAME 'kill `cat /home/bdsm/pids/DS18B20.pid`'
+ ssh $HOSTNAME 'rm /home/bdsm/pids/DS18B20.pid'
+}
+
+status()
+{
+ running=`ssh $HOSTNAME "cat /home/bdsm/pids/DS18B20.pid 2>/dev/null | \
+ xargs ps -p 2>/dev/null | \
+ grep -v PID | \
+ wc -l"`
+
+ if [ -z "$running" ]; then
+ running=0
+ fi
+ if [ $running -eq 0 ]; then
+ echo "OFF"
+ else
+ echo "ON"
+ fi
+}
+
+compatible()
+{
+ compatible="`ssh -q -n $HOSTNAME 'cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves | grep \"^28\" | wc -l' 2>/dev/null`"
+ if [ "$compatible" -gt 0 ]; then
+ echo 0
+ else
+ echo 1
+ fi
+}
+
+# SCRIPT START
+###############################################################################
+
+if [ -z $1 ]; then
+ help
+elif [ $1 == "start" ]; then
+ start
+elif [ $1 == "stop" ]; then
+ stop
+elif [ $1 == "status" ]; then
+ status
+elif [ $1 == "compatible" ]; then
+ compatible
+elif [ $1 == "help" ]; then
+ help
+fi
start()
{
- cat /home/bdsm/in.fifo | grep '.*|.*|.*|.*' >> /home/bdsm/bdsm.out &
+ cat /home/bdsm/in.fifo | grep '.*|.*|.*|.*' --line-buffered >> /home/bdsm/bdsm.out &
echo $! > /home/bdsm/pids/file.processor.pid
+
+ # Check if it failed to write the pid...
+ if [ ! -s /home/bdsm/pids/file.processor.pid ]; then
+ ps -ef | grep in.fifo | grep -v grep | awk '{print $2}' > /home/bdsm/pids/file.processor.pid
+ fi
+
+ # Check if it failed to start...
+ if [ ! -s /home/bdsm/pids/file.processor.pid ]; then
+ error "File processor was unable to start."
+ return 1
+ fi
+ nohhup logrotation &
}
stop()
fi
}
+logrotation()
+{
+ hours=`date +%H`
+ minutes=`date +%M`
+ hourdiff=`expr 23 - $hours`
+ mindiff=`expr 59 - $minutes`
+ diff=`expr $hourdiff \* 3600 + $mindiff \* 60`
+
+ filedate=`date +%Y%m%d`
+
+ if [ -s /home/bdsm/bdsm.out ]; then
+ mv /home/bdsm/bdsm.out /home/bdsm/bdsm.$filedate.out
+ touch /home/bdsm/bdsm.out
+ fi
+
+ sleep $diff && logrotation
+}
+
# SCRIPT START
###############################################################################
if [ -z $1 ]; then