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