📄 snmpnotificationmib.java
字号:
snmpNotifyFilterEntry =
new DefaultMOTable(oidSnmpNotifyFilterEntry,
snmpNotifyFilterEntryIndex,
snmpNotifyFilterEntryColumns);
snmpNotifyFilterEntryModel = new DefaultMOMutableTableModel();
snmpNotifyFilterEntryModel.setRowFactory(new DefaultMOMutableRow2PCFactory());
snmpNotifyFilterEntry.setModel(snmpNotifyFilterEntryModel);
}
private void createSnmpNotifyFilterProfileEntry() {
MOColumn[] snmpNotifyFilterProfileEntryColumns = new MOColumn[3];
snmpNotifyFilterProfileEntryColumns[idxSnmpNotifyFilterProfileName] =
new SnmpAdminString(colSnmpNotifyFilterProfileName,
MOAccessImpl.ACCESS_READ_CREATE,
new OctetString(),
true, 1, 32);
snmpNotifyFilterProfileEntryColumns[idxSnmpNotifyFilterProfileStorType] =
new StorageType(colSnmpNotifyFilterProfileStorType,
MOAccessImpl.ACCESS_READ_CREATE,
new Integer32(3),
true);
snmpNotifyFilterProfileEntryColumns[idxSnmpNotifyFilterProfileRowStatus] =
new RowStatus(colSnmpNotifyFilterProfileRowStatus);
snmpNotifyFilterProfileEntry =
new DefaultMOTable(oidSnmpNotifyFilterProfileEntry,
snmpNotifyFilterProfileEntryIndex,
snmpNotifyFilterProfileEntryColumns);
snmpNotifyFilterProfileEntryModel = new DefaultMOMutableTableModel();
snmpNotifyFilterProfileEntryModel.setRowFactory(new DefaultMOMutableRow2PCFactory());
snmpNotifyFilterProfileEntry.setModel(snmpNotifyFilterProfileEntryModel);
}
public void registerMOs(MOServer server, OctetString context)
throws DuplicateRegistrationException
{
// Scalar Objects
server.register(this.snmpNotifyEntry, context);
server.register(this.snmpNotifyFilterEntry, context);
server.register(this.snmpNotifyFilterProfileEntry, context);
}
public void unregisterMOs(MOServer server, OctetString context) {
// Scalar Objects
server.unregister(this.snmpNotifyEntry, context);
server.unregister(this.snmpNotifyFilterEntry, context);
server.unregister(this.snmpNotifyFilterProfileEntry, context);
}
public boolean addNotifyEntry(OctetString name, OctetString tag, int type,
int storageType) {
Variable[] vbs = new Variable[snmpNotifyEntry.getColumnCount()];
int n=0;
vbs[n++] = tag;
vbs[n++] = new Integer32(type);
vbs[n++] = new Integer32(storageType);
vbs[n++] = new Integer32(RowStatus.active);
OID index = name.toSubIndex(true);
MOTableRow row = snmpNotifyEntry.createRow(index, vbs);
snmpNotifyEntry.addRow(row);
return true;
}
public DefaultMOTable getNotifyTable() {
return snmpNotifyEntry;
}
public DefaultMOTable getNotifyFilterTable() {
return snmpNotifyFilterEntry;
}
public DefaultMOTable getNotifyFilterProfileTable() {
return snmpNotifyFilterProfileEntry;
}
public boolean passesFilter(OID paramsIndex, OID notificationID,
VariableBinding[] vbs) {
MOTableRowFilter activeFilter =
new RowStatus.ActiveRowsFilter(idxSnmpNotifyFilterProfileRowStatus);
List profiles =
snmpNotifyFilterProfileEntryModel.getRows(paramsIndex, paramsIndex,
activeFilter);
if (profiles.size() == 0) {
// no profile -> passes filter
return true;
}
OctetString profileName = (OctetString)
((MOTableRow)profiles.get(0)).getValue(idxSnmpNotifyFilterProfileName);
OID profileNameOID = profileName.toSubIndex(true);
OID profileNameOIDNext = profileNameOID.successor();
activeFilter = new RowStatus.ActiveRowsFilter(idxSnmpNotifyFilterRowStatus);
List filters =
snmpNotifyFilterEntryModel.getRows(profileNameOID,
profileNameOIDNext,
activeFilter);
if (filters.size() == 0) {
// no filters -> no trap is sent
return false;
}
TreeMap oidMatches = new TreeMap();
TreeMap[] vbMatches = new TreeMap[vbs.length];
for (Iterator it = filters.iterator(); it.hasNext(); ) {
MOTableRow row = (MOTableRow) it.next();
Variable[] indexValues =
snmpNotifyFilterEntryIndex.getIndexValues(row.getIndex());
OID subtree = (OID) indexValues[idxSnmpNotifyFilterSubtree];
OctetString mask = (OctetString)row.getValue(idxSnmpNotifyFilterMask);
Integer32 type = (Integer32)row.getValue(idxSnmpNotifyFilterType);
OID subtreeWithLength = new OID();
subtreeWithLength.append(subtree.size());
subtreeWithLength.append(subtree);
if (isInSubtree(notificationID, subtree, mask)) {
oidMatches.put(subtreeWithLength, type);
}
// filter VBs
for (int i=0; i<vbs.length; i++) {
if (isInSubtree(vbs[i].getOid(), subtree, mask)) {
if (vbMatches[i] == null) {
vbMatches[i] = new TreeMap();
}
vbMatches[i].put(subtreeWithLength, type);
}
}
}
if (oidMatches.size() == 0) {
// no matches against notification ID
if (logger.isInfoEnabled()) {
logger.info("Filter " + profileName +
" has no matches for notification ID " +
notificationID);
}
return false;
}
else if (((Integer32)oidMatches.get(oidMatches.lastKey())).getValue() ==
SnmpNotifyFilterTypeEnum.excluded) {
if (logger.isInfoEnabled()) {
logger.info("Notification ID " + notificationID +
" is excluded from filter " + profileName);
}
return false;
}
for (int i=0; i<vbMatches.length; i++) {
if ((vbMatches[i] != null) && (vbMatches[i].size() > 0)) {
if (((Integer32)vbMatches[i].get(vbMatches[i].lastKey())).getValue() ==
SnmpNotifyFilterTypeEnum.excluded) {
if (logger.isInfoEnabled()) {
logger.info("Variable binding " + vbs[i] +
" is not in filter " + profileName);
}
return false;
}
}
}
return true;
}
private static boolean isInSubtree(OID oid, OID subtree, OctetString mask) {
OID maskedSubtree = subtree.mask(mask);
OID maskedOID = oid.mask(mask);
if (maskedOID.equals(maskedSubtree)) {
return true;
}
return maskedOID.startsWith(maskedSubtree);
}
// Enumerations
public static final class SnmpNotifyTypeEnum {
public static final int trap = 1;
public static final int inform = 2;
}
public static final class SnmpNotifyFilterTypeEnum {
public static final int included = 1;
public static final int excluded = 2;
}
// Scalars
// Value Validators
/**
* The <code>SnmpNotifyFilterMaskValidator</code> implements the value validation
* for <code>SnmpNotifyFilterMask</code>.
*/
static class SnmpNotifyFilterMaskValidator implements MOValueValidationListener {
public void validate(MOValueValidationEvent validationEvent) {
Variable newValue = validationEvent.getNewValue();
OctetString os = (OctetString)newValue;
if (!(((os.length() >= 0) && (os.length() <= 16)))) {
validationEvent.setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
return;
}
//--AgentGen BEGIN=snmpNotifyFilterMask::validate
//--AgentGen END
}
}
//--AgentGen BEGIN=_CLASSES
//--AgentGen END
//--AgentGen BEGIN=_END
//--AgentGen END
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -