oi-extras/net-snmp/sun/sdk/demo/demo_module_10/README_demo_module_10
author Andrzej Szeszo <aszeszo@gmail.com>
Wed, 22 Jun 2011 00:51:55 +0100
branchoi-extras
changeset 215 6eb7b62e444c
permissions -rw-r--r--
Added libusb and net-snmp packages
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
215
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     1
#
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     2
# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     3
#
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     4
# U.S. Government Rights - Commercial software. Government users are subject
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     5
# to the Sun Microsystems, Inc. standard license agreement and applicable
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     6
# provisions of the FAR and its supplements.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     7
#
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     8
#
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
     9
# This distribution may include materials developed by third parties. Sun,
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    10
# Sun Microsystems, the Sun logo and Solaris are trademarks or registered
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    11
# trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    12
#
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    13
#
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    14
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    15
README for demo_module_10
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    16
***********************************************************************
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    17
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    18
This example demonstrates a module design that handles long running
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    19
data collections so that their values can be polled by an SNMP manager.  
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    20
The example also shows how to implement objects that normally would block 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    21
the agent as it waits for external events in such a way that the agent can 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    22
continue responding to other requests while this implementation waits.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    23
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    24
This example uses the following features of SMA:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    25
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    26
- Setting the delegated member of the requests structure to 1 to indicate to 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    27
  the agent that this request should be delayed.  The agent queues this request
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    28
  to be handled later and then is available to handle other requests.  The
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    29
  agent is not blocked by this request.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    30
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    31
- Registering an SNMP alarm to update the results at a later time. 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    32
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    33
- Use of a status variable to communicate the status of a data collection to
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    34
  the polling SNMP manager.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    35
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    36
- Use of a refreshTime variable to return the date and time that the data 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    37
  collection completed.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    38
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    39
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    40
How to Build the demo_module_10 Code Example
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    41
============================================
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    42
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    43
The demo_module_10 code example includes the following files, by default 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    44
located in the directory /usr/demo/sma_snmp/demo_module_10.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    45
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    46
Files:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    47
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    48
Makefile - makefile to build the demo_module_10.so shared library file
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    49
demo_module_10.c  - module source code
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    50
demo_module_10.h - module header file
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    51
SDK-DEMO10-MIB.txt - MIB file
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    52
get_status - Script that gets the value of the status variable
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    53
get_refreshtime - Script that gets the date and time of the current data 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    54
collection get_data - Script that gets the data returned by the data collection
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    55
set_data - Script sets the value of the status variable to 0, which starts a 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    56
new data collection
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    57
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    58
To set up your build environment for the demo:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    59
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    60
1. Copy the demo code to a directory for which you have write permission.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    61
   For example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    62
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    63
   % cp -R /usr/demo/sma_snmp/demo_module_10  /home/username/demo
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    64
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    65
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    66
2. Create a lib directory that you can use to store shared object libraries 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    67
   that you generate from demo code examples, if you have not already done so. 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    68
   For example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    69
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    70
   % mkdir /home/username/demo/lib
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    71
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    72
    
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    73
3. Create a mibs directory that you can use to store MIB files for the demo 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    74
   code examples, if you have not already done so. 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    75
   For example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    76
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    77
   % mkdir /home/username/demo/mibs
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    78
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    79
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    80
4. Set the CC environment variable to the location of the C compiler to be 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    81
   used.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    82
   For example, if you are using Sun ONE Studio:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    83
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    84
   % setenv CC /opt/SUNWspro/bin/cc
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    85
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    86
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    87
5. Set your PATH environment variable to include the appropriate paths, so that
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    88
   needed binaries can be found during the compilation process. 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    89
   For example, in the csh: 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    90
    
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    91
   % setenv PATH .:/usr/bin:$PATH
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    92
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    93
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    94
To build the example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    95
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    96
1. Change to the directory where you copied the demo module files. 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    97
   For example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    98
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
    99
   % cd /home/username/demo/demo_module_10
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   100
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   101
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   102
2. Use the make command to generate object files.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   103
  
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   104
   If you are running the 64-bit SPARC Solaris kernel, type:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   105
   % /usr/ccs/bin/make
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   106
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   107
   If you are running the 32-bit SPARC Solaris kernel, type:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   108
   % /usr/ccs/bin/make ARCH=32
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   109
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   110
   If you are running the Solaris x86 kernel, type:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   111
   % /usr/ccs/bin/make ARCH=32
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   112
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   113
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   114
3. Copy the module shared library object to the lib directory you created. 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   115
   For example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   116
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   117
   % cp demo_module_10.so /home/username/demo/lib
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   118
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   119
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   120
4. Copy SDK-DEMO10-MIB.txt to the mibs directory you created for the demos.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   121
   For example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   122
  
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   123
   % cp SDK-DEMO10-MIB.txt /home/username/demo/mibs
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   124
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   125
       
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   126
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   127
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   128
Setting Up Agent to Run the demo_module_10 Module
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   129
=================================================
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   130
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   131
1. As root, edit the agent's configuration file /etc/sma/snmp/snmpd.conf,
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   132
   and insert a dlmod statement for the module. This statement enables the 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   133
   agent to load the module.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   134
   For example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   135
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   136
   dlmod demo_module_10 /home/username/demo/lib/demo_module_10.so
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   137
    
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   138
    
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   139
2. As root, start the SMA snmp agent. If the agent is already running, 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   140
   stop and restart it in debug mode.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   141
   For example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   142
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   143
   # /etc/init.d/init.sma stop
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   144
   # /usr/sbin/snmpd -Ddemo_module_10
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   145
    
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   146
   The optional -Ddemo_module_10 argument sends debugging statements from 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   147
   demo_module_10 to the /var/log/snmpd.log file. You can also use the -L 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   148
   and -f options to send debugging statements to the screen instead.   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   149
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   150
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   151
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   152
Testing the Code Example
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   153
========================
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   154
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   155
1. Set your MIBS and MIBDIRS environment variables to
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   156
   include the appropriate paths.  
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   157
   For example, in the csh: 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   158
    
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   159
   % setenv MIBDIRS .:/home/username/demo/mibs:/etc/sma/snmp/mibs
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   160
   % setenv MIBS +SDK-DEMO10-MIB
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   161
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   162
   Note that step 1 is not required, but it enables snmpget to access the MIB
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   163
   to provide variable names instead of OIDs in its output.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   164
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   165
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   166
2. Run the get_status script to get the default value of 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   167
   the status variable.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   168
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   169
   % get_status
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   170
   SDK-DEMO10-MIB::status.0 = INTEGER: 2
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   171
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   172
   An SNMP manager would typically poll the status variable
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   173
   of devices that generate long running data collections, until
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   174
   a value 2 is returned, which indicates that the collection is 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   175
   complete and the data is ready to get.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   176
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   177
   status has a default value of 0, which means no data collection
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   178
   has been started, so the module starts a new collection.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   179
   When the collection completes, status is set to 2.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   180
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   181
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   182
3. Run the get_refreshtime script to get the date and time
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   183
   of the data collection.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   184
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   185
   % get_refreshtime
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   186
   SDK-DEMO10-MIB::refreshTime.0 = STRING: Fri Jul 18 12:36:56 2003
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   187
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   188
   After retrieving the date and time, the SNMP manager can decide whether the
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   189
   date of the data collection is acceptable. If the manager needs more recent
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   190
   data, it can set the status variable to 0 to start a new collection. In this
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   191
   example, the manager wants more recent data.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   192
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   193
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   194
4. Set the status variable to 0 to start a new collection, as follows:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   195
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   196
   % set_status
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   197
   SDK-DEMO10-MIB::status.0 = INTEGER: 0
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   198
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   199
   Note that SET requests through this object will take longer, 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   200
   since the delay is applied to each internal transaction phase,
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   201
   which could result in delays of up to 4 times the value of this object.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   202
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   203
   For example, initially, the default value is
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   204
   1 second. Therefore, specify a 3 second timeout value on the
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   205
   snmpset command line.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   206
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   207
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   208
5. Run the get_status script again to get the status value.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   209
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   210
   % get_status
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   211
   SDK-DEMO10-MIB::status.0 = INTEGER: 2
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   212
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   213
6. Run the get_data script to get the data resulting from
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   214
   the data collection, for example:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   215
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   216
   % get_data
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   217
   SDK-DEMO10-MIB::longRunScalar.0 = INTEGER: 325
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   218
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   219
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   220
7. Open two terminal windows so you can run two scripts at the same time, as
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   221
   follows:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   222
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   223
   In the first window, run the get_status script:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   224
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   225
   % get_status
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   226
   SDK-DEMO10-MIB::status.0 = INTEGER: 2
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   227
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   228
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   229
   In the second window, run the walk_demo_module_10 script:
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   230
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   231
   % walk_demo_module_10
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   232
   
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   233
   SNMPv2-MIB::sysDescr.0 = STRING: SunOS myhost 5.10 s10_35 sun4u
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   234
   SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-TC::solaris
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   235
   DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (497128) 1:22:51.28
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   236
   SNMPv2-MIB::sysContact.0 = STRING: "Administrator's Name"
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   237
   SNMPv2-MIB::sysName.0 = STRING: myhost
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   238
   SNMPv2-MIB::sysLocation.0 = STRING: My Town
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   239
   SNMPv2-MIB::sysORLastChange.0 = Timeticks: (8) 0:00:00.08
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   240
   SNMPv2-MIB::sysORID.1 = OID: IF-MIB::ifMIB
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   241
   ...
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   242
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   243
   This example demonstrates that the agent is not blocked and does respond to
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   244
   the snmpwalk request, while the snmpget request executed in the first 
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   245
   window is still pending.
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   246
6eb7b62e444c Added libusb and net-snmp packages
Andrzej Szeszo <aszeszo@gmail.com>
parents:
diff changeset
   247