Solaris System Management Agent Developer's Guide

Loading Modules Dynamically

The simplest way to load modules dynamically is to restart the agent after you add entries to the configuration file. Dynamic loading is the best method to use while you are developing and testing a module. Most of the demonstration modules in /usr/demo/sma_snmp use dynamic loading. You should use the procedure How to Dynamically Load a Module and Restart the Agent during the development and testing phase.

When you are using the module in a production environment, that environment might require you not to restart the agent. If you want to load modules without restarting the agent, you should use the procedure How to Dynamically Load a Module Without Restarting the Agent.

ProcedureHow to Dynamically Load a Module and Restart the Agent

  1. Copy the module shared library object to a lib directory.

    You should keep your .so files in a directory that is writable by non-root users.

  2. As root, edit the agent's configuration file to enable the agent to dynamically load the module.

    In the /etc/sma/snmp/snmpd.conf file, add a line that is similar to the following, where testmodule is the name of the module.

    dlmod testmodule /home/username/snmp/lib/testmodule.so
  3. As root, restart the snmpd agent by typing the following command.


    # svcadm restart svc:/application/management/sma:default
    

    The module should now be loaded. You can use snmpget and snmpset commands to access the module's data to confirm that the module is loaded. You should make sure your MIB can be located by the snmpget and snmpset commands by setting your MIBDIRS and MIBS environment variables, as described in Setting MIB Environment Variables.


    Tip –

    To unload a module, you would remove the dlmod line from the snmpd.conf file and restart the agent.


ProcedureHow to Dynamically Load a Module Without Restarting the Agent

The UCD-DLMOD-MIB provides MIB entries for the module name, path, and status. By setting these MIB entries, you can cause the agent to load or unload the module without restarting the agent.


Note –

This procedure causes the module to be loaded only for the current session of the agent. If you want the module to be loaded each time the agent starts, you should add a dlmod line to the snmpd.conf file. The process of adding the line is described in Step 2 of the previous procedure. Do not restart the agent after adding the line.


  1. View the UCD-DLMOD-MIB.txt file in /etc/sma/snmp/mibs.

    Look for the DlmodEntry and dlmodStatus entries, which appear as follows:

    DlmodEntry ::= SEQUENCE {
         dlmodIndex  Integer32,
         dlmodName   DisplayString,
         dlmodPath   DisplayString,
         dlmodError  DisplayString,
         dlmodStatus INTEGER
     }
     
     dlmodStatus OBJECT-TYPE
         SYNTAX      INTEGER {
                         loaded(1),
                         unloaded(2),
                         error(3),
                         load(4),
                         unload(5),
                         create(6),
                         delete(7)
                     }
         MAX-ACCESS  read-write
         STATUS      current
         DESCRIPTION
             "The current status of the loaded module."
         ::= { dlmodEntry 5 }

    DlmodEntry defines a row in a table of dynamically loaded modules. A table row describes an instance by defining an index, name, path, error code, and status code. You need to set the name, path, and status of the first empty row of the table.

  2. Type the following command to check the first row of the table. The command can tell you whether an instance of a dynamically loaded module already exists in the table.


    $ /usr/sfw/bin/snmpget -v 1 -c public localhost UCD-DLMOD-MIB::dlmodStatus.1
    Error in packet
    Reason: (noSuchName) There is no such variable name in this MIB. 
    Failed object: UCD-DLMOD-MIB::dlmodStatus.1

    This response indicates that no other dynamic module is defined as instance 1. If you get back a positive response, examine dlmodStatus.2 with the same command.

  3. Create an instance for your module in the table by typing the following command:


    $ /usr/sfw/bin/snmpset -v 1 -c private localhost \
    UCD-DLMOD-MIB::dlmodStatus.1 i create
    
    UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: create(6)
  4. Repeat the snmpget command to show the status of the first instance.


    $ /usr/sfw/bin/snmpget -v 1 -c public localhost \
    UCD-DLMOD-MIB::dlmodStatus.1
    UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: unloaded(2)

    The instance now exists, but the module is unloaded currently.

  5. Set the name and path to the module that you want to load. Type a command that is similar to the following:


    $ /usr/sfw/bin/snmpset -v 1 -c private localhost \
    UCD-DLMOD-MIB::dlmodName.1 s "testmodule" \ 
    UCD-DLMOD-MIB::dlmodPath.1 s "/home/username/lib/testmodule.so"
    UCD-DLMOD-MIB::dlmodName.1 = STRING: testmodule
    UCD-DLMOD-MIB::dlmodPath.1 = STRING: /home/username/lib/testmodule.so

    testmodule is the name of your module.

  6. Load the module by typing the following command:


    $ /usr/sfw/bin/snmpset -v 1 -c private localhost \
    UCD-DLMOD-MIB::dlmodStatus.1 i load
    UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: load(4)

    This command sets the dlmodStatus.1 variable to load.

  7. Confirm that the module was loaded by typing the following command:


    $ /usr/sfw/bin/snmpget  -v 1 -c public localhost \
    UCD-DLMOD-MIB::dlmodStatus.1
    UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: loaded(1)

    The response indicates that the module is loaded.

  8. (Optional) Unload the module by typing the following command:


    $ /usr/sfw/bin/snmpset -v 1 -c private localhost \
    UCD-DLMOD-MIB::dlmodStatus.1 i unload
    UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: unload(5)
  9. (Optional) Confirm that the module was unloaded by typing the following command:


    $ /usr/sfw/bin/snmpget -v 1 -c public localhost \
    UCD-DLMOD-MIB::dlmodStatus.1
    Timeout: No Response from localhost.

    The lack of response from localhost indicates that the module is unloaded.