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
|
#!./perl
use strict;
use warnings;
use Cwd qw(getcwd);
use Exporter;
our @ISA = 'Exporter';
our @EXPORT_OK = qw($agent_host $agent_port $mibdir $snmpd_cmd $snmptrapd_cmd);
our ($agent_host, $agent_port, $mibdir, $snmpd_cmd, $snmptrapd_cmd);
if (open(CMD, "<../SNMP/t/snmptest.cmd")) {
while (my $line = <CMD>) {
if ($line =~ /HOST\s*=>\s*(.*?)\s+$/) {
$agent_host = $1;
} elsif ($line =~ /MIBDIR\s*=>\s*(.*?)\s+$/) {
$mibdir = $1;
} elsif ($line =~ /AGENT_PORT\s*=>\s*(.*?)\s+$/) {
$agent_port = $1;
} elsif ($line =~ /SNMPD\s*=>\s*(.*?)\s+$/) {
$snmpd_cmd = $1;
} elsif ($line =~ /SNMPTRAPD\s*=>\s*(.*?)\s+$/) {
$snmptrapd_cmd = $1;
}
} # end of while
close CMD;
} else {
die ("Could not start agent. Couldn't find snmptest.cmd file\n");
}
# On Windows %ENV changes only affect new processes but not the current
# process. Hence write the MIB dir into an snmp.conf file instead of setting
# $ENV{'MIBDIRS'}.
open(H, ">snmp.conf") or die "Failed to open snmp.conf: $!";
print H "mibdirs +$mibdir\n";
close(H);
# use SNMP;
# SNMP::register_debug_tokens("get_mib_directory");
# SNMP::register_debug_tokens("read_config");
use NetSNMP::default_store (':all');
netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_CONFIGURATION_DIR,
getcwd()) == 0 or
die "Failed to set configuration directory";
1;
|