Search in sources :

Example 41 with OnmsAlarm

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

the class AlarmRepositoryHibernate method removeStickyMemo.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
public void removeStickyMemo(Integer alarmId) {
    OnmsAlarm onmsAlarm = m_alarmDao.get(alarmId);
    if (onmsAlarm != null && onmsAlarm.getStickyMemo() != null) {
        m_memoDao.delete(onmsAlarm.getStickyMemo());
        onmsAlarm.setStickyMemo(null);
    }
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with OnmsAlarm

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

the class AlarmRepositoryHibernate method unacknowledgeMatchingAlarms.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void unacknowledgeMatchingAlarms(OnmsCriteria criteria, String user) {
    List<OnmsAlarm> alarms = m_alarmDao.findMatching(criteria);
    for (OnmsAlarm alarm : alarms) {
        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, user);
        ack.setAckAction(AckAction.UNACKNOWLEDGE);
        m_ackDao.processAck(ack);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with OnmsAlarm

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

the class AlarmRepositoryHibernate method escalateAlarms.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void escalateAlarms(int[] alarmIds, String user, Date timestamp) {
    OnmsCriteria criteria = new OnmsCriteria(OnmsAlarm.class);
    criteria.add(Restrictions.in("id", Arrays.asList(ArrayUtils.toObject(alarmIds))));
    List<OnmsAlarm> alarms = m_alarmDao.findMatching(criteria);
    Iterator<OnmsAlarm> alarmsIt = alarms.iterator();
    while (alarmsIt.hasNext()) {
        OnmsAlarm alarm = alarmsIt.next();
        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, user);
        ack.setAckTime(timestamp);
        ack.setAckAction(AckAction.ESCALATE);
        m_ackDao.processAck(ack);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with OnmsAlarm

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

the class ApplicationDaoHibernate method getApplicationStatus.

@Override
public List<ApplicationStatus> getApplicationStatus(List<OnmsApplication> applications) {
    // Applications do not have a alarm mapping, so we grab all nodeDown, interfaceDown and serviceLost alarms
    // for all monitored services of each application to calculate the maximum severity (-> status)
    final List<ApplicationStatus> statusList = new ArrayList<>();
    for (OnmsApplication application : applications) {
        final Set<String> reductionKeys = new HashSet<>();
        for (OnmsMonitoredService eachService : application.getMonitoredServices()) {
            reductionKeys.addAll(ReductionKeyHelper.getReductionKeys(eachService));
        }
        if (!reductionKeys.isEmpty()) {
            final CriteriaBuilder builder = new CriteriaBuilder(OnmsAlarm.class);
            builder.in("reductionKey", reductionKeys);
            // findMatching would exepct OnmsApplications, but we need OnmsAlarms, so hack it
            HibernateCallback<List<OnmsAlarm>> callback = buildHibernateCallback(builder.toCriteria());
            List<OnmsAlarm> alarms = getHibernateTemplate().execute(callback);
            // All alarms for the current application have been determined, now get the max severity
            final Optional<OnmsAlarm> maxSeverity = alarms.stream().reduce((leftAlarm, rightAlarm) -> {
                if (leftAlarm.getSeverity().isGreaterThan(rightAlarm.getSeverity())) {
                    return leftAlarm;
                }
                return rightAlarm;
            });
            if (maxSeverity.isPresent()) {
                statusList.add(new ApplicationStatus(application, maxSeverity.get().getSeverity()));
            } else {
                // ensure that each application has a status
                statusList.add(new ApplicationStatus(application, OnmsSeverity.NORMAL));
            }
        } else {
            // ensure that each application has a status
            statusList.add(new ApplicationStatus(application, OnmsSeverity.NORMAL));
        }
    }
    return statusList;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) ApplicationStatus(org.opennms.netmgt.dao.api.ApplicationStatus) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 45 with OnmsAlarm

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

the class NCSNorthbounderIT method alarm.

private NorthboundAlarm alarm(int alarmId) {
    OnmsEvent event = new OnmsEvent();
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "componentType", "Service", "string"), new OnmsEventParameter(event, "componentName", "NAM" + alarmId, "string"), new OnmsEventParameter(event, "componentForeignSource", "FS", "string"), new OnmsEventParameter(event, "componentForeignId", "" + alarmId, "string"), new OnmsEventParameter(event, "cause", "17", "string")));
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setId(alarmId);
    alarm.setUei("uei.opennms.org/test/httpNorthBounder");
    alarm.setLastEvent(event);
    alarm.setAlarmType((alarmId + 1) % 2 + 1);
    return new NorthboundAlarm(alarm);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter)

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