Storage
banshee/storage-collection/storage/truenas/https/api-v2.0/
alerts
The alerts a TrueNAS raises itself and that are still active, by its REST API v2.0.
by banshee1 installation1 version
Published on October 27, 2026. First version.
// The alerts a TrueNAS raises itself (a SMART failure, a pool degraded, a certificate expiring, an update
// available...), by its REST API v2.0 (GET /api/v2.0/alert/list), behind an API key: the most severe level of
// each class of alert still active. The REST API v2.0 answers on TrueNAS CORE 12 and 13 and on TrueNAS SCALE
// up to 25.10.
// An alert an administrator dismissed in TrueNAS is left out: he has seen it.
need('protocol:http');
$address = need('host:address');
$token = need('protocol:http:token');
per('alert', 'Alert classes');
output('level', 'text', array('label' => 'Most severe level', 'per' => 'alert'));
output('count', 'number', array('label' => 'Active alerts', 'per' => 'alert'));
watch.state('raised', 'TrueNAS alert', 'level', array(
'warning' => array('warning'),
'critical' => array('error', 'critical', 'alert', 'emergency'),
));
// The key goes in a header: the answer is not secret, its body having carried none.
$answer = http.get('https://' . $address . '/api/v2.0/alert/list', 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.');
}
// The levels of TrueNAS, from the least to the most severe.
$ranks = array('INFO' => 1, 'NOTICE' => 2, 'WARNING' => 3, 'ERROR' => 4, 'CRITICAL' => 5, 'ALERT' => 6, 'EMERGENCY' => 7);
// A list of alerts: {"klass": "SMARTFail", "level": "CRITICAL", "dismissed": false, ...}. Several alerts of
// one class (two disks failing) make one instance, with the most severe level and their count.
$alerts = json.read($answer['body']);
$level_of = array();
$count_of = array();
foreach ($alerts as $alert) {
if ($alert['dismissed']) {
continue;
}
$class = $alert['klass'];
$level = $alert['level'];
if (!list.has($level_of, $class) || list.get($ranks, $level, 0) > list.get($ranks, $level_of[$class], 0)) {
$level_of[$class] = $level;
}
$count_of[$class] = list.get($count_of, $class, 0) + 1;
}
foreach ($level_of as $class => $level) {
value('level', text.lower($level), $class);
value('count', $count_of[$class], $class);
}