|
Categories
|
|
|
|
Kris Springer's Tech Blog - Xymon Custom Email Alerts
Xymon Custom Email Alerts |
7-9-20 Kris Springer |
I have been using Xymon Monitoring for many years. The default email alerts have always felt a bit clunky and some are too verbose for mobile devices. Xymon has a built-in 'sms' style of messages, but that stripped away too much information. I wanted something clean and concise, but I still needed the content visible in the email body. So after some web searching and Xymon Mailing List assistance I landed on a simple solution. I made my own alert script that allows me to theme it however I wish.
Here's the steps to accomplish the goal.
- Use the following commands to create the email_script.sh file.
NOTE: my Xymon server is located in /home/xymon/server/ Make adjustments to your path if yours is located somewhere else.
sudo bash
cd /home/xymon/server/bin
nano email_script.sh
- Copy this content into the file and save it. Most of it is basic html so you can change it however you want. I added my server's logo since I have multiple company's systems, and made it clickable to take me directly to the hosts status page.
#!/bin/sh
NOTICE=`echo "$BBALPHAMSG" | grep -c INFO`
if [ $RECOVERED -eq 1 ];
then
echo "
Host: | $BBHOSTNAME |
Test: | $BBSVCNAME |
Status: | Recovered |
" | mailx -a 'Content-Type: text/html' -s "$BBHOSTSVC (Recovered)" $RCPT
elif [ $NOTICE -gt 0 ];
then
echo "
Host: | $BBHOSTNAME |
Test: | $BBSVCNAME |
Status: | Notice |
Alert Content:
$BBALPHAMSG
" | mailx -a 'Content-Type: text/html' -s "$BBHOSTSVC (Notice)" $RCPT
else
echo "
Host: | $BBHOSTNAME |
Test: | $BBSVCNAME |
Status: | $BBCOLORLEVEL |
Alert Content:
$BBALPHAMSG
" | mailx -a 'Content-Type: text/html' -s "$BBHOSTSVC ($BBCOLORLEVEL)" $RCPT
fi
- Edit the permissions on the email_script.sh file so it will work.
chmod 755 email_script.sh
chown xymon:xymon email_script.sh
- Edit your alerts.cfg file and make the following change. Remove MAIL and add SCRIPT and the path. All the other settings stay the same.
Here's what your existing alert line of code probably looks like. It sends alerts using the default MAIL settings.
MAIL [email protected] COLOR=red,yellow,purple DURATION>15m RECOVERED NOTICE REPEAT=2h
Here's what it looks like after we edit it. Now it will send alerts using our script.
SCRIPT /home/xymon/server/bin/email_script.sh [email protected] COLOR=red,yellow,purple DURATION>15m RECOVERED NOTICE REPEAT=2h
- That's it. Trigger some alerts easily by temporarily disabling one of your host's tests, or reboot some client device you're testing.
|
|
|
|
|