Search in sources :

Example 6 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class DaoWebOutageRepositoryIT method createNodeEventAndOutage.

protected void createNodeEventAndOutage(String location, String label, String ip, String svc) {
    OnmsMonitoringLocation onmsMonitoringLocation = m_dbPopulator.getMonitoringLocationDao().get(location);
    if (onmsMonitoringLocation == null) {
        onmsMonitoringLocation = new OnmsMonitoringLocation();
        onmsMonitoringLocation.setLocationName(location);
        onmsMonitoringLocation.setLatitude(1.0f);
        onmsMonitoringLocation.setLongitude(1.0f);
        onmsMonitoringLocation.setMonitoringArea(location);
        onmsMonitoringLocation.setPriority(1L);
        m_dbPopulator.getMonitoringLocationDao().save(onmsMonitoringLocation);
    }
    List<OnmsNode> nodes = m_dbPopulator.getNodeDao().findByLabel(label);
    OnmsNode node = (nodes.size() == 1 ? nodes.get(0) : null);
    if (node == null) {
        node = new OnmsNode(m_dbPopulator.getMonitoringLocationDao().get(location), label);
        node.setForeignSource(location);
        node.setForeignId(label);
        m_dbPopulator.getNodeDao().save(node);
    }
    int nodeId = m_dbPopulator.getNodeDao().findByForeignId(location, label).getId();
    OnmsIpInterface ipInterface = m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip);
    if (ipInterface == null) {
        ipInterface = new OnmsIpInterface(addr(ip), node);
    }
    OnmsMonitoredService monitoredService = ipInterface.getMonitoredServiceByServiceType(svc);
    if (monitoredService == null) {
        monitoredService = new OnmsMonitoredService(m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip), m_dbPopulator.getServiceTypeDao().findByName(svc));
        m_dbPopulator.getMonitoredServiceDao().save(monitoredService);
    }
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
    event.setEventUei("uei.opennms.org/" + location + "/" + label);
    event.setEventTime(new Date());
    event.setEventSource(location + "/" + label);
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.CLEARED.getId());
    event.setEventLog("Y");
    event.setEventDisplay("N");
    m_dbPopulator.getEventDao().save(event);
    m_dbPopulator.getEventDao().flush();
    OnmsOutage outage = new OnmsOutage(new Date(), event, monitoredService);
    outage.setServiceLostEvent(event);
    m_dbPopulator.getOutageDao().save(outage);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 7 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class WebEventRepositoryFilterIT method setUp.

@Before
public void setUp() {
    m_dbPopulator.populateDatabase();
    final OnmsNode node2 = m_dbPopulator.getNode2();
    final OnmsMonitoringLocation location = m_monitoringLocationDao.get("RDU");
    node2.setLocation(location);
    m_nodeDao.saveOrUpdate(node2);
    m_nodeDao.flush();
    final OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
    event.setAlarm(m_dbPopulator.getAlarmDao().get(1));
    event.setNode(node2);
    event.setEventUei("uei.opennms.org/test2");
    event.setEventTime(new Date());
    event.setEventSource("test");
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.CLEARED.getId());
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setIfIndex(11);
    event.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
    event.setEventLogMsg("This is a test log message");
    event.setEventDescr("This is a test event");
    event.setServiceType(m_dbPopulator.getServiceTypeDao().get(1));
    m_dbPopulator.getEventDao().save(event);
    m_dbPopulator.getEventDao().flush();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Example 8 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class PollerRpcTimeoutIT method setUp.

