Search in sources :

Example 76 with OnmsMonitoredService

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

the class MonitoredServiceDaoIT method testLazy.

@Test
@Transactional
public void testLazy() {
    final List<OnmsMonitoredService> allSvcs = m_monitoredServiceDao.findAll();
    assertTrue(allSvcs.size() > 1);
    final OnmsMonitoredService svc = allSvcs.iterator().next();
    assertEquals(addr("192.168.1.1"), svc.getIpAddress());
    assertEquals(1, svc.getIfIndex().intValue());
    assertEquals(m_databasePopulator.getNode1().getId(), svc.getIpInterface().getNode().getId());
    assertEquals("M", svc.getIpInterface().getIsManaged());
}
Also used : OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with OnmsMonitoredService

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

the class IfServicesRestService method getServices.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public OnmsMonitoredServiceDetailList getServices(@Context final UriInfo uriInfo) {
    final Criteria c = getCriteria(uriInfo.getQueryParameters());
    final OnmsMonitoredServiceDetailList servicesList = new OnmsMonitoredServiceDetailList();
    final List<OnmsMonitoredService> services = m_serviceDao.findMatching(c);
    for (OnmsMonitoredService svc : services) {
        servicesList.add(new OnmsMonitoredServiceDetail(svc));
    }
    c.setLimit(null);
    c.setOffset(null);
    c.setOrders(new ArrayList<Order>());
    servicesList.setTotalCount(m_serviceDao.countMatching(c));
    return servicesList;
}
Also used : OnmsMonitoredServiceDetailList(org.opennms.netmgt.model.OnmsMonitoredServiceDetailList) OnmsMonitoredServiceDetail(org.opennms.netmgt.model.OnmsMonitoredServiceDetail) Order(org.opennms.core.criteria.Order) Criteria(org.opennms.core.criteria.Criteria) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 78 with OnmsMonitoredService

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

the class AgentConfigurationResourceTest method testSimpleFilter.

@Test
public void testSimpleFilter() throws Exception {
    final InetAddress oneNinetyTwo = addr("192.168.0.1");
    final List<InetAddress> addresses = Arrays.asList(oneNinetyTwo);
    m_filterDao.setActiveIPAddressList(addresses);
    final OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setForeignSource("foo");
    node.setForeignId("bar");
    node.setLabel("foo");
    node.setSysObjectId(".1.2.3.4.5");
    final OnmsIpInterface iface = new OnmsIpInterface(oneNinetyTwo, node);
    final OnmsServiceType serviceType = new OnmsServiceType("SNMP");
    final OnmsMonitoredService service = new OnmsMonitoredService(iface, serviceType);
    m_monitoredServiceDao.setMatching(Arrays.asList(service));
    final Response response = m_configResource.getAgentsJson("example1", "SNMP");
    assertEquals(200, response.getStatus());
    final Object entity = response.getEntity();
    assertNotNull(entity);
    assertTrue(entity instanceof List<?>);
    @SuppressWarnings("unchecked") final List<AgentResponse> agentResponses = (List<AgentResponse>) entity;
    System.err.println(agentResponses);
    assertEquals(1, agentResponses.size());
    assertTrue(agentResponses.get(0).getAddress().isPresent());
    assertEquals(oneNinetyTwo, agentResponses.get(0).getAddress().get());
    assertTrue(agentResponses.get(0).getPort().isPresent());
    assertEquals(1161, agentResponses.get(0).getPort().get().intValue());
    assertEquals(".1.2.3.4.5", agentResponses.get(0).getParameters().get("sysObjectId"));
    assertEquals("1", agentResponses.get(0).getParameters().get("nodeId"));
    assertEquals("foo", agentResponses.get(0).getParameters().get("foreignSource"));
    assertEquals("bar", agentResponses.get(0).getParameters().get("foreignId"));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) AgentResponse(org.opennms.netmgt.config.agents.AgentResponse) Response(javax.ws.rs.core.Response) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) List(java.util.List) InetAddress(java.net.InetAddress) AgentResponse(org.opennms.netmgt.config.agents.AgentResponse) Test(org.junit.Test)

Example 79 with OnmsMonitoredService

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

the class DaoWebOutageRepositoryIT method setUp.

@Before
public void setUp() {
    m_dbPopulator.populateDatabase();
    OnmsMonitoredService svc2 = m_dbPopulator.getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.2.1"), "ICMP");
    OnmsEvent event = m_dbPopulator.getEventDao().get(1);
    OnmsOutage unresolved2 = new OnmsOutage(new Date(), event, svc2);
    m_dbPopulator.getOutageDao().save(unresolved2);
    m_dbPopulator.getOutageDao().flush();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

Example 80 with OnmsMonitoredService

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

the class WebOutageRepositoryFilterIT method testRegainedServiceDateAfterFilter.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testRegainedServiceDateAfterFilter() {
    OnmsMonitoredService svc2 = m_dbPopulator.getMonitoredServiceDao().get(m_dbPopulator.getNode2().getId(), InetAddressUtils.addr("192.168.2.1"), "ICMP");
    // This requires every test method to have a new database instance :/
    OnmsEvent event = m_dbPopulator.getEventDao().get(1);
    // Put a resolved outage into the database so that one will match the
    // filter below
    OnmsOutage resolvedToday = new OnmsOutage(new Date(), new Date(), event, event, svc2, null, null);
    m_dbPopulator.getOutageDao().save(resolvedToday);
    m_dbPopulator.getOutageDao().flush();
    RegainedServiceDateAfterFilter filter = new RegainedServiceDateAfterFilter(yesterday());
    OutageCriteria criteria = new OutageCriteria(filter);
    Outage[] outages = m_daoOutageRepo.getMatchingOutages(criteria);
    assertEquals(1, outages.length);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Outage(org.opennms.web.outage.Outage) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

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