avoid usage MIB-files
I need a suggestion about this example snippet.
e.g. How I can use with trap receiver without MIB-files? I want to do this because files would have so much dependency's , therefore I seeing it in another way, i.e just define necessary OID value into my script and use it.
use strict;
use vars qw();
use SNMP qw();
&SNMP::initMib();
&SNMP::loadModules(
'RFC2127-MIB',
);
sub trap_call_setup;
sub trap_dummy;
my %dispatch_table = (
'isdnMibCallInformation', \&trap_call_setup,
'.', \&trap_dummy,
);
sub trap_dispatcher
{
my $session = shift;
my $ref = shift;
my $trapType;
my ($reqid, $addr, $community);
# if this is a timeout, then there will be no args...
if (defined($ref)) {
$ref->[1]->[2] = SNMP::translateObj($ref->[1]->val);
$trapType = $ref->[1]->val;
my $args = shift;
($reqid, $addr, $community) = @{$args};
} else {
$trapType = 'timeout';
}
if (defined($dispatch_table{$trapType})) {
&{$dispatch_table{$trapType}}($session, $ref);
} elsif (defined($dispatch_table{'.'})) {
&{$dispatch_table{'.'}}($session, $ref);
} else {
# don't do anything... silently discard.
}
}
sub trap_dummy
{
my $session = shift;
my $ref = shift;
my $trapType = $ref->[1]->val;
warn "unexpected trap " . $trapType;
}
sub trap_call_setup
{
my $session = shift;
my $varlist = shift;
my $args = shift;
my $ifIndex = $varlist->[2]->val;
my $isdnBearerOperStatus = $varlist->[3]->val;
my $isdnBearerPeerAddress = $varlist->[4]->val;
my $isdnBearerPeerSubAddress = $varlist->[5]->val;
my $isdnBearerInfoType = $varlist->[6]->val;
my $isdnBearerCallOrigin = $varlist->[5]->val;
my ($reqid, $ipaddr, $community) = @{$args};
printf "Call from %s", $isdnBearerPeerAddress;
printf "*%s", $isdnBearerPeerSubAddress if ($isdnBearerPeerSubAddres
+s ne '');
printf "\n";
}
my $session = new SNMP::Session(
DestHost => 'udp:162',
LocalPort => 1,
Version => '2c',
UseEnums => 0,
);
if (!defined($session)) {
die "can't create listener session";
}
$session->SNMP::_catch([\&trap_dispatcher, $session]);
&SNMP::MainLoop();
In reply to snmp-trap
by gants
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.