How to return error message using pass-persist!

"quhp" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Organization ict
Message-ID <[email protected]>
Hello everyone,

   I am developing some MIB handlers using pass_persist perl script. I try
the example(local/pass_persist) provided in your packege(version
5.2.1), and encounted some problems. The example is as following:

#!/usr/bin/perl

# Persistant perl script to respond to pass-through smnp requests

# put the following in your snmpd.conf file to call this script:
#
# pass_persist .1.3.6.1.4.1.2021.255 /path/to/pass_persisttest

# Forces a buffer flush after every echo
$|=1;

use strict;

my $counter = 0;
my $place = ".1.3.6.1.4.1.2021.255";

while (<>){
  if (m!^PING!){
    print "PONG\n";
    next;
  }
  my $cmd = $_;
  my $req = <>;
  my $ret;
  chomp($cmd);
  chomp($req);

  if ( $cmd eq "set" ) {            # i add
	print "wrong-type\n";       # these lines
	next;                       # to try
  }                                 # how to handle set command

  if ( $cmd eq "getnext" ) {
    if ($req eq $place) {
      $ret = "$place.1";
    } elsif ($req eq "$place.1") {
      $ret = "$place.2.1";
    } elsif ($req eq "$place.2.1") {
      $ret = "$place.2.2";
    } elsif ($req eq "$place.2.2") {
      $ret = "$place.3";
    } elsif ($req eq "$place.3") {
      $ret = "$place.4";
    } elsif ($req eq "$place.4") {
      $ret = "$place.5";
    } elsif ($req eq "$place.5") {
      $ret = "$place.6";
    } else {
      print "NONE\n";
      next;
    }
  } else {
    if ($req eq $place) {
      print "NONE\n";
      next;
    } else {
      $ret = $req;
    }
  }

  print "$ret\n";

  if ($ret eq "$place.1") {
    print "string\nlife the universe and everything\n";
  } elsif ($ret eq "$place.2.1") {
    print "integer\n423\n";
  } elsif ($ret eq "$place.2.2") {
    print "objectid\n.1.3.6.1.4.42.42.42\n";
  } elsif ($ret eq "$place.3") {
    print "timeticks\n363136200\n";
  } elsif ($ret eq "$place.4") {
    print "ipaddress\n127.0.0.1\n";
  } elsif ($ret eq "$place.5") {
    $counter++;
    print "counter\n$counter\n";
  } elsif ($ret eq "$place.6") {
    print "gauge\n42\n";
  } else {
    print "string\nack... $ret $req\n";
  }
}

When i run the command as following:
[root@localhost snmp]# snmpset -v 2c -c private localhost
1.3.6.1.4.1.2021.255.1.1 i 5

I expect to get output something like:

Error in packet.
Reason: wrongType (The set datatype does not match the data type the agent
expects)

But in fact, the output is:
UCD-SNMP-MIB::ucdavis.255.1.1 = INTEGER: 5

In addition, when i run the command a second time, the process running the
pass_persist script will exit. It seems that such a script aren't
"persist" as it was called :)

So, my questions are:
1)how to write script to handle snmp set command;
2)how to let such scripts to return correct error message.


PS:
If we resive the script as following:

#!/usr/bin/perl

# Persistant perl script to respond to pass-through smnp requests

# put the following in your snmpd.conf file to call this script:
#
# pass_persist .1.3.6.1.4.1.2021.255 /path/to/pass_persisttest

# Forces a buffer flush after every echo
$|=1;

use strict;

my $counter = 0;
my $place = ".1.3.6.1.4.1.2021.255";

while (<>){
  if (m!^PING!){
    print "PONG\n";
    next;
  }
  my $cmd = $_;
  my $req = <>;
  my $ret;
  chomp($cmd);
  chomp($req);

  if ( $cmd eq "set" ) {            # i add
	print "wrong-type";         # these lines
        print "PONG\n";             #####################note this line
	next;                       # to try
  }                                 # how to handle set command

  if ( $cmd eq "getnext" ) {
    if ($req eq $place) {
      $ret = "$place.1";
    } elsif ($req eq "$place.1") {
      $ret = "$place.2.1";
    } elsif ($req eq "$place.2.1") {
      $ret = "$place.2.2";
    } elsif ($req eq "$place.2.2") {
      $ret = "$place.3";
    } elsif ($req eq "$place.3") {
      $ret = "$place.4";
    } elsif ($req eq "$place.4") {
      $ret = "$place.5";
    } elsif ($req eq "$place.5") {
      $ret = "$place.6";
    } else {
      print "NONE\n";
      next;
    }
  } else {
    if ($req eq $place) {
      print "NONE\n";
      next;
    } else {
      $ret = $req;
    }
  }

  print "$ret\n";

  if ($ret eq "$place.1") {
    print "string\nlife the universe and everything\n";
  } elsif ($ret eq "$place.2.1") {
    print "integer\n423\n";
  } elsif ($ret eq "$place.2.2") {
    print "objectid\n.1.3.6.1.4.42.42.42\n";
  } elsif ($ret eq "$place.3") {
    print "timeticks\n363136200\n";
  } elsif ($ret eq "$place.4") {
    print "ipaddress\n127.0.0.1\n";
  } elsif ($ret eq "$place.5") {
    $counter++;
    print "counter\n$counter\n";
  } elsif ($ret eq "$place.6") {
    print "gauge\n42\n";
  } else {
    print "string\nack... $ret $req\n";
  }
}

we can run snmpset command mentioned before for any times. The process
running the pass_persist script will NOT exit now! But we still cannot get
the the correct error reports.

Thanks.


Best regards,

quhp





-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.