So I have been playing around with creating simulated agents to run in our system. So far I have successfully implemented V1 and V2 using the TestAgent example. However, I am having issues configuring the code to allow for V3. I was wondering if you could lend some assistance showing me what configuration setting I’m missing?
Given the Simulated V1 I am able to get a Server response with
snmpwalk.exe -v1 -c public 127.0.0.3:16100 1.3.6.1.2.2.0
AgentCodeV1-
public class TestAgent extends BaseAgent {
// initialize Log4J logging
static {
LogFactory.setLogFactory(new Log4jLogFactory());
}
protected String address;
/**
* Creates the test agent with a file to read and store the boot counter and
* a file to read and store its configuration.
*
* @param bootCounterFile
* a file containing the boot counter in serialized form (as expected by
* BaseAgent).
* @param configFile
* a configuration file with serialized management information.
* @throws IOException
* if the boot counter or config file cannot be read properly.
*/
public TestAgent(File bootCounterFile, File configFile) throws IOException {
super(bootCounterFile, configFile,
new CommandProcessor(new OctetString(MPv3.createLocalEngineID())));
}
protected void registerManagedObjects() {
try {
VariableBinding vb = new VariableBinding(new OID("1.3.6.1.4.1.73.1.8.2.1.1.1.10.1"),new OctetString("WinsXP"));
StaticMOGroup group = new StaticMOGroup(new OID("1.2.3.4.5.6.7"),new VariableBinding[]{vb});
MOScalar mo = new MOScalar(new OID("1.3.6.1.2.2.0"), MOAccessImpl.ACCESS_READ_WRITE, new OctetString("This is a test"));
server.register(mo, new OctetString("public"));
}
catch (DuplicateRegistrationException ex) {
ex.printStackTrace();
}
}
protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB) {}
protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1,
new OctetString("cpublic"),
new OctetString("v1v2group"),
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"),
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
}
protected void addUsmUser(USM usm) {
}
protected void initTransportMappings() throws IOException {
transportMappings = new TransportMapping[1];
Address addr = GenericAddress.parse(address);
TransportMapping tm =
TransportMappings.getInstance().createTransportMapping(addr);
transportMappings[0] = tm;
}
public static void main(String[] args) {
String address;
if (args.length > 0) {
address = args[0];
}
else {
address = "127.0.0.3/16100";
}
BasicConfigurator.configure();
try {
TestAgent testAgent1 = new TestAgent(new File("SNMP4JTestAgentBC.cfg"),
new File("SNMP4JTestAgentConfig.cfg"));
testAgent1.address = address;
testAgent1.init();
testAgent1.loadConfig(ImportModes.REPLACE_CREATE);
testAgent1.addShutdownHook();
testAgent1.getServer().addContext(new OctetString("public"));
testAgent1.finishInit();
testAgent1.run();
testAgent1.sendColdStartNotification();
/* Try to rerun agent:
try {
Thread.sleep(30000);
}
catch (InterruptedException ex2) {
}
testAgent1.stop();
testAgent1.run();
*/
while (true) {
try {
Thread.sleep(1000);
}
catch (InterruptedException ex1) {
break;
}
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
protected void unregisterManagedObjects() {
// here we should unregister those objects previously registered...
}
protected void addCommunities(SnmpCommunityMIB communityMIB) {
Variable[] com2sec = new Variable[] {
new OctetString("public"), // community name
new OctetString("cpublic"), // security name
getAgent().getContextEngineID(), // local engine ID
new OctetString("public"), // default context name
new OctetString(), // transport tag
new Integer32(StorageType.nonVolatile), // storage type
new Integer32(RowStatus.active) // row status
};
SnmpCommunityMIB.SnmpCommunityEntryRow row =
communityMIB.getSnmpCommunityEntry().createRow(
new OctetString("public2public").toSubIndex(true), com2sec);
communityMIB.getSnmpCommunityEntry().addRow(row);
// snmpCommunityMIB.setSourceAddressFiltering(true);
}
}
I have attempted to configure this to V3 by adding a UsmUser
protected void addUsmUser(USM usm) {
UsmUser user = new UsmUser(new OctetString("TEST"),
AuthSHA.ID,
new OctetString("maplesyrup"),
PrivDES.ID,
new OctetString("maplesyrup"));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
}
And adding security settings to the VacmView
protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString("TEST"),
new OctetString("v3test"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v3test"),
new OctetString("public")
, SecurityModel.SECURITY_MODEL_USM,
SecurityLevel.NOAUTH_NOPRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullReadView"),
new OctetString("fullWriteView"),
new OctetString("fullNotifyView"),
StorageType.nonVolatile);
Attempting to reach the server Via Net-SNMP command results in undesired results. .
snmpwalk -v3 -l noAuthNoPriv -u TEST -a SHA -A "maplesyrup" -x DES -X "maplesyrup" 127.0.0.3:16100
Complete AgentCodeV3 example:
public class TestAgent extends BaseAgent {
// initialize Log4J logging
static {
LogFactory.setLogFactory(new Log4jLogFactory());
}
protected String address;
/**
* Creates the test agent with a file to read and store the boot counter and
* a file to read and store its configuration.
*
* @param bootCounterFile
* a file containing the boot counter in serialized form (as expected by
* BaseAgent).
* @param configFile
* a configuration file with serialized management information.
* @throws IOException
* if the boot counter or config file cannot be read properly.
*/
public TestAgent(File bootCounterFile, File configFile) throws IOException {
super(bootCounterFile, configFile,
new CommandProcessor(new OctetString(MPv3.createLocalEngineID())));
}
protected void registerManagedObjects() {
try {
VariableBinding vb = new VariableBinding(new OID("1.3.6.1.4.1.73.1.8.2.1.1.1.10.1"),new OctetString("WinsXP"));
StaticMOGroup group = new StaticMOGroup(new OID("1.2.3.4.5.6.7"),new VariableBinding[]{vb});
MOScalar mo = new MOScalar(new OID("1.3.6.1.2.2.0"), MOAccessImpl.ACCESS_READ_WRITE, new OctetString("This is a test"));
server.register(mo, new OctetString("public"));
}
catch (DuplicateRegistrationException ex) {
ex.printStackTrace();
}
}
protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB) {}
protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString("TEST"),
new OctetString("v3test"),
StorageType.nonVolatile);
/*
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1,
new OctetString("cpublic"),
new OctetString("v1v2group"),
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"),
StorageType.nonVolatile);
*/
vacm.addAccess(new OctetString("v3test"),
new OctetString("public")
, SecurityModel.SECURITY_MODEL_USM,
SecurityLevel.NOAUTH_NOPRIV,
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);
vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
}
protected void addUsmUser(USM usm) {
UsmUser user = new UsmUser(new OctetString("TEST"),
AuthSHA.ID,
new OctetString("maplesyrup"),
PrivDES.ID,
new OctetString("maplesyrup"));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
}
protected void initTransportMappings() throws IOException {
transportMappings = new TransportMapping[1];
Address addr = GenericAddress.parse(address);
TransportMapping tm =
TransportMappings.getInstance().createTransportMapping(addr);
transportMappings[0] = tm;
}
public static void main(String[] args) {
String address;
if (args.length > 0) {
address = args[0];
}
else {
address = "127.0.0.3/16100";
}
BasicConfigurator.configure();
try {
TestAgent testAgent1 = new TestAgent(new File("SNMP4JTestAgentBC.cfg"),
new File("SNMP4JTestAgentConfig.cfg"));
testAgent1.address = address;
testAgent1.init();
testAgent1.loadConfig(ImportModes.REPLACE_CREATE);
testAgent1.addShutdownHook();
testAgent1.getServer().addContext(new OctetString("public"));
testAgent1.finishInit();
testAgent1.run();
testAgent1.sendColdStartNotification();
/* Try to rerun agent:
try {
Thread.sleep(30000);
}
catch (InterruptedException ex2) {
}
testAgent1.stop();
testAgent1.run();
*/
while (true) {
try {
Thread.sleep(1000);
}
catch (InterruptedException ex1) {
break;
}
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
protected void unregisterManagedObjects() {
// here we should unregister those objects previously registered...
}
protected void addCommunities(SnmpCommunityMIB communityMIB) {
Variable[] com2sec = new Variable[] {
new OctetString("public"), // community name
new OctetString("cpublic"), // security name
getAgent().getContextEngineID(), // local engine ID
new OctetString("public"), // default context name
new OctetString(), // transport tag
new Integer32(StorageType.nonVolatile), // storage type
new Integer32(RowStatus.active) // row status
};
SnmpCommunityMIB.SnmpCommunityEntryRow row =
communityMIB.getSnmpCommunityEntry().createRow(
new OctetString("public2public").toSubIndex(true), com2sec);
communityMIB.getSnmpCommunityEntry().addRow(row);
// snmpCommunityMIB.setSourceAddressFiltering(true);
}
}
I pretty much went off of the examples provided in the TestAgent exaple, but I feel like I am still missing something… I could use some help being pointed in the right direction.
For now I would just like to set up the Agent server so that I may connect to it in a similar manner to “SNMPWALK -v1 -c public < Ip:Socket > < OID >”
Eventaully I want to create a client application to connect to the agent and allows for custom user input. I have configured a simple app for SNMPV1 and V2. Will need to configure it for SNMPV3. For now I would just like to be able to establish communication using NET-SNMP tools.