Skip to content

plex: add webhook healthcheck against active sessions#1196

Open
nicholaskurjo wants to merge 1 commit into
Notifiarr:mainfrom
nicholaskurjo:feat/1131-plex-webhook-healthcheck
Open

plex: add webhook healthcheck against active sessions#1196
nicholaskurjo wants to merge 1 commit into
Notifiarr:mainfrom
nicholaskurjo:feat/1131-plex-webhook-healthcheck

Conversation

@nicholaskurjo

Copy link
Copy Markdown

Summary

  • add Plex webhook healthcheck logic that compares active sessions against webhook recency
  • track webhook health state in plexcron (startAt, lastWebhookAt, lastAlertAt)
  • record webhook receipt time from the Plex webhook handler
  • evaluate health during session polling and send a throttled health alert payload when webhooks appear stale
  • add new optional Plex action config fields:
    • webhookHealthEnabled
    • webhookStaleAfter
    • webhookAlertCooldown
    • webhookStartupGrace

Behavior

A health alert is sent only when:

  • webhook health is enabled
  • there is at least one active Plex session
  • startup grace has elapsed
  • alert cooldown has elapsed
  • and either no webhook has been seen since startup, or the last webhook is older than the stale threshold

Tests

  • added pkg/triggers/plexcron/webhook_health_test.go with decision-logic coverage:
    • stale webhook + active sessions alerts
    • no sessions does not alert
    • recent webhook does not alert
    • startup grace suppresses alerts
    • cooldown suppresses alerts
    • never-seen webhook alerts after grace
  • ran:
    • go test ./pkg/triggers/plexcron
    • go test ./pkg/client
    • go test ./pkg/apps/apppkg/plex

Closes #1131

cfg := defaultWebhookHealthConfig()

if !cfg.Enabled {
t.Fatal("expected default webhook health config to be enabled")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tell your AI to use testify.

"time"
)

func TestShouldAlertForStaleWebhook(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can add an override for test files in .golangci-lint.yml to ignore the funlen linter.

@@ -0,0 +1,102 @@
package plexcron

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
package plexcron
package plexcron_test

See if you can make the tests work like this. It's not mandatory, but if you don't then you need to make the linter shut up.

Payload: &website.Payload{
Snap: c.getMetaSnap(ctx),
Plex: sessions,
Load: hook,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This payload structure you created int's going to work out. I'll figure out what we need...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Plex Webhook Healthcheck/Notify - Compare Plex Sessions Vs. Webhook

2 participants