User Tools

Site Tools


simple_snmp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
simple_snmp [2007/08/28 23:58]
adam
simple_snmp [2016/11/25 22:38] (current)
Line 11: Line 11:
 Most networking devices such as routers (even home consumer routers) and managed switches offer SNMP support. The most common usage of SNMP is in querying for system status information as described above, but it is also possible to write values to a system using SNMP and using certain types of system events as what are called SNMP traps, which are sent to a monitoring system which will generate alerts for the system administrators. Neither SNMP writes or SNMP traps are discussed here. Perhaps they will be in an update at some point. Most networking devices such as routers (even home consumer routers) and managed switches offer SNMP support. The most common usage of SNMP is in querying for system status information as described above, but it is also possible to write values to a system using SNMP and using certain types of system events as what are called SNMP traps, which are sent to a monitoring system which will generate alerts for the system administrators. Neither SNMP writes or SNMP traps are discussed here. Perhaps they will be in an update at some point.
  
-Information is stored in a tree like structure as far as SNMP is concerned. MIBs (Management Information Bases) are essentially like branches on the tree, they are groups of related SNMP data, such as system data, interface data. OIDs (object identifiers) are leaves on the tree, that is, they are individual items of queryable data. Phew. Technical. OIDs are normally numeric values, but thankfully most have human memorable names. MIBs are stored as text files under /usr/share/snmp/mibs/ in Linux.+Information is stored in a tree like structure as far as SNMP is concerned. MIBs (Management Information Bases) are essentially like branches on the tree, they are groups of related SNMP data, such as system data, interface data etc. OIDs (object identifiers) are leaves on the tree, that is, they are individual items of queryable data, as defined in the MIBs. Phew. Technical. OIDs are normally numeric values, but thankfully most have human memorable names. MIBs are stored as text files under /usr/share/snmp/mibs/ in Linux.
  
 Many network hardware vendors provide MIBs which map their specific hardware information (temperatures, fans speeds etc, power usage) to a set of OIDs, normally under the 'enterprises' MIB group. The default set of MIBs on Linux is pretty good, so you only need these extra MIBs for system data unique to the hardware you are using. Cisco MIBs will certainly be useful when using their equipment. You should first try your hardware vendor or there are many places to get get MIBs if you need them. I haven't yet found a clean, easy way to include vendor specific MIBs when querying, but you should start by placing them under /usr/share/snmp/mibs/. Many network hardware vendors provide MIBs which map their specific hardware information (temperatures, fans speeds etc, power usage) to a set of OIDs, normally under the 'enterprises' MIB group. The default set of MIBs on Linux is pretty good, so you only need these extra MIBs for system data unique to the hardware you are using. Cisco MIBs will certainly be useful when using their equipment. You should first try your hardware vendor or there are many places to get get MIBs if you need them. I haven't yet found a clean, easy way to include vendor specific MIBs when querying, but you should start by placing them under /usr/share/snmp/mibs/.
Line 91: Line 91:
 ==== Set Up Your SNMP Query Host ==== ==== Set Up Your SNMP Query Host ====
  
-You need a machine to make requests from and this should be the machine which you have in your SNMP configuration on the other machines. For Windows, I don't know what you're going to do, I don't use Windows for anything network related, so you're on your own. You'll probably have to pay someone money for some software, but you could try starting with the snmp command or look at PRTG for graphing, it should point you in the right direction.+You need a machine to make requests from and this should be the machine which you have in your SNMP configuration on the other machines. For Windows, I don't know what you're going to do, I don't use Windows for anything network related, so you're on your own. You'll probably have to pay someone money for some software, but you could try starting with the snmp command or look at PRTG for graphing, they should point you in the right direction.
  
 On Fedora: On Fedora:
Line 100: Line 100:
  
   apt-get install snmp   apt-get install snmp
 +
  
 ==== Running SNMP Queries ==== ==== Running SNMP Queries ====
Line 107: Line 108:
   snmpwalk -c <my_community_name> -v 2c <machine>   snmpwalk -c <my_community_name> -v 2c <machine>
  
