JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Solaris System Management Agent Developer's Guide
search filter icon
search icon

Document Information

Preface

1.  Introduction to the System Management Agent

2.  Creating Modules

3.  Data Modeling

4.  Storing Module Data

About Storing Module Data

Configuration Files

Defining New Configuration Tokens

Implementing Persistent Data in a Module

Storing Persistent Data

Reading Persistent Data

demo_module_5 Code Example for Persistent Data

Storing Persistent Data in demo_module_5

Reading Persistent Data in demo_module_5

Using SNMP_CALLBACK_POST_READ_CONFIG in demo_module_5

5.  Implementing Alarms

6.  Deploying Modules

7.  Multiple Instance Modules

8.  Long-Running Data Collection

9.  Entity MIB

10.  Migration of Solstice Enterprise Agents to the System Management Agent

A.  SMA Resources

B.  MIBs Implemented in SMA

Glossary

Index

demo_module_5 Code Example for Persistent Data

The demo_module_5 code example demonstrates the persistence of data across agent restart. The demo is located in the directory /usr/demo/sma_snmp/demo_module_5 by default.

This module implements SDK-DEMO5-MIB.txt. The demo_module_5.c and demo_module_5.h templates were renamed from the original templates me5FileGroup.c and me5FileGroup.h that were generated with the mib2c command. The name of the initialization function is changed from init_me5FileGroup to init_demo_module_5.

See the README_demo_module_5 file in the demo_module_5 directory for the procedures to build and run the demo.

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.

Reading Persistent Data in demo_module_5

Data is read from the configuration files into a module by registering a callback function to be called whenever an relevant token is encountered. For example, you can call the function as follows:

register_config_handler(DEMO5_CONF_FILE, "demo5_file1",
demo5_load_tokens, NULL, NULL);

Whenever the demo5_file1 token in the demo_module_5.conf file is read by the agent, the function demo5_load_tokens() is called with token name and value as arguments. The demo5_load_tokens() function stores the token value in appropriate variables:

void
demo5_load_tokens(const char *token, char *cptr)
{

    if (strcmp(token, "demo5_file1") == 0) {
        strcpy(file1, cptr);
    } else if (strcmp(token, "demo5_file2") == 0) {
        strcpy(file2, cptr);
    } else if (strcmp(token, "demo5_file3") == 0) {
        strcpy(file3, cptr);
    } else if (strcmp(token, "demo5_file4") == 0) {
        strcpy(file4, cptr);
    } else {
        /* Do Nothing */
    }

    return;

}

Using SNMP_CALLBACK_POST_READ_CONFIG in demo_module_5

A few seconds elapse after agent startup while all configuration tokens are read by the module. During this interval, the module should not perform certain functions. For example, until the persistent file names are read from /var/sma_snmp/demo_module_5.conf into the module, the file table cannot be populated. To handle these cases, a callback function can be set. This callback function is called when the process of reading the configuration files is complete. For example, you might call the function as follows:

snmp_register_callback(SNMP_CALLBACK_LIBRARY,
 SNMP_CALLBACK_POST_READ_CONFIG, demo_5_post_read_config, NULL);

The demo_5_post_read_config() function is called after the configuration files are read. In this example, the demo_5_post_read_config() function populates the file table, then registers the callback function for data persistence.

int
demo5_post_read_config(int a, int b, void *c, void *d)
{   if (!AddItem(file1))
     snmp_log(LOG_ERR, "Failed to add instance in init_demo_module_5\n");
  if (!AddItem(file2))
     snmp_log(LOG_ERR, "Failed to add instance in init_demo_module_5\n");
  if (!AddItem(file3))
     snmp_log(LOG_ERR, "Failed to add instance in init_demo_module_5\n");
  if (!AddItem(file4))
     snmp_log(LOG_ERR, "Failed to add instance in init_demo_module_5\n");


snmp_register_callback
(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
demo5_persist_data, NULL);

}