Search in sources :

Example 21 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface 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);
}
Also used : NSClientPeerFactory(org.opennms.protocols.nsclient.config.NSClientPeerFactory) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) NSClientDataCollectionConfigFactory(org.opennms.protocols.nsclient.config.NSClientDataCollectionConfigFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) EventProxy(org.opennms.netmgt.events.api.EventProxy) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) Before(org.junit.Before)

Example 22 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class DemandPollServiceTest method testPollMonitoredService.

public void testPollMonitoredService() throws EventProxyException {
    final int expectedResultId = m_pollStore.getExpectedId();
    // anticipate a call to the dao save with a pollResult
    m_demandPollDao.save(isA(DemandPoll.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            DemandPoll poll = (DemandPoll) getCurrentArguments()[0];
            m_pollStore.save(poll);
            return null;
        }
    });
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    expect(m_monitoredServiceDao.get(1, addr("192.168.1.1"), 1, 3)).andReturn(monSvc);
    m_pollerService.poll(monSvc, expectedResultId);
    replay(m_demandPollDao);
    replay(m_monitoredServiceDao);
    replay(m_pollerService);
    DemandPoll result = m_demandPollService.pollMonitoredService(1, addr("192.168.1.1"), 1, 3);
    verify(m_demandPollDao);
    verify(m_monitoredServiceDao);
    verify(m_pollerService);
    assertNotNull("Null is an invalid response from pollMonitoredService", result);
    assertEquals("Expected Id to be set by dao", expectedResultId, result.getId().intValue());
}
Also used : DemandPoll(org.opennms.netmgt.model.DemandPoll) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 23 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class DefaultProvisionService method updateNodeHostname.

private void updateNodeHostname(final OnmsNode node) {
    if (NodeLabelSource.HOSTNAME.equals(node.getLabelSource()) || NodeLabelSource.ADDRESS.equals(node.getLabelSource())) {
        OnmsIpInterface primary = node.getPrimaryInterface();
        if (primary == null && node.getIpInterfaces() != null) {
            primary = node.getIpInterfaces().iterator().next();
        }
        final InetAddress primaryAddr = primary.getIpAddress();
        final String primaryHostname = getHostnameResolver().getHostname(primaryAddr, node.getLocation().getLocationName());
        if (primaryHostname == null && node.getLabel() != null && NodeLabelSource.HOSTNAME.equals((node.getLabelSource()))) {
            LOG.warn("Previous node label source for address {} was hostname, but it does not currently resolve.  Skipping update.", InetAddressUtils.str(primaryAddr));
            return;
        }
        for (final OnmsIpInterface iface : node.getIpInterfaces()) {
            final InetAddress addr = iface.getIpAddress();
            final String ipAddress = str(addr);
            final String hostname = getHostnameResolver().getHostname(addr, node.getLocation().getLocationName());
            if (iface.equals(primary)) {
                LOG.debug("Node Label was set by hostname or address.  Re-setting.");
                if (hostname == null || ipAddress.equals(hostname)) {
                    node.setLabel(ipAddress);
                    node.setLabelSource(NodeLabelSource.ADDRESS);
                } else {
                    node.setLabel(hostname);
                    node.setLabelSource(NodeLabelSource.HOSTNAME);
                }
            }
            if (hostname == null) {
                iface.setIpHostName(ipAddress);
            } else {
                iface.setIpHostName(hostname);
            }
        }
    } else {
        LOG.debug("Node label source ({}) is not host or address. Skipping update.", node.getLabelSource());
    }
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) InetAddress(java.net.InetAddress)

Example 24 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class DefaultProvisionService method updateMonitoredServiceState.

