[SNMP4J] Please need help with trap filtering
nino fattore
ninofattore at yahoo.com
Sat May 28 00:43:31 CEST 2016
I'd like to know what is wrong with my code!My goal is to learn how to filter notification sent out.With the following code i am trying to use the NotifyFilterTable and NotifyFilterProfileTable to send
all the traps to all the targets. the following step (once the following code is working) is to try to send different traps to different targets.Thanks,Nino
protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB) {
targetMIB.addDefaultTDomains();
targetMIB.addTargetAddress(new OctetString("notificationV3"),
TransportDomains.transportDomainUdpIpv4,
new OctetString(new UdpAddress("92.135.77.100/162").getValue()),
500, 1,
new OctetString("notify"),
new OctetString("v3notify"),
StorageType.permanent);
targetMIB.addTargetParams(new OctetString("v3notify"),
MessageProcessingModel.MPv3,
SecurityModel.SECURITY_MODEL_USM,
//new OctetString("v3notify"),
//SecurityLevel.NOAUTH_NOPRIV,
// new OctetString("SHADES"),
new OctetString("NINO"),
SecurityLevel.AUTH_PRIV,
StorageType.permanent);
notificationMIB.addNotifyEntry(new OctetString("v3notify"),
new OctetString("notify"),
SnmpNotificationMIB.SnmpNotifyTypeEnum.trap/,
StorageType.permanent);
notificationMIB.getNotifyFilterProfileTable().addRow(
notificationMIB.getNotifyFilterProfileTable().createRow(
new OctetString("v3notify").toSubIndex(true),
new Variable[]{
new OctetString("v3notify"),
new Integer32(StorageType.permanent),
new Integer32(RowStatus.active)
}));
notificationMIB.getNotifyFilterTable().addRow(
notificationMIB.getNotifyFilterTable().createRow(
new OctetString("v3notify").toSubIndex(false).append(new OID(new int[]{1,3}).toSubIndex(true)),
new Variable[]{
new OID(new int[]{1,3}),
new OctetString(),
new Integer32(1), // Included
new Integer32(StorageType.permanent),
new Integer32(RowStatus.active)}));
}
protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1,
new OctetString("cpublic"),
new OctetString("v1v2group"),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString("public"/*"cpublic"*/),
new OctetString("v1v2group"),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString("NINO"),
new OctetString("v3group"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v1v2group"), new OctetString(""/*"public"*/),
SecurityModel.SECURITY_MODEL_ANY,
SecurityLevel.NOAUTH_NOPRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullReadView"),
new OctetString("fullWriteView"),
new OctetString("fullNotifyView"),
//new OctetString("unrestrictedReadView"),
//new OctetString("unrestrictedView"),
//new OctetString("unrestrictedNotifyView"),
StorageType.permanent/* .nonVolatile*/);
vacm.addAccess(new OctetString("v3group"), new OctetString(),
SecurityModel.SECURITY_MODEL_USM,
SecurityLevel.AUTH_PRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullReadView"),
new OctetString("fullWriteView"),
new OctetString("fullNotifyView"),
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
// StorageType.nonVolatile);
StorageType.permanent);
vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3.6.1.2.1.1.1.0"),
new OctetString(), VacmMIB.vacmViewExcluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullNotifyView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.permanent);
}
protected void addUsmUser(USM usm) {
UsmUser user = new UsmUser(new OctetString("NINO"),
AuthSHA.ID,
new OctetString("ninoPassword"),
PrivDES.ID,
new OctetString("ninoPassword"));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
}
More information about the SNMP4J
mailing list