Storage
banshee/storage-collection/storage/truenas/https/api-v2.0/
replication
The state of each replication task of a TrueNAS, to see a replication in error, by its REST API v2.0.
by banshee1 installation1 version
Published on October 27, 2026. First version.
// The replication tasks of a TrueNAS, by its REST API v2.0 (GET /api/v2.0/replication), behind an API key:
// the state of the last run of each, so that a replication in error is seen. The REST API v2.0 answers on
// TrueNAS CORE 12 and 13 and on TrueNAS SCALE up to 25.10.
need('protocol:http');
$address = need('host:address');
$token = need('protocol:http:token');
per('task', 'Replication tasks');
output('state', 'text', array('label' => 'State', 'per' => 'task'));
watch.state('failed', 'Replication in error', 'state', array('critical' => array('error')));
watch.state('held', 'Replication on hold', 'state', array('warning' => array('hold')));
watch.missing('missing', 'Replication task missing', 'state', array('enabled' => false));
// The key goes in a header: the answer is not secret, its body having carried none.
$answer = http.get('https://' . $address . '/api/v2.0/replication', headers=array('Authorization' => 'Bearer ' . $token));
if ($answer['status'] == 401 || $answer['status'] == 403) {
fail('misconfigured', 'The TrueNAS API refuses the key, code ' . $answer['status']);
}
if ($answer['status'] != 200) {
fail('unreachable', 'The TrueNAS API answers code ' . $answer['status'],
'A TrueNAS 26 or later has no REST API: it answers 404.');
}
// A list of tasks: {"name": "tank/data - backup/data", "enabled": true, "state": {"state": "FINISHED",
// "datetime": ..., "error": ...}}. The states zettarepl gives a task: WAITING, RUNNING, FINISHED, ERROR, HOLD
// (its definition stops it); a task with no state yet (never run) reads "pending". A task disabled in TrueNAS
// reads "disabled".
$tasks = json.read($answer['body']);
foreach ($tasks as $task) {
$state = 'disabled';
if ($task['enabled']) {
$state = text.lower(list.get($task['state'], 'state', 'pending'));
}
value('state', $state, $task['name']);
}