Solaris System Management Agent Developer's Guide

Storing Persistent Data in demo_module_5

This example stores configuration data in the /var/sma_snmp/demo_module_5.conf file.

In demo_module_5.c, the following statement registers the callback function. The callback function is called whenever the agent sees that module data needs to be stored, such as during normal termination of the agent.

snmp_register_callback(SNMP_CALLBACK_LIBRARY, 
                                SNMP_CALLBACK_STORE_DATA,
                                demo5_persist_data, 
                                NULL);

The demo5_persist_data() function uses read_store_config to store data:

int demo5_persist_data(int a, int b, void *c, void *d)
{
    char            filebuf[300];

    sprintf(filebuf, "demo5_file1 %s", file1);
    read_config_store(DEMO5_CONF_FILE, filebuf);

    sprintf(filebuf, "demo5_file2 %s", file2);
    read_config_store(DEMO5_CONF_FILE, filebuf);

    sprintf(filebuf, "demo5_file3 %s", file3);
    read_config_store(DEMO5_CONF_FILE, filebuf);

    sprintf(filebuf, "demo5_file4 %s", file4);
    read_config_store(DEMO5_CONF_FILE, filebuf);

}

In demo_module_5, a new file can be added for monitoring, by using the snmpset command. The commit phase of the snmpset request uses the read_config_store() function to store file information:

case MODE_SET_COMMIT:
    /*
     * Everything worked, so we can discard any saved information,
     * and make the change permanent (e.g. write to the config file).
     * We also free any allocated resources.
     *
     */Persist the file information */

    snprintf(&filebuf[0], MAXNAMELEN, "demo5_file%d %s",
		    data->findex, data->fileName);


		
		read_config_store(DEMO5_CONF_FILE, &filebuf[0]);

	    /*
	     * The netsnmp_free_list_data should take care of the allocated
	     * resources
	     */

The persistent data is stored in the /var/sma_snmp/demo_module_5.conf file.