Skip to content

Commit b5528ad

Browse files
committed
clients/upsmon.{c,h}, NEWS.adoc: Make sure FSD notifications are always issued at latest when shutdown handling just starts (or earlier) [#3003, #3110]
Signed-off-by: Jim Klimov <[email protected]>
1 parent 21e4752 commit b5528ad

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

NEWS.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ https://github.com/networkupstools/nut/milestone/12
100100
* Introduced a `SHUTDOWN_HOSTSYNC` notification message, to report that
101101
the primary `upsmon` initiated the shutdown and has some secondaries
102102
to wait for first. [#3084]
103+
* Make sure an `FSD` notification is issued for each UPS when this primary
104+
`upsmon` instance sets it (and does not return to usual data processing
105+
loop to see and report it like secondaries do). This allows a `NOTIFYCMD`
106+
such as `upssched` on the primary to handle the pending power outage
107+
(e.g. begin stopping heavy services) even while `upsmon` waits for the
108+
secondaries to complete their shutdowns and log out of the `upsd` data
109+
server. [issue #3003, PR #3110]
110+
+
111+
NOTE: If using `upssched` and monitoring multiple UPSes, consider setting up
112+
a `START-TIMER-SHARED` rule with a short (approx. 1 second) timeout to group
113+
several `FSD` notifications into one executed action. [PR #3097]
103114

104115
- `upssched` tool updates:
105116
* Previously in PR #2896 (NUT releases v2.8.3 and v2.8.4) the `UPSNAME` and

clients/upsmon.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,20 @@ static void setfsd(utype_t *ups)
11331133
return;
11341134
}
11351135

1136-
if (!strncmp(buf, "OK", 2))
1136+
if (!strncmp(buf, "OK", 2)) {
1137+
upsdebugx(1, "%s: data server confirmed setting FSD for UPS [%s]", __func__, ups->sys);
1138+
1139+
/* Let NOTIFYCMD (if any) know, and have a chance to react */
1140+
if (ups->lastfsdnotify) {
1141+
/* e.g. upsd was still alive with a latched FSD
1142+
* status when this upsmon instance started */
1143+
upsdebugx(2, "%s: not notifying about FSD for UPS [%s] because it was recently reported already", __func__, ups->sys);
1144+
} else {
1145+
time(&(ups->lastfsdnotify));
1146+
do_notify(ups, NOTIFY_FSD, NULL);
1147+
}
11371148
return;
1149+
}
11381150

11391151
/* protocol error: upsd said something other than "OK" */
11401152
upslogx(LOG_ERR, "FSD set on UPS %s failed: %s", ups->sys, buf);
@@ -1843,9 +1855,12 @@ static void ups_fsd(utype_t *ups)
18431855

18441856
upsdebugx(3, "%s: %s (first time)", __func__, ups->sys);
18451857

1846-
/* must have changed from !FSD to FSD, so notify */
1858+
/* must have changed from !FSD to FSD, so notify; avoid duplicates though */
18471859

1848-
do_notify(ups, NOTIFY_FSD, NULL);
1860+
if (!(ups->lastfsdnotify)) {
1861+
time(&(ups->lastfsdnotify));
1862+
do_notify(ups, NOTIFY_FSD, NULL);
1863+
}
18491864
setflag(&ups->status, ST_FSD);
18501865
}
18511866

@@ -2113,6 +2128,8 @@ static void addups(int reloading, const char *sys, const char *pvs,
21132128
tmp->lastrbwarn = 0;
21142129
tmp->lastncwarn = 0;
21152130

2131+
tmp->lastfsdnotify = 0;
2132+
21162133
tmp->offsince = 0;
21172134
tmp->oblbsince = 0;
21182135
tmp->oversince = 0;
@@ -2868,8 +2885,10 @@ static void parse_status(utype_t *ups, char *status, char *buzzword, char *buzzw
28682885
/* clear these out early if they disappear */
28692886
if (!strstr(status, "LB"))
28702887
clearflag(&ups->status, ST_LOWBATT);
2871-
if (!strstr(status, "FSD"))
2888+
if (!strstr(status, "FSD")) {
28722889
clearflag(&ups->status, ST_FSD);
2890+
ups->lastfsdnotify = 0;
2891+
}
28732892

28742893
/* similar to above - clear these flags and send notifications */
28752894
if (!strstr(status, "CAL"))

clients/upsmon.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ typedef struct {
9292
int pollfail_log_throttle_count; /* How many pollfreq loops this UPS was in this state since last logged report? */
9393

9494
time_t lastpoll; /* time of last successful poll */
95-
time_t lastnoncrit; /* time of last non-crit poll */
95+
time_t lastnoncrit; /* time of last non-crit poll */
9696
time_t lastrbwarn; /* time of last REPLBATT warning*/
9797
time_t lastncwarn; /* time of last NOCOMM warning */
9898

99+
time_t lastfsdnotify; /* time of last FSD notification (when first discovering the state, or setting it - avoid duplicate notification); 0 initially or if that state clears */
100+
99101
time_t offsince; /* time of recent entry into OFF state */
100102
time_t oblbsince; /* time of recent entry into OB LB state (normally this causes immediate shutdown alert, unless we are configured to delay it) */
101103
time_t oversince; /* time of recent entry into OVER state */

0 commit comments

Comments
 (0)