Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / perl / SNMP / t / notify.t
1 #!./perl
2
3 BEGIN {
4     unless(grep /blib/, @INC) {
5         chdir 't' if -d 't';
6         @INC = '../lib' if -d '../lib';
7     }
8 }
9 use Test;
10 BEGIN { $n = 10; plan tests => $n }
11 use SNMP;
12 use vars qw($agent_port $comm $comm2 $trap_port $agent_host $sec_name $priv_pass $auth_pass $bad_name);
13 require 't/startagent.pl';
14 $SNMP::debugging = 0;
15
16 my $res;
17 my $enterprise = '.1.3.6.1.2.1.1.1.0';
18 my $generic = 'specific';
19
20 #                         V1 trap testing
21 ######################  1  #############################
22 # Fire up a trap session.
23 my $s1 =
24     new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$trap_port);
25 ok(defined($s1));
26
27 ##########################  2  ####################################
28 # test v1 trap
29 $res = $s1->trap(enterprise => $enterprise, agent=>$agent_host, generic=>$generic,[[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
30 ok($res =~ /^0 but true/);
31
32 ########################### 3 #############################
33 # test with wrong varbind
34 $res = $s1->trap([[$bad_name, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
35 #print("res is $res\n");
36 ok(!defined($res));
37 #########################################################
38
39 #                      V2 testing
40 ########################## 4 ############################
41 # Fire up a v2 trap session.
42 my $s2 =
43     new SNMP::Session (Version=>2, DestHost=>$agent_host,Community=>$comm2,RemotePort=>$trap_port);
44 ok(defined($s2));
45 #########################  5  ###########################
46 # test v2 trap
47 $res = $s2->trap(uptime=>200, trapoid=>'coldStart',[[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
48 #print("res is $res\n");
49 ok($res =~ /^0 but true/);
50 ##########################  6  ##########################
51 # no trapoid and uptime given. Should take defaults...
52 my $ret = $s2->trap([[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
53 #print("res is $ret\n");
54 ok(defined($ret));
55
56 #########################################################
57
58 #                     v3 testing
59 ########################  7  ############################
60 # Fire up a v3 trap session.
61 my $s3 = new SNMP::Session(Version=>3, DestHost=> $agent_host, RemotePort=>$trap_port, SecName => $sec_name);
62 ok(defined($s3));
63
64 ########################  8  ###########################
65 $res = $s3->inform(uptime=>111, trapoid=>'coldStart', [[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
66 ok($res =~ /^0 but true/);
67
68 #################### 9 #####################
69 # Fire up a v3 trap session.
70 $s3 = new SNMP::Session(Version=>3, DestHost=> $agent_host, RemotePort=>$trap_port, SecName => $sec_name, SecLevel => authPriv, AuthPass => $auth_pass, PrivPass => $priv_pass);
71 ok(defined($s3));
72
73 ########################  10  ###########################
74 $res = $s3->inform(uptime=>111, trapoid=>'coldStart', [[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] );
75 print "res = $res\n";
76 ok($res =~ /^0 but true/);
77
78     snmptest_cleanup();