📄 snmp4jconfigmib.java
字号:
/*_############################################################################
_##
_## SNMP4J-Agent - Snmp4jConfigMib.java
_##
_## Copyright 2005-2006 Frank Fock (SNMP4J.org)
_##
_## Licensed under the Apache License, Version 2.0 (the "License");
_## you may not use this file except in compliance with the License.
_## You may obtain a copy of the License at
_##
_## http://www.apache.org/licenses/LICENSE-2.0
_##
_## Unless required by applicable law or agreed to in writing, software
_## distributed under the License is distributed on an "AS IS" BASIS,
_## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
_## See the License for the specific language governing permissions and
_## limitations under the License.
_##
_##########################################################################*/
package org.snmp4j.agent.mo.snmp4j;
//--AgentGen BEGIN=_BEGIN
//--AgentGen END
import java.io.*;
import org.snmp4j.*;
import org.snmp4j.agent.*;
import org.snmp4j.agent.io.*;
import org.snmp4j.agent.mo.*;
import org.snmp4j.agent.mo.snmp.*;
import org.snmp4j.agent.request.*;
import org.snmp4j.mp.*;
import org.snmp4j.smi.*;
import org.snmp4j.agent.mo.snmp4j.Snmp4jConfigMib.Snmp4jCfgStorageEntryRow;
import org.snmp4j.log.LogFactory;
import org.snmp4j.log.LogAdapter;
//--AgentGen BEGIN=_IMPORT
//--AgentGen END
public class Snmp4jConfigMib
//--AgentGen BEGIN=_EXTENDS
//--AgentGen END
implements MOGroup
//--AgentGen BEGIN=_IMPLEMENTS
//--AgentGen END
{
private static final LogAdapter logger =
LogFactory.getLogger(Snmp4jConfigMib.class);
// Factory
private static MOFactory moFactory = DefaultMOFactory.getInstance();
// Constants
private static final OID oidSnmp4jCfgSecSrcAddrValidation =
new OID(new int[] { 1,3,6,1,4,1,4976,10,1,1,2,1,1,1,0 });
// Scalars
private MOScalar snmp4jCfgSecSrcAddrValidation;
// Tables
private static final OID oidSnmp4jCfgStorageEntry =
new OID(new int[] { 1,3,6,1,4,1,4976,10,1,1,2,1,2,1,1 });
// Column sub-identifer defintions for snmp4jCfgStorageEntry:
private static final int colSnmp4jCfgStoragePath = 2;
private static final int colSnmp4jCfgStorageFormat = 3;
private static final int colSnmp4jCfgStorageLastStore = 4;
private static final int colSnmp4jCfgStorageLastRestore = 5;
private static final int colSnmp4jCfgStorageRestoreMode = 6;
private static final int colSnmp4jCfgStorageOperation = 7;
private static final int colSnmp4jCfgStorageStorageType = 8;
private static final int colSnmp4jCfgStorageStatus = 9;
// Column index defintions for snmp4jCfgStorageEntry:
private static final int idxSnmp4jCfgStoragePath = 0;
private static final int idxSnmp4jCfgStorageFormat = 1;
private static final int idxSnmp4jCfgStorageLastStore = 2;
private static final int idxSnmp4jCfgStorageLastRestore = 3;
private static final int idxSnmp4jCfgStorageRestoreMode = 4;
private static final int idxSnmp4jCfgStorageOperation = 5;
private static final int idxSnmp4jCfgStorageStorageType = 6;
private static final int idxSnmp4jCfgStorageStatus = 7;
private static MOTableSubIndex[] snmp4jCfgStorageEntryIndexes =
new MOTableSubIndex[] {
moFactory.createSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 0, 255)
};
private static MOTableIndex snmp4jCfgStorageEntryIndex =
moFactory.createIndex(snmp4jCfgStorageEntryIndexes,
false);
private MOTable snmp4jCfgStorageEntry;
private MOMutableTableModel snmp4jCfgStorageEntryModel;
//--AgentGen BEGIN=_MEMBERS
public static final OID PRIMARY_INDEX =
new OctetString("primary").toSubIndex(false);
protected SnmpCommunityMIB snmpCommunityMIB;
protected MOPersistenceProvider[] persistenceProvider =
new MOPersistenceProvider[Snmp4jCfgStorageFormatEnum.xml];
protected File defaultConfigFile;
protected SysUpTime sysUpTime;
private File configPathRoot;
//--AgentGen END
public Snmp4jConfigMib(SysUpTime sysUpTime) {
this.sysUpTime = sysUpTime;
snmp4jCfgSecSrcAddrValidation =
new Snmp4jCfgSecSrcAddrValidation(oidSnmp4jCfgSecSrcAddrValidation,
MOAccessImpl.ACCESS_READ_WRITE);
createSnmp4jCfgStorageEntry();
configPathRoot = new File(System.getProperty("user.dir", ""));
}
public MOTable getSnmp4jCfgStorageEntry() {
return snmp4jCfgStorageEntry;
}
public File getDefaultConfigFile() {
return defaultConfigFile;
}
private void createSnmp4jCfgStorageEntry() {
MOColumn[] snmp4jCfgStorageEntryColumns = new MOColumn[8];
snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStoragePath] =
new DisplayString(colSnmp4jCfgStoragePath,
MOAccessImpl.ACCESS_READ_CREATE,
null,
true,
0, 255);
((MOMutableColumn)snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStoragePath]).
addMOValueValidationListener(new Snmp4jCfgStoragePathValidator());
snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageFormat] =
new Enumerated(colSnmp4jCfgStorageFormat,
MOAccessImpl.ACCESS_READ_CREATE,
new Integer32(1),
true,
new int[] { Snmp4jCfgStorageFormatEnum.binary,
Snmp4jCfgStorageFormatEnum.xml });
((MOMutableColumn)snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageFormat]).
addMOValueValidationListener(new Snmp4jCfgStorageFormatValidator());
snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageLastStore] =
new MOColumn(colSnmp4jCfgStorageLastStore,
SMIConstants.SYNTAX_TIMETICKS,
MOAccessImpl.ACCESS_READ_ONLY);
snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageLastRestore] =
new MOColumn(colSnmp4jCfgStorageLastRestore,
SMIConstants.SYNTAX_TIMETICKS,
MOAccessImpl.ACCESS_READ_ONLY);
snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageRestoreMode] =
new Enumerated(colSnmp4jCfgStorageRestoreMode,
MOAccessImpl.ACCESS_READ_CREATE,
new Integer32(1),
true,
new int[] { Snmp4jCfgStorageRestoreModeEnum.replaceAndCreate,
Snmp4jCfgStorageRestoreModeEnum.updateAndCreate,
Snmp4jCfgStorageRestoreModeEnum.updateOnly,
Snmp4jCfgStorageRestoreModeEnum.createOnly });
snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageOperation] =
new Enumerated(colSnmp4jCfgStorageOperation,
MOAccessImpl.ACCESS_READ_CREATE,
new Integer32(1),
true,
new int[] { Snmp4jCfgStorageOperationEnum.idle,
Snmp4jCfgStorageOperationEnum.inProgress,
Snmp4jCfgStorageOperationEnum.store,
Snmp4jCfgStorageOperationEnum.restore });
((MOMutableColumn)snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageOperation]).
addMOValueValidationListener(new Snmp4jCfgStorageOperationValidator());
snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageStorageType] =
new StorageType(colSnmp4jCfgStorageStorageType,
MOAccessImpl.ACCESS_READ_CREATE,
new Integer32(3),
true);
snmp4jCfgStorageEntryColumns[idxSnmp4jCfgStorageStatus] =
new RowStatus(colSnmp4jCfgStorageStatus);
snmp4jCfgStorageEntryModel = new DefaultMOMutableTableModel();
snmp4jCfgStorageEntryModel.setRowFactory(new Snmp4jCfgStorageEntryRowFactory());
snmp4jCfgStorageEntry =
moFactory.createTable(oidSnmp4jCfgStorageEntry,
snmp4jCfgStorageEntryIndex,
snmp4jCfgStorageEntryColumns,
snmp4jCfgStorageEntryModel);
}
public void registerMOs(MOServer server, OctetString context)
throws DuplicateRegistrationException
{
// Scalar Objects
server.register(this.snmp4jCfgSecSrcAddrValidation, context);
server.register(this.snmp4jCfgStorageEntry, context);
//--AgentGen BEGIN=_registerMOs
//--AgentGen END
}
public void unregisterMOs(MOServer server, OctetString context) {
// Scalar Objects
server.unregister(this.snmp4jCfgSecSrcAddrValidation, context);
server.unregister(this.snmp4jCfgStorageEntry, context);
//--AgentGen BEGIN=_unregisterMOs
//--AgentGen END
}
// Notifications
// Scalars
public class Snmp4jCfgSecSrcAddrValidation extends EnumeratedScalar {
Snmp4jCfgSecSrcAddrValidation(OID oid, MOAccess access) {
super(oid, access, new Integer32(),
new int[] { Snmp4jCfgSecSrcAddrValidationEnum.enabled,
Snmp4jCfgSecSrcAddrValidationEnum.disabled,
Snmp4jCfgSecSrcAddrValidationEnum.notAvailable });
//--AgentGen BEGIN=snmp4jCfgSecSrcAddrValidation
//--AgentGen END
}
public Variable getValue() {
if (snmpCommunityMIB != null) {
if (snmpCommunityMIB.isSourceAddressFiltering()) {
setValue(new Integer32(Snmp4jCfgSecSrcAddrValidationEnum.enabled));
}
else {
setValue(new Integer32(Snmp4jCfgSecSrcAddrValidationEnum.disabled));
}
}
else {
setValue(new Integer32(Snmp4jCfgSecSrcAddrValidationEnum.notAvailable));
}
return (Variable) super.getValue().clone();
}
public void commit(SubRequest request) {
//--AgentGen BEGIN=snmp4jCfgSecSrcAddrValidation::commit
Integer32 newValue =
(Integer32) request.getVariableBinding().getVariable();
switch (newValue.getValue()) {
case Snmp4jCfgSecSrcAddrValidationEnum.disabled:
snmpCommunityMIB.setSourceAddressFiltering(false);
break;
case Snmp4jCfgSecSrcAddrValidationEnum.enabled:
snmpCommunityMIB.setSourceAddressFiltering(true);
break;
default:
request.getRequest().setErrorStatus(PDU.commitFailed);
}
//--AgentGen END
super.commit(request);
}
public void cleanup(SubRequest request) {
//--AgentGen BEGIN=snmp4jCfgSecSrcAddrValidation::cleanup
//--AgentGen END
super.cleanup(request);
}
public int isValueOK(SubRequest request) {
Variable newValue =
request.getVariableBinding().getVariable();
//--AgentGen BEGIN=snmp4jCfgSecSrcAddrValidation::isValueOK
if (snmpCommunityMIB != null) {
switch (((Integer32)newValue).getValue()) {
case Snmp4jCfgSecSrcAddrValidationEnum.disabled:
case Snmp4jCfgSecSrcAddrValidationEnum.enabled:
break;
default:
return PDU.wrongValue;
}
}
else if (((Integer32)newValue).getValue() !=
Snmp4jCfgSecSrcAddrValidationEnum.notAvailable) {
return PDU.inconsistentValue;
}
else {
return PDU.wrongValue;
}
//--AgentGen END
return super.isValueOK(request);
}
}
// Value Validators
/**
* The <code>Snmp4jCfgStoragePathValidator</code> implements the value
* validation for <code>Snmp4jCfgStoragePath</code>.
*/
static class Snmp4jCfgStoragePathValidator implements MOValueValidationListener {
public void validate(MOValueValidationEvent validationEvent) {
Variable newValue = validationEvent.getNewValue();
OctetString os = (OctetString)newValue;
if (!(((os.length() >= 0) && (os.length() <= 255)))) {
validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
return;
}
//--AgentGen BEGIN=snmp4jCfgStoragePath::validate
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -