use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class JavaMailAckReaderIT method testIntegration.
/**
* This test requires that 4 emails can be read from a Google account. The mails should be
* in this order:
* Subject matching ackd-configuration expression of action type ack
* Subject matching ackd-configuration expression of action type ack
* Subject matching ackd-configuration expression of action type ack
* Subject matching ackd-configuration expression of action type clear
*
* The test has been updated to now include sending an email message to a gmail account. Just correct
* the account details for your own local testing.
*
* @throws JavaMailerException
*
*/
@Ignore
@Test
public void testIntegration() throws JavaMailerException {
String gmailAccount = getUser();
String gmailPassword = getPassword();
JavaSendMailer sendMailer = createSendMailer(gmailAccount, gmailPassword);
SendmailMessage sendMsg = createAckMessage(gmailAccount, "1", "ack");
sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg));
sendMailer.send();
sendMsg = createAckMessage(gmailAccount, "2", "ack");
sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg));
sendMailer.send();
sendMsg = createAckMessage(gmailAccount, "3", "ack");
sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg));
sendMailer.send();
sendMsg = createAckMessage(gmailAccount, "4", "clear");
sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg));
sendMailer.send();
ReadmailConfig config = m_processor.determineMailReaderConfig();
Assert.assertNotNull(config);
updateConfigWithGoogleReadConfiguration(config, gmailAccount, gmailPassword);
List<Message> msgs = m_processor.retrieveAckMessages();
List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
Assert.assertNotNull(acks);
Assert.assertEquals(4, acks.size());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
Assert.assertEquals(Integer.valueOf(1), acks.get(0).getRefId());
Assert.assertEquals(getUser() + "@gmail.com", acks.get(0).getAckUser());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(1).getAckType());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(1).getAckAction());
Assert.assertEquals(Integer.valueOf(2), acks.get(1).getRefId());
Assert.assertEquals(getUser() + "@gmail.com", acks.get(1).getAckUser());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(2).getAckType());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(2).getAckAction());
Assert.assertEquals(Integer.valueOf(3), acks.get(2).getRefId());
Assert.assertEquals(getUser() + "@gmail.com", acks.get(2).getAckUser());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(3).getAckType());
Assert.assertEquals(AckAction.CLEAR, acks.get(3).getAckAction());
Assert.assertEquals(Integer.valueOf(4), acks.get(3).getRefId());
Assert.assertEquals(getUser() + "@gmail.com", acks.get(3).getAckUser());
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class DefaultAckServiceIT method notificationWithMissingAlarm.
@Test(expected = IllegalStateException.class)
public void notificationWithMissingAlarm() {
OnmsNode dbNode = m_nodeDao.get(m_populator.getNode1().getId());
OnmsEvent event = getEvent(dbNode);
OnmsAlarm alarm = new OnmsAlarm();
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setDescription(event.getEventDescr());
alarm.setDistPoller(event.getDistPoller());
alarm.setEventParms(event.getEventParms());
alarm.setFirstEventTime(event.getEventTime());
alarm.setIfIndex(event.getIfIndex());
alarm.setIpAddr(event.getIpAddr());
alarm.setLastEvent(event);
alarm.setLastEventTime(event.getEventTime());
alarm.setLogMsg(event.getEventLogMsg());
alarm.setMouseOverText(event.getEventMouseOverText());
alarm.setNode(dbNode);
alarm.setSeverityId(event.getEventSeverity());
alarm.setUei(event.getEventUei());
alarm.setCounter(1);
m_alarmDao.save(alarm);
m_alarmDao.flush();
getNotification(event);
OnmsAcknowledgment ack = new OnmsAcknowledgment();
ack.setRefId(alarm.getAckId());
ack.setAckType(alarm.getType());
m_alarmDao.delete(alarm);
m_alarmDao.flush();
m_ackDao.processAck(ack);
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class MailAckProcessor method createAcks.
//should probably be static
/**
* Creates <code>OnmsAcknowledgment</code>s for each notification reply email message determined
* to have an acknowledgment action.
*
* @param msgs a {@link java.util.List} object.
* @return a {@link java.util.List} object.
*/
protected List<OnmsAcknowledgment> createAcks(final List<Message> msgs) {
LOG.info("createAcks: Detecting and possibly creating acknowledgments from {} messages...", msgs.size());
List<OnmsAcknowledgment> acks = null;
if (msgs != null && msgs.size() > 0) {
acks = new ArrayList<OnmsAcknowledgment>();
Iterator<Message> it = msgs.iterator();
while (it.hasNext()) {
Message msg = (Message) it.next();
try {
LOG.debug("createAcks: detecting acks in message: {}", msg.getSubject());
Integer id = detectId(msg.getSubject(), m_ackdDao.getConfig().getNotifyidMatchExpression());
if (id != null) {
final OnmsAcknowledgment ack = createAck(msg, id);
ack.setAckType(AckType.NOTIFICATION);
ack.setLog(createLog(msg));
acks.add(ack);
msg.setFlag(Flag.DELETED, true);
LOG.debug("createAcks: found notification acknowledgment: {}", ack);
continue;
}
id = detectId(msg.getSubject(), m_ackdDao.getConfig().getAlarmidMatchExpression());
if (id != null) {
final OnmsAcknowledgment ack = createAck(msg, id);
ack.setAckType(AckType.ALARM);
ack.setLog(createLog(msg));
acks.add(ack);
msg.setFlag(Flag.DELETED, true);
LOG.debug("createAcks: found alarm acknowledgment: {}", ack);
continue;
}
} catch (MessagingException e) {
LOG.error("createAcks: messaging error", e);
} catch (IOException e) {
LOG.error("createAcks: IO problem", e);
}
}
} else {
LOG.debug("createAcks: No messages for acknowledgment processing.");
}
LOG.info("createAcks: Completed detecting and possibly creating acknowledgments. Created {} acknowledgments.", (acks == null ? 0 : acks.size()));
return acks;
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class MailAckProcessor method createAck.
/**
* <p>createAck</p>
*
* @param msg a {@link javax.mail.Message} object.
* @param refId a {@link java.lang.Integer} object.
* @return a {@link org.opennms.netmgt.model.OnmsAcknowledgment} object.
* @throws javax.mail.MessagingException if any.
* @throws java.io.IOException if any.
*/
protected OnmsAcknowledgment createAck(final Message msg, final Integer refId) throws MessagingException, IOException {
String ackUser = ((InternetAddress) msg.getFrom()[0]).getAddress();
Date ackTime = msg.getReceivedDate();
OnmsAcknowledgment ack = new OnmsAcknowledgment(ackTime, ackUser);
ack.setAckType(AckType.NOTIFICATION);
ack.setAckAction(determineAckAction(msg));
ack.setRefId(refId);
return ack;
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class AcknowledgmentDaoIT method testSaveWithAlarm.
@Test
@Transactional
public void testSaveWithAlarm() {
OnmsEvent event = new OnmsEvent();
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventCreateTime(new Date());
event.setDistPoller(m_distPollerDao.whoami());
event.setEventTime(new Date());
event.setEventSeverity(new Integer(7));
event.setEventUei("uei://org/opennms/test/EventDaoTest");
event.setEventSource("test");
m_eventDao.save(event);
OnmsNode node = m_nodeDao.findAll().iterator().next();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setNode(node);
alarm.setUei(event.getEventUei());
alarm.setSeverityId(event.getEventSeverity());
alarm.setFirstEventTime(event.getEventTime());
alarm.setLastEvent(event);
alarm.setCounter(new Integer(1));
alarm.setDistPoller(m_distPollerDao.whoami());
alarm.setAlarmAckTime(new Date());
alarm.setAlarmAckUser("not-admin");
m_alarmDao.save(alarm);
m_alarmDao.flush();
OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm);
getAcknowledgmentDao().save(ack);
Integer ackId = new Integer(ack.getId());
ack = null;
OnmsAcknowledgment ack2 = getAcknowledgmentDao().get(ackId);
OnmsAlarm alarm2 = m_alarmDao.get(ack2.getRefId());
assertEquals(ack2.getAckUser(), alarm2.getAlarmAckUser());
assertEquals(ack2.getAckTime(), alarm2.getAlarmAckTime());
}
Aggregations