Search in sources :

Example 1 with SeverityLevel

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

the class FujitsuVoltAlarmConsumer method parseVoltActiveAlerts.

/**
 * Parses XML string to get controller information.
 *
 * @param cfg a hierarchical configuration
 * @return a list of alarms
 */
private List<Alarm> parseVoltActiveAlerts(HierarchicalConfiguration cfg) {
    List<Alarm> alarms = new ArrayList<>();
    List<HierarchicalConfiguration> fields = cfg.configurationsAt(OLT_ACTIVE_ALERTS_KEY);
    for (HierarchicalConfiguration sub : fields) {
        List<HierarchicalConfiguration> childFields = sub.configurationsAt(ALERT_INFO);
        for (HierarchicalConfiguration child : childFields) {
            try {
                int seqNum = Integer.parseInt(child.getString(ALERT_SEQNUM));
                boolean cleared = Boolean.parseBoolean(child.getString(ALERT_CLEAR));
                String alertType = child.getString(ALERT_TYPE);
                String severity = child.getString(SEVERITY);
                List<HierarchicalConfiguration> idFields = child.configurationsAt(RESOURCE_ID);
                if (idFields.isEmpty()) {
                    log.error("{} does not exist: SQ={}, TYPE={}, SEV={}, CLEARED={}", RESOURCE_ID, seqNum, alertType, severity, cleared);
                    continue;
                }
                String alarmSrc = formAlarmSource(idFields);
                if (alarmSrc == null) {
                    log.error("Cannot build description: SQ={}, TYPE={}, SEV={}, CLEARED={}", seqNum, alertType, severity, cleared);
                    continue;
                }
                long timeRaised = getTimeRaised(child);
                log.debug("VOLT: ACTIVE ALERT: SQ={}, TYPE={}, SEV={}, CLEARED={}, TIME={}", seqNum, alertType, severity, cleared, timeRaised);
                SeverityLevel alarmLevel = AlertSeverity.convertToAlarmSeverityLevel(severity);
                if (alarmLevel.equals(SeverityLevel.INDETERMINATE)) {
                    log.warn("Unknown severity: {}", severity);
                }
                DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(AlarmId.alarmId(ncDeviceId, Long.toString(timeRaised)), ncDeviceId, alertType.toUpperCase(), alarmLevel, timeRaised).forSource(AlarmEntityId.alarmEntityId(alarmSrc));
                alarms.add(alarmBuilder.build());
            } catch (NumberFormatException e) {
                log.error("Non-number exception {}", e);
            } catch (Exception e) {
                log.error("Exception {}", e);
            }
        }
    }
    return alarms;
}
Also used : ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) NetconfException(org.onosproject.netconf.NetconfException) ParseException(java.text.ParseException) SeverityLevel(org.onosproject.alarm.Alarm.SeverityLevel) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Example 2 with SeverityLevel

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

the class PolatisAlarmConfig method translateAlarms.

@Override
public <T> Set<Alarm> translateAlarms(List<T> unparsedAlarms) {
    deviceId = handler().data().deviceId();
    Set<Alarm> alarms = new HashSet<>();
    for (T alarm : unparsedAlarms) {
        if (alarm instanceof CommandResponderEvent) {
            CommandResponderEvent alarmEvent = (CommandResponderEvent) alarm;
            PDU pdu = alarmEvent.getPDU();
            if (pdu != null) {
                String alarmType = pdu.getVariable(SNMP_TRAP_OID).toString();
                if (alarmType.equals(OPM_ALARM_OID.toString())) {
                    String label = pdu.getVariable(ALARM_PORT_LABEL_OID).toString();
                    int port = pdu.getVariable(ALARM_PORT_OID).toInt();
                    String uniqueIdentifier = "LOS" + port;
                    String status = pdu.getVariable(ALARM_STATUS_OID).toString();
                    String alarmMessage = "Loss of Service alarm " + status + " for fibre " + port;
                    SeverityLevel alarmLevel = SeverityLevel.MAJOR;
                    long timeRaised = 0;
                    DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(AlarmId.alarmId(deviceId, uniqueIdentifier), deviceId, alarmMessage, alarmLevel, timeRaised);
                    if (status.equals(CLEARED)) {
                        long now = System.currentTimeMillis();
                        alarmBuilder.clear().withTimeUpdated(now).withTimeCleared(now);
                    }
                    alarms.add(alarmBuilder.build());
                }
            }
        }
    }
    return alarms;
}
Also used : PDU(org.snmp4j.PDU) CommandResponderEvent(org.snmp4j.CommandResponderEvent) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) SeverityLevel(org.onosproject.alarm.Alarm.SeverityLevel) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) HashSet(java.util.HashSet)

Example 3 with SeverityLevel

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

the class PolatisAlarmConsumer method parseAlarm.

private Alarm parseAlarm(HierarchicalConfiguration cfg) {
    boolean cleared = false;
    String alarmType = cfg.getString(ALARM_TYPE);
    String alarmMessage = cfg.getString(ALARM_MESSAGE);
    SeverityLevel alarmLevel = SeverityLevel.INDETERMINATE;
    if (alarmType.equals(ALARM_TYPE_LOS)) {
        alarmLevel = SeverityLevel.MAJOR;
    }
    long timeRaised = getTimeRaised(cfg);
    DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(AlarmId.alarmId(deviceId, alarmMessage), deviceId, alarmMessage, alarmLevel, timeRaised);
    return alarmBuilder.build();
}
Also used : SeverityLevel(org.onosproject.alarm.Alarm.SeverityLevel) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Aggregations

SeverityLevel (org.onosproject.alarm.Alarm.SeverityLevel)3 DefaultAlarm (org.onosproject.alarm.DefaultAlarm)3 Alarm (org.onosproject.alarm.Alarm)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 NetconfException (org.onosproject.netconf.NetconfException)1 CommandResponderEvent (org.snmp4j.CommandResponderEvent)1 PDU (org.snmp4j.PDU)1