Search in sources :

Example 1 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class TicketNotificationStrategyTest method testCreateTicket.

public void testCreateTicket() {
    // Setup the event anticipator
    EventBuilder newSuspectBuilder = new EventBuilder(EventConstants.TROUBLETICKET_CREATE_UEI, m_ticketNotificationStrategy.getName());
    newSuspectBuilder.setParam(EventConstants.PARM_ALARM_ID, "1");
    newSuspectBuilder.setParam(EventConstants.PARM_ALARM_UEI, EventConstants.NODE_DOWN_EVENT_UEI);
    newSuspectBuilder.setParam(EventConstants.PARM_USER, "admin");
    m_eventIpcManager.getEventAnticipator().anticipateEvent(newSuspectBuilder.getEvent());
    m_ticketNotificationStrategy.setAlarmState(new TicketNotificationStrategy.AlarmState(1));
    m_ticketNotificationStrategy.setAlarmType(AlarmType.PROBLEM);
    List<Argument> arguments = buildArguments("1", EventConstants.NODE_DOWN_EVENT_UEI);
    assertEquals(0, m_ticketNotificationStrategy.send(arguments));
    assertTrue("Expected events not forthcoming", m_eventIpcManager.getEventAnticipator().waitForAnticipated(0).isEmpty());
    assertEquals("Received unexpected events", 0, m_eventIpcManager.getEventAnticipator().getUnanticipatedEvents().size());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Argument(org.opennms.netmgt.model.notifd.Argument)

Example 2 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class MicroblogReplyNotificationStrategyTest method configureArgs.

@Override
public List<Argument> configureArgs() {
    List<Argument> arguments = super.configureArgs();
    Argument arg = new Argument("-ublog", null, "jeffg", false);
    arguments.add(arg);
    return arguments;
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument)

Example 3 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class MicroblogReplyNotificationStrategyTest method postNotice.

@Ignore
@Test
@Override
public void postNotice() {
    NotificationStrategy ns = new MicroblogReplyNotificationStrategy(m_daoConfigResource);
    List<Argument> arguments = configureArgs();
    Assert.assertEquals("NotificationStrategy should return 0 on success", 0, ns.send(arguments));
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument) NotificationStrategy(org.opennms.netmgt.model.notifd.NotificationStrategy) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class MicroblogDMNotificationStrategyTest method postNotice.

@Ignore
@Test
@Override
public void postNotice() {
    NotificationStrategy ns = new MicroblogDMNotificationStrategy(m_daoConfigResource);
    List<Argument> arguments = configureArgs();
    Assert.assertEquals("NotificationStrategy should return 0 on success", 0, ns.send(arguments));
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument) NotificationStrategy(org.opennms.netmgt.model.notifd.NotificationStrategy) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class IrcCatNotificationStrategy method buildMessage.

private String buildMessage(List<Argument> arguments) {
    String recipient = null;
    String message = null;
    for (Argument arg : arguments) {
        if (NotificationManager.PARAM_EMAIL.equals(arg.getSwitch())) {
            recipient = arg.getValue();
        } else if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch())) {
            message = arg.getValue();
        } else if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch())) {
            message = arg.getValue();
        } else {
            throw new IllegalArgumentException("Unsupported notification argument switch '" + arg.getSwitch() + "'");
        }
    }
    if (recipient == null) {
        // FIXME We should have a better Exception to use here for configuration problems
        throw new IllegalArgumentException("no recipient specified, but is required");
    }
    if (message == null) {
        // FIXME We should have a better Exception to use here for configuration problems
        throw new IllegalArgumentException("no message specified, but is required");
    }
    return recipient + " " + message;
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument)

Aggregations

Argument (org.opennms.netmgt.model.notifd.Argument)29 ArrayList (java.util.ArrayList)12 NotificationStrategy (org.opennms.netmgt.model.notifd.NotificationStrategy)8 Test (org.junit.Test)7 Ignore (org.junit.Ignore)3 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)3 JSONObject (org.json.simple.JSONObject)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Date (java.util.Date)1 NameValuePair (org.apache.http.NameValuePair)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 JavaMailer (org.opennms.javamail.JavaMailer)1 AsteriskOriginator (org.opennms.netmgt.asterisk.utils.AsteriskOriginator)1 MockNotification (org.opennms.netmgt.mock.MockNotification)1 NotificationAnticipator (org.opennms.netmgt.mock.NotificationAnticipator)1 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)1