Search in sources :

Example 11 with OnmsSeverity

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

the class Bsmd method handleBusinessServiceStateChanged.

/**
     * Called when the operational status of a business service was changed.
     */
@Override
public void handleBusinessServiceStateChanged(BusinessService businessService, Status newStatus, Status prevStatus) {
    final OnmsSeverity newSeverity = SeverityMapper.toSeverity(newStatus);
    final OnmsSeverity prevSeverity = SeverityMapper.toSeverity(prevStatus);
    // Always send an serviceOperationalStatusChanged event
    EventBuilder ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_OPERATIONAL_STATUS_CHANGED_UEI, NAME);
    addBusinessServicesAttributesAsEventParms(businessService, ebldr);
    ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_ID, businessService.getId());
    ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_NAME, businessService.getName());
    ebldr.addParam(EventConstants.PARM_PREV_SEVERITY_ID, prevSeverity.getId());
    ebldr.addParam(EventConstants.PARM_PREV_SEVERITY_LABEL, prevSeverity.getLabel());
    ebldr.addParam(EventConstants.PARM_NEW_SEVERITY_ID, newSeverity.getId());
    ebldr.addParam(EventConstants.PARM_NEW_SEVERITY_LABEL, newSeverity.getLabel());
    m_eventIpcManager.sendNow(ebldr.getEvent());
    // Generate a serviceProblem or a serviceProblemResolved event based on the current status
    if (newSeverity.isGreaterThan(OnmsSeverity.NORMAL)) {
        ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_UEI, NAME);
        addBusinessServicesAttributesAsEventParms(businessService, ebldr);
        ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_ID, businessService.getId());
        ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_NAME, businessService.getName());
        ebldr.setSeverity(newSeverity.toString());
    } else {
        ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_RESOLVED_UEI, NAME);
        addBusinessServicesAttributesAsEventParms(businessService, ebldr);
        ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_ID, businessService.getId());
        ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_NAME, businessService.getName());
    }
    m_eventIpcManager.sendNow(ebldr.getEvent());
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 12 with OnmsSeverity

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

the class GraphMLEdgeStatus method merge.

