[mrtg] {partial solution} RE: Re: Threshold examples

Justin Shore listuser at vinnie.ksu.ksu.edu
Mon Feb 7 12:23:06 MET 2000

	I spent a few hours tonight and wrote a nice shell script to 
help regulate the Threshold error e-mail.  It works on my setup just 
fine (be warned though, $CONFIG_FILE doesn't work yet.  Use the path 
instead where applicable).  I've added variables at the top that 
users can easily edit and comments to describe each of them.  If 
people find it useful, I may add it to the MRTG contrib.
	While I was writing the text of the email to be sent I 
thought to myself that the script could be reusable for multiple 
Targets if MRTG would just return more variables.  It returns 
$THRESH_DESC which is a start but it should be able to return a lot 
more.  Even if the variable means nothing to MRTG is could still be 
defined and returned to the external program.  Possible variables 
would be the time MRTG encountered the Threshold breach, URL for the 
page to view the graph, the hostname that MRTG was running on, 
MaxBytes and AbsMax.  There are many more that could be used; it just 
depends on how much you want to customize your e-mail.  As it stands 
now, I have to duplicate that script 5 times for each of our dialin 
pools when I could have just made it once.  Anyways, that's a feature 
suggestion for the author.  Here's the script so far.  Again, 
$CONFIG_FILE doesn't work yet.  Use the path instead where 
applicable.  Let me know what you think of it.


# This was written by Justin Shore on 2/7/00.
# Sorry, I don't have a name for it yet. :-)
# What is does is e-mail a user-defined e-mail to a user defined address
# when a certain MRTG's Threshold features call it.  While this can be acheived
# via a simple command line, you can't define how often you want MRTG to e-mail
# you.  This script takes care of that for you.  You define via cron how often
# you want MRTG to run.  You define within this script how many iteration you
# want the script to ignore before sending out any subsequent messages.  Let's
# say for example that you run your MRTG config through every 3 minutes.  If
# you define the maximum number of iterations to be 20, this script will have
# to be called 20 times before it will send out another message.  20 iterations
# times 3 minutes equals an hour.  From that you can define how often you
# want MRTG to send you a message about your exceded Threshold.  You must
# configure your mrtg config file properly for Threshold checking.  Look at
# this page for help.
# http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/config.html#Threshold_Checking
# Your config must have similar lines for the target you want to Threshol
# monitor:
#ThreshDesc[your_target]: "A brief description"
#ThreshProgI[your_target]: scripts/your_target.script
# You must define ThreshDesc or remove it from the script below.  You will also
# have to adjust the spacing if you remove it.  You also *must* specify the
# following line:
#ThreshProgOKI[your_target]: scripts/your_target.script-remove
# In that file put "rm -f ~/scripts/elk-pool-mail.count" and make it executable
# or the count file will throw off this script the next MRTG asks it to run.
# Replace "your_target" with your Target name.  Replace the paths and filenames
# above with your own also.
# MRTG <http://www.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg.html>

# This is the file that will hold the current number of iterations MRTG has
# been told to skip before sending the followup e-mail.
# Important!  Uh, this may or may not work.  Give it a try.  If it hurls a slew
# of errors at you, replace every $COUNT_FILE with your own path. :-)

# You don't want MRTG to e-mail you every single time it runs and the threshold
# has been met (which is every 3 minutes on my setup) define a number of cycles
# you want MRTG to skip before it e-mails you.
# (i.e. 20 cycles at 3 minutes each is 1 hour)

# Since I wrote this to e-mail me when the maximum number of dialin ports were
# used on one of our terminal servers, I also worded the warning e-mail that
# way.  Word you message however you like to suit your needs.

# This is the address that the message will be sent to.
CONTACT_EMAIL="your_contact at e-mail.address"

# The current date in the format The date in the format "2:54 AM Mon Feb 07"
#  (no quotes).  DO NOT comment this out unless you intend on removing it from
DATE=`date '+%l:%M %p %a %b %d' |awk '{print $1, $2, $3, $4, $5}'`

# Subject line for the initial e-mail you're sending.  Make it something that
# stands outs a bit.

# Subject line for the followup e-mail you're sending.  Make it something that
# stands outs a bit.

# If you don't define the fully qualified hostname here, it will be assigned
# later on in the script. The only problem produced by *not* specifying it here
# is that $HOST won't be printed in $INITIAL_MESSAGE or either of the $FOLLOWUP
# messages.

# This is the URL you want printed in the body of the message.  Its customary
# to use the same URL as the MRTG Target that produced the Threshold error.

# Enter the body of the initial e-mail that you want to send here.  This is
# the message that is sent the first time the Threshold is breached.
# Below is a list of variables you can use within you message.
This message is an automated repsonse from MRTG running on '$HOST'.
It was sent to let you know that at '$DATE' '$THRESH_DESC' reached
its max limit of $MAX_USERS simultaneous users.


# Enter the top half body of the followup e-mail that you want to send here.
# This is only the top half.  You enter the bottom half just below.  Between
# the two the initial time that the problem was encountered is printed.
# This is the message that is sent after the time you specified has passed,
# assuming the Threshold is still breached and it didn't fall below that
# Threshold since the first breach.  The time passed is calculated on the
# frequency MRTG running on your system and $MAX_COUNT.
# (i.e.  how often you run MRTG in minutes * $MAX_COUNT = how often you'll
# recieve the warning e-mail.
# Below is a list of variables you can use within you message.
This followup message is an automated repsonse from MRTG running on
'$HOST'.  It was sent to remind you that at:

# Enter the bottom half of the followup message.
'$THRESH_DESC' reached its max limit of $MAX_USERS simultaneous users.


# $DATE  The date in the format "2:54 AM Mon Feb 07" (no quotes)
# $HOST  The fully-qualified domain name composed of $HOSTNAME.$DNSDOMAINAME.
# The rest are self explanitory or are explained above.
# $URL

# Unless you were told to modify something below this line, or unless you know
# what you're doing...
#    Don't modify anything below this line.

# piped through awk to eliminate the annoying space at the beginning.
DATE=`date '+%l:%M %p %a %b %d' |awk '{print $1, $2, $3, $4, $5}'`

if [ -f ~/scripts/elk-pool-mail.count ];
    CURRENT_COUNT=`cat ~/scripts/your_target.count |awk '{print $1}'`
    START_DATE=`cat ~/scripts/your_target.count |awk '{print $2, $3, 
$4, $5, $6}'`
    echo $CURRENT_COUNT;
    echo $START_DATE;
    NEW_COUNT=`expr "$CURRENT_COUNT" \+ 1`;
    echo "$NEW_COUNT  $DATE" > ~/scripts/your_target.count;
    echo $NEW_COUNT;
    if [ $NEW_COUNT -eq $MAX_COUNT ];
     then {
       echo $NEW_COUNT;

     echo "1  $START_DATE" > ~/scripts/your_target.count;
   else {

     echo "$CURRENT_COUNT  $DATE" > ~/scripts/your_target.count;

Justin Shore
K-State Linux Distro Mirror, Sysadmin
macdaddy at vinnie.ksu.ksu.edu

Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:mrtg-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/mrtg

More information about the mrtg mailing list