public String getStringValue(SnmpValue result) { if (hex) return result.toHexString(); return result.toString(); }
/** * <p>getDot1dStpPortDesignatedPort</p> * * @return a {@link java.lang.String} object. */ public String getDot1dStpPortDesignatedPort() { return getValue(DOT1D_STP_PORT_DESIGNATED_PORT).toHexString(); }
@Override public String getStringValue() { return m_attribute.getValue().toHexString(); } }
public static String getPhysAddrFromValue(SnmpValue value) { String hexString = value.toHexString(); if (hexString.length() != 12) { return null; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 12; i += 2) { sb.append(hexString.substring(i, i + 2)); if (i < 10) { sb.append(':'); } } return sb.toString().toUpperCase(); }
public String getHexString(String key) { SnmpValue val = getValue(key); return (val == null ? null : val.toHexString()); }
public String getHexString(String key) { SnmpValue val = getValue(key); return (val == null ? null : val.toHexString()); }
public String getIsisISAdjNeighSnpaAddress() { return getValue(ISIS_IS_ADJ_NBR_SNPAADDR).toHexString(); }
public String getDot1dStpPortDesignatedRoot() { return getValue(DOT1D_STP_PORT_DESIGNATED_ROOT).toHexString(); }
public String getIsisISAdjNeighSysID() { return getValue(ISIS_IS_ADJ_NBR_SYSID).toHexString(); }
/** * <p>getDot1dStpPortDesignatedBridge</p> *BridgeId ::= TEXTUAL-CONVENTION * STATUS current * DESCRIPTION * "The Bridge-Identifier, as used in the Spanning Tree * Protocol, to uniquely identify a bridge. Its first two * octets (in network byte order) contain a priority value, * and its last 6 octets contain the MAC address used to * refer to a bridge in a unique fashion (typically, the * numerically smallest MAC address of all ports on the * bridge)." * SYNTAX OCTET STRING (SIZE (8)) * * @return a {@link java.lang.String} object. */ public String getDot1dStpPortDesignatedBridge() { return getValue(DOT1D_STP_PORT_DESIGNATED_BRIDGE).toHexString(); }
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(); }
/** * <p>getDot1dTpFdbAddress</p> * * @return a {@link java.lang.String} object. */ public String getDot1dTpFdbAddress() { if (getValue(DOT1D_TP_FDB_ADDRESS) != null) return getValue(DOT1D_TP_FDB_ADDRESS).toHexString(); return null; }
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 getDisplayableCdpCacheAddress() { SnmpValue cdpCacheAddressValue = getValue(CDP_CACHE_ADDRESS); try { if (cdpCacheAddressValue.isDisplayable()) return cdpCacheAddressValue.toDisplayString(); } catch (Exception e) { return cdpCacheAddressValue.toHexString(); } return "not able to diplay"; }
@Override public boolean isServiceDetected(InetAddress address, SnmpAgentConfig agentConfig) { try { configureAgentPTR(agentConfig); configureAgentVersion(agentConfig); final String expectedValue = getVbvalue(); if (this.m_isTable) { LOG.debug(getServiceName() + ": table detect enabled"); final SnmpObjId snmpObjId = SnmpObjId.get(getOid()); final Map<SnmpInstId, SnmpValue> table = SnmpUtils.getOidValues(agentConfig, DEFAULT_SERVICE_NAME, snmpObjId); final List<String> retrievedValues = table.values().stream().map(snmpValue -> m_hex ? snmpValue.toHexString() : snmpValue.toString()).collect(Collectors.toList()); return isServiceDetected(this.matchType, retrievedValues, expectedValue); } else { final String retrievedValue = getValue(agentConfig, getOid(), m_hex); // we have to ensure that if expectedValue is defined, we use ANY, this is due to backwards compatibility MatchType matchType = this.matchType; if (matchType == null && expectedValue != null) { matchType = MatchType.Any; } return isServiceDetected(matchType, Lists.newArrayList(retrievedValue), expectedValue); } } catch (Throwable t) { throw new UndeclaredThrowableException(t); } }
/** * <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(); } }
/** * <p>getCdpCacheDeviceId</p> * * @return a {@link java.lang.String} object. */ public String getCdpCacheDeviceId() { if (getValue(CDP_CACHE_DEVICE_ID).isDisplayable()) return getValue(CDP_CACHE_DEVICE_ID).toDisplayString(); return getValue(CDP_CACHE_DEVICE_ID).toHexString(); }
/** * <p>getCdpCacheDevicePort</p> * * @return a {@link java.lang.String} object. */ public String getCdpCacheDevicePort() { if (getValue(CDP_CACHE_DEVICE_PORT).isDisplayable()) return getValue(CDP_CACHE_DEVICE_PORT).toDisplayString(); return getValue(CDP_CACHE_DEVICE_PORT).toHexString(); }
private void addGroupToBuilder(CollectionSetBuilder builder, Resource resource, AttributeGroup group) { for (CollectionAttribute attribute : group.getAttributes()) { String value; if(!attribute.shouldPersist(params)){ continue; } else if (attribute.getAttributeType() instanceof HexStringAttributeType) { value = ((SnmpAttribute) attribute).getValue().toHexString(); } else { value = attribute.getStringValue(); } builder.withAttribute(resource, group.getName(), attribute.getName(), value, attribute.getType()); } } }