Cheshire Cat Computing

Software support and information
It is currently Thu Jan 17, 2019 12:46 pm

All times are UTC + 12 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun May 24, 2015 10:39 am 
Offline
Silver User

Joined: Thu Jan 26, 2012 11:32 am
Posts: 29
Location: Linköping, Sweden
This interface template will add lldp information to the interface pages:
Code:
##########################################################################
# MRTG interface template to add LLDP informaiton to interface pages.
# Usage: cfgmaker --if-template=lldp.itp community@device
#
# Known caveats:
#
# This template is available under the GNU GPL. For more information, please
# see http://www.gnu.org/copyleft/gpl.html.
#
# This is version 20150519
#
# Version History:
# 20150519 - Initial Release

$target_lines = $default_target_lines;

my($extrarows);
my($ifname)= $target_lines =~ /<td>ifName:<\/td>\n\t\t\t\t\t<td>(.*?)<\/td>/;
if($ifname)
{
  # my (@interfaces) = snmpwalk($router_connect,'1.0.8802.1.1.2.1.3.7.1.4');
  # Using IF-MIB::ifName instead of lldp ifname seems to work with more
  # devices:
  my (@interfaces) = snmpwalk($router_connect,'1.3.6.1.2.1.31.1.1.1.1');
  foreach my $tmpinterface (@interfaces)
  {
    $tmpinterface =~ /(\d+):(.+)/;
    my($instance,$tmpifname)=($1,$2);
    if($tmpifname eq $ifname)
    {
      my(@dummyline) = snmpwalk($router_connect, "1.0.8802.1.1.2.1.4.1.1.4");
      foreach my $tmpline (@dummyline)
      {
        $tmpline =~ /(\d+)\.(\d+)\.(\d+):(\d+)/;
        my($firstnum, $tmpinst, $lastnum) = ($1, $2, $3);
        if($tmpinst == $instance)
        {
          my($portid, $portname, $machinename, $machinetype) =
            snmpget(
              $router_connect,
              "1.0.8802.1.1.2.1.4.1.1.7.".$firstnum.".".$instance.".".$lastnum,
              "1.0.8802.1.1.2.1.4.1.1.8.".$firstnum.".".$instance.".".$lastnum,
              "1.0.8802.1.1.2.1.4.1.1.9.".$firstnum.".".$instance.".".$lastnum,
            "1.0.8802.1.1.2.1.4.1.1.10.".$firstnum.".".$instance.".".$lastnum);
          if((defined $firstnum) && (defined $portname))
          {
            $extrarows =
              "<tr>\n\t\t\t\t\t<td>Connected to:</td>\n\t\t\t\t\t<td>";
            $extrarows .=
              "Port $portname ";
            if(($portid =~ /^[A-Za-z0-9]*\z/) && !($portid eq $portname))
            {
              $extrarows .= "($portid) ";
            }
            $extrarows .= "on $machinename which is a $machinetype";
            $extrarows .=
              "</td>\n\t\t\t\t</tr>";

            $target_lines =~ s|</table>|\t$extrarows\n\t\t\t</table>|
          }
        }
      }
    }
  }

}


