use of org.opennms.mock.snmp.responder.SnmpErrorStatusException in project opennms by OpenNMS.
the class PropertiesBackedManagedObject method getVariable.
private void getVariable(final SubRequest request, final OID oid) {
try {
final Variable value = findValueForOID(oid);
final VariableBinding vb = request.getVariableBinding();
vb.setOid(oid);
vb.setVariable(value == null ? Null.noSuchObject : value);
request.completed();
} catch (SnmpErrorStatusException e) {
request.setErrorStatus(e.getErrorStatus());
request.completed();
}
}
use of org.opennms.mock.snmp.responder.SnmpErrorStatusException 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;
}
Aggregations