public static GraphMLEdgeStatus merge(final GraphMLEdgeStatus s1, final GraphMLEdgeStatus s2) {
    final OnmsSeverity severity = s1.getSeverity().isGreaterThan(s2.getSeverity()) ? s1.getSeverity() : s2.getSeverity();
    final Map<String, String> styleProperties = Maps.newHashMap(EMPTY_PROPERTIES);
    for (final Map.Entry<String, String> e : s1.styleProperties.entrySet()) {
        if (e.getValue() != null) {
            styleProperties.put(e.getKey(), e.getValue());
        }
    }
    for (final Map.Entry<String, String> e : s2.styleProperties.entrySet()) {
        if (e.getValue() != null) {
            styleProperties.put(e.getKey(), e.getValue());
        }
    }
    return new GraphMLEdgeStatus(severity, styleProperties);
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 13 with OnmsSeverity

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

the class ApplicationStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    Map<VertexRef, Status> returnMap = new HashMap<>();
    Map<ApplicationStatusEntity.Key, Status> statusMap = new HashMap<>();
    List<ApplicationStatusEntity> result = applicationDao.getAlarmStatus();
    for (ApplicationStatusEntity eachRow : result) {
        DefaultStatus status = createStatus(eachRow.getSeverity(), eachRow.getCount());
        statusMap.put(eachRow.getKey(), status);
    }
    // status for all known node ids
    Collection<VertexRef> vertexRefsForNamespace = getVertexRefsForNamespace(vertices);
    Collection<VertexRef> vertexRefsRoot = getRootElements(vertexRefsForNamespace);
    Collection<VertexRef> vertexRefs = new ArrayList<>(vertexRefsForNamespace);
    vertexRefs.removeAll(vertexRefsRoot);
    // calculate status for children
    for (VertexRef eachVertex : vertexRefs) {
        ApplicationVertex applicationVertex = (ApplicationVertex) eachVertex;
        Status alarmStatus = statusMap.get(createKey(applicationVertex));
        if (alarmStatus == null) {
            alarmStatus = createStatus(OnmsSeverity.NORMAL, 0);
        }
        returnMap.put(eachVertex, alarmStatus);
    }
    // calculate status for root
    for (VertexRef eachRoot : vertexRefsRoot) {
        ApplicationVertex eachRootApplication = (ApplicationVertex) eachRoot;
        OnmsSeverity maxSeverity = OnmsSeverity.NORMAL;
        int count = 0;
        for (VertexRef eachChild : eachRootApplication.getChildren()) {
            ApplicationVertex eachChildApplication = (ApplicationVertex) eachChild;
            ApplicationStatusEntity.Key childKey = createKey(eachChildApplication);
            Status childStatus = statusMap.get(childKey);
            if (childStatus != null && maxSeverity.isLessThan(createSeverity(childStatus.computeStatus()))) {
                maxSeverity = createSeverity(childStatus.computeStatus());
                count = Integer.parseInt(childStatus.getStatusProperties().get("statusCount"));
            }
        }
        returnMap.put(eachRoot, createStatus(maxSeverity, count));
    }
    return returnMap;
}
Also used : DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationStatusEntity(org.opennms.netmgt.dao.api.ApplicationStatusEntity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 14 with OnmsSeverity

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

the class QoSDrxAlarmEventReceiverEventHandlerImpl2 method onNotifyNewAlarmEvent.

// ************************
// On Event Methods
// ************************
/** {@inheritDoc} */
@Override
public void onNotifyNewAlarmEvent(NotifyNewAlarmEvent nnae, OssBeanAlarmEventReceiver callingAer) {
    //	Get a reference to the QoSD logger instance assigned by OpenNMS
    String logheader = "RX:" + callingAer.getName() + ":" + this.getClass().getSimpleName() + ".onNotifyNewAlarmEvent(): ";
    LOG.debug("{} Statistics: {}", logheader, callingAer.getRuntimeStatistics());
    if (!initialised) {
        LOG.error("{} event handler not initialised. init() must be called by receiver before handling any events", logheader);
        return;
    }
    try {
        OnmsAlarm alarm = null;
        String ossPrimaryKey = nnae.getAlarmKey().getAlarmPrimaryKey();
        String applicationDN = nnae.getAlarmKey().getApplicationDN();
        LOG.debug("{} Received an onNotifyNewAlarmEvent() - AlarmPrimaryKey: {} ApplictionDN: {} eventtime: {}", logheader, ossPrimaryKey, applicationDN, nnae.getEventTime());
        LOG.debug("{} Using this OssDao (toString):{}", logheader, ossDao.toString());
        if ((applicationDN == null) || (applicationDN.equals("")) || (ossPrimaryKey == null) || (ossPrimaryKey.equals(""))) {
            LOG.error("{} ApplicatioDN or PrimaryKey not set", logheader);
        } else {
            LOG.debug("{} Creating new alarm", logheader);
            //				alarm = ossDao.getCurrentAlarmForUniqueKey(applicationDN, ossPrimaryKey);
            //				if (alarm!=null) { // already an alarm with this unique id - LOG.error
            //				LOG.error("{} Alarm Already exists with this Unique ID", logheader);
            //				} else {
            alarm = new OnmsAlarm();
            alarm.setUei(OnmsAlarmOssjMapper.ossjAlarmTypeToUei(nnae.getAlarmType()));
            alarm.setX733AlarmType((nnae.getAlarmType() == null) ? "" : nnae.getAlarmType());
            alarm.setX733ProbableCause(nnae.getProbableCause());
            // needed?
            alarm.setTTicketState(null);
            // TODO changed
            alarm.setTTicketId("");
            // TODO changed				
            alarm.setQosAlarmState("external_type");
            // needed?
            alarm.setSuppressedUser("");
            // needed?
            alarm.setSuppressedUntil(new Date());
            // needed?
            alarm.setSuppressedTime(new Date());
            OnmsSeverity onmsseverity;
            try {
                onmsseverity = OnmsAlarmOssjMapper.ossjSeveritytoOnmsSeverity(nnae.getPerceivedSeverity());
            } catch (IllegalArgumentException iae) {
                LOG.error("{} problem setting severity used default:'WARNING'. Exception:", logheader, iae);
                onmsseverity = OnmsSeverity.WARNING;
            }
            alarm.setSeverity(onmsseverity);
            //TODO not needed
            //				OnmsServiceType service= new OnmsServiceType();
            //				service.setId(new Integer(-1));
            //				alarm.setServiceType(new OnmsServiceType()); // needed?
            alarm.setReductionKey(":managedObjectInstance:" + nnae.getManagedObjectInstance() + ":managedObjectType:" + nnae.getManagedObjectClass() + ":ossPrimaryKey:-" + ossPrimaryKey + ":applicationDN:-" + // must be unique because of alarm_reductionkey_idx
            applicationDN);
            alarm.setOssPrimaryKey(ossPrimaryKey);
            alarm.setOperInstruct(nnae.getProposedRepairActions());
            // defaultvalue if search fails - will update node with ID 1
            // TODO remove ossDao.makeExtendedOnmsNode(); 
            OnmsNode node = new OnmsNode();
            // node id cannot be null
            node.setId(new Integer(1));
            // 
            alarm.setNode(node);
            if (almUpdateBehaviour == null) {
                LOG.error("RX:{}: This receiver's alarmUpdateBehaviour is not set: defaulting to update nodeID:1", callingAer.getName());
            } else if (callingAer.getName() == null) {
                LOG.error("RX:{}: This receiver has no name: default alarms will update nodeID:1", callingAer.getName());
            } else {
                LOG.debug("{} alarmUpdateBehaviour:{} {}", logheader, almUpdateBehaviour, alarmUpdateBehaviour);
                if (almUpdateBehaviour.equals(SPECIFY_OUTSTATION)) {
                    // this will look for first match of node label to callingAer.getName()
                    // and set node id to this value.
                    LOG.debug("{} SPECIFY_OUTSTATION looking for node with nodelabel:{}", logheader, callingAer.getName());
                    try {
                        // TODO temp remove ?
                        try {
                            node = ossDao.findNodeByLabel(callingAer.getName());
                        } catch (Throwable ex) {
                            LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node ", logheader, ex);
                        }
                        if (node != null) {
                            LOG.debug("{} alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION):NODE FOUND for this RX Name:{} setting node id to NodeLabel:{} NodeID:{}", logheader, callingAer.getName(), node.getLabel(), node.getId());
                            // maps into FIRST instance of node with the same managedObjectInstance and managedObjectType
                            alarm.setNode(node);
                        } else {
                            LOG.error("{} alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION):NODE NOT FOUND for this RX Name:{} setting node id to default NodeID: 1", logheader, callingAer.getName());
                            // TODO remove ossDao.makeExtendedOnmsNode(); 
                            node = new OnmsNode();
                            // node id cannot be null
                            node.setId(new Integer(1));
                            // 
                            alarm.setNode(node);
                        }
                    } catch (Throwable ex) {
                        LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node for alarm Set to default nodeID:1", logheader, ex);
                    }
                } else if (almUpdateBehaviour.equals(USE_TYPE_INSTANCE)) {
                    // this will look for first match of node Managed object Instance and Managed Object type
                    // and set node id to this value. 
                    String managedObjectType = nnae.getManagedObjectClass();
                    String managedObjectInstance = nnae.getManagedObjectInstance();
                    LOG.debug("{} USE_TYPE_INSTANCE looking for node with managedObjectType:{} managedObjectInstance:{}", logheader, managedObjectType, managedObjectInstance);
                    try {
                        node = ossDao.findNodeByInstanceAndType(managedObjectInstance, managedObjectType);
                        if (node != null) {
                            LOG.debug("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE):NODE FOUND for this RX Name:{} setting node id to NodeLabel:{} NodeID:{}", logheader, callingAer.getName(), node.getLabel(), node.getId());
                            // maps into FIRST instance of node with the same managedObjectInstance and managedObjectType
                            alarm.setNode(node);
                        } else {
                            LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE):NODE NOT FOUND for this managedObjectType:{} managedObjectInstance:{} setting node id to default NodeID: 1", logheader, managedObjectType, managedObjectInstance);
                            // TODO remove ossDao.makeExtendedOnmsNode();
                            node = new OnmsNode();
                            // node id cannot be null
                            node.setId(new Integer(1));
                            // 
                            alarm.setNode(node);
                        }
                    } catch (Throwable ex) {
                        LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node for alarm Set to default nodeID:1", logheader, ex);
                    }
                } else {
                    LOG.error("{} Invalid value for alarmUpdateBehaviour:{} {} defaulting to update nodeID:1", logheader, almUpdateBehaviour, alarmUpdateBehaviour);
                }
            }
            // needed?
            alarm.setMouseOverText("");
            alarm.setManagedObjectType(nnae.getManagedObjectClass());
            alarm.setManagedObjectInstance(nnae.getManagedObjectInstance());
            alarm.setLogMsg(nnae.getSpecificProblem());
            // NOTE - this has no effect here as .setLastEvent nulls value
            // alarm.setLastEventTime(nnae.getEventTime());
            //TODO REMOVED - DO NOT CREATE EVENT WITH HIBERNATE AlarmDAo
            //				OnmsEvent event= new OnmsEvent();
            //				//event.setId(new Integer(1));  // This is NOT set since unique constraint in alarms table on Events table
            //				alarm.setLastEvent(event); 
            // needed?
            alarm.setIpAddr(InetAddressUtils.getLocalHostAddress());
            // set null as updating alarm
            alarm.setId(null);
            alarm.setFirstEventTime(nnae.getEventTime());
            alarm.setLastEventTime(nnae.getEventTime());
            alarm.setDistPoller(distPollerDao.whoami());
            //TODO need Qosd Not to generate this if remote
            alarm.setDescription(nnae.getAdditionalText());
            alarm.setCounter(new Integer(1));
            alarm.setApplicationDN(applicationDN);
            // set to raise alarm
            alarm.setAlarmType(new Integer(1));
            //alarm.setAlarmAckUser(arg0);
            //alarm.setAlarmAckTime(arg0);
            //TODO added for new alarm field
            HashMap<String, String> m_details = new HashMap<String, String>();
            alarm.setDetails(m_details);
            try {
                LOG.debug("{} Creating Alarm: ", logheader);
                OnmsAlarm updatedAlarm = ossDao.addCurrentAlarmForUniqueKey(alarm);
                LOG.debug("{} Created alarm: {}", logheader, OssDaoOpenNMSImpl.alarmToString(updatedAlarm));
            } catch (Exception ex) {
                LOG.error("{} problem creating new alarm AlarmPrimaryKey: {} ApplictionDN: {}", logheader, ossPrimaryKey, applicationDN, ex);
            }
        }
    //TODO remove			}
    } catch (Throwable e) {
        LOG.error("{} Error", logheader, e);
    }
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 15 with OnmsSeverity

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

the class AlarmFeed method getFeed.

/**
     * <p>getFeed</p>
     *
     * @return a {@link com.sun.syndication.feed.synd.SyndFeed} object.
     */
@Override
public SyndFeed getFeed() {
    SyndFeed feed = new SyndFeedImpl();
    feed.setTitle("Alarms");
    feed.setDescription("OpenNMS Alarms");
    feed.setLink(getUrlBase() + "alarm/list.htm");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    List<Filter> filters = new ArrayList<Filter>();
    if (this.getRequest().getParameter("node") != null) {
        Integer nodeId = WebSecurityUtils.safeParseInt(this.getRequest().getParameter("node"));
        filters.add(new NodeFilter(nodeId, getServletContext()));
    }
    if (this.getRequest().getParameter("severity") != null) {
        String sev = this.getRequest().getParameter("severity");
        for (OnmsSeverity severity : OnmsSeverity.values()) {
            if (severity.getLabel().equalsIgnoreCase(sev)) {
                filters.add(new SeverityFilter(severity));
            }
        }
    }
    OnmsCriteria queryCriteria = AlarmUtil.getOnmsCriteria(new AlarmCriteria(filters.toArray(new Filter[] {}), SortStyle.FIRSTEVENTTIME, AcknowledgeType.BOTH, this.getMaxEntries(), AlarmCriteria.NO_OFFSET));
    OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(queryCriteria);
    SyndEntry entry;
    for (OnmsAlarm alarm : alarms) {
        entry = new SyndEntryImpl();
        entry.setPublishedDate(alarm.getFirstEventTime());
        if (alarm.getAckTime() != null) {
            entry.setTitle(sanitizeTitle(alarm.getLogMsg()) + " (acknowledged by " + alarm.getAckUser() + ")");
            entry.setUpdatedDate(alarm.getAckTime());
        } else {
            entry.setTitle(sanitizeTitle(alarm.getLogMsg()));
            entry.setUpdatedDate(alarm.getFirstEventTime());
        }
        entry.setLink(getUrlBase() + "alarm/detail.htm?id=" + alarm.getId());
        entry.setAuthor("OpenNMS");
        SyndContent content = new SyndContentImpl();
        content.setType("text/html");
        content.setValue(alarm.getDescription());
        entry.setDescription(content);
        entries.add(entry);
    }
    feed.setEntries(entries);
    return feed;
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.sun.syndication.feed.synd.SyndContent) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) NodeFilter(org.opennms.web.alarm.filter.NodeFilter) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) NodeFilter(org.opennms.web.alarm.filter.NodeFilter)

Aggregations

OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)18 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)7 ArrayList (java.util.ArrayList)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)4 SyndContent (com.sun.syndication.feed.synd.SyndContent)2 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)2 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)2 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)2 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)2 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)2 Label (com.vaadin.ui.Label)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 PluginException (org.opennms.api.integration.ticketing.PluginException)2 Restrictions (org.opennms.core.criteria.restrictions.Restrictions)2