apccontrol, which runs the executable in /etc/apcupsd that has the same name as the event and passes the UPS name as the first argument. apcupsd has no native webhook, so an event script pushes the events to Flashduty in the Standard Alert Event format: onbattery triggers an alert and offbattery 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 apcupsd.
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 apcupsd
Step 1: Create the push script
On the host that runsapcupsd, create /etc/apcupsd/flashduty-notify.sh, replace URL with the push URL copied above, and make it executable (chmod +x). The host needs curl.
Step 2: Hook the script into the events
apcupsd’s customization mechanism (see theapccontrol manual): create an executable file named after the event in /etc/apcupsd. apccontrol runs it first when the event occurs; if it exits with status 0, apccontrol continues with the event’s default action, and exit status 99 skips the default action. The script above always exits with 0, so it does not change apcupsd’s default behavior (including the shutdown sequence).
The command below creates one event file per event that only calls the push script. Events that already have a file in the directory (the onbattery, offbattery, commfailure, commok and changeme sample scripts installed by apcupsd are such files) are not overwritten; the command tells you to add the call line near the top of the file yourself:
powerout (generated as soon as the UPS switches to battery) is not hooked: onbattery only fires when the outage lasts longer than ONBATTERYDELAY, which avoids alerts for momentary power dips.
Step 3: Verify
Run the event scripts by hand on the host, first a trigger and then a recovery:UPS myups: on battery and then see it recover. Running onbattery by hand also runs whatever else the event file already contains; to test only the push, run /etc/apcupsd/flashduty-notify.sh onbattery myups directly.
Recovery and deduplication
onbattery, the failure events (failing,timeout,loadlimit,runlimit),offbatteryandmainsbackshare the Alert Keyapcupsd:<UPS name>:power:onbatterytriggers the alert, a following failure event raises it to Critical, and it recovers when utility power returnscommfailureandcommok, andbattdetachandbattattach, are pairedchangemeandemergencyhave no matching recovery event. While a battery fault persists, apcupsd repeatschangemeevery 9 hours. After replacing the battery, close the alert manually in Flashduty, or enable the auto-resolve timeout on the channel, starting with 24 hours; if the battery has not been replaced, the nextchangemetriggers the alert again- Alerts of several UPS units do not affect each other: the Alert Key contains the UPS name (the name configured in
apcupsd.conf)
Troubleshooting
- No alert arrives: confirm the file named after the event exists in
/etc/apcupsdand is executable, and thatURLinflashduty-notify.shis correct; run the event file by hand and check the output - The alert does not recover: confirm the recovery events (
offbattery,mainsback,commok,battattach) are hooked too - Flashduty returns a parameter error: confirm
URLis the full push URL, includingintegration_key