public SnmpValue get(SnmpObjId entryoid,Integer index) { SnmpObjId instance = SnmpObjId.get(new int[] {index}); List<SnmpObjId> oids = new ArrayList<SnmpObjId>(1); oids.add(SnmpObjId.get(entryoid, instance)); List<SnmpValue> val= get(oids); if (val == null || val.size() != 1 || val.get(0) == null || val.get(0).isError()) return null; return val.get(0); }
private String getPhysAddr() { final SnmpValue value = getValue(IF_PHYS_ADDR); if (value == null || value.isError()) { return null; } String hexString = value == null ? null : value.toHexString(); String displayString = value == null ? null : value.toDisplayString(); // See ifTableEntry: NMS-4902 (revision cee964fe979e6465aeb4e2efd4772e50ebc54831) try { if (hexString != null && hexString.length() == 12) { // If the hex string is 12 characters long, than the agent is kinda weird and // is returning the value as a raw binary value that is 6 bytes in length. // But that's OK, as long as we can convert it into a string, that's fine. return hexString; } else { // This is the normal case that most agents conform to: the value is an ASCII // string representing the colon-separated MAC address. We just need to reformat // it to remove the colons and convert it into a 12-character string. return displayString == null || displayString.trim().isEmpty() ? null : InetAddressUtils.normalizeMacAddress(displayString); } } catch (IllegalArgumentException e) { LOG.warn(e.getMessage(), e); return displayString; } }
private String getPhysAddr() { final SnmpValue value = getValue(IF_PHYS_ADDR); if (value == null || value.isError()) { return null; } String hexString = value == null ? null : value.toHexString(); String displayString = value == null ? null : value.toDisplayString(); // See ifTableEntry: NMS-4902 (revision cee964fe979e6465aeb4e2efd4772e50ebc54831) try { if (hexString != null && hexString.length() == 12) { // If the hex string is 12 characters long, than the agent is kinda weird and // is returning the value as a raw binary value that is 6 bytes in length. // But that's OK, as long as we can convert it into a string, that's fine. return hexString; } else { // This is the normal case that most agents conform to: the value is an ASCII // string representing the colon-separated MAC address. We just need to reformat // it to remove the colons and convert it into a 12-character string. return displayString == null || displayString.trim().isEmpty() ? null : InetAddressUtils.normalizeMacAddress(displayString); } } catch (IllegalArgumentException e) { LOG.warn(e.getMessage(), e); return displayString; } }
public OspfLink get(OspfLink link) { //use point to point by default link.setOspfIpMask(InetAddressUtils.addr("255.255.255.252")); List<SnmpValue> val = get(link.getOspfIpAddr()); if (val != null && val.size() == 2 ) { if (!val.get(0).isNull() && val.get(0).isNumeric() ) link.setOspfIfIndex(val.get(0).toInt()); if (!val.get(1).isNull() && !val.get(1).isError()) { try { link.setOspfIpMask(val.get(1).toInetAddress()); } catch (IllegalArgumentException e) { } } } return link; }
for (int i = 0; i < values.size(); i++) { if (values.get(i) == null || values.get(i).isError()) {
/** * <p>getValue</p> * * @param agentConfig a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object. * @param oid a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ protected static String getValue(SnmpAgentConfig agentConfig, String oid, boolean hex) { SnmpValue val = SnmpUtils.get(agentConfig, SnmpObjId.get(oid)); if (val == null || val.isNull() || val.isEndOfMib() || val.isError()) { return null; } else { return hex ? val.toHexString() : val.toString(); } }
for (int i = 0; i < values.size(); i++) { if (values.get(i) == null || values.get(i).isError()) {
public OspfElement get(OspfElement element) { //loopback mask by default element.setOspfRouterIdNetmask(InetAddressUtils.addr("255.255.255.255")); //-1 ifindex by default element.setOspfRouterIdIfindex(-1); List<SnmpValue> val = get(element.getOspfRouterId()); if (val != null && val.size() == 2) { if (!val.get(0).isNull() && val.get(0).isNumeric()) element.setOspfRouterIdIfindex(val.get(0).toInt()); if (!val.get(1).isNull() && !val.get(1).isError()) { try { element.setOspfRouterIdNetmask(val.get(1).toInetAddress()); } catch (IllegalArgumentException e) { } } } return element; }
if (val.get(0) == null || val.get(0).isError() || !val.get(0).isNumeric()) { LOG.debug("get: [{}], port id subtype is null or invalid for lldp local port number {}", getNodeId(), lldplink.setLldpPortIdSubType(LldpPortIdSubType.get(val.get(0).toInt())); if (val.get(1) == null || val.get(1).isError()) { LOG.debug("get: [{}], port id is null for lldp local port number {}", getNodeId(), val.get(1))); if (val.get(2) != null && !val.get(2).isError()) lldplink.setLldpPortDescr((val.get(2).toDisplayString())); else
/** {@inheritDoc} */ @Override public void storeResult(final SnmpResult res) { final SnmpObjId base = res.getBase(); final SnmpValue value = res.getValue(); putValue(base.toString(), value); for (final NamedSnmpVar var : ms_elemList) { if (base.equals(var.getSnmpObjId())) { if (value.isError()) { LOG.error("storeResult: got an error for alias {} [{}].[{}], but we should only be getting non-errors: {}", var.getAlias(), base, res.getInstance(), value); } else if (value.isEndOfMib()) { LOG.debug("storeResult: got endOfMib for alias {} [{}].[{}], not storing", var.getAlias(), base, res.getInstance()); } else { final SnmpValueType type = SnmpValueType.valueOf(value.getType()); LOG.debug("Storing Result: alias: {} [{}].[{}] = {}: {}", var.getAlias(), base, res.getInstance(), (type == null ? "Unknown" : type.getDisplayString()), toLogString(value)); putValue(var.getAlias(), value); } } } }