Thursday 7 November 2013

MRTG Configure for Router

 Step # 1 : Make sure snmp server installed

Type the following rpm command to find out, if snmp server installed or not:

# rpm -qa | grep snmp

If snmp installed then

# yum install net-snmp-utils net-snmp

Step # 2 : Determine if snmp server is running or not

Run 'ps' command to see if snmp server is running or not:

# ps -aux | grep snmp

Output:

root   5512  0.0  2.3  5872 3012 pts/0    S    22:04   0:00 /usr/sbin/snmpd

# netstat -natv | grep ':199'

tcp        0      0 0.0.0.0:199             0.0.0.0:*               LISTEN

If you found snmp service is running or listing on port 199

# service snmpd start

Make sure snmpd service starts automatically, when linux comes us (add snmpd service):

# chkconfig --add snmpd

Turn on snmpd service, enter:

# chkconfig snmpd on

Step # 3 : Make sure snmp server configured properly

# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Sample outputs:

ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.127.0.0.1 = 1

ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.192.168.0.3 = 2

Configure SNMP

(1) Edit the file /etc/snmp/snmpd.conf using a text editor such as vi, enter:

# vi /etc/snmp/snmpd.conf

Change/Modify line(s) as follows:

Find the following Line:

com2sec notConfigUser  default       public

Replace with (make sure you replace 192.168.0.0/24 with your network/subnet) the following lines:

com2sec local     localhost           public

com2sec mynetwork 192.168.0.0/24      public

(a) Make sure when linux comes up snmpd always starts after the system reboot:

 # chkconfig snmpd on

(b) Start the snmpd service:

 # service snmpd start

(c) Finally, test your snmp server:

 # snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Step # 4 : Install mrtg if not installed

Mrtg software may install during initial installation; you can verify if MRTG installed or not with the following RPM command:

rpm -qa | grep mrtg

Step # 5 : Commands to Configure mrtg

mkdir -p /var/www/html/mrtg/

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


Copy the image files--


cp -av /var/www/html/images/*.png /var/www/html/mrtg/




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


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


----Finally

http://192.168.10.29/mrtg/

No comments:

Post a Comment