Leser: 1
8 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
my $if_state = new SNMP::VarList(
["local.2.1.1.28"],
["ifName"]); # .1.3.6.1.2.1.31.1.1.1.1
do {
my ($desc1,$short) = $session->getnext($if_state);
$index++;
print "DESC: $desc1\n";
# no response is bad community or dead daemon or other failure...
if ($session->{ErrorNum}) {
next if ($session->{ErrorNum}==2);
$counter++;
push @$longerr, "$host no session: $session->{ErrorStr}\n";
}
my $if_state = new SNMP::VarList(["1.3.6.1.4.1.9.2.2.1.1.28"]);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
#use strict;
use SNMP;
use Getopt::Long;
# Nagios specific
#use lib "/opt/nagios/libexec";
#use utils qw(%ERRORS $TIMEOUT);
# prototype
sub checkInterfaces($$$$$$);
$host="cisco-router";
$community = $o_community || "pubic";
$version = $o_version || "1";
$timeout = $o_timeout || "10000000";
$retries = $o_retries || "10";
# create session
($session, $error) = new SNMP::Session(
DestHost => $host,
Community => $community,
Version => $version,
Timeout => $timeout,
Retries => $retries);
# if session does not exist ... exit
if (!defined($session)) {
print "ERROR opening session\n";
exit $ERRORS{"UNKNOWN"};
}
# get Number of Interfaces on this Host
$ifcount = $session->get(["ifNumber",0]);
# get sysDescr field and check if device is a 375x l3-switch
#my $sysdescr = $session->get(["sysDescr",0]);
$num_o_errors = checkInterfaces(0, $ifcount, $session, $version, \@longerr, $host);
sub checkInterfaces($$$$$$) {
my($index, $ifcount, $border, $version, $session, $host, $longerr, $not_to_search);
$index = $_[0];
$ifcount = $_[1];
$session= $_[2];
$version = $_[3];
$longerr = $_[4];
$host = $_[5];
my %admin_states = ((my $admin_state_ok=1)=>"adminUp",
2=>"adminDown",
3=>"adminTest");
my %oper_states = ((my $oper_state_ok=1)=>"up",
2=>"down",
3=>"testing",
4=>"unknown",
5=>"sleeping");
my $counter = 0;
my $if_state = new SNMP::VarList(
["ifDescr"],
["ifAdminStatus"],
["ifOperStatus"],
["ifAlias"], # .1.3.6.1.2.1.31.1.1.1.18
["ifName"]); # .1.3.6.1.2.1.31.1.1.1.1
my $desc;
my $desc2 = undef;
do {
my ($name,$admin,$oper,$desc1,$short) = $session->getnext($if_state);
$index++;
$desc = $desc1?$desc1:$desc2?$desc2:"N/A";
$short = $name if (!$short);
if ($session->{ErrorNum}) {
next if ($session->{ErrorNum}==2);
$counter++;
push @$longerr, "$host no session: $session->{ErrorStr}";
#last;
}
print "Name: $name, Admin-State: $admin, Oper-State: $oper, Desc: $desc, Shotname: $short\n";
} while ($index <= $ifcount-1); # -1 to get rid of last...unused...element
return $counter;
}
1
2
3
4
$ snmpwalk -v 2c -c community host 1.3.6.1.4.1.9.2.2.1.1.28
SNMPv2-SMI::enterprises.9.2.2.1.1.28.1 = ""
SNMPv2-SMI::enterprises.9.2.2.1.1.28.2 = ""
SNMPv2-SMI::enterprises.9.2.2.1.1.28.3 = ""
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#! /usr/local/bin/perl use strict; use lib '/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi/auto'; use Net::SNMP; my ($session, $error) = Net::SNMP->session( -version => 'snmpv2c', -hostname => shift || 'localhost', -community => shift || 'public', -port => shift || 161 ); if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; } my $oid = '1.3.6.1.4.1.9.2.2.1.1.28.1'; my $result = $session->get_request( -varbindlist => [ $oid ] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("oid '%s' -> '%s'\n", $oid, $result->{$oid} ); $session->close; exit 0;
8 Einträge, 1 Seite |