Debian Codegraph @

perl/SNMP/t/readsnmptest.pl

raw
1 #!./perl
2
3 use strict;
4 use warnings;
5 use Cwd qw(getcwd);
6 use Exporter;
7
8 our @ISA = 'Exporter';
9 our @EXPORT_OK = qw($agent_host $agent_port $mibdir $snmpd_cmd $snmptrapd_cmd);
10 our ($agent_host, $agent_port, $mibdir, $snmpd_cmd, $snmptrapd_cmd);
11
12 if (open(CMD, "<../SNMP/t/snmptest.cmd")) {
13 while (my $line = <CMD>) {
14 if ($line =~ /HOST\s*=>\s*(.*?)\s+$/) {
15 $agent_host = $1;
16 } elsif ($line =~ /MIBDIR\s*=>\s*(.*?)\s+$/) {
17 $mibdir = $1;
18 } elsif ($line =~ /AGENT_PORT\s*=>\s*(.*?)\s+$/) {
19 $agent_port = $1;
20 } elsif ($line =~ /SNMPD\s*=>\s*(.*?)\s+$/) {
21 $snmpd_cmd = $1;
22 } elsif ($line =~ /SNMPTRAPD\s*=>\s*(.*?)\s+$/) {
23 $snmptrapd_cmd = $1;
24 }
25 } # end of while
26 close CMD;
27 } else {
28 die ("Could not start agent. Couldn't find snmptest.cmd file\n");
29 }
30
31 # On Windows %ENV changes only affect new processes but not the current
32 # process. Hence write the MIB dir into an snmp.conf file instead of setting
33 # $ENV{'MIBDIRS'}.
34 open(H, ">snmp.conf") or die "Failed to open snmp.conf: $!";
35 print H "mibdirs +$mibdir\n";
36 close(H);
37 # use SNMP;
38 # SNMP::register_debug_tokens("get_mib_directory");
39 # SNMP::register_debug_tokens("read_config");
40 use NetSNMP::default_store (':all');
41 netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_CONFIGURATION_DIR,
42 getcwd()) == 0 or
43 die "Failed to set configuration directory";
44
45 1;