@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().getCounter32(Long.parseLong(value))); } catch (NumberFormatException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpCounter32"); } catch (IllegalArgumentException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpCounter32"); } catch (NullPointerException e) { throw new SnmpTrapException("Value is null for SnmpCounter32"); } } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpCounter32"); } } }
trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getCounter32(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); }
SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.2.2.1.10.6"), SnmpUtils.getValueFactory().getCounter32(7654321));
SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.2.2.1.10.6"), SnmpUtils.getValueFactory().getCounter32(7654321)); SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.2.2.1.10.6"), SnmpUtils.getValueFactory().getCounter32(1234567));
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(1000)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100)); resource.visit(visitor);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(1000)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100)); resource.visit(visitor);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(2000)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(20000)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(53000)); resource.visit(visitor); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(65000)); 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); }