components/net-snmp/sun/sdk/demo/demo_module_6/README_demo_module_6
changeset 252 ee0fb1eabcbf
equal deleted inserted replaced
251:f527656d334f 252:ee0fb1eabcbf
       
     1 #
       
     2 # Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
       
     3 #
       
     4 # U.S. Government Rights - Commercial software. Government users are subject
       
     5 # to the Sun Microsystems, Inc. standard license agreement and applicable
       
     6 # provisions of the FAR and its supplements.
       
     7 #
       
     8 #
       
     9 # This distribution may include materials developed by third parties. Sun,
       
    10 # Sun Microsystems, the Sun logo and Solaris are trademarks or registered
       
    11 # trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
       
    12 #
       
    13 #
       
    14 
       
    15 README for demo_module_6
       
    16 ***********************************************************************
       
    17 
       
    18 This code example demonstrates how to implement a module in such a way that
       
    19 more than one instance of the module can run simultaneously on a single host. 
       
    20 See the System Management Agent Developer's Guide for more information about 
       
    21 implementing multi-instance modules.
       
    22 
       
    23 
       
    24 Introduction
       
    25 ============
       
    26 
       
    27 The demo_module_6.c file shows how to write a module that registers an object
       
    28 in two different contexts. It also shows how to check for the contextName in 
       
    29 a request and return a different value depending on the value of the 
       
    30 contextName. 
       
    31     
       
    32 The code example registers one object, filesize, in two different contexts, 
       
    33 fileX and fileY. This example registers the OIDs using a read-only instance 
       
    34 handler helper. The OIDs do not need to be read-only. You could also register 
       
    35 the OIDs using any of the SMA instance handler helper APIs. 
       
    36     
       
    37 The function get_filesize is registered to handle get requests for instances 
       
    38 of  the filesize object. This function checks the contextName in the reginfo 
       
    39 structure that is passed to the function by the SMA agent. If the value of 
       
    40 contextName is fileX, the function returns fileX_data, which has been set to 
       
    41 the integer 111. If the value of contextName is fileY, the function returns 
       
    42 fileY_data, which has been set to the integer 999. 
       
    43 
       
    44 
       
    45 How to Build the demo_module_6 Code Example
       
    46 ===========================================
       
    47 
       
    48 The demo_module_6 code example includes the following files, by default located
       
    49 in the directory /usr/demo/sma_snmp/demo_module_6.
       
    50 
       
    51 
       
    52 Files:
       
    53 
       
    54 Makefile - makefile to build demo_module_6.so shared library file
       
    55 demo_module_6.c  - module source code
       
    56 demo_module_6.h - module header file
       
    57 SDK-DEMO6-MIB.txt - MIB file
       
    58 get_demo_module_6 - Script that executes snmpget against the OID defined 
       
    59 		    in the module.
       
    60 
       
    61 
       
    62 To set up your build environment for the demo:
       
    63 
       
    64 1. Copy the demo code to a directory for which you have write permission.
       
    65    For example:
       
    66    % cp -R /usr/demo/sma_snmp/demo_module_6  /home/username/demo
       
    67 
       
    68 
       
    69 2. Create a lib directory that you can use to store shared object libraries 
       
    70    that you generate from demo code examples, if you have not already done so. 
       
    71    For example:
       
    72    % mkdir /home/username/demo/lib
       
    73 
       
    74     
       
    75 3. Create a mibs directory that you can use to store MIB files for the demo 
       
    76    code examples, if you have not already done so. 
       
    77    For example:
       
    78    % mkdir /home/username/demo/mibs
       
    79 
       
    80 
       
    81 4. Set the CC environment variable to the location of the C compiler to be 
       
    82    used. For example, if you are using Sun ONE Studio:
       
    83    % setenv CC /opt/SUNWspro/bin/cc
       
    84 
       
    85 
       
    86 5. Set your PATH environment variable to include the appropriate paths, so that
       
    87    needed binaries can be found during the compilation process. 
       
    88    For example, in the csh: 
       
    89     
       
    90    % setenv PATH .:/usr/bin:$PATH
       
    91    
       
    92 
       
    93 To build the example:
       
    94 
       
    95 1. Change to the directory where you copied the demo module files. 
       
    96    For example:
       
    97 
       
    98    % cd /home/username/demo/demo_module_6
       
    99    
       
   100 
       
   101 2. Use the make command to generate object files.
       
   102   
       
   103    If you are running the 64-bit SPARC Solaris kernel, type:
       
   104    % /usr/ccs/bin/make
       
   105    
       
   106    If you are running the 32-bit SPARC Solaris kernel, type:
       
   107    % /usr/ccs/bin/make ARCH=32
       
   108    
       
   109    If you are running the Solaris x86 kernel, type:
       
   110    % /usr/ccs/bin/make ARCH=32
       
   111    
       
   112 
       
   113 3. Copy the module shared library object to the lib directory you created. 
       
   114    For example:
       
   115 
       
   116    % cp demo_module_6.so /home/username/demo/lib
       
   117    
       
   118 
       
   119 4. Copy the SDK-DEMO6-MIB.tx file to the mibs directory you created for the 
       
   120    demos.
       
   121    For example:
       
   122      
       
   123    % cp SDK-DEMO6-MIB.txt /home/username/demo/mibs
       
   124 
       
   125 
       
   126 
       
   127 Setting Up Agent to Run the Multi-Instance Module
       
   128 =================================================
       
   129 
       
   130 To run this module, the agent must be configured for SNMPv3.
       
   131 
       
   132 
       
   133  1. As root, stop the SNMP agent if it is running.
       
   134     For example:
       
   135     
       
   136     # /etc/init.d/init.sma stop
       
   137     
       
   138      
       
   139  2. Set up an SNMP v3 user as follows, if you have not already done so. 
       
   140     Note that you should use "myuser" and "mypassword" -- do not replace with
       
   141     other values because the test script expects these values.
       
   142  
       
   143     # /usr/bin/net-snmp-config --create-snmpv3-user myuser
       
   144  
       
   145     Enter authentication pass-phrase: 
       
   146     mypassword
       
   147  
       
   148     Enter encryption pass-phrase: 
       
   149     [press return to reuse the authentication pass-phrase]
       
   150     <Return>
       
   151  
       
   152       
       
   153  3. Edit the agent's configuration file /etc/sma/snmp/snmpd.conf,
       
   154     and insert a dlmod statement for the module. This statement enables 
       
   155     the agent to load the module.
       
   156     For example:
       
   157    
       
   158     dlmod demo_module_6 /home/username/demo/lib/demo_module_6.so
       
   159    
       
   160     
       
   161  4. Start the SMA snmp agent in debug mode.
       
   162     For example:
       
   163    
       
   164     # /usr/sbin/snmpd -Ddemo_module_6
       
   165     
       
   166     The optional -Ddemo_module_6 argument sends debugging statements from 
       
   167     demo_module_6 to the /var/log/snmpd.log file. You can also use the -L 
       
   168     and -f options to send debugging statements to the screen instead.
       
   169 
       
   170 
       
   171     
       
   172 
       
   173 
       
   174 Testing the demo_module_6 Module
       
   175 ================================
       
   176     
       
   177 1. Set your MIBS and MIBDIRS environment variables to
       
   178    include the appropriate paths.  
       
   179    For example, in the csh: 
       
   180     
       
   181    % setenv MIBDIRS .:/home/username/demo/mibs:/etc/sma/snmp/mibs
       
   182    % setenv MIBS +SDK-DEMO6-MIB
       
   183    
       
   184    Note that step 1 is not required, but it enables snmpget to access the MIB
       
   185    to provide variable names instead of OIDs in its output.   
       
   186    
       
   187    
       
   188 2. Run the get_demo_module_6 script to access the agent: 
       
   189  
       
   190    % get_demo_module_6
       
   191     
       
   192    SMA-SDK-MODULE-EXAMPLE1-MIB::me1FileSize.0 = INTEGER: 111
       
   193    SMA-SDK-MODULE-EXAMPLE1-MIB::me1FileSize.0 = INTEGER: 999
       
   194   
       
   195       
       
   196    The first snmpget in the script accesses the module whose contextName is 
       
   197    fileX, and the second snmpget accesses the module whose contextName is 
       
   198    fileY.  
       
   199       
       
   200 
       
   201 
       
   202