@Transactional
@Override
public OnmsMonitoredService updateMonitoredServiceState(final Integer nodeId, final String ipAddress, final String svcName) {
    final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
    assertNotNull(iface, "could not find interface with nodeid %d and ipAddr %s", nodeId, ipAddress);
    return new UpsertTemplate<OnmsMonitoredService, MonitoredServiceDao>(m_transactionManager, m_monitoredServiceDao) {

        @Override
        protected OnmsMonitoredService query() {
            return iface.getMonitoredServiceByServiceType(svcName);
        }

        @Override
        protected OnmsMonitoredService doUpdate(OnmsMonitoredService dbObj) {
            // NMS-3906
            LOG.debug("current status of service {} on node with IP {} is {} ", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress(), dbObj.getStatus());
            switch(dbObj.getStatus()) {
                case "S":
                    LOG.debug("suspending polling for service {} on node with IP {}", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress());
                    dbObj.setStatus("F");
                    m_monitoredServiceDao.update(dbObj);
                    sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, dbObj);
                    break;
                case "R":
                    LOG.debug("resume polling for service {} on node with IP {}", dbObj.getServiceName(), dbObj.getIpAddress().getHostAddress());
                    dbObj.setStatus("A");
                    m_monitoredServiceDao.update(dbObj);
                    sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, dbObj);
                    break;
                case "A":
                    // we can ignore active statuses
                    break;
                default:
                    LOG.warn("Unhandled state: {}", dbObj.getStatus());
                    break;
            }
            return dbObj;
        }

        @Override
        protected OnmsMonitoredService doInsert() {
            return null;
        }

        private void sendEvent(String eventUEI, OnmsMonitoredService dbObj) {
            final EventBuilder bldr = new EventBuilder(eventUEI, "ProvisionService");
            bldr.setNodeid(dbObj.getNodeId());
            bldr.setInterface(dbObj.getIpAddress());
            bldr.setService(dbObj.getServiceName());
            m_eventForwarder.sendNow(bldr.getEvent());
        }
    }.execute();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class LocationDataServiceIT method setUp.

@Before
public void setUp() throws Exception {
    Properties p = new Properties();
    p.setProperty("log4j.logger.org.hibernate", "INFO");
    p.setProperty("log4j.logger.org.hibernate.SQL", "DEBUG");
    MockLogAppender.setupLogging(p);
    OnmsMonitoringLocation location = new OnmsMonitoringLocation("RDU", "East Coast", new String[] { "example1" }, new String[0], "Research Triangle Park, NC", 35.715751f, -79.16262f, 1L, "odd");
    m_monitoringLocationDao.saveOrUpdate(location);
    OnmsApplication app = new OnmsApplication();
    app.setName("TestApp1");
    m_applicationDao.saveOrUpdate(app);
    OnmsNode localhostNode = new OnmsNode(location, "localhost");
    m_nodeDao.saveOrUpdate(localhostNode);
    OnmsNode googleNode = new OnmsNode(location, "google");
    m_nodeDao.saveOrUpdate(googleNode);
    OnmsIpInterface localhostIpInterface = new OnmsIpInterface(addr("127.0.0.1"), localhostNode);
    m_ipInterfaceDao.saveOrUpdate(localhostIpInterface);
    OnmsIpInterface googleIpInterface = new OnmsIpInterface(addr("66.249.80.104"), googleNode);
    m_ipInterfaceDao.saveOrUpdate(googleIpInterface);
    OnmsServiceType httpServiceType = new OnmsServiceType("HTTP");
    m_serviceTypeDao.saveOrUpdate(httpServiceType);
    m_localhostHttpService = createService(app, localhostIpInterface, httpServiceType);
    m_googleHttpService = createService(app, googleIpInterface, httpServiceType);
    m_rduMonitor1 = new OnmsLocationMonitor();
    m_rduMonitor1.setId(UUID.randomUUID().toString());
    m_rduMonitor1.setLocation("RDU");
    m_rduMonitor1.setLastUpdated(m_pollingEnd);
    m_rduMonitor1.setStatus(MonitorStatus.STARTED);
    m_locationMonitorDao.saveOrUpdate(m_rduMonitor1);
    m_rduMonitor2 = new OnmsLocationMonitor();
    m_rduMonitor2.setId(UUID.randomUUID().toString());
    m_rduMonitor2.setLocation("RDU");
    m_rduMonitor2.setLastUpdated(m_pollingEnd);
    m_rduMonitor2.setStatus(MonitorStatus.STARTED);
    m_locationMonitorDao.saveOrUpdate(m_rduMonitor2);
    m_applicationDao.flush();
    m_distPollerDao.flush();
    m_nodeDao.flush();
    m_ipInterfaceDao.flush();
    m_serviceTypeDao.flush();
    m_monitoredServiceDao.flush();
    m_locationMonitorDao.flush();
    OnmsApplication onmsApp = m_applicationDao.findByName("TestApp1");
    assertTrue(onmsApp.equals(app));
    assertEquals("Count of applications associated with services is wrong", 1, m_localhostHttpService.getApplications().size());
    assertEquals("Count of applications associated with services is wrong", 1, m_googleHttpService.getApplications().size());
    assertEquals("Count of services associated with application is wrong", 2, app.getMonitoredServices().size());
    m_pollingEnd = new Date();
    m_pollingStart = new Date(m_pollingEnd.getTime() - (1000 * 60 * 60 * 24));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Properties(java.util.Properties) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

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