Skip to content

sysutils/nut: fix upsstatus diagnostics and netclient model definition#5469

Open
Drinker09 wants to merge 2 commits into
opnsense:masterfrom
Drinker09:master
Open

sysutils/nut: fix upsstatus diagnostics and netclient model definition#5469
Drinker09 wants to merge 2 commits into
opnsense:masterfrom
Drinker09:master

Conversation

@Drinker09
Copy link
Copy Markdown

@Drinker09 Drinker09 commented May 29, 2026

Important notices

Before you submit a pull request, we ask you kindly to acknowledge the following:

If AI was used, please disclose:

  • Model used: Claude Sonet 4.6
  • Extent of AI involvement: Claude did pretty much all the work. I just followed along. Seriously.

This PR covers issue #5470

Description

This PR fixes two issues with the NUT plugin that prevent the diagnostics page, dashboard widget, and API endpoint from returning UPS status data when running in netclient mode.

Problem 1: upsc binary segfaults on FreeBSD 14.x with NUT 2.8.5

The DiagnosticsController::upsstatusAction() method called /usr/local/bin/upsc via configd to retrieve UPS status. This approach fails for two reasons:

1.) configd sanitizes the @ symbol in parameters, making it impossible to pass upsname@host as an argument via configdpRun().

2.) On FreeBSD 14.x with NUT 2.8.5, upsc segfaults (SIGSEGV, exit code 11) when querying a remote upsd server, producing no output before crashing.

This bug has been reported to the NUT project: networkupstools/nut#3454

Fix: Replace the upsc call with a direct TCP socket connection to the remote upsd server using the NUT protocol. This is more reliable, faster, and bypasses both issues entirely.

Problem 2: Bare HostnameField definition in netclient model

The netclient->address field in Nut.xml was defined as a bare address type="HostnameField" with no configuration, which is inconsistent with how other fields in the model are defined.

Fix: Add explicit Required and IpWithPrefix attributes to properly define the field.

Files changed

sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/DiagnosticsController.php — replaced upsc call with direct NUT protocol socket connection
sysutils/nut/src/opnsense/mvc/app/models/OPNsense/Nut/Nut.xml — properly defined netclient address HostnameField

Testing

Tested on OPNsense 26.1 (FreeBSD 14.3-RELEASE-p12) with NUT 2.8.5 in netclient mode, monitoring a CyberPower CP1500PFCLCDa connected to a Raspberry Pi NUT server. After this fix:

Services > NUT > Diagnostics > UPS Status displays full UPS data
Dashboard NUT widget displays UPS status, battery level, and runtime
/api/nut/diagnostics/upsstatus API endpoint returns correct data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant