Search in sources :

Example 86 with OnmsAlarm

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);
    }
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 87 with OnmsAlarm

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));
}
Also used : CategoryProvider(org.opennms.features.topology.app.internal.CategoryProvider) OnmsNode(org.opennms.netmgt.model.OnmsNode) IpInterfaceProvider(org.opennms.features.topology.app.internal.IpInterfaceProvider) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) SearchResult(org.opennms.features.topology.api.topo.SearchResult) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) Date(java.util.Date) CategorySearchProvider(org.opennms.features.topology.app.internal.CategorySearchProvider) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) AlarmSearchProvider(org.opennms.features.topology.app.internal.AlarmSearchProvider) AlarmProvider(org.opennms.features.topology.app.internal.AlarmProvider) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) IpLikeSearchProvider(org.opennms.features.topology.app.internal.IpLikeSearchProvider)

Example 88 with OnmsAlarm

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;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 89 with OnmsAlarm

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;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Criteria(org.opennms.features.topology.api.topo.Criteria) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) HashSet(java.util.HashSet)

Example 90 with OnmsAlarm

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);
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) PluginException(org.opennms.api.integration.ticketing.PluginException)

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