use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runFileSystemDataTest.
private void runFileSystemDataTest(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
// Creating Generic ResourceType
GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "hrStorageIndex");
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1", "hrStorageIndex", Integer.toString(resourceId));
m_resourceStorageDao.setStringAttribute(path, "hrStorageType", ".1.3.6.1.2.1.25.2.1.4");
m_resourceStorageDao.setStringAttribute(path, "hrStorageDescr", fs);
// Creating Resource
SnmpInstId inst = new SnmpInstId(resourceId);
SnmpCollectionResource resource = new GenericIndexResource(resourceType, "hrStorageIndex", inst);
addAttributeToCollectionResource(resource, resourceType, "hrStorageUsed", "gauge", "hrStorageIndex", value);
addAttributeToCollectionResource(resource, resourceType, "hrStorageSize", "gauge", "hrStorageIndex", max);
addAttributeToCollectionResource(resource, resourceType, "hrStorageAllocUnits", "gauge", "hrStorageIndex", 1);
// Run Visitor
resource.visit(visitor);
EasyMock.verify(agent);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testThresholdsFiltersOnNodeResourceWithCollectionSetBuilder.
/**
* Similar to {@link #testThresholdsFiltersOnNodeResource()}, but
* we generate the collection set using the CollectionSetBuilder instead
* of using SnmpCollector specific types.
*/
@Test
public void testThresholdsFiltersOnNodeResourceWithCollectionSetBuilder() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-5.xml");
ThresholdingVisitor visitor = createVisitor();
// Adding Expected Thresholds
addHighThresholdEvent(1, 30, 25, 50, "/home", "node", "(hda1_hrStorageUsed/hda1_hrStorageSize)*100", null, null);
addHighThresholdEvent(1, 50, 45, 60, "/opt", "node", "(hda2_hrStorageUsed/hda2_hrStorageSize)*100", null, null);
// Creating Node ResourceType
SnmpCollectionAgent agent = createCollectionAgent();
NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(nodeResource, "hd-usage", "hda1_hrStorageUsed", 50, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda1_hrStorageSize", 100, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda2_hrStorageUsed", 60, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda2_hrStorageSize", 100, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda3_hrStorageUsed", 70, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda3_hrStorageSize", 100, AttributeType.GAUGE).build();
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1");
m_resourceStorageDao.setStringAttribute(path, "hda1_hrStorageDescr", "/home");
m_resourceStorageDao.setStringAttribute(path, "hda2_hrStorageDescr", "/opt");
m_resourceStorageDao.setStringAttribute(path, "hda3_hrStorageDescr", "/usr");
// Run Visitor and Verify Events
collectionSet.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testThresholdsFiltersOnNodeResource.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-5.xml
*/
@Test
public void testThresholdsFiltersOnNodeResource() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-5.xml");
ThresholdingVisitor visitor = createVisitor();
// Adding Expected Thresholds
addHighThresholdEvent(1, 30, 25, 50, "/home", "node", "(hda1_hrStorageUsed/hda1_hrStorageSize)*100", null, null);
addHighThresholdEvent(1, 50, 45, 60, "/opt", "node", "(hda2_hrStorageUsed/hda2_hrStorageSize)*100", null, null);
// Creating Node ResourceType
SnmpCollectionAgent agent = createCollectionAgent();
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
NodeResourceType resourceType = new NodeResourceType(agent, collection);
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1");
m_resourceStorageDao.setStringAttribute(path, "hda1_hrStorageDescr", "/home");
m_resourceStorageDao.setStringAttribute(path, "hda2_hrStorageDescr", "/opt");
m_resourceStorageDao.setStringAttribute(path, "hda3_hrStorageDescr", "/usr");
// Creating Resource
SnmpCollectionResource resource = new NodeInfo(resourceType, agent);
addAttributeToCollectionResource(resource, resourceType, "hda1_hrStorageUsed", "gauge", "node", 50);
addAttributeToCollectionResource(resource, resourceType, "hda1_hrStorageSize", "gauge", "node", 100);
addAttributeToCollectionResource(resource, resourceType, "hda2_hrStorageUsed", "gauge", "node", 60);
addAttributeToCollectionResource(resource, resourceType, "hda2_hrStorageSize", "gauge", "node", 100);
addAttributeToCollectionResource(resource, resourceType, "hda3_hrStorageUsed", "gauge", "node", 70);
addAttributeToCollectionResource(resource, resourceType, "hda3_hrStorageSize", "gauge", "node", 100);
// Run Visitor and Verify Events
resource.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class Sftp3gppXmlCollectionHandler method collect.
/* (non-Javadoc)
* @see org.opennms.protocols.xml.collector.XmlCollectionHandler#collect(org.opennms.netmgt.collectd.CollectionAgent, org.opennms.protocols.xml.config.XmlDataCollection, java.util.Map)
*/
@Override
public CollectionSet collect(CollectionAgent agent, XmlDataCollection collection, Map<String, Object> parameters) throws CollectionException {
String status = "finished";
// Create a new collection set.
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
// TODO We could be careful when handling exceptions because parsing exceptions will be treated different from connection or retrieval exceptions
DateTime startTime = new DateTime();
Sftp3gppUrlConnection connection = null;
try {
ResourcePath resourcePath = ResourcePath.get(ResourceTypeUtils.SNMP_DIRECTORY, Integer.toString(agent.getNodeId()));
for (XmlSource source : collection.getXmlSources()) {
if (!source.getUrl().startsWith(Sftp3gppUrlHandler.PROTOCOL)) {
throw new CollectionException("The 3GPP SFTP Collection Handler can only use the protocol " + Sftp3gppUrlHandler.PROTOCOL);
}
final String urlStr = source.getUrl();
final Request request = source.getRequest();
URL url = UrlFactory.getUrl(urlStr, request);
String lastFile = Sftp3gppUtils.getLastFilename(getResourceStorageDao(), getServiceName(), resourcePath, url.getPath());
connection = (Sftp3gppUrlConnection) url.openConnection();
if (lastFile == null) {
lastFile = connection.get3gppFileName();
LOG.debug("collect(single): retrieving file from {}{}{} from {}", url.getPath(), File.separatorChar, lastFile, agent.getHostAddress());
Document doc = getXmlDocument(urlStr, request);
fillCollectionSet(agent, builder, source, doc);
Sftp3gppUtils.setLastFilename(getResourceStorageDao(), getServiceName(), resourcePath, url.getPath(), lastFile);
Sftp3gppUtils.deleteFile(connection, lastFile);
} else {
connection.connect();
List<String> files = connection.getFileList();
long lastTs = connection.getTimeStampFromFile(lastFile);
boolean collected = false;
for (String fileName : files) {
if (connection.getTimeStampFromFile(fileName) > lastTs) {
LOG.debug("collect(multiple): retrieving file {} from {}", fileName, agent.getHostAddress());
InputStream is = connection.getFile(fileName);
try {
Document doc = getXmlDocument(is, request);
IOUtils.closeQuietly(is);
fillCollectionSet(agent, builder, source, doc);
} finally {
IOUtils.closeQuietly(is);
}
Sftp3gppUtils.setLastFilename(getResourceStorageDao(), getServiceName(), resourcePath, url.getPath(), fileName);
Sftp3gppUtils.deleteFile(connection, fileName);
collected = true;
}
}
if (!collected) {
LOG.warn("collect: could not find any file after {} on {}", lastFile, agent);
}
}
}
return builder.build();
} catch (Exception e) {
status = "failed";
throw new CollectionException(e.getMessage(), e);
} finally {
DateTime endTime = new DateTime();
LOG.debug("collect: {} collection {}: duration: {} ms", status, collection.getName(), endTime.getMillis() - startTime.getMillis());
UrlFactory.disconnect(connection);
}
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class TcaCollectionHandler method getLastTimestamp.
/**
* Gets the last timestamp.
*
* @param resource the TCA resource
* @return the last timestamp
*/
private long getLastTimestamp(CollectionResource resource) {
long timestamp = 0;
ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, resource.getPath());
try {
LOG.debug("Retrieving timestamp from path {}", path);
String ts = m_resourceStorageDao.getStringAttribute(path, LAST_TIMESTAMP);
if (ts != null) {
timestamp = Long.parseLong(ts);
}
} catch (Exception e) {
LOG.error("Failed to retrieve timestamp from path {}", path, e);
}
return timestamp;
}
Aggregations