More elegant one-Liner:
if cpstat os -f power_supply | grep -qi "down"; then logger -s -p kern.crit -t kernel 'PSU is down !!! Please replace faulty PSU.'; fi
This command will check if output of "cpstat os -f power_supply" contains string "down" (not case sensitive) and in case yes, issue command logger with facility kern and priority crit to print desired text in /var/log/messages in order to be caught by any Syslog server as critical message (or check it some other way within logs).
Just schedule this one line using cron job every day and you have monitoring of PSU in place 🙂
Please note that there are some exceptions where PSU is considered as down, but not really:
sk107199 - Power Supply sensors are shown as "Up" or "Down" when using one Power Supply and one Powe...
Another solution is to use snmpwalk to get status of PSUs, or create trap for it:
OID Name: powerSupplyStatus
OID Number: 1.3.6.1.4.1.2620.1.6.7.9.1.1.2
Kind regards,
Jozko Mrkvicka