Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Cisco SNMP CDP Poll (humble suggestions)

by ybiC (Prior)
on May 17, 2001 at 02:14 UTC ( [id://81105]=note: print w/replies, xml ) Need Help??


in reply to Cisco SNMP CDP Poll

    Hi fingers,
Since you asked, here's my thoughts on Cisco SNMP CDP Poll.   Keep in mind that IANAJAPH, so Wiser Monks Than ITM may tell you I'm fullabeans {grin}

First off - I like it, and will tweak it for use instead of some of my own Net::Telnet::Cisco-based scripts for query-only operations.   Net::Snmp++

use strict; is your friend, despite sounding rather stern 8^)

pod is also your friend. To my eye, that many embedded comments reduce readability

Use subroutines only for modular functionality (cdp-neighbor, port count, model, etc.)   A wise monk recently advised me to think of subroutines as mini-programs instead of chapters in a book.   Reduces unecessary global variables, and offers potential for improved readability.

Assign variable names to $_[0] and $_[1], etc early in subroutine.   Improved readability??   references?

Combine into chomp($community = <STDIN>);

die "usage: $0 seedip" unless ( $seedhost =~ m{\d+\.\d+\.\d+\.\d+} )   Improved readability??

die "usage: $0 seedip" unless ( @ARGV == 1 )   Improved readability??

Use a CPAN module to parse IP address for legality.   m/\d{1,3}.\d{1,3}.\d{1,3},\d{1,3}/ would be small improvement, checking for 1-to3-digit numbers.

Mixed-case subroutine names for clarity.   There are a few links to relevant posts on my homenode, near the middle in the "educate" section.

++fingers for verbish subroutine names.

    cheers,
    Don
    striving toward Perl Adept
    (it's pronounced "why-bick")

Update 2001-05-17   19:45

The following adds a configurable delay:
my $delay = '2'; near head of script along with other variable declarations, and
sleep($delay); in get_oids() just after write;

Save results to an output file:
my $outfile = 'cdppoll.out'; near head of script along with other variable declarations
open (OUTFILE, ">$outfile") or die"Error opening $outfile WO:$!"; between "chomp" and "@todo"
format OUTFILE = (same as format STDOUT) right after "format STDOUT"
close OUTFILE or die"Error closing $outfile:$!"; right after above "format OUTFILE"

Use x operator to simplify code line for visual output divider, and reduce code width.
print "\n", '=' x 94, "\n";

I don't have these coded yet, but could be good to:

  • csv outfile for easy manipulation and importing
  • generate summarized outfile listing only unique devices
  • check hostname (in addition to IP address) for 'already done'.   Avoid discovering same router twice if redundant paths.
  • use Term::ReadKey for no-echo entry of SNMP community string.
  • use hash(es) to reduce number of global variables:   my %oid; $oid{root}, $oid{starting}, $oid{new} instead of $oid_root, $oid_starting, $oid_new

Update 2001-05-17   20:45
"multiple devices w/same hostname..."   Ah, I hadn't thought of that. How about an SNMP query for *all* interface addresses then add device to list only if no match?   I've not given any thought to the logic, just searching for an easy identifier of "unique".

Replies are listed 'Best First'.
Re:Re: Cisco SNMP CDP Poll (Hostnames may not be unique)
by fingers (Acolyte) on May 18, 2001 at 05:29 UTC
    check hostname (in addition to IP address) for 'already done'.Avoid discovering same router twice if redundant paths

    I had initally given some thought to the fact that many routers may get discovered multiple times, because they by their nature have multiple IPs.

    The problem I have with checking by hostname is that it is entirely possible to have multiple devices with the same hostname, (ok - I guess using IPs reserved for private networks it would be possible to have the same IP on multiple devices, but the box you're running the script off of wouldn't be able to have a route to more than one of them at a time).

    I am considering using serial numbers as my second key to verify uniqueness, however the OID for serial numbers appears to vary from device to device.

    Checking the serial number would still entail opening an SNMP session, but at least your output would be a little less redundant.

    Well off I go to find more usefull OIDs ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://81105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found