Skip to content

Instantly share code, notes, and snippets.

@grahambrown11
Last active May 30, 2023 22:50
Show Gist options
  • Save grahambrown11/08867dc72bba22982edce042f8eeabe4 to your computer and use it in GitHub Desktop.
Save grahambrown11/08867dc72bba22982edce042f8eeabe4 to your computer and use it in GitHub Desktop.
UPS Monitoring with NUT

At work we have a PowerWise+ UPS made localally by EDSUPS, it came with Silon2000 software - which is for Windows. We only have linux servers so I installed NUT and tried to get the correct settings so NUT could send a Slack for the UPS state change

Add a rule so the USB creates a known symlink /etc/udev/rules.d/10-local.rules

ACTION=="add", KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="ttyUSB_UPS"

In /etc/nut/nut.conf make MODE=standalone

The follwing files need editing too, find their contents below

  • /etc/nut/ups.conf
  • /etc/nut/upsd.users
  • /etc/nut/upsmon.conf
  • /usr/local/bin/upsnotiftyslack
# My UPS Definition
[myups]
driver = blazer_ser
port = /dev/ttyUSB_UPS
desc = "PowerWise+ UPS"
# Define a user to monoitor the UPS (making a better password)
[local_mon]
password = password
allowfrom = localhost
upsmon master
# Add UPS to monitor (making a better password set in upsd.users)
MONITOR myups@localhost 1 local_mon password master
# use the slack shell scrips
NOTIFYCMD "/usr/local/bin/upsnotiftyslack"
# set the messages
NOTIFYMSG ONLINE "UPS on Power"
NOTIFYMSG ONBATT "UPS on Battery"
NOTIFYMSG LOWBATT "UPS battery is low"
NOTIFYMSG FSD "UPS forced shutdown in progress"
NOTIFYMSG COMMOK "Communications with UPS established"
NOTIFYMSG COMMBAD "Communications with UPS lost"
NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT "UPS battery needs to be replaced"
NOTIFYMSG NOCOMM "UPS is unavailable"
# add EXEC to the NOTIFYFLAGs
NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG LOWBATT SYSLOG+EXEC
#!/bin/bash
webhook=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
col="#e01a1a"
title="UPS Alert"
if [ "$*" = "UPS on Power" ]; then
col="#36a64f"
title="UPS Ok"
fi
data="{\"icon_emoji\":\":zap:\",\"channel\":\"#server-monitoring\",\"attachments\":[{\"color\":\"$col\",\"title\":\"$title\",\"text\":\"$*\"}]}"
curl -X POST -H 'Content-type: application/json' --data "$data" "$webhook" > /dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment