Search in sources :

Example 26 with OnmsAlarm

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

the class IfTttDaemonTest method addAlarm.

private void addAlarm(Integer id, Integer nodeId, OnmsSeverity onmsSeverity, final boolean acknowledged) {
    final OnmsAlarm onmsAlarm = new OnmsAlarm(id, EventConstants.NODE_LOST_SERVICE_EVENT_UEI, null, null, onmsSeverity.getId(), new Date(), new OnmsEvent()) {

        @Override
        public boolean isAcknowledged() {
            return acknowledged;
        }
    };
    onmsAlarm.setNode(nodeMap.get(nodeId));
    alarmMap.put(id, onmsAlarm);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date)

Example 27 with OnmsAlarm

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

the class DefaultTicketerServiceLayer method closeTicketForAlarm.

/*
     * (non-Javadoc)
     * @see org.opennms.netmgt.ticketd.TicketerServiceLayer#closeTicketForAlarm(int, java.lang.String)
     */
/**
 * {@inheritDoc}
 */
@Override
public void closeTicketForAlarm(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 closed.", alarmId, ticketId);
        return;
    }
    if (SKIP_CLOSE_WHEN_NOT_CLEARED) {
        final OnmsSeverity currentSeverity = alarm.getSeverity();
        if (currentSeverity != null && !currentSeverity.equals(OnmsSeverity.CLEARED)) {
            LOG.info("Alarm with id {} is not currently cleared. Ticket with id '{}' will not be closed.", alarmId, ticketId);
            return;
        }
    }
    try {
        setTicketState(ticketId, State.CLOSED);
        alarm.setTTicketState(TroubleTicketState.CLOSED);
    } catch (PluginException e) {
        alarm.setTTicketState(TroubleTicketState.CLOSE_FAILED);
        LOG.error("Unable to close ticket for alarm: {}", e.getMessage(), e);
        m_eventIpcManager.sendNow(createEvent(e.getMessage()));
    }
    m_alarmDao.saveOrUpdate(alarm);
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 28 with OnmsAlarm

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

the class DefaultTicketerServiceLayer method createTicketForAlarm.

/*
     * (non-Javadoc)
     * @see org.opennms.netmgt.ticketd.TicketerServiceLayer#createTicketForAlarm(int)
     */
/**
 * {@inheritDoc}
 */
@Override
public void createTicketForAlarm(int alarmId, Map<String, String> attributes) {
    OnmsAlarm alarm = m_alarmDao.get(alarmId);
    if (alarm == null) {
        LOG.error("No alarm with id {} was found. No ticket will be created.", alarmId);
        return;
    }
    if (SKIP_CREATE_WHEN_CLEARED) {
        final OnmsSeverity currentSeverity = alarm.getSeverity();
        if (currentSeverity != null && currentSeverity.equals(OnmsSeverity.CLEARED)) {
            LOG.info("Alarm with id {} is currently cleared. No ticket will be created.", alarmId);
            return;
        }
    }
    Ticket ticket = createTicketFromAlarm(alarm, attributes);
    try {
        m_ticketerPlugin.saveOrUpdate(ticket);
        alarm.setTTicketId(ticket.getId());
        alarm.setTTicketState(TroubleTicketState.OPEN);
    } catch (PluginException e) {
        alarm.setTTicketState(TroubleTicketState.CREATE_FAILED);
        LOG.error("Unable to create ticket for alarm: {}", e.getMessage(), e);
        m_eventIpcManager.sendNow(createEvent(e.getMessage()));
    }
    m_alarmDao.saveOrUpdate(alarm);
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 29 with OnmsAlarm

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

the class DefaultNodeStatusCalculatorIT method verifyAlarmStatusCalculation.

@Test
@Transactional
public void verifyAlarmStatusCalculation() {
    final OnmsNode node = databasePopulator.getNode1();
    final NodeStatusCalculatorConfig config = new NodeStatusCalculatorConfig();
    config.setCalculationStrategy(NodeStatusCalculationStrategy.Alarms);
    // No nodeIds
    verifyStatus(6, nodeDao.findAll().stream().collect(Collectors.toMap(n -> n.getId(), n -> OnmsSeverity.NORMAL)), statusCalculator.calculateStatus(config));
    // No alarm exists, status should be normal
    config.setNodeIds(Sets.newHashSet(node.getId()));
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.NORMAL), statusCalculator.calculateStatus(config));
    // Create an alarm and verify status
    OnmsAlarm alarm = createAndPersistAlarm(node, OnmsSeverity.WARNING);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.WARNING), statusCalculator.calculateStatus(config));
    // Create an alarm for same node and verify
    OnmsAlarm alarm2 = createAndPersistAlarm(node, OnmsSeverity.MINOR);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(config));
    // Create an alarm for another node and verify
    createAndPersistAlarm(databasePopulator.getNode2(), OnmsSeverity.CRITICAL);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(config));
    // Acknowledge alarms
    alarm2.setAlarmAckTime(new Date());
    alarm2.setAlarmAckUser("ulf");
    alarmDao.saveOrUpdate(alarm2);
    alarmDao.flush();
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.WARNING), statusCalculator.calculateStatus(config));
    alarm.setAlarmAckTime(new Date());
    alarm.setAlarmAckUser("ulf");
    alarmDao.saveOrUpdate(alarm);
    alarmDao.flush();
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.NORMAL), statusCalculator.calculateStatus(config));
    // Include acknowledged alarms
    config.setIncludeAcknowledgedAlarms(true);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(config));
    // Apply severity filter
    config.setSeverity(OnmsSeverity.WARNING);
    verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(config));
    config.setSeverity(OnmsSeverity.MINOR);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(config));
    config.setSeverity(OnmsSeverity.MAJOR);
    verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(config));
    // reset severity filter and apply location filter
    config.setSeverity(null);
    config.setLocation(distPollerDao.whoami().getLocation());
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(config));
    config.setLocation("XXX");
    verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(config));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with OnmsAlarm

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

the class TestUtils method createAlarm.

static OnmsAlarm createAlarm(OnmsNode node, OnmsSeverity severity, OnmsDistPoller distpoller) {
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setUei(EventConstants.NODE_DOWN_EVENT_UEI);
    alarm.setDistPoller(distpoller);
    alarm.setCounter(1);
    alarm.setSeverity(severity);
    alarm.setNode(node);
    return alarm;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

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