Produced by Araxis Merge on 9/25/2018 2:13:03 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\jmx\snmp\daemon | SnmpAdaptorServer.java | Mon Jan 22 14:46:50 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\jmx\snmp\daemon | SnmpAdaptorServer.java | Wed Sep 12 16:27:07 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 4 | 5486 |
Changed | 3 | 6 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 199 7, 2012, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | ||
27 | package co m.sun.jmx. snmp.daemo n; | |
28 | ||
29 | ||
30 | // java im ports | |
31 | // | |
32 | import jav a.util.Vec tor; | |
33 | import jav a.util.Enu meration; | |
34 | import jav a.util.log ging.Level ; | |
35 | import jav a.net.Data gramSocket ; | |
36 | import jav a.net.Data gramPacket ; | |
37 | import jav a.net.Inet Address; | |
38 | import jav a.net.Sock etExceptio n; | |
39 | import jav a.net.Unkn ownHostExc eption; | |
40 | import jav a.io.Objec tInputStre am; | |
41 | import jav a.io.IOExc eption; | |
42 | import jav a.io.Inter ruptedIOEx ception; | |
43 | ||
44 | ||
45 | // jmx imp orts | |
46 | // | |
47 | import jav ax.managem ent.MBeanS erver; | |
48 | import jav ax.managem ent.MBeanR egistratio n; | |
49 | import jav ax.managem ent.Object Name; | |
50 | import sta tic com.su n.jmx.defa ults.JmxPr operties.S NMP_ADAPTO R_LOGGER; | |
51 | import com .sun.jmx.s nmp.SnmpIp Address; | |
52 | import com .sun.jmx.s nmp.SnmpMe ssage; | |
53 | import com .sun.jmx.s nmp.SnmpOi d; | |
54 | import com .sun.jmx.s nmp.SnmpPd uFactory; | |
55 | import com .sun.jmx.s nmp.SnmpPd uPacket; | |
56 | import com .sun.jmx.s nmp.SnmpPd uRequest; | |
57 | import com .sun.jmx.s nmp.SnmpPd uTrap; | |
58 | import com .sun.jmx.s nmp.SnmpTi meticks; | |
59 | import com .sun.jmx.s nmp.SnmpVa rBind; | |
60 | import com .sun.jmx.s nmp.SnmpVa rBindList; | |
61 | import com .sun.jmx.s nmp.SnmpDe finitions; | |
62 | import com .sun.jmx.s nmp.SnmpSt atusExcept ion; | |
63 | import com .sun.jmx.s nmp.SnmpTo oBigExcept ion; | |
64 | import com .sun.jmx.s nmp.InetAd dressAcl; | |
65 | import com .sun.jmx.s nmp.SnmpPe er; | |
66 | import com .sun.jmx.s nmp.SnmpPa rameters; | |
67 | // SNMP Ru ntime impo rts | |
68 | // | |
69 | import com .sun.jmx.s nmp.SnmpPd uFactoryBE R; | |
70 | import com .sun.jmx.s nmp.agent. SnmpMibAge nt; | |
71 | import com .sun.jmx.s nmp.agent. SnmpMibHan dler; | |
72 | import com .sun.jmx.s nmp.agent. SnmpUserDa taFactory; | |
73 | import com .sun.jmx.s nmp.agent. SnmpErrorH andlerAgen t; | |
74 | ||
75 | import com .sun.jmx.s nmp.IPAcl. SnmpAcl; | |
76 | ||
77 | import com .sun.jmx.s nmp.tasks. ThreadServ ice; | |
78 | ||
79 | /** | |
80 | * Impleme nts an ada ptor on to p of the S NMP protoc ol. | |
81 | * <P> | |
82 | * When th is SNMP pr otocol ada ptor is st arted it c reates a d atagram so cket | |
83 | * and is able to re ceive requ ests and s end traps or inform requests. | |
84 | * When it is stoppe d, the soc ket is clo sed and ne ither requ ests | |
85 | * and nor traps/inf orm reques t are proc essed. | |
86 | * <P> | |
87 | * The def ault port number of the socket is 161. T his defaul t value ca n be | |
88 | * changed by specif ying a por t number: | |
89 | * <UL> | |
90 | * <LI>in the object construct or</LI> | |
91 | * <LI>usi ng the {@l ink com.su n.jmx.snmp .daemon.Co mmunicator Server#set Port | |
92 | * set Port} meth od before starting t he adaptor </LI> | |
93 | * </UL> | |
94 | * The def ault objec t name is defined by {@link | |
95 | * com.sun .jmx.snmp. ServiceNam e#DOMAIN c om.sun.jmx .snmp.Serv iceName.DO MAIN} | |
96 | * and {@l ink com.su n.jmx.snmp .ServiceNa me#SNMP_AD APTOR_SERV ER | |
97 | * com.sun .jmx.snmp. ServiceNam e.SNMP_ADA PTOR_SERVE R}. | |
98 | * <P> | |
99 | * The SNM P protocol adaptor s upports ve rsions 1 a nd 2 of th e SNMP pro tocol | |
100 | * in a st ateless wa y: when it receives a v1 reque st, it rep lies with a v1 | |
101 | * respons e, when it receives a v2 reque st it repl ies with a v2 respon se. | |
102 | * <BR>The method {@ link #snmp V1Trap snm pV1Trap} s ends traps using SNM P v1 | |
103 | * format. | |
104 | * The met hod {@link #snmpV2Tr ap snmpV2T rap} sends traps usi ng SNMP v2 format. | |
105 | * The met hod {@link #snmpInfo rmRequest snmpInform Request} s ends infor m | |
106 | * request s using SN MP v2 form at. | |
107 | * <P> | |
108 | * To rece ive data p ackets, th e SNMP pro tocol adap tor uses a buffer | |
109 | * which s ize can be configure d using th e property <CODE>buf ferSize</C ODE> | |
110 | * (defaul t value is 1024). | |
111 | * Packets which do not fit in to the buf fer are re jected. | |
112 | * Increas ing <CODE> bufferSize </CODE> al lows the e xchange of bigger pa ckets. | |
113 | * However , the unde rlying net working sy stem may i mpose a li mit on the size | |
114 | * of UDP packets. | |
115 | * Packets which siz e exceed t his limit will be re jected, no matter wh at | |
116 | * the val ue of <COD E>bufferSi ze</CODE> actually i s. | |
117 | * <P> | |
118 | * An SNMP protocol adaptor ma y serve se veral mana gers concu rrently. T he | |
119 | * number of concurr ent manage rs can be limited us ing the pr operty | |
120 | * <CODE>m axActiveCl ientCount< /CODE>. | |
121 | * <p> | |
122 | * The SNM P protocol adaptor s pecifies a default v alue (10) for the | |
123 | * <CODE>m axActiveCl ientCount< /CODE> pro perty. Whe n the adap tor is sto pped, | |
124 | * the act ive reques ts are int errupted a nd an erro r result i s sent to | |
125 | * the man agers. | |
126 | * <p><b>T his API is a Sun Mic rosystems internal A PI and is subject | |
127 | * to chan ge without notice.</ b></p> | |
128 | */ | |
129 | ||
130 | public cla ss SnmpAda ptorServer extends C ommunicato rServer | |
131 | implem ents SnmpA daptorServ erMBean, M BeanRegist ration, Sn mpDefiniti ons, | |
132 | SnmpM ibHandler { | |
133 | ||
134 | // PRI VATE VARIA BLES | |
135 | //---- ---------- ---- | |
136 | ||
137 | /** | |
138 | * Por t number f or sending SNMP trap s. | |
139 | * <BR >The defau lt value i s 162. | |
140 | */ | |
141 | private in t trapP ORT
|
|
142 | ||
143 | /** | |
144 | * Por t number f or sending SNMP info rm request s. | |
145 | * <BR >The defau lt value i s 162. | |
146 | */ | |
147 | private in t informP ORT
|
|
148 | ||
149 | /** | |
150 | * The <CODE>Ine tAddress</ CODE> used when crea ting the d atagram so cket. | |
151 | * <BR >It is spe cified whe n creating the SNMP protocol a daptor. | |
152 | * If not specif ied, the l ocal host machine is used. | |
153 | */ | |
154 | InetAd dress addr ess = null ; | |
155 | ||
156 | /** | |
157 | * The IP addres s based AC L used by this SNMP protocol a daptor. | |
158 | */ | |
159 | privat e InetAddr essAcl ipa cl = null; | |
160 | ||
161 | /** | |
162 | * The factory o bject. | |
163 | */ | |
164 | privat e SnmpPduF actory pdu Factory = null; | |
165 | ||
166 | /** | |
167 | * The user-data factory o bject. | |
168 | */ | |
169 | privat e SnmpUser DataFactor y userData Factory = null; | |
170 | ||
171 | /** | |
172 | * Ind icates if the SNMP p rotocol ad aptor send s a respon se in case | |
173 | * of authentica tion failu re | |
174 | */ | |
175 | privat e boolean authRespEn abled = tr ue; | |
176 | ||
177 | /** | |
178 | * Ind icates if authentica tion traps are enabl ed. | |
179 | */ | |
180 | privat e boolean authTrapEn abled = tr ue; | |
181 | ||
182 | /** | |
183 | * The enterpris e OID. | |
184 | * <BR >The defau lt value i s "1.3.6.1 .4.1.42". | |
185 | */ | |
186 | privat e SnmpOid enterprise Oid = new SnmpOid("1 .3.6.1.4.1 .42"); | |
187 | ||
188 | /** | |
189 | * The buffer si ze of the SNMP proto col adapto r. | |
190 | * Thi s buffer s ize is use d for both incoming request an d outgoing | |
191 | * inf orm reques ts. | |
192 | * <BR >The defau lt value i s 1024. | |
193 | */ | |
194 | int bu fferSize = 1024; | |
195 | ||
196 | privat e transien t long st artUpTime = 0; | |
197 | privat e transien t Datagram Socket so cket = null ; | |
198 | transi ent Datagr amSocket tr apSocket = null ; | |
199 | privat e transien t SnmpSess ion in formSessio n = null ; | |
200 | privat e transien t Datagram Packet pa cket = null ; | |
201 | transi ent Vector <SnmpMibAg ent> mi bs = new Vector<>() ; | |
202 | privat e transien t SnmpMibT ree ro ot; | |
203 | ||
204 | /** | |
205 | * Whe ther ACL m ust be use d. | |
206 | */ | |
207 | privat e transien t boolean us eAcl = tru e; | |
208 | ||
209 | ||
210 | // SEN DING SNMP INFORMS ST UFF | |
211 | //---- ---------- ---------- --- | |
212 | ||
213 | /** | |
214 | * Num ber of tim es to try an inform request be fore givin g up. | |
215 | * The default n umber is 3 . | |
216 | */ | |
217 | privat e int maxT ries = 3 ; | |
218 | ||
219 | /** | |
220 | * The amount of time to w ait for an inform re sponse fro m the mana ger. | |
221 | * The default a mount of t ime is 300 0 millisec . | |
222 | */ | |
223 | privat e int time out = 3 * 1000 ; | |
224 | ||
225 | // VAR IABLES REQ UIRED FOR IMPLEMENTI NG SNMP GR OUP (MIBII ) | |
226 | //---- ---------- ---------- ---------- ---------- ---------- - | |
227 | ||
228 | /** | |
229 | * The <CODE>snm pOutTraps< /CODE> val ue defined in MIB-II . | |
230 | */ | |
231 | int sn mpOutTraps =0; | |
232 | ||
233 | /** | |
234 | * The <CODE>snm pOutGetRes ponses</CO DE> value defined in MIB-II. | |
235 | */ | |
236 | privat e int snmp OutGetResp onses=0; | |
237 | ||
238 | /** | |
239 | * The <CODE>snm pOutGenErr s</CODE> v alue defin ed in MIB- II. | |
240 | */ | |
241 | privat e int snmp OutGenErrs =0; | |
242 | ||
243 | /** | |
244 | * The <CODE>snm pOutBadVal ues</CODE> value def ined in MI B-II. | |
245 | */ | |
246 | privat e int snmp OutBadValu es=0; | |
247 | ||
248 | /** | |
249 | * The <CODE>snm pOutNoSuch Names</COD E> value d efined in MIB-II. | |
250 | */ | |
251 | privat e int snmp OutNoSuchN ames=0; | |
252 | ||
253 | /** | |
254 | * The <CODE>snm pOutTooBig s</CODE> v alue defin ed in MIB- II. | |
255 | */ | |
256 | privat e int snmp OutTooBigs =0; | |
257 | ||
258 | /** | |
259 | * The <CODE>snm pOutPkts</ CODE> valu e defined in MIB-II. | |
260 | */ | |
261 | int sn mpOutPkts= 0; | |
262 | ||
263 | /** | |
264 | * The <CODE>snm pInASNPars eErrs</COD E> value d efined in MIB-II. | |
265 | */ | |
266 | privat e int snmp InASNParse Errs=0; | |
267 | ||
268 | /** | |
269 | * The <CODE>snm pInBadComm unityUses< /CODE> val ue defined in MIB-II . | |
270 | */ | |
271 | privat e int snmp InBadCommu nityUses=0 ; | |
272 | ||
273 | /** | |
274 | * The <CODE>snm pInBadComm unityNames </CODE> va lue define d in MIB-I I. | |
275 | */ | |
276 | privat e int snmp InBadCommu nityNames= 0; | |
277 | ||
278 | /** | |
279 | * The <CODE>snm pInBadVers ions</CODE > value de fined in M IB-II. | |
280 | */ | |
281 | privat e int snmp InBadVersi ons=0; | |
282 | ||
283 | /** | |
284 | * The <CODE>snm pInGetRequ ests</CODE > value de fined in M IB-II. | |
285 | */ | |
286 | privat e int snmp InGetReque sts=0; | |
287 | ||
288 | /** | |
289 | * The <CODE>snm pInGetNext s</CODE> v alue defin ed in MIB- II. | |
290 | */ | |
291 | privat e int snmp InGetNexts =0; | |
292 | ||
293 | /** | |
294 | * The <CODE>snm pInSetRequ ests</CODE > value de fined in M IB-II. | |
295 | */ | |
296 | privat e int snmp InSetReque sts=0; | |
297 | ||
298 | /** | |
299 | * The <CODE>snm pInPkts</C ODE> value defined i n MIB-II. | |
300 | */ | |
301 | privat e int snmp InPkts=0; | |
302 | ||
303 | /** | |
304 | * The <CODE>snm pInTotalRe qVars</COD E> value d efined in MIB-II. | |
305 | */ | |
306 | privat e int snmp InTotalReq Vars=0; | |
307 | ||
308 | /** | |
309 | * The <CODE>snm pInTotalSe tVars</COD E> value d efined in MIB-II. | |
310 | */ | |
311 | privat e int snmp InTotalSet Vars=0; | |
312 | ||
313 | /** | |
314 | * The <CODE>snm pInTotalSe tVars</COD E> value d efined in rfc 1907 M IB-II. | |
315 | */ | |
316 | privat e int snmp SilentDrop s=0; | |
317 | ||
318 | privat e static f inal Strin g Interrup tSysCallMs g = | |
319 | "I nterrupted system ca ll"; | |
320 | static final Snm pOid sysUp TimeOid = new SnmpOi d("1.3.6.1 .2.1.1.3.0 ") ; | |
321 | static final Snm pOid snmpT rapOidOid = new Snmp Oid("1.3.6 .1.6.3.1.1 .4.1.0"); | |
322 | ||
323 | privat e ThreadSe rvice thre adService; | |
324 | ||
325 | privat e static i nt threadN umber = 6; | |
326 | ||
327 | static { | |
328 | St ring s = S ystem.getP roperty("c om.sun.jmx .snmp.thre adnumber") ; | |
329 | ||
330 | if (s != nul l) { | |
331 | try { | |
332 | thre adNumber = Integer.p arseInt(Sy stem.getPr operty(s)) ; | |
333 | } catch (Exception e) { | |
334 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN ER, | |
335 | SnmpAd aptorServe r.class.ge tName(), | |
336 | "<stat ic init>", | |
337 | "Got w rong value for com.s un.jmx.snm p.threadnu mber: " + | |
338 | s + ". Use the d efault val ue: " + th readNumber ); | |
339 | } | |
340 | } | |
341 | } | |
342 | ||
343 | // PUB LIC CONSTR UCTORS | |
344 | //---- ---------- ------ | |
345 | ||
346 | /** | |
347 | * Ini tializes t his SNMP p rotocol ad aptor usin g the defa ult port ( 161). | |
348 | * Use the {@lin k com.sun. jmx.snmp.I PAcl.SnmpA cl} defaul t | |
349 | * imp lementatio n of the < CODE>InetA ddressAcl< /CODE> int erface. | |
350 | */ | |
351 | public SnmpAdapt orServer() { | |
352 | th is(true, n ull, com.s un.jmx.snm p.ServiceN ame.SNMP_A DAPTOR_POR T, | |
353 | null) ; | |
354 | } | |
355 | ||
356 | /** | |
357 | * Ini tializes t his SNMP p rotocol ad aptor usin g the spec ified port . | |
358 | * Use the {@lin k com.sun. jmx.snmp.I PAcl.SnmpA cl} defaul t | |
359 | * imp lementatio n of the < CODE>InetA ddressAcl< /CODE> int erface. | |
360 | * | |
361 | * @pa ram port T he port nu mber for s ending SNM P response s. | |
362 | */ | |
363 | public SnmpAdapt orServer(i nt port) { | |
364 | th is(true, n ull, port, null) ; | |
365 | } | |
366 | ||
367 | /** | |
368 | * Ini tializes t his SNMP p rotocol ad aptor usin g the defa ult port ( 161) | |
369 | * and the speci fied IP ad dress base d ACL impl ementation . | |
370 | * | |
371 | * @pa ram acl Th e <CODE>In etAddressA cl</CODE> implementa tion. | |
372 | * <code> null</code > means no ACL - eve rybody is authorized . | |
373 | * | |
374 | * @si nce 1.5 | |
375 | */ | |
376 | public SnmpAdapt orServer(I netAddress Acl acl) { | |
377 | th is(false, acl, com.s un.jmx.snm p.ServiceN ame.SNMP_A DAPTOR_POR T, | |
378 | null) ; | |
379 | } | |
380 | ||
381 | /** | |
382 | * Ini tializes t his SNMP p rotocol ad aptor usin g the defa ult port ( 161) | |
383 | * and the | |
384 | * spe cified <CO DE>InetAdd ress</CODE >. | |
385 | * Use the {@lin k com.sun. jmx.snmp.I PAcl.SnmpA cl} defaul t | |
386 | * imp lementatio n of the < CODE>InetA ddressAcl< /CODE> int erface. | |
387 | * | |
388 | * @pa ram addr T he IP addr ess to bin d. | |
389 | */ | |
390 | public SnmpAdapt orServer(I netAddress addr) { | |
391 | th is(true, n ull, com.s un.jmx.snm p.ServiceN ame.SNMP_A DAPTOR_POR T, | |
392 | addr) ; | |
393 | } | |
394 | ||
395 | /** | |
396 | * Ini tializes t his SNMP p rotocol ad aptor usin g the spec ified port and the | |
397 | * spe cified IP address ba sed ACL im plementati on. | |
398 | * | |
399 | * @pa ram acl Th e <CODE>In etAddressA cl</CODE> implementa tion. | |
400 | * <code> null</code > means no ACL - eve rybody is authorized . | |
401 | * @pa ram port T he port nu mber for s ending SNM P response s. | |
402 | * | |
403 | * @si nce 1.5 | |
404 | */ | |
405 | public SnmpAdapt orServer(I netAddress Acl acl, i nt port) { | |
406 | th is(false, acl, port, null) ; | |
407 | } | |
408 | ||
409 | /** | |
410 | * Ini tializes t his SNMP p rotocol ad aptor usin g the spec ified port and the | |
411 | * spe cified <CO DE>InetAdd ress</CODE >. | |
412 | * Use the {@lin k com.sun. jmx.snmp.I PAcl.SnmpA cl} defaul t | |
413 | * imp lementatio n of the < CODE>InetA ddressAcl< /CODE> int erface. | |
414 | * | |
415 | * @pa ram port T he port nu mber for s ending SNM P response s. | |
416 | * @pa ram addr T he IP addr ess to bin d. | |
417 | */ | |
418 | public SnmpAdapt orServer(i nt port, I netAddress addr) { | |
419 | th is(true, n ull, port, addr) ; | |
420 | } | |
421 | ||
422 | /** | |
423 | * Ini tializes t his SNMP p rotocol ad aptor usin g the spec ified IP | |
424 | * add ress based ACL imple mentation and the sp ecified | |
425 | * <CO DE>InetAdd ress</CODE >. | |
426 | * | |
427 | * @pa ram acl Th e <CODE>In etAddressA cl</CODE> implementa tion. | |
428 | * @pa ram addr T he IP addr ess to bin d. | |
429 | * | |
430 | * @si nce 1.5 | |
431 | */ | |
432 | public SnmpAdapt orServer(I netAddress Acl acl, I netAddress addr) { | |
433 | th is(false, acl, com.s un.jmx.snm p.ServiceN ame.SNMP_A DAPTOR_POR T, | |
434 | addr) ; | |
435 | } | |
436 | ||
437 | /** | |
438 | * Ini tializes t his SNMP p rotocol ad aptor usin g the spec ified port , the | |
439 | * spe cified ad dress base d ACL impl ementation and the s pecified | |
440 | * <CO DE>InetAdd ress</CODE >. | |
441 | * | |
442 | * @pa ram acl Th e <CODE>In etAddressA cl</CODE> implementa tion. | |
443 | * @pa ram port T he port nu mber for s ending SNM P response s. | |
444 | * @pa ram addr T he IP addr ess to bin d. | |
445 | * | |
446 | * @si nce 1.5 | |
447 | */ | |
448 | public SnmpAdapt orServer(I netAddress Acl acl, i nt port, I netAddress addr) { | |
449 | th is(false, acl, port, addr); | |
450 | } | |
451 | ||
452 | /** | |
453 | * Ini tializes t his SNMP p rotocol ad aptor usin g the spec ified port and the | |
454 | * spe cified <CO DE>InetAdd ress</CODE >. | |
455 | * Thi s construc tor allows to initia lize an SN MP adaptor without u sing | |
456 | * the ACL mecha nism (by s etting the <CODE>use Acl</CODE> parameter to | |
457 | * fal se). | |
458 | * <br >This cons tructor mu st be used in partic ular with a platform that | |
459 | * doe s not supp ort the <C ODE>java.s ecurity.ac l</CODE> p ackage lik e pJava. | |
460 | * | |
461 | * @pa ram useAcl Specifies if this n ew SNMP ad aptor uses the ACL m echanism. | |
462 | * If the specif ied parame ter is set to <CODE> true</CODE >, this | |
463 | * con structor i s equivale nt to | |
464 | * <CO DE>SnmpAda ptorServer ((int)port ,(InetAddr ess)addr)< /CODE>. | |
465 | * @pa ram port T he port nu mber for s ending SNM P response s. | |
466 | * @pa ram addr T he IP addr ess to bin d. | |
467 | */ | |
468 | public SnmpAdapt orServer(b oolean use Acl, int p ort, InetA ddress add r) { | |
469 | th is(useAcl, null,port, addr); | |
470 | } | |
471 | ||
472 | // If forceAcl i s `true' a nd InetAdd ressAcl is null, the n a defaul t | |
473 | // Snm pAcl objec t is creat ed. | |
474 | // | |
475 | privat e SnmpAdap torServer( boolean fo rceAcl, In etAddressA cl acl, | |
476 | int port, InetAddres s addr) { | |
477 | su per(Commun icatorServ er.SNMP_TY PE) ; | |
478 | ||
479 | ||
480 | // Initializ e the ACL implementa tion. | |
481 | // | |
482 | if (acl == n ull && for ceAcl) { | |
483 | try { | |
484 | acl = new Snmp Acl("SNMP protocol a daptor IP ACL"); | |
485 | } catch (UnknownHo stExceptio n e) { | |
486 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
487 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, d bgTag, | |
488 | "const ructor", " UnknowHost Exception when creat ing ACL",e ); | |
489 | } | |
490 | } | |
491 | } else { | |
492 | this.use Acl = (acl !=null) || forceAcl; | |
493 | } | |
494 | ||
495 | in it(acl, po rt, addr) ; | |
496 | } | |
497 | ||
498 | // GET TERS AND S ETTERS | |
499 | //---- ---------- ------ | |
500 | ||
501 | /** | |
502 | * Get s the numb er of mana gers that have been processed by this | |
503 | * SNM P protocol adaptor since its creation. | |
504 | * | |
505 | * @re turn The n umber of m anagers ha ndled by t his SNMP p rotocol ad aptor | |
506 | * sin ce its cre ation. Thi s counter is not res et by the <CODE>stop </CODE> | |
507 | * met hod. | |
508 | */ | |
509 | @Overr ide | |
510 | public int getSe rvedClient Count() { | |
511 | re turn super .getServed ClientCoun t(); | |
512 | } | |
513 | ||
514 | /** | |
515 | * Get s the numb er of mana gers curre ntly being processed by this | |
516 | * SNM P protocol adaptor. | |
517 | * | |
518 | * @re turn The n umber of m anagers cu rrently be ing proces sed by thi s | |
519 | * SNM P protocol adaptor. | |
520 | */ | |
521 | @Overr ide | |
522 | public int getAc tiveClient Count() { | |
523 | re turn super .getActive ClientCoun t(); | |
524 | } | |
525 | ||
526 | /** | |
527 | * Get s the maxi mum number of manage rs that th is SNMP pr otocol ada ptor can | |
528 | * pro cess concu rrently. | |
529 | * | |
530 | * @re turn The m aximum num ber of man agers that this SNMP protocol adaptor | |
531 | * can p rocess con currently. | |
532 | */ | |
533 | @Overr ide | |
534 | public int getMa xActiveCli entCount() { | |
535 | re turn super .getMaxAct iveClientC ount(); | |
536 | } | |
537 | ||
538 | /** | |
539 | * Set s the maxi mum number of manage rs this SN MP protoco l adaptor can | |
540 | * pro cess concu rrently. | |
541 | * | |
542 | * @pa ram c The number of managers. | |
543 | * | |
544 | * @ex ception ja va.lang.Il legalState Exception This metho d has been invoked | |
545 | * whi le the com municator was <CODE> ONLINE</CO DE> or <CO DE>STARTIN G</CODE>. | |
546 | */ | |
547 | @Overr ide | |
548 | public void setM axActiveCl ientCount( int c) | |
549 | th rows java. lang.Illeg alStateExc eption { | |
550 | su per.setMax ActiveClie ntCount(c) ; | |
551 | } | |
552 | ||
553 | /** | |
554 | * Ret urns the I p address based ACL used by th is SNMP pr otocol ada ptor. | |
555 | * @re turn The < CODE>InetA ddressAcl< /CODE> imp lementatio n. | |
556 | * | |
557 | * @si nce 1.5 | |
558 | */ | |
559 | @Overr ide | |
560 | public InetAddre ssAcl getI netAddress Acl() { | |
561 | re turn ipacl ; | |
562 | } | |
563 | ||
564 | /** | |
565 | * Ret urns the p ort used b y this SNM P protocol adaptor f or sending traps. | |
566 | * By default, p ort 162 is used. | |
567 | * | |
568 | * @re turn The p ort number for sendi ng SNMP tr aps. | |
569 | */ | |
570 | @Overr ide | |
571 | public Integer g etTrapPort () { | |
572 | re turn new I nteger(tra pPort) ; | |
573 | } | |
574 | ||
575 | /** | |
576 | * Set s the port used by t his SNMP p rotocol ad aptor for sending tr aps. | |
577 | * | |
578 | * @pa ram port T he port nu mber for s ending SNM P traps. | |
579 | */ | |
580 | @Overr ide | |
581 | public void setT rapPort(In teger port ) { | |
582 | se tTrapPort( port.intVa lue()); | |
583 | } | |
584 | ||
585 | /** | |
586 | * Set s the port used by t his SNMP p rotocol ad aptor for sending tr aps. | |
587 | * | |
588 | * @pa ram port T he port nu mber for s ending SNM P traps. | |
589 | */ | |
590 | public void setT rapPort(in t port) { | |
591 | in t val= por t ; | |
592 | if (val < 0) throw new | |
593 | IllegalA rgumentExc eption("Tr ap port ca nnot be a negative v alue"); | |
594 | tr apPort= va l ; | |
595 | } | |
596 | ||
597 | /** | |
598 | * Ret urns the p ort used b y this SNM P protocol adaptor f or sending | |
599 | * inf orm reques ts. By def ault, port 162 is us ed. | |
600 | * | |
601 | * @re turn The p ort number for sendi ng SNMP in form reque sts. | |
602 | */ | |
603 | @Overr ide | |
604 | public int getIn formPort() { | |
605 | re turn infor mPort; | |
606 | } | |
607 | ||
608 | /** | |
609 | * Set s the port used by t his SNMP p rotocol ad aptor for sending | |
610 | * inf orm reques ts. | |
611 | * | |
612 | * @pa ram port T he port nu mber for s ending SNM P inform r equests. | |
613 | */ | |
614 | @Overr ide | |
615 | public void setI nformPort( int port) { | |
616 | if (port < 0 ) | |
617 | throw ne w IllegalA rgumentExc eption("In form reque st port "+ | |
618 | "ca nnot be a negative v alue"); | |
619 | in formPort= port ; | |
620 | } | |
621 | ||
622 | /** | |
623 | * Ret urns the p rotocol of this SNMP protocol adaptor. | |
624 | * | |
625 | * @re turn The s tring "snm p". | |
626 | */ | |
627 | @Overr ide | |
628 | public String ge tProtocol( ) { | |
629 | re turn "snmp "; | |
630 | } | |
631 | ||
632 | /** | |
633 | * Ret urns the b uffer size of this S NMP protoc ol adaptor . | |
634 | * Thi s buffer s ize is use d for both incoming request an d outgoing | |
635 | * inf orm reques ts. | |
636 | * By default, b uffer size 1024 is u sed. | |
637 | * | |
638 | * @re turn The b uffer size . | |
639 | */ | |
640 | @Overr ide | |
641 | public Integer g etBufferSi ze() { | |
642 | re turn new I nteger(buf ferSize) ; | |
643 | } | |
644 | ||
645 | /** | |
646 | * Set s the buff er size of this SNMP protocol adaptor. | |
647 | * Thi s buffer s ize is use d for both incoming request an d outgoing | |
648 | * inf orm reques ts. | |
649 | * | |
650 | * @pa ram s The buffer siz e. | |
651 | * | |
652 | * @ex ception ja va.lang.Il legalState Exception This metho d has been invoked | |
653 | * whi le the com municator was <CODE> ONLINE</CO DE> or <CO DE>STARTIN G</CODE>. | |
654 | */ | |
655 | @Overr ide | |
656 | public void setB ufferSize( Integer s) | |
657 | th rows java. lang.Illeg alStateExc eption { | |
658 | if ((state = = ONLINE) || (state == STARTIN G)) { | |
659 | throw ne w IllegalS tateExcept ion("Stop server bef ore carryi ng out"+ | |
660 | " this operation "); | |
661 | } | |
662 | bu fferSize = s.intValu e() ; | |
663 | } | |
664 | ||
665 | /** | |
666 | * Get s the numb er of time s to try s ending an inform req uest befor e | |
667 | * giv ing up. | |
668 | * By default, a maximum o f 3 tries is used. | |
669 | * @re turn The m aximun num ber of tri es. | |
670 | */ | |
671 | @Overr ide | |
672 | final public int getMaxTri es() { | |
673 | re turn maxTr ies; | |
674 | } | |
675 | ||
676 | /** | |
677 | * Cha nges the m aximun num ber of tim es to try sending an inform | |
678 | * req uest befor e giving u p. | |
679 | * @pa ram newMax Tries The maximun nu mber of tr ies. | |
680 | */ | |
681 | @Overr ide | |
682 | final public syn chronized void setMa xTries(int newMaxTri es) { | |
683 | if (newMaxTr ies < 0) | |
684 | throw ne w IllegalA rgumentExc eption(); | |
685 | ma xTries = n ewMaxTries ; | |
686 | } | |
687 | ||
688 | /** | |
689 | * Get s the time out to wai t for an i nform resp onse from the manage r. | |
690 | * By default, a timeout o f 3 second s is used. | |
691 | * @re turn The v alue of th e timeout property. | |
692 | */ | |
693 | @Overr ide | |
694 | final public int getTimeou t() { | |
695 | re turn timeo ut; | |
696 | } | |
697 | ||
698 | /** | |
699 | * Cha nges the t imeout to wait for a n inform r esponse fr om the man ager. | |
700 | * @pa ram newTim eout The t imeout (in milliseco nds). | |
701 | */ | |
702 | @Overr ide | |
703 | final public syn chronized void setTi meout(int newTimeout ) { | |
704 | if (newTimeo ut < 0) | |
705 | throw ne w IllegalA rgumentExc eption(); | |
706 | ti meout= new Timeout; | |
707 | } | |
708 | ||
709 | /** | |
710 | * Ret urns the m essage fac tory of th is SNMP pr otocol ada ptor. | |
711 | * | |
712 | * @re turn The f actory obj ect. | |
713 | */ | |
714 | @Overr ide | |
715 | public SnmpPduFa ctory getP duFactory( ) { | |
716 | re turn pduFa ctory ; | |
717 | } | |
718 | ||
719 | /** | |
720 | * Set s the mess age factor y of this SNMP proto col adapto r. | |
721 | * | |
722 | * @pa ram factor y The fact ory object (null mea ns the def ault facto ry). | |
723 | */ | |
724 | @Overr ide | |
725 | public void setP duFactory( SnmpPduFac tory facto ry) { | |
726 | if (factory == null) | |
727 | pduFacto ry = new S nmpPduFact oryBER() ; | |
728 | el se | |
729 | pduFacto ry = facto ry ; | |
730 | } | |
731 | ||
732 | /** | |
733 | * Set the user- data facto ry of this SNMP prot ocol adapt or. | |
734 | * | |
735 | * @pa ram factor y The fact ory object (null mea ns no fact ory). | |
736 | * @se e com.sun. jmx.snmp.a gent.SnmpU serDataFac tory | |
737 | */ | |
738 | @Overr ide | |
739 | public void setU serDataFac tory(SnmpU serDataFac tory facto ry) { | |
740 | us erDataFact ory = fact ory ; | |
741 | } | |
742 | ||
743 | /** | |
744 | * Get the user- data facto ry associa ted with t his SNMP p rotocol ad aptor. | |
745 | * | |
746 | * @re turn The f actory obj ect (null means no f actory). | |
747 | * @se e com.sun. jmx.snmp.a gent.SnmpU serDataFac tory | |
748 | */ | |
749 | @Overr ide | |
750 | public SnmpUserD ataFactory getUserDa taFactory( ) { | |
751 | re turn userD ataFactory ; | |
752 | } | |
753 | ||
754 | /** | |
755 | * Ret urns <CODE >true</COD E> if auth entication traps are enabled. | |
756 | * <P> | |
757 | * Whe n this fea ture is en abled, the SNMP prot ocol adapt or sends | |
758 | * an <CODE>auth entication Failure</C ODE> trap each time an | |
759 | * aut henticatio n fails. | |
760 | * <P> | |
761 | * The default b ehaviour i s to send authentica tion traps . | |
762 | * | |
763 | * @re turn <CODE >true</COD E> if auth entication traps are enabled, | |
764 | * <CODE >false</CO DE> otherw ise. | |
765 | */ | |
766 | @Overr ide | |
767 | public boolean g etAuthTrap Enabled() { | |
768 | re turn authT rapEnabled ; | |
769 | } | |
770 | ||
771 | /** | |
772 | * Set s the flag indicatin g if traps need to b e sent in case of | |
773 | * aut henticatio n failure. | |
774 | * | |
775 | * @pa ram enable d Flag ind icating if traps nee d to be se nt. | |
776 | */ | |
777 | @Overr ide | |
778 | public void setA uthTrapEna bled(boole an enabled ) { | |
779 | au thTrapEnab led = enab led ; | |
780 | } | |
781 | ||
782 | /** | |
783 | * Ret urns <code >true</cod e> if this SNMP prot ocol adapt or sends a | |
784 | * res ponse in c ase of aut henticatio n failure. | |
785 | * <P> | |
786 | * Whe n this fea ture is en abled, the SNMP prot ocol adapt or sends a | |
787 | * res ponse with <CODE>noS uchName</C ODE> or <C ODE>readOn ly</CODE> when | |
788 | * the authentic ation fail ed. If the flag is d isabled, t he | |
789 | * SNM P protocol adaptor t rashes the PDU silen tly. | |
790 | * <P> | |
791 | * The default b ehavior is to send r esponses. | |
792 | * | |
793 | * @re turn <CODE >true</COD E> if resp onses are sent. | |
794 | */ | |
795 | @Overr ide | |
796 | public boolean g etAuthResp Enabled() { | |
797 | re turn authR espEnabled ; | |
798 | } | |
799 | ||
800 | /** | |
801 | * Set s the flag indicatin g if respo nses need to be sent in case o f | |
802 | * aut henticatio n failure. | |
803 | * | |
804 | * @pa ram enable d Flag ind icating if responses need to b e sent. | |
805 | */ | |
806 | @Overr ide | |
807 | public void setA uthRespEna bled(boole an enabled ) { | |
808 | au thRespEnab led = enab led ; | |
809 | } | |
810 | ||
811 | /** | |
812 | * Ret urns the e nterprise OID. It is used by | |
813 | * {@l ink #snmpV 1Trap snmp V1Trap} to fill the 'enterpris e' field o f the | |
814 | * tra p request. | |
815 | * | |
816 | * @re turn The O ID in stri ng format "x.x.x.x". | |
817 | */ | |
818 | @Overr ide | |
819 | public String ge tEnterpris eOid() { | |
820 | re turn enter priseOid.t oString() ; | |
821 | } | |
822 | ||
823 | /** | |
824 | * Set s the ente rprise OID . | |
825 | * | |
826 | * @pa ram oid Th e OID in s tring form at "x.x.x. x". | |
827 | * | |
828 | * @ex ception Il legalArgum entExcepti on The str ing format is incorr ect | |
829 | */ | |
830 | @Overr ide | |
831 | public void setE nterpriseO id(String oid) throw s IllegalA rgumentExc eption { | |
832 | en terpriseOi d = new Sn mpOid(oid) ; | |
833 | } | |
834 | ||
835 | /** | |
836 | * Ret urns the n ames of th e MIBs ava ilable in this SNMP protocol a daptor. | |
837 | * | |
838 | * @re turn An ar ray of MIB names. | |
839 | */ | |
840 | @Overr ide | |
841 | public String[] getMibs() { | |
842 | St ring[] res ult = new String[mib s.size()] ; | |
843 | in t i = 0 ; | |
844 | fo r (Enumera tion<SnmpM ibAgent> e = mibs.el ements() ; e.hasMore Elements() ;) { | |
845 | SnmpMibA gent mib = e.nextEle ment() ; | |
846 | result[i ++] = mib. getMibName (); | |
847 | } | |
848 | re turn resul t ; | |
849 | } | |
850 | ||
851 | // GET TERS FOR S NMP GROUP (MIBII) | |
852 | //---- ---------- ---------- ------- | |
853 | ||
854 | /** | |
855 | * Ret urns the < CODE>snmpO utTraps</C ODE> value defined i n MIB-II. | |
856 | * | |
857 | * @re turn The < CODE>snmpO utTraps</C ODE> value . | |
858 | */ | |
859 | @Overr ide | |
860 | public Long getS nmpOutTrap s() { | |
861 | re turn new L ong(snmpOu tTraps); | |
862 | } | |
863 | ||
864 | /** | |
865 | * Ret urns the < CODE>snmpO utGetRespo nses</CODE > value de fined in M IB-II. | |
866 | * | |
867 | * @re turn The < CODE>snmpO utGetRespo nses</CODE > value. | |
868 | */ | |
869 | @Overr ide | |
870 | public Long getS nmpOutGetR esponses() { | |
871 | re turn new L ong(snmpOu tGetRespon ses); | |
872 | } | |
873 | ||
874 | /** | |
875 | * Ret urns the < CODE>snmpO utGenErrs< /CODE> val ue defined in MIB-II . | |
876 | * | |
877 | * @re turn The < CODE>snmpO utGenErrs< /CODE> val ue. | |
878 | */ | |
879 | @Overr ide | |
880 | public Long getS nmpOutGenE rrs() { | |
881 | re turn new L ong(snmpOu tGenErrs); | |
882 | } | |
883 | ||
884 | /** | |
885 | * Ret urns the < CODE>snmpO utBadValue s</CODE> v alue defin ed in MIB- II. | |
886 | * | |
887 | * @re turn The < CODE>snmpO utBadValue s</CODE> v alue. | |
888 | */ | |
889 | @Overr ide | |
890 | public Long getS nmpOutBadV alues() { | |
891 | re turn new L ong(snmpOu tBadValues ); | |
892 | } | |
893 | ||
894 | /** | |
895 | * Ret urns the < CODE>snmpO utNoSuchNa mes</CODE> value def ined in MI B-II. | |
896 | * | |
897 | * @re turn The < CODE>snmpO utNoSuchNa mes</CODE> value. | |
898 | */ | |
899 | @Overr ide | |
900 | public Long getS nmpOutNoSu chNames() { | |
901 | re turn new L ong(snmpOu tNoSuchNam es); | |
902 | } | |
903 | ||
904 | /** | |
905 | * Ret urns the < CODE>snmpO utTooBigs< /CODE> val ue defined in MIB-II . | |
906 | * | |
907 | * @re turn The < CODE>snmpO utTooBigs< /CODE> val ue. | |
908 | */ | |
909 | @Overr ide | |
910 | public Long getS nmpOutTooB igs() { | |
911 | re turn new L ong(snmpOu tTooBigs); | |
912 | } | |
913 | ||
914 | /** | |
915 | * Ret urns the < CODE>snmpI nASNParseE rrs</CODE> value def ined in MI B-II. | |
916 | * | |
917 | * @re turn The < CODE>snmpI nASNParseE rrs</CODE> value. | |
918 | */ | |
919 | @Overr ide | |
920 | public Long getS nmpInASNPa rseErrs() { | |
921 | re turn new L ong(snmpIn ASNParseEr rs); | |
922 | } | |
923 | ||
924 | /** | |
925 | * Ret urns the < CODE>snmpI nBadCommun ityUses</C ODE> value defined i n MIB-II. | |
926 | * | |
927 | * @re turn The < CODE>snmpI nBadCommun ityUses</C ODE> value . | |
928 | */ | |
929 | @Overr ide | |
930 | public Long getS nmpInBadCo mmunityUse s() { | |
931 | re turn new L ong(snmpIn BadCommuni tyUses); | |
932 | } | |
933 | ||
934 | /** | |
935 | * Ret urns the < CODE>snmpI nBadCommun ityNames</ CODE> valu e defined in | |
936 | * MIB -II. | |
937 | * | |
938 | * @re turn The < CODE>snmpI nBadCommun ityNames</ CODE> valu e. | |
939 | */ | |
940 | @Overr ide | |
941 | public Long getS nmpInBadCo mmunityNam es() { | |
942 | re turn new L ong(snmpIn BadCommuni tyNames); | |
943 | } | |
944 | ||
945 | /** | |
946 | * Ret urns the < CODE>snmpI nBadVersio ns</CODE> value defi ned in MIB -II. | |
947 | * | |
948 | * @re turn The < CODE>snmpI nBadVersio ns</CODE> value. | |
949 | */ | |
950 | @Overr ide | |
951 | public Long getS nmpInBadVe rsions() { | |
952 | re turn new L ong(snmpIn BadVersion s); | |
953 | } | |
954 | ||
955 | /** | |
956 | * Ret urns the < CODE>snmpO utPkts</CO DE> value defined in MIB-II. | |
957 | * | |
958 | * @re turn The < CODE>snmpO utPkts</CO DE> value. | |
959 | */ | |
960 | @Overr ide | |
961 | public Long getS nmpOutPkts () { | |
962 | re turn new L ong(snmpOu tPkts); | |
963 | } | |
964 | ||
965 | /** | |
966 | * Ret urns the < CODE>snmpI nPkts</COD E> value d efined in MIB-II. | |
967 | * | |
968 | * @re turn The < CODE>snmpI nPkts</COD E> value. | |
969 | */ | |
970 | @Overr ide | |
971 | public Long getS nmpInPkts( ) { | |
972 | re turn new L ong(snmpIn Pkts); | |
973 | } | |
974 | ||
975 | /** | |
976 | * Ret urns the < CODE>snmpI nGetReques ts</CODE> value defi ned in MIB -II. | |
977 | * | |
978 | * @re turn The < CODE>snmpI nGetReques ts</CODE> value. | |
979 | */ | |
980 | @Overr ide | |
981 | public Long getS nmpInGetRe quests() { | |
982 | re turn new L ong(snmpIn GetRequest s); | |
983 | } | |
984 | ||
985 | /** | |
986 | * Ret urns the < CODE>snmpI nGetNexts< /CODE> val ue defined in MIB-II . | |
987 | * | |
988 | * @re turn The < CODE>snmpI nGetNexts< /CODE> val ue. | |
989 | */ | |
990 | @Overr ide | |
991 | public Long getS nmpInGetNe xts() { | |
992 | re turn new L ong(snmpIn GetNexts); | |
993 | } | |
994 | ||
995 | /** | |
996 | * Ret urns the < CODE>snmpI nSetReques ts</CODE> value defi ned in MIB -II. | |
997 | * | |
998 | * @re turn The < CODE>snmpI nSetReques ts</CODE> value. | |
999 | */ | |
1000 | @Overr ide | |
1001 | public Long getS nmpInSetRe quests() { | |
1002 | re turn new L ong(snmpIn SetRequest s); | |
1003 | } | |
1004 | ||
1005 | /** | |
1006 | * Ret urns the < CODE>snmpI nTotalSetV ars</CODE> value def ined in MI B-II. | |
1007 | * | |
1008 | * @re turn The < CODE>snmpI nTotalSetV ars</CODE> value. | |
1009 | */ | |
1010 | @Overr ide | |
1011 | public Long getS nmpInTotal SetVars() { | |
1012 | re turn new L ong(snmpIn TotalSetVa rs); | |
1013 | } | |
1014 | ||
1015 | /** | |
1016 | * Ret urns the < CODE>snmpI nTotalReqV ars</CODE> value def ined in MI B-II. | |
1017 | * | |
1018 | * @re turn The < CODE>snmpI nTotalReqV ars</CODE> value. | |
1019 | */ | |
1020 | @Overr ide | |
1021 | public Long getS nmpInTotal ReqVars() { | |
1022 | re turn new L ong(snmpIn TotalReqVa rs); | |
1023 | } | |
1024 | ||
1025 | /** | |
1026 | * Ret urns the < CODE>snmpS ilentDrops </CODE> va lue define d in RFC | |
1027 | * 190 7 NMPv2-MI B . | |
1028 | * | |
1029 | * @re turn The < CODE>snmpS ilentDrops </CODE> va lue. | |
1030 | * | |
1031 | * @si nce 1.5 | |
1032 | */ | |
1033 | @Overr ide | |
1034 | public Long getS nmpSilentD rops() { | |
1035 | re turn new L ong(snmpSi lentDrops) ; | |
1036 | } | |
1037 | ||
1038 | /** | |
1039 | * Ret urns the < CODE>snmpP roxyDrops< /CODE> val ue defined in RFC | |
1040 | * 190 7 NMPv2-MI B . | |
1041 | * | |
1042 | * @re turn The < CODE>snmpP roxyDrops< /CODE> val ue. | |
1043 | * | |
1044 | * @si nce 1.5 | |
1045 | */ | |
1046 | @Overr ide | |
1047 | public Long getS nmpProxyDr ops() { | |
1048 | re turn new L ong(0); | |
1049 | } | |
1050 | ||
1051 | ||
1052 | // PUB LIC METHOD S | |
1053 | //---- ---------- - | |
1054 | ||
1055 | /** | |
1056 | * All ows the MB ean to per form any o perations it needs b efore bein g | |
1057 | * reg istered in the MBean server. | |
1058 | * If the name o f the SNMP protocol adaptor MB ean is not specified , | |
1059 | * it is initial ized with the defaul t value: | |
1060 | * {@l ink com.su n.jmx.snmp .ServiceNa me#DOMAIN | |
1061 | * c om.sun.jmx .snmp.Serv iceName.DO MAIN}:{@li nk | |
1062 | * com .sun.jmx.s nmp.Servic eName#SNMP _ADAPTOR_S ERVER | |
1063 | * com .sun.jmx.s nmp.Servic eName.SNMP _ADAPTOR_S ERVER}. | |
1064 | * If any except ion is rai sed, the S NMP protoc ol adaptor MBean wil l | |
1065 | * not be regist ered in th e MBean se rver. | |
1066 | * | |
1067 | * @pa ram server The MBean server to register the servic e with. | |
1068 | * @pa ram name T he object name. | |
1069 | * | |
1070 | * @re turn The n ame of the SNMP prot ocol adapt or registe red. | |
1071 | * | |
1072 | * @ex ception ja va.lang.Ex ception | |
1073 | */ | |
1074 | @Overr ide | |
1075 | public ObjectNam e preRegis ter(MBeanS erver serv er, Object Name name) | |
1076 | th rows java. lang.Excep tion { | |
1077 | ||
1078 | if (name == null) { | |
1079 | name = n ew ObjectN ame(server .getDefaul tDomain() + ":" + | |
1080 | c om.sun.jmx .snmp.Serv iceName.SN MP_ADAPTOR _SERVER); | |
1081 | } | |
1082 | re turn (supe r.preRegis ter(server , name)); | |
1083 | } | |
1084 | ||
1085 | /** | |
1086 | * Not used in t his contex t. | |
1087 | */ | |
1088 | @Overr ide | |
1089 | public void post Register ( Boolean re gistration Done) { | |
1090 | su per.postRe gister(reg istrationD one); | |
1091 | } | |
1092 | ||
1093 | /** | |
1094 | * Not used in t his contex t. | |
1095 | */ | |
1096 | @Overr ide | |
1097 | public void preD eregister( ) throws j ava.lang.E xception { | |
1098 | su per.preDer egister(); | |
1099 | } | |
1100 | ||
1101 | /** | |
1102 | * Not used in t his contex t. | |
1103 | */ | |
1104 | @Overr ide | |
1105 | public void post Deregister () { | |
1106 | su per.postDe register() ; | |
1107 | } | |
1108 | ||
1109 | /** | |
1110 | * Add s a new MI B in the S NMP MIB ha ndler. | |
1111 | * | |
1112 | * @pa ram mib Th e MIB to a dd. | |
1113 | * | |
1114 | * @re turn A ref erence to the SNMP M IB handler . | |
1115 | * | |
1116 | * @ex ception Il legalArgum entExcepti on If the parameter is null. | |
1117 | */ | |
1118 | @Overr ide | |
1119 | public SnmpMibHa ndler addM ib(SnmpMib Agent mib) | |
1120 | th rows Illeg alArgument Exception { | |
1121 | if (mib == n ull) { | |
1122 | throw ne w IllegalA rgumentExc eption() ; | |
1123 | } | |
1124 | ||
1125 | if (!mibs.con tains(mib) ) | |
1126 | mibs.add Element(mi b); | |
1127 | ||
1128 | ro ot.registe r(mib); | |
1129 | ||
1130 | re turn this; | |
1131 | } | |
1132 | ||
1133 | /** | |
1134 | * Add s a new MI B in the S NMP MIB ha ndler. | |
1135 | * Thi s method i s to be ca lled to se t a specif ic agent t o a specif ic OID. | |
1136 | * Thi s can be u seful when dealing w ith MIB ov erlapping. | |
1137 | * Som e OID can be impleme nted in mo re than on e MIB. In this case, | |
1138 | * the OID neare r agent wi ll be used on SNMP o perations. | |
1139 | * | |
1140 | * @pa ram mib Th e MIB to a dd. | |
1141 | * @pa ram oids T he set of OIDs this agent impl ements. | |
1142 | * | |
1143 | * @re turn A ref erence to the SNMP M IB handler . | |
1144 | * | |
1145 | * @ex ception Il legalArgum entExcepti on If the parameter is null. | |
1146 | * | |
1147 | * @si nce 1.5 | |
1148 | */ | |
1149 | @Overr ide | |
1150 | public SnmpMibHa ndler addM ib(SnmpMib Agent mib, SnmpOid[] oids) | |
1151 | th rows Illeg alArgument Exception { | |
1152 | if (mib == n ull) { | |
1153 | throw ne w IllegalA rgumentExc eption() ; | |
1154 | } | |
1155 | ||
1156 | // If null oi d array, j ust add it to the mi b. | |
1157 | if (oids == n ull) | |
1158 | return a ddMib(mib) ; | |
1159 | ||
1160 | if (!mibs.con tains(mib) ) | |
1161 | mibs.add Element(mi b); | |
1162 | ||
1163 | fo r (int i = 0; i < oi ds.length; i++) { | |
1164 | root.reg ister(mib, oids[i].l ongValue() ); | |
1165 | } | |
1166 | re turn this; | |
1167 | } | |
1168 | ||
1169 | /** | |
1170 | * Add s a new MI B in the S NMP MIB ha ndler. In SNMP V1 an d V2 the | |
1171 | * <CO DE>context Name</CODE > is usele ss and thi s method | |
1172 | * is equivalent to <CODE> addMib(Snm pMibAgent mib)</CODE >. | |
1173 | * | |
1174 | * @pa ram mib Th e MIB to a dd. | |
1175 | * @pa ram contex tName The MIB contex t name. | |
1176 | * @re turn A ref erence on the SNMP M IB handler . | |
1177 | * | |
1178 | * @ex ception Il legalArgum entExcepti on If the parameter is null. | |
1179 | * | |
1180 | * @si nce 1.5 | |
1181 | */ | |
1182 | @Overr ide | |
1183 | public SnmpMibHa ndler addM ib(SnmpMib Agent mib, String co ntextName) | |
1184 | th rows Illeg alArgument Exception { | |
1185 | re turn addMi b(mib); | |
1186 | } | |
1187 | ||
1188 | /** | |
1189 | * Add s a new MI B in the S NMP MIB ha ndler. In SNMP V1 an d V2 the | |
1190 | * <CO DE>context Name</CODE > is usele ss and thi s method | |
1191 | * is equivalent to <CODE> addMib(Snm pMibAgent mib, SnmpO id[] oids) </CODE>. | |
1192 | * | |
1193 | * @pa ram mib Th e MIB to a dd. | |
1194 | * @pa ram contex tName The MIB contex t. If null is passed , will be | |
1195 | * regist ered in th e default context. | |
1196 | * @pa ram oids T he set of OIDs this agent impl ements. | |
1197 | * | |
1198 | * @re turn A ref erence to the SNMP M IB handler . | |
1199 | * | |
1200 | * @ex ception Il legalArgum entExcepti on If the parameter is null. | |
1201 | * | |
1202 | * @si nce 1.5 | |
1203 | */ | |
1204 | @Overr ide | |
1205 | public SnmpMibHa ndler addM ib(SnmpMib Agent mib, | |
1206 | String contextNam e, | |
1207 | SnmpOid [] oids) | |
1208 | th rows Illeg alArgument Exception { | |
1209 | ||
1210 | re turn addMi b(mib, oid s); | |
1211 | } | |
1212 | ||
1213 | /** | |
1214 | * Rem oves the s pecified M IB from th e SNMP pro tocol adap tor. | |
1215 | * In SNMP V1 an d V2 the < CODE>conte xtName</CO DE> is use less and t his | |
1216 | * met hod is equ ivalent to <CODE>rem oveMib(Snm pMibAgent mib)</CODE >. | |
1217 | * | |
1218 | * @pa ram mib Th e MIB to b e removed. | |
1219 | * @pa ram contex tName The context na me used at registrat ion time. | |
1220 | * | |
1221 | * @re turn <CODE >true</COD E> if the specified <CODE>mib< /CODE> was | |
1222 | * a M IB include d in the S NMP MIB ha ndler, <CO DE>false</ CODE> | |
1223 | * oth erwise. | |
1224 | * | |
1225 | * @si nce 1.5 | |
1226 | */ | |
1227 | @Overr ide | |
1228 | public boolean r emoveMib(S nmpMibAgen t mib, Str ing contex tName) { | |
1229 | re turn remov eMib(mib); | |
1230 | } | |
1231 | ||
1232 | /** | |
1233 | * Rem oves the s pecified M IB from th e SNMP pro tocol adap tor. | |
1234 | * | |
1235 | * @pa ram mib Th e MIB to b e removed. | |
1236 | * | |
1237 | * @re turn <CODE >true</COD E> if the specified <CODE>mib< /CODE> was a MIB | |
1238 | * inclu ded in the SNMP MIB handler, < CODE>false </CODE> ot herwise. | |
1239 | */ | |
1240 | @Overr ide | |
1241 | public boolean r emoveMib(S nmpMibAgen t mib) { | |
1242 | ro ot.unregis ter(mib); | |
1243 | re turn (mibs .removeEle ment(mib)) ; | |
1244 | } | |
1245 | ||
1246 | /** | |
1247 | * Rem oves the s pecified M IB from th e SNMP pro tocol adap tor. | |
1248 | * | |
1249 | * @pa ram mib Th e MIB to b e removed. | |
1250 | * @pa ram oids T he oid the MIB was p reviously registered for. | |
1251 | * @re turn <CODE >true</COD E> if the specified <CODE>mib< /CODE> was | |
1252 | * a M IB include d in the S NMP MIB ha ndler, <CO DE>false</ CODE> | |
1253 | * oth erwise. | |
1254 | * | |
1255 | * @si nce 1.5 | |
1256 | */ | |
1257 | @Overr ide | |
1258 | public boolean r emoveMib(S nmpMibAgen t mib, Snm pOid[] oid s) { | |
1259 | ro ot.unregis ter(mib, o ids); | |
1260 | re turn (mibs .removeEle ment(mib)) ; | |
1261 | } | |
1262 | ||
1263 | /** | |
1264 | * Rem oves the s pecified M IB from th e SNMP pro tocol adap tor. | |
1265 | * | |
1266 | * @pa ram mib Th e MIB to b e removed. | |
1267 | * @pa ram contex tName The context na me used at registrat ion time. | |
1268 | * @pa ram oids T he oid the MIB was p reviously registered for. | |
1269 | * @re turn <CODE >true</COD E> if the specified <CODE>mib< /CODE> was | |
1270 | * a M IB include d in the S NMP MIB ha ndler, <CO DE>false</ CODE> | |
1271 | * oth erwise. | |
1272 | * | |
1273 | * @si nce 1.5 | |
1274 | */ | |
1275 | @Overr ide | |
1276 | public boolean r emoveMib(S nmpMibAgen t mib, | |
1277 | S tring cont extName, | |
1278 | S nmpOid[] o ids) { | |
1279 | re turn remov eMib(mib, oids); | |
1280 | } | |
1281 | ||
1282 | // SUB CLASSING O F COMMUNIC ATOR SERVE R | |
1283 | //---- ---------- ---------- ---------- - | |
1284 | ||
1285 | /** | |
1286 | * Cre ates the d atagram so cket. | |
1287 | */ | |
1288 | @Overr ide | |
1289 | protec ted void d oBind() | |
1290 | th rows Commu nicationEx ception, I nterrupted Exception { | |
1291 | ||
1292 | tr y { | |
1293 | synchron ized (this ) { | |
1294 | sock et = new D atagramSoc ket(port, address) ; | |
1295 | } | |
1296 | dbgTag = makeDebug Tag(); | |
1297 | } catch (Soc ketExcepti on e) { | |
1298 | if (e.ge tMessage() .equals(In terruptSys CallMsg)) | |
1299 | thro w new Inte rruptedExc eption(e.t oString()) ; | |
1300 | else { | |
1301 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1302 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, d bgTag, | |
1303 | "doBin d", "canno t bind on port " + p ort); | |
1304 | } | |
1305 | thro w new Comm unicationE xception(e ) ; | |
1306 | } | |
1307 | } | |
1308 | } | |
1309 | ||
1310 | /** | |
1311 | * Ret urn the ac tual port to which t he adaptor is bound. | |
1312 | * Can be differ ent from t he port gi ven at con struction time if | |
1313 | * tha t port num ber was 0. | |
1314 | * @re turn the a ctual port to which the adapto r is bound . | |
1315 | **/ | |
1316 | @Overr ide | |
1317 | public int getPo rt() { | |
1318 | sy nchronized (this) { | |
1319 | if (sock et != null ) return s ocket.getL ocalPort() ; | |
1320 | } | |
1321 | re turn super .getPort() ; | |
1322 | } | |
1323 | ||
1324 | /** | |
1325 | * Clo ses the da tagram soc ket. | |
1326 | */ | |
1327 | @Overr ide | |
1328 | protec ted void d oUnbind() | |
1329 | th rows Commu nicationEx ception, I nterrupted Exception { | |
1330 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
1331 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
1332 | "doU nbind","Fi nally clos e the sock et"); | |
1333 | } | |
1334 | sy nchronized (this) { | |
1335 | if (sock et != null ) { | |
1336 | sock et.close() ; | |
1337 | sock et = null ; | |
1338 | // I mportant t o inform f inalize() that the s ocket is c losed... | |
1339 | } | |
1340 | } | |
1341 | cl oseTrapSoc ketIfNeede d() ; | |
1342 | cl oseInformS ocketIfNee ded() ; | |
1343 | } | |
1344 | ||
1345 | privat e void cre ateSnmpReq uestHandle r(SnmpAdap torServer server, | |
1346 | int id, | |
1347 | Datagram Socket s, | |
1348 | Datagram Packet p, | |
1349 | SnmpMibT ree tree, | |
1350 | Vector<S nmpMibAgen t> m, | |
1351 | InetAddr essAcl a, | |
1352 | SnmpPduF actory fac tory, | |
1353 | SnmpUser DataFactor y dataFact ory, | |
1354 | MBeanSer ver f, | |
1355 | ObjectNa me n) { | |
1356 | fi nal SnmpRe questHandl er handler = | |
1357 | new Snmp RequestHan dler(this, id, s, p, tree, m, a, factory , | |
1358 | dataF actory, f, n); | |
1359 | th readServic e.submitTa sk(handler ); | |
1360 | } | |
1361 | ||
1362 | /** | |
1363 | * Rea ds a packe t from the datagram socket and creates a request | |
1364 | * han dler which decodes a nd process es the req uest. | |
1365 | */ | |
1366 | @Overr ide | |
1367 | protec ted void d oReceive() | |
1368 | th rows Commu nicationEx ception, I nterrupted Exception { | |
1369 | ||
1370 | // Let's wai t for some thing to b e received . | |
1371 | // | |
1372 | tr y { | |
1373 | packet = new Datag ramPacket( new byte[b ufferSize] , bufferSi ze) ; | |
1374 | socket.r eceive(pac ket); | |
1375 | int stat e = getSta te(); | |
1376 | ||
1377 | if(state != ONLINE ) { | |
1378 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN ER)) { | |
1379 | SNMP_ADAPT OR_LOGGER. logp(Level .FINER, db gTag, | |
1380 | "doRec eive","rec eived a me ssage but state not online, re turning.") ; | |
1381 | } | |
1382 | retu rn; | |
1383 | } | |
1384 | ||
1385 | createSn mpRequestH andler(thi s, servedC lientCount , socket, | |
1386 | pac ket, root, mibs, ipa cl, pduFac tory, | |
1387 | use rDataFacto ry, topMBS , objectNa me); | |
1388 | } catch (Soc ketExcepti on e) { | |
1389 | // Let's check if we have be en interru pted by st op(). | |
1390 | // | |
1391 | if (e.ge tMessage() .equals(In terruptSys CallMsg)) | |
1392 | thro w new Inte rruptedExc eption(e.t oString()) ; | |
1393 | else | |
1394 | thro w new Comm unicationE xception(e ) ; | |
1395 | } catch (Int erruptedIO Exception e) { | |
1396 | throw ne w Interrup tedExcepti on(e.toStr ing()) ; | |
1397 | } catch (Com munication Exception e) { | |
1398 | throw e ; | |
1399 | } catch (Exc eption e) { | |
1400 | throw ne w Communic ationExcep tion(e) ; | |
1401 | } | |
1402 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
1403 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
1404 | "doR eceive", " received a message") ; | |
1405 | } | |
1406 | } | |
1407 | ||
1408 | @Overr ide | |
1409 | protec ted void d oError(Exc eption e) throws Com munication Exception { | |
1410 | } | |
1411 | ||
1412 | /** | |
1413 | * Not used in t his contex t. | |
1414 | */ | |
1415 | @Overr ide | |
1416 | protec ted void d oProcess() | |
1417 | th rows Commu nicationEx ception, I nterrupted Exception { | |
1418 | } | |
1419 | ||
1420 | ||
1421 | /** | |
1422 | * The number of times the communica tor server will atte mpt | |
1423 | * to bind befor e giving u p. | |
1424 | * We attempt on ly once... | |
1425 | * @re turn 1 | |
1426 | **/ | |
1427 | @Overr ide | |
1428 | protec ted int ge tBindTries () { | |
1429 | re turn 1; | |
1430 | } | |
1431 | ||
1432 | /** | |
1433 | * Sto ps this SN MP protoco l adaptor. | |
1434 | * Clo ses the da tagram soc ket. | |
1435 | * <p> | |
1436 | * Has no effect if this S NMP protoc ol adaptor is <CODE> OFFLINE</C ODE> or | |
1437 | * <CO DE>STOPPIN G</CODE>. | |
1438 | */ | |
1439 | @Overr ide | |
1440 | public void stop (){ | |
1441 | ||
1442 | fi nal int po rt = getPo rt(); | |
1443 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
1444 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
1445 | "sto p", "Stopp ing: using port " + port); | |
1446 | } | |
1447 | if ((state = = ONLINE) || (state == STARTIN G)){ | |
1448 | super.st op(); | |
1449 | try { | |
1450 | Data gramSocket sn = new DatagramSo cket(0); | |
1451 | try { | |
1452 | byte[] ob = new byte [1]; | |
1453 | ||
1454 | DatagramPa cket pk; | |
1455 | if (addres s != null) | |
1456 | pk = n ew Datagra mPacket(ob , 1, addr ess, port) ; | |
1457 | else | |
1458 | pk = n ew Datagra mPacket(ob , 1, | |
1459 | java.ne t.InetAddr ess.getLoc alHost(), port); | |
1460 | ||
1461 | if (SNMP_A DAPTOR_LOG GER.isLogg able(Level .FINER)) { | |
1462 | SNMP_A DAPTOR_LOG GER.logp(L evel.FINER , dbgTag, | |
1463 | "s top", "Sen ding: usin g port " + port); | |
1464 | } | |
1465 | sn.send(pk ); | |
1466 | } fi nally { | |
1467 | sn.close() ; | |
1468 | } | |
1469 | } catch (Throwable e){ | |
1470 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
1471 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, d bgTag, | |
1472 | "stop" , "Got une xpected Th rowable", e); | |
1473 | } | |
1474 | } | |
1475 | } | |
1476 | } | |
1477 | ||
1478 | // SEN DING SNMP TRAPS STUF F | |
1479 | //---- ---------- ---------- - | |
1480 | ||
1481 | /** | |
1482 | * Sen ds a trap using SNMP V1 trap f ormat. | |
1483 | * <BR >The trap is sent to each dest ination de fined in t he ACL fil e | |
1484 | * (if available ). | |
1485 | * If no ACL fil e or no de stinations are avail able, the trap is se nt | |
1486 | * to the local host. | |
1487 | * | |
1488 | * @pa ram generi c The gene ric number of the tr ap. | |
1489 | * @pa ram specif ic The spe cific numb er of the trap. | |
1490 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
1491 | * | |
1492 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
1493 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit de fined | |
1494 | * by <CODE>buf ferSize</C ODE>. | |
1495 | */ | |
1496 | @Overr ide | |
1497 | public void snmp V1Trap(int generic, int specif ic, | |
1498 | Snm pVarBindLi st varBind List) | |
1499 | th rows IOExc eption, Sn mpStatusEx ception { | |
1500 | ||
1501 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
1502 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
1503 | "snm pV1Trap", "generic=" + generic + | |
1504 | ", specific= " + specif ic); | |
1505 | } | |
1506 | ||
1507 | // First, ma ke an SNMP V1 trap p du | |
1508 | // | |
1509 | Sn mpPduTrap pdu = new SnmpPduTra p() ; | |
1510 | pd u.address = null ; | |
1511 | pd u.port = t rapPort ; | |
1512 | pd u.type = p duV1TrapPd u ; | |
1513 | pd u.version = snmpVers ionOne ; | |
1514 | pd u.communit y = null ; | |
1515 | pd u.enterpri se = enter priseOid ; | |
1516 | pd u.genericT rap = gene ric ; | |
1517 | pd u.specific Trap = spe cific ; | |
1518 | pd u.timeStam p = getSys UpTime(); | |
1519 | ||
1520 | if (varBindL ist != nul l) { | |
1521 | pdu.varB indList = new SnmpVa rBind[varB indList.si ze()] ; | |
1522 | varBindL ist.copyIn to(pdu.var BindList); | |
1523 | } | |
1524 | el se | |
1525 | pdu.varB indList = null ; | |
1526 | ||
1527 | // If the lo cal host c annot be d etermined, we put 0. 0.0.0 in a gentAddr | |
1528 | tr y { | |
1529 | if (addr ess != nul l) | |
1530 | pdu. agentAddr = handleMu ltipleIpVe rsion(addr ess.getAdd ress()); | |
1531 | else pdu .agentAddr = | |
1532 | handle MultipleIp Version(In etAddress. getLocalHo st().getAd dress()); | |
1533 | } catch (Unk nownHostEx ception e) { | |
1534 | byte[] z eroedAddr = new byte [4]; | |
1535 | pdu.agen tAddr = ha ndleMultip leIpVersio n(zeroedAd dr) ; | |
1536 | } | |
1537 | ||
1538 | // Next, sen d the pdu to all des tinations defined in ACL | |
1539 | // | |
1540 | se ndTrapPdu( pdu) ; | |
1541 | } | |
1542 | ||
1543 | privat e SnmpIpAd dress hand leMultiple IpVersion( byte[] add ress) { | |
1544 | if (address.l ength == 4 ) | |
1545 | return new SnmpIpAdd ress(addre ss); | |
1546 | el se { | |
1547 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINEST) ) { | |
1548 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN EST, dbgTa g, | |
1549 | "handleMul tipleIPVer sion", | |
1550 | "Not an IPv4 addre ss, return null"); | |
1551 | } | |
1552 | return n ull; | |
1553 | } | |
1554 | } | |
1555 | ||
1556 | /** | |
1557 | * Sen ds a trap using SNMP V1 trap f ormat. | |
1558 | * <BR >The trap is sent to the speci fied <CODE >InetAddre ss</CODE> | |
1559 | * des tination u sing the s pecified c ommunity s tring (and the ACL f ile | |
1560 | * is not used). | |
1561 | * | |
1562 | * @pa ram addr T he <CODE>I netAddress </CODE> de stination of the tra p. | |
1563 | * @pa ram cs The community string to be used f or the tra p. | |
1564 | * @pa ram generi c The gene ric number of the tr ap. | |
1565 | * @pa ram specif ic The spe cific numb er of the trap. | |
1566 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
1567 | * | |
1568 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
1569 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit de fined | |
1570 | * by <CODE>buf ferSize</C ODE>. | |
1571 | */ | |
1572 | @Overr ide | |
1573 | public void snmp V1Trap(Ine tAddress a ddr, Strin g cs, int generic, | |
1574 | int specific, SnmpVarBi ndList var BindList) | |
1575 | th rows IOExc eption, Sn mpStatusEx ception { | |
1576 | ||
1577 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
1578 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
1579 | "snm pV1Trap", "generic=" + generic + ", spec ific=" + | |
1580 | sp ecific); | |
1581 | } | |
1582 | ||
1583 | // First, ma ke an SNMP V1 trap p du | |
1584 | // | |
1585 | Sn mpPduTrap pdu = new SnmpPduTra p() ; | |
1586 | pd u.address = null ; | |
1587 | pd u.port = t rapPort ; | |
1588 | pd u.type = p duV1TrapPd u ; | |
1589 | pd u.version = snmpVers ionOne ; | |
1590 | ||
1591 | if (cs != nul l) | |
1592 | pdu.comm unity = cs .getBytes( ); | |
1593 | el se | |
1594 | pdu.comm unity = nu ll ; | |
1595 | ||
1596 | pd u.enterpri se = enter priseOid ; | |
1597 | pd u.genericT rap = gene ric ; | |
1598 | pd u.specific Trap = spe cific ; | |
1599 | pd u.timeStam p = getSys UpTime(); | |
1600 | ||
1601 | if (varBindL ist != nul l) { | |
1602 | pdu.varB indList = new SnmpVa rBind[varB indList.si ze()] ; | |
1603 | varBindL ist.copyIn to(pdu.var BindList); | |
1604 | } | |
1605 | el se | |
1606 | pdu.varB indList = null ; | |
1607 | ||
1608 | // If the lo cal host c annot be d etermined, we put 0. 0.0.0 in a gentAddr | |
1609 | tr y { | |
1610 | if (addr ess != nul l) | |
1611 | pdu. agentAddr = handleMu ltipleIpVe rsion(addr ess.getAdd ress()); | |
1612 | else pdu .agentAddr = | |
1613 | handle MultipleIp Version(In etAddress. getLocalHo st().getAd dress()); | |
1614 | } catch (Unk nownHostEx ception e) { | |
1615 | byte[] z eroedAddr = new byte [4]; | |
1616 | pdu.agen tAddr = ha ndleMultip leIpVersio n(zeroedAd dr) ; | |
1617 | } | |
1618 | ||
1619 | // Next, sen d the pdu to the spe cified des tination | |
1620 | // | |
1621 | if (addr != n ull) | |
1622 | sendTrap Pdu(addr, pdu) ; | |
1623 | el se | |
1624 | sendTrap Pdu(pdu); | |
1625 | } | |
1626 | ||
1627 | /** | |
1628 | * Sen ds a trap using SNMP V1 trap f ormat. | |
1629 | * <BR >The trap is sent to the speci fied <CODE >InetAddre ss</CODE> | |
1630 | * des tination u sing the s pecified p arameters (and the A CL file is not | |
1631 | * use d). | |
1632 | * Not e that if the specif ied <CODE> InetAddres s</CODE> d estination is null, | |
1633 | * the n the ACL file mecha nism is us ed. | |
1634 | * | |
1635 | * @pa ram addr T he <CODE>I netAddress </CODE> de stination of the tra p. | |
1636 | * @pa ram agentA ddr The ag ent addres s to be us ed for the trap. | |
1637 | * @pa ram cs The community string to be used f or the tra p. | |
1638 | * @pa ram enterp Oid The en terprise O ID to be u sed for th e trap. | |
1639 | * @pa ram generi c The gene ric number of the tr ap. | |
1640 | * @pa ram specif ic The spe cific numb er of the trap. | |
1641 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
1642 | * @pa ram time T he time st amp (overw rite the c urrent tim e). | |
1643 | * | |
1644 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
1645 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit de fined | |
1646 | * by <CODE>buf ferSize</C ODE>. | |
1647 | * | |
1648 | * @si nce 1.5 | |
1649 | */ | |
1650 | public void snmp V1Trap(Ine tAddress a ddr, | |
1651 | Snm pIpAddress agentAddr , | |
1652 | Str ing cs, | |
1653 | Snm pOid enter pOid, | |
1654 | int generic, | |
1655 | int specific, | |
1656 | Snm pVarBindLi st varBind List, | |
1657 | Snm pTimeticks time) | |
1658 | th rows IOExc eption, Sn mpStatusEx ception { | |
1659 | sn mpV1Trap(a ddr, | |
1660 | t rapPort, | |
1661 | a gentAddr, | |
1662 | c s, | |
1663 | e nterpOid, | |
1664 | g eneric, | |
1665 | s pecific, | |
1666 | v arBindList , | |
1667 | t ime); | |
1668 | } | |
1669 | ||
1670 | /** | |
1671 | * Sen ds a trap using SNMP V1 trap f ormat. | |
1672 | * <BR >The trap is sent to the speci fied <CODE >SnmpPeer< /CODE> des tination. | |
1673 | * The community string us ed is the one locate d in the | |
1674 | * <CO DE>SnmpPee r</CODE> p arameters | |
1675 | * (<C ODE>SnmpPa rameters.g etRdCommun ity() </CO DE>). | |
1676 | * | |
1677 | * @pa ram peer T he <CODE>S nmpPeer</C ODE> desti nation of the trap. | |
1678 | * @pa ram agentA ddr The ag ent addres s to be us ed for the trap. | |
1679 | * @pa ram enterp Oid The en terprise O ID to be u sed for th e trap. | |
1680 | * @pa ram generi c The gene ric number of the tr ap. | |
1681 | * @pa ram specif ic The spe cific numb er of the trap. | |
1682 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
1683 | * @pa ram time T he time st amp (overw rite the c urrent tim e). | |
1684 | * | |
1685 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
1686 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit | |
1687 | * def ined by <C ODE>buffer Size</CODE >. | |
1688 | * | |
1689 | * @si nce 1.5 | |
1690 | */ | |
1691 | @Overr ide | |
1692 | public void snmp V1Trap(Snm pPeer peer , | |
1693 | Snm pIpAddress agentAddr , | |
1694 | Snm pOid enter pOid, | |
1695 | int generic, | |
1696 | int specific, | |
1697 | Snm pVarBindLi st varBind List, | |
1698 | Snm pTimeticks time) | |
1699 | th rows IOExc eption, Sn mpStatusEx ception { | |
1700 | ||
1701 | Sn mpParamete rs p = (Sn mpParamete rs) peer.g etParams() ; | |
1702 | sn mpV1Trap(p eer.getDes tAddr(), | |
1703 | p eer.getDes tPort(), | |
1704 | a gentAddr, | |
1705 | p .getRdComm unity(), | |
1706 | e nterpOid, | |
1707 | g eneric, | |
1708 | s pecific, | |
1709 | v arBindList , | |
1710 | t ime); | |
1711 | } | |
1712 | ||
1713 | privat e void snm pV1Trap(In etAddress addr, | |
1714 | in t port, | |
1715 | Sn mpIpAddres s agentAdd r, | |
1716 | St ring cs, | |
1717 | Sn mpOid ente rpOid, | |
1718 | in t generic, | |
1719 | in t specific , | |
1720 | Sn mpVarBindL ist varBin dList, | |
1721 | Sn mpTimetick s time) | |
1722 | th rows IOExc eption, Sn mpStatusEx ception { | |
1723 | ||
1724 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
1725 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
1726 | "snm pV1Trap", "generic=" + generic + ", spec ific=" + | |
1727 | sp ecific); | |
1728 | } | |
1729 | ||
1730 | // First, ma ke an SNMP V1 trap p du | |
1731 | // | |
1732 | Sn mpPduTrap pdu = new SnmpPduTra p() ; | |
1733 | pd u.address = null ; | |
1734 | pd u.port = p ort ; | |
1735 | pd u.type = p duV1TrapPd u ; | |
1736 | pd u.version = snmpVers ionOne ; | |
1737 | ||
1738 | // Diff start | |
1739 | if (cs != nul l) | |
1740 | pdu.comm unity = cs .getBytes( ); | |
1741 | el se | |
1742 | pdu.comm unity = nu ll ; | |
1743 | // Diff end | |
1744 | ||
1745 | // Diff star t | |
1746 | if (enterpOid != null) | |
1747 | pdu.ente rprise = e nterpOid; | |
1748 | el se | |
1749 | pdu.ente rprise = e nterpriseO id ; | |
1750 | // Diff end | |
1751 | pd u.genericT rap = gene ric ; | |
1752 | pd u.specific Trap = spe cific ; | |
1753 | // Diff start | |
1754 | if (time != n ull) | |
1755 | pdu.time Stamp = ti me.longVal ue(); | |
1756 | el se | |
1757 | pdu.time Stamp = ge tSysUpTime (); | |
1758 | // Diff end | |
1759 | ||
1760 | if (varBindL ist != nul l) { | |
1761 | pdu.varB indList = new SnmpVa rBind[varB indList.si ze()] ; | |
1762 | varBindL ist.copyIn to(pdu.var BindList); | |
1763 | } | |
1764 | el se | |
1765 | pdu.varB indList = null ; | |
1766 | ||
1767 | if (agentAdd r == null) { | |
1768 | // If th e local ho st cannot be determi ned, | |
1769 | // we pu t 0.0.0.0 in agentAd dr | |
1770 | try { | |
1771 | fina l InetAddr ess inetAd dr = | |
1772 | (address!= null)?addr ess:InetAd dress.getL ocalHost() ; | |
1773 | agen tAddr = ha ndleMultip leIpVersio n(inetAddr .getAddres s()); | |
1774 | } catch (UnknownH ostExcepti on e) { | |
1775 | byte [] zeroedA ddr = new byte[4]; | |
1776 | agen tAddr = ha ndleMultip leIpVersio n(zeroedAd dr); | |
1777 | } | |
1778 | } | |
1779 | ||
1780 | pd u.agentAdd r = agentA ddr; | |
1781 | ||
1782 | // Next, sen d the pdu to the spe cified des tination | |
1783 | // | |
1784 | // Diff star t | |
1785 | if (addr != n ull) | |
1786 | sendTrap Pdu(addr, pdu) ; | |
1787 | el se | |
1788 | sendTrap Pdu(pdu); | |
1789 | ||
1790 | // End diff | |
1791 | } | |
1792 | ||
1793 | /** | |
1794 | * Sen ds a trap using SNMP V2 trap f ormat. | |
1795 | * <BR >The trap is sent to the speci fied <CODE >SnmpPeer< /CODE> des tination. | |
1796 | * <BR >The commu nity strin g used is the one lo cated in t he | |
1797 | * <CO DE>SnmpPee r</CODE> p arameters | |
1798 | * (<C ODE>SnmpPa rameters.g etRdCommun ity() </CO DE>). | |
1799 | * <BR >The varia ble list i ncluded in the outgo ing trap i s composed of | |
1800 | * the following items: | |
1801 | * <UL > | |
1802 | * <LI ><CODE>sys UpTime.0</ CODE> with the value specified by | |
1803 | * <CODE>tim e</CODE></ LI> | |
1804 | * <LI ><CODE>snm pTrapOid.0 </CODE> wi th the val ue specifi ed by | |
1805 | * <CODE>tra pOid</CODE ></LI> | |
1806 | * <LI ><CODE>all the (oid, values)</C ODE> from the specif ied | |
1807 | * <CODE>var BindList</ CODE></LI> | |
1808 | * </U L> | |
1809 | * | |
1810 | * @pa ram peer T he <CODE>S nmpPeer</C ODE> desti nation of the trap. | |
1811 | * @pa ram trapOi d The OID identifyin g the trap . | |
1812 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
1813 | * @pa ram time T he time st amp (overw rite the c urrent tim e). | |
1814 | * | |
1815 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
1816 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit | |
1817 | * def ined by <C ODE>buffer Size</CODE >. | |
1818 | * | |
1819 | * @si nce 1.5 | |
1820 | */ | |
1821 | @Overr ide | |
1822 | public void snmp V2Trap(Snm pPeer peer , | |
1823 | Snm pOid trapO id, | |
1824 | Snm pVarBindLi st varBind List, | |
1825 | Snm pTimeticks time) | |
1826 | th rows IOExc eption, Sn mpStatusEx ception { | |
1827 | ||
1828 | Sn mpParamete rs p = (Sn mpParamete rs) peer.g etParams() ; | |
1829 | sn mpV2Trap(p eer.getDes tAddr(), | |
1830 | p eer.getDes tPort(), | |
1831 | p .getRdComm unity(), | |
1832 | t rapOid, | |
1833 | v arBindList , | |
1834 | t ime); | |
1835 | } | |
1836 | ||
1837 | /** | |
1838 | * Sen ds a trap using SNMP V2 trap f ormat. | |
1839 | * <BR >The trap is sent to each dest ination de fined in t he ACL fil e | |
1840 | * (if available ). If no A CL file or no destin ations are available , | |
1841 | * the trap is s ent to the local hos t. | |
1842 | * <BR >The varia ble list i ncluded in the outgo ing trap i s composed of | |
1843 | * the following items: | |
1844 | * <UL > | |
1845 | * <LI ><CODE>sys UpTime.0</ CODE> with its curre nt value</ LI> | |
1846 | * <LI ><CODE>snm pTrapOid.0 </CODE> wi th the val ue specifi ed by | |
1847 | * <CODE>tra pOid</CODE ></LI> | |
1848 | * <LI ><CODE>all the (oid, values)</C ODE> from the specif ied | |
1849 | * <CODE>var BindList</ CODE></LI> | |
1850 | * </U L> | |
1851 | * | |
1852 | * @pa ram trapOi d The OID identifyin g the trap . | |
1853 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
1854 | * | |
1855 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
1856 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit de fined | |
1857 | * by <CODE>buf ferSize</C ODE>. | |
1858 | */ | |
1859 | @Overr ide | |
1860 | public void snmp V2Trap(Snm pOid trapO id, SnmpVa rBindList varBindLis t) | |
1861 | th rows IOExc eption, Sn mpStatusEx ception { | |
1862 | ||
1863 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
1864 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
1865 | "snm pV2Trap", "trapOid=" + trapOid ); | |
1866 | } | |
1867 | ||
1868 | // First, ma ke an SNMP V2 trap p du | |
1869 | // We clone varBindLis t and inse rt sysUpTi me and snm pTrapOid | |
1870 | // | |
1871 | Sn mpPduReque st pdu = n ew SnmpPdu Request() ; | |
1872 | pd u.address = null ; | |
1873 | pd u.port = t rapPort ; | |
1874 | pd u.type = p duV2TrapPd u ; | |
1875 | pd u.version = snmpVers ionTwo ; | |
1876 | pd u.communit y = null ; | |
1877 | ||
1878 | Sn mpVarBindL ist fullVb l ; | |
1879 | if (varBindL ist != nul l) | |
1880 | fullVbl = varBindL ist.clone( ) ; | |
1881 | el se | |
1882 | fullVbl = new Snmp VarBindLis t(2) ; | |
1883 | Sn mpTimetick s sysUpTim eValue = n ew SnmpTim eticks(get SysUpTime( )) ; | |
1884 | fu llVbl.inse rtElementA t(new Snmp VarBind(sn mpTrapOidO id, trapOi d), 0) ; | |
1885 | fu llVbl.inse rtElementA t(new Snmp VarBind(sy sUpTimeOid , sysUpTim eValue), | |
1886 | 0); | |
1887 | pd u.varBindL ist = new SnmpVarBin d[fullVbl. size()] ; | |
1888 | fu llVbl.copy Into(pdu.v arBindList ) ; | |
1889 | ||
1890 | // Next, sen d the pdu to all des tinations defined in ACL | |
1891 | // | |
1892 | se ndTrapPdu( pdu) ; | |
1893 | } | |
1894 | ||
1895 | /** | |
1896 | * Sen ds a trap using SNMP V2 trap f ormat. | |
1897 | * <BR >The trap is sent to the speci fied <CODE >InetAddre ss</CODE> | |
1898 | * des tination u sing the s pecified c ommunity s tring (and the ACL f ile | |
1899 | * is not used). | |
1900 | * <BR >The varia ble list i ncluded in the outgo ing trap i s composed of | |
1901 | * the following items: | |
1902 | * <UL > | |
1903 | * <LI ><CODE>sys UpTime.0</ CODE> with its curre nt value</ LI> | |
1904 | * <LI ><CODE>snm pTrapOid.0 </CODE> wi th the val ue specifi ed by | |
1905 | * <CODE>tra pOid</CODE ></LI> | |
1906 | * <LI ><CODE>all the (oid, values)</C ODE> from the specif ied | |
1907 | * <CODE>var BindList</ CODE></LI> | |
1908 | * </U L> | |
1909 | * | |
1910 | * @pa ram addr T he <CODE>I netAddress </CODE> de stination of the tra p. | |
1911 | * @pa ram cs The community string to be used f or the tra p. | |
1912 | * @pa ram trapOi d The OID identifyin g the trap . | |
1913 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
1914 | * | |
1915 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
1916 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit | |
1917 | * de fined by < CODE>buffe rSize</COD E>. | |
1918 | */ | |
1919 | @Overr ide | |
1920 | public void snmp V2Trap(Ine tAddress a ddr, Strin g cs, Snmp Oid trapOi d, | |
1921 | Snm pVarBindLi st varBind List) | |
1922 | th rows IOExc eption, Sn mpStatusEx ception { | |
1923 | ||
1924 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
1925 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
1926 | "snm pV2Trap", "trapOid=" + trapOid ); | |
1927 | } | |
1928 | ||
1929 | // First, ma ke an SNMP V2 trap p du | |
1930 | // We clone varBindLis t and inse rt sysUpTi me and snm pTrapOid | |
1931 | // | |
1932 | Sn mpPduReque st pdu = n ew SnmpPdu Request() ; | |
1933 | pd u.address = null ; | |
1934 | pd u.port = t rapPort ; | |
1935 | pd u.type = p duV2TrapPd u ; | |
1936 | pd u.version = snmpVers ionTwo ; | |
1937 | ||
1938 | if (cs != nul l) | |
1939 | pdu.comm unity = cs .getBytes( ); | |
1940 | el se | |
1941 | pdu.comm unity = nu ll; | |
1942 | ||
1943 | Sn mpVarBindL ist fullVb l ; | |
1944 | if (varBindL ist != nul l) | |
1945 | fullVbl = varBindL ist.clone( ) ; | |
1946 | el se | |
1947 | fullVbl = new Snmp VarBindLis t(2) ; | |
1948 | Sn mpTimetick s sysUpTim eValue = n ew SnmpTim eticks(get SysUpTime( )) ; | |
1949 | fu llVbl.inse rtElementA t(new Snmp VarBind(sn mpTrapOidO id, trapOi d), 0) ; | |
1950 | fu llVbl.inse rtElementA t(new Snmp VarBind(sy sUpTimeOid , sysUpTim eValue), | |
1951 | 0); | |
1952 | pd u.varBindL ist = new SnmpVarBin d[fullVbl. size()] ; | |
1953 | fu llVbl.copy Into(pdu.v arBindList ) ; | |
1954 | ||
1955 | // Next, sen d the pdu to the spe cified des tination | |
1956 | // | |
1957 | if (addr != n ull) | |
1958 | sendTrap Pdu(addr, pdu); | |
1959 | el se | |
1960 | sendTrap Pdu(pdu); | |
1961 | } | |
1962 | ||
1963 | /** | |
1964 | * Sen ds a trap using SNMP V2 trap f ormat. | |
1965 | * <BR >The trap is sent to the speci fied <CODE >InetAddre ss</CODE> | |
1966 | * des tination u sing the s pecified p arameters (and the A CL file is not | |
1967 | * use d). | |
1968 | * Not e that if the specif ied <CODE> InetAddres s</CODE> d estination is null, | |
1969 | * the n the ACL file mecha nism is us ed. | |
1970 | * <BR >The varia ble list i ncluded in the outgo ing trap i s composed of the | |
1971 | * fol lowing ite ms: | |
1972 | * <UL > | |
1973 | * <LI ><CODE>sys UpTime.0</ CODE> with the value specified by | |
1974 | * <CODE>tim e</CODE></ LI> | |
1975 | * <LI ><CODE>snm pTrapOid.0 </CODE> wi th the val ue specifi ed by | |
1976 | * <CODE>tra pOid</CODE ></LI> | |
1977 | * <LI ><CODE>all the (oid, values)</C ODE> from the specif ied | |
1978 | * <CODE>var BindList</ CODE></LI> | |
1979 | * </U L> | |
1980 | * | |
1981 | * @pa ram addr T he <CODE>I netAddress </CODE> de stination of the tra p. | |
1982 | * @pa ram cs The community string to be used f or the tra p. | |
1983 | * @pa ram trapOi d The OID identifyin g the trap . | |
1984 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
1985 | * @pa ram time T he time st amp (overw rite the c urrent tim e). | |
1986 | * | |
1987 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
1988 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit | |
1989 | * def ined by <C ODE>buffer Size</CODE >. | |
1990 | * | |
1991 | * @si nce 1.5 | |
1992 | */ | |
1993 | public void snmp V2Trap(Ine tAddress a ddr, | |
1994 | Str ing cs, | |
1995 | Snm pOid trapO id, | |
1996 | Snm pVarBindLi st varBind List, | |
1997 | Snm pTimeticks time) | |
1998 | th rows IOExc eption, Sn mpStatusEx ception { | |
1999 | ||
2000 | sn mpV2Trap(a ddr, | |
2001 | t rapPort, | |
2002 | c s, | |
2003 | t rapOid, | |
2004 | v arBindList , | |
2005 | t ime); | |
2006 | } | |
2007 | ||
2008 | privat e void snm pV2Trap(In etAddress addr, | |
2009 | in t port, | |
2010 | St ring cs, | |
2011 | Sn mpOid trap Oid, | |
2012 | Sn mpVarBindL ist varBin dList, | |
2013 | Sn mpTimetick s time) | |
2014 | th rows IOExc eption, Sn mpStatusEx ception { | |
2015 | ||
2016 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
2017 | final St ringBuilde r strb = n ew StringB uilder() | |
2018 | .app end("trapO id=").appe nd(trapOid ) | |
2019 | .app end("\ncom munity="). append(cs) | |
2020 | .app end("\nadd r=").appen d(addr) | |
2021 | .app end("\nvar BindList=" ).append(v arBindList ) | |
2022 | .app end("\ntim e=").appen d(time) | |
2023 | .app end("\ntra pPort=").a ppend(port ); | |
2024 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
2025 | "snm pV2Trap", strb.toStr ing()); | |
2026 | } | |
2027 | ||
2028 | // First, ma ke an SNMP V2 trap p du | |
2029 | // We clone varBindLis t and inse rt sysUpTi me and snm pTrapOid | |
2030 | // | |
2031 | Sn mpPduReque st pdu = n ew SnmpPdu Request() ; | |
2032 | pd u.address = null ; | |
2033 | pd u.port = p ort ; | |
2034 | pd u.type = p duV2TrapPd u ; | |
2035 | pd u.version = snmpVers ionTwo ; | |
2036 | ||
2037 | if (cs != nul l) | |
2038 | pdu.comm unity = cs .getBytes( ); | |
2039 | el se | |
2040 | pdu.comm unity = nu ll; | |
2041 | ||
2042 | Sn mpVarBindL ist fullVb l ; | |
2043 | if (varBindL ist != nul l) | |
2044 | fullVbl = varBindL ist.clone( ) ; | |
2045 | el se | |
2046 | fullVbl = new Snmp VarBindLis t(2) ; | |
2047 | ||
2048 | // Only diff erence wit h other | |
2049 | Sn mpTimetick s sysUpTim eValue; | |
2050 | if (time != n ull) | |
2051 | sysUpTim eValue = t ime; | |
2052 | el se | |
2053 | sysUpTim eValue = n ew SnmpTim eticks(get SysUpTime( )) ; | |
2054 | // End of dif f | |
2055 | ||
2056 | fu llVbl.inse rtElementA t(new Snmp VarBind(sn mpTrapOidO id, trapOi d), 0) ; | |
2057 | fu llVbl.inse rtElementA t(new Snmp VarBind(sy sUpTimeOid , sysUpTim eValue), | |
2058 | 0); | |
2059 | pd u.varBindL ist = new SnmpVarBin d[fullVbl. size()] ; | |
2060 | fu llVbl.copy Into(pdu.v arBindList ) ; | |
2061 | ||
2062 | // Next, sen d the pdu to the spe cified des tination | |
2063 | // | |
2064 | // Diff star t | |
2065 | if (addr != n ull) | |
2066 | sendTrap Pdu(addr, pdu) ; | |
2067 | el se | |
2068 | sendTrap Pdu(pdu); | |
2069 | // End diff | |
2070 | } | |
2071 | ||
2072 | /** | |
2073 | * Sen d the spec ified trap PDU to th e passed < CODE>InetA ddress</CO DE>. | |
2074 | * @pa ram addres s The dest ination ad dress. | |
2075 | * @pa ram pdu Th e pdu to s end. | |
2076 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
2077 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit | |
2078 | * def ined by <C ODE>buffer Size</CODE >. | |
2079 | * | |
2080 | * @si nce 1.5 | |
2081 | */ | |
2082 | @Overr ide | |
2083 | public void snmp PduTrap(In etAddress address, S nmpPduPack et pdu) | |
2084 | throws I OException , SnmpStat usExceptio n { | |
2085 | ||
2086 | if (address ! = null) | |
2087 | sendTrap Pdu(addres s, pdu); | |
2088 | el se | |
2089 | sendTrap Pdu(pdu); | |
2090 | } | |
2091 | ||
2092 | /** | |
2093 | * Sen d the spec ified trap PDU to th e passed < CODE>SnmpP eer</CODE> . | |
2094 | * @pa ram peer T he destina tion peer. The Read community string is used of | |
2095 | * <CO DE>SnmpPar ameters</C ODE> is us ed as the trap commu nity strin g. | |
2096 | * @pa ram pdu Th e pdu to s end. | |
2097 | * @ex ception IO Exception An I/O err or occurre d while se nding the trap. | |
2098 | * @ex ception Sn mpStatusEx ception If the trap exceeds th e limit de fined | |
2099 | * by <CODE>buff erSize</CO DE>. | |
2100 | * @si nce 1.5 | |
2101 | */ | |
2102 | @Overr ide | |
2103 | public void snmp PduTrap(Sn mpPeer pee r, | |
2104 | Sn mpPduPacke t pdu) | |
2105 | th rows IOExc eption, Sn mpStatusEx ception { | |
2106 | if (peer != n ull) { | |
2107 | pdu.port = peer.ge tDestPort( ); | |
2108 | sendTrap Pdu(peer.g etDestAddr (), pdu); | |
2109 | } | |
2110 | el se { | |
2111 | pdu.port = getTrap Port().int Value(); | |
2112 | sendTrap Pdu(pdu); | |
2113 | } | |
2114 | } | |
2115 | ||
2116 | /** | |
2117 | * Sen d the spec ified trap PDU to ev ery destin ations fro m the ACL file. | |
2118 | */ | |
2119 | privat e void sen dTrapPdu(S nmpPduPack et pdu) | |
2120 | throw s SnmpStat usExceptio n, IOExcep tion { | |
2121 | ||
2122 | // Make an S NMP messag e from the pdu | |
2123 | // | |
2124 | Sn mpMessage msg = null ; | |
2125 | tr y { | |
2126 | msg = (S nmpMessage )pduFactor y.encodeSn mpPdu(pdu, bufferSiz e) ; | |
2127 | if (msg == null) { | |
2128 | thro w new Snmp StatusExce ption( | |
2129 | Snmp Definition s.snmpRspA uthorizati onError) ; | |
2130 | } | |
2131 | } | |
2132 | ca tch (SnmpT ooBigExcep tion x) { | |
2133 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINEST) ) { | |
2134 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN EST, dbgTa g, | |
2135 | "sendTrapP du", "Trap pdu is to o big. " + | |
2136 | "Trap has n't been s ent to any one" ); | |
2137 | } | |
2138 | throw ne w SnmpStat usExceptio n(SnmpDefi nitions.sn mpRspTooBi g) ; | |
2139 | // FIXME : is the r ight excep tion to th row ? | |
2140 | // We co uld simply forward S nmpTooBigE xception ? | |
2141 | } | |
2142 | ||
2143 | // Now send the SNMP m essage to each desti nation | |
2144 | // | |
2145 | in t sendingC ount = 0 ; | |
2146 | op enTrapSock etIfNeeded () ; | |
2147 | if (ipacl != null) { | |
2148 | Enumerat ion<InetAd dress> ed = ipacl.ge tTrapDesti nations() ; | |
2149 | while (e d.hasMoreE lements()) { | |
2150 | msg. address = ed.nextEle ment() ; | |
2151 | Enum eration<St ring> ec = ipacl.get TrapCommun ities(msg. address) ; | |
2152 | whil e (ec.hasM oreElement s()) { | |
2153 | msg.commun ity = ec.n extElement ().getByte s() ; | |
2154 | try { | |
2155 | sendTr apMessage( msg) ; | |
2156 | sendin gCount++ ; | |
2157 | } | |
2158 | catch (Snm pTooBigExc eption x) { | |
2159 | if (SN MP_ADAPTOR _LOGGER.is Loggable(L evel.FINES T)) { | |
2160 | SN MP_ADAPTOR _LOGGER.lo gp(Level.F INEST, dbg Tag, | |
2161 | "sendTra pPdu", "Tr ap pdu is too big. " + | |
2162 | "Trap h asn't been sent to " +msg.addre ss); | |
2163 | } | |
2164 | } | |
2165 | } | |
2166 | } | |
2167 | } | |
2168 | ||
2169 | // If there is no dest ination de fined or i f everythi ng has fai led | |
2170 | // we tried to send th e trap to the local host (as s uggested b y | |
2171 | // mister Ol ivier Reis acher). | |
2172 | // | |
2173 | if (sendingC ount == 0) { | |
2174 | try { | |
2175 | msg. address = InetAddres s.getLocal Host() ; | |
2176 | send TrapMessag e(msg) ; | |
2177 | } catch (SnmpTooBi gException x) { | |
2178 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
2179 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, d bgTag, | |
2180 | "sendT rapPdu", " Trap pdu i s too big. " + | |
2181 | "Trap hasn't be en sent.") ; | |
2182 | } | |
2183 | } catch (UnknownHo stExceptio n e) { | |
2184 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
2185 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, d bgTag, | |
2186 | "sendT rapPdu", " Trap pdu i s too big. " + | |
2187 | "Trap hasn't be en sent.") ; | |
2188 | } | |
2189 | } | |
2190 | } | |
2191 | ||
2192 | cl oseTrapSoc ketIfNeede d() ; | |
2193 | } | |
2194 | ||
2195 | /** | |
2196 | * Sen d the spec ified trap PDU to th e specifie d destinat ion. | |
2197 | */ | |
2198 | privat e void sen dTrapPdu(I netAddress addr, Snm pPduPacket pdu) | |
2199 | th rows SnmpS tatusExcep tion, IOEx ception { | |
2200 | ||
2201 | // Make an S NMP messag e from the pdu | |
2202 | // | |
2203 | Sn mpMessage msg = null ; | |
2204 | tr y { | |
2205 | msg = (S nmpMessage )pduFactor y.encodeSn mpPdu(pdu, bufferSiz e) ; | |
2206 | if (msg == null) { | |
2207 | thro w new Snmp StatusExce ption( | |
2208 | Snmp Definition s.snmpRspA uthorizati onError) ; | |
2209 | } | |
2210 | } catch (Snm pTooBigExc eption x) { | |
2211 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINEST) ) { | |
2212 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN EST, dbgTa g, | |
2213 | "sendTrapP du", "Trap pdu is to o big. " + | |
2214 | "Trap has n't been s ent to the specified host."); | |
2215 | } | |
2216 | throw ne w SnmpStat usExceptio n(SnmpDefi nitions.sn mpRspTooBi g) ; | |
2217 | // FIXME : is the r ight excep tion to th row ? | |
2218 | // We co uld simply forward S nmpTooBigE xception ? | |
2219 | } | |
2220 | ||
2221 | // Now send the SNMP m essage to specified destinatio n | |
2222 | // | |
2223 | op enTrapSock etIfNeeded () ; | |
2224 | if (addr != null) { | |
2225 | msg.addr ess = addr ; | |
2226 | try { | |
2227 | send TrapMessag e(msg) ; | |
2228 | } catch (SnmpTooBi gException x) { | |
2229 | if ( SNMP_ADAPT OR_LOGGER. isLoggable (Level.FIN EST)) { | |
2230 | SNMP_ADAPT OR_LOGGER. logp(Level .FINEST, d bgTag, | |
2231 | "sendT rapPdu", " Trap pdu i s too big. " + | |
2232 | "Trap hasn't be en sent to " + msg. address); | |
2233 | } | |
2234 | } | |
2235 | } | |
2236 | ||
2237 | cl oseTrapSoc ketIfNeede d() ; | |
2238 | } | |
2239 | ||
2240 | /** | |
2241 | * Sen d the spec ified mess age on tra pSocket. | |
2242 | */ | |
2243 | privat e void sen dTrapMessa ge(SnmpMes sage msg) | |
2244 | th rows IOExc eption, Sn mpTooBigEx ception { | |
2245 | ||
2246 | by te[] buffe r = new by te[bufferS ize] ; | |
2247 | Da tagramPack et packet = new Data gramPacket (buffer, b uffer.leng th) ; | |
2248 | in t encoding Length = m sg.encodeM essage(buf fer) ; | |
2249 | pa cket.setLe ngth(encod ingLength) ; | |
2250 | pa cket.setAd dress(msg. address) ; | |
2251 | pa cket.setPo rt(msg.por t) ; | |
2252 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
2253 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
2254 | "sen dTrapMessa ge", "send ing trap t o " + msg. address + ":" + | |
2255 | ms g.port); | |
2256 | } | |
2257 | tr apSocket.s end(packet ) ; | |
2258 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
2259 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
2260 | "sen dTrapMessa ge", "sent to " + ms g.address + ":" + | |
2261 | ms g.port); | |
2262 | } | |
2263 | sn mpOutTraps ++; | |
2264 | sn mpOutPkts+ +; | |
2265 | } | |
2266 | ||
2267 | /** | |
2268 | * Ope n trapSock et if it's not alrea dy done. | |
2269 | */ | |
2270 | synchr onized voi d openTrap SocketIfNe eded() thr ows Socket Exception { | |
2271 | if (trapSock et == null ) { | |
2272 | trapSock et = new D atagramSoc ket(0, add ress) ; | |
2273 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINER)) { | |
2274 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN ER, dbgTag , | |
2275 | "openTrapS ocketIfNee ded", "usi ng port " + | |
2276 | trapSock et.getLoca lPort() + " to send traps"); | |
2277 | } | |
2278 | } | |
2279 | } | |
2280 | ||
2281 | /** | |
2282 | * Clo se trapSoc ket if the SNMP prot ocol adapt or is not ONLINE. | |
2283 | */ | |
2284 | synchr onized voi d closeTra pSocketIfN eeded() { | |
2285 | if ((trapSoc ket != nul l) && (sta te != ONLI NE)) { | |
2286 | trapSock et.close() ; | |
2287 | trapSock et = null ; | |
2288 | } | |
2289 | } | |
2290 | ||
2291 | // SEN DING SNMP INFORMS ST UFF | |
2292 | //---- ---------- ---------- --- | |
2293 | ||
2294 | /** | |
2295 | * Sen ds an info rm using S NMP V2 inf orm reques t format. | |
2296 | * <BR >The infor m request is sent to each dest ination de fined in t he ACL | |
2297 | * fil e (if avai lable). | |
2298 | * If no ACL fil e or no de stinations are avail able, the inform req uest is | |
2299 | * sen t to the l ocal host. | |
2300 | * <BR >The varia ble list i ncluded in the outgo ing inform is compos ed of | |
2301 | * the following items: | |
2302 | * <UL > | |
2303 | * <LI ><CODE>sys UpTime.0</ CODE> with its curre nt value</ LI> | |
2304 | * <LI ><CODE>snm pTrapOid.0 </CODE> wi th the val ue specifi ed by | |
2305 | * <CODE>tra pOid</CODE ></LI> | |
2306 | * <LI ><CODE>all the (oid, values)</C ODE> from the specif ied | |
2307 | * <CODE>var BindList</ CODE></LI> | |
2308 | * </U L> | |
2309 | * To send an in form reque st, the SN MP adaptor server mu st be acti ve. | |
2310 | * | |
2311 | * @pa ram cb The callback that is in voked when a request is comple te. | |
2312 | * @pa ram trapOi d The OID identifyin g the trap . | |
2313 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
2314 | * | |
2315 | * @re turn A vec tor of {@l ink com.su n.jmx.snmp .daemon.Sn mpInformRe quest} | |
2316 | * objec ts. | |
2317 | * <P>If there is no destina tion host for this i nform requ est, | |
2318 | * the r eturned ve ctor will be empty. | |
2319 | * | |
2320 | * @ex ception Il legalState Exception This meth od has bee n invoked while | |
2321 | * th e SNMP ada ptor serve r was not active. | |
2322 | * @ex ception IO Exception An I/O err or occurre d while se nding the | |
2323 | * in form reque st. | |
2324 | * @ex ception Sn mpStatusEx ception If the infor m request exceeds th e | |
2325 | * li mit define d by <CODE >bufferSiz e</CODE>. | |
2326 | */ | |
2327 | @Overr ide | |
2328 | public Vector<Sn mpInformRe quest> snm pInformReq uest(SnmpI nformHandl er cb, | |
2329 | SnmpO id trapOid , | |
2330 | SnmpV arBindList varBindLi st) | |
2331 | th rows Illeg alStateExc eption, IO Exception, SnmpStatu sException { | |
2332 | ||
2333 | if (!isActiv e()) { | |
2334 | throw ne w IllegalS tateExcept ion( | |
2335 | "Star t SNMP ada ptor serve r before c arrying ou t this ope ration"); | |
2336 | } | |
2337 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
2338 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
2339 | "snm pInformReq uest", "tr apOid=" + trapOid); | |
2340 | } | |
2341 | ||
2342 | // First, ma ke an SNMP inform pd u: | |
2343 | // We clone varBindLis t and inse rt sysUpTi me and snm pTrapOid v ariables. | |
2344 | // | |
2345 | Sn mpVarBindL ist fullVb l ; | |
2346 | if (varBindL ist != nul l) | |
2347 | fullVbl = varBindL ist.clone( ) ; | |
2348 | el se | |
2349 | fullVbl = new Snmp VarBindLis t(2) ; | |
2350 | Sn mpTimetick s sysUpTim eValue = n ew SnmpTim eticks(get SysUpTime( )) ; | |
2351 | fu llVbl.inse rtElementA t(new Snmp VarBind(sn mpTrapOidO id, trapOi d), 0) ; | |
2352 | fu llVbl.inse rtElementA t(new Snmp VarBind(sy sUpTimeOid , sysUpTim eValue), | |
2353 | 0); | |
2354 | ||
2355 | // Next, sen d the pdu to the spe cified des tination | |
2356 | // | |
2357 | op enInformSo cketIfNeed ed() ; | |
2358 | ||
2359 | // Now send the SNMP m essage to each desti nation | |
2360 | // | |
2361 | Ve ctor<SnmpI nformReque st> inform ReqList = new Vector <>(); | |
2362 | In etAddress addr; | |
2363 | St ring cs; | |
2364 | if (ipacl != null) { | |
2365 | Enumerat ion<InetAd dress> ed = ipacl.ge tInformDes tinations( ) ; | |
2366 | while (e d.hasMoreE lements()) { | |
2367 | addr = ed.next Element() ; | |
2368 | Enum eration<St ring> ec = ipacl.get InformComm unities(ad dr) ; | |
2369 | whil e (ec.hasM oreElement s()) { | |
2370 | cs = ec.ne xtElement( ) ; | |
2371 | informReqL ist.addEle ment( | |
2372 | informS ession.mak eAsyncRequ est(addr, cs, cb, | |
2373 | full Vbl,getInf ormPort()) ) ; | |
2374 | } | |
2375 | } | |
2376 | } | |
2377 | ||
2378 | re turn infor mReqList ; | |
2379 | } | |
2380 | ||
2381 | /** | |
2382 | * Sen ds an info rm using S NMP V2 inf orm reques t format. | |
2383 | * <BR >The infor m is sent to the spe cified <CO DE>InetAdd ress</CODE > | |
2384 | * des tination | |
2385 | * usi ng the spe cified com munity str ing. | |
2386 | * <BR >The varia ble list i ncluded in the outgo ing inform is compos ed | |
2387 | * of the fo llowing it ems: | |
2388 | * <UL > | |
2389 | * <LI ><CODE>sys UpTime.0</ CODE> with its curre nt value</ LI> | |
2390 | * <LI ><CODE>snm pTrapOid.0 </CODE> wi th the val ue specifi ed by | |
2391 | * <CODE>tr apOid</COD E></LI> | |
2392 | * <LI ><CODE>all the (oid, values)</C ODE> from the specif ied | |
2393 | * <CODE>var BindList</ CODE></LI> | |
2394 | * </U L> | |
2395 | * To send an in form reque st, the SN MP adaptor server mu st be acti ve. | |
2396 | * | |
2397 | * @pa ram addr T he <CODE>I netAddress </CODE> de stination for this i nform | |
2398 | * r equest. | |
2399 | * @pa ram cs The community string to be used f or the inf orm reques t. | |
2400 | * @pa ram cb The callback that is in voked when a request is comple te. | |
2401 | * @pa ram trapOi d The OID identifyin g the trap . | |
2402 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
2403 | * | |
2404 | * @re turn The i nform requ est object . | |
2405 | * | |
2406 | * @ex ception Il legalState Exception This meth od has bee n invoked | |
2407 | * wh ile the SN MP adaptor server wa s not acti ve. | |
2408 | * @ex ception IO Exception An I/O err or occurre d while se nding the | |
2409 | * in form reque st. | |
2410 | * @ex ception Sn mpStatusEx ception If the infor m request exceeds th e | |
2411 | * li mit define d by <CODE >bufferSiz e</CODE>. | |
2412 | */ | |
2413 | @Overr ide | |
2414 | public SnmpInfor mRequest s nmpInformR equest(Ine tAddress a ddr, | |
2415 | Str ing cs, | |
2416 | Snm pInformHan dler cb, | |
2417 | Snm pOid trapO id, | |
2418 | Snm pVarBindLi st varBind List) | |
2419 | th rows Illeg alStateExc eption, IO Exception, SnmpStatu sException { | |
2420 | ||
2421 | re turn snmpI nformReque st(addr, | |
2422 | getInfo rmPort(), | |
2423 | cs, | |
2424 | cb, | |
2425 | trapOid , | |
2426 | varBind List); | |
2427 | } | |
2428 | ||
2429 | /** | |
2430 | * Sen ds an info rm using S NMP V2 inf orm reques t format. | |
2431 | * <BR >The infor m is sent to the spe cified <CO DE>SnmpPee r</CODE> | |
2432 | * destinati on. | |
2433 | * <BR >The commu nity strin g used is the one lo cated in t he | |
2434 | * <CODE>Snm pPeer</COD E> paramet ers | |
2435 | * (<CODE>Sn mpParamete rs.getInfo rmCommunit y() </CODE >). | |
2436 | * <BR >The varia ble list i ncluded in the outgo ing inform is compos ed | |
2437 | * of the fo llowing it ems: | |
2438 | * <UL > | |
2439 | * <LI ><CODE>sys UpTime.0</ CODE> with its curre nt value</ LI> | |
2440 | * <LI ><CODE>snm pTrapOid.0 </CODE> wi th the val ue specifi ed by | |
2441 | * <CODE>tra pOid</CODE ></LI> | |
2442 | * <LI ><CODE>all the (oid, values)</C ODE> from the specif ied | |
2443 | * <CODE>var BindList</ CODE></LI> | |
2444 | * </U L> | |
2445 | * To send an in form reque st, the SN MP adaptor server mu st be acti ve. | |
2446 | * | |
2447 | * @pa ram peer T he <CODE>S nmpPeer</C ODE> desti nation for this info rm | |
2448 | * r equest. | |
2449 | * @pa ram cb The callback that is in voked when a request is comple te. | |
2450 | * @pa ram trapOi d The OID identifyin g the trap . | |
2451 | * @pa ram varBin dList A li st of <COD E>SnmpVarB ind</CODE> instances or null. | |
2452 | * | |
2453 | * @re turn The i nform requ est object . | |
2454 | * | |
2455 | * @ex ception Il legalState Exception This meth od has bee n invoked while | |
2456 | * th e SNMP ada ptor serve r was not active. | |
2457 | * @ex ception IO Exception An I/O err or occurre d while se nding the | |
2458 | * in form reque st. | |
2459 | * @ex ception Sn mpStatusEx ception If the infor m request exceeds th e | |
2460 | * li mit define d by <CODE >bufferSiz e</CODE>. | |
2461 | * | |
2462 | * @si nce 1.5 | |
2463 | */ | |
2464 | @Overr ide | |
2465 | public SnmpInfor mRequest s nmpInformR equest(Snm pPeer peer , | |
2466 | Snm pInformHan dler cb, | |
2467 | Snm pOid trapO id, | |
2468 | Snm pVarBindLi st varBind List) | |
2469 | th rows Illeg alStateExc eption, IO Exception, SnmpStatu sException { | |
2470 | ||
2471 | Sn mpParamete rs p = (Sn mpParamete rs) peer.g etParams() ; | |
2472 | re turn snmpI nformReque st(peer.ge tDestAddr( ), | |
2473 | peer.ge tDestPort( ), | |
2474 | p.getIn formCommun ity(), | |
2475 | cb, | |
2476 | trapOid , | |
2477 | varBind List); | |
2478 | } | |
2479 | ||
2480 | /** | |
2481 | * Met hod that m aps an SNM P error st atus in th e passed p rotocolVer sion | |
2482 | * acc ording to the provid ed pdu typ e. | |
2483 | * @pa ram errorS tatus The error stat us to conv ert. | |
2484 | * @pa ram protoc olVersion The protoc ol version . | |
2485 | * @pa ram reqPdu Type The p du type. | |
2486 | */ | |
2487 | public static in t mapError Status(int errorStat us, | |
2488 | int protocolV ersion, | |
2489 | int reqPduTyp e) { | |
2490 | re turn SnmpS ubRequestH andler.map ErrorStatu s(errorSta tus, | |
2491 | protocol Version, | |
2492 | reqPduTy pe); | |
2493 | } | |
2494 | ||
2495 | privat e SnmpInfo rmRequest snmpInform Request(In etAddress addr, | |
2496 | in t port, | |
2497 | St ring cs, | |
2498 | Sn mpInformHa ndler cb, | |
2499 | Sn mpOid trap Oid, | |
2500 | Sn mpVarBindL ist varBin dList) | |
2501 | th rows Illeg alStateExc eption, IO Exception, SnmpStatu sException { | |
2502 | ||
2503 | if (!isActiv e()) { | |
2504 | throw ne w IllegalS tateExcept ion( | |
2505 | "Start SNMP adap tor server before ca rrying out this oper ation"); | |
2506 | } | |
2507 | if (SNMP_ADA PTOR_LOGGE R.isLoggab le(Level.F INER)) { | |
2508 | SNMP_ADA PTOR_LOGGE R.logp(Lev el.FINER, dbgTag, | |
2509 | "snm pInformReq uest", "tr apOid=" + trapOid); | |
2510 | } | |
2511 | ||
2512 | // First, ma ke an SNMP inform pd u: | |
2513 | // We clone varBindLis t and inse rt sysUpTi me and snm pTrapOid v ariables. | |
2514 | // | |
2515 | Sn mpVarBindL ist fullVb l ; | |
2516 | if (varBindL ist != nul l) | |
2517 | fullVbl = varBindL ist.clone( ) ; | |
2518 | el se | |
2519 | fullVbl = new Snmp VarBindLis t(2) ; | |
2520 | Sn mpTimetick s sysUpTim eValue = n ew SnmpTim eticks(get SysUpTime( )) ; | |
2521 | fu llVbl.inse rtElementA t(new Snmp VarBind(sn mpTrapOidO id, trapOi d), 0) ; | |
2522 | fu llVbl.inse rtElementA t(new Snmp VarBind(sy sUpTimeOid , sysUpTim eValue), | |
2523 | 0); | |
2524 | ||
2525 | // Next, sen d the pdu to the spe cified des tination | |
2526 | // | |
2527 | op enInformSo cketIfNeed ed() ; | |
2528 | re turn infor mSession.m akeAsyncRe quest(addr , cs, cb, fullVbl, p ort) ; | |
2529 | } | |
2530 | ||
2531 | ||
2532 | /** | |
2533 | * Ope n informSo cket if it 's not alr eady done. | |
2534 | */ | |
2535 | synchr onized voi d openInfo rmSocketIf Needed() t hrows Sock etExceptio n { | |
2536 | if (informSe ssion == n ull) { | |
2537 | informSe ssion = ne w SnmpSess ion(this) ; | |
2538 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINER)) { | |
2539 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN ER, dbgTag , | |
2540 | " openInform SocketIfNe eded", | |
2541 | "to send inform re quests and receive i nform resp onses"); | |
2542 | } | |
2543 | } | |
2544 | } | |
2545 | ||
2546 | /** | |
2547 | * Clo se informS ocket if t he SNMP pr otocol ada ptor is no t ONLINE. | |
2548 | */ | |
2549 | synchr onized voi d closeInf ormSocketI fNeeded() { | |
2550 | if ((informS ession != null) && ( state != O NLINE)) { | |
2551 | informSe ssion.dest roySession () ; | |
2552 | informSe ssion = nu ll ; | |
2553 | } | |
2554 | } | |
2555 | ||
2556 | /** | |
2557 | * Get s the IP a ddress to bind. | |
2558 | * Thi s getter i s used to initialize the Datag ramSocket in the | |
2559 | * Snm pSocket ob ject creat ed for the inform re quest stuf f. | |
2560 | */ | |
2561 | InetAd dress getA ddress() { | |
2562 | re turn addre ss; | |
2563 | } | |
2564 | ||
2565 | ||
2566 | // PRO TECTED MET HODS | |
2567 | //---- ---------- ---- | |
2568 | ||
2569 | /** | |
2570 | * Fin alizer of the SNMP p rotocol ad aptor obje cts. | |
2571 | * Thi s method i s called b y the garb age collec tor on an object | |
2572 | * whe n garbage collection determine s that the re are no more | |
2573 | * ref erences to the objec t. | |
2574 | * <P> Closes the datagram socket ass ociated to this SNMP protocol adaptor. | |
2575 | */ | |
2576 | @Overr ide | |
2577 | protec ted void f inalize() { | |
2578 | tr y { | |
2579 | if (sock et != null ) { | |
2580 | sock et.close() ; | |
2581 | sock et = null ; | |
2582 | } | |
2583 | ||
2584 | threadSe rvice.term inate(); | |
2585 | } catch (Exc eption e) { | |
2586 | if (SNMP _ADAPTOR_L OGGER.isLo ggable(Lev el.FINER)) { | |
2587 | SNMP _ADAPTOR_L OGGER.logp (Level.FIN ER, dbgTag , | |
2588 | " finalize", "Exceptio n in final izer", e); | |
2589 | } | |
2590 | } | |
2591 | } | |
2592 | ||
2593 | // PAC KAGE METHO DS | |
2594 | //---- ---------- -- | |
2595 | ||
2596 | /** | |
2597 | * Ret urns the s tring used in debug traces. | |
2598 | */ | |
2599 | @Overr ide | |
2600 | String makeDebug Tag() { | |
2601 | re turn "Snmp AdaptorSer ver["+ get Protocol() + ":" + g etPort() + "]"; | |
2602 | } | |
2603 | ||
2604 | void u pdateReque stCounters (int pduTy pe) { | |
2605 | sw itch(pduTy pe) { | |
2606 | ||
2607 | ca se pduGetR equestPdu: | |
2608 | snmpInGe tRequests+ +; | |
2609 | break; | |
2610 | ca se pduGetN extRequest Pdu: | |
2611 | snmpInGe tNexts++; | |
2612 | break; | |
2613 | ca se pduSetR equestPdu: | |
2614 | snmpInSe tRequests+ +; | |
2615 | break; | |
2616 | de fault: | |
2617 | break; | |
2618 | } | |
2619 | sn mpInPkts++ ; | |
2620 | } | |
2621 | ||
2622 | void u pdateError Counters(i nt errorSt atus) { | |
2623 | sw itch(error Status) { | |
2624 | ||
2625 | ca se snmpRsp NoError: | |
2626 | snmpOutG etResponse s++; | |
2627 | break; | |
2628 | ca se snmpRsp GenErr: | |
2629 | snmpOutG enErrs++; | |
2630 | break; | |
2631 | ca se snmpRsp BadValue: | |
2632 | snmpOutB adValues++ ; | |
2633 | break; | |
2634 | ca se snmpRsp NoSuchName : | |
2635 | snmpOutN oSuchNames ++; | |
2636 | break; | |
2637 | ca se snmpRsp TooBig: | |
2638 | snmpOutT ooBigs++; | |
2639 | break; | |
2640 | de fault: | |
2641 | break; | |
2642 | } | |
2643 | sn mpOutPkts+ + ; | |
2644 | } | |
2645 | ||
2646 | void u pdateVarCo unters(int pduType, int n) { | |
2647 | sw itch(pduTy pe) { | |
2648 | ||
2649 | ca se pduGetR equestPdu: | |
2650 | ca se pduGetN extRequest Pdu: | |
2651 | ca se pduGetB ulkRequest Pdu: | |
2652 | snmpInTo talReqVars += n ; | |
2653 | break ; | |
2654 | ca se pduSetR equestPdu: | |
2655 | snmpInTo talSetVars += n ; | |
2656 | break ; | |
2657 | } | |
2658 | } | |
2659 | ||
2660 | void i ncSnmpInAS NParseErrs (int n) { | |
2661 | sn mpInASNPar seErrs += n ; | |
2662 | } | |
2663 | ||
2664 | void i ncSnmpInBa dVersions( int n) { | |
2665 | sn mpInBadVer sions += n ; | |
2666 | } | |
2667 | ||
2668 | void i ncSnmpInBa dCommunity Uses(int n ) { | |
2669 | sn mpInBadCom munityUses += n ; | |
2670 | } | |
2671 | ||
2672 | void i ncSnmpInBa dCommunity Names(int n) { | |
2673 | sn mpInBadCom munityName s += n ; | |
2674 | } | |
2675 | ||
2676 | void i ncSnmpSile ntDrops(in t n) { | |
2677 | sn mpSilentDr ops += n ; | |
2678 | } | |
2679 | // PRI D A N E S M T ODS | |
2680 | //---- ---------- -- | |
2681 | ||
2682 | /** | |
2683 | * Ret urns the t ime (in hu ndreths of second) e lapsed sin ce the SNM P | |
2684 | * pro tocol adap tor startu p. | |
2685 | */ | |
2686 | long g etSysUpTim e() { | |
2687 | re turn (Syst em.current TimeMillis () - start UpTime) / 10 ; | |
2688 | } | |
2689 | ||
2690 | /** | |
2691 | * Con trol the w ay the Snm pAdaptorSe rver servi ce is dese rialized. | |
2692 | */ | |
2693 | privat e void rea dObject(Ob jectInputS tream stre am) | |
2694 | th rows IOExc eption, Cl assNotFoun dException { | |
2695 | ||
2696 | // Call the default de serializat ion of the object. | |
2697 | // | |
2698 | st ream.defau ltReadObje ct(); | |
2699 | ||
2700 | // Call the specific i nitializat ion for th e SnmpAdap torServer service. | |
2701 | // This is f or transie nt structu res to be initialize d to speci fic | |
2702 | // default v alues. | |
2703 | // | |
2704 | mi bs = new Vector <>() ; | |
2705 | } | |
2706 | ||
2707 | /** | |
2708 | * Com mon initia lizations. | |
2709 | */ | |
2710 | privat e void ini t(InetAddr essAcl acl , int p, I netAddress a) { | |
2711 | ||
2712 | ro ot= new Sn mpMibTree( ); | |
2713 | ||
2714 | // The defau lt Agent i s initiali zed with a SnmpError HandlerAge nt agent. | |
2715 | ro ot.setDefa ultAgent(n ew SnmpErr orHandlerA gent()); | |
2716 | ||
2717 | // For the t rap time, use the ti me the age nt started ... | |
2718 | // | |
2719 | st artUpTime= java.lang .System.cu rrentTimeM illis(); | |
2720 | ma xActiveCli entCount = 10; | |
2721 | ||
2722 | // Create th e default message fa ctory | |
2723 | pd uFactory = new SnmpP duFactoryB ER() ; | |
2724 | ||
2725 | po rt = p ; | |
2726 | ip acl = acl ; | |
2727 | ad dress = a ; | |
2728 | ||
2729 | if ((ipacl = = null) && (useAcl = = true)) | |
2730 | throw ne w IllegalA rgumentExc eption("AC L object c annot be n ull") ; | |
2731 | ||
2732 | th readServic e = new Th readServic e(threadNu mber); | |
2733 | } | |
2734 | ||
2735 | SnmpMi bAgent get AgentMib(S nmpOid oid ) { | |
2736 | re turn root. getAgentMi b(oid); | |
2737 | } | |
2738 | ||
2739 | @Overr ide | |
2740 | protec ted Thread createMai nThread() { | |
2741 | fi nal Thread t = super .createMai nThread(); | |
2742 | t. setDaemon( true); | |
2743 | re turn t; | |
2744 | } | |
2745 | ||
2746 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.