File: //usr/syno/bin/synoups_battery_notify.sh
#!/bin/sh
. /usr/syno/bin/synoupscommon
if [ "$UpsMode" == "usb" -o "$UpsMode" == "snmp" ];then
UPSC_CMD="$BIN_FILE_UPSC ups@localhost"
else
SERVER_IP=`synogetkeyvalue $SYNOUPS_CONF upsslave_server`
UPSC_CMD="$BIN_FILE_UPSC ups@$SERVER_IP"
fi
RUNTIME_CNT=`$UPSC_CMD | grep -c "battery.runtime"`
if [ $RUNTIME_CNT -ge 1 ];then
RUNTIME_RESULT=`$UPSC_CMD | grep "battery.runtime" | head -1 | cut -d":" -f2`
RUNTIME_RESULT=`expr ${RUNTIME_RESULT/\.*} / 60`
if [ $RUNTIME_RESULT -gt 1 ];then
TIME_UNIT_STRING="dsm:common:time_minutes"
else
TIME_UNIT_STRING="dsm:common:time_minute"
fi
$BIN_SYNONOTIFY UPSOnBattery "{\"%BATTERY_STRING%\":\"dsm:ups:battery_notification\", \"%REMAIN_TIME%\":\"${RUNTIME_RESULT}\", \"%REMAIN_TIME_UNIT%\":\"${TIME_UNIT_STRING}\"}"
else
$BIN_SYNONOTIFY UPSOnBattery "{\"%BATTERY_STRING%\":\" \"}"
fi