Search in sources :

Example 1 with SnmpController

use of org.onosproject.snmp.SnmpController 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 2 with SnmpController

use of org.onosproject.snmp.SnmpController in project onos by opennetworkinglab.

the class PolatisSnmpUtility method getDevice.

private static SnmpDevice getDevice(DriverHandler handler) {
    SnmpController controller = checkNotNull(handler.get(SnmpController.class));
    SnmpDevice device = controller.getDevice(handler.data().deviceId());
    return device;
}
Also used : SnmpDevice(org.onosproject.snmp.SnmpDevice) SnmpController(org.onosproject.snmp.SnmpController)

Aggregations

SnmpController (org.onosproject.snmp.SnmpController)2 SnmpDevice (org.onosproject.snmp.SnmpDevice)2 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 Alarm (org.onosproject.alarm.Alarm)1 SeverityLevel (org.onosproject.alarm.Alarm.SeverityLevel)1 AlarmConsumer (org.onosproject.alarm.AlarmConsumer)1 AlarmId (org.onosproject.alarm.AlarmId)1 DefaultAlarm (org.onosproject.alarm.DefaultAlarm)1 DeviceId (org.onosproject.net.DeviceId)1 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)1 Logger (org.slf4j.Logger)1 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)1 OID (org.snmp4j.smi.OID)1 VariableBinding (org.snmp4j.smi.VariableBinding)1 TreeEvent (org.snmp4j.util.TreeEvent)1