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