@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { try { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getGauge32(Long.parseLong(value))); } catch (NumberFormatException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpGauge32"); } catch (IllegalArgumentException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpGauge32"); } catch (NullPointerException e) { throw new SnmpTrapException("Value is null for SnmpGauge32"); } } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpGauge32"); } } }
trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getGauge32(Long.parseLong(value)));
private static void addAttributeToCollectionResource(SnmpCollectionResource resource, ResourceType type, String attributeName, String attributeType, String attributeInstance, long value) { MibObject object = createMibObject(attributeType, attributeName, attributeInstance); SnmpAttributeType objectType = new NumericAttributeType(type, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); SnmpValue snmpValue = attributeType.equals("counter") ? SnmpUtils.getValueFactory().getCounter32(value) : SnmpUtils.getValueFactory().getGauge32(value); resource.setAttributeValue(objectType, snmpValue); }
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(20)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(60)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(45)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getGauge32(55)); resource.visit(visitor);
private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, String value) { MibObject object = createMibObject(attributeType, attributeName, attributeInstance); SnmpAttributeType objectType = null; SnmpValue snmpValue = null; if (AttributeType.STRING.equals(attributeType)) { objectType = new SnmpAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)) { @Override public AttributeType getType() { return AttributeType.STRING; } @Override public void storeAttribute(CollectionAttribute attribute, Persister persister) { persister.persistStringAttribute(attribute); } }; snmpValue = SnmpUtils.getValueFactory().getOctetString(value.getBytes()); } else { objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); long v = Long.parseLong(value); snmpValue = AttributeType.COUNTER.equals(attributeType) ? SnmpUtils.getValueFactory().getCounter32(v) : SnmpUtils.getValueFactory().getGauge32(v); } resource.setAttributeValue(objectType, snmpValue); return new SnmpAttribute(resource, objectType, snmpValue); }