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
|
#!./perl
use strict;
use warnings;
BEGIN {
eval "use Cwd qw(abs_path)";
}
use Test;
BEGIN { plan tests => 5}
use SNMP;
require "t/startagent.pl";
use vars qw($agent_host $agent_port $auth_pass $bad_auth_pass $bad_priv_pass
$bad_sec_name $bad_version $comm $priv_pass $sec_name);
$SNMP::debugging = 0;
# create list of varbinds for GETS, val field can be null or omitted
my $vars = new SNMP::VarList (
['sysDescr', '0', ''],
['sysContact', '0'],
['sysName', '0'],
['sysLocation', '0'],
['sysServices', '0'],
['ifNumber', '0'],
['ifDescr', '1'],
['ifSpeed', '1'],
);
#########################== 1 ===#########################################
# Create a bogus session, undef means the host can't be found.
# removed! this test can hang for a long time if DNS is not functioning
# my $s1 = new SNMP::Session (DestHost => $bad_host );
# ok(!defined($s1));
#print("\n");
#####################== 2 ====############################################
# Fire up a session.
my $s2 =
new SNMP::Session (DestHost=>$agent_host, Community=>$comm,
RemotePort=>$agent_port);
ok(defined($s2));
######################== 3 ==== ##########################################
# Fire up a V3 session
my $s3 = new SNMP::Session (Version => 3 , RemotePort => $agent_port,
SecName => $sec_name );
ok(defined($s3));
#print STDERR "Error string1 = $s3->{ErrorStr}:$s3->{ErrorInd}\n";
#print("\n");
#####################=== 4 ====###########################################
#create a V3 session with an IP address/port not running an agent
my $s4 = new SNMP::Session (Version => 3, RemotePort => 1002, Retries => 0);
ok(defined($s4));
#print STDERR "Error string1 = $s4->{ErrorStr}:$s4->{ErrorInd}\n";
#print("\n");
###################### 5 ###########################################
#create a session with bad version
my $s5 = new SNMP::Session (Version=>$bad_version);
ok(!defined($s5));
#print("\n");
######################## 6 ########################################
#Test for v3 session creation success
my $s6 = new SNMP::Session (Version => 3, RemotePort => $agent_port,
SecLevel => 'authPriv',
SecName => $sec_name,
PrivPass => $priv_pass,
AuthPass => $auth_pass);
ok(defined($s6));
#print STDERR "Error string2 = $s6->{ErrorStr}:$s6->{ErrorInd}\n";
#print("\n");
##################### 7 ############################################
snmptest_cleanup();
|