components/net-snmp-57/sun/sdk/demo/demo_module_1/README_demo_module_1
changeset 5867 445e2cf1c845
parent 252 ee0fb1eabcbf
equal deleted inserted replaced
5866:683c5c035a79 5867:445e2cf1c845
       
     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 README for demo_module_1
       
    15 ********************************************************************
       
    16 
       
    17 This code example shows you how to modify the code generated by 
       
    18 "mib2c -c mib2c.scalar.conf" command to perform a scalar
       
    19 data retrieval.  See the System Management Agent Developer's Guide 
       
    20 for more information about scalar data retrieval.
       
    21 
       
    22 
       
    23 Introduction
       
    24 ------------
       
    25 This example shows you how to generate templates with mib2c from a sample 
       
    26 MIB.  You can then compare these templates with the source code and header
       
    27 files provided with the example. The source files were created by modifying
       
    28 the templates that you create in this example. 
       
    29 
       
    30 The example also shows you how to build a module from the modified source files. 
       
    31 
       
    32 The demo_module_1 code example includes the following files, by default 
       
    33 located in the directory /usr/demo/sma_snmp/demo_module_1.
       
    34 
       
    35 Files:
       
    36 
       
    37 o Makefile - Compiles the module source code
       
    38 o demo_module_1.c - Source code for the module, returns load averages
       
    39 o demo_module_1.h - Header file for the module
       
    40 o SDK-DEMO1-MIB.txt - MIB file used in the module
       
    41 
       
    42 
       
    43 
       
    44 
       
    45 How to Use the demo_module_1 Code Example
       
    46 ==========================================
       
    47 
       
    48 
       
    49 To set up your environment for the demo:
       
    50 
       
    51 1. Copy the demo code to a directory for which you have write permission.
       
    52    For example:
       
    53    % cp -R /usr/demo/sma_snmp/demo_module_1  /home/username/demo
       
    54 
       
    55 
       
    56 2. Create a lib directory that you can use to store shared object libraries 
       
    57     
       
    58    that you generate from demo code examples, if you have not already done so. 
       
    59    For example:
       
    60    % mkdir /home/username/demo/lib
       
    61 
       
    62     
       
    63 3. Create a mibs directory that you can use to store MIB files for the 
       
    64    demo code examples, if you have not already done so. 
       
    65    For example:
       
    66    % mkdir /home/username/demo/mibs
       
    67 
       
    68 
       
    69 4. Set the CC environment variable to the location of the C compiler to be used.
       
    70    For example, if you are using Sun ONE Studio:
       
    71    % setenv CC /opt/SUNWspro/bin/cc
       
    72 
       
    73 
       
    74 5. Set your PATH environment variable to include the appropriate paths, so that
       
    75    needed binaries can be found during the compilation process. 
       
    76    For example, in the csh: 
       
    77     
       
    78    % setenv PATH .:/usr/bin:$PATH
       
    79       
       
    80 
       
    81 
       
    82 
       
    83 To generate code templates from the sample MIB:
       
    84 
       
    85 
       
    86 1. Change to the directory where you copied the demo module files. 
       
    87    For example:
       
    88 
       
    89    % cd /home/username/demo/demo_module_1
       
    90    
       
    91 
       
    92 2. Copy the SDK-DEMO1-MIB.txt file to the mibs directory you created 
       
    93    for the demos.
       
    94    For example:
       
    95   
       
    96    % cp SDK-DEMO1-MIB.txt /home/username/demo/mibs
       
    97 
       
    98       
       
    99 3. Set your MIBS and MIBDIRS environment variables to
       
   100    include the appropriate paths.  
       
   101    For example, in the csh: 
       
   102     
       
   103    % setenv MIBDIRS .:/home/username/demo/mibs:/etc/sma/snmp/mibs
       
   104    % setenv MIBS +SDK-DEMO1-MIB
       
   105    
       
   106  
       
   107 4. Run mib2c on the me1LoadGroup group in the SDK-DEMO1-MIB.
       
   108    For example:
       
   109    
       
   110    % mib2c -c mib2c.scalar.conf me1LoadGroup
       
   111 
       
   112    The mib2c utility generates the following template files:
       
   113    me1LoadGroup.c 
       
   114    me1LoadGroup.h
       
   115    
       
   116 
       
   117 5. Compare the template files with the demo_module_1.c and the
       
   118    demo_module_1.h files. 
       
   119    
       
   120    The demo_module_1 files were created by modifying the templates. 
       
   121     
       
   122    See the System Management Agent Developer's Guide for more information
       
   123    about modifying templates.   
       
   124  
       
   125    
       
   126   
       
   127 
       
   128 To build the example:
       
   129 
       
   130 1. Change to the directory where you copied the demo module files. 
       
   131    For example:
       
   132 
       
   133    % cd /home/username/demo/demo_module_1
       
   134    
       
   135 
       
   136 2. Use the make command to generate object files.
       
   137   
       
   138    If you are running the 64-bit SPARC Solaris kernel, type:
       
   139    % /usr/ccs/bin/make
       
   140    
       
   141    If you are running the 32-bit SPARC Solaris kernel, type:
       
   142    % /usr/ccs/bin/make ARCH=32
       
   143    
       
   144    If you are running the Solaris x86 kernel, type:
       
   145    % /usr/ccs/bin/make ARCH=32
       
   146    
       
   147 
       
   148 3. Copy the module shared library object to the lib directory you created. 
       
   149    For example:
       
   150 
       
   151    % cp demo_module_1.so /home/username/demo/lib
       
   152 
       
   153    
       
   154 
       
   155    
       
   156    
       
   157    
       
   158 Setting Up Agent to Run demo_module_1
       
   159 =============================================
       
   160     
       
   161 1. As root, edit the agent's configuration file /etc/sma/snmp/snmpd.conf,
       
   162    and insert a dlmod statement for the module. This statement enables 
       
   163    the agent to load the module.
       
   164    For example:
       
   165    
       
   166    dlmod demo_module_1 /home/username/demo/lib/demo_module_1.so
       
   167    
       
   168     
       
   169 2. As root, start the SMA snmp agent. If the agent is already running, stop 
       
   170    and restart it in debug mode.
       
   171    For example:
       
   172    
       
   173     # /etc/init.d/init.sma stop
       
   174     # /usr/sbin/snmpd -Ddemo_module_1
       
   175     
       
   176     The optional -Ddemo_module_1 argument sends debugging statements 
       
   177     from demo_module_1 to the /var/log/snmpd.log file. 
       
   178     You can also use the -L and -f options to send debugging statements to 
       
   179     the screen instead.
       
   180 
       
   181 
       
   182 
       
   183 Testing the Module
       
   184 ==================
       
   185 
       
   186 1. As a non-root user, issue snmpget commands to retrieve scalar data from the module.
       
   187    For example:
       
   188     
       
   189    % snmpget -v1 -c public localhost SDK-DEMO1-MIB::me1SystemLoadAvg1min.0
       
   190    % snmpget -v1 -c public localhost SDK-DEMO1-MIB::me1SystemLoadAvg5min.0 
       
   191    % snmpget -v1 -c public localhost SDK-DEMO1-MIB::me1SystemLoadAvg15min.0   
       
   192    
       
   193    Or
       
   194    
       
   195    % snmpget -v1 -c public localhost .1.3.6.1.4.1.42.2.2.4.4.1.1.1.0
       
   196    % snmpget -v1 -c public localhost .1.3.6.1.4.1.42.2.2.4.4.1.1.2.0
       
   197    % snmpget -v1 -c public localhost .1.3.6.1.4.1.42.2.2.4.4.1.1.3.0 
       
   198       
       
   199 
       
   200    These commands should produce output similar to the following:
       
   201     
       
   202     SDK-DEMO1-MIB::me1SystemLoadAvg1min.0 = STRING: 3.906250e-02 Jobs
       
   203     SDK-DEMO1-MIB::me1SystemLoadAvg5min.0 = STRING: 2.734375e-02 Jobs
       
   204     SDK-DEMO1-MIB::me1SystemLoadAvg15min.0 = STRING: 3.906250e-02 Jobs