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();
}
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;
}
}
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);
}
Aggregations