Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_mrtgtraf

Rating
4 votes
Favoured:
1
Current Version
1.01
Last Release Date
2012-08-21
Compatible With
  • Nagios 1.x
  • Nagios 2.x
  • Nagios 3.x
Owner
Hits
72680
Files:
FileDescription
check_mrtgtraf.plcheck_mrtgtraf.pl
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
almost the same as original check_mrtgtraf but this one works and is "fine tuned" to give detailed output on which IN or OUT threshold was exceeded, it is also "fine tuned" to present the output in Mbyte and/or Kbytes depending on how much traffic there was.

You can tell the program what "unit" the WARNING or CRITICAL thresholds will be in. The script supports input as kbytes, mbytes, gbytes or tbytes.

Don't forget to edit the file to point to the directory where your utils.pm is located. Find and Change below line.
use lib "/usr/local/nagios/libexec";
check_mrtgtraf.pl 1.0.1
Usage: check_mrtgtraf.pl -|--f|F|FUN|function|FUNCTION -|--l|L|log|LOG|logfile|LOGFILE
-|--w|W|warn|WARN|warning|WARNING Warning threshold in bytes ,
-|--c|C|crit|CRIT|critical|CRITICAL critical threshold in bytes ,
-|--u|un|UNIT unit for , thresholds
-|--v|V|VERSION |version -|--he|HE|help|HELP -|--d|D|DEBUG|debug [debug]

./check_mrtgtraf.pl -F MAX -L /scripts/test.log -w 9,9 -c 9999999999,999999999
./check_mrtgtraf.pl -FUNC MAX -LOG /scripts/test.log -WARN 1048576,2097152 -CRIT 2097152,3145728
./check_mrtgtraf.pl -function MAX -logfile /scripts/test.log -warning 1048576 -critcal 2097152 --debug
./check_mrtgtraf.pl -F AVG -L /scripts/test.log -w 9,9 -c 9999999999,999999999
./check_mrtgtraf.pl -FUNCT AVG -LOG /scripts/test.log -WARN 1048576,2097152 -CRIT 2097152,3145728
./check_mrtgtraf.pl -function AVG -logfile /scripts/test.log -warning 1048576 -critical 2097152 --debug
./check_mrtgtraf.pl -FUNCT AVG -LOG /scripts/test.log -WARN 100,100 -CRIT 200,2000 -u kilobytes
./check_mrtgtraf.pl -FUNCT AVG -LOG /scripts/test.log -WARN 100,100 -CRIT 200,2000 -u megabytes
./check_mrtgtraf.pl -FUNCT AVG -LOG /scripts/test.log -WARN 100,100 -CRIT 200,2000 -u gigabytes
./check_mrtgtraf.pl -FUNCT AVG -LOG /scripts/test.log -WARN 100,100 -CRIT 200,2000 -u terabytes
./check_mrtgtraf.pl --help
./check_mrtgtraf.pl --version

-|--f|F|FUN|FUNCTION|function Can be either AVG or MAX. where AVG = "The average incoming transfer rate in bytes per second"
AND MAX = "The maximum incoming transfer rate in bytes per second since last MRTG poll"
(DEFAULT AVG)

-|--w|W|warn|WARN|warning|WARNING This will tell Nagios when to send a WARNING message.
WARNING Threshold expects bytes input as default(unless you use the -u flag) and needs to be supplied as
a "warning threshold pair" ,.
If there is only one value passed in it will use that value in both pairs.
(NO DEFAULT)

-|--c|C|crit|CRIT|critical|CRITICAL This will tell Nagios when to send a CRITCAL message.
CRITCAL Threshold expects bytes input as default(unless you use the -u flag) and needs to be supplied as
a "critical threshold pair" ,.
If there is only one value passed in it will use that value in both pairs.
(NO DEFAULT)

-|--|u|un|UNIT If you don't want to pass in WARNING and CRITICAL threshold pairs using default "bytes input" then use this flag to
change it to suit your need. This script understands Kilobytes, Megabytes, Gigabytes and Terabytes.
Input is regexped so can be anything from or or or .
If this flag is not used THEN scripts expects input for WARNING and CRITICAL thresholds to be in bytes.

-d|D|DEBUG|debug : Enable debugging (DEFAULT disabled)

-|--he|HE|help|HELP Prints this help screen

-|--v|V|VERSION|version Prints program version

INFO: WARNING THRESHOLDS must be exceeded before any checks are done on CRITICAL THRESHOLDS!
Also only use the debug flag from the CLI Nagios will be very confused by it.
If you find any BUGs or have a suggestion on a feature or improvments then please drop a line to cocoon.is@gmail.com

IMPORTANT!! For this scripts to work with Nagios! This script needs to be able to find nagios supplied utils.pm file.
Edit this file at the top of the file change "use lib qw( /usr/local/nagios/libexec );" to point to where you Nagios
installation installed utils.pm.
IF you get errors looking like
"Global symbol "%ERRORS" requires explicit package name" Then it is a sure sign that your path to utils.pm is wrong.



