Storage
banshee/storage-collection/storage/truenas/https/api-v2.0/
services
Whether each service of a TrueNAS set to start at boot runs, by its REST API v2.0.
by banshee1 installation1 version
Published on October 27, 2026. First version.
// The services of a TrueNAS (SMB, NFS, iSCSI, SSH, UPS, SNMP...), by its REST API v2.0 (GET /api/v2.0/service),
// behind an API key: whether each one set to start at boot runs. The REST API v2.0 answers on TrueNAS CORE 12
// and 13 and on TrueNAS SCALE up to 25.10.
// A service is "running", "stopped" (set to start at boot, and not running) or "disabled" (not set to start,
// and not running): only a stopped service raises.
need('protocol:http');
$address = need('host:address');
$token = need('protocol:http:token');
per('service', 'Services');
output('state', 'text', array('label' => 'State', 'per' => 'service'));
watch.state('stopped', 'Service stopped', 'state', array('critical' => array('stopped')));
watch.expect('not-running', 'Service not running', 'state', array('warning' => array('running'), '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/service', 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 services: {"service": "cifs", "enable": true, "state": "RUNNING", "pids": [...]}.
$services = json.read($answer['body']);
$read = 0;
foreach ($services as $service) {
$read = $read + 1;
$state = 'disabled';
if ($service['state'] == 'RUNNING') {
$state = 'running';
} elseif ($service['enable']) {
$state = 'stopped';
}
value('state', $state, $service['service']);
}
if ($read == 0) {
fail('misconfigured', 'The TrueNAS API lists no service');
}