use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class JmsNorthbounder method forwardAlarms.
/* (non-Javadoc)
* @see org.opennms.netmgt.alarmd.api.support.AbstractNorthbounder#forwardAlarms(java.util.List)
*/
@Override
public void forwardAlarms(List<NorthboundAlarm> alarms) throws NorthbounderException {
for (final NorthboundAlarm alarm : alarms) {
final Integer count = alarm.getCount();
LOG.debug("Does destination {} take only first occurances? {} Is new alarm? Has count of {}.", m_jmsDestination.getName(), m_jmsDestination.isFirstOccurrenceOnly(), count);
if (count > 1 && m_jmsDestination.isFirstOccurrenceOnly()) {
LOG.debug("Skipping because not new alarm.");
continue;
}
LOG.debug("Attempting to send a message to {} of type {}", m_jmsDestination.getJmsDestination(), m_jmsDestination.getDestinationType());
try {
m_template.send(m_jmsDestination.getJmsDestination(), new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
if (m_jmsDestination.isSendAsObjectMessageEnabled()) {
return session.createObjectMessage(alarm);
} else {
return session.createTextMessage(convertAlarmToText(alarm));
}
}
});
LOG.debug("Sent message");
} catch (JmsException e) {
LOG.error("Unable to send alarm to northbound JMS because {}", e.getLocalizedMessage(), e);
}
}
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class DefaultAlarmProcessor method process.
@Override
public void process(final Exchange exchange) throws Exception {
final NorthboundAlarm alarm = exchange.getIn().getBody(NorthboundAlarm.class);
exchange.getIn().setBody(alarm.toString(), String.class);
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class AMQPAlarmNorthbounderBlueprintTest method canForwardAlarm.
@Test
public void canForwardAlarm() throws Exception {
getMockEndpoint("mock:destination").expectedMessageCount(1);
// Forward a single alarm
OnmsAlarm alarm = new OnmsAlarm();
NorthboundAlarm northboundAlarm = new NorthboundAlarm(alarm);
List<NorthboundAlarm> northboundAlarms = Lists.newArrayList(northboundAlarm);
alarmNorthbounder.forwardAlarms(northboundAlarms);
assertMockEndpointsSatisfied();
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class NCSNorthbounderIT method alarm.
private NorthboundAlarm alarm(int alarmId) {
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "componentType", "Service", "string"), new OnmsEventParameter(event, "componentName", "NAM" + alarmId, "string"), new OnmsEventParameter(event, "componentForeignSource", "FS", "string"), new OnmsEventParameter(event, "componentForeignId", "" + alarmId, "string"), new OnmsEventParameter(event, "cause", "17", "string")));
OnmsAlarm alarm = new OnmsAlarm();
alarm.setId(alarmId);
alarm.setUei("uei.opennms.org/test/httpNorthBounder");
alarm.setLastEvent(event);
alarm.setAlarmType((alarmId + 1) % 2 + 1);
return new NorthboundAlarm(alarm);
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class AbstractNorthbounderTest method testAlarmForwarding.
/**
* Test alarm forwarding.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testAlarmForwarding() throws InterruptedException {
TestNorthbounder tnb = new TestNorthbounder();
tnb.setAccepting(true);
tnb.start();
NorthboundAlarm a = createNorthboundAlarm(1);
tnb.onAlarm(a);
tnb.waitForAcceptsToBeCalled(2000);
tnb.waitForForwardToBeCalled(2000);
assertNotNull(tnb.getAlarms());
assertTrue(tnb.getAlarms().contains(a));
}
Aggregations