Wednesday, 20 November 2013

MRTG Configure for Router for Nagios Monitoring

#Test the Configuration with an SNMP Walk

snmpwalk -v 2c -c COMMUNITYSTRING IPADDRESS

#snmpwalk -v 1 -c public 69.250.150.54 system

snmpwalk -v 1 -c public 172.22.81.1 system
snmpwalk -v 1 -c public 192.168.122.1 system


Now you need to make the config (cfg) file for the device you want to monitor.

Quote
##/usr/bin/cfgmaker --output=/etc/mrtg/69.250.150.54.cfg --ifref=ip --global "workdir: /var/www/mrtg" --snmp-options=:::::1 public@69.250.150.54

/usr/bin/cfgmaker --output=/etc/mrtg/172.22.81.1.cfg --ifref=ip --global "workdir: /var/www/html/mrtg" --snmp-options=:::::1 public@172.22.81.1

Now you need to run the env statement "three" times:

Quote
#run three times
#env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
#env LANG=C /usr/bin/mrtg /etc/mrtg/69.250.150.54.cfg

#You should see this after each time ran:
env LANG=C /usr/bin/mrtg /etc/mrtg/172.22.81.1.cfg

[root@nagios mrtg]# env LANG=C /usr/bin/mrtg /etc/mrtg/172.22.81.1.cfg
07-11-2013 11:59:05, Rateup WARNING: /usr/bin/rateup Can't remove 172.22.81.1_10.67.51.106.old updating log file
07-11-2013 11:59:05, Rateup WARNING: /usr/bin/rateup Can't remove 172.22.81.1_10.255.65.214.old updating log file
07-11-2013 11:59:05, Rateup WARNING: /usr/bin/rateup Can't remove 172.22.81.1_172.22.81.1.old updating log file
07-11-2013 11:59:05, Rateup WARNING: /usr/bin/rateup Can't remove 172.22.81.1_172.29.81.2.old updating log file
07-11-2013 11:59:05, Rateup WARNING: /usr/bin/rateup Can't remove 172.22.81.1_172.29.81.6.old updating log file
[root@nagios mrtg]# env LANG=C /usr/bin/mrtg /etc/mrtg/172.22.81.1.cfg
[root@nagios mrtg]#


Now you need to make the actual index files for each machine:
#Very important you need to append the new machine to the line each time, if you do not you will only see the newest entry

Quote


indexmaker --output=/var/www/html/mrtg/index.html /etc/mrtg/mrtg.cfg /etc/mrtg/172.22.81.1.cfg

###For Two Router###

indexmaker --output=/var/www/html/mrtg/index.html /etc/mrtg/mrtg.cfg /etc/mrtg/172.22.81.1.cfg  /etc/mrtg/192.168.122.1.cfg


Note: The above command should be run for each router

Quote

vim /etc/cron.d/mrtg

#Enter in you machines like my example below:

0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/172.22.81.1.cfg

Note: one entry will be added for every router

Now restart the crond service.

Quote

service crond restart

[root@nagios mrtg]# service crond restart
Stopping crond:                                            [  OK  ]
Starting crond:                                            [  OK  ]
[root@nagios mrtg]#


---Log Location

/var/www/mrtg

# '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$
}

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!
}



define service{
                use                     generic-service
                host_name               core_router_neweskaton_172.22.81.1
                service_description     Port 1 Bandwidth Usage
                check_command           check_mrtgtraf.pl!/var/www/html/mrtg/172.22.81.1_172.22.81.1.log!MAX!10,20!11,21!mbyte!
                }

---compile the command----

/usr/bin/nagios -v /etc/nagios/nagios.cfg



/usr/lib/nagios/plugins/check_mrtgtraf -F /var/www/mrtg/172.22.81.1_172.22.81.1.log -a AVG -w 1000000,1000000 -c 5000000,5000000 -e 10

/usr/lib/nagios/plugins/check_mrtgtraf.pl - F /var/www/mrtg/172.22.81.1_172.22.81.1.log -a MAX -w 10,20 -c 11,21 -e mbyte

-----------------Note-----------

I almost forgot the simple one security is turned on by default and you can't connect remotely unless you change it. In the example below
I canged it to allow all so I could connect to it from anywhere I wanted to from the internet or local lan.

Quote
vi /etc/httpd/conf.d/mrtg.conf


#
# This configuration file maps the mrtg output (generated daily)
# into the URL space. By default these results are only accessible
# from the local host.
#
Alias /mrtg /var/www/mrtg


Order allow,deny
Allow from all

No comments:

Post a Comment