| 1 |
#!./perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
BEGIN { |
| 7 |
eval "use Cwd qw(abs_path)"; |
| 8 |
} |
| 9 |
use Test; |
| 10 |
BEGIN { plan tests => 5} |
| 11 |
use SNMP; |
| 12 |
require "t/startagent.pl"; |
| 13 |
use vars qw($agent_host $agent_port $auth_pass $bad_auth_pass $bad_priv_pass |
| 14 |
$bad_sec_name $bad_version $comm $priv_pass $sec_name); |
| 15 |
|
| 16 |
$SNMP::debugging = 0; |
| 17 |
|
| 18 |
# create list of varbinds for GETS, val field can be null or omitted |
| 19 |
my $vars = new SNMP::VarList ( |
| 20 |
['sysDescr', '0', ''], |
| 21 |
['sysContact', '0'], |
| 22 |
['sysName', '0'], |
| 23 |
['sysLocation', '0'], |
| 24 |
['sysServices', '0'], |
| 25 |
['ifNumber', '0'], |
| 26 |
['ifDescr', '1'], |
| 27 |
['ifSpeed', '1'], |
| 28 |
); |
| 29 |
|
| 30 |
#########################== 1 ===######################################### |
| 31 |
# Create a bogus session, undef means the host can't be found. |
| 32 |
# removed! this test can hang for a long time if DNS is not functioning |
| 33 |
# my $s1 = new SNMP::Session (DestHost => $bad_host ); |
| 34 |
# ok(!defined($s1)); |
| 35 |
#print("\n"); |
| 36 |
#####################== 2 ====############################################ |
| 37 |
# Fire up a session. |
| 38 |
my $s2 = |
| 39 |
new SNMP::Session (DestHost=>$agent_host, Community=>$comm, |
| 40 |
RemotePort=>$agent_port); |
| 41 |
ok(defined($s2)); |
| 42 |
######################== 3 ==== ########################################## |
| 43 |
|
| 44 |
# Fire up a V3 session |
| 45 |
my $s3 = new SNMP::Session (Version => 3 , RemotePort => $agent_port, |
| 46 |
SecName => $sec_name ); |
| 47 |
ok(defined($s3)); |
| 48 |
#print STDERR "Error string1 = $s3->{ErrorStr}:$s3->{ErrorInd}\n"; |
| 49 |
#print("\n"); |
| 50 |
#####################=== 4 ====########################################### |
| 51 |
#create a V3 session with an IP address/port not running an agent |
| 52 |
my $s4 = new SNMP::Session (Version => 3, RemotePort => 1002, Retries => 0); |
| 53 |
ok(defined($s4)); |
| 54 |
#print STDERR "Error string1 = $s4->{ErrorStr}:$s4->{ErrorInd}\n"; |
| 55 |
#print("\n"); |
| 56 |
###################### 5 ########################################### |
| 57 |
#create a session with bad version |
| 58 |
my $s5 = new SNMP::Session (Version=>$bad_version); |
| 59 |
ok(!defined($s5)); |
| 60 |
#print("\n"); |
| 61 |
######################## 6 ######################################## |
| 62 |
#Test for v3 session creation success |
| 63 |
my $s6 = new SNMP::Session (Version => 3, RemotePort => $agent_port, |
| 64 |
SecLevel => 'authPriv', |
| 65 |
SecName => $sec_name, |
| 66 |
PrivPass => $priv_pass, |
| 67 |
AuthPass => $auth_pass); |
| 68 |
ok(defined($s6)); |
| 69 |
#print STDERR "Error string2 = $s6->{ErrorStr}:$s6->{ErrorInd}\n"; |
| 70 |
#print("\n"); |
| 71 |
##################### 7 ############################################ |
| 72 |
|
| 73 |
snmptest_cleanup(); |