id: traccar-fleet-tracker-silence-sentinel
namespace: company.team
description: |
On a schedule, read-only fetch every vehicle and its latest position from a
Traccar GPS tracking server (nothing is created, changed or deleted) and
classify the fleet as HEALTHY, WARNING, CRITICAL or UNREACHABLE. Log quiet
runs and page Slack when trackers stop reporting or lose their GPS fix, so
dispatch is not working from positions that are hours old.
inputs:
- id: traccar_url
type: STRING
defaults: "https://traccar.example.com"
displayName: "Traccar URL"
description: "Base URL of the Traccar server, without a trailing slash."
- id: silent_minutes
type: INT
defaults: 30
displayName: "Silent After (minutes)"
description: "A vehicle whose tracker has not reached the server for this long,
or has never reported, counts as silent."
- id: fix_minutes
type: INT
defaults: 30
displayName: "Stale GPS Fix After (minutes)"
description: "A tracker that still reports but whose latest GPS fix is this old,
or marked invalid, counts as having no fix."
- id: critical_minutes
type: INT
defaults: 240
displayName: "Critical Silence (minutes)"
description: "If any vehicle has been silent this long, the check is classified
CRITICAL."
- id: critical_silent_count
type: INT
defaults: 3
displayName: "Critical Silent Vehicles"
description: "At or above this many silent vehicles at once, the check is
classified CRITICAL, which usually points to a server, network or SIM
provider problem rather than one vehicle."
triggers:
- id: fleet_check
type: io.kestra.plugin.core.trigger.Schedule
description: Check the fleet every 15 minutes during operating hours (06:00 to
22:00). Shipped disabled; enable it once traccar_url and the TRACCAR_TOKEN
secret point at a real server and a manual run has been verified.
cron: "*/15 6-21 * * *"
timezone: Asia/Kolkata
disabled: true
inputs:
traccar_url: "https://traccar.example.com"
tasks:
- id: fetch_devices
type: io.kestra.plugin.core.http.Request
description: Read every device the token's user can see, with its status, the
time the server last heard from it (lastUpdate) and whether it is
disabled. This is a GET; nothing in Traccar is changed.
uri: "{{ inputs.traccar_url }}/api/devices"
method: GET
headers:
Accept: application/json
Authorization: "Bearer {{ secret('TRACCAR_TOKEN') }}"
options:
allowFailed: true
timeout:
connectTimeout: PT10S
readIdleTimeout: PT30S
retry:
type: constant
interval: PT15S
maxAttempts: 3
allowFailure: true
- id: fetch_positions
type: io.kestra.plugin.core.http.Request
description: Read the latest position of every device (Traccar returns one per
device when no filter is given), with its GPS fix time and validity.
Skipped when the device list could not be read.
runIf: "{{ outputs.fetch_devices.code is defined and outputs.fetch_devices.code
== 200 and (outputs.fetch_devices.body | trim | startsWith('[')) }}"
uri: "{{ inputs.traccar_url }}/api/positions"
method: GET
headers:
Accept: application/json
Authorization: "Bearer {{ secret('TRACCAR_TOKEN') }}"
options:
allowFailed: true
timeout:
connectTimeout: PT10S
readIdleTimeout: PT30S
retry:
type: constant
interval: PT15S
maxAttempts: 3
allowFailure: true
- id: classify_fleet
type: io.kestra.plugin.core.debug.Return
description: Join each enabled device to its latest position and classify the
fleet in one jq query. A device is silent when the server has not heard
from it for silent_minutes (or ever), and has no fix when it still reports
but its GPS fix is stale or invalid. A missing response, a non-200 code, a
body that is not a JSON array, or no visible devices become UNREACHABLE
instead of looking healthy.
format: >-
{{ (outputs.fetch_devices.code is not defined or
outputs.fetch_devices.code != 200 or not (outputs.fetch_devices.body |
trim | startsWith('[')) or outputs.fetch_positions is not defined or
outputs.fetch_positions.code is not defined or
outputs.fetch_positions.code != 200 or not (outputs.fetch_positions.body |
trim | startsWith('['))) ?
'{"status":"UNREACHABLE","vehicles":0,"silent":0,"no_fix":0,"longest_silent":"none","silent_vehicles":"none","no_fix_vehicles":"none"}'
: ({'d': fromJson(outputs.fetch_devices.body), 'p':
fromJson(outputs.fetch_positions.body)} | jq(' ' ~ (now() | timestamp) ~ '
as $now | ' ~ (inputs.silent_minutes * 60) ~ ' as $silent_s | ' ~
(inputs.fix_minutes * 60) ~ ' as $fix_s | ([.p[] | {key: (.deviceId |
tostring), value: .}] | from_entries) as $pos | [.d[] | select(.disabled
!= true) | $pos[(.id | tostring)] as $p | (if .lastUpdate == null then
null else ($now - (.lastUpdate[0:19] + "Z" | fromdateiso8601)) end) as
$quiet | (if $p == null or $p.fixTime == null then null else ($now -
($p.fixTime[0:19] + "Z" | fromdateiso8601)) end) as $fixage | {name:
.name, quiet: $quiet, fixage: $fixage, valid: ($p.valid // false)}] as $v
| [$v[] | select(.quiet == null or .quiet >= $silent_s)] as $silent |
[$v[] | select(.quiet != null and .quiet < $silent_s and (.fixage == null
or .fixage >= $fix_s or .valid == false))] as $nofix | ([$silent[] |
select(.quiet != null) | .quiet] | max // 0) as $longest | {vehicles: ($v
| length), silent: ($silent | length), no_fix: ($nofix | length),
longest_silent_minutes: (($longest - ($longest % 60)) / 60),
longest_silent: (if ($silent | length) == 0 then "none" else ([$silent[] |
select(.quiet != null)] | max_by(.quiet) | if . == null then "never
reported" else .name + " (" + (((.quiet - (.quiet % 60)) / 60) | tostring)
+ " min)" end) end), silent_vehicles: (if ($silent | length) == 0 then
"none" else ([$silent[] | .name + (if .quiet == null then " (never
reported)" else "" end)] | .[0:10] | join(", ")) end), no_fix_vehicles:
(if ($nofix | length) == 0 then "none" else ([$nofix[] | .name] | .[0:10]
| join(", ")) end), status: (if ($v | length) == 0 then "UNREACHABLE" elif
($silent | length) >= ' ~ inputs.critical_silent_count ~ ' or $longest >=
' ~ (inputs.critical_minutes * 60) ~ ' then "CRITICAL" elif ($silent |
length) > 0 or ($nofix | length) > 0 then "WARNING" else "HEALTHY" end)}
') | first | toJson) }}
- id: route_by_fleet_status
type: io.kestra.plugin.core.flow.Switch
description: Route to a quiet log when every tracker is reporting with a fresh
fix, an informational Slack message when a few vehicles are silent or have
no fix, or a Slack page when many are silent, one has been silent for
hours, or Traccar could not be read.
value: "{{ fromJson(outputs.classify_fleet.value).status }}"
cases:
"HEALTHY":
- id: log_healthy
type: io.kestra.plugin.core.log.Log
description: Log a quiet confirmation when every enabled vehicle is reporting
with a fresh GPS fix.
message: "Traccar fleet healthy: all {{
fromJson(outputs.classify_fleet.value).vehicles }} enabled
vehicle(s) reported in the last {{ inputs.silent_minutes }}
minute(s) with a fresh GPS fix."
"WARNING":
- id: alert_warning_fleet
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post an informational Slack message naming the silent vehicles and
the vehicles without a GPS fix.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Traccar fleet WARNING ({{ fromJson(outputs.classify_fleet.value).vehicles }} vehicle(s) checked).{% if fromJson(outputs.classify_fleet.value).silent > 0 %} Silent for {{ inputs.silent_minutes }}+ minute(s): {{ fromJson(outputs.classify_fleet.value).silent_vehicles }}.{% endif %}{% if fromJson(outputs.classify_fleet.value).no_fix > 0 %} Reporting without a fresh GPS fix: {{ fromJson(outputs.classify_fleet.value).no_fix_vehicles }}.{% endif %} Execution {{ execution.id }}."
}
"CRITICAL":
- id: alert_critical_fleet
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Page Slack when many vehicles are silent at once or one has been
silent past critical_minutes; dispatch may be working from positions
that are hours old.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Traccar fleet CRITICAL: {{ fromJson(outputs.classify_fleet.value).silent }} of {{ fromJson(outputs.classify_fleet.value).vehicles }} vehicle(s) silent: {{ fromJson(outputs.classify_fleet.value).silent_vehicles }}. Longest silence: {{ fromJson(outputs.classify_fleet.value).longest_silent }}. Check the vehicles, SIM data and the server's tracker ports. Execution {{ execution.id }}."
}
"UNREACHABLE":
- id: alert_unreachable_traccar
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Page Slack when Traccar could not be read, rejected the token, or
showed no devices to the monitoring account.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Traccar fleet UNREACHABLE: {{ inputs.traccar_url }} did not return the device and position lists (server down, wrong URL, expired or revoked token, disabled account, or no devices shared with the monitoring account). Fleet visibility is unknown. Execution {{ execution.id }}."
}
defaults:
- id: log_unclassified
type: io.kestra.plugin.core.log.Log
description: Log any classification outside the four known values, so a change
in the jq query never fails silently.
message: "Traccar fleet tracker silence sentinel completed with an unexpected
classification: {{ outputs.classify_fleet.value }}."
- id: log_audit_result
type: io.kestra.plugin.core.log.Log
description: Record one audit line for every run, whichever branch fired, with
both HTTP codes and the classification, so the check's own history stays
queryable even if Slack delivery fails.
message: "Traccar fleet audit: server={{ inputs.traccar_url }} devices_http={{
outputs.fetch_devices.code ?? 'n/a' }} positions_http={{
outputs.fetch_positions.code ?? 'n/a' }} result={{
outputs.classify_fleet.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 outright, so a
broken check is never mistaken for a fleet where every tracker is
reporting.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"text": "Traccar fleet tracker silence sentinel flow {{ flow.id }} FAILED (execution {{ execution.id }}). Fleet visibility at {{ inputs.traccar_url }} is unknown; check the task logs and the Traccar server manually."
}
outputs:
- id: status
type: STRING
value: "{{ outputs.classify_fleet is defined ?
fromJson(outputs.classify_fleet.value).status : 'UNREACHABLE' }}"
- id: fleet
type: JSON
value: "{{ outputs.classify_fleet is defined ? outputs.classify_fleet.value :
'{\"status\":\"UNREACHABLE\"}' }}"