Search in sources :

Example 16 with Alarm

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

the class AlarmCodec method decode.

@Override
public Alarm decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    log.debug("id={}, full json={} ", json.get("id"), json);
    String id = json.get("id").asText();
    DeviceId deviceId = DeviceId.deviceId(json.get("deviceId").asText());
    String description = json.get("description").asText();
    Long timeRaised = json.get("timeRaised").asLong();
    Long timeUpdated = json.get("timeUpdated").asLong();
    JsonNode jsonTimeCleared = json.get("timeCleared");
    Long timeCleared = jsonTimeCleared == null || jsonTimeCleared.isNull() ? null : jsonTimeCleared.asLong();
    Alarm.SeverityLevel severity = Alarm.SeverityLevel.valueOf(json.get("severity").asText().toUpperCase());
    Boolean serviceAffecting = json.get("serviceAffecting").asBoolean();
    Boolean acknowledged = json.get("acknowledged").asBoolean();
    Boolean manuallyClearable = json.get("manuallyClearable").asBoolean();
    JsonNode jsonAssignedUser = json.get("assignedUser");
    String assignedUser = jsonAssignedUser == null || jsonAssignedUser.isNull() ? null : jsonAssignedUser.asText();
    return new DefaultAlarm.Builder(AlarmId.alarmId(deviceId, id), deviceId, description, severity, timeRaised).forSource(AlarmEntityId.NONE).withTimeUpdated(timeUpdated).withTimeCleared(timeCleared).withServiceAffecting(serviceAffecting).withAcknowledged(acknowledged).withManuallyClearable(manuallyClearable).withAssignedUser(assignedUser).build();
}
Also used : DeviceId(org.onosproject.net.DeviceId) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 17 with Alarm

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

the class AlarmsWebResource method getAlarms.

/**
 * Get alarms. Returns a list of alarms
 *
 * @param includeCleared (optional) include recently cleared alarms in response
 * @param devId          (optional) include only for specified device
 * @return JSON encoded set of alarms
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAlarms(@DefaultValue("false") @QueryParam("includeCleared") boolean includeCleared, @DefaultValue("") @QueryParam("devId") String devId) {
    log.debug("Requesting all alarms, includeCleared={}", includeCleared);
    AlarmService service = get(AlarmService.class);
    Iterable<Alarm> alarms;
    if (StringUtils.isBlank(devId)) {
        alarms = includeCleared ? service.getAlarms() : service.getActiveAlarms();
    } else {
        alarms = service.getAlarms(DeviceId.deviceId(devId));
    }
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("alarms", new AlarmCodec().encode(alarms, this));
    return ok(result.toString()).build();
}
Also used : AlarmService(org.onosproject.alarm.AlarmService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Alarm(org.onosproject.alarm.Alarm) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 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 19 with Alarm

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

the class UpdateAlarm method doExecute.

@Override
protected void doExecute() {
    Alarm existing = alarmStore.getAlarm(AlarmId.alarmId(alarmId));
    DefaultAlarm.Builder newAlarmBuilder = new DefaultAlarm.Builder(existing);
    UpdateAlarm.AlarmField field = UpdateAlarm.AlarmField.valueOf(alarmField);
    switch(field) {
        case SOURCE:
            AlarmEntityId sourceId = AlarmEntityId.alarmEntityId(alarmFieldValue);
            newAlarmBuilder.forSource(sourceId);
            break;
        case ASSIGNED_USER:
            newAlarmBuilder.withAssignedUser(alarmFieldValue);
            break;
        case ACKNOWLEDGED:
            newAlarmBuilder.withAcknowledged("TRUE".equalsIgnoreCase(alarmFieldValue));
            break;
        case MANUALLY_CLEARABLE:
            newAlarmBuilder.withManuallyClearable("TRUE".equalsIgnoreCase(alarmFieldValue));
            break;
        case SERVICE_AFFECTING:
            newAlarmBuilder.withServiceAffecting("TRUE".equalsIgnoreCase(alarmFieldValue));
            break;
        case TIME_CLEARED:
            newAlarmBuilder.clear();
            newAlarmBuilder.withTimeCleared(Instant.parse(alarmFieldValue).toEpochMilli());
            break;
        case TIME_UPDATED:
        default:
            newAlarmBuilder.withTimeUpdated(Instant.parse(alarmFieldValue).toEpochMilli());
            break;
    }
    alarmStore.createOrUpdateAlarm(newAlarmBuilder.build());
}
Also used : Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) AlarmEntityId(org.onosproject.alarm.AlarmEntityId) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Example 20 with Alarm

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

the class CreateAlarm method doExecute.

@Override
protected void doExecute() {
    DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
    if (!deviceManager.isAvailable(deviceId)) {
        throw new IllegalArgumentException("Device " + deviceIdStr + " is not available");
    }
    Alarm.SeverityLevel severityLevel = Alarm.SeverityLevel.valueOf(severityStr);
    Alarm newAlarm = new DefaultAlarm.Builder(AlarmId.alarmId(deviceId, alarmId), deviceId, desc, severityLevel, Instant.now().toEpochMilli()).build();
    alarmStore.createOrUpdateAlarm(newAlarm);
}
Also used : DeviceId(org.onosproject.net.DeviceId) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) 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