Search in sources :

Example 16 with OnmsMonitoredService

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

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

the class OnmsMonitoredServiceResource method updateService.

/**
     * <p>updateService</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @param ipAddress a {@link java.lang.String} object.
     * @param serviceName a {@link java.lang.String} object.
     * @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{service}")
public Response updateService(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress, @PathParam("service") String serviceName, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null)
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
        if (intf == null)
            throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
        OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
        if (service == null)
            throw getException(Status.BAD_REQUEST, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
        LOG.debug("updateService: updating service {}", service);
        boolean modified = false;
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(service);
        for (String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                String stringValue = params.getFirst(key);
                Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                if (key.equals("status")) {
                    if ("S".equals(value) || ("A".equals(service.getStatus()) && "F".equals(value))) {
                        LOG.debug("updateService: suspending polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
                        value = "F";
                        sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, service);
                    }
                    if ("R".equals(value) || ("F".equals(service.getStatus()) && "A".equals(value))) {
                        LOG.debug("updateService: resuming polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
                        value = "A";
                        sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, service);
                    }
                }
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            LOG.debug("updateSservice: service {} updated", service);
            m_serviceDao.saveOrUpdate(service);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 18 with OnmsMonitoredService

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

the class OnmsMonitoredServiceResource method deleteService.

/**
     * <p>deleteService</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @param ipAddress a {@link java.lang.String} object.
     * @param serviceName a {@link java.lang.String} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("{service}")
public Response deleteService(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, @PathParam("service") final String serviceName) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null)
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
        if (intf == null)
            throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
        OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
        if (service == null)
            throw getException(Status.CONFLICT, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
        LOG.debug("deleteService: deleting service {} from node {}", serviceName, nodeCriteria);
        Event e = EventUtils.createDeleteServiceEvent("OpenNMS.REST", node.getId(), ipAddress, serviceName, -1L);
        sendEvent(e);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Event(org.opennms.netmgt.xml.event.Event) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 19 with OnmsMonitoredService

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

the class DemandPollServiceTest method testPollMonitoredService.

public void testPollMonitoredService() throws EventProxyException {
    final int expectedResultId = m_pollStore.getExpectedId();
    // anticipate a call to the dao save with a pollResult
    m_demandPollDao.save(isA(DemandPoll.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            DemandPoll poll = (DemandPoll) getCurrentArguments()[0];
            m_pollStore.save(poll);
            return null;
        }
    });
    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);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    expect(m_monitoredServiceDao.get(1, addr("192.168.1.1"), 1, 3)).andReturn(monSvc);
    m_pollerService.poll(monSvc, expectedResultId);
    replay(m_demandPollDao);
    replay(m_monitoredServiceDao);
    replay(m_pollerService);
    DemandPoll result = m_demandPollService.pollMonitoredService(1, addr("192.168.1.1"), 1, 3);
    verify(m_demandPollDao);
    verify(m_monitoredServiceDao);
    verify(m_pollerService);
    assertNotNull("Null is an invalid response from pollMonitoredService", result);
    assertEquals("Expected Id to be set by dao", expectedResultId, result.getId().intValue());
}
Also used : DemandPoll(org.opennms.netmgt.model.DemandPoll) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 20 with OnmsMonitoredService

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

the class DefaultCategoryStatusServiceTest method testGetCategoriesStatus.

public void testGetCategoriesStatus() {
    View view = new View();
    Section section = new Section();
    section.setSectionName("Section One");
    section.addCategory("Category One");
    OnmsOutage outage = new OnmsOutage();
    Collection<OnmsOutage> outages = new ArrayList<OnmsOutage>();
    outage.setId(300);
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("superLabel");
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    //iface.setId(9);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    outage.setMonitoredService(monSvc);
    outages.add(outage);
    view.addSection(section);
    List<String> services = new ArrayList<String>();
    services.add("HTTP");
    //		ServiceSelector selector = new ServiceSelector("isHTTP",(List<String>) services);
    expect(viewDisplayDao.getView()).andReturn(view);
    expect(categoryDao.getCategoryByLabel("Category One")).andReturn(createCategoryFromLabel("Category One"));
    expect(outageDao.matchingCurrentOutages(isA(ServiceSelector.class))).andReturn(outages);
    replay(categoryDao);
    replay(viewDisplayDao);
    replay(outageDao);
    Collection<StatusSection> statusSections = categoryStatusService.getCategoriesStatus();
    verify(viewDisplayDao);
    verify(categoryDao);
    verify(outageDao);
    assertEquals("Wrong Number of StatusSections", view.getSections().size(), statusSections.size());
    for (StatusSection statusSection : statusSections) {
        assertEquals("StatusSection Name Does Not Match", "Section One", statusSection.getName());
        Collection<StatusCategory> statusCategorys = statusSection.getCategories();
        for (StatusCategory statusCategory : statusCategorys) {
            assertEquals("StatusCategoryName does not match", "Category One", statusCategory.getLabel());
            //assertEquals("Category Comment Does not match","Category One Comment",statusCategory.getComment());				
            assertTrue("Nodes >= 1", statusCategory.getNodes().size() >= 1);
            for (StatusNode statusNode : statusCategory.getNodes()) {
                assertEquals("Label does not match", "superLabel", statusNode.getLabel());
            }
        }
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) StatusNode(org.opennms.web.svclayer.catstatus.model.StatusNode) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) ArrayList(java.util.ArrayList) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) View(org.opennms.netmgt.config.viewsdisplay.View) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) Section(org.opennms.netmgt.config.viewsdisplay.Section) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) StatusCategory(org.opennms.web.svclayer.catstatus.model.StatusCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType)

Aggregations

OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)116 Date (java.util.Date)35 OnmsNode (org.opennms.netmgt.model.OnmsNode)35 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)33 Test (org.junit.Test)26 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)23 Transactional (org.springframework.transaction.annotation.Transactional)21 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)16 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)12 HashSet (java.util.HashSet)8 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