Re: How to return error message with snmpset using pass_persist

Turbo Fredriksson <[email protected]>
Newsgroups gmane.network.net-snmp.user
Organization Bah!
Message-ID <[email protected]>
Quoting "quhp" <[email protected]>:

>   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

The input can be retreived with a '<>':

    my $input = <>; chomp($input);
    my ($type, $value) = split(' ', $input);

The '$type' variable will be 'integer', 'string' etc and '$value'
will contain the value you want to set the OID to.


The error 'wrong-type' should work, but maybe not for 'set' commands.

> 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

If you check the logfiles for snmpd, you'll notice that snmpd first
tries to do a GET on the OID and _THEN_ do the 'SET'... So what you
got was just the result from the 'GET', not the 'SET'.

> 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 :)

Then there's something wrong with the perl script. Either there's an
exit, die or other parse/compile error that makes it die.

Try this:

printf "set\n1.3.6.1.4.1.2021.255.1.1\ni 5\n" | /path/to/pass_persisttest

you SHOULD see some perl compile errors in this...


If you'd like to see a (bad!) example on how to implement SET, GET, GETNEXT and
tables ('normal'/simple tables and linked tables) in a pass_persist perlscript,
have a look at http://www.bayour.com/bacula-snmp/.


The code itself isn't to bad, it's the last part (trying to figure out what
OID comes next) that sucks. 
-- 
cryptographic terrorist SEAL Team 6 domestic disruption Marxist DES
ammonium Khaddafi supercomputer [Hello to all my fans in domestic
surveillance] arrangements iodine class struggle Peking NSA
[See http://www.aclu.org/echelonwatch/index.html for more about this]
[Or http://www.europarl.eu.int/tempcom/echelon/pdf/rapport_echelon_en.pdf]
If neither of these works, try http://www.aclu.org and search for echelon.


-------------------------------------------------------
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.