Search in sources :

Example 41 with OnmsMonitoredService

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

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

the class OutageDaoIT method getMonitoredService.

private OnmsMonitoredService getMonitoredService(OnmsIpInterface ipInterface, OnmsServiceType serviceType) {
    final OnmsCriteria criteria = new OnmsCriteria(OnmsMonitoredService.class).add(Restrictions.eq("ipInterface", ipInterface)).add(Restrictions.eq("serviceType", serviceType));
    final List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(criteria);
    OnmsMonitoredService monitoredService;
    if (services.size() > 0) {
        monitoredService = services.get(0);
    } else {
        monitoredService = new OnmsMonitoredService(ipInterface, serviceType);
    }
    m_monitoredServiceDao.save(monitoredService);
    return monitoredService;
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 43 with OnmsMonitoredService

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

the class CollectdIntegrationTest method createGetPackagesExpectation.

private void createGetPackagesExpectation(OnmsMonitoredService svc) {
    String rule = "ipaddr = '" + str(svc.getIpAddress()) + "'";
    //EasyMock.expect(m_filterDao.getActiveIPAddressList(rule)).andReturn(Collections.singletonList(svc.getIpAddress()));
    final Package pkg = new Package();
    pkg.setName("testPackage");
    Filter filter = new Filter();
    filter.setContent(rule);
    pkg.setFilter(filter);
    final Service collector = new Service();
    collector.setName("SNMP");
    collector.setStatus("on");
    collector.setInterval(3000l);
    Parameter parm = new Parameter();
    parm.setKey(TEST_KEY_PARM_NAME);
    parm.setValue(m_key);
    collector.setParameters(Collections.singletonList(parm));
    pkg.addService(collector);
    EasyMock.expect(m_collectdConfiguration.getPackages()).andReturn(Collections.singletonList(pkg));
    EasyMock.expect(m_collectdConfigFactory.interfaceInPackage(anyObject(OnmsIpInterface.class), eq(pkg))).andReturn(true);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Filter(org.opennms.netmgt.config.collectd.Filter) Service(org.opennms.netmgt.config.collectd.Service) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Parameter(org.opennms.netmgt.config.collectd.Parameter) Package(org.opennms.netmgt.config.collectd.Package)

Example 44 with OnmsMonitoredService

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

the class ApplicationTopologyProvider method load.

private void load() {
    resetContainer();
    for (OnmsApplication application : applicationDao.findAll()) {
        ApplicationVertex applicationVertex = new ApplicationVertex(application);
        addVertices(applicationVertex);
        for (OnmsMonitoredService eachMonitoredService : application.getMonitoredServices()) {
            final ApplicationVertex serviceVertex = new ApplicationVertex(eachMonitoredService);
            applicationVertex.addChildren(serviceVertex);
            addVertices(serviceVertex);
            // connect with application
            String id = String.format("connection:%s:%s", applicationVertex.getId(), serviceVertex.getId());
            Edge edge = new AbstractEdge(getNamespace(), id, applicationVertex, serviceVertex);
            addEdges(edge);
        }
    }
}
Also used : AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) Edge(org.opennms.features.topology.api.topo.Edge) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 45 with OnmsMonitoredService

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

the class IfServicesRestService method updateServices.

@PUT
public Response updateServices(@Context final UriInfo uriInfo, final MultivaluedMapImpl params) {
    final String status = params.getFirst("status");
    if (status == null || !status.matches("(A|R|S|F)")) {
        throw getException(Status.BAD_REQUEST, "Parameter status must be specified. Possible values: A (Managed), F (Forced Unmanaged), R (Rescan to Resume), S (Rescan to Suspend)");
    }
    final String services_csv = params.getFirst("services");
    final List<String> serviceList = new ArrayList<String>();
    if (services_csv != null) {
        for (String s : services_csv.split(",")) {
            serviceList.add(s);
        }
    }
    final Criteria c = getCriteria(uriInfo.getQueryParameters());
    c.setLimit(null);
    c.setOffset(null);
    final OnmsMonitoredServiceList services = new OnmsMonitoredServiceList(m_serviceDao.findMatching(c));
    if (services.isEmpty()) {
        throw getException(Status.BAD_REQUEST, "Can't find any service matching the provided criteria: {}.", uriInfo.getQueryParameters().toString());
    }
    boolean modified = false;
    for (OnmsMonitoredService svc : services) {
        boolean proceed = false;
        if (serviceList.isEmpty()) {
            proceed = true;
        } else {
            if (serviceList.contains(svc.getServiceName())) {
                proceed = true;
            }
        }
        if (proceed) {
            modified = true;
            final String currentStatus = svc.getStatus();
            svc.setStatus(status);
            m_serviceDao.update(svc);
            if ("S".equals(status) || ("A".equals(currentStatus) && "F".equals(status))) {
                LOG.debug("updateServices: suspending polling for service {} on node with IP {}", svc.getServiceName(), svc.getIpAddress().getHostAddress());
                // TODO ManageNodeServlet is sending this.
                sendEvent(EventConstants.SERVICE_UNMANAGED_EVENT_UEI, svc);
                sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, svc);
            }
            if ("R".equals(status) || ("F".equals(currentStatus) && "A".equals(status))) {
                LOG.debug("updateServices: resuming polling for service {} on node with IP {}", svc.getServiceName(), svc.getIpAddress().getHostAddress());
                sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, svc);
            }
        }
    }
    return modified ? Response.noContent().build() : Response.notModified().build();
}
Also used : ArrayList(java.util.ArrayList) OnmsMonitoredServiceList(org.opennms.netmgt.model.OnmsMonitoredServiceList) Criteria(org.opennms.core.criteria.Criteria) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) PUT(javax.ws.rs.PUT)

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