commands.cfg
# 'check_mrtgtraf.pl' command definition #
define command{
command_name check_mrtgtraf.pl
command_line $USER1$/check_mrtgtraf.pl -L $ARG1$ -F $ARG2$ -w $ARG3$ -c $ARG4$ -u $ARG5$
}

bandwidth_checks.cfg
# Define a host for the local machine

define host{
use unix-server ; Name of host template to use
host_name mrtghost1
alias mrtg.
address 127.0.0.1
}

define hostgroup{
hostgroup_name bandwidth-monitoring ; The name of the hostgroup
alias bw-monitoring
members mrtghost1
}

define service{
use local-service
host_name mrtghost1
service_description Check bandwidth router1 customer1
check_command check_mrtgtraf.pl!/usr/home/www/mrtg/customer1/router1/1.1.1.1_ae0.log!MAX!10,20!11,21!mbyte!
}
Reviews (3)
+1 for the user who submitted "script to obtain check_mrtgtraf performance data needed by NagiosGraph"
https://exchange.nagios.org/directory/Plugins/%2A-Plugin-Development-Tools/check_mrtgtraf/details#rev-3196

Using that, as is, even though it is written in Spanish, I was able to pop it in as a proxy script to check_mrtgtraf and it works out of the box for me using Graphite, Whipser, Grafana! Thanks for that contribution!!!
I wrote this script that modifies check_mrtgtraf output in order to obtain usable performance data usable by nagiosgraph.

I hope it will be useful.

Rodrigo

#!/bin/sh
# parche check_mrtgtraf para que salga en nagiosgraph v_1.2 3 dic 2014 Rodrigo Avila

COMANDO=/usr/lib/nagios/plugins/check_mrtgtraf

ARCHIVO=$2
AGREGACION=$4
CRITI=$6
WARNI=$8

#valor=`/usr/lib/nagios/plugins/check_mrtgtraf -F /srv/www/htdocs/mrtg/192.168.1.1.log -a AVG -c "175000,175000" -w "165000,165000"`

valor=`$COMANDO -F $ARCHIVO -a $AGREGACION -c $CRITI -w $WARNI`

literal=`echo $valor | cut -d"|" -f1`

valorInKB=`echo $valor | cut -d"|" -f2 | cut -d"=" -f2 | cut -d "K" -f1`
valorIn=`echo "scale=4 ; $valorInKB * 1024 * 8 /1 "| bc`

valorOutKB=`echo $valor | cut -d"|" -f2 | cut -d"=" -f3 | cut -d "K" -f1`
valorOut=`echo "scale=4 ; $valorOutKB *1024 * 8 /1 "| bc`

# convert Bytes to bits
AJUSTE="8"

inCritiKB=`echo $CRITI | cut -d"," -f1`
inCriti=`echo "scale=2 ; $inCritiKB * $AJUSTE /1 "| bc`

#inCriti=$inCritiKB

outCritiKB=`echo $CRITI | cut -d"," -f2`
outCriti=`echo "scale=2 ;$outCritiKB * $AJUSTE /1"| bc`

#outCriti=$outCritiKB

inWarniKB=`echo $WARNI | cut -d"," -f1`
inWarni=`echo "scale=2 ; $inWarniKB * $AJUSTE /1"| bc`

#inWarni=$inWarniKB


outWarniKB=`echo $WARNI | cut -d"," -f2`
outWarni=`echo "scale=2 ;$outWarniKB * $AJUSTE /1"| bc`

#outWarni=$outWarniKB

esCritico=`echo $literal | grep "Traffic CRITICAL" | wc -l `
if [ $esCritico -eq "1" ]
then
echo "$literal|in=$valorIn;$inWarni;$inCriti;0 out=$valorOut;$outWarni;$outCriti;0"
exit 2;
fi


esWarning=`echo $literal | grep "Traffic WARNING" | wc -l `
if [ $esWarning -eq "1" ]
then
echo "$literal|in=$valorIn;$inWarni;$inCriti;0 out=$valorOut;$outWarni;$outCriti;0"
exit 1;
fi


echo "$literal|in=$valorIn;$inWarni;$inCriti;0 out=$valorOut;$outWarni;$outCriti;0"
exit 0;

------------------------
commands.cfg:
# 'check_local_mrtgtraf' command definition
define command{
command_name check_local_mrtgtraf
#RAK command_line $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$
command_line $USER1$/parche_check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$
}
----------------------
myrouter.cfg:

define service{
use generic-service
host_name MYROUTER
service_description Uso de ancho de banda del Enlace ISP
check_command check_local_mrtgtraf!/srv/www/htdocs/mrtg/myrouter_192.168.1.1.log!AVG!276000,113750!256000,93750!10
}
Hello,

I started to use this script, and it looks good to use easier than the original one. My only problem is, that the pnp4nagios stopped working and doesn't want to make the graphs anymore. Don't you have any idea about it?

Thank for the great script!

Regards,

Tamás