| 1 |
#!./perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
BEGIN { |
| 7 |
eval "use Cwd qw(abs_path)"; |
| 8 |
} |
| 9 |
|
| 10 |
use Test; |
| 11 |
BEGIN { plan tests => 9 } |
| 12 |
use SNMP; |
| 13 |
require "t/startagent.pl"; |
| 14 |
use vars qw($agent_host $agent_port $comm); |
| 15 |
|
| 16 |
|
| 17 |
my $junk_oid = ".1.3.6.1.2.1.1.1.1.1.1"; |
| 18 |
my $oid = '.1.3.6.1.2.1.1.1'; |
| 19 |
my $junk_name = 'fooDescr'; |
| 20 |
my $junk_host = 'no.host.here'; |
| 21 |
my $name = "gmarzot\@nortelnetworks.com"; |
| 22 |
|
| 23 |
$SNMP::debugging = 0; |
| 24 |
|
| 25 |
# create list of varbinds for GETS, val field can be null or omitted |
| 26 |
my $vars = new SNMP::VarList ( |
| 27 |
['sysDescr', '0', ''], |
| 28 |
['sysContact', '0'], |
| 29 |
['sysName', '0'], |
| 30 |
['sysLocation', '0'], |
| 31 |
['sysServices', '0'], |
| 32 |
['ifNumber', '0'], |
| 33 |
['ifDescr', '1'], |
| 34 |
['ifSpeed', '1'], |
| 35 |
); |
| 36 |
|
| 37 |
|
| 38 |
############################## 1 ##################################### |
| 39 |
# Fire up a session. |
| 40 |
my $s1 = |
| 41 |
new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$agent_port); |
| 42 |
ok(defined($s1)); |
| 43 |
|
| 44 |
############################# 2 ####################################### |
| 45 |
# Try getnext on sysDescr.0 |
| 46 |
|
| 47 |
my $next = $s1->getnext('sysDescr.0'); |
| 48 |
#print ("The next OID is : $next\n"); |
| 49 |
ok($s1->{ErrorStr} eq ''); |
| 50 |
#print STDERR "Error string1 = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; |
| 51 |
#print("\n"); |
| 52 |
|
| 53 |
########################### 3 ######################################## |
| 54 |
#$v1 = $s1->getnext('sysLocation.0'); |
| 55 |
#print ("The next OID is : $v1\n"); |
| 56 |
my $v2 = $s1->getnext('sysServices.0'); |
| 57 |
#print ("The next OID is : $v2\n"); |
| 58 |
ok($s1->{ErrorStr} eq ''); |
| 59 |
#print STDERR "Error string2 = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; |
| 60 |
#print("\n"); |
| 61 |
|
| 62 |
|
| 63 |
############################ 4 ####################################### |
| 64 |
# try it on an unknown OID |
| 65 |
my $v3 = $s1->getnext('Srivathsan.0'); |
| 66 |
#print ("The unknown OID is : $v3\n"); |
| 67 |
ok($s1->{ErrorStr} =~ /^Unknown/); |
| 68 |
#print STDERR "Error string5 = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; |
| 69 |
#print("\n"); |
| 70 |
############################# 5 ####################################### |
| 71 |
# On a non-accessible value |
| 72 |
#my $kkk = $s1->getnext('vacmSecurityName.1'); |
| 73 |
#print("kkk is $kkk\n"); |
| 74 |
#ok($s1->{ErrorInd} != 0); |
| 75 |
#print STDERR "Error string5 = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; |
| 76 |
#print("\n"); |
| 77 |
|
| 78 |
############################# 6 #################################### |
| 79 |
# We should get back sysDescr.0 here. |
| 80 |
my $var = new SNMP::Varbind(['sysDescr']); |
| 81 |
my $res2 = $s1->getnext($var); |
| 82 |
#print("res2 is : $res2\n"); |
| 83 |
ok((not $s1->{ErrorStr} and not $s1->{ErrorInd})); |
| 84 |
ok((defined $var->iid and $var->iid eq 0)); |
| 85 |
ok((defined $var->val and $var->val eq $res2)); |
| 86 |
|
| 87 |
############################# 7 ###################################### |
| 88 |
# get the next one after that as well for a second check |
| 89 |
my $res3 = $s1->getnext($var); |
| 90 |
#print("res3 is : $res3\n"); |
| 91 |
ok((defined $var->tag and $var->tag eq 'sysObjectID')); |
| 92 |
ok((defined $var->val and $var->val eq $res3)); |
| 93 |
|
| 94 |
|
| 95 |
snmptest_cleanup(); |