Skip to content

Create status json for use by the panel control plugin.#2652

Open
SimonFair wants to merge 2 commits into
unraid:masterfrom
SimonFair:feature/os-261-add-support-in-monitor-to-create-output-for-panel
Open

Create status json for use by the panel control plugin.#2652
SimonFair wants to merge 2 commits into
unraid:masterfrom
SimonFair:feature/os-261-add-support-in-monitor-to-create-output-for-panel

Conversation

@SimonFair
Copy link
Copy Markdown
Contributor

@SimonFair SimonFair commented May 28, 2026

This change creates a new json in the state directory.

This is to add support for controlling LEDs and LCD panels for devices like LincStation N1/N2 initially with others to follow like S1 and Ugreen.

Summary by CodeRabbit

  • New Features
    • Generates and exports a comprehensive PanelControl-compatible JSON monitor payload with per-disk and per-device temperature/health events, aggregated target states, and summary counts.
    • Monitoring output is conditionally shown via a show-flag.
    • Payload is pretty-printed and updated on disk only when changed, using a safe write-and-rename strategy.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0fca4bef-5061-40b0-8af8-01eeea75252c

📥 Commits

Reviewing files that changed from the base of the PR and between 526f923 and 8e4c413.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/scripts/monitor
🚧 Files skipped from review as they are similar to previous changes (1)
  • emhttp/plugins/dynamix/scripts/monitor

Walkthrough

The monitor script now conditionally generates a JSON payload containing disk and device monitor events and aggregated per-target health states for PanelControl integration. It provides helper functions to check enablement and rank event severity, constructs events from disk status, temperatures, and health checks, and persists the payload to a state file with change-detection logic.

Changes

PanelControl Monitor Payload Generation

Layer / File(s) Summary
PanelControl monitor helper functions
emhttp/plugins/dynamix/scripts/monitor
Adds panelcontrol_monitor_has_show_flag() to check if PanelControl output should be displayed, and panelcontrol_monitor_state_rank() to map monitor state strings to numeric rank values for per-target state aggregation.
Event and payload building
emhttp/plugins/dynamix/scripts/monitor
Introduces panelcontrol_monitor_push_event() and panelcontrol_monitor_build_payload() to normalize and collect disk/device monitor events (status, temperature, errors), aggregate them into per-target highest-severity states, and construct a complete payload object with schema, thresholds, timestamps, and summary counts. Initializes $panelcontrolShow flag at script startup.
Payload file persistence
emhttp/plugins/dynamix/scripts/monitor
When PanelControl output is enabled, JSON-encodes the payload with pretty-printing, compares against the existing state file, and updates the file only if content differs, using atomic-style write via temporary file rename with fallback to direct write.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 New payloads for the Panel so bright,
Events and states aligned just right,
Temps and health in tidy array,
Atomic writes save the day, hooray! 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Create status json for use by the panel control plugin' accurately describes the main objective of the pull request, which adds PanelControl monitoring output generation with JSON payload creation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

🔧 PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2026.05.28.1136
Build: View Workflow Run

📥 Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins → Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-2652/webgui-pr-2652.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates
  • Post-merge behavior: This preview stays available after merge until preview storage expires or it is manually cleaned up

📝 Modified Files:

Click to expand file list
emhttp/plugins/dynamix/scripts/monitor

🔄 To Remove:

Navigate to Plugins → Installed Plugins and remove webgui-pr-2652, or run:

plugin remove webgui-pr-2652

🤖 This comment is automatically generated and will be updated with each new push to this PR.

@SimonFair SimonFair added the 7.3 label May 28, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@emhttp/plugins/dynamix/scripts/monitor`:
- Around line 45-47: The function panelcontrol_monitor_has_show_flag currently
always returns true; replace that hardcoded return with a real
feature-flag/config lookup (e.g., read the PanelControl plugin setting key such
as "enabled" or "panelcontrol_enabled" from the plugin configuration or system
feature flags via the existing config-API helper used elsewhere in this script)
and return its boolean value (with a safe default of false if the key is missing
or parsing fails); apply the same change to the duplicate occurrence referenced
around the other location so payload generation only runs when the actual config
flag is enabled.
- Around line 576-579: The current write-then-rename sequence writes JSON to
$tmpPath and calls `@rename`($tmpPath, $payloadPath) but ignores rename()'s return
value, leaving a stale $tmpPath (payloadPath . '.tmp') if rename fails; update
the block around the write to check the boolean result of rename($tmpPath,
$payloadPath) and on failure attempt a safe fallback: write the payloadJson
directly to $payloadPath (e.g., with file_put_contents and LOCK_EX), and then
remove the $tmpPath (unlink) to avoid leaving the .tmp file; ensure errors are
suppressed/handled similarly to the surrounding code and reference the variables
$tmpPath, $payloadPath, rename(), file_put_contents(), and unlink() when
editing.
- Around line 572-574: Check the result of json_encode($payload,
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) before appending "\n" and before
comparing/writing to $payloadPath: if json_encode returns false, log or report
the encoding error (include json_last_error_msg()), do not overwrite
panelcontrol-monitor-payload.json, and skip the file_put_contents path; ensure
subsequent logic uses $existingPayloadJson unchanged. Target the $payloadJson
variable and the json_encode(...) call and guard the comparison against
$existingPayloadJson so invalid JSON is never written to $payloadPath.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 826870c2-29d4-49f1-a06e-76d8c5458ef8

📥 Commits

Reviewing files that changed from the base of the PR and between 982b3c2 and 526f923.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/scripts/monitor

Comment thread emhttp/plugins/dynamix/scripts/monitor
Comment thread emhttp/plugins/dynamix/scripts/monitor Outdated
Comment thread emhttp/plugins/dynamix/scripts/monitor Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant