001: /*_############################################################################
002: _##
003: _## SNMP4J-Agent - Snmp4jConfigMib.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.agent.mo.snmp4j;
022:
023: //--AgentGen BEGIN=_BEGIN
024: //--AgentGen END
025:
026: import java.io.*;
027:
028: import org.snmp4j.*;
029: import org.snmp4j.agent.*;
030: import org.snmp4j.agent.io.*;
031: import org.snmp4j.agent.mo.*;
032: import org.snmp4j.agent.mo.snmp.*;
033: import org.snmp4j.agent.request.*;
034: import org.snmp4j.mp.*;
035: import org.snmp4j.smi.*;
036: import org.snmp4j.agent.mo.snmp4j.Snmp4jConfigMib.Snmp4jCfgStorageEntryRow;
037: import org.snmp4j.log.LogFactory;
038: import org.snmp4j.log.LogAdapter;
039:
040: //--AgentGen BEGIN=_IMPORT
041: //--AgentGen END
042:
043: public class Snmp4jConfigMib
044: //--AgentGen BEGIN=_EXTENDS
045: //--AgentGen END
046: implements MOGroup
047: //--AgentGen BEGIN=_IMPLEMENTS
048: //--AgentGen END
049: {
050:
051: private static final LogAdapter logger = LogFactory
052: .getLogger(Snmp4jConfigMib.class);
053:
054: // Factory
055: private static MOFactory moFactory = DefaultMOFactory.getInstance();
056:
057: // Constants
058: private static final OID oidSnmp4jCfgSecSrcAddrValidation = new OID(
059: new int[] { 1, 3, 6, 1, 4, 1, 4976, 10, 1, 1, 2, 1, 1, 1, 0 });
060:
061: // Scalars
062: private MOScalar snmp4jCfgSecSrcAddrValidation;
063:
064: // Tables
065: private static final OID oidSnmp4jCfgStorageEntry = new OID(
066: new int[] { 1, 3, 6, 1, 4, 1, 4976, 10, 1, 1, 2, 1, 2, 1, 1 });
067:
068: // Column sub-identifer defintions for snmp4jCfgStorageEntry:
069: private static final int colSnmp4jCfgStoragePath = 2;
070: private static final int colSnmp4jCfgStorageFormat = 3;
071: private static final int colSnmp4jCfgStorageLastStore = 4;
072: private static final int colSnmp4jCfgStorageLastRestore = 5;
073: private static final int colSnmp4jCfgStorageRestoreMode = 6;
074: private static final int colSnmp4jCfgStorageOperation = 7;
075: private static final int colSnmp4jCfgStorageStorageType = 8;
076: private static final int colSnmp4jCfgStorageStatus = 9;
077:
078: // Column index defintions for snmp4jCfgStorageEntry:
079: private static final int idxSnmp4jCfgStoragePath = 0;
080: private static final int idxSnmp4jCfgStorageFormat = 1;
081: private static final int idxSnmp4jCfgStorageLastStore = 2;
082: private static final int idxSnmp4jCfgStorageLastRestore = 3;
083: private static final int idxSnmp4jCfgStorageRestoreMode = 4;
084: private static final int idxSnmp4jCfgStorageOperation = 5;
085: private static final int idxSnmp4jCfgStorageStorageType = 6;
086: private static final int idxSnmp4jCfgStorageStatus = 7;
087: private static MOTableSubIndex[] snmp4jCfgStorageEntryIndexes = new MOTableSubIndex[] { moFactory
088: .createSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 0, 255) };
089:
090: private static MOTableIndex snmp4jCfgStorageEntryIndex = moFactory
091: .createIndex(snmp4jCfgStorageEntryIndexes, false);
092:
093: private MOTable snmp4jCfgStorageEntry;
094: private MOMutableTableModel snmp4jCfgStorageEntryModel;
095:
096: //--AgentGen BEGIN=_MEMBERS
097: public static final OID PRIMARY_INDEX = new OctetString("primary")
098: .toSubIndex(false);
099:
100: protected SnmpCommunityMIB snmpCommunityMIB;
101: protected MOPersistenceProvider[] persistenceProvider = new MOPersistenceProvider[Snmp4jCfgStorageFormatEnum.xml];
102: protected File defaultConfigFile;
103: protected SysUpTime sysUpTime;
104:
105: private File configPathRoot;
106:
107: //--AgentGen END
108:
109: public Snmp4jConfigMib(SysUpTime sysUpTime) {
110: this .sysUpTime = sysUpTime;
111: snmp4jCfgSecSrcAddrValidation = new Snmp4jCfgSecSrcAddrValidation(
112: oidSnmp4jCfgSecSrcAddrValidation,
113: MOAccessImpl.ACCESS_READ_WRITE);
114: createSnmp4jCfgStorageEntry();
115: configPathRoot = new File(System.getProperty("user.dir", ""));
116: }
117:
118: public MOTable getSnmp4jCfgStorageEntry() {
119: return snmp4jCfgStorageEntry;
120: }
121:
122: public File getDefaultConfigFile() {
123: return defaultConfigFile;
124: }
125:
126: private void createSnmp4jCfgStorageEntry() {
127: MOColumn[] snmp4jCfgStorageEntryColumns = new MOColumn[8];
128: snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStoragePath] = new DisplayString(
129: colSnmp4jCfgStoragePath,
130: MOAccessImpl.ACCESS_READ_CREATE, null, true, 0, 255);
131: ((MOMutableColumn) snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStoragePath])
132: .addMOValueValidationListener(new Snmp4jCfgStoragePathValidator());
133: snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageFormat] = new Enumerated(
134: colSnmp4jCfgStorageFormat,
135: MOAccessImpl.ACCESS_READ_CREATE, new Integer32(1),
136: true, new int[] { Snmp4jCfgStorageFormatEnum.binary,
137: Snmp4jCfgStorageFormatEnum.xml });
138: ((MOMutableColumn) snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageFormat])
139: .addMOValueValidationListener(new Snmp4jCfgStorageFormatValidator());
140: snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageLastStore] = new MOColumn(
141: colSnmp4jCfgStorageLastStore,
142: SMIConstants.SYNTAX_TIMETICKS,
143: MOAccessImpl.ACCESS_READ_ONLY);
144: snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageLastRestore] = new MOColumn(
145: colSnmp4jCfgStorageLastRestore,
146: SMIConstants.SYNTAX_TIMETICKS,
147: MOAccessImpl.ACCESS_READ_ONLY);
148: snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageRestoreMode] = new Enumerated(
149: colSnmp4jCfgStorageRestoreMode,
150: MOAccessImpl.ACCESS_READ_CREATE,
151: new Integer32(1),
152: true,
153: new int[] {
154: Snmp4jCfgStorageRestoreModeEnum.replaceAndCreate,
155: Snmp4jCfgStorageRestoreModeEnum.updateAndCreate,
156: Snmp4jCfgStorageRestoreModeEnum.updateOnly,
157: Snmp4jCfgStorageRestoreModeEnum.createOnly });
158: snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageOperation] = new Enumerated(
159: colSnmp4jCfgStorageOperation,
160: MOAccessImpl.ACCESS_READ_CREATE, new Integer32(1),
161: true, new int[] { Snmp4jCfgStorageOperationEnum.idle,
162: Snmp4jCfgStorageOperationEnum.inProgress,
163: Snmp4jCfgStorageOperationEnum.store,
164: Snmp4jCfgStorageOperationEnum.restore });
165: ((MOMutableColumn) snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageOperation])
166: .addMOValueValidationListener(new Snmp4jCfgStorageOperationValidator());
167: snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageStorageType] = new StorageType(
168: colSnmp4jCfgStorageStorageType,
169: MOAccessImpl.ACCESS_READ_CREATE, new Integer32(3), true);
170: snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageStatus] = new RowStatus(
171: colSnmp4jCfgStorageStatus);
172:
173: snmp4jCfgStorageEntryModel = new DefaultMOMutableTableModel();
174: snmp4jCfgStorageEntryModel
175: .setRowFactory(new Snmp4jCfgStorageEntryRowFactory());
176: snmp4jCfgStorageEntry = moFactory.createTable(
177: oidSnmp4jCfgStorageEntry, snmp4jCfgStorageEntryIndex,
178: snmp4jCfgStorageEntryColumns,
179: snmp4jCfgStorageEntryModel);
180: }
181:
182: public void registerMOs(MOServer server, OctetString context)
183: throws DuplicateRegistrationException {
184: // Scalar Objects
185: server.register(this .snmp4jCfgSecSrcAddrValidation, context);
186: server.register(this .snmp4jCfgStorageEntry, context);
187: //--AgentGen BEGIN=_registerMOs
188: //--AgentGen END
189: }
190:
191: public void unregisterMOs(MOServer server, OctetString context) {
192: // Scalar Objects
193: server.unregister(this .snmp4jCfgSecSrcAddrValidation, context);
194: server.unregister(this .snmp4jCfgStorageEntry, context);
195: //--AgentGen BEGIN=_unregisterMOs
196: //--AgentGen END
197: }
198:
199: // Notifications
200:
201: // Scalars
202: public class Snmp4jCfgSecSrcAddrValidation extends EnumeratedScalar {
203: Snmp4jCfgSecSrcAddrValidation(OID oid, MOAccess access) {
204: super (oid, access, new Integer32(), new int[] {
205: Snmp4jCfgSecSrcAddrValidationEnum.enabled,
206: Snmp4jCfgSecSrcAddrValidationEnum.disabled,
207: Snmp4jCfgSecSrcAddrValidationEnum.notAvailable });
208: //--AgentGen BEGIN=snmp4jCfgSecSrcAddrValidation
209: //--AgentGen END
210: }
211:
212: public Variable getValue() {
213: if (snmpCommunityMIB != null) {
214: if (snmpCommunityMIB.isSourceAddressFiltering()) {
215: setValue(new Integer32(
216: Snmp4jCfgSecSrcAddrValidationEnum.enabled));
217: } else {
218: setValue(new Integer32(
219: Snmp4jCfgSecSrcAddrValidationEnum.disabled));
220: }
221: } else {
222: setValue(new Integer32(
223: Snmp4jCfgSecSrcAddrValidationEnum.notAvailable));
224: }
225: return (Variable) super .getValue().clone();
226: }
227:
228: public void commit(SubRequest request) {
229: //--AgentGen BEGIN=snmp4jCfgSecSrcAddrValidation::commit
230: Integer32 newValue = (Integer32) request
231: .getVariableBinding().getVariable();
232: switch (newValue.getValue()) {
233: case Snmp4jCfgSecSrcAddrValidationEnum.disabled:
234: snmpCommunityMIB.setSourceAddressFiltering(false);
235: break;
236: case Snmp4jCfgSecSrcAddrValidationEnum.enabled:
237: snmpCommunityMIB.setSourceAddressFiltering(true);
238: break;
239: default:
240: request.getRequest().setErrorStatus(PDU.commitFailed);
241: }
242: //--AgentGen END
243: super .commit(request);
244: }
245:
246: public void cleanup(SubRequest request) {
247: //--AgentGen BEGIN=snmp4jCfgSecSrcAddrValidation::cleanup
248: //--AgentGen END
249: super .cleanup(request);
250: }
251:
252: public int isValueOK(SubRequest request) {
253: Variable newValue = request.getVariableBinding()
254: .getVariable();
255: //--AgentGen BEGIN=snmp4jCfgSecSrcAddrValidation::isValueOK
256: if (snmpCommunityMIB != null) {
257: switch (((Integer32) newValue).getValue()) {
258: case Snmp4jCfgSecSrcAddrValidationEnum.disabled:
259: case Snmp4jCfgSecSrcAddrValidationEnum.enabled:
260: break;
261: default:
262: return PDU.wrongValue;
263: }
264: } else if (((Integer32) newValue).getValue() != Snmp4jCfgSecSrcAddrValidationEnum.notAvailable) {
265: return PDU.inconsistentValue;
266: } else {
267: return PDU.wrongValue;
268: }
269: //--AgentGen END
270: return super .isValueOK(request);
271: }
272: }
273:
274: // Value Validators
275:
276: /**
277: * The <code>Snmp4jCfgStoragePathValidator</code> implements the value
278: * validation for <code>Snmp4jCfgStoragePath</code>.
279: */
280: static class Snmp4jCfgStoragePathValidator implements
281: MOValueValidationListener {
282:
283: public void validate(MOValueValidationEvent validationEvent) {
284: Variable newValue = validationEvent.getNewValue();
285: OctetString os = (OctetString) newValue;
286: if (!(((os.length() >= 0) && (os.length() <= 255)))) {
287: validationEvent
288: .setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
289: return;
290: }
291: //--AgentGen BEGIN=snmp4jCfgStoragePath::validate
292: //--AgentGen END
293: }
294: }
295:
296: /**
297: * The <code>Snmp4jCfgStorageFormatValidator</code> implements the value
298: * validation for <code>Snmp4jCfgStorageFormat</code>.
299: */
300: static class Snmp4jCfgStorageFormatValidator implements
301: MOValueValidationListener {
302:
303: public void validate(MOValueValidationEvent validationEvent) {
304: Variable newValue = validationEvent.getNewValue();
305: //--AgentGen BEGIN=snmp4jCfgStorageFormat::validate
306: if (((Integer32) newValue).getValue() != Snmp4jCfgStorageFormatEnum.binary) {
307: validationEvent.setValidationStatus(PDU.wrongValue);
308: }
309: //--AgentGen END
310: }
311: }
312:
313: /**
314: * The <code>Snmp4jCfgStorageOperationValidator</code> implements the value
315: * validation for <code>Snmp4jCfgStorageOperation</code>.
316: */
317: static class Snmp4jCfgStorageOperationValidator implements
318: MOValueValidationListener {
319:
320: public void validate(MOValueValidationEvent validationEvent) {
321: Variable newValue = validationEvent.getNewValue();
322: //--AgentGen BEGIN=snmp4jCfgStorageOperation::validate
323: switch (newValue.toInt()) {
324: case Snmp4jCfgStorageOperationEnum.restore:
325: case Snmp4jCfgStorageOperationEnum.store:
326: break;
327: default:
328: validationEvent.setValidationStatus(PDU.wrongValue);
329: }
330: //--AgentGen END
331: }
332: }
333:
334: // Enumerations
335: public static final class Snmp4jCfgSecSrcAddrValidationEnum {
336: public static final int enabled = 1;
337: public static final int disabled = 2;
338: public static final int notAvailable = 3;
339: }
340:
341: public static final class Snmp4jCfgStorageFormatEnum {
342: /* -- Default format */
343: public static final int binary = 1;
344: public static final int xml = 2;
345: }
346:
347: public static final class Snmp4jCfgStorageRestoreModeEnum {
348: public static final int replaceAndCreate = 1;
349: public static final int updateAndCreate = 2;
350: public static final int updateOnly = 3;
351: public static final int createOnly = 4;
352: }
353:
354: public static final class Snmp4jCfgStorageOperationEnum {
355: /* -- no action */
356: public static final int idle = 1;
357: /* -- (re)store operation in progress */
358: public static final int inProgress = 2;
359: /* -- store current configuration */
360: public static final int store = 3;
361: /* -- restore configuration */
362: public static final int restore = 4;
363: }
364:
365: // Rows and Factories
366: class Snmp4jCfgStorageEntryRowFactory extends
367: DefaultMOMutableRow2PCFactory {
368: public Snmp4jCfgStorageEntryRowFactory() {
369: }
370:
371: public MOTableRow createRow(OID index, Variable[] values)
372: throws UnsupportedOperationException {
373: Snmp4jCfgStorageEntryRow row = new Snmp4jCfgStorageEntryRow(
374: index, values);
375: //--AgentGen BEGIN=snmp4jCfgStorageEntry::createRow
376: ((Integer32) values[idxSnmp4jCfgStorageOperation])
377: .setValue(Snmp4jCfgStorageOperationEnum.idle);
378: //--AgentGen END
379: return row;
380: }
381:
382: public void freeRow(MOTableRow row) {
383: //--AgentGen BEGIN=snmp4jCfgStorageEntry::freeRow
384: //--AgentGen END
385: }
386: }
387:
388: class Snmp4jCfgStorageEntryRow extends DefaultMOMutableRow2PC {
389:
390: public Snmp4jCfgStorageEntryRow(OID index, Variable[] values) {
391: super (index, values);
392: }
393:
394: public OctetString getSnmp4jCfgStoragePath() {
395: return (OctetString) getValue(idxSnmp4jCfgStoragePath);
396: }
397:
398: public void setSnmp4jCfgStoragePath(OctetString newValue) {
399: setValue(idxSnmp4jCfgStoragePath, newValue);
400: }
401:
402: public Integer32 getSnmp4jCfgStorageFormat() {
403: return (Integer32) getValue(idxSnmp4jCfgStorageFormat);
404: }
405:
406: public void setSnmp4jCfgStorageFormat(Integer32 newValue) {
407: setValue(idxSnmp4jCfgStorageFormat, newValue);
408: }
409:
410: public TimeTicks getSnmp4jCfgStorageLastStore() {
411: return (TimeTicks) getValue(idxSnmp4jCfgStorageLastStore);
412: }
413:
414: public void setSnmp4jCfgStorageLastStore(TimeTicks newValue) {
415: setValue(idxSnmp4jCfgStorageLastStore, newValue);
416: }
417:
418: public TimeTicks getSnmp4jCfgStorageLastRestore() {
419: return (TimeTicks) getValue(idxSnmp4jCfgStorageLastRestore);
420: }
421:
422: public void setSnmp4jCfgStorageLastRestore(TimeTicks newValue) {
423: setValue(idxSnmp4jCfgStorageLastRestore, newValue);
424: }
425:
426: public Integer32 getSnmp4jCfgStorageRestoreMode() {
427: return (Integer32) getValue(idxSnmp4jCfgStorageRestoreMode);
428: }
429:
430: public void setSnmp4jCfgStorageRestoreMode(Integer32 newValue) {
431: setValue(idxSnmp4jCfgStorageRestoreMode, newValue);
432: }
433:
434: public Integer32 getSnmp4jCfgStorageOperation() {
435: return (Integer32) getValue(idxSnmp4jCfgStorageOperation);
436: }
437:
438: public void setSnmp4jCfgStorageOperation(Integer32 newValue) {
439: setValue(idxSnmp4jCfgStorageOperation, newValue);
440: }
441:
442: public Integer32 getSnmp4jCfgStorageStorageType() {
443: return (Integer32) getValue(idxSnmp4jCfgStorageStorageType);
444: }
445:
446: public void setSnmp4jCfgStorageStorageType(Integer32 newValue) {
447: setValue(idxSnmp4jCfgStorageStorageType, newValue);
448: }
449:
450: public Integer32 getSnmp4jCfgStorageStatus() {
451: return (Integer32) getValue(idxSnmp4jCfgStorageStatus);
452: }
453:
454: public void setSnmp4jCfgStorageStatus(Integer32 newValue) {
455: setValue(idxSnmp4jCfgStorageStatus, newValue);
456: }
457:
458: //--AgentGen BEGIN=snmp4jCfgStorageEntry::RowFactory
459:
460: public void prepareRow(SubRequest subRequest,
461: MOTableRow changeSet) {
462: if (PRIMARY_INDEX.equals(changeSet.getIndex())) {
463: if (snmp4jCfgStorageEntryModel.getRow(PRIMARY_INDEX) == null) {
464: subRequest.getRequest().setErrorStatus(
465: PDU.noCreation);
466: }
467: }
468: }
469:
470: public void commitRow(SubRequest subRequest,
471: MOTableRow changeSet) {
472: Integer32 operation = getSnmp4jCfgStorageOperation();
473: Integer32 format = getSnmp4jCfgStorageFormat();
474: if (format.getValue() == Snmp4jCfgStorageFormatEnum.binary) {
475: MOPersistenceProvider provider = getPersistenceProvider(format
476: .getValue());
477: if (provider == null) {
478: subRequest.getRequest().setErrorStatus(
479: PDU.commitFailed);
480: } else {
481: Operation op = new Operation(
482: this ,
483: provider,
484: getSnmp4jCfgStorageRestoreMode().getValue(),
485: operation.getValue());
486: setValue(
487: idxSnmp4jCfgStorageOperation,
488: new Integer32(
489: Snmp4jCfgStorageOperationEnum.inProgress));
490: op.start();
491: }
492: } else {
493: subRequest.getRequest()
494: .setErrorStatus(PDU.commitFailed);
495: }
496: }
497:
498: //--AgentGen END
499: }
500:
501: //--AgentGen BEGIN=_METHODS
502:
503: public void setSnmpCommunityMIB(SnmpCommunityMIB snmpCommunityMIB) {
504: this .snmpCommunityMIB = snmpCommunityMIB;
505: }
506:
507: public void setDefaultConfigFile(File defaultConfigFile) {
508: this .defaultConfigFile = defaultConfigFile;
509:
510: Snmp4jCfgStorageEntryRow primary = (Snmp4jCfgStorageEntryRow) snmp4jCfgStorageEntryModel
511: .getRow(PRIMARY_INDEX);
512: if (primary == null) {
513: Variable[] vbs = snmp4jCfgStorageEntry.getDefaultValues();
514: vbs[idxSnmp4jCfgStorageStatus] = new Integer32(
515: RowStatus.active);
516: primary = (Snmp4jCfgStorageEntryRow) snmp4jCfgStorageEntry
517: .createRow(PRIMARY_INDEX, vbs);
518: primary.setSnmp4jCfgStorageStorageType(new Integer32(
519: StorageType.permanent));
520: primary.setSnmp4jCfgStorageOperation(new Integer32(
521: Snmp4jCfgStorageOperationEnum.idle));
522: snmp4jCfgStorageEntry.addRow(primary);
523: }
524: primary.setSnmp4jCfgStoragePath(new OctetString(
525: defaultConfigFile.getPath()));
526: }
527:
528: public void setPersistenceProvider(int format,
529: MOPersistenceProvider provider) {
530: persistenceProvider[format - 1] = provider;
531: }
532:
533: public MOPersistenceProvider getPersistenceProvider(int format) {
534: return persistenceProvider[format - 1];
535: }
536:
537: public SnmpCommunityMIB getCoexistenceInfoProvider() {
538: return this .snmpCommunityMIB;
539: }
540:
541: //--AgentGen END
542:
543: //--AgentGen BEGIN=_CLASSES
544:
545: private class Operation extends Thread {
546:
547: private Snmp4jCfgStorageEntryRow row;
548: private int operation;
549: private int restoreType;
550: private MOPersistenceProvider provider;
551:
552: public Operation(Snmp4jCfgStorageEntryRow row,
553: MOPersistenceProvider provider, int restoreType,
554: int operation) {
555: this .operation = operation;
556: this .provider = provider;
557: this .restoreType = restoreType;
558: this .row = row;
559: }
560:
561: public void run() {
562: switch (operation) {
563: case Snmp4jCfgStorageOperationEnum.store: {
564: File f = new File(row.getValue(idxSnmp4jCfgStoragePath)
565: .toString());
566: FileOutputStream fos = null;
567: try {
568: fos = new FileOutputStream(f);
569: provider.saveConfig(fos);
570: fos.close();
571: row.setValue(idxSnmp4jCfgStorageLastStore,
572: sysUpTime.get());
573: row
574: .setValue(
575: idxSnmp4jCfgStorageOperation,
576: new Integer32(
577: Snmp4jCfgStorageOperationEnum.idle));
578: } catch (Exception iox) {
579: logger.warn("Failed to store config to '" + f
580: + "': " + iox.getMessage());
581: row
582: .setValue(
583: idxSnmp4jCfgStorageOperation,
584: new Integer32(
585: Snmp4jCfgStorageOperationEnum.idle));
586: } finally {
587: if (fos != null) {
588: try {
589: fos.close();
590: } catch (IOException ex) {
591: logger.warn(ex);
592: }
593: }
594: }
595: break;
596: }
597: case Snmp4jCfgStorageOperationEnum.restore: {
598: File f = new File(row.getValue(idxSnmp4jCfgStoragePath)
599: .toString());
600: if (f.exists() && f.canRead()) {
601: FileInputStream fis = null;
602: try {
603: fis = new FileInputStream(f);
604: provider.loadConfig(fis, restoreType);
605: fis.close();
606: row.setValue(idxSnmp4jCfgStorageLastRestore,
607: sysUpTime.get());
608: row
609: .setValue(
610: idxSnmp4jCfgStorageOperation,
611: new Integer32(
612: Snmp4jCfgStorageOperationEnum.idle));
613: } catch (Exception iox) {
614: logger.warn("Failed to restore config from '"
615: + f + "': " + iox.getMessage());
616: row
617: .setValue(
618: idxSnmp4jCfgStorageOperation,
619: new Integer32(
620: Snmp4jCfgStorageOperationEnum.idle));
621: } finally {
622: if (fis != null) {
623: try {
624: fis.close();
625: } catch (IOException ex) {
626: logger.warn(ex);
627: }
628: }
629: }
630: } else {
631: logger.warn("File '" + f
632: + "' does not exists or is not readable");
633: row
634: .setValue(
635: idxSnmp4jCfgStorageOperation,
636: new Integer32(
637: Snmp4jCfgStorageOperationEnum.idle));
638: }
639: break;
640: }
641: }
642: }
643: }
644:
645: //--AgentGen END
646:
647: //--AgentGen BEGIN=_END
648: //--AgentGen END
649: }
|