Re: [cricket-users] How do I get Switch Port Names?

From: Alan Nichols (Alan.Nichols@EBay.Sun.COM)
Date: Thu Sep 09 1999 - 16:24:24 PDT


Rose:

The attached code works under Cricket 0.67 (the last version that I have
tested it under).

Rather than patch this into Map.pm, I put at the top of collector
a "require 'mapping.pl';" line.

The main thing that changed between the earlier version and the current
version is some calls to Cricket internal functions.

Alan

>From: rose@gerf.org
>To: cricket-users@onelist.com
>Mailing-List: list cricket-users@onelist.com; contact
cricket-users-owner@onelist.com
>Delivered-To: mailing list cricket-users@onelist.com
>List-Unsubscribe: <mailto:cricket-users-unsubscribe@ONElist.com>
>Mime-Version: 1.0
>Content-Transfer-Encoding: 7bit
>Subject: [cricket-users] How do I get Switch Port Names?
>
>From: rose@gerf.org
>
>Hi all,
> I have been beating my head against the wall trying to figure out
>how to get switch interface names to show up somewhere, just like
>the router interface names pop up now.
>
> I looked through Alan Nicholas' stuff, and in there he tells you to modify
>common.pm, which no longer exists in cricket 0.70. So what exactly
>do I do to make the switch interface names come up?
>
> I did splice his code in with Map.pm instead of common.pm, and changed the
>other things he mentioned in the readme, but I only end up breaking things.
>
> Can someone tell me how to get switch instances to come up with the switch
>port name for something as standard as a Cisco 5500? I'd greatly appreciate
>it.
>
>Thanks again,
> Rose
>
>
-------------------------------------------------------------------------
Email: Alan.Nichols@Sun.COM Phone:(408)276-1306
Pager: Alan.Nichols@pager.ebay.sun.com or (650)940-0687
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/PA d- s:+ a- C++(++++)$ USC++++$ P++(+++)$ L>++++ E+(+++)$
W+(+++)$ N+$ o--- !K w--- O? M- V+ PS@ PE@ Y+>+++$ PGP?>+++ t+ !5 X+
R* tv b+++>++++ DI++++ D++ G e++ h--- r++ y+++
------END GEEK CODE BLOCK------


# netManagement: mapping.pl 1.2 07/01/99 16:12:05

my (%portmapping);

sub map_port {
    use SNMP_MIB;
    use SNMP_Simple;
    
    my($target) = @_;
    my $host = ConfigTree::Cache::expandString($target->{'snmp-host'}, $target);
    my $community = ConfigTree::Cache::expandString($target->{'snmp-community'}, $target);
    my $oids = $target->{'oids'};
    my $port = $target->{'port-name'};
    my $mapping = $portmapping{$host};

    if (!defined($mapping)) {
        Debug("Finding mapping for $host");
        $mapping = {};
        &SNMP_MIB::loadoids($oids, 'CISCO-STACK');
        my $session = SNMP_Simple->open($host, $community);
        my %portEntries = $session->snmpgettableka(2, 'portName',
                                                   'portIfIndex');
        my $portkey;
        foreach $portkey (keys %portEntries) {
            next if ($portEntries{$portkey}->{'portName'} eq "");
            $mapping->{$portEntries{$portkey}->{'portName'}} =
                $portEntries{$portkey}->{'portIfIndex'};
        }
        $portmapping{$host} = $mapping;

        #For some reason, this closes more than I expect. So don't do it. :-(
        #$session->close();
    }
 
    Debug("Mapping $host:$port -> $host:$mapping->{$port}");
    return $mapping->{$port} if (defined($mapping->{$port}));
    return 0;
}

my (%aliasmapping);

sub map_alias {
    use SNMP_MIB;
    use SNMP_Simple;

    my ($target) = @_;
    my $host = ConfigTree::Cache::expandString($target->{'snmp-host'}, $target);
    my $community = ConfigTree::Cache::expandString($target->{'snmp-community'}, $target);
    my $oids = $target->{'oids'};
    return 0 unless defined($target->{'if-alias'});
    my ($port, $junk) = split(' ', $target->{'if-alias'}, 2);
    my $mapping = $aliasmapping{$host};

    if (!defined($mapping)) {
        Debug("Finding mapping for $host");
        $mapping = {};
        &SNMP_MIB::loadoids($oids, 'IF');
        my $session = SNMP_Simple->open($host, $community);
        my %ifAlias = $session->snmpgettablean('ifAlias');

        my $interface;
        foreach $interface (sort { $a <=> $b } keys %ifAlias) {
            my ($alias, $rest) = split(' ', $ifAlias{$interface}, 2);
            next if (!defined($alias) || $alias eq "");
            my ($base, $unique) = split(/;/, $alias, 2);
            $unique = 1 if (!defined($unique) || $unique eq "");
            while (defined($mapping->{"$base;$unique"})) {
                $unique++;
            }
            $mapping->{"$base;$unique"} = $interface;
        }
        $aliasmapping{$host} = $mapping;

        #For some reason, this closes more than I expect. So don't do it. :-(
        #$session->close();
    }
    
    Debug("Mapping $host:$port -> $host:$mapping->{$port}");
    return $mapping->{$port} if (defined($mapping->{$port}));
    return 0;
}

1;



This archive was generated by hypermail 2b29 : Mon Mar 06 2000 - 19:01:02 PST