@Before
public void setUp() throws Exception {
    MockUtil.println("------------ Begin Test  --------------------------");
    MockLogAppender.setupLogging();
    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface(str(InetAddressUtils.UNPINGABLE_ADDRESS));
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    // Add a location that no systems are monitoring
    OnmsMonitoringLocation location = new OnmsMonitoringLocation(NONEXISTENT_LOCATION, "Nullsville");
    m_monitoringLocationDao.save(location);
    // Update all of the nodes to have the nonexistent location
    for (OnmsNode node : m_nodeDao.findAll()) {
        node.setLocation(location);
        m_nodeDao.save(node);
    }
    InputStream is = new FileInputStream(new File("src/test/resources/etc/rpctimeout-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    // Sanity check the config
    ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("HTTP");
    Assert.assertNotNull(monitor);
    Package pkg = PollerConfigFactory.getInstance().getPackage("PollerRpcTimeoutIT");
    Assert.assertNotNull(pkg);
    Service svc = pkg.getServices().iterator().next();
    Assert.assertEquals("HTTP", svc.getName());
    DefaultPollContext pollContext = new DefaultPollContext();
    pollContext.setEventManager(m_eventMgr);
    pollContext.setLocalHostName("localhost");
    pollContext.setName("Test.DefaultPollContext");
    pollContext.setPollerConfig(factory);
    pollContext.setQueryManager(m_queryManager);
    pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
    PollableNetwork network = new PollableNetwork(pollContext);
    m_poller = new Poller();
    m_poller.setMonitoredServiceDao(m_monitoredServiceDao);
    m_poller.setOutageDao(m_outageDao);
    m_poller.setTransactionTemplate(m_transactionTemplate);
    m_poller.setEventIpcManager(m_eventMgr);
    m_poller.setNetwork(network);
    m_poller.setQueryManager(m_queryManager);
    m_poller.setPollerConfig(factory);
    m_poller.setPollOutagesConfig(m_pollOutagesConfig);
    m_poller.setLocationAwarePollerClient(m_locationAwarePollerClient);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Service(org.opennms.netmgt.config.poller.Service) FileInputStream(java.io.FileInputStream) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) MockNetwork(org.opennms.netmgt.mock.MockNetwork) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) PollableNetwork(org.opennms.netmgt.poller.pollables.PollableNetwork) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Example 9 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class CollectionConfigurationResource method getCollectdConfigurationForLocation.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public Response getCollectdConfigurationForLocation(@PathParam("location") final String location) throws ConfigurationResourceException {
    final OnmsMonitoringLocation def = m_monitoringLocationDao.get(location);
    if (def == null) {
        LOG.warn("Unable to find monitoring location {}", location);
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    final List<String> collectionPackageNames = def.getCollectionPackageNames();
    if (collectionPackageNames != null && collectionPackageNames.size() > 0) {
        final CollectdConfiguration collectdConfig = m_collectdConfigResource.get().getCollectdConfigurationForPackages(collectionPackageNames);
        return Response.ok(collectdConfig).build();
    }
    LOG.warn("Monitoring location {} does not have a collection package defined.", location);
    return Response.status(Response.Status.NOT_FOUND).build();
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class RemotePollerAvailabilityService method getAvailabilityByLocation.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("availability/{location}")
public OnmsLocationAvailDefinitionList getAvailabilityByLocation(@Context final UriInfo uriInfo, @PathParam("location") String location) {
    final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
    OnmsMonitoringLocation locationDefinition = m_monitoringLocationDao.get(location);
    if (locationDefinition == null) {
        throw getException(Status.BAD_REQUEST, "Cannot find location definition: {}", location);
    }
    Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByLocationDefinition(locationDefinition);
    OnmsLocationAvailDefinitionList availList = getAvailabilityList(createTimeChunker(queryParameters), getSortedApplications(), monitors, null);
    return availList;
}
Also used : OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsLocationAvailDefinitionList(org.opennms.netmgt.model.OnmsLocationAvailDefinitionList) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)52 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)18 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)16 OnmsNode (org.opennms.netmgt.model.OnmsNode)15 ArrayList (java.util.ArrayList)13 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)12 Date (java.util.Date)11 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)9 Transactional (org.springframework.transaction.annotation.Transactional)9 LinkedList (java.util.LinkedList)8 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)8 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)7 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 Before (org.junit.Before)4 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)4 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)4 InetAddress (java.net.InetAddress)3 LinkedHashMap (java.util.LinkedHashMap)3