use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class AlarmNorthbounder method forwardAlarms.
@Override
public void forwardAlarms(List<NorthboundAlarm> alarms) throws NorthbounderException {
for (NorthboundAlarm alarm : alarms) {
LOG.trace("AMQPNorthbounder Forwarding alarm: {}", alarm);
alarmForwarder.sendNow(alarm);
}
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class SnmpTrapNorthbounder method forwardAlarms.
/**
* Each implementation of the AbstractNorthbounder has a nice queue (Nagle's algorithmic) and the worker thread that processes the queue
* calls this method to send alarms to the northern NMS.
*
* @param alarms the alarms
* @throws NorthbounderException the northbounder exception
*/
@Override
public void forwardAlarms(List<NorthboundAlarm> alarms) throws NorthbounderException {
if (alarms == null) {
String errorMsg = "No alarms in alarms list for SNMP Trap forwarding.";
NorthbounderException e = new NorthbounderException(errorMsg);
LOG.error(errorMsg, e);
throw e;
}
LOG.info("Forwarding {} alarms to destination {}", alarms.size(), m_trapSink.getName());
for (NorthboundAlarm alarm : alarms) {
try {
SnmpTrapConfig config = m_trapSink.createTrapConfig(alarm);
if (config != null) {
m_trapHelper.forwardTrap(config);
}
} catch (SnmpTrapException e) {
LOG.error("Can't send trap for {}", alarm, e);
}
}
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class SyslogNorthBounderTest 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());
SyslogNorthbounderConfigDao dao = new SyslogNorthbounderConfigDao();
dao.setConfigResource(resource);
dao.afterPropertiesSet();
SyslogNorthbounderConfig config = dao.getConfig();
List<SyslogNorthbounder> nbis = new LinkedList<SyslogNorthbounder>();
for (SyslogDestination syslogDestination : config.getDestinations()) {
SyslogNorthbounder nbi = new SyslogNorthbounder(dao, syslogDestination.getName());
nbi.afterPropertiesSet();
nbis.add(nbi);
}
int j = 7;
List<NorthboundAlarm> alarms = new LinkedList<NorthboundAlarm>();
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "p-brane");
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("p-brane");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
ipInterfaces.add(onmsIf);
node.setIpInterfaces(ipInterfaces);
m_nodeDao.save(node);
m_nodeDao.flush();
for (SyslogNorthbounder nbi : nbis) {
for (int i = 1; i <= j; ++i) {
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(i);
onmsAlarm.setUei("uei.opennms.org/test/syslogNorthBounder");
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
String eventparms = "foreignSource=fabric(string,text);foreignId=space-0256012012000038(string,text);reason=Aborting node scan : Agent timed out while scanning the system table(string,text);" + ".1.3.6.1.4.1.2636.3.18.1.7.1.2.732=207795895(TimeTicks,text)";
onmsAlarm.setEventParms(eventparms);
}
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);
BufferedReader r = new BufferedReader(new StringReader(m_logStream.readStream()));
List<String> messages = new LinkedList<String>();
String line = null;
while ((line = r.readLine()) != null) {
messages.add(line);
Thread.sleep(10);
}
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) {
if (i == 0) {
i++;
continue;
}
switch(i) {
case 1:
Assert.assertTrue("Alarm (OnmsSeverity: " + OnmsSeverity.get(i) + ") = LEVEL_INFO.", message.contains("INFO"));
Assert.assertTrue(message.contains("NODE:p-brane"));
break;
case 2:
Assert.assertTrue("Alarm (OnmsSeverity: " + OnmsSeverity.get(i) + ") = LEVEL_NOTICE.", message.contains("NOTICE"));
Assert.assertTrue(message.contains("NODE:p-brane"));
break;
case 3:
Assert.assertTrue("Alarm (OnmsSeverity: " + OnmsSeverity.get(i) + ") = LEVEL_WARN.", message.contains("WARN"));
Assert.assertTrue(message.contains("NODE:p-brane"));
break;
case 4:
Assert.assertTrue("Alarm (OnmsSeverity: " + OnmsSeverity.get(i) + ") = LEVEL_ERROR.", message.contains("ERROR"));
Assert.assertTrue(message.contains("NODE:p-brane"));
break;
case 5:
Assert.assertTrue("Alarm (OnmsSeverity: " + OnmsSeverity.get(i) + ") = LEVEL_ERROR.", message.contains("ERROR"));
Assert.assertTrue(message.contains("NODE:p-brane"));
break;
case 6:
Assert.assertTrue("Alarm (OnmsSeverity: " + OnmsSeverity.get(i) + ") = LEVEL_CRITICAL.", message.contains("CRITICAL"));
Assert.assertTrue(message.contains("NODE:p-brane"));
break;
}
i++;
}
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class SnmpTrapNorthbounderTest method testNorthbounder.
/**
* Tests the trap northbounder.
*
* @throws Exception the exception
*/
// FIXME Verify the content of the trap sent.
@Test
public void testNorthbounder() throws Exception {
// Setup the configuration DAO
FileSystemResource resource = new FileSystemResource(new File("src/test/resources/etc/snmptrap-northbounder-config.xml"));
SnmpTrapNorthbounderConfigDao configDao = new SnmpTrapNorthbounderConfigDao();
configDao.setConfigResource(resource);
configDao.afterPropertiesSet();
// Setup the trap northbounder (overriding the settings of the first sink to use the test trap receiver)
SnmpTrapSink sink = configDao.getConfig().getSnmpTrapSink("localTest1");
sink.setIpAddress(TRAP_DESTINATION.getHostAddress());
sink.setPort(TRAP_PORT);
SnmpTrapNorthbounder nbi = new SnmpTrapNorthbounder(configDao, sink.getName());
nbi.afterPropertiesSet();
// Setup test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Server-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.setEventParms("alarmId=10(Int32,text);alarmMessage=this is a test(string,text);");
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));
nbi.forwardAlarms(Collections.singletonList(alarm));
// Introduce a delay to make sure the trap was sent and received.
Thread.sleep(5000);
Assert.assertEquals(1, getTrapsReceivedCount());
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm 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.setEventParms("alarmId=99(Int32,text);alarmMessage=this is just a test(string,text);forwardAlarmToUserSnmpTrap=true(string,text)");
// 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