Skip to content

New api endpoint notification history - #472

Open
Jan-Schuppik wants to merge 2 commits into
mainfrom
new-api-endpoint-notification-history
Open

New api endpoint notification history#472
Jan-Schuppik wants to merge 2 commits into
mainfrom
new-api-endpoint-notification-history

Conversation

@Jan-Schuppik

@Jan-Schuppik Jan-Schuppik commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Sources currently have no way to ask Icinga Notifications which notifications it actually attempted for their objects. This PR adds a GET /notification-history HTTP endpoint that streams every notification attempt (sent or failed) recorded since a given point in time, along with the database schema and internal plumbing needed to record that history.

What's included

Two new tables, notification_history and skipped_notification_history, record every notification attempt and, for cases where multiple escalation recipients would have notified the same contact through the same channel, the additional origins that were skipped as duplicates. To support this, rule.ContactChannels was reworked from a per-contact/channel boolean into a map of []ChannelOrigin (rule, escalation, contact group, schedule, role), so internal/incident can tell which origin a pending notification is attributed to and which ones were superfluous.

Events now carry a stable event_id (a UUID either provided by the source or derived by hashing the event's JSON representation via the new event.CreateEvent/EnsureID). This ID is persisted on incident_history and used to correlate notification_history rows to the event that triggered them. As part of this, the event_queue deduplication key was migrated from a raw SHA256 bytea hash to the same UUID.

ContactRole and NotificationState moved out of internal/incident: ContactRole now lives in internal/recipient (its file relocated to internal/utils/contact_role.go), and the local NotificationState type was replaced by icinga-go-library's notifications/source.NotificationState, which required bumping the icinga-go-library dependency in go.mod.

The new endpoint reuses the same source-authentication and NDJSON-streaming machinery as the existing /incidents endpoint; the shared error-handling logic in listener.go was factored out into createStreamErrFunc so both endpoints use it.

Schema changes (see schema/{mysql,pgsql}/upgrades/notification-history.sql): adds the notification_history and skipped_notification_history tables, adds incident_history.event_id, and changes event_queue.id from a binary hash column to a UUID column. A running deployment needs the migration applied before upgrading.

Testing

Added unit tests for event ID generation (event_id_test.go), the event queue (queue_test.go), notification history persistence (notification_history_test.go, requires a test database), and the new listener endpoint (listener/notification_history_test.go).

To verify manually, run the daemon, trigger some events, then query the endpoint as documented in the new doc/20-HTTP-API.md section:

curl -u 'example:insecureinsecure' 'http://localhost:5680/notification-history?since=<unix-ms>'

Depends on:

resloves #415

@cla-bot cla-bot Bot added the cla/signed CLA is signed by all contributors of a PR label Jul 22, 2026
@Jan-Schuppik Jan-Schuppik self-assigned this Jul 22, 2026
@Jan-Schuppik
Jan-Schuppik force-pushed the new-api-endpoint-notification-history branch from 003a26d to 89af19b Compare July 27, 2026 11:46
@nilmerg nilmerg linked an issue Aug 12, 2026 that may be closed by this pull request
@Jan-Schuppik
Jan-Schuppik force-pushed the new-api-endpoint-notification-history branch from d18d485 to 8612926 Compare August 13, 2026 13:58
@Jan-Schuppik
Jan-Schuppik requested a review from yhabteab August 13, 2026 14:42

@yhabteab yhabteab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I haven't got the time to review this thoroughly, but I left some inline comments below. I'll try to get back to this tomorrow and do a more thorough review.

Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread internal/event/event_id_test.go Outdated
Comment thread internal/event/event_id_test.go Outdated
Comment thread internal/event/event_id_test.go Outdated
Comment thread internal/event/queue.go Outdated
Comment thread internal/recipient/contact_role.go Outdated
Comment thread internal/incident/incident.go Outdated
Comment thread internal/incident/notification_history.go Outdated
Comment thread internal/incident/notification_history.go Outdated
Comment thread internal/incident/notification_history.go Outdated
Comment thread internal/incident/notification_history.go Outdated
Comment thread internal/utils/contact_role.go Outdated
Comment thread schema/mysql/upgrades/notification-history.sql Outdated
Comment thread schema/mysql/upgrades/notification-history.sql Outdated
Comment thread schema/mysql/upgrades/notification-history.sql Outdated
Comment thread schema/mysql/upgrades/notification-history.sql Outdated
Comment thread doc/40-Authentication.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread internal/listener/listener.go Outdated
Comment thread internal/event/queue.go
Comment thread internal/incident/incident.go Outdated
Comment thread internal/incident/incidents_test.go Outdated
Comment thread internal/incident/notification_history.go Outdated

@yhabteab yhabteab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another round of review comments :). Sorry for the chunked review comments but the PR is quite big, so I need to do something else to get my head right again :). Apart from the tests, I've now reviewed all at least once.

