blob: 47e62de3d587eeba8dd84e3b4ee9c0af7e99f49f [file] [log] [blame]
kmcpeakeb172d5f2015-12-10 11:30:43 +00001/*
Brian O'Connor7cbbbb72016-04-09 02:13:23 -07002 * Copyright 2015-present Open Networking Laboratory
kmcpeakeb172d5f2015-12-10 11:30:43 +00003 *
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'Connor7cbbbb72016-04-09 02:13:23 -07008 * http://www.apache.org/licenses/LICENSE-2.0
kmcpeakeb172d5f2015-12-10 11:30:43 +00009 *
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 */
16package org.onosproject.provider.snmp.alarm.impl;
17
18import com.btisystems.mibbler.mibs.netsnmp.netsnmp.I_Device;
19import com.btisystems.mibbler.mibs.netsnmp.netsnmp._OidRegistry;
20import com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.interfaces.IfTable;
21import com.btisystems.pronx.ems.core.model.ClassRegistry;
22import com.btisystems.pronx.ems.core.model.IClassRegistry;
23import com.btisystems.pronx.ems.core.model.NetworkDevice;
24import com.btisystems.pronx.ems.core.snmp.ISnmpSession;
25import java.io.IOException;
26import java.util.Arrays;
27import java.util.Collection;
28import java.util.HashSet;
29import java.util.Set;
30import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
31import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId;
32import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
33import org.onosproject.net.DeviceId;
34import org.slf4j.Logger;
35import static org.slf4j.LoggerFactory.getLogger;
36import org.snmp4j.smi.OID;
37
38/**
39 * Net SNMP specific implementation to provide a list of current alarms.
Andrea Campanella3eca4a82016-02-10 17:35:14 -080040 * @deprecated 1.5.0 Falcon, not compliant with ONOS SB and driver architecture.
kmcpeakeb172d5f2015-12-10 11:30:43 +000041 */
Andrea Campanella3eca4a82016-02-10 17:35:14 -080042@Deprecated
kmcpeakeb172d5f2015-12-10 11:30:43 +000043public 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}