id: exotel-call-failure-sentinel
namespace: company.team
description: |
Every hour, read recent calls from the Exotel Call Details API (read-only:
no call is placed or ended) and classify voice calling as HEALTHY,
WARNING, CRITICAL, LOW_VOLUME or UNREACHABLE. Log quiet runs and alert
Slack when outbound calls start failing to connect, with the busy and
no-answer counts and the connect rate alongside.
inputs:
- id: api_host
type: STRING
defaults: "api.exotel.com"
displayName: "Exotel API Host"
description: "api.exotel.com for the Singapore cluster, api.in.exotel.com for
the Mumbai cluster, as shown in the API settings of your Exotel
dashboard."
- id: direction
type: STRING
defaults: "outbound-api"
displayName: "Call Direction"
description: "Which calls to judge: outbound-api (API and campaign calls),
outbound-dial (dashboard calls) or inbound."
- id: lookback_hours
type: INT
defaults: 2
displayName: "Lookback Window (hours)"
description: "Read calls created in the last this many hours (sent to Exotel as
a DateCreated filter, in IST)."
- id: warning_failure_rate
type: FLOAT
defaults: 5.0
displayName: "Warning Failure Rate (%)"
description: "At or above this share of failed calls among finished ones, the
check is WARNING."
- id: critical_failure_rate
type: FLOAT
defaults: 15.0
displayName: "Critical Failure Rate (%)"
description: "At or above this share of failed calls among finished ones, the
check is CRITICAL."
- id: min_calls
type: INT
defaults: 30
displayName: "Minimum Calls"
description: "Below this many finished calls, the rate is too noisy to judge and
the run is LOW_VOLUME."
triggers:
- id: hourly_check
type: io.kestra.plugin.core.trigger.Schedule
description: Check call failures every hour, India time. Shipped disabled;
enable it once the Exotel secrets are set and a manual run has been
verified.
cron: "5 * * * *"
timezone: Asia/Kolkata
disabled: true
tasks:
- id: list_calls
type: io.kestra.plugin.core.http.Request
description: Read up to 100 calls in the chosen direction created since the
start of the lookback window from the Exotel bulk Call Details API. This
is a GET; no call is placed, ended or changed.
uri: "https://{{ inputs.api_host }}/v1/Accounts/{{ secret('EXOTEL_ACCOUNT_SID')
}}/Calls.json?PageSize=100&Direction={{ inputs.direction
}}&DateCreated=gte:{{ now() | dateAdd(-inputs.lookback_hours, 'HOURS') |
date(\"yyyy-MM-dd'+'HH:mm:ss\", timeZone='Asia/Kolkata') }}"
method: GET
options:
auth:
type: BASIC
username: "{{ secret('EXOTEL_API_KEY') }}"
password: "{{ secret('EXOTEL_API_TOKEN') }}"
allowFailed: true
timeout:
connectTimeout: PT10S
readIdleTimeout: PT60S
retry:
type: constant
interval: PT10S
maxAttempts: 3
allowFailure: true
- id: summarize_calls
type: io.kestra.plugin.core.debug.Return
description: Keep calls that have finished (completed, failed, busy, no-answer),
compute the failed share and the connect rate, count busy and no-answer
calls and ones still ringing or in progress, and classify in one jq query.
A missing or non-200 response becomes UNREACHABLE.
format: >-
{{ (outputs.list_calls.code is not defined or outputs.list_calls.code !=
200) ?
'{"status":"UNREACHABLE","finished":0,"completed":0,"failed":0,"busy":0,"no_answer":0,"rate":0,"connect_rate":0,"in_flight":0,"total_in_window":0}'
: (fromJson(outputs.list_calls.body) | jq(' (.Calls // []) as $c | [$c[] |
select(.Status == "completed" or .Status == "failed" or .Status == "busy"
or .Status == "no-answer")] as $f | ($f | length) as $n | ([$f[] |
select(.Status == "failed")] | length) as $bad | ([$f[] | select(.Status
== "completed")] | length) as $ok | (if $n == 0 then 0 else (($bad * 1000
/ $n) | floor) / 10 end) as $r | {finished: $n, completed: $ok, failed:
$bad, busy: ([$f[] | select(.Status == "busy")] | length), no_answer:
([$f[] | select(.Status == "no-answer")] | length), rate: $r,
connect_rate: (if $n == 0 then 0 else (($ok * 1000 / $n) | floor) / 10
end), in_flight: (($c | length) - $n), total_in_window: (.Metadata.Total
// ($c | length)), status: (if $n < ' ~ inputs.min_calls ~ ' then
"LOW_VOLUME" elif $r >= ' ~ inputs.critical_failure_rate ~ ' then
"CRITICAL" elif $r >= ' ~ inputs.warning_failure_rate ~ ' then "WARNING"
else "HEALTHY" end)} ') | first | toJson) }}
- id: route_by_failures
type: io.kestra.plugin.core.flow.Switch
description: Route to a quiet log when calling is healthy or volume is too low
to judge, a Slack message when failed calls cross the warning line, or a
Slack page when they cross the critical line or Exotel could not be read.
value: "{{ fromJson(outputs.summarize_calls.value).status }}"
cases:
"HEALTHY":
- id: log_healthy
type: io.kestra.plugin.core.log.Log
description: Log a quiet line when the check is healthy; no Slack message is sent.
message: "Exotel calls healthy: {{
fromJson(outputs.summarize_calls.value).failed }} of {{
fromJson(outputs.summarize_calls.value).finished }} finished {{
inputs.direction }} calls failed ({{
fromJson(outputs.summarize_calls.value).rate }}%); connect rate {{
fromJson(outputs.summarize_calls.value).connect_rate }}%."
"LOW_VOLUME":
- id: log_low_volume
type: io.kestra.plugin.core.log.Log
description: Log a quiet line when there is too little activity in the window to
judge; no Slack message is sent.
message: "Exotel calls: only {{ fromJson(outputs.summarize_calls.value).finished
}} finished {{ inputs.direction }} call(s) in the last {{
inputs.lookback_hours }} hour(s), below the minimum of {{
inputs.min_calls }}; rate not judged this run."
"WARNING":
- id: alert_warning_calls
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post a Slack message when the failed-call rate is at or above the
warning line.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Exotel calls WARNING: {{ fromJson(outputs.summarize_calls.value).failed }} of {{ fromJson(outputs.summarize_calls.value).finished }} finished {{ inputs.direction }} calls failed ({{ fromJson(outputs.summarize_calls.value).rate }}%) in the last {{ inputs.lookback_hours }} hour(s). Busy {{ fromJson(outputs.summarize_calls.value).busy }}, no answer {{ fromJson(outputs.summarize_calls.value).no_answer }}, connect rate {{ fromJson(outputs.summarize_calls.value).connect_rate }}%. Execution {{ execution.id }}."
}
"CRITICAL":
- id: alert_critical_calls
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Page Slack when the failed-call rate is at or above the critical
line, which usually means an ExoPhone, the account balance or a
telecom route is broken.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Exotel calls CRITICAL: {{ fromJson(outputs.summarize_calls.value).failed }} of {{ fromJson(outputs.summarize_calls.value).finished }} finished {{ inputs.direction }} calls failed ({{ fromJson(outputs.summarize_calls.value).rate }}%) in the last {{ inputs.lookback_hours }} hour(s). Connect rate {{ fromJson(outputs.summarize_calls.value).connect_rate }}%. Customers are not being reached; check the account balance, the ExoPhone and the call flow now. Execution {{ execution.id }}."
}
"UNREACHABLE":
- id: alert_unreachable_api
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Page Slack when the Call Details API could not be read, indicating
an outage, the wrong cluster host or invalid credentials.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Exotel call sentinel UNREACHABLE: the Call Details API did not return a usable response (HTTP {{ outputs.list_calls.code ?? 'no response' }}). Check the API key, token, account SID and api_host. Execution {{ execution.id }}."
}
defaults:
- id: log_unclassified
type: io.kestra.plugin.core.log.Log
description: Fallback for any classification the cases above do not cover, so an
unexpected value is visible in the logs.
message: "Exotel call sentinel completed with an unexpected classification: {{
outputs.summarize_calls.value }}."
- id: log_audit_result
type: io.kestra.plugin.core.log.Log
description: Record one audit line for every run, whichever branch fired, so the
calling history stays queryable even if Slack delivery fails.
message: "Exotel call sentinel audit: direction={{ inputs.direction }}
lookback_hours={{ inputs.lookback_hours }} http={{ outputs.list_calls.code
?? 'n/a' }} summary={{ outputs.summarize_calls.value }} execution={{
execution.id }}."
errors:
- id: alert_flow_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Alert Slack when the sentinel flow itself fails, so a broken check
is never mistaken for healthy calling.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Exotel call sentinel flow {{ flow.id }} FAILED (execution {{ execution.id }}). Call health is now unknown; check the task logs and the Exotel call reports."
}
outputs:
- id: status
type: STRING
value: "{{ fromJson(outputs.summarize_calls.value).status }}"