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

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found