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;
}
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;
}
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);
}
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);
}
}
}
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();
}
Aggregations