This scipts will send scheduled report of open alerts in LibreNMS via SSMTP
cd /opt
git clone https://github.com/jozefrebjak/librenms-mail-report.git
cd librenms-mail-report
mkdir api-report && mkdir full-mail && mkdir log
`
apt install -y ssmtp
echo "">/etc/ssmtp/ssmtp.conf
nano /etc/ssmtp/ssmtp.conf
`
root=<RCPT_EMAIL>
mailhub=smtp.office365.com:587
AuthUser=<OFFICE365_EMAIL>
AuthPass=<OFFICE365_PASSWORD>
UseTLS=YES
UseSTARTTLS=YES
nano /etc/ssmtp/revaliases:
`
root:<OFFICE365_EMAIL>:smtp.office365.com:587
This script talks to the LibreNMS API to receive a list of down devices and alerts. The LibreNMS dashboard provides widgets for alerts and host statusses, but there is no easy way to access that output via the API. Using Python I was able to get certain information and output it as HTML or text using PrettyTable. It can be included in other systems or be used in a chain of monitoring customizations.
On Ubuntu 18.04 with default pvthon3 you need to install prettytable
:
sudo apt install python3-prettytable
On Ubuntu prior version if you want to install python3:
sudo apt install python3-prettytable python3
On Ubuntu prior version if you want to install python2:
sudo apt install python-prettytable python-requests python
Add your API token in the script and change the API URL:
auth_token = "API_TOKEN"
api_url = "https://LIBRENMS_URL/api/v0/"
Run the script:
python ./open_alerts.py
nano send-mail-report.sh
MAIL_ADDRESS="MAIl_ADDRESS"
./send-mail-report.sh