upsmon daemon can run the script set by NOTIFYCMD when a UPS changes state: the environment variable NOTIFYTYPE holds the event type (ONBATT, ONLINE, COMMBAD and so on), UPSNAME holds the UPS name, and the notification text is passed as the last argument. NUT has no native webhook, so a short script pushes these events to Flashduty in the Standard Alert Event format: ONBATT triggers an alert and ONLINE recovers it.
In Flashduty On-call
Get an integration push URL in either of the two ways below. Choose the Standard Alert Event integration type in both, not NUT.
Use a dedicated integration
- In the Flashduty console, go to Channels and open a channel
- Go to Settings → Integrations → Dedicated integrations and click Add an integration
- Select Standard Alert Event and click Save
- Open the generated integration card and copy the Push URL, in the form
https://api.flashcat.cloud/event/push/alert/standard?integration_key=<integration key>
Use a shared integration
- In the Flashduty console, go to Integration Center → Alert Events
- Select Standard Alert Event and enter an integration name
- Configure the default route and select a channel; you can add more rules under Routes after creation
- Click Save and copy the generated Push URL
Configure in NUT
Step 1: Create the notification script
On the host that runsupsmon, create a script such as /usr/local/bin/nut-flashduty.sh, replace URL with the push URL copied above, and make it executable (chmod +x). The host needs curl.
Step 2: Enable the script in upsmon.conf
Editupsmon.conf, set the notification script, and add the EXEC flag for every event type you want to push (NOTIFYCMD only runs for events that have EXEC set):
NOTIFYCMD is interpreted as the full path of the script, quoted if the path contains spaces (NUT 2.8.5 and older releases parsed it differently; see the NUT documentation for upsmon.conf). To also push ALARM, OVER or BYPASS, add a NOTIFYFLAG line for each of them and for their recovery types (NOTALARM, NOTOVER, NOTBYPASS) in the same way. Then have upsmon re-read its configuration:
upsmon runs NOTIFYCMD in the background, so several instances can run at once when many events happen together; the script above sends exactly one request per call and is safe to run in parallel. Shutdown-related event types (FSD, SHUTDOWN and so on) are outside the script’s scope and it exits when it receives them.Step 3: Verify
Run the script by hand on the host, first a trigger and then a recovery:UPS ups@localhost: on battery and then see it recover.
Recovery and deduplication
ONBATT,LOWBATTandONLINEshare the Alert Keynut:<UPS name>:power:ONBATTtriggers the alert, a followingLOWBATTraises it to Critical, andONLINErecovers itCOMMBAD,NOCOMMandCOMMOKsharecomm;ALARMandNOTALARM,OVERandNOTOVER, andBYPASSandNOTBYPASSare also pairedREPLBATThas no matching recovery event. After replacing the battery, close the alert manually in Flashduty, or enable the auto-resolve timeout on the channel, starting with 7 days- Alerts of several UPS units do not affect each other: the Alert Key contains
UPSNAME
Troubleshooting
- No alert arrives: confirm the
NOTIFYFLAGof the event type inupsmon.confincludesEXECand thatupsmon -c reloadwas run - The script works by hand but no alert arrives when upsmon triggers it:
NOTIFYCMDmust be the full path of the script and the userupsmonruns as must be able to execute it;curl -fsSprints failures to stderr, whichupsmonmay not record, so run the script by hand to see them - The alert does not recover: confirm recovery types such as
ONLINEalso haveEXECset - Flashduty returns a parameter error: confirm
URLis the full push URL, includingintegration_key