Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
    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".


In reply to Re: Cisco SNMP CDP Poll (humble suggestions) by ybiC
in thread Cisco SNMP CDP Poll by fingers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (17)
    As of 2014-08-01 13:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Who would be the most fun to work for?















      Results (19 votes), past polls