use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class AlarmRepositoryIT method testSort.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testSort() {
for (SortStyle style : SortStyle.values()) {
AlarmCriteria sorted = new AlarmCriteria(new Filter[0], style, AcknowledgeType.UNACKNOWLEDGED, 100, 0);
OnmsAlarm[] alarms = m_alarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(sorted));
assertTrue("Failed to sort with style " + style, alarms.length > 0);
}
}
use of org.opennms.netmgt.model.OnmsAlarm 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));
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class OnmsDaoContainerIT method createAlarm.
private OnmsAlarm createAlarm() {
final OnmsAlarm alarm = new OnmsAlarm();
alarm.setDistPoller(m_distPollerDao.whoami());
alarm.setUei(EventConstants.NODE_LOST_SERVICE_EVENT_UEI);
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setNode(m_databasePopulator.getNode1());
alarm.setDescription("This is a test alarm");
alarm.setLogMsg("this is a test alarm log message");
alarm.setCounter(1);
alarm.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
alarm.setSeverity(OnmsSeverity.NORMAL);
m_alarmDao.save(alarm);
m_alarmDao.flush();
return alarm;
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class NCSEdgeStatusProvider method getNCSImpactedAlarms.
private Set<String> getNCSImpactedAlarms() {
org.opennms.core.criteria.Criteria criteria = new org.opennms.core.criteria.Criteria(OnmsAlarm.class);
criteria.addRestriction(new EqRestriction("uei", "uei.opennms.org/internal/ncs/componentImpacted"));
List<OnmsAlarm> alarms = getAlarmDao().findMatching(criteria);
Set<String> alarmsSet = new HashSet<>();
for (OnmsAlarm alarm : alarms) {
final Optional<String> foreignSource = alarm.findEventParameter("foreignSource").map(OnmsEventParameter::getValue);
final Optional<String> foreignId = alarm.findEventParameter("foreignId").map(OnmsEventParameter::getValue);
if (foreignSource.isPresent() && foreignId.isPresent()) {
alarmsSet.add(foreignSource.get() + "::" + foreignId.get());
}
}
return alarmsSet;
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class DefaultTicketerServiceLayer method updateTicketForAlarm.
/*
* (non-Javadoc)
* @see org.opennms.netmgt.ticketd.TicketerServiceLayer#updateTicketForAlarm(int, java.lang.String)
*/
/**
* {@inheritDoc}
*/
@Override
public void updateTicketForAlarm(int alarmId, String ticketId) {
OnmsAlarm alarm = m_alarmDao.get(alarmId);
if (alarm == null) {
LOG.error("No alarm with id {} was found. Ticket with id '{}' will not be updated.", alarmId, ticketId);
return;
}
Ticket ticket = null;
try {
ticket = m_ticketerPlugin.get(ticketId);
if (ticket.getState() == Ticket.State.CANCELLED) {
alarm.setTTicketState(TroubleTicketState.CANCELLED);
} else if (ticket.getState() == Ticket.State.CLOSED) {
alarm.setTTicketState(TroubleTicketState.CLOSED);
} else if (ticket.getState() == Ticket.State.OPEN) {
alarm.setTTicketState(TroubleTicketState.OPEN);
} else {
alarm.setTTicketState(TroubleTicketState.OPEN);
}
} catch (PluginException e) {
alarm.setTTicketState(TroubleTicketState.UPDATE_FAILED);
LOG.error("Unable to update ticket for alarm: {}", e.getMessage());
m_eventIpcManager.sendNow(createEvent(e.getMessage()));
}
m_alarmDao.saveOrUpdate(alarm);
}
Aggregations