API and integration surface
Kener exposes server-side interfaces for status data, monitor control, incident and maintenance work, page management, image assets, health signals from external jobs, and external sign-in. The versioned REST API is the main contract for external automation. Browser management actions, OpenID Connect login, heartbeat calls, and dashboard data requests serve different clients and security needs.
Interface map
Kener separates read and write access by the kind of client and the kind of work it performs. Use the versioned REST API for durable integrations. Use the heartbeat endpoint to report that a job ran. Use OpenID Connect for external user sign-in. Treat the management action endpoint as an internal browser interface.
Versioned REST API
The public REST API is rooted at /api/v4 and presents Kener data as resources. It lets an integration read and change monitors, monitoring samples, incidents, incident comments, maintenances, maintenance events, pages, images, and approved site settings such as OIDC settings. Monitor management also protects URL-facing tags, validates proxy and heartbeat settings, and masks secrets in returned data. The API also supports creation of the main status-page resources, so external automation can build and update a status surface without using the browser. API writes use the same controller paths as dashboard writes, which keeps related cache, queue, and relationship effects aligned. Request bodies follow the versioned OpenAPI contract and return a stable JSON error shape when validation fails. The public REST API page describes the resource paths and payload contracts.
References: src/…/EGM.md• L1-14 src/…/+server.ts• L20-37 src/…/+server.ts• L40-155 src/…/+server.ts• L22-30 src/…/+server.ts• L33-186 src/…/+server.ts• L18-79 src/…/+server.ts• L82-173 src/…/+server.ts• L34-89 src/…/+server.ts• L91-209 src/…/+server.ts• L37-46 src/…/+server.ts• L49-163 src/…/+server.ts• L12-37 src/…/write-parity.test.ts• L668-675
Resource creation
The create operations turn external management input into complete Kener resources. Each operation checks the data needed to connect the new resource to the status page, then returns the stored resource so the caller can continue from Kener's accepted state.
| Resource | Integration result |
|---|---|
| Monitor | Adds a uniquely tagged service that can be listed and monitored. |
| Incident | Publishes an API-sourced incident and can attach it to existing monitors. |
| Maintenance | Schedules planned work with a repeat rule and optional monitor impact. |
| Page | Adds a public page with a path, display content, settings, and ordered monitor links. |
These operations use UTC-second input for time values and align stored incident, comment, and maintenance time points to minute boundaries. Maintenance repeat rules use the iCalendar RRULE form. Monitor tags and page paths must remain usable as resource addresses, and references to monitors must resolve before Kener creates the link. The home page has the stable ~home address, and nested comments and maintenance events remain owned by their parent resource.
References: src/…/+server.ts• L40-155 src/…/+server.ts• L82-173 src/…/+server.ts• L49-93 src/…/+server.ts• L91-209 src/…/+server.ts• L49-163 src/…/+server.ts• L81-124 src/…/+server.ts• L44-74
Image upload
The image endpoint lets an integration store an image before another API resource refers to it. The caller sends base64 image data and a MIME type. Kener checks the image content and size, can fit or crop it to requested bounds, stores it, and returns metadata with an asset URL. The upload accepts common raster formats but rejects SVG data, limits decoded data to 2 MB, and limits each side to 4096 pixels.
A successful upload returns 201; invalid input returns a stable BAD_REQUEST response and does not store the image. A storage failure returns a fixed INTERNAL_ERROR response.
References: src/…/+server.ts• L7-37 src/…/server.test.ts• L36-64 src/…/server.test.ts• L72-138
Dashboard data endpoints
The dashboard data surface supplies read models for the status UI rather than a stable external resource contract. It returns monitor bars for one or many monitors, latency charts over selected ranges, day-level status and latency detail, day incidents and maintenances, and page-scoped events for a month. These handlers fill missing periods and aggregate data so the UI receives chart-ready results. Monitor-bar requests also normalize malformed numeric query values to safe defaults before loading a bounded time range.
The bulk monitor view limits the request to 100 tags and the monitor bar view to 90 days. Day detail uses the signed-in user's visibility of hidden monitors. Use the versioned REST API for external automation instead of depending on these dashboard-shaped responses.
References: src/…/get.ts• L10-60 src/…/shared.ts• L25-113 src/…/get.ts• L17-123 src/…/get.test.ts• L31-62 src/…/get.ts• L19-112 src/…/post.ts• L29-104 src/…/post.ts• L100-178 src/…/post.ts• L19-51 src/…/post.ts• L20-52 src/…/post.ts• L17-64
Management action interface
The management interface is a single browser-facing endpoint at /manage/api. A request names an action and supplies its inputs in data. The server checks the signed-in session and the permission mapped to that action before it can change Kener state. This interface supports the manage UI across monitors, alerts, incidents, maintenances, pages, users, subscriptions, images, settings, roles, email templates, Docker resources, and OIDC administration; it is not the stable external API contract.
Management actions can test OIDC discovery, read OIDC settings with the client secret masked, and maintain group-to-role mappings. When saved OIDC settings omit the client secret, Kener keeps the stored secret. A settings change also clears the OIDC discovery cache so later sign-ins use the new connection details. The site-data key registry limits configuration updates to known settings and assigns validation rules and data types to those settings.
The REST API and management actions share the domain controllers for writes. Parity checks compare stored records and downstream signals from both surfaces, while a route check prevents v4 handlers from writing to the database directly. Secret values remain masked in responses; omitting an existing OIDC client secret preserves the stored value, while an untrusted masked secret submitted for another integration is not treated as the real secret and can make that integration fail closed.
References: src/…/+server.ts• L142-167 src/…/+server.ts• L214-287 src/…/+server.ts• L402-430 src/…/+server.ts• L518-681 src/…/+server.ts• L682-719 src/…/+server.ts• L13-120 src/…/siteDataKeys.ts• L18-323 src/…/write-parity.test.ts• L668-675
Server-side integration adapters
Management automation can use server-side adapters when a task needs access to a protected external service. Alert triggers keep destination URLs and header values masked while they are edited, and the Docker container picker restores saved monitor secrets before it asks the Docker service for container data. These adapters return only the data needed by the management flow, so external credentials stay on the server.
References: src/…/triggerController.ts• L21-64 src/…/triggerController.ts• L67-89 src/…/dockerController.ts• L13-29
OpenID Connect authentication
OpenID Connect (OIDC) is an external sign-in flow in which an identity provider (IdP) confirms a user's identity before Kener creates a local session. The login route builds a provider redirect with state, nonce, and PKCE values. The callback checks those values, exchanges the authorization code, reads identity claims, and creates the Kener session.
The user link is based on the provider subject. New users are created only when auto-provisioning is enabled, and an existing local account with the same email is not merged. On later sign-ins, mapped IdP groups update OIDC-managed roles while manually assigned roles remain. A configured default role applies when no group mapping matches.
The sign-in page can offer both OIDC and local password login. Configuration controls whether local login is allowed, while KENER_FORCE_LOCAL_LOGIN=true provides a local fallback when needed. OIDC errors return stable codes that the sign-in page maps to user-facing messages rather than passing provider text through the URL.
References: src/…/oidcController.ts• L17-29 src/…/oidcController.ts• L37-121 src/…/oidcController.ts• L124-195 src/…/oidcController.ts• L207-315 src/…/+server.ts• L5-38 src/…/+server.ts• L12-76 src/…/+page.server.ts• L14-50 src/…/+page.server.ts• L54-127
Heartbeat integration
The heartbeat interface lets a scheduled job or worker push a completion signal without sending monitoring data itself. The caller uses /ext/heartbeat/{tag}/{secret} with GET or POST; Kener uses the signal time and the monitor thresholds to derive the current state. This is the smallest integration surface for jobs that only need to say that they completed.
References: src/…/+server.ts• L4-20 src/…/heartbeat.md• L6-18 src/…/heartbeat.md• L29-41 src/…/monitorsController.ts• L524-570
Outbound API checks
An API monitor is Kener's server-side client for an HTTP or HTTPS service. It sends the configured request, measures the response, and applies a built-in or custom evaluation rule so the result becomes a Kener monitoring state. This supports integrations where Kener must test a service rather than wait for that service to call Kener.
References: src/…/apiCall.ts• L22-39 src/…/apiCall.ts• L73-107 src/…/apiCall.ts• L138-211 src/…/api.md• L6-25
Request lifecycle
API requests pass through a shared server boundary before a resource handler reads or changes data. The boundary applies cross-site form checks, authenticates protected API calls, resolves resource identifiers, and makes the resolved records available to the handler. This keeps resource handlers focused on validation and the resource operation.
The request path follows this sequence:
flowchart TD
A[HTTP request] --> B{Form write?}
B -->|yes| C[Check request origin]
B -->|no| D[API path check]
C --> D
D -->|Protected /api path| E[Read Bearer token]
D -->|Public path or non-API path| H[Resolve route]
E --> F{Active API key?}
F -->|no| G[JSON 401]
F -->|yes| I[Resolve monitor, incident, maintenance, or page]
I -->|missing resource| J[JSON 404]
I -->|found| H
H --> K[Run request handler]
K --> L[JSON response]
Request boundary
The shared server hook treats paths under /api/ as API requests. Except for the exact public status path, an API request must carry Authorization: Bearer <API key>. The key is hashed for lookup and must have an ACTIVE status. Missing or invalid keys stop the request with a JSON 401 response.
References: src/hooks.server.ts• L9-40 src/hooks.server.ts• L94-121 src/…/apiController.ts• L17-21 src/…/apiController.ts• L62-71 src/…/EGM.md• L3-9
Resource lookup
For resource paths, the request boundary checks that the monitor tag, incident ID, maintenance ID, or page path exists before the handler runs. It stores the matching record in request-local state. An unknown /api/ route or missing resource returns a JSON 404 instead of an HTML page.
References: src/hooks.server.ts• L123-204 src/…/+server.ts• L22-27 src/…/+server.ts• L51-65 src/…/+server.ts• L45-62 src/…/EGM.md• L3-9
Resource operation
Resource handlers read JSON bodies for write operations and return JSON resource objects or structured errors. A shared body reader checks each body against the v4 request schema before the handler changes state. Handlers then validate values at the API boundary, normalize time values to UTC minute points where the data model requires it, and return the stored resource after a successful change. Create operations return the new resource with HTTP 201, while invalid input returns a JSON 400 response with an error code and message.
Write handlers call domain controllers instead of changing database rows directly. This makes API writes use the same business effects as dashboard writes, including incident subscriber notifications, monitor cache refreshes, and alert evaluation requests where those effects apply.
References: src/…/EGM.md• L7-14 src/…/+server.ts• L40-155 src/…/+server.ts• L33-169 src/…/+server.ts• L82-173 src/…/+server.ts• L68-158 src/…/+server.ts• L49-93 src/…/+server.ts• L92-175 src/…/+server.ts• L91-209 src/…/+server.ts• L79-204 src/…/+server.ts• L49-163 src/…/+server.ts• L65-284 src/…/write-parity.test.ts• L997-1041
Resource model
The REST surface groups operations around the objects that drive a status page. These groups connect operational signals to the public view: monitors provide status data, incidents explain service impact, maintenances describe planned work, pages select what an audience sees, and images provide reusable visual assets.
| Resource group | Integration purpose |
|---|---|
| Monitors | Create, inspect, update, or remove monitored services and their settings. |
| Monitoring data | Read time ranges or individual samples. Write manual status and latency samples when an external system is the source of truth. |
| Incidents and comments | Publish service events and their progress for the status page. |
| Maintenances and events | Schedule planned work and control its generated event windows. |
| Pages | Manage public page content and the monitors shown on each page. |
| Images | Store validated image assets and return metadata that other resources can use. |
| Site settings | Read or update only known configuration keys, including OIDC settings. |
State propagation
Writes to monitoring data do more than store a row. Kener refreshes the latest-value cache so grouped monitors can see the new state, then asks the alerting system to re-evaluate the written sample. A queue failure does not undo the committed sample, so an integration can receive a successful write while alert processing completes later.
Incident comment writes also move the incident state through the shared incident controller. A resolving comment sets the incident end time, a later investigating comment can clear it, and subscriber notification work is queued after a valid change.
References: src/…/+server.ts• L74-139 src/…/+server.ts• L67-154 src/…/+server.ts• L49-93 src/…/+server.ts• L140-175 src/…/write-parity.test.ts• L95-119 src/…/monitorsController.ts• L132-155
Time representation
The API accepts timestamps as UTC seconds. Monitoring samples, incident times, comments, and maintenance times are aligned to minute starts where their handlers require alignment. Clients that exchange time windows should therefore treat the returned timestamps as the stored time points rather than as arbitrary request times.
References: src/…/+server.ts• L20-55 src/…/+server.ts• L124-134 src/…/+server.ts• L138-156 src/…/+server.ts• L67-78
Relationship boundaries
Nested paths enforce ownership between related resources. For example, an event must belong to the maintenance named in its parent path, and a comment must belong to the incident named in its parent path. Page and incident updates also verify referenced monitor tags before creating links.
References: src/…/+server.ts• L44-67 src/…/+server.ts• L37-83 src/…/+server.ts• L152-175
Contract discovery
The v4 API contract is available as an OpenAPI JSON document and as a rendered reference page. The request body reader and parity checks use static/…/v4.json as the machine-readable contract, while the rendered documentation serves the specification through docs/…/spec.json. Use that contract and the public REST API page when building a client instead of relying on the internal management action names.
References: src/…/EGM.md• L11-14 src/…/write-parity.test.ts• L821-836 src/…/write-parity.test.ts• L989-1041 src/…/+server.ts• L6-15 src/…/+server.ts• L9-35
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to API path patterns must stay aligned with the resource lookup rules in src/hooks.server.ts; a new nested identifier can otherwise skip validation or receive the wrong
404behavior. - Changes to response or request shapes must stay aligned across the route handler, DTO types in src/…/api.ts, and static/…/v4.json.
- Changes to create operations must keep resource links valid. Monitor tags used by incidents, maintenances, and pages must still resolve, and page paths must remain addressable.
- Changes to image upload rules must stay aligned across MIME checks, decoded-size and dimension limits, resize behavior, stored asset metadata, and the v4 contract.
- Changes to time input rules must stay aligned across incident, comment, and maintenance writes, stored minute points, and the public API contract.
- Changes to manual monitoring writes must preserve the cache refresh and alert enqueue steps. A stored value can look correct while dashboards or alerts still show old state.
- Changes to monitor
type_datamust keep secret masking and restoration aligned with proxy validation, heartbeat secret rules, and the monitor create and update routes. - Changes to monitor deletion must preserve cleanup of monitoring data, status-page links, alert records, group membership, and caches.
- Changes to trigger or Docker adapter inputs must preserve server-side secret restoration before calls to alert destinations or the Docker service.
- Changes to API key status or format must remain compatible with both key creation in apiController.ts and Bearer validation in hooks.server.ts.
- Changes to dashboard monitor query parsing must keep malformed numeric values from creating invalid or unbounded time-range queries, while preserving the 90-day and 100-tag limits.
- Changes to management actions must update the action-to-permission map and the browser caller together. The endpoint rejects actions that have no known permission mapping.
- Changes to a v4 write must keep its controller call and downstream signals aligned with the matching management action. The parity suite checks both stored data and queued work.
- Changes to OIDC settings must keep the site configuration key, masked management response, client-secret preservation rule, and discovery-cache invalidation aligned.
- Changes to OIDC login claims or role mappings must preserve the subject link, email conflict rule, default-role fallback, and separation between manual and OIDC-managed roles.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Protected API call has no valid Bearer token | Kener returns JSON 401 and does not run the resource handler. | Send an active API key in the Authorization header. |
| Resource identifier does not exist or does not belong to its parent | Kener returns JSON 404; no child resource operation runs. | Resolve the monitor tag or parent resource before sending a nested request. |
| Invalid JSON, wrong body type, or invalid resource value | Kener returns JSON 400 and does not apply the write. | Send the documented DTO shape and valid UTC-second, RRULE, path, or enum values. |
| Monitor proxy is not an HTTP or HTTPS URL, or a new heartbeat secret breaks its rule | Kener returns JSON 400 and does not save the monitor. | Send a supported proxy URL and a valid heartbeat secret, or omit the secret so Kener can generate one. |
| A masked monitor secret comes from a different stored monitor | The mask is not accepted as a real credential; the saved value becomes empty instead of leaking another monitor's secret. | Use the mask only to preserve the secret for the same monitor, or send a new real value. |
| Create request names a monitor that does not exist | Kener rejects the incident, maintenance, or page link instead of creating that relationship. | Create or resolve the monitor before sending the related resource request. |
| Image data is invalid, too large, an SVG, or does not match its MIME type | Kener returns 400 BAD_REQUEST and stores nothing. | Send a supported image whose decoded data and dimensions are within the upload limits. |
| Image storage fails after validation | Kener returns a fixed 500 INTERNAL_ERROR; the caller does not receive an asset URL. | Treat the upload as unsuccessful and retry only after checking storage health. |
| Monitoring data write reaches the database while the alert queue is unavailable | The data write succeeds, but alert evaluation is delayed or absent until another evaluation occurs. | Monitor queue health when manual writes drive alert behavior. |
| A resolving incident comment is dated before the incident start | Kener returns 400 and saves neither the comment nor the incident state change. | Use a comment timestamp at or after the incident start. |
| A maintenance event update sends status and window fields together | Kener returns 400 and does not choose an update mode. | Send either a valid terminal status or both valid window times. |
| Management request uses an unknown action or lacks its permission | Kener returns 400 or 403 before the action runs. | Use a supported management action with a session that has the mapped permission. |
| API monitor evaluation fails or returns an invalid result | Kener records an error result and treats the check as down. | Keep the endpoint response and evaluation result within the monitor contract. |
| OIDC callback lacks valid state, nonce, or PKCE session data | Kener rejects the sign-in attempt and asks the user to start again. | Keep the OIDC callback cookies available through the provider redirect. |
| OIDC user is not provisioned and auto-creation is disabled | Kener rejects the login without creating a local account. | Provision the user or enable controlled auto-creation. |
| OIDC email belongs to a different local account | Kener rejects a new account or keeps the existing user's email; accounts are not merged. | Use one account identity per email or resolve the account ownership first. |
| OIDC user is inactive or has no roles after sign-in | Kener does not create an active management session. | Activate the user and assign a valid role through local administration or group mapping. |
| A masked secret from another instance is saved as an integration secret | Secret-backed verification fails closed instead of using the masked value as a working credential. | Do not send response masks as replacement secrets; send the real secret or omit it when the endpoint supports preservation. |
Key files
| File | Why to read it |
|---|---|
| src/hooks.server.ts | Shared authentication, origin checks, resource lookup, and API error boundary. |
| src/…/apiController.ts | API key creation and active-key verification. |
| src/…/monitorsController.ts | Monitor validation, secret handling, monitoring writes, cache updates, alert enqueueing, and complete deletion cleanup. |
| src/…/triggerController.ts | Alert destination storage, email validation, and trigger secret masking and restoration. |
| src/…/dockerController.ts | Server-side Docker container lookup for monitor management. |
| src/…/controller.ts | Central controller export surface, including the OIDC controller and site data key registry. |
| src/…/oidcController.ts | OIDC discovery, sign-in data exchange, user provisioning, role sync, and session creation. |
| src/…/siteDataKeys.ts | Known site configuration keys and their value checks, including OIDC settings. |
| src/…/api.ts | Request and response DTOs for the versioned REST contract. |
| src/…/site.ts | OIDC configuration and group-to-role mapping shapes. |
| src/…/EGM.md | Shared v4 route rules, request validation, errors, and write-safety checks. |
| src/…/+server.ts | Monitor listing and creation for external automation. |
| src/…/+server.ts | Monitor retrieval, update, deletion, and secret-safe responses. |
| src/…/+server.ts | Monitoring data reads and range writes plus downstream cache and alert effects. |
| src/…/+server.ts | Incident listing and publication with monitor relationships. |
| src/…/+server.ts | Incident retrieval, update, and removal. |
| src/…/+server.ts | Incident progress comments and their state effects. |
| src/…/+server.ts | Planned-work listing and scheduling. |
| src/…/+server.ts | Maintenance event ownership and window or status changes. |
| src/…/+server.ts | Public-page listing, creation, settings, and monitor assignment. |
| src/…/+server.ts | Public-page retrieval, update, deletion, and home-page rules. |
| src/…/+server.ts | Validated image upload and asset metadata response. |
| src/…/+server.ts | Site setting reads and updates through the known-key registry. |
| src/…/write-parity.test.ts | Checks that v4 writes match dashboard writes and preserve downstream signals. |
| src/…/server.test.ts | Guarantees image validation, resizing, and stable upload errors. |
| src/…/get.ts | Bulk dashboard monitor summaries and hidden-monitor visibility. |
| src/…/get.test.ts | Guarantees safe query parsing for bulk monitor summary requests. |
| src/…/get.ts | Chart-ready latency ranges for the dashboard. |
| src/…/post.ts | Page-scoped incident and maintenance event data for the dashboard. |
| src/…/+server.ts | Browser management action dispatch, permission checks, and OIDC settings actions. |
| src/…/+server.ts | OIDC authorization redirect and short-lived callback state. |
| src/…/+server.ts | OIDC callback validation, user linking, and session handoff. |
| src/…/+server.ts | Minimal push integration for external jobs. |
| src/…/apiCall.ts | Server-side HTTP checks for API monitors. |
| static/…/v4.json | Machine-readable v4 API contract used by request validation and the reference page. |