--- snmpdx 2003/09/03 15:15:05 1.7
+++ snmpdx 2003/09/03 15:37:48 1.8
@@ -486,6 +486,7 @@
'tmpdir' => ($ENV{TMPDIR} || $ENV{TEMPDIR} || "/tmp"),
'get' => 0,
'next' => 0,
+ 'set' => 0,
'bindir' => "/cw/bin",
'probedir' => "$myroot/snmpdx.d",
'probename' => "*",
@@ -502,8 +503,9 @@
'V|version' => \$opt->{'version'},
'h|help' => \$opt->{'help'},
't|tmpdir=s' => \$opt->{'tmpdir'},
- 'g|get' => \$opt->{'get'}, # FIXME: still unused!
- 'n|next' => \$opt->{'next'}, # FIXME: still unused!
+ 'g|get' => \$opt->{'get'},
+ 'n|next' => \$opt->{'next'},
+ 's|set' => \$opt->{'set'},
'b|bindir=s' => \$opt->{'bindir'},
'P|probedir=s' => \$opt->{'probedir'},
'p|probename=s' => \$opt->{'probename'},
@@ -511,7 +513,7 @@
'm|mibname=s' => \$opt->{'mibname'},
'l|logfile=s' => \$opt->{'logfile'},
'L|loglevel=i' => \$opt->{'loglevel'},
- 's|strict' => \$opt->{'strict'},
+ 'S|strict' => \$opt->{'strict'},
);
Getopt::Long::Configure("bundling");
my $result = GetOptions(%options) || die "option parsing failed";
@@ -522,8 +524,9 @@
" -V,--version print program version\n" .
" -h,--help print out this usage page\n" .
" -t,--tmpdir=PATH filesystem path to temporary directory\n" .
- " -g,--get=MIBOID get value of this MIB OID\n" .
- " -n,--next=MIBOID get value of next MIB OID\n" .
+ " -g,--get get value of this MIB OID\n" .
+ " -n,--next get value of next MIB OID\n" .
+ " -s,--set set value of next MIB OID (NOT IMPLEMENTED)\n" .
" -b,--bindir=PATH path to the net-snmp binaries\n" .
" -P,--probedir=PATH path to probe directory\n" .
" -p,--probename=NAME the pattern for probes to load\n" .
@@ -531,7 +534,7 @@
" -m,--mibname=MIB the name of the MIB to act under\n" .
" -l,--logfile=PATH path to daemon logfile\n" .
" -L,--loglevel=NUM logging level (0...9)\n" .
- " -s,--strict strict processing of unknown values\n";
+ " -S,--strict strict processing of unknown values\n";
exit(0);
}
if ($opt->{'version'}) {
@@ -649,6 +652,12 @@
}
@{$oidtable} = sort(@{$oidtable});
+# determine run-time mode
+my $mode = "pass_persist";
+if ($opt->{'get'} or $opt->{'next'} or $opt->{'set'}) {
+ $mode = "pass";
+}
+
# connect I/O channels
my $stdin = new IO::Handle;;
$stdin->fdopen(fileno(STDIN), "r");
@@ -658,17 +667,28 @@
$stdout->autoflush(1);
open(STDERR, ">/dev/null");
-# daemon loop
+# processing loop
while (1) {
- # read next command from snmpd
- my $cmd = $stdin->getline;
- if (not defined($cmd)) {
- $ctx->{-log}->printf(4, "IO: EOF");
- last;
+ # determine command
+ my $cmd;
+ if ($mode eq "pass_persist") {
+ # read next command from snmpd
+ $cmd = $stdin->getline;
+ if (not defined($cmd)) {
+ $ctx->{-log}->printf(4, "IO: EOF");
+ last;
+ }
+ $cmd =~ s|\n?$||s;
+ $ctx->{-log}->printf(4, "IO: recv: << \"%s\\n\"", $cmd);
+ }
+ else {
+ $cmd = ($opt->{'get'} ? 'get' :
+ ($opt->{'next'} ? 'getnext' :
+ ($opt->{'set'} ? 'set' : 'unknown')));
+ $ctx->{-log}->printf(4, "CMD: \"%s\\n\"", $cmd);
}
- $cmd =~ s|\n?$||s;
- $ctx->{-log}->printf(4, "IO: recv: << \"%s\\n\"", $cmd);
+ # act upon command
if ($cmd =~ m/^PING$/i) {
#
# the PING/PONG protocol part
@@ -681,15 +701,21 @@
#
# the GET/GETNEXT protocol part
#
+ my $error = 1;
# read requested OID
- my $error = 1;
- my $oid_request = $stdin->getline;
- if (not defined($oid_request)) {
- $ctx->{-log}->printf(1, "ERROR: EOF instead of OID");
- goto ERROR;
+ my $oid_request;
+ if ($mode eq "pass") {
+ $oid_request = $ARGV[0];
+ }
+ else {
+ $oid_request = $stdin->getline;
+ if (not defined($oid_request)) {
+ $ctx->{-log}->printf(1, "ERROR: EOF instead of OID");
+ goto ERROR;
+ }
+ $oid_request =~ s|\n?$||s;
}
- $oid_request =~ s|\n?$||s;
$ctx->{-log}->printf(4, "IO: recv: << \"%s\\n\"", $oid_request);
if ($oid_request !~ m/^(\.\d+)+$/) {
$ctx->{-log}->printf(1, "ERROR: invalid query OID \"%s\"", $oid_request);
@@ -862,9 +888,28 @@
$error = 0;
if ($error) {
ERROR:
+ if ($mode eq "pass_persist") {
+ $ctx->{-log}->printf(4, "IO: send: >> \"NONE\\n\"");
+ $stdout->printf("NONE\n");
+ }
+ }
+ }
+ elsif ($cmd =~ m/^SET$/i) {
+ #
+ # the SET protocol part
+ #
+ if ($mode eq "pass_persist") {
+ # read requested OID/TYPE/VALUE (and ignore)
+ my $oid = $stdin->getline;
+ my $oid_type = $stdin->getline;
+ my $oid_value = $stdin->getline;
$ctx->{-log}->printf(4, "IO: send: >> \"NONE\\n\"");
$stdout->printf("NONE\n");
}
+ else {
+ $ctx->{-log}->printf(4, "IO: send: >> \"not-writable\\n\"");
+ $stdout->printf("not-writable\n");
+ }
}
else {
# for anything else (not expected) just send at least
@@ -872,6 +917,9 @@
$ctx->{-log}->printf(4, "IO: send: >> \"NONE\\n\"");
$stdout->printf("NONE\n");
}
+
+ # stop processing on "pass" mode
+ last if ($mode eq "pass");
}
# shutdown gracefully
|