Search in sources :

Example 21 with OnmsEvent

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

the class MockEventDao method getUeiCounts.

@Override
public Set<CountedObject<String>> getUeiCounts(final Integer limit) {
    final Map<String, Long> counts = new HashMap<String, Long>();
    for (final OnmsEvent event : findAll()) {
        final String eventUei = event.getEventUei();
        if (!counts.containsKey(eventUei)) {
            counts.put(eventUei, 0L);
        }
        counts.put(eventUei, counts.get(eventUei) + 1);
    }
    final Set<CountedObject<String>> countedObjects = new HashSet<CountedObject<String>>();
    for (final String uei : counts.keySet()) {
        countedObjects.add(new CountedObject<String>(uei, counts.get(uei)));
    }
    return countedObjects;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) HashMap(java.util.HashMap) CountedObject(org.opennms.netmgt.dao.api.CountedObject) HashSet(java.util.HashSet)

Example 22 with OnmsEvent

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

the class MockEventWriter method process.

private void process(final Event event) throws EventProcessorException {
    LOG.debug("Writing event: {}", event);
    final OnmsEvent oe = new OnmsEvent();
    oe.setEventAutoAction((event.getAutoactionCount() > 0) ? AutoAction.format(event.getAutoaction(), EVENT_AUTOACTION_FIELD_SIZE) : null);
    oe.setEventCorrelation((event.getCorrelation() != null) ? org.opennms.netmgt.dao.util.Correlation.format(event.getCorrelation(), EVENT_CORRELATION_FIELD_SIZE) : null);
    oe.setEventCreateTime(event.getCreationTime());
    oe.setId(event.getDbid());
    oe.setEventDescr(event.getDescr());
    try {
        oe.setDistPoller(m_distPollerDao.get(event.getDistPoller()));
    } catch (final DataAccessException e) {
        throw new EventProcessorException(e);
    }
    oe.setEventHost(event.getHost());
    oe.setEventForward((event.getForwardCount() > 0) ? org.opennms.netmgt.dao.util.Forward.format(event.getForward(), EVENT_FORWARD_FIELD_SIZE) : null);
    oe.setIfIndex(event.getIfIndex());
    oe.setIpAddr(event.getInterfaceAddress());
    if (event.getLogmsg() != null) {
        // set log message
        oe.setEventLogMsg(EventDatabaseConstants.format(event.getLogmsg().getContent(), 0));
        final String logdest = event.getLogmsg().getDest();
        if (logdest.equals("logndisplay")) {
            // if 'logndisplay' set both log and display column to yes
            oe.setEventLog("Y");
            oe.setEventDisplay("Y");
        } else if (logdest.equals("logonly")) {
            // if 'logonly' set log column to true
            oe.setEventLog("Y");
            oe.setEventDisplay("N");
        } else if (logdest.equals("displayonly")) {
            // if 'displayonly' set display column to true
            oe.setEventLog("N");
            oe.setEventDisplay("Y");
        } else if (logdest.equals("suppress")) {
            // if 'suppress' set both log and display to false
            oe.setEventLog("N");
            oe.setEventDisplay("N");
        }
    }
    oe.setEventMouseOverText(event.getMouseovertext());
    try {
        oe.setNode(m_nodeDao.get(event.getNodeid().intValue()));
    } catch (final DataAccessException e) {
        throw new EventProcessorException(e);
    }
    if (event.getOperactionCount() > 0) {
        final List<Operaction> a = new ArrayList<>();
        final List<String> b = new ArrayList<>();
        for (final Operaction eoa : event.getOperactionCollection()) {
            a.add(eoa);
            b.add(eoa.getMenutext());
        }
        oe.setEventOperAction(OperatorAction.format(a, EVENT_OPERACTION_FIELD_SIZE));
        oe.setEventOperActionMenuText(EventDatabaseConstants.format(b, EVENT_OPERACTION_MENU_FIELD_SIZE));
    }
    oe.setEventOperInstruct(event.getOperinstruct());
    oe.setEventParametersFromEvent(event);
    oe.setEventPathOutage(event.getPathoutage());
    try {
        oe.setServiceType(m_serviceTypeDao.findByName(event.getService()));
    } catch (final DataAccessException e) {
        throw new EventProcessorException(e);
    }
    oe.setSeverityLabel(event.getSeverity());
    oe.setEventSnmp(SnmpInfo.format(event.getSnmp(), EVENT_SNMP_FIELD_SIZE));
    oe.setEventSnmpHost(EventDatabaseConstants.format(event.getSnmphost(), EVENT_SNMPHOST_FIELD_SIZE));
    oe.setEventSource(event.getSource());
    oe.setEventTime(event.getTime());
    if (event.getTticket() != null) {
        oe.setEventTTicket(EventDatabaseConstants.format(event.getTticket().getContent(), EVENT_TTICKET_FIELD_SIZE));
        oe.setEventTTicketState(event.getTticket().getState().equals("on") ? 1 : 0);
    }
    oe.setEventUei(event.getUei());
    m_eventDao.saveOrUpdate(oe);
}
Also used : EventProcessorException(org.opennms.netmgt.events.api.EventProcessorException) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Operaction(org.opennms.netmgt.xml.event.Operaction) ArrayList(java.util.ArrayList) DataAccessException(org.springframework.dao.DataAccessException)

