Search in sources :

Example 6 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)

Example 7 with OnmsServiceType

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

the class PollerBackEndTest method testSaveResponseTimeDataWithLocaleThatUsesCommasForDecimals.

public void testSaveResponseTimeDataWithLocaleThatUsesCommasForDecimals() throws Exception {
    Properties p = new Properties();
    p.setProperty("org.opennms.netmgt.ConfigFileConstants", "ERROR");
    MockLogAppender.setupLogging(p);
    Locale.setDefault(Locale.FRENCH);
    // Make sure we actually have a valid test
    NumberFormat nf = NumberFormat.getInstance();
    assertEquals("ensure that the newly set default locale (" + Locale.getDefault() + ") uses ',' as the decimal marker", "1,5", nf.format(1.5));
    OnmsMonitoredService svc = new OnmsMonitoredService();
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setName("HTTP");
    svc.setServiceType(svcType);
    OnmsIpInterface intf = new OnmsIpInterface();
    intf.setIpAddress(InetAddressUtils.addr("1.2.3.4"));
    svc.setIpInterface(intf);
    Package pkg = new Package();
    Service pkgService = new Service();
    pkgService.setName("HTTP");
    addParameterToService(pkgService, "ds-name", "http");
    addParameterToService(pkgService, "rrd-repository", "/foo");
    pkg.addService(pkgService);
    Rrd rrd = new Rrd();
    rrd.setStep(300);
    rrd.addRra("bogusRRA");
    pkg.setRrd(rrd);
    // TODO: Figure out why these mock calls aren't being invoked
    //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), endsWith(":1.5"));
    //m_rrdStrategy.closeFile(isA(Object.class));
    expect(m_pollerConfig.getServiceInPackage("HTTP", pkg)).andReturn(m_httpSvcConfig);
    expect(m_pollerConfig.parameters(m_httpSvcConfig)).andReturn(m_httpSvcConfig.getParameters()).atLeastOnce();
    m_mocks.replayAll();
    m_backEnd.saveResponseTimeData("Tuvalu", svc, 1.5, pkg);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Rrd(org.opennms.netmgt.config.poller.Rrd) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package) Properties(java.util.Properties) NumberFormat(java.text.NumberFormat) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 8 with OnmsServiceType

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

the class PollerBackEndTest method setUp.

@Override
protected void setUp() throws Exception {
    System.setProperty("opennms.home", "src/test/test-configurations/PollerBackEndTest-home");
    m_monitoringLocationDao = m_mocks.createMock(MonitoringLocationDao.class);
    m_locMonDao = m_mocks.createMock(LocationMonitorDao.class);
    m_scanReportDao = m_mocks.createMock(ScanReportDao.class);
    m_monSvcDao = m_mocks.createMock(MonitoredServiceDao.class);
    m_pollerConfig = m_mocks.createMock(PollerConfig.class);
    m_timeKeeper = m_mocks.createMock(TimeKeeper.class);
    m_eventIpcManager = new MockEventIpcManager();
    m_backEnd = new DefaultPollerBackEnd();
    m_backEnd.setMonitoringLocationDao(m_monitoringLocationDao);
    m_backEnd.setLocationMonitorDao(m_locMonDao);
    m_backEnd.setScanReportDao(m_scanReportDao);
    m_backEnd.setMonitoredServiceDao(m_monSvcDao);
    m_backEnd.setPollerConfig(m_pollerConfig);
    m_backEnd.setTimeKeeper(m_timeKeeper);
    m_backEnd.setEventIpcManager(m_eventIpcManager);
    m_backEnd.setDisconnectedTimeout(DISCONNECTED_TIMEOUT);
    m_backEnd.setPersisterFactory(new MockPersisterFactory());
    m_startTime = new Date(System.currentTimeMillis() - 600000);
    expect(m_timeKeeper.getCurrentDate()).andReturn(m_startTime);
    replay(m_timeKeeper);
    m_backEnd.afterPropertiesSet();
    verify(m_timeKeeper);
    reset(m_timeKeeper);
    // set up some objects that can be used to mock up the tests
    // the location definition
    m_locationDefinition = new OnmsMonitoringLocation();
    m_locationDefinition.setMonitoringArea("Oakland");
    m_locationDefinition.setLocationName("OAK");
    m_locationDefinition.setPollingPackageNames(Collections.singletonList("OAKPackage"));
    m_package = createPackage("OAKPackage", "ipaddr = '192.168.1.1'");
    m_serviceSelector = new ServiceSelector(m_package.getFilter().getContent(), Arrays.asList(new String[] { "HTTP", "DNS" }));
    m_httpSvcConfig = addService(m_package, "HTTP", 1234, "url", "http://www.opennms.org");
    m_dnsSvcConfig = addService(m_package, "DNS", 5678, "hostname", "www.opennms.org");
    m_locationMonitor = new OnmsLocationMonitor();
    m_locationMonitor.setId(LOCATION_MONITOR_ID);
    m_locationMonitor.setLocation(m_locationDefinition.getLocationName());
    OnmsApplication application = new OnmsApplication();
    application.setName(APPLICATION_NAME);
    NetworkBuilder builder = new NetworkBuilder();
    builder.addNode("testNode").setId(1);
    builder.addInterface("192.168.1.1").setId(1);
    m_httpService = builder.addService(new OnmsServiceType("HTTP"));
    m_httpService.setId(1);
    m_httpService.setApplications(Collections.singleton(application));
    m_dnsService = builder.addService(new OnmsServiceType("DNS"));
    m_dnsService.setId(2);
    m_dnsService.setApplications(Collections.singleton(application));
    m_monServices = new OnmsMonitoredService[] { m_httpService, m_dnsService };
    long now = System.currentTimeMillis();
    PollStatus httpResult = PollStatus.available(1000.0);
    httpResult.setTimestamp(new Date(now - 300000));
    m_httpCurrentStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_httpService, httpResult);
    m_httpCurrentStatus.setId(1);
    PollStatus dnsResult = PollStatus.unavailable("Non responsive");
    dnsResult.setTimestamp(new Date(now - 300000));
    m_dnsCurrentStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_dnsService, dnsResult);
    m_dnsCurrentStatus.setId(2);
    m_pollerDetails = new HashMap<String, String>();
    m_pollerDetails.put("os.name", "WonkaOS");
    m_pollerDetails.put("os.version", "1.2.3");
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) TimeKeeper(org.opennms.netmgt.collection.api.TimeKeeper) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ScanReportDao(org.opennms.netmgt.dao.api.ScanReportDao) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) PollerConfig(org.opennms.netmgt.config.PollerConfig) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) MonitoringLocationDao(org.opennms.netmgt.dao.api.MonitoringLocationDao) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) LocationMonitorDao(org.opennms.netmgt.dao.api.LocationMonitorDao) DefaultPollerBackEnd(org.opennms.netmgt.poller.remote.support.DefaultPollerBackEnd) Date(java.util.Date) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 9 with OnmsServiceType

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

the class OutageDaoIT method insertEntitiesAndOutage.

private OnmsOutage insertEntitiesAndOutage(final String ipAddr, final String serviceName, OnmsNode node) {
    OnmsIpInterface ipInterface = getIpInterface(ipAddr, node);
    OnmsServiceType serviceType = getServiceType(serviceName);
    OnmsMonitoredService monitoredService = getMonitoredService(ipInterface, serviceType);
    OnmsEvent event = getEvent();
    OnmsOutage outage = getOutage(monitoredService, event);
    return outage;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 10 with OnmsServiceType

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

the class OutageDaoIT method getServiceType.

private OnmsServiceType getServiceType(final String serviceName) {
    OnmsServiceType serviceType = m_serviceTypeDao.findByName(serviceName);
    assertNotNull("Couldn't find " + serviceName + " in the database", serviceType);
    return serviceType;
}
Also used : OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType)

Aggregations

OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)34 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)19 OnmsNode (org.opennms.netmgt.model.OnmsNode)17 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)16 Date (java.util.Date)7 Test (org.junit.Test)7 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)6 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)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 InsufficientInformationException (org.opennms.core.utils.InsufficientInformationException)2 DefaultServiceCollectorRegistry (org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry)2