Tech Corner

MRTG Config - Using RSH with a Cisco Router

[Last Updated: Monday, 09-Apr-2007 21:30:52 EDT]

Multi-Router Traffic Grapher (MRTG) is a great Unix utility that has been around for a long time to monitor and graph statistics related to anything and everything you can imagine. The trouble always is that if a device does not support SNMP or you need to capture a statistic that for some reason is not tracked with an SNMP MIB variable, it is kind of difficult to do it without some form of custom script. For the few people out there who understand the finer points of shell or PERL scripting, it isn't terribly difficult to throw something together from scratch. For the vast majority of users out there it means they are out of luck.

Here is an example script I put together to collect statistics related to the health of my DSL signal on my phone line. The statistics are able to be viewed from the command line on my router with a specific command but there is no way to grab the values individually using an SNMP MIB variable. So, I had to improvise to capture the data so I could graph it to watch for trending information.

It is effectively a one line script that uses rshell to login to my router, execute the particular command and then parse out the values that I need to graph. Cisco routers support rshell access using the 'ip rcmd' commands. Enabling rsh on a router does pose risk and should not be done without the proper security controls in place to keep unauthorized users from gaining administrative access to the device.


DISCLAIMER
 
No Warranty of any kind is expressed or implied with respect to the information contained in this document!
The information found here is compiled for the convenience of anyone looking for general guidelines and best practices for configuration based on my own professional experience, as well as industry standards.
Use this information at your own risk!
 
Scott S. 2007


Custom Shell Script

#!/bin/sh

# Get the Noise Margin info using rsh to the router

rsh router.domain.com sh dsl int atm0/0 | grep Noise | awk '{print $3; print $5}'

This script is saved in a common script directory for MRTG and the permissions are changed to allow it to be executable. RSH is a normally included binary utility with most Linux distributions. RSH is executed against the router's hostname followed by the actual command to be executed on the IOS command line. The results of this command are then piped to the grep command to filter everything out except for the line that includes the word Noise which contains the 2 values I am trying to extract. That output is then piped to the awk utility which essentially maps each space delimited string into an array. Now I can send the specific resulting fields to the standard output in the format that MRTG is expecting.


Cisco Router Config

ip rcmd rcp-enable
ip rcmd rsh-enable
ip rcmd remote-host mrtg 192.168.1.5 mrtg enable
ip rcmd remote-username root
!
username mrtg privilege 15 password 7 xxxxxxxxxxxxxxxx

This config enables a Cisco router to accept inbound RSH requests from my server's IP address with the privileges of the local mrtg user sourced from the remote user of root. Since my MRTG installations runs as root, the script inherits root permissions when it executes. The remote-username should be configured to whatever userID your MRTG installation runs under.


MRTG Config

Target[router.domain.com_dslnoise]: `/usr/local/mrtg-2/bin/mrtgdslnoise`
RouterUptime[router.domain.com_dslnoise]: community@router.domain.com
MaxBytes[router.domain.com_dslnoise]: 20
Options[router.domain.com_dslnoise]: gauge, absolute, nopercent, unknaszero
Colours[router.domain.com_dslnoise]: GREEN#00eb0c,BLUE#1000ff,DARK GREEN#006600,VIOLET#ff00ff
YLegend[router.domain.com_dslnoise]: Decibels
ShortLegend[router.domain.com_dslnoise]: dB
Legend1[router.domain.com_dslnoise]: Downstream Noise Margin, dB
Legend2[router.domain.com_dslnoise]: Upstream Noise Margin, dB
Legend3[router.domain.com_dslnoise]: Avg downstream Noise Margin, dB
Legend4[router.domain.com_dslnoise]: Avg upstream Noise Margin, dB
LegendI[router.domain.com_dslnoise]:  dB:
LegendO[router.domain.com_dslnoise]:  dB:
Title[router.domain.com_dslnoise]: DSL Noise Margin for -- router
PageTop[router.domain.com_dslnoise]: <H1>DSL Noise Margin for -- router</H1>
 <TABLE>
   <TR><TD>System:</TD><TD>router.domain.com in Address City, ST ZIP</TD></TR>
   <TR><TD></TD><TD>Cisco 3725 256MB DRAM IOS 12.4(4)XC1 Advanced IP Services<br>
   c3725-advipservicesk9-mz.124-4.XC1.bin</TD></TR>
   <TR><TD>Maintainer:</TD> <TD>Your Name</TD></TR>
   <TR><TD>Interface:</TD><TD>ATM0/0 Alcatel 20150 chipset<br>DSL Mode: ITU G.992.1 (G.DMT)<br>
   SW Version: 3.8131<br>FW Version: 0x1A04</TD></TR>
   <TR><TD>IP:</TD>     <TD>router.domain.com (192.168.1.1)</TD></TR>
   <TR><TD>Max dB:</TD>  <TD>20.0</TD></TR>
 </TABLE>
  <br>

DISCLAIMER
 
No Warranty of any kind is expressed or implied with respect to the information contained in this document!
The information found here is compiled for the convenience of anyone looking for general guidelines and best practices for configuration based on my own professional experience, as well as industry standards.
Use this information at your own risk!
 
Scott S. 2007

Last Revised: Monday, 09-Apr-2007 21:30:52 EDT


Privacy Statement   SSL Security by 
www.cacert.org