GetBalance icon
Return icon
Switch icon
Log icon
SlackIncomingWebhook icon
Schedule icon

DigitalOcean Account Balance Depletion Sentinel

Read a DigitalOcean account balance on a schedule and alert Slack with the real remaining credit before services are suspended.

Categories
CloudInfrastructure

A DigitalOcean account running on promotional or prepaid credit shows no warning as that credit runs down, the droplets, databases, and load balancers it pays for keep running right up until the balance crosses zero, at which point the account owes money and risks suspension for non-payment with no notice beyond an email easy to miss. This blueprint reads the account's real balance on a schedule and alerts Slack with the exact remaining credit or amount owed, never an invented figure.

How it works

  1. probe_balance (io.kestra.plugin.digitalocean.billing.GetBalance) reads accountBalance (negative means credit remaining, zero or positive means money owed), monthToDateUsage, and monthToDateBalance, with allowFailure: true so a bad or expired API token does not stop the flow before it can be classified as PROBE_FAILED below.
  2. classify_balance_status (io.kestra.plugin.core.debug.Return) returns PROBE_FAILED when the probe did not return at all, CRITICAL when accountBalance is at or above zero, WARNING when the real remaining credit is below low_credit_warning_threshold_usd, HEALTHY otherwise.
  3. route_by_balance_status (io.kestra.plugin.core.flow.Switch) branches on that status: HEALTHY logs it, the other three alert Slack with the real dollar figures, never an invented number. A defaults branch logs anything unexpected.
  4. log_audit_summary always runs last. The errors block posts to Slack if the flow itself fails outside the gate logic above.

What you get

  • A real read of the account's own balance, not a guess from when the last invoice email arrived.
  • A Slack alert naming the real remaining credit or the real amount owed, never an invented number.
  • A warning before the balance crosses zero, not only after services are already at risk of suspension.

Who it's for

  • Platform and FinOps teams running infrastructure on DigitalOcean on prepaid or promotional credit who need to know before that credit runs out, not after.
  • Teams evaluating the DigitalOcean plugin who want a working example of billing.GetBalance and its signed-balance convention.

Why orchestrate this with Kestra

DigitalOcean's own notifications for a depleted balance arrive by email, easy to miss in a shared inbox, and carry no severity tiering of their own. Kestra adds the schedule, a warning tier before the balance actually crosses zero, and a Slack alert with the real figures as one declarative, auditable flow.

Prerequisites

  • A DigitalOcean account and a personal access token with read access to billing, generated under API in the DigitalOcean control panel. DigitalOcean's billing API has no local emulator, this gate runs against a real account; a free-tier account and token are sufficient to call this endpoint.
  • A Slack incoming webhook for alerts.

Secrets

  • DIGITALOCEAN_TOKEN: personal access token used by the probe task.

  • SLACK_WEBHOOK: Slack incoming webhook URL used by the alert tasks and the errors block.

    In Kestra OSS, set these as base64-encoded environment variables, for example SECRET_DIGITALOCEAN_TOKEN, SECRET_SLACK_WEBHOOK.

Quick start

  1. Generate a DigitalOcean API token and add the two secrets above.
  2. Run this flow manually with the defaults, it should report HEALTHY on an account with more than the threshold in remaining credit, or CRITICAL if the account already owes money.
  3. Lower low_credit_warning_threshold_usd above the account's current remaining credit, run again, it should report WARNING naming the real figure.
  4. Enable the every_morning trigger.

How to extend

  • Add ListBillingHistory to break the alert down by which resource type drove the month-to-date usage, not only the total.
  • Add a remediation branch that powers off a named, non-critical droplet via droplet.Action when CRITICAL, gated behind an explicit operator-supplied droplet ID, never an automatic bulk shutdown.
  • Track generatedAt across runs to alert if the figures themselves have gone stale, meaning the account's billing data is not refreshing as expected.

Pitfalls

  • accountBalance's sign convention is easy to get backwards, negative means credit remaining, zero or positive means money owed, this gate's classification depends on that being read correctly.
  • This gate only reads and alerts, it never pauses or deletes any resource automatically, choosing what to shut down to control cost needs a human decision, not an automated guess.
  • monthToDateUsage resets each billing period, a WARNING or CRITICAL reading near the start of a new period reflects the account's actual remaining credit, not a bug in this gate.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.