Search in sources :

Example 1 with OnmsServiceType

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

the class MockMonitoredServiceDao method updateSubObjects.

private void updateSubObjects(final OnmsMonitoredService svc) {
    final OnmsServiceType serviceType = svc.getServiceType();
    final OnmsServiceType existingServiceType = getServiceTypeDao().findByName(serviceType.getName());
    if (existingServiceType != null && existingServiceType.getId() != serviceType.getId()) {
        svc.setServiceType(existingServiceType);
    }
    getServiceTypeDao().saveOrUpdate(svc.getServiceType());
}
Also used : OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType)

Example 2 with OnmsServiceType

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

the class AvailabilityDatabasePopulator method getServiceType.

private OnmsServiceType getServiceType(String name) {
    OnmsServiceType serviceType = getServiceTypeDao().findByName(name);
    if (serviceType == null) {
        serviceType = new OnmsServiceType(name);
        getServiceTypeDao().save(serviceType);
        getServiceTypeDao().flush();
    }
    return serviceType;
}
Also used : OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType)

Example 3 with OnmsServiceType

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

the class DatabasePopulator method doResetDatabase.

private void doResetDatabase() {
    LOG.debug("==== DatabasePopulator Reset ====");
    for (final OnmsOutage outage : m_outageDao.findAll()) {
        m_outageDao.delete(outage);
    }
    for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
        m_userNotificationDao.delete(not);
    }
    for (final OnmsNotification not : m_notificationDao.findAll()) {
        m_notificationDao.delete(not);
    }
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
        m_alarmDao.delete(alarm);
    }
    for (final OnmsEvent event : m_eventDao.findAll()) {
        m_eventDao.delete(event);
    }
    for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
        for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
            eachIf.setSnmpInterface(null);
            snmpIface.getNode().getIpInterfaces().remove(eachIf);
        }
        snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
        m_snmpInterfaceDao.delete(snmpIface);
    }
    for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
        iface.setSnmpInterface(null);
        iface.getNode().getIpInterfaces().remove(iface);
        m_ipInterfaceDao.delete(iface);
    }
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
        m_serviceTypeDao.delete(service);
    }
    for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
        // Don't delete the default localhost monitoring location
        if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
            m_monitoringLocationDao.delete(location);
        }
    }
    for (final OnmsCategory category : m_categoryDao.findAll()) {
        m_categoryDao.delete(category);
    }
    LOG.debug("= DatabasePopulatorExtension Reset Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
        eachExtension.onShutdown(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Reset Finished =");
    m_outageDao.flush();
    m_userNotificationDao.flush();
    m_notificationDao.flush();
    m_alarmDao.flush();
    m_eventDao.flush();
    m_snmpInterfaceDao.flush();
    m_ipInterfaceDao.flush();
    m_nodeDao.flush();
    m_serviceTypeDao.flush();
    LOG.debug("==== DatabasePopulator Reset Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 4 with OnmsServiceType

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

the class PollerServiceTest method testPoll.

public void testPoll() throws EventProxyException {
    final int expectedPolldId = 7;
    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);
    final OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    m_eventProxy.send(isA(Event.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            Event event = (Event) getCurrentArguments()[0];
            assertEquals("Incorrect uei for demandPollService event", EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI, event.getUei());
            assertEquals("Incorrect nodeid for demandPollService event", monSvc.getNodeId().longValue(), event.getNodeid().longValue());
            assertEquals("Incorrect ipadr for demandPollService event", InetAddressUtils.str(monSvc.getIpAddress()), event.getInterface());
            assertEquals("Incorrect ifIndex for demandPollService event", monSvc.getIfIndex(), Integer.valueOf(event.getIfIndex()));
            assertEquals("Incorrect service for demandPollService event", monSvc.getServiceType().getName(), event.getService());
            EventUtils.requireParm(event, EventConstants.PARM_DEMAND_POLL_ID);
            assertEquals(expectedPolldId, EventUtils.getIntParm(event, EventConstants.PARM_DEMAND_POLL_ID, -1));
            return null;
        }
    });
    replay(m_eventProxy);
    m_pollerService.poll(monSvc, expectedPolldId);
    verify(m_eventProxy);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Event(org.opennms.netmgt.xml.event.Event) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 5 with OnmsServiceType

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

the class PollerBackEndIT method testReportResults.

@Test
@Transactional
public void testReportResults() throws InterruptedException {
    final OnmsNode node = new OnmsNode(m_monitoringLocationDao.getDefaultLocation(), "foo");
    final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr("192.168.1.1"), node);
    OnmsServiceType serviceType = m_serviceTypeDao.findByName("HTTP");
    if (serviceType == null) {
        serviceType = new OnmsServiceType("HTTP");
        m_serviceTypeDao.save(serviceType);
        m_serviceTypeDao.flush();
    }
    final OnmsMonitoredService service = new OnmsMonitoredService(iface, serviceType);
    iface.setMonitoredServices(Collections.singleton(service));
    m_nodeDao.save(node);
    m_nodeDao.flush();
    final String locationMonitorId = m_backEnd.registerLocationMonitor("RDU");
    final int serviceId = service.getId();
    // make sure there is no rrd data
    final File rrdFile = new File("target/test-data/distributed/" + locationMonitorId + "/" + InetAddressUtils.str(iface.getIpAddress()) + "/http" + m_rrdStrategy.getDefaultFileExtension());
    if (rrdFile.exists()) {
        rrdFile.delete();
    }
    assertFalse(rrdFile.exists());
    m_backEnd.reportResult(locationMonitorId, serviceId, PollStatus.available(1234.0));
    Thread.sleep(1000);
    m_backEnd.reportResult(locationMonitorId, serviceId, PollStatus.unavailable());
    final Collection<OnmsLocationSpecificStatus> statuses = m_locationMonitorDao.getStatusChangesForLocationBetween(new Date(0L), new Date(), "RDU");
    assertEquals(2, statuses.size());
    final Iterator<OnmsLocationSpecificStatus> statusIterator = statuses.iterator();
    final OnmsLocationSpecificStatus status1 = statusIterator.next();
    final OnmsLocationSpecificStatus status2 = statusIterator.next();
    assertEquals(Double.valueOf(1234D), status1.getPollResult().getResponseTime());
    assertNull(status2.getPollResult().getResponseTime());
    assertTrue("rrd file doesn't exist at " + rrdFile.getAbsolutePath(), rrdFile.exists());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) File(java.io.File) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)38 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)19 OnmsNode (org.opennms.netmgt.model.OnmsNode)19 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)17 Date (java.util.Date)8 Test (org.junit.Test)8 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)6 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)6 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)4 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)4 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4 Transactional (org.springframework.transaction.annotation.Transactional)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)3 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)3 ServiceSelector (org.opennms.netmgt.model.ServiceSelector)3 Properties (java.util.Properties)2