Search in sources :

Example 1 with DefaultAlarm

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

Example 2 with DefaultAlarm

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;
}
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 3 with DefaultAlarm

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;
}
Also used : XPath(javax.xml.xpath.XPath) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Document(org.w3c.dom.Document) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader)

Aggregations

DefaultAlarm (org.onosproject.alarm.DefaultAlarm)3 Alarm (org.onosproject.alarm.Alarm)2 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 XPath (javax.xml.xpath.XPath)1 XPathFactory (javax.xml.xpath.XPathFactory)1 ItemNotFoundException (org.onlab.util.ItemNotFoundException)1 NetconfDeviceOutputEvent (org.onosproject.netconf.NetconfDeviceOutputEvent)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1