Webhook notifications
What a Costfluent webhook channel posts to your endpoint for each kind of notification, and how to tell the kinds and the repeats apart.
Planned: webhook channels
A webhook channel posts each notification to your endpoint as JSON. Notification channels owns adding the channel and choosing what goes to it; this page describes what your endpoint receives.
Before you start
- Your endpoint is reached at a public address and answers within 10 seconds.
- You kept the channel's signing secret, which Costfluent shows once when it adds the channel or rotates the secret (Check a delivery).
The request
Each notification is one POST with a JSON body:
Code
| Field | Meaning |
|---|---|
event_type | What the notification is about; see the table below. Branch on it rather than on the subject. |
schema_version | The version of this body. It is 1, and rises only when a field changes meaning or goes away; a new field or event type does not raise it. |
subject, content, html_content | The notification as a person reads it, in plain text and in HTML. The wording can change. |
timestamp | When this attempt was sent, in UTC. It changes on every attempt, so the signature does too. |
app_id | The channel the notification was sent to. |
delivery_id | The notification's id. It is the same on every attempt, so your endpoint can drop a repeat, and the signature covers it. null for channel_test. |
occurred_at | When Costfluent recorded what the notification reports, in UTC. It is the same on every attempt, so order notifications by it rather than by timestamp. For channel_test, when it was sent. |
data | The event's own fields, by event_type; see Event data. An empty object for channel_test. Read figures and ids from here rather than from the text. |
The request carries these headers:
| Header | Value |
|---|---|
X-Costfluent-Event | The event_type, so a router can dispatch without reading the body. |
X-Costfluent-Delivery | The body's delivery_id, so a router can read it without parsing the body. The signature does not cover a header, so drop repeats by the body's delivery_id. A channel test has none. |
X-Costfluent-Signature | sha256= and the lowercase hex HMAC-SHA256 of the raw body, keyed with the channel's signing secret. Absent only when the channel has no secret. |
Event types
event_type | Sent when |
|---|---|
budget_alert | A budget crosses one of its thresholds. |
cost_alert | A spend threshold, percentage change or tag coverage alert fires. |
anomaly | A cost anomaly is detected in a workspace whose anomaly notifications name the channel. |
commitment_expiry | A commitment enters the lead time of a workspace whose commitment expiry notices name the channel. Sent once per commitment and term; a channel two workspaces name receives it once. |
credit_runway | A connection's credits run out, or one of its credit grants expires with credit left, within 30 days. Sent once per grant and kind of notice to each enabled channel that answers to someone who can see the connection's credits, or to the organization (Credits). |
connection_stale | A connection's data runs two days behind its sync schedule, and once more at seven days; a Kubernetes cluster's agent has not reported for a day, and once more at three days. Every enabled channel of the organization receives it. |
channel_test | Someone selects Test on the channel. |
savings_item_status | A savings opportunity is accepted, implemented, verified, rejected, withdrawn or reopened. |
provider_health | A connection's health changes, its last sync turns from success to failure or back, or it is disabled or enabled again. A sync that ends as the last one did sends nothing. |
spend_band | A completed month's tracked spend is counted above the plan's band, or a second such month schedules the move to a larger plan or, on Free, pauses collection. Sent only while the channel answers to someone who can manage billing, or to the organization (Notification channels). |
subscription_status | The subscription's plan or status changes. Sent only while the channel answers to someone who can manage billing, or to the organization (Notification channels). |
anomaly_status | An anomaly is acknowledged, archived, ignored or reopened, by a person or by Costfluent archiving it. |
connection_imported | A new connection's first import finishes: every month its first collection asked for has arrived. Sent once per connection. |
The last six are state changes, which a channel receives only when it subscribes to them (Choose state changes).
Choose state changes
A webhook channel subscribes to state changes in its configuration's events: tick them under Events when you add or edit the channel in the console, or list them in the config the Public API or the Terraform provider sends:
Code
A channel without events receives none of them, as before they existed. Saving the channel refuses any name outside these six, so events cannot hold budget_alert, credit_runway or another routed event. Alerts, anomalies, expiring commitments, credit notices and stale connections reach the channel as Notification channels routes them, whatever events says.
Event data
data holds the event as Costfluent stored it when the event happened, so every attempt at one notification carries the same values. Ids are the ids the Public API uses, amounts are numbers in the stated currency (a usage budget's are quantities; see below) and those in unconverted each in their own currency, days are YYYY-MM-DD and instants are UTC. An id is null for a notification queued before Costfluent recorded it, and workspace_id is null when the workspace no longer exists.
event_type | Fields of data |
|---|---|
budget_alert | budget_id, budget_name, workspace_id, threshold_percent, budget_amount, current_spend, percent_used, currency, measure (cost or usage), usage_unit (the unit a usage budget counts, null for a cost budget), triggered_at, unconverted (the cost not counted because no usable exchange rate converts it into currency, per billing currency, each with currency and amount; empty when everything counted), basis (actual when the threshold is held against the spend so far, forecast when it is held against the forecast for the period's end), forecast_amount, forecast_lower_bound and forecast_upper_bound (where the period is forecast to end and the forecast's range, in currency; null unless basis is forecast), period_end (the period's last day, the day a forecast is for) |
cost_alert | alert_id, alert_name, workspace_id, threshold_type (absolute, percentageIncrease, budgetPercentage or tagCoverageBelow; for budgetPercentage, threshold_value and actual_value are amounts of month-to-date spend in currency, not a share of a budget), threshold_value, actual_value, comparison_value (the comparison window's cost, or null), comparison_period (previousDay, previousWeek, previousMonth, sameDayLastMonth or null), currency, triggered_at, unconverted (the cost not counted because no usable exchange rate converts it into currency, per billing currency, each with currency and amount; empty when everything counted) |
anomaly | anomaly_id, workspace_id, anomaly_type (spike, or new_spend when a service or a region of one started costing money; read any other value as an anomaly), severity, service_name, region (the region with more than half the increase, otherwise null; for new_spend, the new region with more than half the new spend), anomaly_date, expected_cost (for new_spend, the day's cost less the new spend), actual_cost, deviation_percent (for new_spend, the new spend over expected_cost, or 100 when all of the day's cost is new), currency, description, detected_at, attributed_resource_id, contributors (up to three resources that added most to the increase, largest first, each with account_id, resource_id and increase), attributed_sku (the SKU with more than half the increase, otherwise null), and sku_contributors: up to three SKUs that added most to the increase, largest first, each with sku (the provider's SKU label, such as an AWS usage type, or its SKU id when it has none) and increase |
commitment_expiry | commitment_id (the provider's own id: a Savings Plan's ARN, or a reservation's id), commitment_type (SavingsPlan, ReservedInstance or CommittedUseDiscount), description, account_id, region (null for a commitment that applies in every region), connection_id, connection_name, workspace_id, ends_at, days_until_expiry (whole days from the notice to ends_at) |
credit_runway | connection_id, connection_name, credit_grant_id, credit_grant_name (for run_out, the grant whose end starts paid usage), notice (run_out or expiry), day (for run_out the day paid usage is projected to start, for expiry the grant's last day), amount (for run_out what the connection's grants have left, for expiry what is projected to go unused), currency |
connection_stale | connection_id, connection_name, data_through (null when it never delivered data), days_overdue (for a Kubernetes cluster, whole days since last_report_at), notice (1, then 2 for the repeat), sync_status, sync_error, last_report_at (when a Kubernetes cluster's agent last reported, the instant its notice counts from; null for any other connection) |
channel_test | None: data is {}. |
savings_item_status | opportunity_id, workspace_id, title, status and previous_status (open, accepted, implemented, verified, rejected or withdrawn), estimated_monthly_saving, currency, changed_at |
provider_health | connection_id, provider (as the Public API spells it, aws for example), connection_name, health_status and previous_health_status (unknown, healthy, degraded or failed), sync_status and previous_sync_status (the last sync's outcome: success, error, throttled, quota_exceeded, restatement_refused, collection_stopped, processing_failed, or null before the first sync), disabled, error (the last error as recorded, in English, or null), changed_at |
spend_band | step (firstMonthAbove, upgradeScheduled, salesReferral or collectionPaused), month (YYYY-MM), tracked_spend, currency, plan, band_plan (pro, business or custom), effective_on (the day the plan moves, or null) |
subscription_status | plan and previous_plan, status and previous_status (free, active, pastDue or canceled), changed_at |
anomaly_status | anomaly_id, workspace_id, status and previous_status (open, acknowledged, archived or ignored), reason (expired or restated when Costfluent archived it, otherwise null), changed_at |
connection_imported | connection_id, provider (as the Public API spells it, aws for example), connection_name, first_month and last_month (YYYY-MM, the first and last month with imported cost, or null when the import found none), records (the cost records imported, 0 when it found none), data_through (the last day the imported data covers, or null), detail_follows (true when Costfluent read an AWS period from Cost Explorer, so resource and tag detail follows with the export within 24 to 72 hours), changed_at |
A budget_alert whose basis is forecast was sent when the forecast for the period reached the threshold, before the spend did: forecast_amount is the forecast that reached it, percent_used and current_spend are still the spend so far. Only a cost budget has a forecast, so a forecast's fields are always money. See Budgets.
A budget_alert whose measure is usage comes from a usage budget: its budget_amount and current_spend are quantities in usage_unit, and currency is not their unit, so read measure before treating them as money. See Budgets.
A new field can appear in data without notice, so ignore the ones you do not know.
Check a delivery
When Costfluent adds a webhook channel without a secret of yours, it generates one, which Add notification channel in the console and the Public API's create answer (signingSecret) show only once. A channel created through the Public API with its own secret in its config is signed with that one. A secret you choose, on create or update, must be at least 32 characters; a shorter one is refused with 400. A secret saved before this rule keeps working, and sending it back unchanged with the channel's config is accepted. Keep the secret where your endpoint can read it, then for each request:
- Compute the HMAC-SHA256 of the raw request body with the secret, before parsing it: parsing and serializing again changes the bytes.
- Compare
sha256=and its lowercase hex digest with theX-Costfluent-Signatureheader in constant time, and refuse the request when they differ. - Refuse a request whose body's
timestampis further from your clock than you allow, five minutes for example. The signature covers the timestamp, so a recorded request cannot be replayed later with a new one. - Drop a request whose body's
delivery_idyou already handled: a retry carries the same id, a new timestamp and a new signature. The signature coversdelivery_id, and not theX-Costfluent-Deliveryheader. - Apply state changes in the order of their
occurred_at: a retry can arrive after a later change.
Code
Anyone who can reach your endpoint can post to it. Without these checks, a forged or replayed request looks like a real notification.
To find a delivery your endpoint logged, or to send a failed one again, select Deliveries on the channel in the console; see Notification channels. A resent delivery keeps its delivery_id, so step 4 drops it when your endpoint already handled it.
Rotate the signing secret
Rotate the secret when it may have leaked, or to sign a channel that has none. In the console, the pencil on the channel opens Edit notification channel, where Rotate signing secret asks you to confirm, then shows the new Signing secret once. Costfluent generates it; copy it before you select Done. Through the Public API, you update the channel's config with a secret of your own instead.
The old secret stops signing at once: no period accepts both. Until your endpoint checks the new secret, it refuses the requests signed with it, and Costfluent retries each delivery after 1, 5, 15, 60 and 240 minutes, about 5 hours in all. Give your endpoint the new secret right after you rotate, and the retries reach it.
How it behaves
- Any
2xxanswer is a delivery. Another status, a redirect, or no answer within 10 seconds is a failed attempt, retried as Notification channels describes. - A redirect is never followed.
- Scheduled cost reports are delivered by email, Slack and Microsoft Teams only, so no webhook receives them.