use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class RestClient method getEvents.
public List<OnmsEvent> getEvents() {
GenericType<List<OnmsEvent>> events = new GenericType<List<OnmsEvent>>() {
};
final WebTarget target = getTarget().path("events");
return getBuilder(target).get(events);
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class RestClient method getAllEvents.
public List<OnmsEvent> getAllEvents() {
GenericType<List<OnmsEvent>> events = new GenericType<List<OnmsEvent>>() {
};
final WebTarget target = getTarget().path("events").queryParam("limit", 0);
return getBuilder(target).get(events);
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class Poller method scheduleService.
private boolean scheduleService(OnmsMonitoredService service) {
final OnmsIpInterface iface = service.getIpInterface();
final Set<OnmsOutage> outages = service.getCurrentOutages();
final OnmsOutage outage = (outages == null || outages.size() < 1 ? null : outages.iterator().next());
final OnmsEvent event = (outage == null ? null : outage.getServiceLostEvent());
final String ipAddr = InetAddressUtils.str(iface.getIpAddress());
final String serviceName = service.getServiceName();
boolean active = "A".equals(service.getStatus());
final Number svcLostEventId = event == null ? null : event.getId();
final Date ifLostService = outage == null ? null : outage.getIfLostService();
final String svcLostUei = event == null ? null : event.getEventUei();
closeOutageIfSvcLostEventIsMissing(outage);
// We don't want to adjust the management state of the service if we're
// on a machine that uses multiple servers with access to the same database
// so check the value of OpennmsServerConfigFactory.getInstance().verifyServer()
// before doing any updates.
final Package pkg = findPackageForService(ipAddr, serviceName);
final boolean verifyServer = OpennmsServerConfigFactory.getInstance().verifyServer();
if (pkg == null) {
if (active && !verifyServer) {
LOG.warn("Active service {} on {} not configured for any package. Marking as Not Polled.", serviceName, ipAddr);
updateServiceStatus(service, "N");
}
return false;
} else if (!active && !verifyServer) {
LOG.info("Active service {} on {} is now configured for a package. Marking as active.", serviceName, ipAddr);
updateServiceStatus(service, "A");
}
ServiceMonitor monitor = m_pollerConfig.getServiceMonitor(serviceName);
if (monitor == null) {
LOG.info("Could not find service monitor associated with service {}", serviceName);
return false;
}
InetAddress addr;
addr = InetAddressUtils.addr(ipAddr);
if (addr == null) {
LOG.error("Could not convert {} as an InetAddress {}", ipAddr, ipAddr);
return false;
}
PollableService svc = getNetwork().createService(service.getNodeId(), iface.getNode().getLabel(), iface.getNode().getLocation().getLocationName(), addr, serviceName);
PollableServiceConfig pollConfig = new PollableServiceConfig(svc, m_pollerConfig, m_pollOutagesConfig, pkg, getScheduler(), m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
svc.setPollConfig(pollConfig);
synchronized (svc) {
if (svc.getSchedule() == null) {
Schedule schedule = new Schedule(svc, pollConfig, getScheduler());
svc.setSchedule(schedule);
}
}
if (svcLostEventId == null) {
if (svc.getParent().getStatus().isUnknown()) {
svc.updateStatus(PollStatus.up());
} else {
svc.updateStatus(svc.getParent().getStatus());
}
} else {
svc.updateStatus(PollStatus.down());
PollEvent cause = new DbPollEvent(svcLostEventId.intValue(), svcLostUei, ifLostService);
svc.setCause(cause);
}
svc.schedule();
return true;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class InvalidRequisitionDataIT method setUp.
@Before
public void setUp() throws Exception {
// clean out any existing nodes
for (final OnmsNode node : m_nodeDao.findAll()) {
m_nodeDao.delete(node);
}
m_nodeDao.flush();
for (final OnmsEvent event : m_eventDao.findAll()) {
m_eventDao.delete(event);
}
MockLogAppender.setupLogging(true, "DEBUG");
m_eventManager.setSynchronous(true);
m_provisioner.start();
// make sure node scan scheduler is running initially
getScanExecutor().resume();
getScheduledExecutor().resume();
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class BundleContextHistoryManagerTest method initProvidersAndCriteria.
/**
* In this method all starting {@link SearchCriteria} and {@link SearchProvider} objects are initialized
*/
private void initProvidersAndCriteria() {
// Preparing SearchProviders
CategoryProvider vertexProvider = new CategoryProvider() {
@Override
public Collection<OnmsCategory> getAllCategories() {
return Lists.newArrayList(findCategoryByName("somename"));
}
@Override
public OnmsCategory findCategoryByName(String m_categoryName) {
OnmsCategory cat = new OnmsCategory("test", "test");
cat.setId(Integer.valueOf(idCategory));
return cat;
}
@Override
public List<OnmsNode> findNodesForCategory(OnmsCategory category) {
return new ArrayList<>();
}
};
IpInterfaceProvider ipInterfaceProvider = new IpInterfaceProvider() {
@Override
public List<OnmsIpInterface> findMatching(org.opennms.core.criteria.Criteria criteria) {
OnmsNode node = new OnmsNode();
node.setId(Integer.valueOf(idIpLike));
String ipAddr = "127.0.0.1";
OnmsIpInterface ipInterface = new OnmsIpInterface(ipAddr, node);
return Lists.newArrayList(ipInterface);
}
};
AlarmProvider alarmProvider = new AlarmProvider() {
@Override
public List<OnmsAlarm> findMatchingAlarms(org.opennms.core.criteria.Criteria criteria) {
Date eventTime = new Date();
OnmsDistPoller distPoller = new OnmsDistPoller("pollerID");
OnmsEvent event = new OnmsEvent();
OnmsAlarm alarm = new OnmsAlarm(Integer.valueOf(idAlarm), "eventUI", distPoller, 2, 3, eventTime, event);
return Lists.newArrayList(alarm);
}
};
// Creating SearchResults to be used in testing
SearchResult sResultCategory = new SearchResult(CategoryHopCriteria.NAMESPACE, idCategory, labelCategory, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
SearchResult sResultAlarm = new SearchResult(AlarmHopCriteria.NAMESPACE, idAlarm, labelAlarm, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
SearchResult sResultIpLike = new SearchResult(IpLikeHopCriteria.NAMESPACE, idIpLike, labelIpLike, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
this.startingSearchResults.put(CriteriaTypes.alarm, sResultAlarm);
this.startingSearchResults.put(CriteriaTypes.ipLike, sResultIpLike);
this.startingSearchResults.put(CriteriaTypes.category, sResultCategory);
// Initializing available (initial) SearchProviders
final DefaultTopologyService topologyService = new DefaultTopologyService();
topologyService.setServiceLocator(serviceLocatorMock);
this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(topologyService, vertexProvider));
this.startingProviders.put(CriteriaTypes.ipLike, new IpLikeSearchProvider(ipInterfaceProvider));
this.startingProviders.put(CriteriaTypes.alarm, new AlarmSearchProvider(alarmProvider));
// Initializing available (initial) Criteria
this.startingCriteria.put(CriteriaTypes.category, new CategoryHopCriteria(sResultCategory, vertexProvider, graphContainerMock));
this.startingCriteria.put(CriteriaTypes.ipLike, new IpLikeHopCriteria(sResultIpLike, ipInterfaceProvider));
this.startingCriteria.put(CriteriaTypes.alarm, new AlarmHopCriteria(new AlarmSearchProvider(alarmProvider).new AlarmSearchResult(sResultAlarm), alarmProvider));
}
Aggregations