I’ve got a couple of Nagios check_* scripts that query Vera over its HTTP interface, for feeding into nagiosgraph.
Edit: Here is my check_vera script:
[code]#!/bin/sh
refreshUserData ()
{
Set user_data2_* variables
userData=$(curl -s “http://${host}:3480/data_request?id=lu_user_data2&output_format=xml”)
eval $(echo “$userData” | xsltproc
–stringparam serviceType “$serviceType”
–stringparam deviceName “$deviceName”
/opt/local/libexec/nagios/user_data2.xsl -)
}
refreshStatus ()
{
statusData=$(curl -s “http://${host}:3480/data_request?id=lu_status2&DeviceNum=$1&LoadTime=$4&DataVersion=$5&timeout=60&minimumdelay=1000&output_format=xml”)
eval $(echo “$statusData” | xsltproc
–stringparam serviceId “$2”
–stringparam variableName “$3”
/opt/local/libexec/nagios/status2.xsl -)
}
usage ()
{
echo “$0 -H host -d device_name -s service_type -v variable_name [-i interval] [-p host service]”
}
Process command-line arguments
while [ $# -gt 0 ]; do
case $1 in
–) break ;;
-h) usage; exit 0 ;;
-H) host=$2; shift 2 ;;
-d) deviceName=$2; shift 2 ;;
-s) serviceType=$2; shift 2 ;;
-v) variableName=$2; shift 2 ;;
-i) continuous=$2; shift 2 ;;
-p) passive=1; passiveHost=$2; passiveService=$3; shift 3 ;;
*) usage; exit 1 ;;
esac
done
Force load of user_data2.
user_data2_LoadTime=0
status2_LoadTime=0
while true; do
if [ “$user_data2_LoadTime” -eq 0 ]; then
refreshUserData
fi
if [ -z “$user_data2_deviceId” ]; then
message=“Device "$deviceName" not found”
exitStatus=3
else
refreshStatus “$user_data2_deviceId” “$user_data2_serviceId” “$variableName” “$status2_LoadTime” “$status2_DataVersion”
# Has user data changed?
if [ "$status2_UserData_DataVersion" -ne "$user_data2_DataVersion" ]; then
user_data2_LoadTime=0
continue
fi
# To do.
exitStatus=0
message="$variableName = $value"
perfdata="|'$variableName'=$value"
fi
if [ -z “$passive” ]; then
echo “$message$perfdata”
else
echo “$(date +%s) PROCESS_SERVICE_CHECK_RESULT;$passiveHost;$passiveService;$exitStatus;$message$perfdata”
fi
if [ -z “$continuous” ]; then
exit $exitStatus;
fi
sleep $continuous;
done
[/code]
And here is how I check a couple of devices:
[code]# Check micasaverde Vera through its port-3480 interface.
define command {
command_name check_vera
command_line /opt/local/libexec/nagios/check_vera -H $HOSTADDRESS$ -d “$ARG1$” -s “$ARG2$” -v “$ARG3$”
}
define service {
use local-service,graphed-service
host_name veralite
service_description Whole house usage
check_command check_vera!Whole house usage!urn:schemas-micasaverde-com:service:EnergyMetering:1!Watts
}
define service {
use local-service,graphed-service
host_name veralite
service_description Solar array generation
check_command check_vera!Solar array generation!urn:schemas-micasaverde-com:service:EnergyMetering:1!Watts
}
[/code]
There are some shortcomings of the code: it doesn’t know what to do when there are two services with the same type (e.g., Cool and Heat setpoints on a thermostat). It also taxes the Vera a bit with all that XML and should really be using JSON. I poll only once every 5 minutes personally so I’m not it a rush to fix this.