Search in sources :

Example 1 with OnmsSeverity

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

the class AlarmSearchProvider method findAlarms.

private List<OnmsAlarm> findAlarms(final List<SearchResult> results, final String queryString) {
    CriteriaBuilder bldr = new CriteriaBuilder(OnmsAlarm.class);
    OnmsSeverity severity = OnmsSeverity.get(queryString);
    List<OnmsAlarm> alarms;
    if (!OnmsSeverity.INDETERMINATE.equals(severity)) {
        bldr = new CriteriaBuilder(OnmsAlarm.class);
        bldr.eq("severity", severity);
        alarms = alarmProvider.findMatchingAlarms(bldr.toCriteria());
        if (alarms.size() > 0) {
            AlarmSearchResult result = new AlarmSearchResult(queryString);
            result.setSeverityQuery(true);
            results.add(result);
        }
    } else {
        bldr.isNotNull("node").ilike("uei", "%" + queryString + "%").orderBy("node");
        alarms = alarmProvider.findMatchingAlarms(bldr.toCriteria());
    }
    return alarms;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 2 with OnmsSeverity

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

the class AlarmStatusProvider method calculateAlarmStatusForGroup.

private static AlarmStatus calculateAlarmStatusForGroup(List<AlarmSummary> alarmSummaries) {
    if (!alarmSummaries.isEmpty()) {
        Collections.sort(alarmSummaries, new Comparator<AlarmSummary>() {

            @Override
            public int compare(AlarmSummary o1, AlarmSummary o2) {
                return o1.getMaxSeverity().compareTo(o2.getMaxSeverity());
            }
        });
        OnmsSeverity severity = alarmSummaries.get(0).getMaxSeverity();
        int count = 0;
        for (AlarmSummary eachSummary : alarmSummaries) {
            count += eachSummary.getAlarmCount();
        }
        return new AlarmStatus(severity.getLabel(), count);
    }
    return createDefaultStatus();
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary)

Example 3 with OnmsSeverity

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

the class SeverityGenerator method generateCell.

@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    Property<OnmsSeverity> property = source.getContainerProperty(itemId, columnId);
    if (property == null || property.getValue() == null) {
        return null;
    } else {
        OnmsSeverity severity = property.getValue();
        String label = severity.getLabel();
        label = label.toLowerCase();
        label = new String(label.substring(0, 1)).toUpperCase() + label.substring(1);
        return new Label("&nbsp;&nbsp;&nbsp;&nbsp;" + escapeHtml(label), Label.CONTENT_XML);
    }
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) Label(com.vaadin.ui.Label)

Example 4 with OnmsSeverity

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

the class AlarmRestServiceBase method translateParameters.

protected void translateParameters(final MultivaluedMap<String, String> params) {
    // this is handled by a @QueryParam annotation, ignore it from the UriInfo object
    params.remove("severities");
    if (params.containsKey("nodeId")) {
        final String nodeId = params.getFirst("nodeId");
        params.remove("nodeId");
        params.add("node.id", nodeId);
    }
    if (params.containsKey("nodeLabel")) {
        final String nodeLabel = params.getFirst("nodeLabel");
        params.remove("nodeLabel");
        params.add("node.label", nodeLabel);
    }
    final String query = params.getFirst("query");
    // System.err.println("tranlateSeverity: query = " + query + ", pattern = " + p);
    if (query != null) {
        final Matcher m = m_severityPattern.matcher(query);
        if (m.find()) {
            // System.err.println("translateSeverity: group(1) = '" + m.group(1) + "', group(2) = '" + m.group(2) + "', group(3) = '" + m.group(3) + "'");
            final String alias = m.group(1);
            final String comparator = m.group(2);
            final String severity = m.group(3);
            final OnmsSeverity onmsSeverity = OnmsSeverity.get(severity);
            // System.err.println("translateSeverity: " + severity + " = " + onmsSeverity);
            final String newQuery = m.replaceFirst(" " + (alias == null ? "" : alias) + "severity " + comparator + " " + onmsSeverity.getId());
            params.remove("query");
            params.add("query", newQuery);
        // System.err.println("translateSeverity: newQuery = '" + newQuery + "'");
        } else {
        // System.err.println("translateSeverity: failed to find pattern");
        }
    }
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) Matcher(java.util.regex.Matcher)

Example 5 with OnmsSeverity

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

the class DefaultGeolocationService method calculateStatus.

private Status calculateStatus(GeolocationQuery query, Set<Integer> nodeIds) {
    final NodeStatusCalculatorConfig nodeStatusCalculatorConfig = new NodeStatusCalculatorConfig();
    nodeStatusCalculatorConfig.setIncludeAcknowledgedAlarms(query.isIncludeAcknowledgedAlarms());
    nodeStatusCalculatorConfig.setLocation(query.getLocation());
    if (query.getSeverity() != null) {
        final OnmsSeverity severity = OnmsSeverity.get(query.getSeverity().getId());
        final List<OnmsSeverity> severityFilter = Arrays.stream(OnmsSeverity.values()).filter(s -> s.isGreaterThanOrEqual(severity)).collect(Collectors.toList());
        nodeStatusCalculatorConfig.setSeverities(severityFilter);
    }
    nodeStatusCalculatorConfig.setCalculationStrategy(NodeStatusCalculationStrategy.None);
    if (query.getStatusCalculationStrategy() != null) {
        nodeStatusCalculatorConfig.setCalculationStrategy(NodeStatusCalculationStrategy.valueOf(query.getStatusCalculationStrategy().name()));
    }
    nodeStatusCalculatorConfig.setNodeIds(nodeIds);
    final Status status = nodeStatusCalculator.calculateStatus(nodeStatusCalculatorConfig);
    return status;
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) Arrays(java.util.Arrays) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Status(org.opennms.features.status.api.node.strategy.Status) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) ArrayList(java.util.ArrayList) Coordinates(org.opennms.features.geolocation.api.Coordinates) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Set(java.util.Set) SeverityInfo(org.opennms.features.geolocation.api.SeverityInfo) Collectors(java.util.stream.Collectors) Restrictions(org.opennms.core.criteria.restrictions.Restrictions) NodeStatusCalculator(org.opennms.features.status.api.node.NodeStatusCalculator) Objects(java.util.Objects) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) List(java.util.List) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) NodeInfo(org.opennms.features.geolocation.api.NodeInfo) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Status(org.opennms.features.status.api.node.strategy.Status) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Aggregations

OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)24 ArrayList (java.util.ArrayList)8 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)8 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 NodeStatusCalculatorConfig (org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Objects (java.util.Objects)4 NodeStatusCalculationStrategy (org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy)4 Status (org.opennms.features.status.api.node.strategy.Status)4 Arrays (java.util.Arrays)3 Set (java.util.Set)3 Restrictions (org.opennms.core.criteria.restrictions.Restrictions)3 InetAddressUtils (org.opennms.core.utils.InetAddressUtils)3 AddressInfo (org.opennms.features.geolocation.api.AddressInfo)3 Coordinates (org.opennms.features.geolocation.api.Coordinates)3 GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)3