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