public TrapIdentity(SnmpObjId entId, int generic, int specific) { m_enterpriseId = entId.toString(); m_generic = generic; m_specific = specific; }
public TrapIdentity(SnmpObjId entId, int generic, int specific) { m_enterpriseId = entId.toString(); m_generic = generic; m_specific = specific; }
@Override public String marshal(SnmpObjId v) throws Exception { return v.toString(); }
public OidSnmpValue(SnmpObjId objId) { this(objId.toString()); }
@Override public String marshal(SnmpObjId snmpObjId) throws Exception { final String oidStr = snmpObjId.toString(); if (oidStr.length() > 0 && oidStr.charAt(0) != '.') { // Always prepend a '.' to the string representation // These won't get added automatically if the SnmpObjId is actually a SnmpInstId return "." + oidStr; } return oidStr; }
/** * Gets the MIB object by OID. * * @param oid the OID * @return the MIB object by OID */ public MibObj getMibObjectByOid(final String oid) { return m_mibObjects.stream().filter(obj -> { return oid.equals(obj.getOid().toString()); }).findFirst().orElse(null); }
/** * Convert the OpenNMS Generic SnmpObjId[] array to a JoeSnmp SnmpObjectId[] * * @param oids * @return * An array of JoeSnmp SnmpObjectIds */ private SnmpObjectId[] convertOids(SnmpObjId[] oids) { SnmpObjectId[] jOids = new SnmpObjectId[oids.length]; for (int i=0; i<oids.length; i++) { jOids[i] = new SnmpObjectId(oids[i].toString()); } return jOids; }
/** * Convert the OpenNMS Generic SnmpObjId[] array to a JoeSnmp SnmpObjectId[] * * @param oids * @return * An array of JoeSnmp SnmpObjectIds */ private SnmpObjectId[] convertOids(SnmpObjId[] oids) { SnmpObjectId[] jOids = new SnmpObjectId[oids.length]; for (int i=0; i<oids.length; i++) { jOids[i] = new SnmpObjectId(oids[i].toString()); } return jOids; }
/** * Convert the OpenNMS Generic SnmpObjId[] array to a JoeSnmp SnmpObjectId[] * * @param oids * @return * An array of JoeSnmp SnmpObjectIds */ private SnmpObjectId[] convertOids(SnmpObjId[] oids) { SnmpObjectId[] jOids = new SnmpObjectId[oids.length]; for (int i=0; i<oids.length; i++) { jOids[i] = new SnmpObjectId(oids[i].toString()); } return jOids; }
/** * <p>notifyIfNotFound</p> * * @param attrType a {@link org.opennms.netmgt.collection.api.CollectionAttributeType} object. * @param res a {@link org.opennms.netmgt.snmp.SnmpResult} object. */ public void notifyIfNotFound(CollectionAttributeType attrType, SnmpResult res) { // If we're collecting from ifTable or ifXTable, be less noisy and explain // the likeliest reason for the absence of the target instance String baseOID = res.getBase().toString(); if (baseOID.startsWith(".1.3.6.1.2.1.2.2.1") || baseOID.startsWith(".1.3.6.1.2.1.31.1.1.1")) { LOG.debug("Unable to locate interface with ifIndex {} for agent {} while collecting attribute {}. Perhaps a DO_NOT_PERSIST policy excluded this interface?", getCollectionAgent(), res.getInstance(), attrType); } else { LOG.info("Unable to locate resource for agent {} with instance id {} while collecting attribute {}", getCollectionAgent(), res.getInstance(), attrType); } }
public String toDisplayString() { switch (m_value.getSyntax()) { case SMIConstants.SYNTAX_OBJECT_IDENTIFIER : return SnmpObjId.get(((OID)m_value).getValue()).toString(); case SMIConstants.SYNTAX_TIMETICKS : return Long.toString(toLong()); case SMIConstants.SYNTAX_OCTET_STRING : return toStringDottingCntrlChars(((OctetString)m_value).getValue()); default : return m_value.toString(); } }
public byte[] getBytes() { switch (m_value.getSyntax()) { case SMIConstants.SYNTAX_INTEGER: case SMIConstants.SYNTAX_COUNTER32: case SMIConstants.SYNTAX_COUNTER64: case SMIConstants.SYNTAX_TIMETICKS: case SMIConstants.SYNTAX_UNSIGNED_INTEGER32: return toBigInteger().toByteArray(); case SMIConstants.SYNTAX_IPADDRESS: return toInetAddress().getAddress(); case SMIConstants.SYNTAX_OBJECT_IDENTIFIER: return toSnmpObjId().toString().getBytes(); case SMIConstants.SYNTAX_OCTET_STRING: return ((OctetString)m_value).getValue(); case SMIConstants.SYNTAX_OPAQUE: return((Opaque)m_value).getValue(); case SMIConstants.SYNTAX_NULL: return new byte[0]; default: throw new IllegalArgumentException("cannot convert "+m_value+" to a byte array"); } }
@Override public byte[] getBytes() { switch (m_value.getSyntax()) { case SMIConstants.SYNTAX_INTEGER: case SMIConstants.SYNTAX_COUNTER32: case SMIConstants.SYNTAX_COUNTER64: case SMIConstants.SYNTAX_TIMETICKS: case SMIConstants.SYNTAX_UNSIGNED_INTEGER32: return toBigInteger().toByteArray(); case SMIConstants.SYNTAX_IPADDRESS: return toInetAddress().getAddress(); case SMIConstants.SYNTAX_OBJECT_IDENTIFIER: return toSnmpObjId().toString().getBytes(); case SMIConstants.SYNTAX_OCTET_STRING: return ((OctetString)m_value).getValue(); case SMIConstants.SYNTAX_OPAQUE: return((Opaque)m_value).getValue(); case SMIConstants.EXCEPTION_END_OF_MIB_VIEW: case SMIConstants.EXCEPTION_NO_SUCH_INSTANCE: case SMIConstants.EXCEPTION_NO_SUCH_OBJECT: case SMIConstants.SYNTAX_NULL: return new byte[0]; default: throw new IllegalArgumentException("cannot convert "+m_value+" to a byte array"); } }
/** {@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); }
/** * Initialize vendor attributes. */ private void initializeVendorAttributes() { m_vendorAttributes.clear(); for (HwEntityAttributeType type : m_hwEntityAttributeTypeDao.findAll()) { LOG.debug("Loading attribute type {}", type); m_vendorAttributes.put(type.getSnmpObjId(), type); } for (HwExtension ext : m_hwInventoryAdapterConfigDao.getConfiguration().getExtensions()) { for (MibObj obj : ext.getMibObjects()) { HwEntityAttributeType type = m_vendorAttributes.get(obj.getOid()); if (type == null) { type = new HwEntityAttributeType(obj.getOid().toString(), obj.getAlias(), obj.getType()); LOG.info("Creating attribute type {}", type); m_hwEntityAttributeTypeDao.save(type); m_vendorAttributes.put(type.getSnmpObjId(), type); } } } }
@Override public String toDisplayString() { switch (m_value.getSyntax()) { case SMIConstants.SYNTAX_OBJECT_IDENTIFIER : return SnmpObjId.get(((OID)m_value).getValue()).toString(); case SMIConstants.SYNTAX_TIMETICKS : return Long.toString(toLong()); case SMIConstants.SYNTAX_OCTET_STRING : return toStringDottingCntrlChars(((OctetString)m_value).getValue()); case SMIConstants.SYNTAX_NULL: return ""; default : return m_value.toString(); } }
@Override public String toDisplayString() { switch (m_value.getSyntax()) { case SMIConstants.SYNTAX_OBJECT_IDENTIFIER : return SnmpObjId.get(((OID)m_value).getValue()).toString(); case SMIConstants.SYNTAX_TIMETICKS : return Long.toString(toLong()); case SMIConstants.SYNTAX_OCTET_STRING : return toStringDottingCntrlChars(((OctetString)m_value).getValue()); case SMIConstants.SYNTAX_NULL: return ""; default : return m_value.toString(); } }
/** {@inheritDoc} */ @Override public void storeResult(SnmpResult res) { String key = res.getAbsoluteInstance().toString(); putValue(key, res.getValue()); List<SnmpAttributeType> attrTypes = findAttributeTypeForOid(res.getBase(), res.getInstance()); if (attrTypes.isEmpty()) { throw new IllegalArgumentException("Received result for unexpected oid ["+res.getBase()+"].["+res.getInstance()+"]"); } for (SnmpAttributeType attrType : attrTypes) { if (attrType.getInstance().equals(MibObject.INSTANCE_IFINDEX)) { putIfIndex(res.getInstance().toInt()); } attrType.storeResult(m_collectionSet, this, res); LOG.debug("storeResult: added value for {}: {}", attrType.getAlias(), res.toString()); } }
protected PDU buildPdu(Snmp4JAgentConfig agentConfig, int pduType, SnmpObjId[] oids, SnmpValue[] values) { PDU pdu = agentConfig.createPdu(pduType); if (values == null) { for (SnmpObjId oid : oids) { pdu.add(new VariableBinding(new OID(oid.toString()))); } } else { // TODO should this throw an exception? This situation is fairly bogus and probably signifies a coding error. if (oids.length != values.length) { Exception e = new SnmpException("PDU values do not match OIDs"); LOG.error("PDU to prepare has object values but not the same number as there are OIDs. There are {} OIDs and {} object values.", oids.length, values.length, e); return null; } for (int i = 0; i < oids.length; i++) { pdu.add(new VariableBinding(new OID(oids[i].toString()), new Snmp4JValue(values[i].getType(), values[i].getBytes()).getVariable())); } } // TODO should this throw an exception? This situation is fairly bogus. if (pdu.getVariableBindings().size() != oids.length) { Exception e = new SnmpException("PDU bindings do not match OIDs"); LOG.error("Prepared PDU does not have as many variable bindings as there are OIDs. There are {} OIDs and {} variable bindings.", oids.length,pdu.getVariableBindings(), e); return null; } return pdu; }
/** {@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); } } } }