NUT UPS
Edit user settings
NAS:
sudo nano /usr/syno/etc/ups/upsd.users | sudo nano /etc/ups/upsd.users
LINIX:
sudo nano /etc/nut/upsd.users
upsd.users
[mac]
password = cyber
actions = set
instcmds = all # allow user to change UPS settings (beeps)
[upsmon]
password = cyber
upsmon secondary
Restart NUT
NAS:
sudo killall usbhid-ups upsd upsmon
sudo /usr/bin/usbhid-ups -a ups
sudo /usr/sbin/upsd
sudo /usr/sbin/upsmon
sudo upsd -c reload
LINIX:
sudo systemctl restart nut-monitor
sudo systemctl restart nut-client
sudo systemctl status nut-client # Check status
Check the server logs in live time
NAS:
sudo tail -f /var/log/messages
LINIX:
sudo tail -f /var/log/syslog
Edit upsmon config on main UPS server
NAS:
sudo nano etc/ups/upsmon.conf
upsmon.conf
MONITOR ups@localhost 1 mac cyber master
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/poweroff"
POLLFREQ 2
POLLFREQALERT 1
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
NOTIFYCMD "/etc/ups/notifycmd.sh"
NOTIFYMSG ONLINE "UPS %s on line power"
NOTIFYMSG ONBATT "UPS %s on battery"
NOTIFYMSG LOWBATT "UPS %s battery is low"
NOTIFYMSG FSD "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK "Communications with UPS %s established"
NOTIFYMSG COMMBAD "Communications with UPS %s lost"
NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT "UPS %s battery needs to be replaced"
NOTIFYMSG NOCOMM "UPS %s is unavailable"
NOTIFYMSG NOPARENT "upsmon parent process died - shutdown impossible"
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL
NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT SYSLOG+WALL
RBWARNTIME 43200
NOCOMMWARNTIME 600
FINALDELAY 5
Discord webhook:
#!/bin/bash
WEBHOOK_URL="https://discord.com/api/webhooks/1291208566203486310/TVowi6MVC4cSJFOt1U9TfVq5QSgD-paYM1EiDn0u77gp4Lm8-1Pt0DXV2ZXtC3yo_nf9"
USERNAME="UPS Monitor"
AVATAR_URL="https://clipground.com/images/cyberpower-logo.png" # Link to CyberPower logo or any image representing your UPS
TITLE="🚨 UPS Event Alert 🚨"
THUMBNAIL_URL="https://upload.wikimedia.org/wikipedia/commons/9/95/CyberPower_logo.png" # Optional: Use a relevant UPS image
FOOTER_TEXT="Network UPS Tools (NUT)"
FOOTER_ICON_URL="https://clipground.com/images/cyberpower-logo.png"
TIMESTAMP=$(date --utc +%FT%TZ) # ISO 8601 timestamp for Discord
# Extracting information from NUT environment variables
EVENT_TYPE=$NOTIFYTYPE
UPS_NAME=$UPSNAME
DATE_TIME=$(date '+%Y-%m-%d %H:%M:%S')
BATTERY_LEVEL=$(upsc ups@localhost battery.charge) # Adjust this to match your UPS setup
UPS_STATUS=$(upsc ups@localhost ups.status) # Example for getting UPS status
# Conditional color: light green for ONLINE, red for other events
if [[ "$EVENT_TYPE" == "ONLINE" ]]; then
COLOR="65280" # Light green in decimal
else
COLOR="16711680" # Red in decimal
fi
# Creating the JSON payload with detailed embed
JSON_PAYLOAD=$(cat <<EOF
{
"username": "$USERNAME",
"avatar_url": "$AVATAR_URL",
"embeds": [
{
"title": "$TITLE",
"description": "An event has occurred on your UPS system. See the details below:",
"color": $COLOR,
"fields": [
{
"name": "🔋 Event Type",
"value": "$EVENT_TYPE",
"inline": true
},
{
"name": "⚡ UPS Name",
"value": "$UPS_NAME",
"inline": true
},
{
"name": "📅 Date & Time",
"value": "$DATE_TIME",
"inline": false
},
{
"name": "🔋 Battery Level",
"value": "$BATTERY_LEVEL%",
"inline": true
},
{
"name": "⚠️ UPS Status",
"value": "$UPS_STATUS",
"inline": true
},
{
"name": "📝 Event Details",
"value": "The UPS event **$EVENT_TYPE** occurred on **$UPS_NAME** at **$DATE_TIME**.",
"inline": false
}
],
"thumbnail": {
"url": "$THUMBNAIL_URL"
},
"footer": {
"text": "$FOOTER_TEXT",
"icon_url": "$FOOTER_ICON_URL"
},
"timestamp": "$TIMESTAMP"
}
]
}
EOF
)
# Sending the embed payload to Discord
curl -H "Content-Type: application/json" -X POST -d "$JSON_PAYLOAD" $WEBHOOK_URL
Misc:
https://technotim.live/posts/NUT-server-guide/