use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class AlarmQueueTest method createAlarm.
/**
* Creates the alarm.
*
* @return the northbound alarm
*/
private NorthboundAlarm createAlarm() {
OnmsAlarm alarm = new OnmsAlarm();
alarm.setId(++alarmNumber);
alarm.setUei("uei.opennms.org/test/httpNorthBounder");
return new NorthboundAlarm(alarm);
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class BSFNorthbounderIT method testNorthbounder.
/**
* Test northbounder.
*
* @throws Exception the exception
*/
@Test
public void testNorthbounder() 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");
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "alarmId", "10", "Int32"), new OnmsEventParameter(event, "alarmMessage", "this is a test", "string")));
onmsAlarm.setLastEvent(event);
onmsAlarm.setLogMsg("Test log message");
onmsAlarm.setDescription("Test description");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(2, alarm.getEventParametersCollection().size());
Assert.assertTrue(nbi.accepts(alarm));
nbi.forwardAlarms(Lists.newArrayList(alarm));
nbi.stop();
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class DroolsNorthbounderIT method testNorthbounder.
/**
* Test northbounder.
*
* @throws Exception the exception
*/
@Test
public void testNorthbounder() 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");
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "alarmId", "10", "Int32"), new OnmsEventParameter(event, "alarmMessage", "this is a test", "string")));
onmsAlarm.setLastEvent(event);
onmsAlarm.setLogMsg("Test log message");
onmsAlarm.setDescription("Test description");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(2, alarm.getEventParametersCollection().size());
Assert.assertTrue(nbi.accepts(alarm));
nbi.forwardAlarms(Lists.newArrayList(alarm));
nbi.stop();
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class HttpNorthBounderTest method testForwardAlarms.
/**
* Test forward alarms.
*
* @throws InterruptedException the interrupted exception
*/
@Test
@JUnitHttpServer(port = 10342)
public void testForwardAlarms() throws InterruptedException {
HttpNorthbounder nb = new HttpNorthbounder();
HttpNorthbounderConfig config = new HttpNorthbounderConfig("localhost");
config.setMethod(HttpMethod.POST);
config.setPath("/jms/post");
config.setPort(Integer.valueOf(10342));
nb.setConfig(config);
OnmsAlarm alarm = new OnmsAlarm();
alarm.setId(1);
alarm.setUei("uei.opennms.org/test/httpNorthBounder");
NorthboundAlarm a = new NorthboundAlarm(alarm);
nb.onAlarm(a);
}
use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class JmsNorthBounderTest method testForwardAlarms.
/**
* This tests forwarding of 7 alarms, one for each OpenNMS severity to
* verify the LOG_LEVEL agrees with the Severity based on our algorithm.
*
* @throws Exception the exception
*/
@Test
public void testForwardAlarms() throws Exception {
String xml = generateConfigXml();
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.afterPropertiesSet();
nbis.add(nbi);
}
int j = 7;
List<NorthboundAlarm> alarms = new LinkedList<>();
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), NODE_LABEL);
node.setForeignSource("TestGroup");
node.setForeignId("1");
node.setId(m_nodeDao.getNextNodeId());
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");
Set<OnmsIpInterface> ipInterfaces = new LinkedHashSet<OnmsIpInterface>(j);
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(NODE_LABEL);
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
ipInterfaces.add(onmsIf);
node.setIpInterfaces(ipInterfaces);
m_nodeDao.save(node);
m_nodeDao.flush();
// TX via NBIs
for (JmsNorthbounder nbi : nbis) {
for (int i = 1; i <= j; ++i) {
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(i);
onmsAlarm.setUei("uei.opennms.org/test/jmsNorthBounder");
onmsAlarm.setNode(node);
onmsAlarm.setSeverityId(i);
onmsAlarm.setIpAddr(InetAddress.getByName("127.0.0.1"));
onmsAlarm.setCounter(i);
onmsAlarm.setLogMsg("Node Down");
onmsAlarm.setX733AlarmType(NorthboundAlarm.x733AlarmType.get(i).name());
onmsAlarm.setX733ProbableCause(NorthboundAlarm.x733ProbableCause.get(i).getId());
if (i < j) {
// Do not add parameters to the last alarm for
// testing NMS-6383
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "foreignSource", "fabric", "string"), new OnmsEventParameter(event, "foreignId", "space-0256012012000038", "string"), new OnmsEventParameter(event, "reason", "Aborting node scan : Agent timed out while scanning the system table", "string"), new OnmsEventParameter(event, ".1.3.6.1.4.1.2636.3.18.1.7.1.2.732", "207795895", "TimeTicks")));
onmsAlarm.setLastEvent(event);
}
NorthboundAlarm a = new NorthboundAlarm(onmsAlarm);
Assert.assertFalse(nbi.accepts(a));
onmsAlarm.setUei("uei.opennms.org/nodes/nodeDown");
a = new NorthboundAlarm(onmsAlarm);
Assert.assertTrue(nbi.accepts(a));
alarms.add(a);
}
nbi.forwardAlarms(alarms);
}
Thread.sleep(100);
// Let's become a consumer and receive the messages!
List<String> messages = new LinkedList<>();
Message m = m_template.receive("OpenNMSAlarmQueue");
while (m != null) {
Assert.assertTrue(m instanceof TextMessage);
messages.add(((TextMessage) m).getText());
m = m_template.receive("OpenNMSAlarmQueue");
}
Assert.assertTrue("Log messages sent: 7, Log messages received: " + messages.size(), 7 == messages.size());
for (String message : messages) {
System.out.println(message);
}
int i = 0;
for (String message : messages) {
Assert.assertTrue("ALARM ID:" + (i + 1), message.contains("ALARM ID:" + (i + 1) + " "));
Assert.assertTrue(message.contains("NODE:" + NODE_LABEL));
i++;
}
}
Aggregations