I gave this a bash and found several funnies. Firstly I dont know what mib you are using so I tested with MIB2 and used system uptime. (I.e. .1.3.6.1.2.1.1.3.0)

Line 13 and 14 seem unnecessary as you are checking if $session1 is defined earlier in line 8 and 9.

I added a print after the $ifDescr and found that it was giving me the correct uptime for my machine. I then changed line 27 $trapvars[5] = $result->{$ifDescr}; to $trapvars[5] = $ifDescr; add instead of getting the HASH stuff I was getting the correct uptime.

Bellow is my code and a few formatting adjustments for my readability.

#!/usr/bin/perl use strict; use warnings; use Net::SNMP; my $NodeAddress = 'localhost'; my $ReadCommunity = 'public'; my ($session1, @trapvars, $error) = Net::SNMP->session( -hostname => $ +NodeAddress, -community => $ReadCommunity); if (!defined($session1)){ printf("ERROR: %s.\n", $error); exit 1; } #my $ifAlias = '.1.3.6.1.2.1.31.1.1.1.18.110'; my $ifAlias = '.1.3.6.1.2.1.1.3.0'; my $result = $session1->get_request($ifAlias); if (!defined($session1)){ printf("ERROR: %s.\n", $error); exit 1; } print "Result = $result\n"; my $ifDescr = $result->{$ifAlias}; print "ifDescr = $ifDescr\n"; my ($session2) = Net::SNMP->session( -hostname => 'localhost', -port => '162', -community => 'public'); if (!defined($session2)){ printf("ERROR: %s.'n", $error); exit 1; } $trapvars[0] = ".1.3.6.1.4.1.78.0.100147"; $trapvars[1] = OCTET_STRING; $trapvars[2] = 'IFName'; $trapvars[3] = ".1.3.6.1.4.1.78.0.100147"; $trapvars[4] = OCTET_STRING; $trapvars[5] = $ifDescr; print "Array = @trapvars\n"; $session2->trap( -enterprise => '1.3.6.1.4.1.78', -agentaddr => $NodeAddress, -generictrap => '6', -specifictrap => '100147', -varbindlist => \@trapvars); if (!defined($session2)){ printf("ERROR: %s.\n", $error); exit 1; } $session1->close; $session2->close;
-----
Of all the things I've lost in my life, its my mind I miss the most.

In reply to Re: SNMP Get and Trap by AcidHawk
in thread SNMP Get and Trap by CongoGrey

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!
  • 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:
    & &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.