Search in sources :

Example 46 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class HypericAckProcessor method run.

/**
 * <p>run</p>
 */
@Override
public void run() {
    List<OnmsAcknowledgment> acks = new ArrayList<OnmsAcknowledgment>();
    try {
        LOG.info("run: Processing Hyperic acknowledgments...");
        // Query list of outstanding alerts with remote platform identifiers
        List<OnmsAlarm> unAckdAlarms = fetchUnclearedHypericAlarms();
        Map<String, List<OnmsAlarm>> organizedAlarms = new TreeMap<String, List<OnmsAlarm>>();
        int legacyAlarmCount = 0;
        // Split the list of alarms up according to the Hyperic system where they originated
        for (OnmsAlarm alarm : unAckdAlarms) {
            String key = getAlertSourceParmValue(alarm);
            if (key == null || "".equals(key)) {
                legacyAlarmCount++;
            } else {
                List<OnmsAlarm> targetList = organizedAlarms.get(key);
                if (targetList == null) {
                    targetList = new ArrayList<OnmsAlarm>();
                    organizedAlarms.put(key, targetList);
                }
                targetList.add(alarm);
            }
        }
        if (legacyAlarmCount > 0) {
            LOG.info("{} Hyperic alarms without an alert.source param found, these alarms will not be processed", String.valueOf(legacyAlarmCount));
        }
        // Connect to each Hyperic system and query for the status of corresponding alerts
        for (Map.Entry<String, List<OnmsAlarm>> alarmList : organizedAlarms.entrySet()) {
            String hypericSystem = alarmList.getKey();
            List<OnmsAlarm> alarmsForSystem = alarmList.getValue();
            // Match the alert.source to the Hyperic URL via the config
            String hypericUrl = getUrlForHypericSource(hypericSystem);
            if (hypericUrl == null) {
                // If the alert.source doesn't match anything in our current config, just ignore it, warn in the logs
                LOG.warn("Could not find Hyperic host URL for the following platform ID: {}", hypericSystem);
                LOG.warn("Skipping processing of {} alarms with that platform ID", alarmsForSystem.size());
                continue;
            }
            try {
                List<String> alertIdList = new ArrayList<String>();
                for (OnmsAlarm alarmForSystem : alarmList.getValue()) {
                    // Construct a sane query for the Hyperic system
                    String alertId = getAlertIdParmValue(alarmForSystem);
                    alertIdList.add(alertId);
                }
                // Call fetchHypericAlerts() for each system
                List<HypericAlertStatus> alertsForSystem = fetchHypericAlerts(hypericUrl, alertIdList);
                // Iterate and update any acknowledged or fixed alerts
                for (HypericAlertStatus alert : alertsForSystem) {
                    OnmsAlarm alarm = findAlarmForHypericAlert(alarmsForSystem, hypericSystem, alert);
                    if (alarm == null) {
                        LOG.warn("Could not find the OpenNMS alarm for the following Hyperic alert: URL: \"{}\", id: {}", hypericUrl, alert.getAlertId());
                    } else if (alert.isFixed() && !OnmsSeverity.CLEARED.equals(alarm.getSeverity())) {
                        // If the Hyperic alert has been fixed and the local alarm is not yet marked as CLEARED, then clear it
                        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, "Ackd.HypericAckProcessor", (alert.getFixTime() != null) ? alert.getFixTime() : new Date());
                        ack.setAckAction(AckAction.CLEAR);
                        ack.setLog(alert.getFixMessage());
                        acks.add(ack);
                    } else if (alert.getAckMessage() != null && alarm.getAckTime() == null) {
                        // If the Hyperic alert has been ack'd and the local alarm is not yet ack'd, then ack it
                        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, "Ackd.HypericAckProcessor", (alert.getAckTime() != null) ? alert.getAckTime() : new Date());
                        ack.setAckAction(AckAction.ACKNOWLEDGE);
                        ack.setLog(alert.getAckMessage());
                        acks.add(ack);
                    }
                }
            } catch (Throwable e) {
                LOG.warn("run: threw exception when processing alarms for Hyperic system {}", hypericSystem, e.getMessage());
                LOG.warn("run: {} acknowledgements processed successfully before exception", acks.size());
            } finally {
                if (acks.size() > 0) {
                    m_ackDao.processAcks(acks);
                }
            }
        }
        LOG.info("run: Finished processing Hyperic acknowledgments ({} ack(s) processed for {} alarm(s))", acks.size(), unAckdAlarms.size());
    } catch (Throwable e) {
        LOG.warn("run: threw exception", e);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Date(java.util.Date) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 47 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AckdIT method testAcknowledgeNotification.

/**
 * This tests acknowledging a notification and a related alarm.  If events are being deduplicated
 * they should all have the same alarm ID.
 * @throws InterruptedException
 */
@Test
public void testAcknowledgeNotification() throws InterruptedException {
    VerificationObject vo = createAckStructure();
    Assert.assertTrue(vo.m_nodeId > 0);
    Assert.assertTrue(vo.m_alarmId > 0);
    Assert.assertTrue(vo.m_eventID > 0);
    Assert.assertTrue(vo.m_userNotifId > 0);
    OnmsAcknowledgment ack = new OnmsAcknowledgment(m_notificationDao.get(vo.m_notifId));
    m_ackDao.save(ack);
    m_ackDao.flush();
    Thread.sleep(1);
    m_ackDao.processAck(ack);
    OnmsNotification notif = m_notificationDao.get(ack.getRefId());
    Assert.assertNotNull(notif.getAnsweredBy());
    Assert.assertEquals("admin", notif.getAnsweredBy());
    OnmsAlarm alarm = m_alarmDao.get(vo.m_alarmId);
    Assert.assertNotNull(alarm);
    Assert.assertEquals("admin", alarm.getAlarmAckUser());
    long ackTime = ack.getAckTime().getTime();
    long respondTime = notif.getRespondTime().getTime();
    // the DAOs now set the acknowledgment time for each Acknowledgable and should
    // be later (by a few millis in this test) than the time the acknowledgment was created
    // this will give us an idea about the processing time of an acknowledgment
    Assert.assertTrue(ackTime < respondTime);
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

Example 48 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AckdIT method testAcknowledgeAlarm.

/**
 * This tests the acknowledgment of an alarm and any related notifications.
 */
@Test
public void testAcknowledgeAlarm() {
    VerificationObject vo = createAckStructure();
    Assert.assertTrue(vo.m_nodeId > 0);
    Assert.assertTrue(vo.m_alarmId > 0);
    Assert.assertTrue(vo.m_eventID > 0);
    Assert.assertTrue(vo.m_userNotifId > 0);
    OnmsAlarm alarm = m_alarmDao.get(vo.m_alarmId);
    OnmsAcknowledgment ack = new OnmsAcknowledgment(m_alarmDao.get(vo.m_alarmId));
    m_ackDao.save(ack);
    m_ackDao.flush();
    m_ackDao.processAck(ack);
    alarm = m_alarmDao.get(ack.getRefId());
    Assert.assertNotNull(alarm.getAlarmAckUser());
    Assert.assertEquals("admin", alarm.getAlarmAckUser());
    OnmsNotification notif = m_notificationDao.get(vo.m_notifId);
    Assert.assertNotNull(notif);
    Assert.assertEquals("admin", notif.getAnsweredBy());
    Assert.assertTrue(alarm.getAlarmAckTime().before(notif.getRespondTime()));
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

Example 49 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class HypericAckProcessorIT method testParseMethods.

@Test
public void testParseMethods() throws Exception {
    OnmsEvent event = new OnmsEvent();
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "platform.id", "10001", "string"), new OnmsEventParameter(event, "platform.commentText", "", "string"), new OnmsEventParameter(event, "platform.platformType.os", "null", "string"), new OnmsEventParameter(event, "platform.platformType.osVersion", "null", "string"), new OnmsEventParameter(event, "platform.platformType.arch", "null(", "tring"), new OnmsEventParameter(event, "platform.agent.address", "192.0.2.143", "string"), new OnmsEventParameter(event, "platform.agent.port", "2144", "string"), new OnmsEventParameter(event, "platform.fqdn", "192.0.2.143", "string"), new OnmsEventParameter(event, "platform.name", "delta", "string"), new OnmsEventParameter(event, "platform.description", "Fedora 12", "string"), new OnmsEventParameter(event, "platform.location", "", "string"), new OnmsEventParameter(event, "alert.id", "11757", "string"), new OnmsEventParameter(event, "alert.fixed", "false", "string"), new OnmsEventParameter(event, "alert.ctime", "1267219500000", "string"), new OnmsEventParameter(event, "alert.timestamp", "1267219500000", "string"), new OnmsEventParameter(event, "alert.ackedBy", "null", "string"), new OnmsEventParameter(event, "alert.stateId", "null", "string"), new OnmsEventParameter(event, "alert.url", "http://192.168.0.5:7080/alerts/Alerts.do?mode%61viewAlert&eid%611:10001&a%6111757", "string"), new OnmsEventParameter(event, "alert.baseURL", "http://192.168.0.5:7080", "string"), new OnmsEventParameter(event, "alert.source", "HQ", "string"), new OnmsEventParameter(event, "alertDef.id", "10002", "string"), new OnmsEventParameter(event, "alertDef.name", "Load Above 2", "string"), new OnmsEventParameter(event, "alertDef.description", "", "string"), new OnmsEventParameter(event, "alertDef.priority", "2", "string"), new OnmsEventParameter(event, "alertDef.appdefType", "1", "string"), new OnmsEventParameter(event, "alertDef.appdefId", "10001", "string"), new OnmsEventParameter(event, "alertDef.notifyFiltered", "false", "string"), new OnmsEventParameter(event, "action.shortReason", "Load Above 2 delta Load Average 5 Minutes (1.4)", "string"), new OnmsEventParameter(event, "action.longReason", "If Load Average 5 Minutes > 0.5 (actual value %61 1.4)", "string"), new OnmsEventParameter(event, "resource.instanceId", "10001", "string"), new OnmsEventParameter(event, "resource.name", "delta", "string"), new OnmsEventParameter(event, "resource.url", "http://192.168.0.5:7080/Resource.do?eid%611:10001", "string"), new OnmsEventParameter(event, "resource.resourceType.name", "covalentEAMPlatform", "string")));
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setLastEvent(event);
    /*
        OnmsAlarm alarm = createMock(OnmsAlarm.class);
        expect(alarm.getEventParms()).andReturn(
                "platform.id=10001(string,text);platform.commentText=(string,text);platform.platformType.os=null(string,text);platform.platformType.osVersion=null(string,text);platform.platformType.arch=null(string,text);platform.agent.address=192.0.2.143(string,text);platform.agent.port=2144(string,text);platform.fqdn=192.0.2.143(string,text);platform.name=delta(string,text);platform.description=Fedora 12(string,text);platform.location=(string,text);alert.id=11757(string,text);alert.fixed=false(string,text);alert.ctime=1267219500000(string,text);alert.timestamp=1267219500000(string,text);alert.ackedBy=null(string,text);alert.stateId=null(string,text);alert.url=http://192.168.0.5:7080/alerts/Alerts.do?mode%61viewAlert&eid%611:10001&a%6111757(string,text);alert.baseURL=http://192.168.0.5:7080(string,text);alert.source=HQ(string,text);alertDef.id=10002(string,text);alertDef.name=Load Above 2(string,text);alertDef.description=(string,text);alertDef.priority=2(string,text);alertDef.appdefType=1(string,text);alertDef.appdefId=10001(string,text);alertDef.notifyFiltered=false(string,text);action.shortReason=Load Above 2 delta Load Average 5 Minutes (1.4)(string,text);action.longReason=If Load Average 5 Minutes > 0.5 (actual value %61 1.4)(string,text);resource.instanceId=10001(string,text);resource.name=delta(string,text);resource.url=http://192.168.0.5:7080/Resource.do?eid%611:10001(string,text);resource.resourceType.name=covalentEAMPlatform(string,text)"
        ).times(2);
        replay(alarm);
         */
    assertEquals("Alert source not parsed properly", "HQ", HypericAckProcessor.getAlertSourceParmValue(alarm));
    assertEquals("Alert ID not parsed properly", "11757", HypericAckProcessor.getAlertIdParmValue(alarm));
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Test(org.junit.Test)

Example 50 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AbstractNorthbounderTest method createNorthboundAlarm.

/**
 * Creates the northbound alarm.
 *
 * @param alarmid the alarmid
 * @return the northbound alarm
 */
private NorthboundAlarm createNorthboundAlarm(int alarmid) {
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setId(alarmid);
    alarm.setUei("uei.opennms.org/test/httpNorthBounder");
    return new NorthboundAlarm(alarm);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm)

Aggregations

OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)143 Test (org.junit.Test)58 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)41 Date (java.util.Date)36 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 Transactional (org.springframework.transaction.annotation.Transactional)35 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)19 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)18 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)18 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)17 ArrayList (java.util.ArrayList)14 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)14 InetAddress (java.net.InetAddress)13 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)11 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)10 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)9 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)9 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)8 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)8 LinkedList (java.util.LinkedList)7