kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 1 | /* |
Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame^] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.provider.snmp.alarm.impl; |
| 17 | |
| 18 | import com.btisystems.mibbler.mibs.netsnmp.netsnmp.I_Device; |
| 19 | import com.btisystems.mibbler.mibs.netsnmp.netsnmp._OidRegistry; |
| 20 | import com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.interfaces.IfTable; |
| 21 | import com.btisystems.pronx.ems.core.model.ClassRegistry; |
| 22 | import com.btisystems.pronx.ems.core.model.IClassRegistry; |
| 23 | import com.btisystems.pronx.ems.core.model.NetworkDevice; |
| 24 | import com.btisystems.pronx.ems.core.snmp.ISnmpSession; |
| 25 | import java.io.IOException; |
| 26 | import java.util.Arrays; |
| 27 | import java.util.Collection; |
| 28 | import java.util.HashSet; |
| 29 | import java.util.Set; |
| 30 | import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; |
| 31 | import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId; |
| 32 | import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; |
| 33 | import org.onosproject.net.DeviceId; |
| 34 | import org.slf4j.Logger; |
| 35 | import static org.slf4j.LoggerFactory.getLogger; |
| 36 | import org.snmp4j.smi.OID; |
| 37 | |
| 38 | /** |
| 39 | * Net SNMP specific implementation to provide a list of current alarms. |
Andrea Campanella | 3eca4a8 | 2016-02-10 17:35:14 -0800 | [diff] [blame] | 40 | * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture. |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 41 | */ |
Andrea Campanella | 3eca4a8 | 2016-02-10 17:35:14 -0800 | [diff] [blame] | 42 | @Deprecated |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 43 | public class NetSnmpAlarmProvider implements SnmpDeviceAlarmProvider { |
| 44 | private final Logger log = getLogger(getClass()); |
| 45 | protected static final IClassRegistry CLASS_REGISTRY = |
| 46 | new ClassRegistry(_OidRegistry.oidRegistry, I_Device.class); |
| 47 | @Override |
| 48 | public Collection<Alarm> getAlarms(ISnmpSession session, DeviceId deviceId) { |
| 49 | Set<Alarm> alarms = new HashSet<>(); |
| 50 | |
| 51 | NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY, |
| 52 | session.getAddress().getHostAddress()); |
| 53 | try { |
| 54 | session.walkDevice(networkDevice, Arrays.asList(new OID[]{ |
| 55 | CLASS_REGISTRY.getClassToOidMap().get(IfTable.class)})); |
| 56 | |
| 57 | IfTable interfaceTable = (IfTable) networkDevice.getRootObject() |
| 58 | .getEntity(CLASS_REGISTRY.getClassToOidMap().get(IfTable.class)); |
| 59 | if (interfaceTable != null) { |
| 60 | interfaceTable.getEntries().values().stream().forEach((ifEntry) -> { |
| 61 | //TODO will raise alarm for each interface as a demo. |
| 62 | // if (ifEntry.getIfAdminStatus() == 1 && ifEntry.getIfOperStatus() == 2){ |
| 63 | alarms.add(new DefaultAlarm.Builder(deviceId, "Link Down.", |
| 64 | Alarm.SeverityLevel.CRITICAL, System.currentTimeMillis()) |
| 65 | .forSource(AlarmEntityId.alarmEntityId("port:" + ifEntry.getIfDescr())).build()); |
| 66 | // } |
| 67 | log.info("Interface: " + ifEntry); |
| 68 | }); |
| 69 | } |
| 70 | } catch (IOException ex) { |
| 71 | log.error("Error reading alarms for device {}.", deviceId, ex); |
| 72 | } |
| 73 | return alarms; |
| 74 | } |
| 75 | } |