use of org.onosproject.alarm.DefaultAlarm in project onos by opennetworkinglab.
the class AlarmManager method updateBookkeepingFields.
@Override
public Alarm updateBookkeepingFields(AlarmId id, boolean clear, boolean isAcknowledged, String assignedUser) {
checkNotNull(id, "Alarm id is null");
Alarm found = store.getAlarm(id);
if (found == null) {
throw new ItemNotFoundException("Alarm with id " + id + " found");
}
long now = System.currentTimeMillis();
DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(found).withTimeUpdated(now);
if (found.cleared() != clear) {
alarmBuilder.clear().withTimeCleared(now);
}
if (found.acknowledged() != isAcknowledged) {
alarmBuilder.withAcknowledged(isAcknowledged);
}
if (assignedUser != null && !found.assignedUser().equals(assignedUser)) {
alarmBuilder.withAssignedUser(assignedUser);
}
DefaultAlarm updated = alarmBuilder.build();
store.createOrUpdateAlarm(updated);
return updated;
}
use of org.onosproject.alarm.DefaultAlarm in project onos by opennetworkinglab.
the class NokiaOpenConfigAlarmConfig method translateAlarms.
@Override
public <T> Set<Alarm> translateAlarms(List<T> unparsedAlarms) {
boolean categoryFound = false;
deviceId = handler().data().deviceId();
Set<Alarm> alarms = new HashSet<>();
for (T alarm : unparsedAlarms) {
categoryFound = false;
if (alarm instanceof NetconfDeviceOutputEvent) {
NetconfDeviceOutputEvent event = (NetconfDeviceOutputEvent) alarm;
if (event.type() == NetconfDeviceOutputEvent.Type.DEVICE_NOTIFICATION) {
String message = event.getMessagePayload();
if (message.contains("<update>")) {
categoryFound = true;
DefaultAlarm newAlarm = treatUpdate(message);
if (newAlarm != null) {
alarms.add(newAlarm);
}
}
if (message.contains("<delete>")) {
categoryFound = true;
treatDelete(message);
}
if (!categoryFound) {
log.debug("[translateAlarms] Appropriate category wasn't found, " + "you have something else \n {} ", message);
}
}
}
}
return alarms;
}
use of org.onosproject.alarm.DefaultAlarm in project onos by opennetworkinglab.
the class NokiaOpenConfigAlarmConfig method buildAlarm.
/**
* Composes an Alarm from XML string.
* @param message - XML string obtained form the device.
* @return - composed alarm as a DefaultAlarm instance.
*/
private DefaultAlarm buildAlarm(String message) {
try {
InputSource src = new InputSource(new StringReader(message));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(src);
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
String severity = null;
severity = xpath.evaluate(XML_PATH + "state/severity", document);
// treating alarm according to the severity level
if ((severity != null) & (severity != "")) {
// Setting flag to match correct severity
boolean severityFound = false;
// Extracting parameters
try {
String id = xpath.evaluate(XML_PATH + "id", document);
String source = xpath.evaluate(XML_PATH + "state/resource", document);
String description = xpath.evaluate(XML_PATH + "state/text", document);
long timeStamp = Long.parseLong(xpath.evaluate(XML_PATH + "state/time-created", document));
if (severity.contains("CRITICAL")) {
return (new DefaultAlarm.Builder(AlarmId.alarmId(id), deviceId, description + ":" + source, SeverityLevel.CRITICAL, timeStamp).withServiceAffecting(true).build());
}
if (severity.contains("MAJOR")) {
return (new DefaultAlarm.Builder(AlarmId.alarmId(id), deviceId, description + ":" + source, SeverityLevel.MAJOR, timeStamp).withServiceAffecting(true).build());
}
if (severity.contains("MINOR")) {
return (new DefaultAlarm.Builder(AlarmId.alarmId(id), deviceId, description + ":" + source, SeverityLevel.MINOR, timeStamp).build());
}
if (!severityFound) {
return (new DefaultAlarm.Builder(AlarmId.alarmId(id), deviceId, description + ":" + source, SeverityLevel.INDETERMINATE, timeStamp).build());
}
} catch (Exception e) {
log.error("[translateAlarms] Exception was caught during the alarm processing\n {}", e);
}
}
} catch (Exception e) {
log.error("[translateAlarms] something went wrong during notification parsing \n {}", e);
}
return null;
}
Aggregations