Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Using the SNMP module from the Net-SNMP library

by Rhys (Pilgrim)
on Oct 04, 2004 at 13:26 UTC ( [id://396223]=perltutorial: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use SNMP;       # This is Net-SNMP.
    use Net::SNMP;  # This is NOT.  DO NOT USE WITH THIS TUTORIAL!
    
  2. or download this
    #!/usr/bin/perl
    use warnings;
    ...
    }
    
    exit;
    
  3. or download this
    &SNMP::addMibFiles("/path/to/some/file.mib");
    &SNMP::initMib();
    
  4. or download this
    # Where $destdir is /usr/share/snmp/mibs in most cases...
    system 
      "mkdir -p $destdir/JScan/everything ;
       cd $destdir/JScan/everything ;
       find .. -type f -exec ln -sf {} \\;";
    
  5. or download this
    # Add the search directory.
    &SNMP::addMibDirs("/usr/share/snmp/mibs/JScan/everything");
    ...
    
    # Wonder-Twin powers, ACTIVATE!
    &SNMP::initMib();
    
  6. or download this
    Cannot find module (THIS-AND-THAT): At line 1 in (none)
    
  7. or download this
    my $comm = 'ihavepower'; # Use read/write community.
    my $dest = '10.1.1.1';  # IP or DNS will work.
    ...
    if ( $sess->{ErrorNum} ) {
      print "Got $sess->{ErrorStr} setting $mib on $host.\n";
    }
    
  8. or download this
    my $comm = 'ihavepower'; # Use read/write community.
    my $dest = '10.1.1.1';  # IP or DNS will work.
    ...
    if ( $sess2->{ErrorNum} ) {
      print "Got $sess2->{ErrorStr} setting $mib on $host.\n";
    }
    
  9. or download this
    $MIB[0] = 'sysName';
    $MIB[1] = 'sysDescr';
    ...
                            [$MIB[1], 0],
                            [$MIB[2], 0]);
    @ANSWERS = $sess->get($vl);
    
  10. or download this
    @MIBS = ('sysName', 'sysDescr', 'sysLocation');
    foreach $mib ( @MIBS ) {
    ...
    # Now the magic!
    $vl = new SNMP::VarList(@bunchovbs);
    @ANSWERS = $sess->get($vl);
    
  11. or download this
    @MIBS = ('ifAdminStatus', 'ifOperStatus', 'ifSpeed');
    $vl = new SNMP::VarList([$MIBS[0]], [$MIBS[1]], [$MIBS[2]]);
    ...
      else next;
      print "  Link status is $STATUS[1].  Speed is $STATUS[2].\n";
    }
    
  12. or download this
    $sess->getbulk(<non-repeaters>, <max-repeaters>, <vars>)
      do an SNMP GETBULK, from the list of Varbinds, the single next lex-
    ...
      <non-repeaters>. For remaining Varbinds, the m lexico instances are
      retrieved each of the remaining Varbinds, where m is
      <max-repeaters>.
    
  13. or download this
    use SNMP;
    use Socket;
    ...
    for ( my $x = 0 ; $x <= $#INDEXES ; $x++ ) {
      print "  INDEX: $INDEXES[$x]  STATUS:  $STATUS[$x]\n";
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://396223]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-20 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found