Search in sources :

Example 1 with NorthboundAlarm

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);
        }
    }
}
Also used : Message(javax.jms.Message) JmsException(org.springframework.jms.JmsException) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 2 with NorthboundAlarm

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);
}
Also used : NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm)

Example 3 with NorthboundAlarm

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();
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 4 with NorthboundAlarm

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

Example 5 with NorthboundAlarm

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));
}
Also used : NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) Test(org.junit.Test)

Aggregations

NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)30 Test (org.junit.Test)19 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)18 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)13 OnmsNode (org.opennms.netmgt.model.OnmsNode)13 InetAddress (java.net.InetAddress)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)12 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)9 LinkedList (java.util.LinkedList)6 Message (javax.jms.Message)5 ByteArrayResource (org.springframework.core.io.ByteArrayResource)5 Resource (org.springframework.core.io.Resource)5 Date (java.util.Date)4 ObjectMessage (javax.jms.ObjectMessage)4 TextMessage (javax.jms.TextMessage)4 JmsDestination (org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination)4 JmsNorthbounder (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounder)4 JmsNorthbounderConfig (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig)4 JmsNorthbounderConfigDao (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao)4