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;
}
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();
}
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(" " + escapeHtml(label), Label.CONTENT_XML);
}
}
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");
}
}
}
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;
}
Aggregations