Search in sources :

Example 11 with Alarm

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);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 12 with Alarm

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);
}
Also used : Logger(org.slf4j.Logger) TreeEvent(org.snmp4j.util.TreeEvent) Alarm(org.onosproject.alarm.Alarm) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SeverityLevel(org.onosproject.alarm.Alarm.SeverityLevel) AlarmId(org.onosproject.alarm.AlarmId) IOException(java.io.IOException) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) SnmpController(org.onosproject.snmp.SnmpController) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) SnmpDevice(org.onosproject.snmp.SnmpDevice) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) VariableBinding(org.snmp4j.smi.VariableBinding) AlarmConsumer(org.onosproject.alarm.AlarmConsumer) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DeviceId(org.onosproject.net.DeviceId) OID(org.snmp4j.smi.OID) SnmpDevice(org.onosproject.snmp.SnmpDevice) DeviceId(org.onosproject.net.DeviceId) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SnmpController(org.onosproject.snmp.SnmpController) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Example 13 with Alarm

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;
}
Also used : Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Example 14 with Alarm

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);
    }
}
Also used : Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Example 15 with Alarm

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;
}
Also used : Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) HashSet(java.util.HashSet) NetconfDeviceOutputEvent(org.onosproject.netconf.NetconfDeviceOutputEvent)

Aggregations

Alarm (org.onosproject.alarm.Alarm)25 DefaultAlarm (org.onosproject.alarm.DefaultAlarm)22 ArrayList (java.util.ArrayList)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Test (org.junit.Test)5 AlarmJsonMatcher.matchesAlarm (org.onosproject.faultmanagement.web.AlarmJsonMatcher.matchesAlarm)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)3 Produces (javax.ws.rs.Produces)3 SeverityLevel (org.onosproject.alarm.Alarm.SeverityLevel)3 AlarmId (org.onosproject.alarm.AlarmId)3 AlarmService (org.onosproject.alarm.AlarmService)3 DeviceId (org.onosproject.net.DeviceId)3 NetconfException (org.onosproject.netconf.NetconfException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2