Search in sources :

Example 1 with AlarmId

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

the class AlarmsWebResource method getAlarm.

/**
 * Get specified alarm. Returns details of the specified alarm.
 *
 * @param id ONOS allocated identifier
 * @return JSON encoded alarm
 */
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getAlarm(@PathParam("id") String id) {
    log.debug("HTTP GET alarm for id={}", id);
    AlarmId alarmId = AlarmId.alarmId(id);
    Alarm alarm = get(AlarmService.class).getAlarm(alarmId);
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("alarm", new AlarmCodec().encode(alarm, this));
    return ok(result.toString()).build();
}
Also used : AlarmId(org.onosproject.alarm.AlarmId) AlarmService(org.onosproject.alarm.AlarmService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Alarm(org.onosproject.alarm.Alarm) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with AlarmId

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

the class CienaRestDevice method newAlarmFromJsonNode.

private Alarm newAlarmFromJsonNode(JsonNode jsonNode) {
    try {
        AlarmId alarmId = AlarmId.alarmId(checkNotNull(jsonNode.get(ALARM_INSTANCE_ID)).asText());
        String time = checkNotNull(jsonNode.get(ALARM_LOCAL_DATE_TIME)).asText();
        String instance = checkNotNull(jsonNode.get(INSTANCE).asText()).toLowerCase();
        String description = checkNotNull(jsonNode.get(DESCRIPTION)).asText() + " - " + instance + " - " + time;
        AlarmEntityId source = getAlarmSource(instance);
        Alarm.SeverityLevel severity = Alarm.SeverityLevel.valueOf(checkNotNull(jsonNode.get(SEVERITY)).asText().toUpperCase());
        long timeRaised = parseAlarmTime(time);
        boolean isAcknowledged = checkNotNull(jsonNode.get(ACKNOWLEDGE)).asBoolean();
        return new DefaultAlarm.Builder(alarmId, deviceId, description, severity, timeRaised).withAcknowledged(isAcknowledged).forSource(source).build();
    } catch (NullPointerException e) {
        log.error("got exception while parsing alarm json node {} for device {}:\n", jsonNode, deviceId, e);
        return null;
    }
}
Also used : AlarmId(org.onosproject.alarm.AlarmId) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) AlarmEntityId(org.onosproject.alarm.AlarmEntityId) DefaultAlarm(org.onosproject.alarm.DefaultAlarm)

Example 3 with AlarmId

use of org.onosproject.alarm.AlarmId 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)

Aggregations

Alarm (org.onosproject.alarm.Alarm)3 AlarmId (org.onosproject.alarm.AlarmId)3 DefaultAlarm (org.onosproject.alarm.DefaultAlarm)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 SeverityLevel (org.onosproject.alarm.Alarm.SeverityLevel)1 AlarmConsumer (org.onosproject.alarm.AlarmConsumer)1 AlarmEntityId (org.onosproject.alarm.AlarmEntityId)1 AlarmService (org.onosproject.alarm.AlarmService)1 DeviceId (org.onosproject.net.DeviceId)1 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)1 SnmpController (org.onosproject.snmp.SnmpController)1