public JaxbSnmpValue(SnmpValue value) { type = value.getType(); bytes = value.getBytes(); }
private String toLogString(final SnmpValue val) { if (val.getType() == SnmpValue.SNMP_OCTET_STRING) { return val.toDisplayString() + " (" + val.toHexString() + ")"; } return val.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SnmpResult other = (SnmpResult) obj; // Compare the type and byte contents to determine if two values are equal // Do not rely on the equals() method for this attribute if (m_value == null) { if (other.m_value != null) return false; } else if (m_value.getType() != other.m_value.getType() || !Arrays.equals(m_value.getBytes(), other.m_value.getBytes())) { return false; } return Objects.equals(this.m_base, other.m_base) && Objects.equals(this.m_instance, other.m_instance); } }
@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()); }
} 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);
/** {@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); } } } }
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; }
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; }
if (m_syntaxToEvents[i].getTypeId() == -1 || m_syntaxToEvents[i].getTypeId() == value.getType()) { val.setType(m_syntaxToEvents[i].getType()); String encoding = null;
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 Exception("This is a bogus exception so we can get a stack backtrace"); log().error("PDU to prepare has object values but not the same number as there are OIDs. There are " + oids.length + " OIDs and " + values.length + " object values.", 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 Exception("This is a bogus exception so we can get a stack backtrace"); log().error("Prepared PDU does not have as many variable bindings as there are OIDs. There are " + oids.length + " OIDs and " + pdu.getVariableBindings() + " variable bindings.", e); return null; } return pdu; }
syntaxvalues[i] = new JoeSnmpValue(values[i].getType(), values[i].getBytes()).getSnmpSyntax();
syntaxvalues[i] = new JoeSnmpValue(values[i].getType(), values[i].getBytes()).getSnmpSyntax();
syntaxvalues[i] = new JoeSnmpValue(values[i].getType(), values[i].getBytes()).getSnmpSyntax();