Well I like to run SNMP over tcp so i do this:
sub get_my_oid
{
my ($host, $oid, undef) = @_;
my $data = '';
my @errors = ();
my $options = " -l authPriv -u $User -X $Pass".
" -A $Pass -v 3 ".
" -t $Timeout -r $Retries -Ouvq ";
my $result = `snmpwalk $options TCP:${host} $oid`;
if(defined $result && (($? >> 8) == 0))
{
my @lines = split "\n", $result;
foreach my $oid_line (@lines)
{
$oid_line = substr $oid_line, 1; #front quote
chop $oid_line; #ending quote
#unescape all of my quotes. \" => "
$oid_line =~ s/\\\"/\"/og;
#it is a part of our data.
$data .= $oid_line;
}
}
else
{
push @errors,
"Error with the snmp walk command: $!\n";
return (undef, \@errors);
}
return ($data, undef);
}
Note that I actually use this code and it does work. BUT! Use at your own risk.
--habit
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.