use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class MockSnmpAgent method addCommunities.
/**
* {@inheritDoc}
*/
@Override
protected void addCommunities(SnmpCommunityMIB communityMIB) {
Variable[] com2sec = new Variable[] { // community name
new OctetString("public"), // security name
new OctetString("public"), // local engine ID
getAgent().getContextEngineID(), // default context name
new OctetString(), // transport tag
new OctetString(), // storage type
new Integer32(StorageType.nonVolatile), // row status
new Integer32(RowStatus.active) };
SnmpCommunityEntryRow row = communityMIB.getSnmpCommunityEntry().createRow(new OctetString("public2public").toSubIndex(true), com2sec);
communityMIB.getSnmpCommunityEntry().addRow(row);
}
use of org.snmp4j.smi.Integer32 in project camel by apache.
the class SnmpProducer method doStop.
@Override
protected void doStop() throws Exception {
super.doStop();
try {
SecurityModels.getInstance().removeSecurityModel(new Integer32(this.usm.getID()));
} finally {
this.targetAddress = null;
this.usm = null;
this.target = null;
this.pdu = null;
}
}
use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class PropertiesBackedManagedObject method getVariableFromValueString.
/**
* <p>getVariableFromValueString</p>
*
* @param oidStr a {@link java.lang.String} object.
* @param valStr a {@link java.lang.String} object.
* @return a {@link org.snmp4j.smi.Variable} object.
* @throws SnmpErrorStatusException
*/
private Variable getVariableFromValueString(String oidStr, String valStr) throws SnmpErrorStatusException {
Variable newVar;
if (valStr.startsWith("Wrong Type")) {
String newVal = valStr.replaceFirst("Wrong Type \\(should be .*\\): ", "");
s_log.error("Bad Mib walk has value: '" + valStr + "' using '" + newVal + "'");
valStr = newVal;
}
if ("\"\"".equals(valStr)) {
newVar = new Null();
} else {
String moTypeStr = valStr.substring(0, valStr.indexOf(':'));
String moValStr = valStr.substring(valStr.indexOf(':') + 2);
try {
if (moTypeStr.equals("STRING")) {
if (moValStr.startsWith("\"") && moValStr.endsWith("\"")) {
moValStr = moValStr.substring(1, moValStr.length() - 1);
}
newVar = new OctetString(moValStr);
} else if (moTypeStr.equals("Hex-STRING")) {
newVar = OctetString.fromHexString(moValStr.trim().replace(' ', ':'));
} else if (moTypeStr.equals("INTEGER")) {
newVar = new Integer32(Integer.parseInt(moValStr));
} else if (moTypeStr.equals("Gauge32")) {
newVar = new Gauge32(Long.parseLong(moValStr));
} else if (moTypeStr.equals("Counter32")) {
// a 32 bit counter can be > 2 ^ 31, which is > INTEGER_MAX
newVar = new Counter32(Long.parseLong(moValStr));
} else if (moTypeStr.equals("Counter64")) {
newVar = new Counter64(Long.parseLong(moValStr));
} else if (moTypeStr.equals("Timeticks")) {
Integer ticksInt = Integer.parseInt(moValStr.substring(moValStr.indexOf('(') + 1, moValStr.indexOf(')')));
newVar = new TimeTicks(ticksInt);
} else if (moTypeStr.equals("OID")) {
newVar = new OID(moValStr);
} else if (moTypeStr.equals("IpAddress")) {
newVar = new IpAddress(moValStr.trim());
} else if (moTypeStr.equals("Network Address")) {
newVar = OctetString.fromHexString(moValStr.trim());
} else if (moTypeStr.equals("Responder")) {
newVar = handleDynamicVariable(oidStr, moValStr);
} else {
// newVar = new OctetString(moValStr);
throw new IllegalArgumentException("Unrecognized SNMP Type " + moTypeStr);
}
} catch (SnmpErrorStatusException e) {
throw e;
} catch (Throwable t) {
throw new UndeclaredThrowableException(t, "Could not convert value '" + moValStr + "' of type '" + moTypeStr + "' to SNMP object for OID " + oidStr);
}
}
return newVar;
}
use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class Snmp4JDummyTransportTest method makePdu.
private static final PDU makePdu() {
PDU snmp4JV2cTrapPdu = new PDUv1();
OID oid = new OID(".1.3.6.1.2.1.1.3.0");
snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(oid)));
snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress("127.0.0.1")));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID(oid), new OctetString("Trap Msg v2-1")));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID(oid), new OctetString("Trap Msg v2-2")));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new OctetString("Trap v1 msg-1")));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3"), new OctetString("Trap v1 msg-2")));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.6.3.1.1.4.1.1"), new OctetString("Trap v1 msg-3")));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.4.1.733.6.3.18.1.5.0"), new Integer32(1)));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new Null()));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.1"), new Null(128)));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.2"), new Null(129)));
snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.3"), new Null(130)));
snmp4JV2cTrapPdu.setType(PDU.V1TRAP);
return snmp4JV2cTrapPdu;
}
use of org.snmp4j.smi.Integer32 in project opennms by OpenNMS.
the class MockAgentTest method setUp.
@Override
protected void setUp() throws Exception {
MockUtil.println("------------ Begin Test " + getName() + " --------------------------");
MockLogAppender.setupLogging();
m_network = new MockNetwork();
m_network.setCriticalService("ICMP");
m_network.addNode(1, "Router");
m_network.addInterface("192.168.1.1");
m_network.addService("ICMP");
m_network.addService("SMTP");
m_network.addInterface("192.168.1.2");
m_network.addService("ICMP");
m_network.addService("SMTP");
m_network.addNode(2, "Server");
m_network.addInterface("192.168.1.3");
m_network.addService("ICMP");
m_network.addService("HTTP");
m_network.addInterface("192.168.1.2");
MapSubAgent systemGroup = new MapSubAgent("1.3.6.1.2.1.1");
systemGroup.put("1.0", new OctetString("MockAgent!"));
systemGroup.put("2.0", new OID("1.3.6.1.4.1.5813.1"));
systemGroup.put("3.0", new TimeTicks(1234));
systemGroup.put("4.0", new OctetString("Mr. Personality"));
systemGroup.put("5.0", new OctetString("mockhost"));
systemGroup.put("6.0", new OctetString("Wouldn't you like to know"));
// what happened to 7.0?
MapSubAgent interfaces = new MapSubAgent("1.3.6.1.2.1.2");
interfaces.put("1.0", new Integer32(2));
try {
m_proxy = new MockProxy(9161);
} catch (Throwable t) {
throw new Exception("Could not start MockProxy on 9161: " + t, t);
}
MockAgent agent = new MockAgent();
agent.addSubAgent(systemGroup);
agent.addSubAgent(interfaces);
m_proxy.addAgent(agent);
}
Aggregations