Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / perl / SNMP / t / startagent.pl
1 # common parameters used in SNMP::Session creation and tests
2 $agent_host = 'localhost';
3 $agent_port = 7000;
4 $trap_port = 8000;
5 $mibdir = '/usr/local/share/snmp/mibs';
6 $comm = 'v1_private';
7 $comm2 = 'v2c_private';
8 $comm3 = 'v3_private';
9 $sec_name = 'v3_user';
10 $oid = '.1.3.6.1.2.1.1.1';
11 $name = 'sysDescr';
12 $auth_pass = 'test_pass_auth';
13 $priv_pass = 'test_pass_priv';
14
15 # don't use any .conf files other than those specified.
16 $ENV{'SNMPCONFPATH'} |= "bogus";
17
18 # erroneous input to test failure cases
19 $bad_comm = 'BAD_COMMUNITY';
20 $bad_name = "badName";
21 $bad_oid = ".1.3.6.1.2.1.1.1.1.1.1";
22 $bad_host = 'bad.host.here';
23 $bad_port = '9999999';
24 $bad_auth_pass = 'bad_auth_pass';
25 $bad_priv_pass = 'bad_priv_pass';
26 $bad_sec_name = 'bad_sec_name';
27 $bad_version = 7;
28
29 local $snmpd_cmd;
30 local $snmptrapd_cmd;
31
32 my $line;
33
34 sub snmptest_cleanup {
35     sleep 1; # strangely we need to wait for pid files to appear ??
36     if ((-e "t/snmpd.pid") && (-r "t/snmpd.pid")) {
37         # Making sure that any running agents are killed.
38         # warn "killing snmpd:", `cat t/snmpd.pid`, "\n";
39         system "kill `cat t/snmpd.pid` > /dev/null 2>&1";
40         unlink "t/snmpd.pid";
41     }
42     if ((-e "t/snmptrapd.pid") && (-r "t/snmptrapd.pid")) {
43         # Making sure that any running agents are killed.
44         # warn "killing snmptrap:", `cat t/snmptrapd.pid`, "\n";
45         system "kill `cat t/snmptrapd.pid` > /dev/null 2>&1";
46         unlink "t/snmptrapd.pid";
47     }
48 }
49 snmptest_cleanup();
50 #Open the snmptest.cmd file and get the info
51 if (open(CMD, "<t/snmptest.cmd")) {
52   while ($line = <CMD>) {
53     if ($line =~ /HOST\s*=>\s*(\S+)/) {
54       $agent_host = $1;
55     } elsif ($line =~ /MIBDIR\s*=>\s*(\S+)/) {
56       $mibdir = $1;
57     } elsif ($line =~ /AGENT_PORT\s*=>\s*(\S+)/) {
58       $agent_port = $1;
59     } elsif ($line =~ /SNMPD\s*=>\s*(\S+)/) {
60       $snmpd_cmd = $1;
61     } elsif ($line =~ /SNMPTRAPD\s*=>\s*(\S+)/) {
62       $snmptrapd_cmd = $1;
63     }
64   } # end of while
65   close CMD;
66 } else {
67   die ("Could not start agent. Couldn't find snmptest.cmd file\n");
68 }
69
70 if ($^O !~ /win32/i) {
71   if ($snmpd_cmd) {
72     if (-r $snmpd_cmd and -x $snmpd_cmd) {
73 #      print STDERR "running: $snmpd_cmd -r -l t/snmptest.log -C -c t/snmptest.conf -P t/snmpd.pid $agent_port > /dev/null 2>&1\n";
74       system "$snmpd_cmd -r -l t/snmptest.log -C -c t/snmptest.conf -P t/snmpd.pid $agent_port > /dev/null 2>&1";
75     } else {
76       warn("Couldn't run snmpd\n");
77     }
78   }
79   if ($snmptrapd_cmd) {
80     if (-r $snmptrapd_cmd and -x $snmptrapd_cmd) {
81       system "$snmptrapd_cmd -u t/snmptrapd.pid -c t/snmptest.conf -C $trap_port > /dev/null 2>&1";
82     } else {
83       warn("Couldn't run snmptrapd\n");
84     }
85   }
86 }
87
88 1;
89