Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update upsmon ALARM support and related themes from issue #415 #2709

Merged
merged 34 commits into from
Dec 6, 2024

Conversation

jimklimov
Copy link
Member

Closes: #415
Follow-up to: #2658
Touches on: #2708

arnaudquette-eaton and others added 6 commits April 4, 2017 15:13
Add general support for alarms to upsmon, which relates to the ups.status
variable of a device holding the flag "ALARM". upsmon now has a "notify type"
alarm, which allows to react on such events, as with other events

Signed-off-by: Arnaud Quette <[email protected]>
Whenever a device publishes the ALARM flag in ups.status, the CGI will publish
it part of the Status

Signed-off-by: Arnaud Quette <[email protected]>
…kupstools#415 discussion adding to PR networkupstools#2658 changes

Previously merged-in the couple of commits from issue
networkupstools#415 proposal at
https://github.com/networkupstools/nut/tree/upsmon_alarm
for posterity, now cherry-picking some changes and further
discussion ideas from mailing list thread at
http://lists.alioth.debian.org/pipermail/nut-upsuser/2017-April/010591.html

Closes: networkupstools#415

Signed-off-by: Jim Klimov <[email protected]>
…: handle STATUS_BIT(NOBATTERY) to also status_set("RB") [networkupstools#415]

Signed-off-by: Jim Klimov <[email protected]>
…further strings if we had a match; report unexpected tokens [networkupstools#415, networkupstools#2708]

Signed-off-by: Jim Klimov <[email protected]>
@jimklimov
Copy link
Member Author

NOTE: This PR currently stops short of actually handling the notifications, as we would need some sort of Map<String, Boolean> to track that a non-standard token was raised once and remains raised continuously (otherwise it would notify about it every cycle).

Probably this can be done with dstate/sstate and a catch-all method similar to ups_is_cal et al (accepting the token as another parameter, and not caring about it beyond notification).

Copy link
Contributor

@desertwitch desertwitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (so far) 👍

@jimklimov
Copy link
Member Author

jimklimov commented Dec 3, 2024

Updated with more comprehensive upsmon support for "ALARM" (to report ups.alarm contents if the formatting string has two %s placeholders), and newly introduced older discussed "OTHER" to report any changes about ups.status tokens not known to upsmon.

Note that unlike most other notifications about change of UPS status, the "OTHER"/"NOTOTHER" events do not map to a specific ups.status flag (so there is no code elsewhere to support a token named OTHER as one of UPS status flag values). This is an upsmon internal detail.

The napkin logic makes sense to me and compiles, but was not tested - that would be most welcome :D

@jimklimov jimklimov added the need testing Code looks reasonable, but the feature would better be tested against hardware or OSes label Dec 3, 2024
@jimklimov
Copy link
Member Author

jimklimov commented Dec 5, 2024

Verified with make check-NIT-sandbox-devel and modified generated dummy.seq to include alarm bits:

ups.status: OB
TIMER 5
ups.status: OL
TIMER 5
ups.status: ALARM OL BOGUS
ups.alarm: Test bug!
TIMER 2

Console messages:

UPS dummy@localhost:12345 on battery
UPS dummy@localhost:12345 on line power
UPS dummy@localhost:12345: one or more active alarms: [Test bug!]
UPS dummy@localhost:12345: has at least one unclassified status token: [BOGUS]
UPS dummy@localhost:12345 is no longer in an alarm state (no active alarms)
UPS dummy@localhost:12345 on battery
UPS dummy@localhost:12345 has no unclassified status tokens anymore

Using notifyme-debug as the handler got:

...
Thu Dec  5 20:10:29 UTC 2024    [uid=1000(jim) gid=1000(jim) groups=1000(jim)]        ONBATT  [dummy@localhost:12345]:      UPS dummy@localhost:12345 on battery    (1 tokens)
Thu Dec  5 20:10:39 UTC 2024    [uid=1000(jim) gid=1000(jim) groups=1000(jim)]        ONLINE  [dummy@localhost:12345]:      UPS dummy@localhost:12345 on line power (1 tokens)
Thu Dec  5 20:10:44 UTC 2024    [uid=1000(jim) gid=1000(jim) groups=1000(jim)]        ALARM   [dummy@localhost:12345]:      UPS dummy@localhost:12345: one or more active alarms: [Test bug!]       (1 tokens)
Thu Dec  5 20:10:44 UTC 2024    [uid=1000(jim) gid=1000(jim) groups=1000(jim)]        OTHER   [dummy@localhost:12345]:      UPS dummy@localhost:12345: has at least one unclassified status token: [BOGUS]  (1 tokens)
Thu Dec  5 20:10:49 UTC 2024    [uid=1000(jim) gid=1000(jim) groups=1000(jim)]        ONBATT  [dummy@localhost:12345]:      UPS dummy@localhost:12345 on battery    (1 tokens)
Thu Dec  5 20:10:49 UTC 2024    [uid=1000(jim) gid=1000(jim) groups=1000(jim)]        NOTALARM        [dummy@localhost:12345]:      UPS dummy@localhost:12345 is no longer in an alarm state (no active alarms)     (1 tokens)
Thu Dec  5 20:10:49 UTC 2024    [uid=1000(jim) gid=1000(jim) groups=1000(jim)]        NOTOTHER        [dummy@localhost:12345]:      UPS dummy@localhost:12345 has no unclassified status tokens anymore     (1 tokens)
...

It seems to lock up after handling "NOTOTHER" though "ALARM/NOTALARM" handling behaves well, investigating.

UPDATE: Small but important bug found, fixed :)

…fall back to /dev/shm or /tmp otherwise [networkupstools#2709]

Signed-off-by: Jim Klimov <[email protected]>
…tworkupstools#2709]

...default the latter to `testgroup_sandbox_upsmon_master` now
(includes the earlier `testcase_sandbox_start_drivers_after_upsd`)

Signed-off-by: Jim Klimov <[email protected]>
…tor_status also if exit_flag gets raised (e.g. Ctrl+C during the wait) [networkupstools#1070]

Signed-off-by: Jim Klimov <[email protected]>
jimklimov added a commit to jimklimov/nut that referenced this pull request Dec 5, 2024
Kudos to `make check-NI-sandbox-devel` and
LD_LIBRARY_PATH=`pwd`/clients/.libs valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./clients/.libs/upsmon -F

Signed-off-by: Jim Klimov <[email protected]>
@jimklimov
Copy link
Member Author

Had some fun with valgrind to make sure these alert loops do not leak memory...

@jimklimov jimklimov merged commit f657e0e into networkupstools:master Dec 6, 2024
30 checks passed
@jimklimov jimklimov deleted the issue-415 branch December 6, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation need testing Code looks reasonable, but the feature would better be tested against hardware or OSes upsmon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

upsmon: add ALARM support
3 participants