Search in sources :

Example 76 with OnmsIpInterface

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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 77 with OnmsIpInterface

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;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 78 with OnmsIpInterface

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();
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 79 with OnmsIpInterface

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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) DefaultCollectionAgent(org.opennms.netmgt.collection.core.DefaultCollectionAgent) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) Test(org.junit.Test)

Example 80 with OnmsIpInterface

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"));
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) SnmpPeerFactory(org.opennms.netmgt.config.SnmpPeerFactory) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) Test(org.junit.Test)

Aggregations

OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)186 OnmsNode (org.opennms.netmgt.model.OnmsNode)117 Test (org.junit.Test)53 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)43 InetAddress (java.net.InetAddress)40 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)33 Transactional (org.springframework.transaction.annotation.Transactional)30 ArrayList (java.util.ArrayList)22 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)21 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)20 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 File (java.io.File)16 HashMap (java.util.HashMap)15 Before (org.junit.Before)15 LinkedList (java.util.LinkedList)14 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)14 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsResource (org.opennms.netmgt.model.OnmsResource)11