Most smart switches support lldp ( Link Layer Discovery Protocol ) which allows network devices to tell each other what they are connected to (which device and what port on that device). It is also possible to get lldp support on computers by installing software like lldpd ( http://vincentbernat.github.io/lldpd/ ) and configure lldpd to add lldp information to net-snmp. Once lldp information is served by snmp it can be extracted by this interface template file and give interface pages like this:
Image

In the above picture the switch named "knossos" knows that port g5 is connected to port eth0 of machine minotaur and that minotaur is running Slackware 13.1. Likewise, the interface page of eth0 on minotaur can show that it is connected to port g5 of switch knossos. This template file adds the row "Connected to:" if both devices support lldp and if the device with the interface provides lldp information with snmp.

Usually smart switches by default provide lldp information by snmp, you can try this with a command like:
snmpwalk -c public -v2c myswitch 1.0.8802.1.1.2.1

To get lldpd to provide lldp information by net-snmp lldp should be started with the switch "-x". Also, net-snmp should be configured to accept lldp information with the agentx subagent support and configured to provide that information. Lines like this are used in snmpd.conf:

To accept lldp information from lldpd:
Code:
master agentx


To provide lldp information
Code:
view    systemview    included   .1.0.8802.1.1.2


regards Henrik


Attachments:
File comment: screenshot of interface page with lldp information.
lldp_screenshot.png
lldp_screenshot.png [ 75.86 KiB | Viewed 11341 times ]
Top
 Profile Send private message  
 
PostPosted: Fri Aug 28, 2015 4:22 pm 
Offline
Site Admin

Joined: Tue Jul 29, 2003 11:42 am
Posts: 3039
Location: Auckland, New Zealand
This is a great idea - it should even be possible, with a little work, to add a routers.cgi*Link[] definition for each interface that points to the corresponding ports on the graphs for the attached device, if you stick to a naming scheme for the cfg files...

_________________
Steve Shipway
UNIX Systems, ITSS, University of Auckland, NZ
Woe unto them that rise up early in the morning... -- Isaiah 5:11


Top
 Profile Send private message  
 
PostPosted: Sat Sep 05, 2015 7:47 am 
Offline
Silver User

Joined: Thu Jan 26, 2012 11:32 am
Posts: 29
Location: Linköping, Sweden
stevesh wrote:
with a little work, to add a routers.cgi*Link[] definition for each interface that points to the corresponding ports on the graphs for the attached device, if you stick to a naming scheme for the cfg files...


I happen to have a naming scheme for the mrtg directory structure with all mrtg.cfg files. It simply looks like this:

balrog/mrtg.cfg
dd-wrt/mrtg.cfg
hugin/mrtg.cfg
igor/mrtg.cfg
knossos/mrtg.cfg
lj/mrtg.cfg
minotaur/mrtg.cfg
mugin/mrtg.cfg

...where the directory name is the name of the computer or the switch. Each directory also contains its own index.html and html pages for all interfaces and other stuff monitored by mrtg.

I haven't used routers.cgi*Link before, but looking at your example at http://www.steveshipway.org/software/rrd/doc/EXAMPLES it seems as it the idea would be:

routers.cgi*Link[switch1.1]: "Remote end of this P-t-P link" ../switch2/mrtg.cfg remote-router-target interface-sm.gif

What does "remote-router-target" mean? Is it the name of the target for the port on the other switch? Maybe named switch2.7 with my naming example above? Would such a link point to the page of that port? If so it would maybe not be that very useful as both ports probably would show the same traffic, only in opposite directions. My port pages does not have any links back to the index.html of their switch, instead I usually use the back button of the browser.

Such a link would be more useful if you could look at the index.html of a switch, click on a port which has a lot of traffic, click on a link to the port of the remote switch and then click to a link to the index.html of the remote switch to see where the traffic goes next.

regards Henrik


Top
 Profile Send private message  
 
PostPosted: Wed Sep 09, 2015 11:14 am 
Offline
Site Admin

Joined: Tue Jul 29, 2003 11:42 am
Posts: 3039
Location: Auckland, New Zealand
The remote-router-target is the identifier in the [] of the Target definition for the graph you want to link to, so in your example you could use 'switch2.7'. However, it does not HAVE to be the port at the other end of the link (which would of course show identical traffic). Instead, you could make it point to the CPU graph, or even to one of the metatargets such as _incoming, __first, __summary, __info or a userdefined graph (see the preferences page for a list of possible metatargets)

_________________
Steve Shipway
UNIX Systems, ITSS, University of Auckland, NZ
Woe unto them that rise up early in the morning... -- Isaiah 5:11


Top
 Profile Send private message  
 
PostPosted: Wed Sep 16, 2015 7:44 am 
Offline
Silver User

Joined: Thu Jan 26, 2012 11:32 am
Posts: 29
Location: Linköping, Sweden
I did look some more into this, but I think it would be hard to create links the right way from a template file using lldp information.

The problem is that the interface pages are named something like:

name_3.html

...where "name" is the name of the switch or the computer and "3" is the interface number. The problem is that for some, but not all switches, the interface number might match the port name given by lldp information (in the example above "3"), but some switches might alter the name slightly (like in my picture example "g5" instead of "5"). Also, computers usually name their interfaces completely different, something like "eth0" which might be interface 2 in mrtg. There are also other switches which name their interfaces completely different.

For now the template will only show some information about what is at the other end, there will be no links going to the other interface page.

regards Henrik


Top
 Profile Send private message  
 
PostPosted: Wed Jan 13, 2016 8:38 am 
Offline
Silver User

Joined: Thu Jan 26, 2012 11:32 am
Posts: 29
Location: Linköping, Sweden
As I have found LLDP very useful to automagically document how things are connected in a network I decided to patch cfgmaker to also accept
Code:
--ifdesc=lldp
.

As allways, this can be combined with other descriptions like
Code:
--ifdesc=lldp,alias


To get an attachment allowed here I had to zip my patch, extensions .patch or .diff were not allowed. Inside the zip file is the file lldp.patch which probably will apply cleanly against recent versions of cfgmaker. I used cfgmaker from latest stable MRTG 2.17.4 as a starting point myself, but before applying this lldp support I had already added support for HP Comware switches. For completeness I also include HPE_Comware.patch in the zip-file.

It would probably be a better idea to contribute patches like this to the mrtg-developers mailing list, but I am not a member there and in my experience any email address used to subscribe to and posting to mailing lists tend to get a lot of spam, even after unsubscribing from the mailing list. Also, I am not good at perl, this lldp patch is the result of a lot of trial and error until I got something that did what I wanted to the lldp info. Someone who knows perl would probably see a better way to code this.

I hope this patch will be useful for people and also that it somehow (maybe modified) might find its way into future releases of MRTG.

regards Henrik


Attachments:
File comment: Patch to add support for --ifdesc=lldp and also a patch to support HPE Comware switches.
patches.zip [2.16 KiB]
Downloaded 350 times
Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 12 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group