/** * <p>getDot1dStpPortEnable</p> * * @return a int. */ public Integer getDot1dStpPortEnable() { return getValue(DOT1D_STP_PORT_ENABLE).toInt(); }
public static String getDisplayable(final SnmpValue snmpValue) { String decodedsnmpValue = snmpValue.toHexString(); try { if (snmpValue.isDisplayable()) decodedsnmpValue = snmpValue.toDisplayString(); } catch (Exception e) { LOG.debug("getDisplayable: got not displayable Value {}", e.getMessage()); } return decodedsnmpValue; }
private String toLogString(final SnmpValue val) { if (val.getType() == SnmpValue.SNMP_OCTET_STRING) { return val.toDisplayString() + " (" + val.toHexString() + ")"; } return val.toString(); }
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; }
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 getIfDescr() { final SnmpValue value = getValue(IF_DESCR); return value == null ? null : value.toDisplayString(); }
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.LLDP_PORTID_SUBTYPE_INTERFACEALIAS); } else { 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 lldplink.setLldpPortDescr(""); if (val.get(0).isNumeric() && val.get(0).toInt() == LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL.getValue().intValue()) { try { lldplink.setLldpPortIfindex((val.get(1).toInt())); } catch (Exception e) { LOG.warn("get: [{}], failed to convert to ifindex local port id {}",
public String getStringValue(SnmpValue result) { if (hex) return result.toHexString(); return result.toString(); }
/** * <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(); } }
LOG.debug("No data collected for attribute {}. Skipping", this); return null; } else if (getValue().isNumeric()) { return getValue().toLong(); } else { } catch(NumberFormatException e) { LOG.trace("Unable to process data received for attribute {} maybe this is not a number? See bug 1473 for more information. Skipping.", this); if (getValue().getType() == SnmpValue.SNMP_OCTET_STRING) { try { return Long.valueOf(getValue().toHexString(), 16); } catch(NumberFormatException ex) { LOG.trace("Unable to process data received for attribute {} maybe this is not a number? See bug 1473 for more information. Skipping.", this);
/** * {@inheritDoc} * * Returns true if the protocol defined by this plugin is supported. If * the protocol is not supported then a false value is returned to the * caller. The qualifier map passed to the method is used by the plugin to * return additional information by key-name. These key-value pairs can be * added to service events if needed. */ @Override public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) { try { configureAgentPTR(agentConfig); configureAgentVersion(agentConfig); SnmpObjId virtualDiskRollUpStatusSnmpObject = SnmpObjId.get(virtualDiskRollUpStatus + '.' + m_virtualDiskNumber); SnmpValue virtualDiskRollUpStatus = SnmpUtils.get(agentConfig, virtualDiskRollUpStatusSnmpObject); if (virtualDiskRollUpStatus == null || virtualDiskRollUpStatus.isNull()) { LOG.debug("SNMP poll failed: no results, addr={} oid={}", agentConfig.getAddress(), virtualDiskRollUpStatusSnmpObject); return false; } if (virtualDiskRollUpStatus.toInt() != 3) { // 3 means Online LOG.debug("OMSAStorageMonitor.poll: Bad Disk Found. Log vol({}) degraded", m_virtualDiskNumber); return false; } } catch (Throwable t) { throw new UndeclaredThrowableException(t); } return true; }
@Override protected void storeResult(SnmpResult result) { LOG.trace("Collected SnmpValue '{}'", result); SnmpValue value = result.getValue(); String metricType = value == null ? "unknown" : typeToString(value.getType()); collectionJob.setMetricValue(metricObjId, metricType, value == null ? null : value.toDisplayString()); }
if (m_syntaxToEvents[i].getTypeId() == -1 || m_syntaxToEvents[i].getTypeId() == value.getType()) { val.setType(m_syntaxToEvents[i].getType()); String encoding = null; boolean displayable = false; try { displayable = value.isDisplayable(); } catch (ArrayIndexOutOfBoundsException aioobe) { if (value.getBytes().length == 6) { encoding = EventConstants.XML_ENCODING_MAC_ADDRESS; } else {
/** * <p>getIpNetToMediaNetAddress</p> * * @return a {@link java.net.InetAddress} object. */ public InetAddress getIpNetToMediaNetAddress(){ SnmpValue value = getValue(IPNETTOMEDIA_TABLE_NETADDR); if (value == null) { return null; } return value.toInetAddress(); }
/** {@inheritDoc} */ @Override protected void storeResult(SnmpResult res) { if(res.getBase().toString().equals(AbstractSnmpCollector.IFALIAS_OID) && (res.getValue().isNull() || res.getValue().toDisplayString() == null || res.getValue().toDisplayString().equals(""))) { LOG.debug("Skipping storeResult. Null or zero length ifAlias"); return; } SNMPCollectorEntry entry = m_results.get(res.getInstance()); if (entry == null) { LOG.debug("Creating new SNMPCollectorEntry entry"); entry = new SNMPCollectorEntry(m_objList, m_collectionSet); m_results.put(res.getInstance(), entry); } entry.storeResult(res); }
/** {@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); } } } }
long getLongValue() { return (value == null ? -1L : value.toLong()); }
public static Long getProtoCounter63Value(SnmpValue value) { Long retval = getProtoCounter63Value(value.getBytes()); if (retval != null && value.isDisplayable()) { LOG.info("Value '{}' is entirely displayable but still meets our other checks to be treated as a proto-Counter64. This may not be what you want.", new String(value.getBytes())); } return retval; }
/** * <p>getCdpCacheAddress</p> * * @return a {@link java.lang.String} object. */ public byte[] getCdpCacheAddress() { return getValue(CDP_CACHE_ADDRESS).getBytes(); }