1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.snmp.r66;
21
22 import org.snmp4j.agent.DuplicateRegistrationException;
23 import org.snmp4j.agent.MOServer;
24 import org.snmp4j.agent.mo.MOAccessImpl;
25 import org.snmp4j.agent.mo.snmp.SNMPv2MIB;
26 import org.snmp4j.agent.mo.snmp.SysUpTime;
27 import org.snmp4j.smi.Integer32;
28 import org.snmp4j.smi.OID;
29 import org.snmp4j.smi.OctetString;
30 import org.snmp4j.smi.SMIConstants;
31 import org.snmp4j.smi.TimeTicks;
32 import org.waarp.common.logging.WaarpLogger;
33 import org.waarp.common.logging.WaarpLoggerFactory;
34 import org.waarp.snmp.WaarpSnmpAgent;
35 import org.waarp.snmp.interf.WaarpInterfaceMib;
36 import org.waarp.snmp.utils.MemoryGauge32;
37 import org.waarp.snmp.utils.MemoryGauge32.MemoryType;
38 import org.waarp.snmp.utils.WaarpEntry;
39 import org.waarp.snmp.utils.WaarpMORow;
40 import org.waarp.snmp.utils.WaarpMOScalar;
41 import org.waarp.snmp.utils.WaarpUptime;
42
43
44
45
46 public abstract class WaarpPrivateMib implements WaarpInterfaceMib {
47
48
49
50 private static final WaarpLogger logger =
51 WaarpLoggerFactory.getLogger(WaarpPrivateMib.class);
52
53
54
55
56
57 public final String textualSysDecr;
58
59
60
61
62 public final OID ggObjectId;
63
64
65
66
67 public String contactName = "Nobody";
68
69
70
71
72 public String textualName = "OpenR66";
73
74
75
76
77 public String address = "somewhere";
78
79
80
81
82
83
84 public int service = 72;
85
86
87
88
89 public SysUpTime upTime;
90
91
92
93
94
95
96 public final String applicationProtocolBase;
97
98
99
100
101 public final OID applicationProtocol;
102
103
104
105
106 public int smiPrivateCode = 66666;
107
108
109
110
111 public int smiTypeWaarp = 66;
112
113
114
115 public final String srootOIDWaarp;
116
117
118
119 public final OID rootOIDWaarp;
120
121
122
123
124 public final OID rootOIDWaarpNotif;
125
126
127
128
129 public final OID rootOIDWaarpNotifStartOrShutdown;
130
131
132
133
134 public final OID rootOIDWaarpInfo;
135
136
137
138 public WaarpMORow rowInfo;
139
140
141
142
143 public final OID rootOIDWaarpGlobal;
144
145
146
147 public WaarpMORow rowGlobal;
148
149
150
151
152 public final OID rootOIDWaarpGlobalUptime;
153
154
155
156
157 public WaarpMOScalar scalarUptime;
158
159
160
161
162 public final OID rootOIDWaarpDetailed;
163
164
165
166 public WaarpMORow rowDetailed;
167
168
169
170
171 public final OID rootOIDWaarpError;
172
173
174
175 public WaarpMORow rowError;
176
177
178
179
180 public SNMPv2MIB snmpv2;
181
182
183
184
185 public WaarpSnmpAgent agent;
186
187
188
189
190
191
192
193
194
195
196
197 protected WaarpPrivateMib(final String sysdesc, final int port,
198 final int smiPrivateCodeFinal,
199 final int typeWaarpObject,
200 final String scontactName,
201 final String stextualName, final String saddress,
202 final int iservice) {
203 textualSysDecr = sysdesc;
204 smiPrivateCode = smiPrivateCodeFinal;
205 smiTypeWaarp = typeWaarpObject;
206 contactName = scontactName;
207 textualName = stextualName;
208 address = saddress;
209 service = iservice;
210 srootOIDWaarp =
211 rootEnterpriseMib + "." + smiPrivateCode + '.' + smiTypeWaarp;
212 applicationProtocolBase = srootOIDWaarp + ".1.1.4.";
213 ggObjectId = new OID(srootOIDWaarp);
214 applicationProtocol = new OID(applicationProtocolBase + port);
215 rootOIDWaarp = new OID(srootOIDWaarp);
216 rootOIDWaarpInfo = new OID(srootOIDWaarp + ".1");
217 rootOIDWaarpGlobal = new OID(srootOIDWaarp + ".2");
218 rootOIDWaarpGlobalUptime = new OID(
219 rootOIDWaarpGlobal + "." + WaarpGlobalValuesIndex.applUptime.getOID() +
220 ".0");
221 rootOIDWaarpDetailed = new OID(srootOIDWaarp + ".3");
222 rootOIDWaarpError = new OID(srootOIDWaarp + ".4");
223 rootOIDWaarpNotif = new OID(srootOIDWaarp + ".5.1");
224 rootOIDWaarpNotifStartOrShutdown = new OID(srootOIDWaarp + ".5.1.1.1");
225 }
226
227 @Override
228 public final void setAgent(final WaarpSnmpAgent agent) {
229 this.agent = agent;
230 }
231
232 @Override
233 public final OID getBaseOidStartOrShutdown() {
234 return rootOIDWaarpNotifStartOrShutdown;
235 }
236
237 @Override
238 public final SNMPv2MIB getSNMPv2MIB() {
239 return snmpv2;
240 }
241
242
243
244
245
246
247
248 protected final void agentRegisterSystem()
249 throws DuplicateRegistrationException {
250
251
252
253
254 agent.unregisterManagedObject(agent.getSnmpv2MIB());
255
256
257
258 snmpv2 = new SNMPv2MIB(new OctetString(textualSysDecr), ggObjectId,
259 new Integer32(service));
260 snmpv2.setContact(new OctetString(contactName));
261 snmpv2.setLocation(new OctetString(address));
262 snmpv2.setName(new OctetString(textualName));
263 snmpv2.registerMOs(agent.getServer(), null);
264 if (logger.isDebugEnabled()) {
265 logger.debug("SNMPV2: {}:{}:{}:{}:{}:{}:{}", snmpv2.getContact(),
266 snmpv2.getDescr(), snmpv2.getLocation(), snmpv2.getName(),
267 snmpv2.getObjectID(), snmpv2.getServices(),
268 snmpv2.getUpTime());
269 }
270
271 upTime = snmpv2.getSysUpTime();
272 }
273
274
275
276
277
278
279 protected final void defaultAgentRegisterWaarpMib()
280 throws DuplicateRegistrationException {
281
282 rowInfo = new WaarpMORow(this, rootOIDWaarpInfo, WaarpDefinition,
283 MibLevel.staticInfo.ordinal());
284 rowInfo.registerMOs(agent.getServer(), null);
285
286 rowGlobal = new WaarpMORow(this, rootOIDWaarpGlobal, WaarpGlobalValues,
287 MibLevel.globalInfo.ordinal());
288 WaarpMOScalar memoryScalar =
289 rowGlobal.getRow()[WaarpGlobalValuesIndex.memoryTotal.ordinal()];
290 memoryScalar.setValue(new MemoryGauge32(MemoryType.TotalMemory));
291 memoryScalar =
292 rowGlobal.getRow()[WaarpGlobalValuesIndex.memoryFree.ordinal()];
293 memoryScalar.setValue(new MemoryGauge32(MemoryType.FreeMemory));
294 memoryScalar =
295 rowGlobal.getRow()[WaarpGlobalValuesIndex.memoryUsed.ordinal()];
296 memoryScalar.setValue(new MemoryGauge32(MemoryType.UsedMemory));
297 rowGlobal.registerMOs(agent.getServer(), null);
298
299 scalarUptime =
300 rowGlobal.getRow()[WaarpGlobalValuesIndex.applUptime.ordinal()];
301 scalarUptime.setValue(new WaarpUptime(upTime));
302 changeStatus(OperStatus.restarting);
303 changeStatus(OperStatus.up);
304
305 rowDetailed =
306 new WaarpMORow(this, rootOIDWaarpDetailed, WaarpDetailedValues,
307 MibLevel.detailedInfo.ordinal());
308 rowDetailed.registerMOs(agent.getServer(), null);
309
310 rowError = new WaarpMORow(this, rootOIDWaarpError, WaarpErrorValues,
311 MibLevel.errorInfo.ordinal());
312 rowError.registerMOs(agent.getServer(), null);
313 }
314
315
316
317
318
319
320 protected abstract void agentRegisterWaarpMib()
321 throws DuplicateRegistrationException;
322
323
324
325
326 protected final void agentUnregisterMibs() {
327 logger.debug("UnRegisterWaarp");
328 rowInfo.unregisterMOs(agent.getServer(), agent.getDefaultContext());
329 rowGlobal.unregisterMOs(agent.getServer(), agent.getDefaultContext());
330 rowDetailed.unregisterMOs(agent.getServer(), agent.getDefaultContext());
331 rowError.unregisterMOs(agent.getServer(), agent.getDefaultContext());
332 }
333
334 @Override
335 public final void registerMOs(final MOServer server,
336 final OctetString context)
337 throws DuplicateRegistrationException {
338 agentRegisterSystem();
339 agentRegisterWaarpMib();
340 }
341
342 @Override
343 public final void unregisterMOs(final MOServer server,
344 final OctetString context) {
345 agentUnregisterMibs();
346 }
347
348
349
350
351
352
353 public final void changeStatus(final OperStatus status) {
354 final WaarpMOScalar statusScalar =
355 rowGlobal.getRow()[WaarpGlobalValuesIndex.applOperStatus.ordinal()];
356 final Integer32 var = (Integer32) statusScalar.getValue();
357 if (var.getValue() != status.status) {
358 var.setValue(status.status);
359 final WaarpMOScalar lastTimeScalar =
360 rowGlobal.getRow()[WaarpGlobalValuesIndex.applLastChange.ordinal()];
361 final TimeTicks time = (TimeTicks) lastTimeScalar.getValue();
362 time.setValue(upTime.get().getValue());
363 }
364 }
365
366
367
368
369 public enum MibLevel {
370 staticInfo, globalInfo, detailedInfo, errorInfo, trapInfo
371 }
372
373
374
375
376
377
378 public enum NotificationElements {
379 TrapShutdown(1), TrapError(2), TrapWarning(3), TrapOverloaded(4),
380 InfoTask(5);
381
382 public final int[] oid;
383
384 NotificationElements(final int oid) {
385 this.oid = new int[] { oid };
386 }
387
388 public final OID getOID(final OID oidBase) {
389 return new OID(oidBase.getValue(), oid);
390 }
391
392 public final OID getOID(final OID oidBase, final int rank) {
393 final int[] ids = { oid[0], rank };
394 return new OID(oidBase.getValue(), ids);
395 }
396 }
397
398
399
400
401 public enum NotificationTasks {
402 globalStepInfo, stepInfo, rankFileInfo, stepStatusInfo, filenameInfo,
403 originalNameInfo, idRuleInfo, modeTransInfo, retrieveModeInfo,
404 startTransInfo, infoStatusInfo, requesterInfo, requestedInfo, specialIdInfo;
405
406 public final int getOID() {
407 return ordinal() + 1;
408 }
409 }
410
411
412
413
414 public enum WaarpDefinitionIndex {
415 applName, applServerName, applVersion, applDescription, applURL,
416 applApplicationProtocol;
417
418 public final int getOID() {
419 return ordinal() + 1;
420 }
421 }
422
423
424
425
426 public static final WaarpEntry[] WaarpDefinition = {
427
428 new WaarpEntry(SMIConstants.SYNTAX_OCTET_STRING,
429 MOAccessImpl.ACCESS_READ_ONLY),
430
431 new WaarpEntry(SMIConstants.SYNTAX_OCTET_STRING,
432 MOAccessImpl.ACCESS_READ_ONLY),
433
434 new WaarpEntry(SMIConstants.SYNTAX_OCTET_STRING,
435 MOAccessImpl.ACCESS_READ_ONLY),
436
437 new WaarpEntry(SMIConstants.SYNTAX_OCTET_STRING,
438 MOAccessImpl.ACCESS_READ_ONLY),
439
440 new WaarpEntry(SMIConstants.SYNTAX_OCTET_STRING,
441 MOAccessImpl.ACCESS_READ_ONLY),
442
443 new WaarpEntry(SMIConstants.SYNTAX_OBJECT_IDENTIFIER,
444 MOAccessImpl.ACCESS_READ_ONLY)
445 };
446
447
448
449
450 public enum WaarpGlobalValuesIndex {
451 applUptime, applOperStatus, applLastChange, applInboundAssociations,
452 applOutboundAssociations, applAccumInboundAssociations,
453 applAccumOutboundAssociations, applLastInboundActivity,
454 applLastOutboundActivity, applRejectedInboundAssociations,
455 applFailedOutboundAssociations, applInboundBandwidthKBS,
456 applOutboundBandwidthKBS, nbInfoUnknown, nbInfoNotUpdated,
457 nbInfoInterrupted, nbInfoToSubmit, nbInfoError, nbInfoRunning, nbInfoDone,
458 nbStepAllTransfer, memoryTotal, memoryFree, memoryUsed, nbThreads,
459 nbNetworkConnection;
460
461 public final int getOID() {
462 return ordinal() + 1;
463 }
464 }
465
466
467
468
469 public static final WaarpEntry[] WaarpGlobalValues = {
470
471 new WaarpEntry(SMIConstants.SYNTAX_TIMETICKS,
472 MOAccessImpl.ACCESS_READ_ONLY),
473
474 new WaarpEntry(SMIConstants.SYNTAX_INTEGER,
475 MOAccessImpl.ACCESS_READ_ONLY),
476
477 new WaarpEntry(SMIConstants.SYNTAX_TIMETICKS,
478 MOAccessImpl.ACCESS_READ_ONLY),
479
480 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
481 MOAccessImpl.ACCESS_READ_ONLY),
482
483 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
484 MOAccessImpl.ACCESS_READ_ONLY),
485
486 new WaarpEntry(SMIConstants.SYNTAX_COUNTER32,
487 MOAccessImpl.ACCESS_READ_ONLY),
488
489 new WaarpEntry(SMIConstants.SYNTAX_COUNTER32,
490 MOAccessImpl.ACCESS_READ_ONLY),
491
492 new WaarpEntry(SMIConstants.SYNTAX_TIMETICKS,
493 MOAccessImpl.ACCESS_READ_ONLY),
494
495 new WaarpEntry(SMIConstants.SYNTAX_TIMETICKS,
496 MOAccessImpl.ACCESS_READ_ONLY),
497
498 new WaarpEntry(SMIConstants.SYNTAX_COUNTER32,
499 MOAccessImpl.ACCESS_READ_ONLY),
500
501 new WaarpEntry(SMIConstants.SYNTAX_COUNTER32,
502 MOAccessImpl.ACCESS_READ_ONLY),
503
504
505 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
506 MOAccessImpl.ACCESS_READ_ONLY),
507
508 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
509 MOAccessImpl.ACCESS_READ_ONLY),
510
511
512 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
513 MOAccessImpl.ACCESS_READ_ONLY),
514
515 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
516 MOAccessImpl.ACCESS_READ_ONLY),
517
518 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
519 MOAccessImpl.ACCESS_READ_ONLY),
520
521 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
522 MOAccessImpl.ACCESS_READ_ONLY),
523
524 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
525 MOAccessImpl.ACCESS_READ_ONLY),
526
527 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
528 MOAccessImpl.ACCESS_READ_ONLY),
529
530 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
531 MOAccessImpl.ACCESS_READ_ONLY),
532
533
534 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
535 MOAccessImpl.ACCESS_READ_ONLY),
536
537 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
538 MOAccessImpl.ACCESS_READ_ONLY),
539
540 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
541 MOAccessImpl.ACCESS_READ_ONLY),
542
543 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
544 MOAccessImpl.ACCESS_READ_ONLY),
545
546 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
547 MOAccessImpl.ACCESS_READ_ONLY),
548
549 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32, MOAccessImpl.ACCESS_READ_ONLY)
550 };
551
552
553
554
555 public enum WaarpDetailedValuesIndex {
556 nbStepNotask, nbStepPretask, nbStepTransfer, nbStepPosttask, nbStepAllDone,
557 nbStepError, nbAllRunningStep, nbRunningStep, nbInitOkStep,
558 nbPreProcessingOkStep, nbTransferOkStep, nbPostProcessingOkStep,
559 nbCompleteOkStep;
560
561 public final int getOID() {
562 return ordinal() + 1;
563 }
564 }
565
566
567
568
569 public static final WaarpEntry[] WaarpDetailedValues = {
570
571 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
572 MOAccessImpl.ACCESS_READ_ONLY),
573
574 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
575 MOAccessImpl.ACCESS_READ_ONLY),
576
577 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
578 MOAccessImpl.ACCESS_READ_ONLY),
579
580 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
581 MOAccessImpl.ACCESS_READ_ONLY),
582
583 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
584 MOAccessImpl.ACCESS_READ_ONLY),
585
586 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
587 MOAccessImpl.ACCESS_READ_ONLY),
588
589
590 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
591 MOAccessImpl.ACCESS_READ_ONLY),
592
593 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
594 MOAccessImpl.ACCESS_READ_ONLY),
595
596 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
597 MOAccessImpl.ACCESS_READ_ONLY),
598
599 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
600 MOAccessImpl.ACCESS_READ_ONLY),
601
602 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
603 MOAccessImpl.ACCESS_READ_ONLY),
604
605 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
606 MOAccessImpl.ACCESS_READ_ONLY),
607
608 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32, MOAccessImpl.ACCESS_READ_ONLY)
609 };
610
611
612
613
614 public enum WaarpErrorValuesIndex {
615 nbStatusConnectionImpossible, nbStatusServerOverloaded, nbStatusBadAuthent,
616 nbStatusExternalOp, nbStatusTransferError, nbStatusMD5Error,
617 nbStatusDisconnection, nbStatusFinalOp, nbStatusUnimplemented,
618 nbStatusInternal, nbStatusWarning, nbStatusQueryAlreadyFinished,
619 nbStatusQueryStillRunning, nbStatusNotKnownHost,
620 nbStatusQueryRemotelyUnknown, nbStatusCommandNotFound,
621 nbStatusPassThroughMode, nbStatusRemoteShutdown, nbStatusShutdown,
622 nbStatusRemoteError, nbStatusStopped, nbStatusCanceled,
623 nbStatusFileNotFound, nbStatusUnknown;
624
625 public final int getOID() {
626 return ordinal() + 1;
627 }
628 }
629
630
631
632
633 public static final WaarpEntry[] WaarpErrorValues = {
634
635
636 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
637 MOAccessImpl.ACCESS_READ_ONLY),
638
639 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
640 MOAccessImpl.ACCESS_READ_ONLY),
641
642 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
643 MOAccessImpl.ACCESS_READ_ONLY),
644
645 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
646 MOAccessImpl.ACCESS_READ_ONLY),
647
648 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
649 MOAccessImpl.ACCESS_READ_ONLY),
650
651 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
652 MOAccessImpl.ACCESS_READ_ONLY),
653
654 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
655 MOAccessImpl.ACCESS_READ_ONLY),
656
657 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
658 MOAccessImpl.ACCESS_READ_ONLY),
659
660 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
661 MOAccessImpl.ACCESS_READ_ONLY),
662
663 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
664 MOAccessImpl.ACCESS_READ_ONLY),
665
666 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
667 MOAccessImpl.ACCESS_READ_ONLY),
668
669 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
670 MOAccessImpl.ACCESS_READ_ONLY),
671
672 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
673 MOAccessImpl.ACCESS_READ_ONLY),
674
675 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
676 MOAccessImpl.ACCESS_READ_ONLY),
677
678 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
679 MOAccessImpl.ACCESS_READ_ONLY),
680
681 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
682 MOAccessImpl.ACCESS_READ_ONLY),
683
684 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
685 MOAccessImpl.ACCESS_READ_ONLY),
686
687 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
688 MOAccessImpl.ACCESS_READ_ONLY),
689
690 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
691 MOAccessImpl.ACCESS_READ_ONLY),
692
693 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
694 MOAccessImpl.ACCESS_READ_ONLY),
695
696 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
697 MOAccessImpl.ACCESS_READ_ONLY),
698
699 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
700 MOAccessImpl.ACCESS_READ_ONLY),
701
702 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32,
703 MOAccessImpl.ACCESS_READ_ONLY),
704
705 new WaarpEntry(SMIConstants.SYNTAX_GAUGE32, MOAccessImpl.ACCESS_READ_ONLY)
706 };
707
708
709
710
711 public enum OperStatus {
712 up(1), down(2), halted(3), congested(4), restarting(5), quiescing(6);
713
714 public final int status;
715
716 OperStatus(final int status) {
717 this.status = status;
718 }
719 }
720 }