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);
}
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);
}
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);
}
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));
}
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;
}
Aggregations