Comment thread internal/rule/rule.go Outdated
Comment thread internal/testutils/testutils.go Outdated
Comment thread internal/incident/sync.go
Comment thread internal/rule/rule.go Outdated
Comment thread schema/mysql/upgrades/notification-history.sql Outdated
Comment thread schema/mysql/upgrades/notification-history.sql Outdated
@Jan-Schuppik
Jan-Schuppik force-pushed the new-api-endpoint-notification-history branch from 2221967 to c780c0c Compare August 27, 2026 14:48
@Jan-Schuppik
Jan-Schuppik marked this pull request as ready for review August 27, 2026 14:49
@Jan-Schuppik
Jan-Schuppik force-pushed the new-api-endpoint-notification-history branch from dd39884 to 1c89f41 Compare August 31, 2026 08:12
Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread doc/20-HTTP-API.md Outdated
Comment thread internal/event/queue.go Outdated
Comment thread internal/incident/incident.go Outdated
Comment thread internal/incident/sync.go Outdated
Comment thread internal/listener/listener.go
Comment thread internal/rule/rule.go Outdated
Comment thread internal/testutils/testutils.go Outdated
Comment thread schema/pgsql/upgrades/notification-history.sql Outdated

@yhabteab yhabteab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apart from the below comment, I think I'm done reviewing the non-test code now.

Comment thread schema/pgsql/upgrades/notification-history.sql Outdated

@yhabteab yhabteab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, sorry. I also forget to mention that you've to adjust the retention pruner for the object table to consider the notification_history reference.

@Jan-Schuppik
Jan-Schuppik force-pushed the new-api-endpoint-notification-history branch 3 times, most recently from 06a5b5b to ab2eb95 Compare September 1, 2026 15:07
Comment thread doc/03-Configuration.md Outdated
Comment thread internal/incident/incidents_test.go Outdated
Comment thread internal/incident/incidents_test.go Outdated
Comment thread internal/incident/incidents_test.go Outdated
Comment thread internal/incident/incidents_test.go Outdated
Comment thread internal/retention/prune.go Outdated
Comment thread schema/mysql/upgrades/notification-history.sql Outdated
Comment thread schema/mysql/upgrades/notification-history.sql Outdated
Comment thread schema/mysql/upgrades/notification-history.sql
Comment thread schema/pgsql/upgrades/notification-history.sql
@Jan-Schuppik
Jan-Schuppik force-pushed the new-api-endpoint-notification-history branch from 32f9075 to 1af62c9 Compare September 2, 2026 12:38
Replace notification_state tracking with a proper notification_history
table so past notifications can be queried directly, instead of being
inferred from incident state. Add the corresponding sync logic, schema
migrations for MySQL and PostgreSQL, and a new /notification-history
HTTP API endpoint with matching documentation.

Extend OrphanRowPruner to accept multiple referencing tables via a
ReferencedBy list, since notification_history rows can now be
referenced from more than one place. Also move contact_role.go from
the incident package into recipient, where it fits better, and
refresh the HTTP API docs' authentication section to cover all three
endpoints (process-event, incidents, notification-history) in one
place.
@Jan-Schuppik
Jan-Schuppik force-pushed the new-api-endpoint-notification-history branch from 36a4e79 to 111c066 Compare September 2, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New API endpoint to fetch notification history

2 participants