use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class CollectdEventHandlingTest method canHandleServiceDeletedEvents.
@Test
public void canHandleServiceDeletedEvents() {
// Handle a serviceDeleted event targeting svc2
OnmsNode node = new OnmsNode();
node.setId(svc2.getNodeId());
OnmsIpInterface iface = new OnmsIpInterface();
iface.setId(101);
iface.setNode(node);
iface.setIpAddress(svc2.getAddress());
Event e = new EventBuilder(EventConstants.SERVICE_DELETED_EVENT_UEI, "test").setIpInterface(iface).setService(svc2.getServiceName()).getEvent();
collectd.onEvent(e);
// The delete flag should be set (and only set) on svc2
assertFalse("deletion flag was set on svc1!", svc1.getCollectorUpdates().isDeletionFlagSet());
assertTrue("deletion flag was not set on svc2!", svc2.getCollectorUpdates().isDeletionFlagSet());
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class CollectdTest method getInterface.
private static OnmsIpInterface getInterface() {
OnmsNode node = new OnmsNode();
node.setId(1);
OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.getInetAddress("192.168.1.1"), node);
iface.setId(1);
return iface;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class CollectdTest method testInterfaceIsNotScheduledWhenValidationFails.
/**
* NMS-9413: Verifies that collectd does not schedule interfaces when the
* {@link ServiceCollector} throws a {@link CollectionInitializationException}
* while validating the agent.
*/
@SuppressWarnings("unchecked")
@Test
public void testInterfaceIsNotScheduledWhenValidationFails() throws Exception {
ServiceCollector svcCollector = m_easyMockUtils.createMock(ServiceCollector.class);
svcCollector.initialize();
svcCollector.validateAgent(isA(CollectionAgent.class), isA(Map.class));
expectLastCall().andThrow(new CollectionInitializationException("No!")).once();
setupCollector("SNMP", svcCollector);
OnmsIpInterface iface = getInterface();
setupInterface(iface);
setupTransactionManager();
expect(m_collectdConfig.getPackages()).andReturn(Collections.singletonList(getCollectionPackageThatMatchesSNMP()));
expect(m_collectdConfigFactory.interfaceInPackage(iface, getCollectionPackageThatMatchesSNMP())).andReturn(true);
m_easyMockUtils.replayAll();
assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount());
m_collectd.afterPropertiesSet();
m_collectd.start();
m_scheduler.next();
assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount());
m_collectd.stop();
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.model.OnmsIpInterface 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.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DefaultCollectionAgentTest method canGetLocationAwareAgentConfig.
/**
* Verifies that the SNMP agent configuration is retrieved using
* the location name that is associated with the interface/node.
*/
@Test
public void canGetLocationAwareAgentConfig() {
// Mock the peer factory
SnmpPeerFactory snmpPeerFactory = mock(SnmpPeerFactory.class);
SnmpPeerFactory.setInstance(snmpPeerFactory);
// Mock the other arguments required to create a DefaultCollectionAgent
Integer ifaceId = 1;
IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
OnmsIpInterface ipIface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS);
when(ifaceDao.load(ifaceId)).thenReturn(ipIface);
when(ipIface.getNode().getLocation().getLocationName()).thenReturn("Ocracoke");
// Retrieve the agent configuration
SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(ifaceId, ifaceDao, transMgr);
agent.getAgentConfig();
// Verify
verify(snmpPeerFactory, times(1)).getAgentConfig(any(), eq("Ocracoke"));
}
Aggregations