use of org.opennms.core.test.MockPlatformTransactionManager in project opennms by OpenNMS.
the class NsclientCollectorTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
startServer("None&8&", "10");
// Initialize Mocks
m_transactionManager = new MockPlatformTransactionManager();
m_ipInterfaceDao = EasyMock.createMock(IpInterfaceDao.class);
m_eventProxy = EasyMock.createMock(EventProxy.class);
NetworkBuilder builder = new NetworkBuilder();
builder.addNode("winsrv");
builder.addInterface(getServer().getInetAddress().getHostAddress()).addSnmpInterface(1).setCollectionEnabled(true);
builder.getCurrentNode().setId(1);
OnmsIpInterface iface = builder.getCurrentNode().getIpInterfaces().iterator().next();
iface.setIsSnmpPrimary(PrimaryType.PRIMARY);
iface.setId(1);
EasyMock.expect(m_ipInterfaceDao.load(1)).andReturn(iface).anyTimes();
EasyMock.replay(m_ipInterfaceDao, m_eventProxy);
// Initialize NSClient Configuration
String nsclient_config = "<nsclient-config port=\"" + getServer().getLocalPort() + "\" retry=\"1\" timeout=\"3000\" />";
NSClientPeerFactory.setInstance(new NSClientPeerFactory(new ByteArrayInputStream(nsclient_config.getBytes())));
NSClientDataCollectionConfigFactory.setInstance(new NSClientDataCollectionConfigFactory("src/test/resources/nsclient-datacollection-config.xml"));
// Initialize Collection Agent
m_collectionAgent = DefaultCollectionAgent.create(1, m_ipInterfaceDao, m_transactionManager);
}
use of org.opennms.core.test.MockPlatformTransactionManager in project opennms by OpenNMS.
the class DefaultCollectionAgentTest method verifyThatTheIpAndNodeIdAreCached.
/**
* NMS-5105: When processing serviceDeleted and interfaceDeleted events
* in Collectd we need to match both the Node ID and IP Address of
* the service that is being collected with the information from the event.
*
* Since the entities have been deleted, we not longer be able to reach
* in the database to fetch the required details. Instead, they
* should be loaded when the agent is created, and cached for the lifetime
* of the object.
*/
@Test
public void verifyThatTheIpAndNodeIdAreCached() {
OnmsNode node = new OnmsNode();
node.setId(11);
OnmsIpInterface iface = new OnmsIpInterface();
iface.setId(42);
iface.setNode(node);
iface.setIpAddress(InetAddressUtils.ONE_TWENTY_SEVEN);
IpInterfaceDao ifaceDao = EasyMock.createMock(IpInterfaceDao.class);
EasyMock.expect(ifaceDao.load(iface.getId())).andReturn(iface).times(5);
EasyMock.replay(ifaceDao);
PlatformTransactionManager transMgr = new MockPlatformTransactionManager();
CollectionAgent agent = DefaultCollectionAgent.create(iface.getId(), ifaceDao, transMgr);
EasyMock.verify(ifaceDao);
assertEquals(iface.getIpAddress(), agent.getAddress());
assertEquals(node.getId().intValue(), agent.getNodeId());
}
use of org.opennms.core.test.MockPlatformTransactionManager in project opennms by OpenNMS.
the class PersistRegexSelectorStrategyTest method setUp.
@Before
public void setUp() throws Exception {
ipInterfaceDao = EasyMock.createMock(IpInterfaceDao.class);
String localhost = InetAddress.getLocalHost().getHostAddress();
NetworkBuilder builder = new NetworkBuilder();
builder.addNode("myNode");
builder.addInterface(localhost).setIsManaged("M").setIsSnmpPrimary("P");
OnmsNode node = builder.getCurrentNode();
node.setId(1);
OnmsIpInterface ipInterface = node.getIpInterfaces().iterator().next();
EasyMock.expect(ipInterfaceDao.load(1)).andReturn(ipInterface).anyTimes();
EasyMock.replay(ipInterfaceDao);
Package pkg = new Package();
pkg.setName("junitTestPackage");
Filter filter = new Filter();
filter.setContent("IPADDR != '0.0.0.0'");
pkg.setFilter(filter);
Service service = new Service();
service.setName("SNMP");
pkg.addService(service);
Map<String, Object> map = new TreeMap<String, Object>();
List<org.opennms.netmgt.config.collectd.Parameter> params = pkg.getService("SNMP").getParameters();
for (org.opennms.netmgt.config.collectd.Parameter p : params) {
map.put(p.getKey(), p.getValue());
}
map.put("collection", "default");
serviceParams = new ServiceParameters(map);
LocationAwareSnmpClient locationAwareSnmpClient = new LocationAwareSnmpClientRpcImpl(new MockRpcClientFactory());
PlatformTransactionManager ptm = new MockPlatformTransactionManager();
SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(1, ipInterfaceDao, ptm);
OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, serviceParams, new MockDataCollectionConfigDao(), locationAwareSnmpClient);
org.opennms.netmgt.config.datacollection.ResourceType rt = new org.opennms.netmgt.config.datacollection.ResourceType();
rt.setName("myResourceType");
StorageStrategy storageStrategy = new StorageStrategy();
storageStrategy.setClazz("org.opennms.netmgt.collection.support.IndexStorageStrategy");
rt.setStorageStrategy(storageStrategy);
PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
persistenceSelectorStrategy.setClazz("org.opennms.netmgt.collectd.PersistRegexSelectorStrategy");
Parameter param = new Parameter();
param.setKey(PersistRegexSelectorStrategy.MATCH_EXPRESSION);
param.setValue("#name matches '^agalue.*$'");
persistenceSelectorStrategy.addParameter(param);
rt.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, snmpCollection, rt);
resourceA = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.1"));
AttributeGroupType groupType = new AttributeGroupType("mib2-interfaces", AttributeGroupType.IF_TYPE_ALL);
MibObject mibObject = new MibObject();
mibObject.setOid(".1.2.3.4.5.6.7.8.9.2.1");
mibObject.setInstance("1");
mibObject.setAlias("name");
mibObject.setType("string");
StringAttributeType attributeType = new StringAttributeType(resourceType, snmpCollection.getName(), mibObject, groupType);
SnmpValue snmpValue = new Snmp4JValueFactory().getOctetString("agalue rules!".getBytes());
resourceA.setAttributeValue(attributeType, snmpValue);
resourceB = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.2"));
}
use of org.opennms.core.test.MockPlatformTransactionManager in project opennms by OpenNMS.
the class SnmpAttributeTest method testPersisting.
@Ignore
private void testPersisting(String matchValue, SnmpValue snmpValue) throws Exception {
OnmsNode node = new OnmsNode();
node.setId(3);
OnmsIpInterface ipInterface = new OnmsIpInterface();
ipInterface.setId(1);
ipInterface.setNode(node);
ipInterface.setIpAddress(InetAddressUtils.addr("192.168.1.1"));
// It used to be 3, but I think it is more correct to use getStoreDir from DefaultCollectionAgentService on DefaultCollectionAgent (NMS-7516)
expect(m_ipInterfaceDao.load(1)).andReturn(ipInterface).times(5);
expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".myLittleEasyMockedStrategyAndMe").anyTimes();
expect(m_rrdStrategy.createDefinition(isA(String.class), isA(String.class), isA(String.class), anyInt(), isAList(RrdDataSource.class), isAList(String.class))).andReturn(new Object());
m_rrdStrategy.createFile(isA(Object.class));
expect(m_rrdStrategy.openFile(isA(String.class))).andReturn(new Object());
m_rrdStrategy.updateFile(isA(Object.class), isA(String.class), matches(".*:" + matchValue));
m_rrdStrategy.closeFile(isA(Object.class));
m_mocks.replayAll();
SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(ipInterface.getId(), m_ipInterfaceDao, new MockPlatformTransactionManager());
OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), new MockDataCollectionConfig(), m_locationAwareSnmpClient);
NodeResourceType resourceType = new NodeResourceType(agent, snmpCollection);
NodeInfo nodeInfo = resourceType.getNodeInfo();
MibObject mibObject = new MibObject();
mibObject.setOid(".1.3.6.1.4.1.12238.55.9997.4.1.2.9.116.101.109.112.95.117.108.107.111");
mibObject.setInstance("1");
mibObject.setAlias("temp_ulko");
mibObject.setType("gauge");
NumericAttributeType attributeType = new NumericAttributeType(resourceType, snmpCollection.getName(), mibObject, new AttributeGroupType("foo", AttributeGroupType.IF_TYPE_IGNORE));
attributeType.storeResult(new SnmpCollectionSet(agent, snmpCollection, m_locationAwareSnmpClient), null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), snmpValue));
RrdRepository repository = createRrdRepository();
repository.setRraList(Collections.singletonList("RRA:AVERAGE:0.5:1:2016"));
RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
persisterFactory.setRrdStrategy(m_rrdStrategy);
persisterFactory.setResourceStorageDao(m_resourceStorageDao);
CollectionSetVisitor persister = persisterFactory.createPersister(new ServiceParameters(Collections.emptyMap()), repository);
final AtomicInteger count = new AtomicInteger(0);
nodeInfo.visit(new CollectionSetVisitorWrapper(persister) {
@Override
public void visitAttribute(CollectionAttribute attribute) {
super.visitAttribute(attribute);
count.incrementAndGet();
}
});
assertEquals(1, count.get());
}
use of org.opennms.core.test.MockPlatformTransactionManager in project opennms by OpenNMS.
the class SnmpCollectorITCase method createAgent.
protected void createAgent(int ifIndex, PrimaryType ifCollType) {
m_node = new OnmsNode();
m_node.setSysObjectId(".1.2.3.4.5.6.7");
OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(m_node, ifIndex);
m_iface = new OnmsIpInterface();
m_iface.setId(123);
m_iface.setIpAddress(myLocalHost());
m_iface.setIsSnmpPrimary(ifCollType);
m_iface.setSnmpInterface(snmpIface);
m_node.addIpInterface(m_iface);
EasyMock.expect(m_ifaceDao.load(m_iface.getId())).andReturn(m_iface).anyTimes();
m_easyMockUtils.replayAll();
m_agent = DefaultSnmpCollectionAgent.create(m_iface.getId(), m_ifaceDao, new MockPlatformTransactionManager());
}
Aggregations