-...where <machine> is the IP of resolvable hostname of the machine you want to query. Here we are using snmpwalk, which basically walks the MIB tree, querying the host, using SNMP v2c as we specified, for everything it knows about. You will get a lot of output. If you don't get anything you have done something wrong and will have to go back through your config on the hosts to make sure it is accepting SNMP queries from your query machine.+...where <machine> is the IP or resolvable hostname of the machine you want to query. Here we are using snmpwalk, which basically walks the MIB tree, querying the host, using SNMP v2c as we specified, for everything it knows about. You will get a lot of output. If you don't get anything you have done something wrong and will have to go back through your config on the hosts to make sure it is accepting SNMP queries from your query machine.
  
 You can do the same but specify a subset of OIDs to query: You can do the same but specify a subset of OIDs to query:
Line 117: Line 118:
   snmpwalk -c <my_community_name> -v 2c <machine> system   snmpwalk -c <my_community_name> -v 2c <machine> system
  
-Good huh?+for system related OIDs. Good huh? 
  
 ==== Graphing Your Output ==== ==== Graphing Your Output ====
Line 123: Line 125:
 So, you want to do something useful with your SNMP output, because it's just a great big list of crap? On Linux, use [[http://oss.oetiker.ch/mrtg/|MRTG]], on Windows, use [[http://www.paessler.com/prtg|PRTG]]. Windows people will have to figure it out themselves, but Linux people can use the following. So, you want to do something useful with your SNMP output, because it's just a great big list of crap? On Linux, use [[http://oss.oetiker.ch/mrtg/|MRTG]], on Windows, use [[http://www.paessler.com/prtg|PRTG]]. Windows people will have to figure it out themselves, but Linux people can use the following.
  
-The following example details how to get bandwidth usage graphs. You can take it further by reading [[http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch23_:_Advanced_MRTG_for_Linux|Chapter 23 or Linux Home Networking]] to graph other SNMP stats.+The following example details how to get bandwidth usage graphs. You can take it further by reading [[http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch23_:_Advanced_MRTG_for_Linux|Chapter 23 or Linux Home Networking]] and the [[http://oss.oetiker.ch/mrtg/doc/|MRTG documentation]] to graph other SNMP stats.
  
 === Install MRTG === === Install MRTG ===
Line 135: Line 137:
   yum install mrtg   yum install mrtg
  
-Your distro will probably create you a directory under /var/www for mrtg so try http://localhost/mrtg/ to see if there is anything there, there should be, but not much yet. Check your apache/httpd configuration if there is a problem accessing it as at least Fedora only allows access from localhost by default. You might want to allow access from other hosts but protect it with a username and password and even SSL if you are wary.+Your distro will probably create you a directory under /var/www for mrtg so try http://localhost/mrtg/ to see if there is anything there, there should be, but not much yet. Check your apache/httpd configuration if there is a problem accessing it as I know Fedora only allows access from localhost by default. You might want to allow access from other hosts but protect it with a username and passwordeven SSL too if you are wary.
  
 Next you need to create some MRTG config files for the hosts you will query: Next you need to create some MRTG config files for the hosts you will query:
Line 161: Line 163:
 Add the following line to the crontab of a user which is able to write to your web server's MRTG directory and files: Add the following line to the crontab of a user which is able to write to your web server's MRTG directory and files:
  
-  */5 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg/myhost.cfg > /dev/null 2>&1+''*/5 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg/myhost.cfg > /dev/null 2>&1'' 
 + 
 +This will make MRTG collect stats via SNMP every 5 minutes. Do the same for any other hosts you wish to graph. Note that I have redirected all standard output and errors to /dev/null, so I don't have to hear about it if it doesn't work. Don't do this until you are satisfied that it works properly. 
 + 
 +And that, my friend, is it.
  
-This will make MRTG collect stats via SNMP every 5 minutes. Do the same for any other hosts you wish to graph.+==== Going Further ====
  
-And that, my friend, is it. You should try graphing CPU, disk and memory usage, system load, component temperatures and so on. MRTG is able to graph anything which you pass it information for and SNMP can make most of that information available over a network.+You should try graphing other data such as CPU, disk and memory usage, system load, component temperatures and so on. MRTG is able to graph anything which you pass it information for and SNMP can make most of that information available over a network. Cacti is an alternative to MRTG for graphing other variables and is probably far easier. Investigate SNMP v3 for a more secure implementation. For lower CPU load, try replacing the default graphing tool in MRTG with RRDTool which was written by the same guy as MRTG.
  
 TODO: TODO:
  
 Links Links
simple_snmp.1188341919.txt.gz · Last modified: 2016/11/25 22:38 (external edit)