background 
Kris' Tech Blog ( and stuff ) Home About Kris Contact Kris

Categories


All by Date

Linux

Security

Networks

Religion

General





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.
  1. 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
    
  2. 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 " <html> <br><a href='$XYMONWEBHOST$XYMONSERVERCGIURL/svcstatus.sh?HOST=$BBHOSTNAME&SERVICE=$BBSVCNAME'><img src='$XYMONWEBHOST$XYMONSKIN/logo.png' alt='View live status on server'></a> <br><br> <table style='border-radius:8px; border:1px solid gray; padding:2px;'> <tr><td>Host: </td><td><b>$BBHOSTNAME</b></td></tr> <tr><td>Test:</td><td><b>$BBSVCNAME</b></td></tr> <tr><td>Status:</td><td><b>Recovered</b></td></tr> <br> </table> </html> " | mailx -a 'Content-Type: text/html' -s "$BBHOSTSVC (Recovered)" $RCPT elif [ $NOTICE -gt 0 ]; then echo " <html> <br><a href='$XYMONWEBHOST$XYMONSERVERCGIURL/svcstatus.sh?HOST=$BBHOSTNAME&SERVICE=$BBSVCNAME'><img src='$XYMONWEBHOST$XYMONSKIN/logo.png' alt='View live status on server'></a> <br><br> <table style='border-radius:8px; border:1px solid gray; padding:2px;'> <tr><td>Host: </td><td><b>$BBHOSTNAME</b></td></tr> <tr><td>Test:</td><td><b>$BBSVCNAME</b></td></tr> <tr><td>Status:</td><td><b>Notice</b></td></tr> <br> </table> <br><u><b>Alert Content:</b></u> <pre>$BBALPHAMSG</pre> </html> " | mailx -a 'Content-Type: text/html' -s "$BBHOSTSVC (Notice)" $RCPT else echo " <html> <br><a href='$XYMONWEBHOST$XYMONSERVERCGIURL/svcstatus.sh?HOST=$BBHOSTNAME&SERVICE=$BBSVCNAME'><img src='$XYMONWEBHOST$XYMONSKIN/logo.png' alt='View live status on server'></a> <br><br> <table style='border-radius:8px; border:1px solid gray; padding:2px;'> <tr><td>Host: </td><td><b>$BBHOSTNAME</b></td></tr> <tr><td>Test:</td><td><b>$BBSVCNAME</b></td></tr> <tr><td>Status:</td><td><b>$BBCOLORLEVEL</b></td></tr> </table> <br><u><b>Alert Content:</b></u> <pre>$BBALPHAMSG</pre> </html> " | mailx -a 'Content-Type: text/html' -s "$BBHOSTSVC ($BBCOLORLEVEL)" $RCPT fi
  3. Edit the permissions on the email_script.sh file so it will work.
    chmod 755 email_script.sh
    chown xymon:xymon email_script.sh
    
  4. 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 xymon@yourdomain.com 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 xymon@yourdomain.com COLOR=red,yellow,purple DURATION>15m RECOVERED NOTICE REPEAT=2h
    
  5. That's it. Trigger some alerts easily by temporarily disabling one of your host's tests, or reboot some client device you're testing.






© Copyright 2024 WarriorSon Productions. All rights reserved.