Search in sources :

Example 1 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AlarmSearchProvider method findAlarms.

private List<OnmsAlarm> findAlarms(final List<SearchResult> results, final String queryString) {
    CriteriaBuilder bldr = new CriteriaBuilder(OnmsAlarm.class);
    OnmsSeverity severity = OnmsSeverity.get(queryString);
    List<OnmsAlarm> alarms;
    if (!OnmsSeverity.INDETERMINATE.equals(severity)) {
        bldr = new CriteriaBuilder(OnmsAlarm.class);
        bldr.eq("severity", severity);
        alarms = alarmProvider.findMatchingAlarms(bldr.toCriteria());
        if (alarms.size() > 0) {
            AlarmSearchResult result = new AlarmSearchResult(queryString);
            result.setSeverityQuery(true);
            results.add(result);
        }
    } else {
        bldr.isNotNull("node").ilike("uei", "%" + queryString + "%").orderBy("node");
        alarms = alarmProvider.findMatchingAlarms(bldr.toCriteria());
    }
    return alarms;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 2 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AlarmSearchProvider method buildResults.

private Set<AlarmSearchResult> buildResults(final String queryString, List<OnmsAlarm> alarms) {
    Set<AlarmSearchResult> queryResults = new HashSet<>();
    LOG.debug("SearchProvider.query: creating alarm results set.");
    for (OnmsAlarm alarm : alarms) {
        String nodeLabel = alarm.getNodeLabel();
        LOG.debug("SearchProvider.query: adding '{}' to set of results.", nodeLabel);
        AlarmSearchResult result = new AlarmSearchResult(alarm.getId(), alarm.getNodeLabel(), queryString, !SearchResult.COLLAPSED);
        queryResults.add(result);
    }
    return queryResults;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) HashSet(java.util.HashSet)

Example 3 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AlarmFilterController method createListModelAndView.

private ModelAndView createListModelAndView(HttpServletRequest request, List<Filter> filterList, AcknowledgeType ackType) {
    final AlarmQueryParms parms = createAlarmQueryParms(request, filterList, ackType);
    AlarmCriteria queryCriteria = new AlarmCriteria(parms);
    AlarmCriteria countCriteria = new AlarmCriteria(filterList, ackType);
    final OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(AlarmUtil.getOnmsCriteria(queryCriteria));
    final long alarmCount = m_webAlarmRepository.countMatchingAlarms(AlarmUtil.getOnmsCriteria(countCriteria));
    final ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("alarms", alarms);
    modelAndView.addObject("alarmCount", alarmCount);
    modelAndView.addObject("parms", new NormalizedQueryParameters(parms));
    modelAndView.addObject("callback", getFilterCallback());
    modelAndView.addObject("favorites", favoriteService.getFavorites(request.getRemoteUser(), OnmsFilterFavorite.Page.ALARM).toArray());
    return modelAndView;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmQueryParms(org.opennms.web.alarm.AlarmQueryParms) ModelAndView(org.springframework.web.servlet.ModelAndView) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) NormalizedQueryParameters(org.opennms.web.filter.NormalizedQueryParameters)

Example 4 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class DroolsTicketerServiceLayerTest method setUp.

@Before
public void setUp() throws Exception {
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    MockLogAppender.setupLogging();
    ResourceLoader loader = new DefaultResourceLoader();
    Resource resource = loader.getResource("classpath:/drools-ticketer-rules.drl");
    m_easyMockUtils = new EasyMockUtils();
    m_configDao = m_easyMockUtils.createMock(DroolsTicketerConfigDao.class);
    EasyMock.expect(m_configDao.getRulesFile()).andReturn(resource.getFile()).times(1);
    EasyMock.replay(m_configDao);
    m_alarmDao = m_easyMockUtils.createMock(AlarmDao.class);
    m_ticketerPlugin = m_easyMockUtils.createMock(Plugin.class);
    m_droolsTicketerServiceLayer = new DroolsTicketerServiceLayer(m_configDao);
    m_droolsTicketerServiceLayer.setAlarmDao(m_alarmDao);
    m_droolsTicketerServiceLayer.setTicketerPlugin(m_ticketerPlugin);
    EasyMock.reset(m_configDao);
    m_alarm = new OnmsAlarm();
    m_alarm.setId(1);
    m_alarm.setLogMsg("Test Logmsg");
    m_alarm.setDescription("Test Description");
    m_alarm.setUei("uei.opennms.org/nodes/nodeDown");
    m_ticket = new Ticket();
    m_ticket.setId("4");
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Ticket(org.opennms.api.integration.ticketing.Ticket) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Resource(org.springframework.core.io.Resource) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Plugin(org.opennms.api.integration.ticketing.Plugin) Before(org.junit.Before)

Example 5 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class DefaultTicketerServiceLayerIT method testWire.

@Test
public void testWire() {
    assertNotNull(m_ticketerServiceLayer);
    assertNotNull(m_ticketerPlugin);
    OnmsAlarm alarm = m_alarmDao.findAll().get(0);
    assertNull(alarm.getTTicketState());
    assertNull(alarm.getTTicketId());
    final int alarmId = alarm.getId();
    m_ticketerServiceLayer.createTicketForAlarm(alarmId, new HashMap<String, String>());
    m_alarmDao.flush();
    alarm = m_alarmDao.get(alarmId);
    assertEquals(TroubleTicketState.OPEN, alarm.getTTicketState());
    assertNotNull(alarm.getTTicketId());
    assertEquals("testId", alarm.getTTicketId());
    m_ticketerServiceLayer.updateTicketForAlarm(alarm.getId(), alarm.getTTicketId());
    m_alarmDao.flush();
    alarm = m_alarmDao.get(alarmId);
    assertEquals(TroubleTicketState.OPEN, alarm.getTTicketState());
    alarm.setSeverity(OnmsSeverity.CLEARED);
    m_alarmDao.update(alarm);
    m_ticketerServiceLayer.closeTicketForAlarm(alarmId, alarm.getTTicketId());
    m_alarmDao.flush();
    alarm = m_alarmDao.get(alarmId);
    assertEquals(TroubleTicketState.CLOSED, alarm.getTTicketState());
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test)

Aggregations

OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)143 Test (org.junit.Test)58 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)41 Date (java.util.Date)36 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 Transactional (org.springframework.transaction.annotation.Transactional)35 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)19 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)18 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)18 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)17 ArrayList (java.util.ArrayList)14 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)14 InetAddress (java.net.InetAddress)13 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)11 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)10 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)9 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)9 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)8 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)8 LinkedList (java.util.LinkedList)7