use of org.opennms.netmgt.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class EmailNorthbounder 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 syslog forwarding.";
NorthbounderException e = new NorthbounderException(errorMsg);
LOG.error(errorMsg, e);
throw e;
}
LOG.info("Forwarding {} alarms to destination {}", alarms.size(), m_destination.getName());
for (NorthboundAlarm alarm : alarms) {
try {
JavaSendMailer mailer = new JavaSendMailer(getSendmailConfig(alarm), false);
mailer.send();
} catch (JavaMailerException e) {
LOG.error("Can't send email for {}", alarm, e);
}
}
}
use of org.opennms.netmgt.alarmd.api.NorthboundAlarm 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.setEventParms("alarmId=10(Int32,text);alarmMessage=this is a test(string,text);");
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.alarmd.api.NorthboundAlarm 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<JmsNorthbounder>();
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<NorthboundAlarm>();
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) {
String eventparms = "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,text);severity=Error(string,text);timestamp=Dec 22 14:13:21(string,text);process=229250(string,text);service=local7(string,text)";
OnmsEvent event = new OnmsEvent(5, "uei.uei.org/uei", new Date(), "eventhost", "eventsource", ia, null, "eventssnmphost", null, "eventsnmp", eventparms, new Date(), "eventdescr", "eventloggroup", "eventlogmsg", 4, null, null, 0, "operinstruct", null, null, null, null, "tticketid", 1, null, null, null, null, null, null, null, node, null, null, 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(1);
alarm.setIpAddr(ia);
alarm.setEventParms(eventparms);
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.alarmd.api.NorthboundAlarm 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.setEventParms("alarmId=10(Int32,text);alarmMessage=this is a test(string,text);");
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.alarmd.api.NorthboundAlarm in project opennms by OpenNMS.
the class AlarmdIT method testNorthbounder.
@Test
public void testNorthbounder() throws Exception {
assertTrue(m_northbounder.isInitialized());
assertTrue(m_northbounder.getAlarms().isEmpty());
final EventBuilder bldr = new EventBuilder("testNoLogmsg", "AlarmdTest");
bldr.setAlarmData(new AlarmData());
bldr.setLogMessage("This is a test.");
final Event event = bldr.getEvent();
event.setDbid(17);
MockNode node = m_mockNetwork.getNode(1);
sendNodeDownEvent("%nodeid%", node);
final List<NorthboundAlarm> alarms = m_northbounder.getAlarms();
assertTrue(alarms.size() > 0);
}
Aggregations