Reference
Cost Alerts
List, create, change, pause and delete the cost alerts that watch an account, a saved cost view or your commitments, and read what each one has said.
The cost alert methods manage the rules Cost alerts describes. Reads take any key. Creating, changing, pausing and deleting take a read-write key. The examples show the Go, Python and TypeScript SDKs and plain HTTP. Python and TypeScript carry these methods from 0.2.0, and Go from v0.2.0.
Methods
| Method | Returns |
|---|---|
| List alerts | Every alert, with the live state of what each one watches |
| List sources | What an alert can watch |
| Create an alert | The stored alert |
| Read one alert | One alert |
| Change an alert | The alert as it now reads |
| Pause and resume | The alert, with who paused it |
| Delete an alert | The id of the alert that is gone |
| Alert events | What one alert has said, newest first |
| Suggestions for an account | Rules the account's own billing history supports |
List alerts
Returns every alert in your organization. watching holds the live state of each thing an alert watches, as the last check left it: ok, pending or firing.
alerts, err := client.CostAlerts.ListAlerts(ctx)List sources
Returns every slice an alert can watch, as id, label, group and provider. group is accounts, views or commitments, and the id is what an alert's source_id takes.
sources, err := client.CostAlerts.ListSources(ctx)Create an alert
Creates an alert. params is the rule: kind is budget, changes or commitment, and Cost alerts says when each one fires. The example fires when month-to-date spend passes 80 percent of a 40,000 budget. An alert needs a member of your organization among its recipients, or a Slack channel.
budget := func(amount float64) *levelfour.BudgetParamsInput {
return &levelfour.BudgetParamsInput{
Budget: &levelfour.BudgetParamsInputBudget{Double: amount},
Reset: "monthly",
Rules: []*levelfour.BudgetRuleInput{
{Amount: &levelfour.BudgetRuleInputAmount{Double: 80}, Unit: "percent"},
},
}
}
created, err := client.CostAlerts.CreateAlert(ctx, &levelfour.CreateAlertRequest{
Name: "Production budget",
SourceID: "123456789012",
Params: &levelfour.CreateAlertRequestParams{Budget: budget(40000)},
Recipients: []*levelfour.AlertRecipient{{Name: "Ana", Email: "ana@example.com", Member: true}},
})
alertID := created.Data.IDOver HTTP, slack_channel_ids takes up to 10 Slack channel ids to post in. Left out, the alert posts in your organization's default channel, if one is set. The SDKs do not carry the field yet, so name channels over HTTP or in the dashboard.
Read one alert
alert, err := client.CostAlerts.GetAlert(ctx, alertID)Change an alert
Only the fields you send change. params replaces the whole rule, so to move one threshold, send the rule back with that figure changed. The API refuses a field sent as null. This raises the budget to 50,000:
_, err = client.CostAlerts.UpdateAlert(ctx, alertID, &levelfour.UpdateAlertRequest{
Params: &levelfour.UpdateAlertRequestParams{Budget: budget(50000)},
})Pause and resume
Pausing is a change to enabled. false silences the alert and records who paused it in paused_by, and true arms it again. A paused alert keeps its history.
enabled := false // true resumes it
_, err = client.CostAlerts.UpdateAlert(ctx, alertID, &levelfour.UpdateAlertRequest{Enabled: &enabled})Delete an alert
Deletes the alert and every event it recorded. Nothing brings either back, so pause an alert you might want again.
_, err = client.CostAlerts.DeleteAlert(ctx, alertID)Alert events
Returns one entry per firing and per recovery, newest first, with the figure observed, the threshold it crossed and whether anyone was notified. limit is 1 to 200 and defaults to 50.
events, err := client.CostAlerts.ListAlertEvents(ctx, alertID,
&levelfour.ListAlertEventsAPIV1CostAlertsAlertIDEventsGetRequest{Limit: levelfour.Int(20)},
)Suggestions for an account
Returns rules in the same grammar params takes, computed from the account's own billing history, with the baseline behind them. An account with too little history returns no suggestion rather than a number nobody can check.
suggestions, err := client.CostAlerts.SuggestionsForAccount(ctx, "123456789012")Related
- Cost alerts: the types of rule, where alerts arrive, and how often they are checked
l4 alerts: the same operations from the terminal- Cost Alerts API reference: every field of every endpoint
Commitments
Read your Reserved Instances and Savings Plans over the API: what you hold, how well you use it, how much of the bill it covers, your effective savings rate, and what renewing each one costs.
Accounts
Read the cloud accounts connected to LevelFour, what each one can do, the modules your organization has, and the work tools it is connected to, and disconnect a work tool.