Example 23 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent 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)

Example 24 with OnmsEvent

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

the class NCSComponentServiceImpl method deleteEvents.

private void deleteEvents(final String foreignSource, final String foreignId) {
    final Map<String, String> eventParameters = new HashMap<>();
    eventParameters.put("componentForeignSource", foreignSource);
    eventParameters.put("componentForeignId", foreignId);
    for (final OnmsEvent event : m_eventDao.getEventsForEventParameters(eventParameters)) {
        m_eventDao.delete(event);
    }
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) HashMap(java.util.HashMap)

Example 25 with OnmsEvent

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

the class OnmsRestEventsClient method toEvent.

public Event toEvent(OnmsEvent onmsEvent) {
    Event event = new Event();
    if (onmsEvent.getId() != null)
        event.setDbid(onmsEvent.getId());
    if (onmsEvent.getEventUei() != null)
        event.setUei(onmsEvent.getEventUei());
    if (onmsEvent.getEventCreateTime() != null)
        event.setCreationTime(onmsEvent.getEventCreateTime());
    // event.setService()
    if (onmsEvent.getSeverityLabel() != null)
        event.setSeverity(onmsEvent.getSeverityLabel());
    if (onmsEvent.getEventDescr() != null)
        event.setDescr(onmsEvent.getEventDescr());
    if (onmsEvent.getEventHost() != null)
        event.setHost(onmsEvent.getEventHost());
    List<Parm> parmColl = new ArrayList<>();
    if (onmsEvent.getEventParameters() != null) {
        List<OnmsEventParameter> params = onmsEvent.getEventParameters();
        for (OnmsEventParameter onmsEventParameter : params) {
            String parmName = onmsEventParameter.getName();
            String type = onmsEventParameter.getType();
            String value = onmsEventParameter.getValue();
            Parm parm = new Parm();
            parm.setParmName(parmName);
            Value parmvalue = new Value();
            parmvalue.setType(type);
            parmvalue.setContent(value);
            parm.setValue(parmvalue);
            parmColl.add(parm);
        }
    }
    // add node label as param
    if (onmsEvent.getNodeLabel() != null) {
        Parm parm = new Parm();
        parm.setParmName(NODE_LABEL);
        Value parmValue = new Value();
        parm.setValue(parmValue);
        parmValue.setType("string");
        parmValue.setEncoding("text");
        parmValue.setContent(onmsEvent.getNodeLabel());
        parmColl.add(parm);
    }
    event.setParmCollection(parmColl);
    if (onmsEvent.getEventLogMsg() != null) {
        Logmsg logmsg = new Logmsg();
        logmsg.setContent(onmsEvent.getEventLogMsg());
        event.setLogmsg(logmsg);
    }
    if (onmsEvent.getNodeId() != null) {
        Integer i = onmsEvent.getNodeId();
        Long l = Long.valueOf(i.longValue());
        event.setNodeid(l);
    }
    return event;
}
Also used : Logmsg(org.opennms.netmgt.xml.event.Logmsg) ArrayList(java.util.ArrayList) Value(org.opennms.netmgt.xml.event.Value) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Event(org.opennms.netmgt.xml.event.Event) Parm(org.opennms.netmgt.xml.event.Parm) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter)

Aggregations

OnmsEvent (org.opennms.netmgt.model.OnmsEvent)94 Date (java.util.Date)49 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)41 OnmsNode (org.opennms.netmgt.model.OnmsNode)37 Test (org.junit.Test)36 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)22 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)21 Transactional (org.springframework.transaction.annotation.Transactional)19 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)16 InetAddress (java.net.InetAddress)13 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)13 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)13 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)9 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)6 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)6 Event (org.opennms.netmgt.xml.event.Event)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)5