use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.
the class PolatisAlarmConsumer method consumeAlarms.
@Override
public List<Alarm> consumeAlarms() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
checkNotNull(controller, "Netconf controller is null");
MastershipService mastershipService = handler.get(MastershipService.class);
deviceId = handler.data().deviceId();
List<Alarm> alarms = new ArrayList<>();
if (!mastershipService.isLocalMaster(deviceId)) {
log.warn("Not master for {} Use {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
return ImmutableList.copyOf(alarms);
}
try {
String request = xmlEmpty(KEY_SYSTEMALARMS_XMLNS);
String reply = controller.getDevicesMap().get(deviceId).getSession().get(request, null);
if (reply != null) {
alarms = parseAlarms(reply);
}
} catch (NetconfException e) {
log.error("Error reading alarms for device {} exception {}", deviceId, e);
}
return ImmutableList.copyOf(alarms);
}
use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.
the class LumentumAlarmConsumer method consumeAlarms.
@Override
public List<Alarm> consumeAlarms() {
SnmpController controller = checkNotNull(handler().get(SnmpController.class));
List<Alarm> alarms = new ArrayList<>();
DeviceId deviceId = handler().data().deviceId();
SnmpDevice device = controller.getDevice(deviceId);
try {
snmp = new LumentumSnmpDevice(device.getSnmpHost(), device.getSnmpPort());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Gets the alarm table and for each entry get the ID and create the proper alarm.
snmp.get(ALARMS_TABLE_OID).forEach(alarm -> snmp.get(ALARMS_ID_OID).forEach(alarmIdEvent -> {
int alarmId = getAlarmId(alarmIdEvent);
alarms.add(new DefaultAlarm.Builder(AlarmId.alarmId(deviceId, String.valueOf(alarmId)), deviceId, getMessage(alarmId), getSeverity(alarmId), System.currentTimeMillis()).build());
}));
return ImmutableList.copyOf(alarms);
}
use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.
the class NokiaOpenConfigAlarmConfig method findAlarm.
/**
* This method searches for similar alarm inside the Alarm store of ONOS.
* @param message - XML String obtained from the device.
* @return - alarm (if was found in the store) or null.
*/
private Alarm findAlarm(String message) {
Collection<Alarm> alarms = alarmService.getAlarms(deviceId);
Alarm alarm = buildAlarm(message);
if ((alarms.contains(alarm)) & (alarm != null)) {
log.debug("Alarm was found \n {}", alarm);
return alarm;
}
log.debug("Alarm was NOT found \n {}", alarm);
return null;
}
use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.
the class NokiaOpenConfigAlarmConfig method treatDelete.
/**
* Treats message in case it contains <delete> tag.
* @param message - XML-encoded notification obtained from the device.
* @return - composed alarm.
*/
private void treatDelete(String message) {
Alarm existingAlarm = findAlarm(getDeleteDataFromNotification(message));
if (existingAlarm != null) {
alarmService.updateBookkeepingFields(existingAlarm.id(), true, true, null);
log.debug("[treatDelete] Existing alarm was updated (CLEARED)");
} else {
log.debug("[treatDelete] We found something new here \n {} \n", message);
}
}
use of org.onosproject.alarm.Alarm 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;
}
Aggregations