use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation 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.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class WebEventRepositoryFilterIT method setUp.
@Before
public void setUp() {
m_dbPopulator.populateDatabase();
final OnmsNode node2 = m_dbPopulator.getNode2();
final OnmsMonitoringLocation location = m_monitoringLocationDao.get("RDU");
node2.setLocation(location);
m_nodeDao.saveOrUpdate(node2);
m_nodeDao.flush();
final OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
event.setAlarm(m_dbPopulator.getAlarmDao().get(1));
event.setNode(node2);
event.setEventUei("uei.opennms.org/test2");
event.setEventTime(new Date());
event.setEventSource("test");
event.setEventCreateTime(new Date());
event.setEventSeverity(OnmsSeverity.CLEARED.getId());
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setIfIndex(11);
event.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
event.setEventLogMsg("This is a test log message");
event.setEventDescr("This is a test event");
event.setServiceType(m_dbPopulator.getServiceTypeDao().get(1));
m_dbPopulator.getEventDao().save(event);
m_dbPopulator.getEventDao().flush();
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class PollerRpcTimeoutIT method setUp.
@Before
public void setUp() throws Exception {
MockUtil.println("------------ Begin Test --------------------------");
MockLogAppender.setupLogging();
m_network = new MockNetwork();
m_network.setCriticalService("ICMP");
m_network.addNode(1, "Router");
m_network.addInterface(str(InetAddressUtils.UNPINGABLE_ADDRESS));
m_network.addService("ICMP");
m_network.addService("HTTP");
m_db.populate(m_network);
DataSourceFactory.setInstance(m_db);
// Add a location that no systems are monitoring
OnmsMonitoringLocation location = new OnmsMonitoringLocation(NONEXISTENT_LOCATION, "Nullsville");
m_monitoringLocationDao.save(location);
// Update all of the nodes to have the nonexistent location
for (OnmsNode node : m_nodeDao.findAll()) {
node.setLocation(location);
m_nodeDao.save(node);
}
InputStream is = new FileInputStream(new File("src/test/resources/etc/rpctimeout-poller-configuration.xml"));
PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
PollerConfigFactory.setInstance(factory);
IOUtils.closeQuietly(is);
// Sanity check the config
ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("HTTP");
Assert.assertNotNull(monitor);
Package pkg = PollerConfigFactory.getInstance().getPackage("PollerRpcTimeoutIT");
Assert.assertNotNull(pkg);
Service svc = pkg.getServices().iterator().next();
Assert.assertEquals("HTTP", svc.getName());
DefaultPollContext pollContext = new DefaultPollContext();
pollContext.setEventManager(m_eventMgr);
pollContext.setLocalHostName("localhost");
pollContext.setName("Test.DefaultPollContext");
pollContext.setPollerConfig(factory);
pollContext.setQueryManager(m_queryManager);
pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
PollableNetwork network = new PollableNetwork(pollContext);
m_poller = new Poller();
m_poller.setMonitoredServiceDao(m_monitoredServiceDao);
m_poller.setOutageDao(m_outageDao);
m_poller.setTransactionTemplate(m_transactionTemplate);
m_poller.setEventIpcManager(m_eventMgr);
m_poller.setNetwork(network);
m_poller.setQueryManager(m_queryManager);
m_poller.setPollerConfig(factory);
m_poller.setPollOutagesConfig(m_pollOutagesConfig);
m_poller.setLocationAwarePollerClient(m_locationAwarePollerClient);
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class CollectionConfigurationResource method getCollectdConfigurationForLocation.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public Response getCollectdConfigurationForLocation(@PathParam("location") final String location) throws ConfigurationResourceException {
final OnmsMonitoringLocation def = m_monitoringLocationDao.get(location);
if (def == null) {
LOG.warn("Unable to find monitoring location {}", location);
return Response.status(Response.Status.NOT_FOUND).build();
}
final List<String> collectionPackageNames = def.getCollectionPackageNames();
if (collectionPackageNames != null && collectionPackageNames.size() > 0) {
final CollectdConfiguration collectdConfig = m_collectdConfigResource.get().getCollectdConfigurationForPackages(collectionPackageNames);
return Response.ok(collectdConfig).build();
}
LOG.warn("Monitoring location {} does not have a collection package defined.", location);
return Response.status(Response.Status.NOT_FOUND).build();
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class RemotePollerAvailabilityService method getAvailabilityByLocation.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("availability/{location}")
public OnmsLocationAvailDefinitionList getAvailabilityByLocation(@Context final UriInfo uriInfo, @PathParam("location") String location) {
final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
OnmsMonitoringLocation locationDefinition = m_monitoringLocationDao.get(location);
if (locationDefinition == null) {
throw getException(Status.BAD_REQUEST, "Cannot find location definition: {}", location);
}
Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByLocationDefinition(locationDefinition);
OnmsLocationAvailDefinitionList availList = getAvailabilityList(createTimeChunker(queryParameters), getSortedApplications(), monitors, null);
return availList;
}
Aggregations