|
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 |
|
16 README for demo_module_5 |
|
17 *********************************************************************** |
|
18 |
|
19 This code example demonstrates how to implement data persistence |
|
20 for a module, across agent restarts. See the System Management |
|
21 Agent Developer's Guide for more information about storing persistent |
|
22 data. |
|
23 |
|
24 |
|
25 Introduction |
|
26 ------------ |
|
27 |
|
28 The demo_module_5 is based on the SDK-DEMO5-MIB.txt MIB, which implements |
|
29 the me5FileGroup objects. me5FileTable monitors a set of files. File size |
|
30 and file permissions are monitored for each file. By default, the |
|
31 following files are monitored: |
|
32 |
|
33 /etc/hosts |
|
34 /etc/group |
|
35 /etc/passwd |
|
36 /etc/system |
|
37 |
|
38 The module user can specify different files to be monitored by using |
|
39 snmp SET requests. Any changes to the list of monitored files are persistent |
|
40 across agent restarts. In other words, when the agent is restarted, the |
|
41 list of files being monitored is the same as before restart. |
|
42 |
|
43 |
|
44 Files |
|
45 ----- |
|
46 |
|
47 The demo_module_5 code example includes the following files, by default located |
|
48 in the directory /usr/demo/sma_snmp/demo_module_5. |
|
49 |
|
50 Makefile - makefile to build demo_module_5.so shared library file |
|
51 demo_module_5.c - module source code |
|
52 demo_module_5.h - module header file |
|
53 SDK-DEMO5-MIB.txt - MIB file for this module |
|
54 |
|
55 |
|
56 How to Build the demo_module_5 Code Example |
|
57 =========================================== |
|
58 |
|
59 To set up your build environment for the demo: |
|
60 |
|
61 1. Copy the demo code to a directory for which you have write permission. |
|
62 For example: |
|
63 % cp -R /usr/demo/sma_snmp/demo_module_5 /home/username/demo |
|
64 |
|
65 |
|
66 2. Create a lib directory that you can use to store shared object libraries |
|
67 that you generate from demo code examples, if you have not already done so. |
|
68 For example: |
|
69 % mkdir /home/username/demo/lib |
|
70 |
|
71 |
|
72 3. Create a mibs directory that you can use to store MIB files for the |
|
73 demo code examples, if you have not already done so. |
|
74 For example: |
|
75 % mkdir /home/username/demo/mibs |
|
76 |
|
77 |
|
78 4. Set the CC environment variable to the location of the C compiler to |
|
79 be used. |
|
80 For example, if you are using Sun ONE Studio: |
|
81 % setenv CC /opt/SUNWspro/bin/cc |
|
82 |
|
83 |
|
84 5. Set your PATH environment variable to include the appropriate paths, so that |
|
85 needed binaries can be found during the compilation process. |
|
86 For example, in the csh: |
|
87 |
|
88 % setenv PATH .:/usr/bin:$PATH |
|
89 |
|
90 |
|
91 To build the example: |
|
92 |
|
93 1. Change to the directory where you copied the demo module files. |
|
94 For example: |
|
95 |
|
96 % cd /home/username/demo/demo_module_5 |
|
97 |
|
98 |
|
99 2. Use the make command to generate object files. |
|
100 |
|
101 If you are running the 64-bit SPARC Solaris kernel, type: |
|
102 % /usr/ccs/bin/make |
|
103 |
|
104 If you are running the 32-bit SPARC Solaris kernel, type: |
|
105 % /usr/ccs/bin/make ARCH=32 |
|
106 |
|
107 If you are running the Solaris x86 kernel, type: |
|
108 % /usr/ccs/bin/make ARCH=32 |
|
109 |
|
110 |
|
111 3. Copy the module shared library object to the lib directory you created. |
|
112 For example: |
|
113 |
|
114 % cp demo_module_5.so /home/username/demo/lib |
|
115 |
|
116 |
|
117 4. Copy the SDK-DEMO5-MIB.txt file to the mibs directory you created for |
|
118 the demos. |
|
119 For example: |
|
120 |
|
121 % cp SDK-DEMO5-MIB.txt /home/username/demo/mibs |
|
122 |
|
123 |
|
124 |
|
125 Setting Up Agent to Run the demo_module_5 Module |
|
126 ================================================= |
|
127 |
|
128 1. As root, edit the agent's configuration file /etc/sma/snmp/snmpd.conf, |
|
129 and insert a dlmod statement for the module. This statement enables |
|
130 the agent to load the module. |
|
131 For example: |
|
132 |
|
133 dlmod demo_module_5 /home/username/demo/lib/demo_module_5.so |
|
134 |
|
135 |
|
136 2. As root, start the SMA snmp agent. If the agent is already running, |
|
137 stop and restart it in debug mode. |
|
138 For example: |
|
139 |
|
140 # /etc/init.d/init.sma stop |
|
141 # /usr/sbin/snmpd -Ddemo_module_5 |
|
142 |
|
143 The optional -Ddemo_module_5 argument sends debugging statements from |
|
144 demo_module_5 to the /var/log/snmpd.log file. You can also use the -L |
|
145 and -f options to send debugging statements to the screen instead. |
|
146 |
|
147 When the module is started, the file /var/sma_snmp/demo_module_5.conf |
|
148 is read and then the latest token values are appended to the file. |
|
149 The demo_module_5.conf file is created if it doesn't exist. When you |
|
150 later use snmpset to specify new token values, the new values are |
|
151 appended to the file. |
|
152 |
|
153 |
|
154 |
|
155 Testing the demo_module_5 Module |
|
156 ================================ |
|
157 |
|
158 1. Set your MIBS and MIBDIRS environment variables to |
|
159 include the appropriate paths. |
|
160 For example, in the csh: |
|
161 |
|
162 % setenv MIBDIRS .:/home/username/demo/mibs:/etc/sma/snmp/mibs |
|
163 % setenv MIBS +SDK-DEMO5-MIB |
|
164 |
|
165 Note that step 1 is not required, but it enables snmp commands to access |
|
166 the MIB to provide variable names instead of OIDs in its output. |
|
167 |
|
168 |
|
169 2. Issue an snmpget or snmpwalk request to test the module. |
|
170 For example: |
|
171 |
|
172 % snmpwalk -v1 -c public localhost 1.3.6.1.4.1.42.2.2.4.4.5 |
|
173 |
|
174 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.1 = Gauge32: 1 |
|
175 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.2 = Gauge32: 2 |
|
176 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.3 = Gauge32: 3 |
|
177 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.4 = Gauge32: 4 |
|
178 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.1 = STRING: "/usr/sbin/snmpd" |
|
179 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.2 = STRING: "/tmp/asdf" |
|
180 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.3 = STRING: "/etc/hosts" |
|
181 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.4 = STRING: "/etc/sma/snmp/snmp.conf" |
|
182 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.1 = Gauge32: 229376 |
|
183 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.2 = Gauge32: 17 |
|
184 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.3 = Gauge32: 74 |
|
185 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.4 = Gauge32: 2904 |
|
186 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.1 = STRING: "755" |
|
187 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.2 = STRING: "644" |
|
188 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.3 = STRING: "444" |
|
189 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.4 = STRING: "755" |
|
190 |
|
191 |
|
192 3. Issue an snmpset command to specify a different file name. |
|
193 For example, to monitor file /var/sma_snmp/snmpd.conf: |
|
194 |
|
195 % snmpset -v2c -c private localhost .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.1 \ |
|
196 s "/var/sma_snmp/snmpd.conf" .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.1 = STRING: \ |
|
197 "/var/sma_snmp/snmpd.conf" |
|
198 |
|
199 |
|
200 4. Verify the results of the set request by using the snmpwalk command. |
|
201 For example: |
|
202 |
|
203 % snmpwalk -v1 -c public localhost 1.3.6.1.4.1.42.2.2.4.4.5 |
|
204 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.1 = Gauge32: 1 |
|
205 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.2 = Gauge32: 2 |
|
206 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.3 = Gauge32: 3 |
|
207 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.4 = Gauge32: 4 |
|
208 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.1 = STRING: "/var/sma_snmp/snmpd.conf" |
|
209 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.2 = STRING: "/tmp/asdf" |
|
210 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.3 = STRING: "/etc/hosts" |
|
211 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.4 = STRING: "/etc/sma/snmp/snmp.conf" |
|
212 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.1 = Gauge32: 489 |
|
213 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.2 = Gauge32: 17 |
|
214 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.3 = Gauge32: 74 |
|
215 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.4 = Gauge32: 2904 |
|
216 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.1 = STRING: "600" |
|
217 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.2 = STRING: "644" |
|
218 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.3 = STRING: "444" |
|
219 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.4 = STRING: "755" |
|
220 |
|
221 |
|
222 5. Verify that the file information that you changed is saved across |
|
223 agent restarts by restarting the agent (as root) and repeating the snmpwalk |
|
224 in step 4. |
|
225 |
|
226 For example: |
|
227 |
|
228 # /etc/init.d/init.sma restart |
|
229 # /usr/bin/snmpwalk -v1 -c public localhost 1.3.6.1.4.1.42.2.2.4.4.5 |
|
230 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.1 = Gauge32: 1 |
|
231 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.2 = Gauge32: 2 |
|
232 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.3 = Gauge32: 3 |
|
233 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.1.4 = Gauge32: 4 |
|
234 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.1 = STRING: "/var/sma_snmp/snmpd.conf" |
|
235 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.2 = STRING: "/tmp/asdf" |
|
236 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.3 = STRING: "/etc/hosts" |
|
237 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.2.4 = STRING: "/etc/sma/snmp/snmp.conf" |
|
238 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.1 = Gauge32: 489 |
|
239 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.2 = Gauge32: 17 |
|
240 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.3 = Gauge32: 74 |
|
241 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.3.4 = Gauge32: 2904 |
|
242 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.1 = STRING: "600" |
|
243 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.2 = STRING: "644" |
|
244 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.3 = STRING: "444" |
|
245 .1.3.6.1.4.1.42.2.2.4.4.5.2.1.1.4.4 = STRING: "755" |
|
246 |
|
247 |
|
248 |