use of org.opennms.netmgt.collection.api.AttributeGroupType in project opennms by OpenNMS.
the class CiscoQoSPropertyExtender method getTargetAttribute.
/* (non-Javadoc)
* @see org.opennms.netmgt.collectd.SnmpPropertyExtender#getTargetAttribute(java.util.List, org.opennms.netmgt.collectd.SnmpCollectionResource, org.opennms.netmgt.config.datacollection.MibObjProperty)
*/
@Override
public SnmpAttribute getTargetAttribute(List<CollectionAttribute> sourceAttributes, SnmpCollectionResource targetResource, MibObjProperty property) {
final String targetProperty = property.getParameterValue(PARAM_TARGET_PROPERTY);
if (targetProperty == null) {
LOG.error("CiscoQoS getTargetAttribute: parameter {} is required. Expected values: policyName, classMapName, interfaceAlias, interfaceName", PARAM_TARGET_PROPERTY);
return null;
}
AttributeGroupType groupType = targetResource.getGroupType(property.getGroupName());
if (groupType == null) {
LOG.error("CiscoQoS getTargetAttribute: can't find the attribute type name associated with the property {}", property);
return null;
}
String oidIndex = targetResource.getInstance();
String[] indexes = oidIndex.split("\\.");
if (indexes.length < 2) {
LOG.warn("CiscoQoS getTargetAttribute: Malformed Cisco QoS Object Index {} for {}", oidIndex, targetResource);
return null;
}
final Map<String, String> parentIndices = getAttributeMap(sourceAttributes, property.getParameterValue(TYPE_QOS_PARENT_INDEX, TYPE_QOS_PARENT_INDEX), property.getParameterValue(OBJ_QOS_PARENT_INDEX, OBJ_QOS_PARENT_INDEX));
if (parentIndices.isEmpty()) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find parent indexes {} for type {}", OBJ_QOS_CONF_INDEX, TYPE_QOS_PARENT_INDEX);
return null;
}
final Map<String, String> configTypes = getAttributeMap(sourceAttributes, property.getParameterValue(TYPE_QOS_CONF_TYPE, TYPE_QOS_CONF_TYPE), property.getParameterValue(OBJ_QOS_CONF_TYPE, OBJ_QOS_CONF_TYPE));
if (configTypes.isEmpty()) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find config types {} for type {}", OBJ_QOS_CONF_TYPE, TYPE_QOS_CONF_TYPE);
return null;
}
String policyIndex = indexes[0];
String objectsIndex = indexes[1];
String parentIndex = objectsIndex;
String searchIndex = null;
boolean found = false;
do {
searchIndex = policyIndex + '.' + parentIndex;
parentIndex = parentIndices.get(searchIndex);
String type = configTypes.get(searchIndex);
// Is a policy
found = "1".equals(type);
LOG.debug("CiscoQoS getTargetAttribute: parent index for {} is {}, is a policy? {}", searchIndex, parentIndex, found);
} while (!found || parentIndex == null);
LOG.debug("CiscoQoS getTargetAttribute: retrieving policy config index for {}", searchIndex);
String targetValue = null;
final String confIndex_TP = property.getParameterValue(TYPE_QOS_CONF_INDEX, TYPE_QOS_CONF_INDEX);
final String confIndex_ID = property.getParameterValue(OBJ_QOS_CONF_INDEX, OBJ_QOS_CONF_INDEX);
final String intfIndex_TP = property.getParameterValue(TYPE_QOS_INTF_INDEX, TYPE_QOS_INTF_INDEX);
final String intfIndex_ID = property.getParameterValue(OBJ_QOS_INTF_INDEX, OBJ_QOS_INTF_INDEX);
switch(targetProperty) {
case PARAM_POLICY_NAME:
String policyConfigIndex = getAttributeValue(sourceAttributes, searchIndex, confIndex_TP, confIndex_ID);
if (policyConfigIndex == null) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find policy for index {}", searchIndex);
return null;
}
final String policyName_TP = property.getParameterValue(TYPE_QOS_POLICY_NAME, TYPE_QOS_POLICY_NAME);
final String policyName_ID = property.getParameterValue(OBJ_QOS_POLICY_NAME, OBJ_QOS_POLICY_NAME);
LOG.debug("CiscoQoS getTargetAttribute: found policy config index {}", policyConfigIndex);
String policyName = getAttributeValue(sourceAttributes, policyConfigIndex, policyName_TP, policyName_ID);
if (policyName == null) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find policy name using index {} for resource {} using {}::{}", policyConfigIndex, targetResource, policyName_TP, policyName_ID);
return null;
}
LOG.debug("CiscoQoS getTargetAttribute: policyIndex={}, policyConfigIndex={}, policyName={}", policyIndex, policyConfigIndex, policyName);
targetValue = policyName;
break;
case PARAM_CLASSMAP_NAME:
String classMapCfgIndex = getAttributeValue(sourceAttributes, oidIndex, confIndex_TP, confIndex_ID);
if (classMapCfgIndex == null) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find class-map config index for resource {}", targetResource);
return null;
}
final String classMapName_TP = property.getParameterValue(TYPE_QOS_CLASS_NAME, TYPE_QOS_CLASS_NAME);
final String classMapName_ID = property.getParameterValue(OBJ_QOS_CLASS_NAME, OBJ_QOS_CLASS_NAME);
String classMapName = getAttributeValue(sourceAttributes, classMapCfgIndex, classMapName_TP, classMapName_ID);
if (classMapName == null) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find class-map name using index {} for resource {} using {}::{}", classMapCfgIndex, targetResource, classMapName_TP, classMapName_ID);
return null;
}
LOG.debug("CiscoQoS getTargetAttribute: classMapCfgIndex={}, classMapName={}", classMapCfgIndex, classMapName);
targetValue = classMapName;
break;
case PARAM_INTERFACE__NAME:
String interfaceIndex = getAttributeValue(sourceAttributes, policyIndex, intfIndex_TP, intfIndex_ID);
if (interfaceIndex == null) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find interface ifIndex for resource {}", targetResource);
return null;
}
final String intfName_ID = property.getParameterValue(OBJ_INTF_NAME, OBJ_INTF_NAME);
String ifName = getAttributeValue(sourceAttributes, interfaceIndex, CollectionResource.RESOURCE_TYPE_IF, intfName_ID);
if (ifName == null) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find ifName using ifIndex {} for resource {} using {}::{}", interfaceIndex, targetResource, CollectionResource.RESOURCE_TYPE_IF, intfName_ID);
return null;
}
targetValue = ifName;
break;
case PARAM_INTERFACE_ALIAS:
interfaceIndex = getAttributeValue(sourceAttributes, policyIndex, intfIndex_TP, intfIndex_ID);
if (interfaceIndex == null) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find interface ifIndex for resource {}", targetResource);
return null;
}
final String intfAlias_ID = property.getParameterValue(OBJ_INTF_ALIAS, OBJ_INTF_ALIAS);
String ifAlias = getAttributeValue(sourceAttributes, interfaceIndex, CollectionResource.RESOURCE_TYPE_IF, intfAlias_ID);
if (ifAlias == null) {
LOG.warn("CiscoQoS getTargetAttribute: Can't find ifAlias using ifIndex {} for resource {} using {}::{}", interfaceIndex, targetResource, CollectionResource.RESOURCE_TYPE_IF, intfAlias_ID);
return null;
}
targetValue = ifAlias;
break;
}
if (targetValue == null) {
LOG.warn("CiscoQoS getTargetAttribute: an unexpected error has happened. Check the parameters on your datacollection-configuration for the property {}", property.getAlias());
return null;
}
MibPropertyAttributeType type = new MibPropertyAttributeType(targetResource.getResourceType(), property, groupType);
SnmpValue value = SnmpUtils.getValueFactory().getOctetString(targetValue.getBytes());
return new SnmpAttribute(targetResource, type, value);
}
use of org.opennms.netmgt.collection.api.AttributeGroupType in project opennms by OpenNMS.
the class OnmsSnmpCollection method findGroup.
private AttributeGroupType findGroup(Map<String, AttributeGroupType> groupTypes, MibObject mibObject) {
AttributeGroupType groupType = groupTypes.get(mibObject.getGroupName());
if (groupType == null) {
groupType = new AttributeGroupType(mibObject.getGroupName(), mibObject.getGroupIfType());
groupTypes.put(mibObject.getGroupName(), groupType);
}
return groupType;
}
use of org.opennms.netmgt.collection.api.AttributeGroupType in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testResourceCounterData.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds.xml
*
* Updated to reflect the fact that counter are treated as rates (counter wrap is not checked here anymore).
*/
@Test
public void testResourceCounterData() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-counters.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
MibObject mibObject = createMibObject("counter", "myCounter", "0");
SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
// Add Events
addHighThresholdEvent(1, 10, 5, 15, "node", "node", "myCounter", null, null);
addHighRearmEvent(1, 10, 5, 2, "node", "node", "myCounter", null, null);
long baseDate = new Date().getTime();
// Step 0: Visit a CollectionSet with a timestamp, so that the thresholder knows how when the collection was held
// Normally visiting the CollectionSet would end up visiting the resources, but we're fudging that for the test
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
// Collect Step 1 : Initialize counter cache.
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(1000));
resource.visit(visitor);
// Collect Step 2 : Trigger. (last-current)/step => (5500-1000)/300=15
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
resource.visit(visitor);
// Collect Step 3 : Rearm. (last-current)/step => (6100-5500)/300=2
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100));
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collection.api.AttributeGroupType in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testZeroIntervalResourceCounterData.
@Test
public void testZeroIntervalResourceCounterData() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-counters.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
MibObject mibObject = createMibObject("counter", "myCounter", "0");
SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
// Add Events
addHighThresholdEvent(1, 10, 5, 15, "node", "node", "myCounter", null, null);
addHighRearmEvent(1, 10, 5, 2, "node", "node", "myCounter", null, null);
long baseDate = new Date().getTime();
// Step 0: Visit a CollectionSet with a timestamp, so that the thresholder knows how when the collection was held
// Normally visiting the CollectionSet would end up visiting the resources, but we're fudging that for the test
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
// Collect Step 1 : Initialize counter cache.
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(1000));
resource.visit(visitor);
// Collect Step 1.5 : Send a new data point with the same timestamp as before and a
// different value. This should not trigger a threshold violation because the time
// interval is zero. It should also not reset the cached value for the attribute
// because the time interval is zero.
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
resource.visit(visitor);
// Collect Step 2 : Trigger. (last-current)/step => (5500-1000)/300=15
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500));
resource.visit(visitor);
// Collect Step 3 : Rearm. (last-current)/step => (6100-5500)/300=2
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100));
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.collection.api.AttributeGroupType in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug3193.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-bug3193.xml
*
* Updated to reflect the fact that counter are treated as rates.
*/
@Test
public void testBug3193() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-bug3193.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeResourceType resourceType = createNodeResourceType(agent);
MibObject mibObject = createMibObject("counter", "myCounter", "0");
SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "default", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
// Add Events
addHighThresholdEvent(1, 100, 90, 110, "node", "node", "myCounter", null, null);
addHighThresholdEvent(1, 70, 60, 80, "node", "node", "myCounter - 30", null, null);
addHighRearmEvent(1, 100, 90, 40, "node", "node", "myCounter", null, null);
addHighRearmEvent(1, 70, 60, 10, "node", "node", "myCounter - 30", null, null);
long baseDate = new Date().getTime();
// Collect Step 1 : First Data: Last should be NaN
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate));
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(2000));
resource.visit(visitor);
// Collect Step 2 : First Value: (last-current)/step => (20000-2000)/300=60
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 300000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(20000));
resource.visit(visitor);
// Collect Step 3 : Second Value: (last-current)/step => (53000-20000)/300=110 => Trigger
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 600000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(53000));
resource.visit(visitor);
// Collect Step 3 : Third Value (last-current)/step => (65000-53000)/300=40 => Rearm
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate + 900000));
resource = new NodeInfo(resourceType, agent);
resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(65000));
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
Aggregations