Re: Persistent storage

Peter Czaja <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hi,

coming back to..
Dave Shield schrieb:
> On 04/09/07, Peter Czaja <[email protected]> wrote:
>> But where is the equivalent to the "init_myagent_scalar()" function?
>>
>> Something like "finalize_myagent_scalar()", which would be a natural
>> place to implement the corresponding calls to netscnmp_ds_write_*().
>>
>> What did I miss?
> 
> Add the following call to init_myagent_scalar():
> 
>         snmp_register_callback(SNMP_CALLBACK_LIBRARY,
>                            SNMP_CALLBACK_STORE_DATA,
>                            finalize_myagent_scalar, NULL);
> 
> That will save your persistent data - both when the agent shuts
> down, and also when it is explicitly told to save or re-read config
> files.

Thanks for your help.
Unfortunately my code doesn't get called on the agent's exit.

But calling the function finalize_myagent_scalar() using the
callback mechanism via

  snmp_call_callbacks( SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, NULL)

does work, after having it registered like you suggested.

The agent is a simple subagent generated using mib2c and communicating
with the master agent via agentx. It is sitting at the right place in
the agents/ directory, so the script "/etc/init.d/snmpd start"
successfully starts my subagent with snmpd. Getting and setting
values of my custom MIB works like a charm.

But that's not even my main concern, as storing data using the
default store mechanism doesn't work out like I expected, either:

In my init function, I registered a variable using

  netsnmp_ds_register_config( ASN_INTEGER, "myagent", "myvalue",
            NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_MYAGENT_MYVALUE)

and expect it to be stored on the agent's exit in the file
/var/net-snmp/myagent.conf in a line like

  myvalue=<whatever_int_i_stored>

and being retrieved on the agents start, being readily available to
be read, umm, via

  netsnmp_ds_get_int( NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_MYAGENT_MYVALUE)

But it keeps returning a value of 0 on a freshly started agent, instead of
the value I had stored previously using

  netsnmp_ds_set_int( NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_MYAGENT_MYVALUE, myvalue)

the last time before the agent was shut down.


Enlightenment is apprecciated :)


    Peter


-- 
   O=====                                                     __o
  /`-´                        Peter Czaja                   _`\<,_
  \/\_ ______ ___ __ _     Paderborn Germany    _ __ ______(_)/ (_)____

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
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.