Pages

Configuring SNMP to work with MRTG on a Linux machine

Configuring SNMP to work with MRTG on a Linux machine
(A very basic, example setup)

All steps in this example are based on the following system / network :-
RedHat 9.0 (Full) running on a P-II Celeron 800 Mhz, 128MB RAM acting as server
One 100Mbps network card connected to a 100Mbps HUB
One 56Kbps external modem (connected to a local ISP of-course)
Two wintendo clients running wintendo ver 2000 and wintendo ver XP
All computers are on a network of 192.168.1.0/24. Server has IP: 192.168.1.254, wintendo computers have IP 192.168.1.1 and 192.168.1.2 respectively


(Note : it is needless to say that Server has all packages installed during installation. If you think you do not have some of the packages, see the MRTG HomePage for a list of what do you need. Also all steps were performed as root on the machine mainserver.kbsoft.local which is server)
Step 1:
Edit the /etc/snmp/snmpd.conf file and change things to make it look like :-


# vi /etc/snmp/snmpd.conf


###############################################################################
#
# snmpd.conf:
# An example configuration file for configuring the ucd-snmp snmpd agent.
#
###############################################################################
#
# This file is intended to only be as a starting point. Many more
# configuration directives exist than are mentioned in this file. For
# full details, see the snmpd.conf(5) manual page.
#
# All lines beginning with a '#' are comments and are intended for you
# to read. All other lines are configuration commands for the agent.


###############################################################################
# Access Control
###############################################################################


# As shipped, the snmpd demon will only respond to queries on the
# system mib group until this file is replaced or modified for
# security purposes. Examples are shown below about how to increase the
# level of access.


# By far, the most common question I get about the agent is "why won't
# it work?", when really it should be "how do I configure the agent to
# allow me to access it?"
#
# By default, the agent responds to the "public" community for read
# only access, if run out of the box without any configuration file in
# place. The following examples show you other ways of configuring
# the agent so that you can change the community names, and give
# yourself write access to the mib tree as well.
#
# For more information, read the FAQ as well as the snmpd.conf(5)
# manual page.


####
# First, map the community name "public" into a "security name"
# sec.name source community
com2sec local localhost KBComputersSNMP
com2sec mynet 192.168.1.0/24 KBComputersSNMP
####
# Second, map the security name into a group name:
# groupName securityModel securityName
group myrwgroup any local
group myrogroup any mynet


####
# Third, create a view for us to let the group have rights to:
# Make at least snmpwalk -v 1 localhost -c public system fast again.
# name incl/excl subtree mask(optional)
view all included .1 80
####
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
access myrwgroup "" any noauth exact all all none
access myrogroup "" any noauth exact all none none
# -----------------------------------------------------------------------------
syslocation KBMainOffice (edit /etc/snmp/snmpd.conf)
syscontact Kamran <root@localhost> (configure /etc/snmp/snmp.local.conf)
sysDescr RedHat_Linux


##########################
# Irrelevant lines removed
##########################


# Added for support of bcm5820 cards.
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat


#############################################################################
# Further Information
# See the snmpd.conf manual page, and the output of "snmpd -H".
##############################################################################




Step 2:
Now start SNMP service by :-
# service snmpd start


Step 3:
Now run cfgmaker on this config file by :-
# cfgmaker KBComputersSNMP@192.168.1.254 > /etc/mrtg/mrtgkbsoft.cfg
And you should get output as :-
--base: Get Device Info on KBComputersSNMP@192.168.1.254:
--base: Vendor Id:
--base: Populating confcache
--snpo: confcache KBComputersSNMP@192.168.1.254: Descr -->
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 1.0 --> 1
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 2.0 --> 64
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 3.0 --> 115822
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 4.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 5.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 6.0 --> 5881
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 7.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 8.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 9.0 --> 108906
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 10.0 --> 70094
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 11.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 12.0 --> 26
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 13.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 14.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 15.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 16.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 17.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 18.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 19.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.1.127.0.0.1 --> 127.0.0.1
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.1.192.168.1.254 --> 192.168.1.254
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.1.210.56.9.144 --> 210.56.9.144
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.2.127.0.0.1 --> 1
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.2.192.168.1.254 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.2.210.56.9.144 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.3.127.0.0.1 --> 255.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.3.192.168.1.254 --> 255.255.255.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.3.210.56.9.144 --> 255.255.255.255
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.4.127.0.0.1 --> 1
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.4.192.168.1.254 --> 1
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 20.1.4.210.56.9.144 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.1.0.0.0.0 --> 0.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.1.127.0.0.0 --> 127.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.1.169.254.0.0 --> 169.254.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.1.192.168.1.0 --> 192.168.1.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.1.210.56.8.143 --> 210.56.8.143
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.2.0.0.0.0 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.2.127.0.0.0 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.2.169.254.0.0 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.2.192.168.1.0 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.2.210.56.8.143 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.3.0.0.0.0 --> 1
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.3.127.0.0.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.3.169.254.0.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.3.192.168.1.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.3.210.56.8.143 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.7.0.0.0.0 --> 210.56.8.143
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.7.127.0.0.0 --> 0.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.7.169.254.0.0 --> 0.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.7.192.168.1.0 --> 0.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.7.210.56.8.143 --> 0.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.8.0.0.0.0 --> 4
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.8.127.0.0.0 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.8.169.254.0.0 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.8.192.168.1.0 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.8.210.56.8.143 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.9.0.0.0.0 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.9.127.0.0.0 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.9.169.254.0.0 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.9.192.168.1.0 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.9.210.56.8.143 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.11.0.0.0.0 --> 0.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.11.127.0.0.0 --> 255.0.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.11.169.254.0.0 --> 255.255.0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.11.192.168.1.0 --> 255.255.255.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.11.210.56.8.143 --> 255.255.255.255
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.13.0.0.0.0 --> 0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.13.127.0.0.0 --> 0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.13.169.254.0.0 --> 0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.13.192.168.1.0 --> 0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 21.1.13.210.56.8.143 --> 0.0
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 22.1.1.2.192.168.1.1 --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 22.1.2.2.192.168.1.1 --> �\
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 22.1.3.2.192.168.1.1 --> 192.168.1.1
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 22.1.4.2.192.168.1.1 --> 3
--snpo: confcache KBComputersSNMP@192.168.1.254: Ip 23.0 --> 0
--snpo: confcache KBComputersSNMP@192.168.1.254: Name -->
--snpo: confcache KBComputersSNMP@192.168.1.254: Type -->
--snpo: confcache KBComputersSNMP@192.168.1.254: Eth --> 1
--snpo: confcache KBComputersSNMP@192.168.1.254: Eth 00-c0-26-69-95-cb --> 2
--snpo: confcache KBComputersSNMP@192.168.1.254: Eth --> 3 (duplicate)
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifSpeed
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
#


If you get errors like 'SNMP Error' , etc then check your config file again, also check if the SNMP service is running or not.


Step 4:
Once the mrtg config file (/etc/mrtg/mrtgkbsoft.cfg) is generated, you have to edit it to change the WorkDir directive in it to the directory under your Webserver's DocumentRoot directory. In my case it is /var/www/html/mrtg. Below is just the starting part of this file:
# vi /etc/mrtg/mrtgkbsoft.cfg
# Created by
# /usr/bin/cfgmaker KBComputersSNMP@192.168.1.254
### Global Config Options


# for UNIX
WorkDir: /var/www/html/mrtg


# or for NT
# WorkDir: c:\mrtgdata


### Global Defaults


# to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits


######################################################################


Step 5:
Once the file is edited, run indexmaker on it to generate the web pages for MRTG by:-
# indexmaker /etc/mrtg/mrtgkbsoft.cfg > /var/www/html/mrtg/index.html
You will see an output like the following, but do not worry, it will work :-


Possible precedence problem on bitwise operator at /usr/bin/../lib/mrtg2/BER.pm line 601.
Can't locate package $VERSION for @MRTG_lib::ISA at /usr/bin/indexmaker line 49
main::BEGIN() called at /usr/bin/../lib/mrtg2/MRTG_lib.pm line 49
eval {...} called at /usr/bin/../lib/mrtg2/MRTG_lib.pm line 49
#
Step 6:
Now that your index page is also made, you need to get data from the snmp daemon and fill the graphs of the index.html web page. Do this by:-
# mrtg /etc/mrtg/mrtgkbsoft.cfg
You will see a lot of error messages on RedHat8 and RedHat9 systems like :-
Malformed UTF-8 character (unexpected non-continuation byte 0x20, immediately after start byte 0xe2) at /usr/bin/../lib/mrtg2/locales_mrtg.pm line 3107.
Malformed UTF-8 character (unexpected non-continuation byte 0xcf, immediately after start byte 0xc0) at /usr/bin/../lib/mrtg2/locales_mrtg.pm line 3107.
But again nothing to worry about. This will work anyway. Just look for the missing file errors at the end, they are normal and you need to issue this command thrice to eliminate those errors.
Step 7:
Now is the time to check your web page. Direct your favorite web-browser to the URL /var/www/html/index.html
You should be able to see a graph (like the one shown below), possibly without any activity in it. If you can see this, then congragulations , you have setup SNMP and MRTG correctly on this machine.




You should be able to see more detailed graphs (child graphs of this graph) by clicking on it.
Now you need to feed data to this graph on a regular basis, let's say an interval of 5 minutes. What you need to do is in Step 8.
Step 8:
Edit crontab and put the entry in it as shown below.
# crontab -e
*/5 * * * * mrtg /etc/mrtg/mrtgkbsoft.cfg


Optional steps:-
The above scenario will allow you to view this graph only from the mainserver.kbsoft.local machine. If you want to view it from the rest of your network, then you may use the power of your web server. You got that right, the idea to put mrtg files in such a long complicated path was to be able to use the power of the web server in future. In order to achieve this, configure your webserver's ServerName directive accordingly and start your webserver by:-
# service httpd start
Now any machine on this network can access these graphs by directing their URL to http://mainserver.kbsoft.local/mrtg/index.html


Important note: Treat your community string as passwords and DO NOT reveal them to others.










Forex Trading