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 Roger Keays

MRTG Email Notifications And Alerts

Roger Keays is an artist, an engineer, and a student of life. He has no fixed address and has left footprints on 40-something different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, the proper use of semicolons, and finding good food.

Comment posted by: Pedro Alarcón, 5 years ago

Hola,

quisiera consultar como pueda hacer que mi MRTG, envie correos de alerta cuando se supera una cantidad de MB en el trafico de una interfas?

saludos

Pedro

Comment posted by: ABC, 8 years ago

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, 9 years ago

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, 9 years ago

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, 9 years ago

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: , 9 years ago

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, 9 years ago

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?