Search in sources :

Example 21 with Alarm

use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.

the class FujitsuVoltAlarmConsumer method consumeAlarms.

@Override
public List<Alarm> consumeAlarms() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    ncDeviceId = handler.data().deviceId();
    checkNotNull(controller, "Netconf controller is null");
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    dateFormat.setTimeZone(ZONE);
    List<Alarm> alarms = new ArrayList<>();
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE).append(ANGLE_RIGHT + NEW_LINE).append(buildStartTag(VOLT_ALERTS)).append(buildEmptyTag(OLT_ACTIVE_ALERTS)).append(buildEndTag(VOLT_ALERTS)).append(VOLT_NE_CLOSE);
        String reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), null);
        if (reply != null) {
            alarms = parseVoltActiveAlerts(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
        }
    } catch (NetconfException e) {
        log.error("Error reading alarms for device {} exception {}", ncDeviceId, e);
    }
    return ImmutableList.copyOf(alarms);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 22 with Alarm

use of org.onosproject.alarm.Alarm in project onos by opennetworkinglab.

the class PolatisAlarmConsumer method parseAlarms.

private List<Alarm> parseAlarms(String content) {
    List<HierarchicalConfiguration> subtrees = configsAt(content, KEY_DATA_SYSTEMALARMS);
    List<Alarm> alarms = new ArrayList<>();
    for (HierarchicalConfiguration alarm : subtrees) {
        alarms.add(parseAlarm(alarm));
    }
    return alarms;
}
Also used : Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 23 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)

Example 24 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 25 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)

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