mirror of
https://github.com/Spearfoot/FreeNAS-scripts
synced 2025-12-06 01:23:19 +00:00
POSIX-compliant version
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/sh
|
||||||
|
|
||||||
# Send UPS report to designated email address
|
# Send UPS report to designated email address
|
||||||
# Reference: http://networkupstools.org/docs/developer-guide.chunked/apas01.html
|
# Reference: http://networkupstools.org/docs/developer-guide.chunked/apas01.html
|
||||||
@@ -13,8 +13,9 @@ email=""
|
|||||||
senddetail=0
|
senddetail=0
|
||||||
|
|
||||||
freenashost=$(hostname -s)
|
freenashost=$(hostname -s)
|
||||||
|
freenashostuc=$(hostname -s | tr '[:lower:]' '[:upper:]')
|
||||||
logfile="/tmp/ups_report.tmp"
|
logfile="/tmp/ups_report.tmp"
|
||||||
subject="UPS Status Report for ${freenashost^^}"
|
subject="UPS Status Report for ${freenashostuc}"
|
||||||
|
|
||||||
### Set email headers ###
|
### Set email headers ###
|
||||||
(
|
(
|
||||||
@@ -22,38 +23,9 @@ subject="UPS Status Report for ${freenashost^^}"
|
|||||||
echo "Subject: ${subject}"
|
echo "Subject: ${subject}"
|
||||||
echo "Content-Type: text/html"
|
echo "Content-Type: text/html"
|
||||||
echo "MIME-Version: 1.0"
|
echo "MIME-Version: 1.0"
|
||||||
echo -e "\r\n"
|
printf "\r\n"
|
||||||
) > ${logfile}
|
) > ${logfile}
|
||||||
|
|
||||||
declare ups_type
|
|
||||||
declare ups_mfr
|
|
||||||
declare ups_model
|
|
||||||
declare ups_serial
|
|
||||||
declare ups_load
|
|
||||||
declare ups_realpower
|
|
||||||
declare ups_batterycharge
|
|
||||||
declare ups_batteryruntime
|
|
||||||
declare ups_batteryvoltage
|
|
||||||
declare ups_inputvoltage
|
|
||||||
declare ups_outputvoltage
|
|
||||||
|
|
||||||
get_ups_info()
|
|
||||||
{
|
|
||||||
ups_type=$(upsc "${ups}" device.type 2> /dev/null)
|
|
||||||
ups_mfr=$(upsc "${ups}" ups.mfr 2> /dev/null)
|
|
||||||
ups_model=$(upsc "${ups}" ups.model 2> /dev/null)
|
|
||||||
ups_serial=$(upsc "${ups}" ups.serial 2> /dev/null)
|
|
||||||
ups_status=$(upsc "${ups}" ups.status 2> /dev/null)
|
|
||||||
ups_load=$(upsc "${ups}" ups.load 2> /dev/null)
|
|
||||||
ups_realpower=$(upsc "${ups}" ups.realpower 2> /dev/null)
|
|
||||||
ups_realpowernominal=$(upsc "${ups}" ups.realpower.nominal 2> /dev/null)
|
|
||||||
ups_batterycharge=$(upsc "${ups}" battery.charge 2> /dev/null)
|
|
||||||
ups_batteryruntime=$(upsc "${ups}" battery.runtime 2> /dev/null)
|
|
||||||
ups_batteryvoltage=$(upsc "${ups}" battery.voltage 2> /dev/null)
|
|
||||||
ups_inputvoltage=$(upsc "${ups}" input.voltage 2> /dev/null)
|
|
||||||
ups_outputvoltage=$(upsc "${ups}" output.voltage 2> /dev/null)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get a list of all ups devices installed on the system:
|
# Get a list of all ups devices installed on the system:
|
||||||
|
|
||||||
upslist=$(upsc -l "${freenashost}")
|
upslist=$(upsc -l "${freenashost}")
|
||||||
@@ -64,28 +36,40 @@ upslist=$(upsc -l "${freenashost}")
|
|||||||
date "+Time: %Y-%m-%d %H:%M:%S"
|
date "+Time: %Y-%m-%d %H:%M:%S"
|
||||||
echo ""
|
echo ""
|
||||||
for ups in $upslist; do
|
for ups in $upslist; do
|
||||||
get_ups_info
|
ups_type=$(upsc "${ups}" device.type 2> /dev/null | tr '[:lower:]' '[:upper:]')
|
||||||
printf "=== %s %s, model %s, serial number %s\n\n" "${ups_mfr}" "${ups_type^^}" "${ups_model}" "${ups_serial} ==="
|
ups_mfr=$(upsc "${ups}" ups.mfr 2> /dev/null)
|
||||||
|
ups_model=$(upsc "${ups}" ups.model 2> /dev/null)
|
||||||
|
ups_serial=$(upsc "${ups}" ups.serial 2> /dev/null)
|
||||||
|
ups_status=$(upsc "${ups}" ups.status 2> /dev/null)
|
||||||
|
ups_load=$(upsc "${ups}" ups.load 2> /dev/null)
|
||||||
|
ups_realpower=$(upsc "${ups}" ups.realpower 2> /dev/null)
|
||||||
|
ups_realpowernominal=$(upsc "${ups}" ups.realpower.nominal 2> /dev/null)
|
||||||
|
ups_batterycharge=$(upsc "${ups}" battery.charge 2> /dev/null)
|
||||||
|
ups_batteryruntime=$(upsc "${ups}" battery.runtime 2> /dev/null)
|
||||||
|
ups_batteryvoltage=$(upsc "${ups}" battery.voltage 2> /dev/null)
|
||||||
|
ups_inputvoltage=$(upsc "${ups}" input.voltage 2> /dev/null)
|
||||||
|
ups_outputvoltage=$(upsc "${ups}" output.voltage 2> /dev/null)
|
||||||
|
printf "=== %s %s, model %s, serial number %s\n\n" "${ups_mfr}" "${ups_type}" "${ups_model}" "${ups_serial} ==="
|
||||||
echo "Name: ${ups}"
|
echo "Name: ${ups}"
|
||||||
echo "Status: ${ups_status}"
|
echo "Status: ${ups_status}"
|
||||||
echo "Output Load: ${ups_load}%"
|
echo "Output Load: ${ups_load}%"
|
||||||
if [[ ! -z ${ups_realpower} ]]; then
|
if [ ! -z "${ups_realpower}" ]; then
|
||||||
echo "Real Power: ${ups_realpower}W"
|
echo "Real Power: ${ups_realpower}W"
|
||||||
fi
|
fi
|
||||||
if [[ ! -z ${ups_realpowernominal} ]]; then
|
if [ ! -z "${ups_realpowernominal}" ]; then
|
||||||
echo "Real Power: ${ups_realpowernominal}W (nominal)"
|
echo "Real Power: ${ups_realpowernominal}W (nominal)"
|
||||||
fi
|
fi
|
||||||
if [[ ! -z ${ups_inputvoltage} ]]; then
|
if [ ! -z "${ups_inputvoltage}" ]; then
|
||||||
echo "Input Voltage: ${ups_inputvoltage}V"
|
echo "Input Voltage: ${ups_inputvoltage}V"
|
||||||
fi
|
fi
|
||||||
if [[ ! -z ${ups_outputvoltage} ]]; then
|
if [ ! -z "${ups_outputvoltage}" ]; then
|
||||||
echo "Output Voltage: ${ups_outputvoltage}V"
|
echo "Output Voltage: ${ups_outputvoltage}V"
|
||||||
fi
|
fi
|
||||||
echo "Battery Runtime: ${ups_batteryruntime}s"
|
echo "Battery Runtime: ${ups_batteryruntime}s"
|
||||||
echo "Battery Charge: ${ups_batterycharge}%"
|
echo "Battery Charge: ${ups_batterycharge}%"
|
||||||
echo "Battery Voltage: ${ups_batteryvoltage}V"
|
echo "Battery Voltage: ${ups_batteryvoltage}V"
|
||||||
echo ""
|
echo ""
|
||||||
if (( senddetail > 0 )); then
|
if [ $senddetail -gt 0 ]; then
|
||||||
echo "=== ALL AVAILABLE UPS VARIABLES ==="
|
echo "=== ALL AVAILABLE UPS VARIABLES ==="
|
||||||
upsc "${ups}"
|
upsc "${ups}"
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user