Hello,
After some months, I am continuing with the task of achieving read and
write a variable to a text file using get/set operations.
To continue with this, I followed the instructions you gave to Guillermo.
According to the last email (which you can see below) I was working with
the code generated by mib2c. After making the necessary changes, I managed
to run set / get operations on a variable but I would extend this to save
the new value to a file
The basic SET processing is working, could you please help me to move on to
the next stage?
Thank you,
greetings,
Juan
---------- Forwarded message ----------
From: Guillermo Veneranda <[email protected]>
Date: 2013/6/3
Subject: Fwd: How to manipulate variables outside of SNMP gets / sets?
To: Juan Bússoli <[email protected]>
---------- Forwarded message ----------
From: Dave Shield <[email protected]>
Date: 2013/1/23
Subject: Re: How to manipulate variables outside of SNMP gets / sets?
To: Guillermo Veneranda <[email protected]>
Cc: Claus Klein <[email protected]>,
[email protected]
On 22 January 2013 21:21, Guillermo Veneranda <[email protected]> wrote:
> I try what you say and... It's Works! :)
But of course, oh ye of little faith....
> Let's go now for the SET!
OK.
So go back to the code generated by mib2c.
Add the declaration of 'example1' as before,
and tweak the MODE_GET block to report this value
(directly, *not* read from the /tmp file just yet).
Now look at the other blocks - the ones that handle
SET processing.
At it's simplest, you just need to use two of these:
MODE_SET_RESERVE1 and either
MODE_SET_ACTION or MODE_SET_COMMIT
The RESERVE1 code is probably OK as it stands.
It checks to see if the incoming assignment is an
integer value (as opposed to a string or an OID),
and complains if it's not.
If your MIB object can only accept a particular
range of values (say 1 to 10), then this is the place
where you would check that the new value was OK,
and reject the request if it was out of range.
Acting on the assignment is simply a matter of
putting the new value into the 'example1' variable.
i.e.
example1 = *(request->requestvb->val.integer);
This operation is so simple that it cannot possibly fail
(at least as long as the 'request' structure is valid!),
so it can go in either ACTION or COMMIT.
Try that - with the other SET blocks left empty
(i.e.
case MODE_SET_XXX;
break;
)
Compile that into the agent as before - you should find
that you can issue an snmpset command for this object
and have the new value returned by a subsequent GET
or snmpwalk request.
Try that, and then come back, and we can talk about how
to extend this to saving the new value in a file.
(Please note that this is *not* simply a matter of adding
suitable 'fopen/write/fclose' calls - there are other
considerations that need to be taken into account)
But get the basic SET processing working first,
and then we can move on to the next stage.
Dave
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders