|
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_9 |
|
16 *********************************************************************** |
|
17 |
|
18 This code example demonstrates how to implement objects for long running |
|
19 data collection. These objects are implemented in a way that allows the |
|
20 agent to respond to other requests while external data collection occurs. |
|
21 When data collection is complete, the agent can reply to the request. |
|
22 |
|
23 This example uses the following features of SMA: |
|
24 |
|
25 - Setting the delegated member of the requests structure to 1 to indicate to |
|
26 the agent that this request should be delayed. The agent queues this request |
|
27 to be handled later and then is available to handle other requests. The |
|
28 agent is not blocked by this request. |
|
29 |
|
30 - Registering an SNMP alarm to update the results at a later time. |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 How to Build the demo_module_9 Code Example |
|
36 =========================================== |
|
37 |
|
38 The demo_module_9 code example includes the following files, by default located |
|
39 in the directory /usr/demo/sma_snmp/demo_module_9. |
|
40 |
|
41 Files: |
|
42 |
|
43 demo_module_9.c - module source code |
|
44 demo_module_9.h - module header file |
|
45 Makefile - makefile to build the demo_module_9.so shared library file |
|
46 SDK-DEMO9-MIB.txt - MIB file |
|
47 get_demo_module_9 - Script that executes snmpget on the delayed OID |
|
48 set_demo_module_9 - Script that executes snmpset on the delayed OID |
|
49 walk_demo_module_9 - Script that executes snmpwalk on the SYSTEM table |
|
50 |
|
51 |
|
52 To set up your build environment for the demo: |
|
53 |
|
54 1. Copy the demo code to a directory for which you have write permission. |
|
55 For example: |
|
56 % cp -R /usr/demo/sma_snmp/demo_module_9 /home/username/demo |
|
57 |
|
58 |
|
59 2. Create a lib directory that you can use to store shared object libraries |
|
60 that you generate from demo code examples, if you have not already done so. |
|
61 For example: |
|
62 % mkdir /home/username/demo/lib |
|
63 |
|
64 |
|
65 3. Create a mibs directory that you can use to store MIB files for the demo |
|
66 code examples, if you have not already done so. |
|
67 For example: |
|
68 % mkdir /home/username/demo/mibs |
|
69 |
|
70 |
|
71 4. Set the CC environment variable to the location of the C compiler to be |
|
72 used. For example, if you are using Sun ONE Studio: |
|
73 % setenv CC /opt/SUNWspro/bin/cc |
|
74 |
|
75 |
|
76 5. Set your PATH environment variable to include the appropriate paths, so that |
|
77 needed binaries can be found during the compilation process. |
|
78 For example, in the csh: |
|
79 |
|
80 % setenv PATH .:/usr/bin:$PATH |
|
81 |
|
82 |
|
83 To build the example: |
|
84 |
|
85 1. Change to the directory where you copied the demo module files. |
|
86 For example: |
|
87 |
|
88 % cd /home/username/demo/demo_module_9 |
|
89 |
|
90 |
|
91 2. Use the make command to generate object files. |
|
92 |
|
93 If you are running the 64-bit SPARC Solaris kernel, type: |
|
94 % /usr/ccs/bin/make |
|
95 |
|
96 If you are running the 32-bit SPARC Solaris kernel, type: |
|
97 % /usr/ccs/bin/make ARCH=32 |
|
98 |
|
99 If you are running the Solaris x86 kernel, type: |
|
100 % /usr/ccs/bin/make ARCH=32 |
|
101 |
|
102 |
|
103 3. Copy the module shared library object to the lib directory you created. |
|
104 For example: |
|
105 |
|
106 % cp demo_module_9.so /home/username/demo/lib |
|
107 |
|
108 |
|
109 4. Copy SDK-DEMO9-MIB.txt to the mibs directory you created for the demos. |
|
110 For example: |
|
111 |
|
112 % cp SDK-DEMO9-MIB.txt /home/username/demo/mibs |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 Setting Up Agent to Run the demo_module_9 Module |
|
118 ================================================= |
|
119 |
|
120 1. As root, edit the agent's configuration file /etc/sma/snmp/snmpd.conf, |
|
121 and insert a dlmod statement for the module. This statement enables the |
|
122 agent to load the module. |
|
123 For example: |
|
124 |
|
125 dlmod demo_module_9 /home/username/demo/lib/demo_module_9.so |
|
126 |
|
127 |
|
128 2. As root, start the SMA snmp agent. If the agent is already running, stop |
|
129 and restart it in debug mode. |
|
130 For example: |
|
131 |
|
132 # /etc/init.d/init.sma stop |
|
133 # /usr/sbin/snmpd -Ddemo_module_9 |
|
134 |
|
135 The optional -Ddemo_module_9 argument sends debugging statements from |
|
136 demo_module_9 to the /var/log/snmpd.log file. You can also use the -L |
|
137 and -f options to send debugging statements to the screen instead. |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 Testing the demo_module_9 Module |
|
143 ================================ |
|
144 |
|
145 1. Run the get_demo_module_9 script to get the default value of |
|
146 the my_delayed_oid object, which is 1 second. |
|
147 For example: |
|
148 |
|
149 % get_demo_module_9 |
|
150 SDK-DEMO9-MIB::delayedInstanceOid.0 = INTEGER: 1 |
|
151 |
|
152 |
|
153 2. Run the set_demo_module_9 script to set the value of the |
|
154 my_delayed_oid object to 10 seconds. |
|
155 For example: |
|
156 |
|
157 % set_demo_module_9 |
|
158 SDK-DEMO9-MIB::delayedInstanceOid.0 = INTEGER: 10 |
|
159 |
|
160 The set_demo_module_9 script specifies a time-out value of three |
|
161 seconds (-t 3). The module uses the my_delayed_oid value as the time |
|
162 interval at which an SNMP alarm is sent to the module. |
|
163 |
|
164 SET requests through this object take longer, since the delay is applied |
|
165 to each internal transaction phase, which could result in delays of up to |
|
166 4 times the value of this object. |
|
167 |
|
168 For example, initially, the default my_delayed_oid value is 1 second. |
|
169 Therefore, the script uses a 3 second time-out value on the snmpset |
|
170 command line. |
|
171 |
|
172 |
|
173 ******************************************************************************* |
|
174 * NOTE: You must comment out the following line in the ** |
|
175 * /etc/sma/snmp/snmpd.conf file ** |
|
176 * rwcommunity private localhost .1.3.6.1.4.1.42.2.15 ** |
|
177 * and UNCOMMENT the line ** |
|
178 * rwcommunity private ** |
|
179 * Otherwise write access would be restricted to the .1.3.6.1.4.1.42.2.15 OID ** |
|
180 * ** |
|
181 * When you are done with this demo you should revert your changes for ** |
|
182 * security reasons ** |
|
183 ******************************************************************************* |
|
184 |
|
185 |
|
186 |
|
187 3 Open two terminal windows so you can run two scripts at the same time, as |
|
188 follows: |
|
189 |
|
190 In the first window, run the get_demo_module_9 script: |
|
191 % get_demo_module_9 |
|
192 |
|
193 |
|
194 In the second window, run the walk_demo_module_9 script: |
|
195 % walk_demo_module_9 |
|
196 |
|
197 SNMPv2-MIB::sysDescr.0 = STRING: SunOS myhost 5.10 s10_35 sun4u |
|
198 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-TC::solaris |
|
199 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (497128) 1:22:51.28 |
|
200 SNMPv2-MIB::sysContact.0 = STRING: "Administrator's Name" |
|
201 SNMPv2-MIB::sysName.0 = STRING: myhost |
|
202 SNMPv2-MIB::sysLocation.0 = STRING: My Town |
|
203 SNMPv2-MIB::sysORLastChange.0 = Timeticks: (8) 0:00:00.08 |
|
204 SNMPv2-MIB::sysORID.1 = OID: IF-MIB::ifMIB |
|
205 |
|
206 |
|
207 This example demonstrates that the agent is not blocked and does respond to |
|
208 the snmpwalk request, while the snmpget request executed in the first window |
|
209 is still pending. |
|
210 |