MRTG Email Notifications And Alerts

By , 30 August 2011

MRTG Email Notifications And Alerts
MRTG Email Notifications And Alerts

While searching the MRTG docs for some settings, I stumbled across the following option:

ThreshMinI (PER TARGET)

This is the minimum acceptable value for the Input (first) parameter. If the parameter falls below this value, the program specified in ThreshProgI will be run and a mail will be sent to the ThreshMailAddress if specified. If the value ends in '%' then the threshold is defined relative to MaxBytes.

Although my version of MRTG didn't support ThreshMailAddress, it was pretty simple to rig up a shell script to send email notifications when threshold values are reached.

Here is the MRTG config I added to notify me if the cpu usage exceeds 75% or the disks reach 95% capacity.

MRTG Email Notifications And Alerts
ThreshDir: /var/run/mrtg
ThreshProgI[_]: /usr/local/sbin/notify
ThreshProgOKI[_]: /usr/local/sbin/notify
ThreshMaxI[cpu]: 75
ThreshMaxI[disk1]: 95
ThreshMaxI[disk2]: 95

Make sure you create the /var/run/mrtg directory.

Here is the /usr/local/sbin/notify shell script to send the mail.

#!/bin/sh
#
# This script is executed by MRTG when threshold values are reached. It
# just sends an email notification to the logging address.
#

echo | mail -s "$1 is at $3" logging@example.com

About I Like Spam

MRTG Email Notifications And Alerts

Leave a Comment

Please visit https://ilikespam.com/mrtg-email-notifications-and-alerts to add your comments.

Comment posted by: ABC, last year

I followed your suggestions to monitor a room temperature.
For the email alert I defined different message when we go outside working range from the one when we fall back into operating range:

ThreshProgI[_]: /usr/local/sbin/notify_above
ThreshProgOKI[_]: /usr/local/sbin/notify_inrange

ThreshMaxI[rack14_temp]: 30
ThreshMinI[rack14_temp]: 0

root@www:/etc/mrtg# cd /usr/local/sbin/
root@www:/usr/local/sbin# cat notify_above
#!/bin/sh
echo | mail -s "$1 has crossed operative range (now at $3)" xxxx@xxx.com

root@www:/usr/local/sbin# cat notify_inrange
#!/bin/sh
echo | mail -s "$1 is back in operative range (now at $3)" xxxx@xxx.com
root@www:/usr/local/sbin#

To reach the smtp server from mail application I just add the correct MX entry in the local DNS.

 

Comment posted by: Farhan, last year

Here I am attach my configuration, log and scripting. Please check if I done anything incorrectly. ox/webcore/attachments/27134/mrtg.rar

Oh one more thing, how did you make mrtg recognize the email? is it sent through the internet?

In my case, I just do it in LAN consist of Email server and Network monitoring system which is mrtg. Maybe there is some addition configuration need to be done?

Comment posted by: Farhan, last year

Here I am attach my configuration, log and scripting. Please check if I done anything incorrectly. ox/webcore/attachments/27134/mrtg.rar

Oh one more thing, how did you make mrtg recognize the email? is it sent through the internet?

In my case, I just do it in LAN consist of Email server and Network monitoring system which is mrtg. Maybe there is some addition configuration need to be done?

Comment posted by: Farhan, last year

Here I am attach my configuration, log and scripting. Please check if I done anything incorrectly. ox/webcore/attachments/27134/mrtg.rar

Oh one more thing, how did you make mrtg recognize the email? is it sent through the internet?

In my case, I just do it in LAN consist of Email server and Network monitoring system which is mrtg. Maybe there is some addition configuration need to be done?

Comment posted by: , last year

You could check if the script is running by having it write a log message to file. Did you make the script executable? Otherwise I'd double-check the syntax of your config file. It's easy to make mistakes there unfortunately.

Comment posted by: Farhan, last year

Hello Roger,

I want to ask about send email using mrtg. I already make the configuration as you do but I cant get any email if its reach threshold that I have set. My email server is work perfectly and it is in vlan email and for my monitoring is in vlan monitor. Is there any possible mistake that I might done in the process?