Difference between revisions of "Net: : SNMP eksempel"

From Teknologisk videncenter
Jump to: navigation, search
m (Eksempel)
m
 
(One intermediate revision by the same user not shown)
Line 75: Line 75:
  
  
[[Category:Perl]]
+
[[Category:Perl]][[Category:Network Management]]

Latest revision as of 09:18, 1 April 2010

Installation af Net:SNMP modul

Net::SNMP kræver pakken Crypt::DES

Visse pakker fx mange krypteringspakker kan normalt kun downloades fra USA til maskiner i USA. (Lovgivning i USA)

Derfor tilføjer vi bare en server som ikke står i USA i PPM søgelisten

Eksempel

#!/usr/bin/perl
#######################################
# Author: Henrik Thomsen / Mercantec  #
# Email.: heth@mercantec.dk           #
#######################################
#
### Pragma's
use strict;
use warnings;
#use diagnostics; # Only for debugging purposes.
### Module's
use Net::SNMP qw(:snmp);

my @devices = ('192.168.22.201','192.168.22.202');

my $ifTable = '1.3.6.1.2.1.2.2.1.2';
              

foreach my $device (@devices) {
my ($session, $error) = Net::SNMP->session(
			 -hostname => $device,
             -version  => '2c', );

  if (!defined($session)) {
    printf("Kan ikke åbne session til $device fejl: $error\n");
    next;
  }
  print "Henter interfaces fra $device\n";
  print "=============================\n";

  my $result = $session->get_next_request(
  		-varbindlist => [$ifTable] );
  my ($key,$value);
  my $lastkey;

  while (defined($result) ) {
    while ( ($key,$value) = each %{$result} ) {
      if ( !oid_base_match($ifTable, $key)) {
        $session->close;
        undef $result;
        last;
      }
     print "  OID: $key = $value\n";
     $lastkey=$key;
    }
    $result = $session->get_next_request( -varbindlist => [$lastkey] );
    print "-->";
  }
}

Opgave

  • 192.168.22.201 RO Community public
  • 192.168.22.202 RO Community public
  • 192.168.22.254 RO Community public
  • 192.168.22.221 RO Community public