Search in sources :

Example 6 with AttributeType

use of org.opennms.netmgt.collection.api.AttributeType in project opennms by OpenNMS.

the class CollectionResourceWrapperIT method addAttributeToCollectionResource.

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);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) AttributeType(org.opennms.netmgt.collection.api.AttributeType) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Persister(org.opennms.netmgt.collection.api.Persister) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType)

Aggregations

AttributeType (org.opennms.netmgt.collection.api.AttributeType)6 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)5 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)4 Resource (org.opennms.netmgt.collection.support.builder.Resource)4 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)3 MalformedURLException (java.net.MalformedURLException)2 RemoteException (java.rmi.RemoteException)2 HashMap (java.util.HashMap)2 VmwareServer (org.opennms.netmgt.config.vmware.VmwareServer)2 VmwareViJavaAccess (org.opennms.protocols.vmware.VmwareViJavaAccess)2 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)1 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)1 HostSystem (com.vmware.vim25.mo.HostSystem)1 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1