Skip to content

fix(integrations): make the SES inbound function work with NetBox 4 - #104

Merged
jsenecal merged 2 commits into
mainfrom
fix/inbound-lambda-netbox4
Dec 3, 2026
Merged

jsenecal merged 2 commits into
mainfrom
fix/inbound-lambda-netbox4

Conversation

@jsenecal

Copy link
Copy Markdown
Owner

Summary

parsers/aws-sns-lambda/ still called the netbox-circuitmaintenance API (plugins.maintenance.circuitmaintenance), so it could not work with this plugin. Its intended replacement, the inbound function of the AWS SES integration, did not work on NetBox 4 either. It looked up content types at /api/extras/content-types/, which NetBox 4.0 moved to /api/core/object-types/. Every parsed email therefore failed after its maintenance was created and before any impact or notification was stored.

This PR fixes the inbound function, tests it, and removes the legacy parser.

Inbound function fixes

  • Object types: looked up at /api/core/object-types/ and cached per container.
  • Matching:
    • A maintenance is matched by maintenance ID and provider.
    • A circuit is matched by exact CID (cid__ie) within that provider.
    • An existing impact is matched by event and target type. The old *_content_type_id params don't exist, and django-filter silently ignored them.
  • Status-less notices (the parser's NO-CHANGE: status-less BCOP and Cogent notices, reminders) keep the existing status, or create the maintenance as UNKNOWN. Before, NetBox rejected them.
  • Cancellation and completion notices leave the impacts alone. The plugin refuses to change impacts on a finished maintenance.
  • Retries: a Lambda retry no longer stores the notification twice. S3 errors now raise, so they get retried too.
  • Every maintenance in an email is recorded, not just the first.
  • Model limits: name, subject and summary are cut to the model limits. A blank subject or a calendar-only body no longer fails validation.
  • Sender matching: domains match exactly or by subdomain, and the most specific entry wins. bso.co no longer matches bso.com.
  • Non-UTF-8 email is parsed, and parser errors are logged and skipped.

Tests and CI

  • integrations/aws-ses/tests/ (27 tests) runs real BCOP iCal notifications through circuit-maintenance-parser against an in-memory NetBox API. The fake validates writes the way the plugin's serializers do, so a payload NetBox would reject with 400 fails the test.
  • New CI job Test AWS SES integration. ruff now also covers integrations/, which needed a one-line UP017 fix in the outbound handler.

Docs

  • Removed parsers/aws-sns-lambda/, its docs page and its screenshots. parsers.md now points to the SES integration.
  • The REST API and Impact pages also told integrators to use /api/extras/content-types/. Both now use /api/core/object-types/.
  • The integration README describes how inbound emails are recorded. It also states the known limits:
    • notices are applied in processing order, not by DTSTAMP/SEQUENCE;
    • two concurrent first notices can each create the maintenance;
    • no dead-letter queue is configured.

Test plan

  • pytest -o addopts="" integrations/aws-ses/tests: 27 passed (clean Python 3.12 venv, same as the CI job)
  • ruff check / ruff format --check on notices tests integrations
  • zensical build: no warnings
  • Deploy the stack and send a real carrier notice through SES (not done)

The inbound function looked up content types at /api/extras/content-types/,
which NetBox 4.0 moved to /api/core/object-types/, so every parsed email
failed after its maintenance was created and before any impact or
notification was stored.

Also match maintenances by ID and provider, circuits by exact CID within
the provider, and impacts by event and target type; skip impact changes on
completed or cancelled maintenances, which the plugin refuses; store each
email's notification once so Lambda retries are safe; record every
maintenance in an email; truncate to model limits; match sender domains
exactly or by subdomain; read non-UTF-8 email.

Add unit tests that run real BCOP notifications through
circuit-maintenance-parser against an in-memory NetBox API, a CI job for
them, and ruff coverage of integrations/.

Remove parsers/aws-sns-lambda, which targeted the netbox-circuitmaintenance
API and cannot work with this plugin, and its docs page.
…tices

A notice without a status (circuit-maintenance-parser's NO-CHANGE, used by
status-less BCOP and Cogent notices and by reminders) was sent to NetBox,
which refuses it; it now keeps the existing status or creates the
maintenance as UNKNOWN. A blank subject or a calendar-only body no longer
fails validation, the maintenance ID is cut to the model limit, non-UTF-8
mail is handed to the parser already decoded, the most specific provider
domain wins, and S3 errors raise so Lambda retries them.

The test fake now validates writes as the plugin's serializers do. Docs
that still looked up /api/extras/content-types/ now use
/api/core/object-types/, and the README states the ordering, concurrency
and dead-letter limits instead of promising every step is safe.
@github-actions github-actions Bot added the fix Bug fix label Nov 27, 2026
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jsenecal
jsenecal merged commit 5a6e72d into main Dec 3, 2026
16 checks passed
@jsenecal
jsenecal deleted the fix/inbound-lambda-netbox4 branch December 3, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant