Search in sources :

Example 31 with OnmsMonitoredService

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

the class AvailabilityDatabasePopulatorIT method testAvailabilityDatabase.

/**
 * @throws Exception
 */
@Test
@Transactional
public void testAvailabilityDatabase() throws Exception {
    List<OnmsNode> nodes = m_nodeDao.findAll();
    for (OnmsNode node : nodes) {
        m_nodeDao.initialize(node);
        // TODO: Is this necessary?
        m_nodeDao.initialize(node.getLocation());
    }
    for (OnmsNode node : nodes) {
        System.err.println("NODE " + node.toString());
    }
    List<OnmsIpInterface> ifs = m_ipInterfaceDao.findAll();
    for (OnmsIpInterface iface : ifs) {
        System.err.println("INTERFACE " + iface.toString());
    }
    Assert.assertEquals("node DB count", 2, m_nodeDao.countAll());
    Assert.assertEquals("service DB count", 3, m_serviceTypeDao.countAll());
    Assert.assertEquals("IP interface DB count", 3, m_ipInterfaceDao.countAll());
    Assert.assertEquals("outages DB Count", 6, m_outageDao.countAll());
    final OnmsIpInterface oneHundredDotOne = m_ipInterfaceDao.findByNodeIdAndIpAddress(1, "192.168.100.1");
    try {
        List<OnmsMonitoredService> stmt = m_template.query("SELECT ifServices.serviceid, service.servicename FROM ifServices, ipInterface, node, service WHERE ifServices.ipInterfaceId = ipInterface.id AND ipInterface.nodeId = node.nodeId " + "AND ipinterface.ipaddr = '192.168.100.1' AND ipinterface.isManaged ='M' AND " + "ifServices.serviceid = service.serviceid AND ifservices.status = 'A' AND node.nodeid = 1 AND node.nodetype = 'A'", new RowMapper<OnmsMonitoredService>() {

            @Override
            public OnmsMonitoredService mapRow(ResultSet rs, int rowNum) throws SQLException {
                OnmsMonitoredService retval = new OnmsMonitoredService(oneHundredDotOne, m_serviceTypeDao.findByName(rs.getString("servicename")));
                return retval;
            }
        });
        // ResultSet srs = stmt.executeQuery("SELECT ipInterface.ipaddr, ipInterface.nodeid FROM ipInterface WHERE ipInterface.ipaddr = '192.168.100.1'" );
        Assert.assertTrue("interface results for 192.168.100.2", stmt.size() > 0);
        Assert.assertEquals(new Integer(1), stmt.get(0).getServiceId());
    } catch (Exception e) {
        LOG.error("unable to execute SQL", e);
        throw e;
    }
/*
		Assert.assertEquals("node DB count", 2, m_db.countRows("select * from node"));
		Assert.assertEquals("service DB count", 3,
				m_db.countRows("select * from service"));
		Assert.assertEquals("ipinterface DB count", 3,
				m_db.countRows("select * from ipinterface"));
		Assert.assertEquals("interface services DB count", 3,
				m_db.countRows("select * from ifservices"));
		// Assert.assertEquals("outages DB count", 3, m_db.countRows("select * from
		// outages"));
		Assert.assertEquals(
				"ip interface DB count where ipaddr = 192.168.100.1",
				1,
				m_db.countRows("select * from ipinterface where ipaddr = '192.168.100.1'"));
		Assert.assertEquals(
				"number of interfaces returned from IPLIKE",
				3,
				m_db.countRows("select * from ipinterface where iplike(ipaddr,'192.168.100.*')"));
		 */
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) SQLException(java.sql.SQLException) SQLException(java.sql.SQLException) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ResultSet(java.sql.ResultSet) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with OnmsMonitoredService

use of org.opennms.netmgt.model.OnmsMonitoredService 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 33 with OnmsMonitoredService

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

the class DefaultPollerBackEnd method reportResult.

/**
 * {@inheritDoc}
 */
@Override
public void reportResult(final String locationMonitorId, final int serviceId, final PollStatus pollResult) {
    final OnmsLocationMonitor locationMonitor;
    try {
        locationMonitor = m_locMonDao.get(locationMonitorId);
    } catch (final Exception e) {
        LOG.info("Unable to report result for location monitor ID {}: Location monitor does not exist.", locationMonitorId, e);
        return;
    }
    if (locationMonitor == null) {
        LOG.info("Unable to report result for location monitor ID {}: Location monitor does not exist.", locationMonitorId);
        return;
    }
    final OnmsMonitoredService monSvc;
    try {
        monSvc = m_monSvcDao.get(serviceId);
    } catch (final Exception e) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Monitored service does not exist.", locationMonitorId, serviceId, e);
        return;
    }
    if (monSvc == null) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Monitored service does not exist.", locationMonitorId, serviceId);
        return;
    }
    if (pollResult == null) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Poll result is null!", locationMonitorId, serviceId);
        return;
    }
    final OnmsLocationSpecificStatus newStatus = new OnmsLocationSpecificStatus(locationMonitor, monSvc, pollResult);
    try {
        if (newStatus.getPollResult().getResponseTime() != null) {
            final Package pkg = getPollingPackageForMonitorAndService(locationMonitor, monSvc);
            saveResponseTimeData(locationMonitorId, monSvc, newStatus.getPollResult().getResponseTime(), pkg);
        }
    } catch (final Exception e) {
        LOG.error("Unable to save response time data for location monitor ID {}, monitored service ID {}.", locationMonitorId, serviceId, e);
    }
    try {
        final OnmsLocationSpecificStatus currentStatus = m_locMonDao.getMostRecentStatusChange(locationMonitor, monSvc);
        processStatusChange(currentStatus, newStatus);
    } catch (final Exception e) {
        LOG.error("Unable to save result for location monitor ID {}, monitored service ID {}.", locationMonitorId, serviceId, e);
    }
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) Package(org.opennms.netmgt.config.poller.Package) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 34 with OnmsMonitoredService

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

the class DefaultPollerBackEnd method saveResponseTimeData.

/**
 * <p>saveResponseTimeData</p>
 *
 * @param locationMonitorId a {@link java.lang.String} object.
 * @param monSvc a {@link org.opennms.netmgt.model.OnmsMonitoredService} object.
 * @param responseTime a double.
 * @param pkg a {@link org.opennms.netmgt.config.poller.Package} object.
 */
@Override
public void saveResponseTimeData(final String locationMonitorId, final OnmsMonitoredService monSvc, final double responseTime, final Package pkg) {
    final String svcName = monSvc.getServiceName();
    final Service svc = m_pollerConfig.getServiceInPackage(svcName, pkg);
    String dsName = getServiceParameter(svc, "ds-name");
    if (dsName == null) {
        dsName = PollStatus.PROPERTY_RESPONSE_TIME;
    }
    String rrdBaseName = getServiceParameter(svc, "rrd-base-name");
    if (rrdBaseName == null) {
        rrdBaseName = dsName;
    }
    final String rrdRepository = getServiceParameter(svc, "rrd-repository");
    if (rrdRepository == null) {
        return;
    }
    RrdRepository repository = new RrdRepository();
    repository.setStep(m_pollerConfig.getStep(pkg));
    repository.setHeartBeat(repository.getStep() * HEARTBEAT_STEP_MULTIPLIER);
    repository.setRraList(m_pollerConfig.getRRAList(pkg));
    repository.setRrdBaseDir(new File(rrdRepository));
    DistributedLatencyCollectionResource distributedLatencyResource = new DistributedLatencyCollectionResource(locationMonitorId, InetAddressUtils.toIpAddrString(monSvc.getIpAddress()));
    DistributedLatencyCollectionAttributeType distributedLatencyType = new DistributedLatencyCollectionAttributeType(rrdBaseName, dsName);
    distributedLatencyResource.addAttribute(new DistributedLatencyCollectionAttribute(distributedLatencyResource, distributedLatencyType, responseTime));
    ServiceParameters params = new ServiceParameters(Collections.emptyMap());
    CollectionSetVisitor persister = m_persisterFactory.createPersister(params, repository, false, true, true);
    SingleResourceCollectionSet collectionSet = new SingleResourceCollectionSet(distributedLatencyResource, new Date());
    collectionSet.setStatus(CollectionStatus.SUCCEEDED);
    collectionSet.visit(persister);
}
Also used : SingleResourceCollectionSet(org.opennms.netmgt.collection.support.SingleResourceCollectionSet) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) PolledService(org.opennms.netmgt.poller.remote.PolledService) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Service(org.opennms.netmgt.config.poller.Service) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) File(java.io.File) Date(java.util.Date)

Example 35 with OnmsMonitoredService

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

the class DefaultLocationDataService method getApplicationInfo.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public ApplicationInfo getApplicationInfo(final OnmsApplication app, final StatusDetails status) {
    waitForGeocoding("getApplicationInfo");
    if (app == null) {
        LOG.warn("no application specified");
        return null;
    }
    final Set<GWTMonitoredService> services = new TreeSet<GWTMonitoredService>();
    final Set<String> locationNames = new TreeSet<String>();
    for (final OnmsMonitoredService service : m_monitoredServiceDao.findByApplication(app)) {
        services.add(transformMonitoredService(service));
    }
    for (final OnmsLocationMonitor mon : m_locationDao.findByApplication(app)) {
        locationNames.add(mon.getLocation());
    }
    final ApplicationInfo applicationInfo = new ApplicationInfo(app.getId(), app.getName(), services, locationNames, status);
    LOG.debug("getApplicationInfo({}) returning {}", app.getName(), applicationInfo);
    return applicationInfo;
}
Also used : TreeSet(java.util.TreeSet) ApplicationInfo(org.opennms.features.poller.remote.gwt.client.ApplicationInfo) GWTMonitoredService(org.opennms.features.poller.remote.gwt.client.GWTMonitoredService) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)119 Date (java.util.Date)37 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)33 Test (org.junit.Test)27 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)25 Transactional (org.springframework.transaction.annotation.Transactional)22 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)20 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)18 ArrayList (java.util.ArrayList)17 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)17 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)15 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)15 LinkedList (java.util.LinkedList)13 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)13 HashSet (java.util.HashSet)9 Before (org.junit.Before)6 Criteria (org.opennms.core.criteria.Criteria)5 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)5