FreeNAS (and TrueNAS) keep track of system alerts and can be configured to send those out via email and a few other services such as Slack and InfluxDB. The selection of these services is pretty limited. Especially limiting is the fact that it does not provide a way to call a custom script or a web service endpoint. But we can capture the alerts from the system and get them out in a roundabout way.
Use FreeNAS middleware client to push alerts from Freenas to Alerta
TrueNAS/FreeNAS does not have a plugin for Alerta, nor does it have a facility to use shell scripts or http/json for alerts.
I wrote a simple script that takes the alerts from the FreeNAS database using the included middleware client midclt and pushes them to the Alerta endpoint using curl, making some assumptions along the way.
Currently the script just invokes FreeNAS provided CLI tool midclt to get the info about ALL alerts without keeping track of their status and pushes them into Alerta. Alerta can take care of duplicates so this is not a big issue.
The freenas-alerta script uses midclt, jq and wget which are all included on a TrueNAS install.
Without going into details, what you have to do is to put freenas-alerta.sh and .secrets in
Add FreeNAS/TrueNAS Cron task as:
cd /<PATH TO SOME LOCATION>/bin/cron && /bin/bash ./freenas-alerta.sh
The script is available on GitHub at the url below. You can modify it to do something else rather than pushing the alerts to Alerta.