Search in sources :

Example 16 with OnmsEventParameter

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

the class AlarmMapperTest method canMapAlarm.

@Test
public void canMapAlarm() throws IOException {
    Event eventConf = new Event();
    eventConf.setUei("uei.opennms.org/nodes/interfaceDown");
    eventConf.setEventLabel("OpenNMS-defined node event: interfaceDown");
    eventConfDao.addEvent(eventConf);
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setId(34);
    alarm.setUei("uei.opennms.org/nodes/interfaceDown");
    OnmsMonitoringSystem monitoringSystem = new OnmsMonitoringSystem();
    monitoringSystem.setLocation("Default");
    alarm.setDistPoller(monitoringSystem);
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("n1");
    alarm.setNode(node);
    alarm.setIpAddr(InetAddress.getByName("10.8.0.30"));
    alarm.setReductionKey("uei.opennms.org/nodes/interfaceDown::1:10.8.0.30");
    alarm.setAlarmType(1);
    alarm.setCounter(1);
    alarm.setSeverity(OnmsSeverity.MINOR);
    alarm.setFirstEventTime(new Date(1503412443118L));
    alarm.setDescription("All services are down on interface 10.8.0.30.");
    alarm.setLogMsg("Interface 10.8.0.30 is down.");
    alarm.setSuppressedUntil(new Date(1503412443118L));
    alarm.setSuppressedTime(new Date(1503412443118L));
    alarm.setLastEventTime(new Date(1503412443118L));
    alarm.setX733ProbableCause(0);
    OnmsServiceType serviceType = new OnmsServiceType();
    serviceType.setName("ICMP");
    serviceType.setId(3);
    alarm.setServiceType(serviceType);
    OnmsEvent event = new OnmsEvent();
    event.setId(2035);
    event.setEventUei("uei.opennms.org/nodes/interfaceDown");
    event.setEventTime(new Date(1503412443118L));
    event.setEventHost("noise");
    event.setEventSource("OpenNMS.Poller.DefaultPollContext");
    event.setIpAddr(InetAddress.getByName("10.8.0.30"));
    event.setEventCreateTime(new Date(1503412443118L));
    event.setEventDescr("All services are down on interface 10.8.0.30.");
    event.setEventLogMsg("Interface 10.8.0.30 is down.");
    event.setEventSeverity(OnmsSeverity.MINOR.getId());
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setNode(node);
    event.setDistPoller(monitoringSystem);
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "test", "testVal", "string")));
    event.setServiceType(serviceType);
    alarm.setLastEvent(event);
    alarm.setTTicketId("NMS-9587");
    alarm.setTTicketState(TroubleTicketState.OPEN);
    AlarmDTO alarmDTO = alarmMapper.alarmToAlarmDTO(alarm);
    mapAndMarshalToFromXmlAndJson(alarmDTO, "alarm.34.dto.xml", "alarm.34.dto.json");
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) AlarmDTO(org.opennms.web.rest.model.v2.AlarmDTO) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Event(org.opennms.netmgt.xml.eventconf.Event) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Date(java.util.Date) OnmsMonitoringSystem(org.opennms.netmgt.model.OnmsMonitoringSystem) JsonTest(org.opennms.core.test.xml.JsonTest) Test(org.junit.Test) XmlTest(org.opennms.core.test.xml.XmlTest)

Example 17 with OnmsEventParameter

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

the class EmailNorthbounderTest method testNorthbounderForServers.

/**
 * Test northbounder for servers.
 *
 * @throws Exception the exception
 */
@Test
public void testNorthbounderForServers() throws Exception {
    // Setup test node
    OnmsNode node = new OnmsNode();
    node.setForeignSource("Servers-MacOS");
    node.setForeignId("1");
    node.setId(1);
    node.setLabel("my-test-server");
    OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
    snmpInterface.setId(1);
    snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
    snmpInterface.setIfDescr("en1");
    snmpInterface.setIfName("en1/0");
    snmpInterface.setPhysAddr("00:00:00:00:00:01");
    InetAddress address = InetAddress.getByName("10.0.1.1");
    OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
    onmsIf.setSnmpInterface(snmpInterface);
    onmsIf.setId(1);
    onmsIf.setIfIndex(1);
    onmsIf.setIpHostName("my-test-server");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    node.getIpInterfaces().add(onmsIf);
    // Setup test alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(100);
    onmsAlarm.setNode(node);
    onmsAlarm.setIpAddr(address);
    onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
    onmsAlarm.setLastEvent(new OnmsEvent() {

        {
            this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "10", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is a test", "string")));
        }
    });
    onmsAlarm.setLogMsg("Test log message");
    onmsAlarm.setDescription("Test description");
    NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
    Assert.assertEquals(2, alarm.getEventParametersCollection().size());
    // Verify the nortbound alarm and send it to the test receiver
    Assert.assertTrue(nbi.accepts(alarm));
    SendmailConfig sendmail = nbi.getSendmailConfig(alarm);
    Assert.assertEquals("noc@networksRus.com", sendmail.getSendmailMessage().getTo());
    Assert.assertEquals("ALARM 100 FROM NODE my-test-server@Servers-MacOS", sendmail.getSendmailMessage().getSubject());
    Assert.assertEquals("ALARM 100 FROM NODE my-test-server@Servers-MacOS: Test log message\nDescription: Test description", sendmail.getSendmailMessage().getBody());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) SendmailConfig(org.opennms.netmgt.config.javamail.SendmailConfig) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 18 with OnmsEventParameter

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

the class EmailNorthbounderTest method testNorthbounderForRouters.

/**
 * Test northbounder for routers.
 *
 * @throws Exception the exception
 */
@Test
public void testNorthbounderForRouters() throws Exception {
    // Setup test node
    OnmsNode node = new OnmsNode();
    node.setForeignSource("Routers-Cisco");
    node.setForeignId("1");
    node.setId(1);
    node.setLabel("my-test-router");
    OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
    snmpInterface.setId(1);
    snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
    snmpInterface.setIfDescr("en1");
    snmpInterface.setIfName("en1/0");
    snmpInterface.setPhysAddr("00:00:00:00:00:01");
    InetAddress address = InetAddress.getByName("10.0.1.1");
    OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
    onmsIf.setSnmpInterface(snmpInterface);
    onmsIf.setId(1);
    onmsIf.setIfIndex(1);
    onmsIf.setIpHostName("my-test-router");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    node.getIpInterfaces().add(onmsIf);
    // Setup test alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(100);
    onmsAlarm.setNode(node);
    onmsAlarm.setIpAddr(address);
    onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
    onmsAlarm.setLastEvent(new OnmsEvent() {

        {
            this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "10", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is a test", "string")));
        }
    });
    onmsAlarm.setLogMsg("Test log message");
    onmsAlarm.setDescription("Test description");
    NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
    Assert.assertEquals(2, alarm.getEventParametersCollection().size());
    // Verify the nortbound alarm and send it to the test receiver
    Assert.assertTrue(nbi.accepts(alarm));
    SendmailConfig sendmail = nbi.getSendmailConfig(alarm);
    Assert.assertEquals("tarus@opennms.org, jeff@opennms.org", sendmail.getSendmailMessage().getTo());
    Assert.assertEquals("my-test-router : Something is wrong!", sendmail.getSendmailMessage().getSubject());
    Assert.assertEquals("Test log message - Test description", sendmail.getSendmailMessage().getBody());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) SendmailConfig(org.opennms.netmgt.config.javamail.SendmailConfig) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 19 with OnmsEventParameter

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

the class JmsNorthBounderTest method testObjectMessage.

@Test
public void testObjectMessage() throws Exception {
    String xml = objectMessageConfigXml();
    Resource resource = new ByteArrayResource(xml.getBytes());
    JmsNorthbounderConfigDao dao = new JmsNorthbounderConfigDao();
    dao.setConfigResource(resource);
    dao.afterPropertiesSet();
    JmsNorthbounderConfig config = dao.getConfig();
    List<JmsDestination> destinations = config.getDestinations();
    List<JmsNorthbounder> nbis = new LinkedList<>();
    for (JmsDestination jmsDestination : destinations) {
        JmsNorthbounder nbi = new JmsNorthbounder(config, m_jmsNorthbounderConnectionFactory, jmsDestination);
        // nbi.setNodeDao(m_nodeDao);
        nbi.afterPropertiesSet();
        nbis.add(nbi);
    }
    List<NorthboundAlarm> alarms = new LinkedList<>();
    OnmsNode node = new OnmsNode(null, NODE_LABEL);
    node.setForeignSource("TestGroup");
    node.setForeignId("2");
    node.setId(m_nodeDao.getNextNodeId());
    OnmsIpInterface ip = new OnmsIpInterface("127.0.0.1", node);
    InetAddress ia = null;
    try {
        ia = InetAddress.getByName("127.0.0.1");
    } catch (UnknownHostException e) {
    }
    m_nodeDao.save(node);
    m_nodeDao.flush();
    // TX via NBIs
    for (JmsNorthbounder nbi : nbis) {
        OnmsEvent event = new OnmsEvent();
        event.setId(5);
        event.setEventUei("uei.uei.org/uei");
        event.setEventTime(new Date());
        event.setEventHost("eventhost");
        event.setEventSource("eventsource");
        event.setIpAddr(ia);
        event.setDistPoller(null);
        event.setEventSnmpHost("eventsnmphost");
        event.setServiceType(null);
        event.setEventSnmp("eventsnmp");
        event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "syslogmessage", "Dec 22 2015 20:12:57.1 UTC :  %UC_CTI-3-CtiProviderOpenFailure: %[CTIconnectionId%61232238][ Login User Id%61pguser][Reason code.%61-1932787616][UNKNOWN_PARAMNAME:IPAddress%61172.17.12.73][UNKNOWN_PARAMNAME:IPv6Address%61][App ID%61Cisco CTIManager][Cluster ID%61SplkCluster][Node ID%61splkcucm6p]: CTI application failed to open provider%59 application startup failed", "string"), new OnmsEventParameter(event, "severity", "Error", "string"), new OnmsEventParameter(event, "timestamp", "Dec 22 14:13:21", "string"), new OnmsEventParameter(event, "process", "229250", "string"), new OnmsEventParameter(event, "service", "local7", "string")));
        event.setEventCreateTime(new Date());
        event.setEventDescr("eventdescr");
        event.setEventLogGroup("eventloggroup");
        event.setEventLogMsg("eventlogmsg");
        event.setEventSeverity(4);
        event.setEventPathOutage(null);
        event.setEventCorrelation(null);
        event.setEventSuppressedCount(0);
        event.setEventOperInstruct("operinstruct");
        event.setEventAutoAction(null);
        event.setEventOperAction(null);
        event.setEventOperActionMenuText(null);
        event.setEventNotification(null);
        event.setEventTTicket("tticketid");
        event.setEventTTicketState(1);
        event.setEventForward(null);
        event.setEventMouseOverText(null);
        event.setEventLog(null);
        event.setEventDisplay(null);
        event.setEventAckUser(null);
        event.setEventAckTime(null);
        event.setAlarm(null);
        event.setNode(node);
        event.setNotifications(null);
        event.setAssociatedServiceRegainedOutages(null);
        event.setAssociatedServiceLostOutages(null);
        OnmsAlarm alarm = new OnmsAlarm(9, event.getEventUei(), null, 1, 4, new Date(), event);
        alarm.setNode(node);
        alarm.setDescription(event.getEventDescr());
        alarm.setApplicationDN("applicationDN");
        alarm.setLogMsg(event.getEventLogMsg());
        alarm.setManagedObjectInstance("managedObjectInstance");
        alarm.setManagedObjectType("managedObjectType");
        alarm.setOssPrimaryKey("ossPrimaryKey");
        alarm.setQosAlarmState("qosAlarmState");
        alarm.setTTicketId("tticketId");
        alarm.setReductionKey("reductionKey");
        alarm.setClearKey("clearKey");
        alarm.setOperInstruct("operInstruct");
        alarm.setFirstEventTime(new Date(0));
        alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
        alarm.setIpAddr(ia);
        alarm.setLastEvent(event);
        alarm.setX733AlarmType(NorthboundAlarm.x733AlarmType.get(1).name());
        alarm.setX733ProbableCause(NorthboundAlarm.x733ProbableCause.get(1).getId());
        NorthboundAlarm a = new NorthboundAlarm(alarm);
        alarms.add(a);
        nbi.forwardAlarms(alarms);
    }
    Thread.sleep(100);
    // Let's become a consumer and receive the message
    Message m = m_template.receive("ObjectTestQueue");
    Assert.assertNotNull(m);
    Object response = ((ObjectMessage) m).getObject();
    Assert.assertNotNull(response);
    Assert.assertTrue("message\n'" + response + "'\n not a NorthboundAlarm\n'" + "'.", (response instanceof NorthboundAlarm));
    String rk = ((NorthboundAlarm) response).getAlarmKey();
    Assert.assertEquals("received alarm has incorrect reduction key: " + rk, "reductionKey", rk);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) UnknownHostException(java.net.UnknownHostException) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JmsNorthbounderConfig(org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) JmsNorthbounderConfigDao(org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) ByteArrayResource(org.springframework.core.io.ByteArrayResource) LinkedList(java.util.LinkedList) Date(java.util.Date) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) JmsNorthbounder(org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounder) ObjectMessage(javax.jms.ObjectMessage) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) JmsDestination(org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 20 with OnmsEventParameter

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

the class SnmpTrapNorthbounderConfigDaoTest method createAlarm.

/**
 * Creates the alarm.
 *
 * @return the northbound alarm
 * @throws UnknownHostException the unknown host exception
 */
private NorthboundAlarm createAlarm() throws UnknownHostException {
    // Build a test node
    OnmsNode node = new OnmsNode();
    node.setForeignSource("Servers");
    node.setForeignId("AAA11122");
    node.setId(1);
    node.setLabel("my-server");
    // Build a test SNMP interface
    OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
    snmpInterface.setId(1);
    snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
    snmpInterface.setIfDescr("en1");
    snmpInterface.setIfName("en1/0");
    snmpInterface.setPhysAddr("00:00:00:00:00:01");
    // Build a test IP interface
    InetAddress address = InetAddress.getByName("10.0.1.1");
    OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
    onmsIf.setSnmpInterface(snmpInterface);
    onmsIf.setId(1);
    onmsIf.setIfIndex(1);
    onmsIf.setIpHostName("p-brane");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    node.addIpInterface(onmsIf);
    // Build a test alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(10);
    onmsAlarm.setNode(node);
    onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
    onmsAlarm.setLogMsg("everything is good");
    onmsAlarm.setLastEvent(new OnmsEvent() {

        {
            this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "99", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is just a test", "String"), new OnmsEventParameter(this, "forwardAlarmToUserSnmpTrap", "true", "String")));
        }
    });
    // Build a test northbound alarm
    NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
    Assert.assertEquals(node.getForeignSource(), alarm.getForeignSource());
    Assert.assertEquals(node.getForeignId(), alarm.getForeignId());
    return alarm;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) InetAddress(java.net.InetAddress)

Aggregations

OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)25 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)22 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)19 Test (org.junit.Test)16 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)12 OnmsNode (org.opennms.netmgt.model.OnmsNode)12 InetAddress (java.net.InetAddress)10 Date (java.util.Date)10 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)8 LinkedList (java.util.LinkedList)4 Message (javax.jms.Message)3 ObjectMessage (javax.jms.ObjectMessage)3 TextMessage (javax.jms.TextMessage)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 JmsDestination (org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination)3 JmsNorthbounder (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounder)3 JmsNorthbounderConfig (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig)3 JmsNorthbounderConfigDao (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao)3 File (java.io.File)2