File: readsnmptest.pl

package info (click to toggle)
net-snmp 5.9.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 37,540 kB
  • sloc: ansic: 282,201; perl: 17,710; sh: 12,006; makefile: 2,712; python: 735; xml: 663; pascal: 62; sql: 47
file content (45 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download | duplicates (3)
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;