/
LldpLocalGroupTracker.java
131 lines (108 loc) · 4.73 KB
/
LldpLocalGroupTracker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2012 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/
package org.opennms.netmgt.enlinkd.snmp;
import org.opennms.netmgt.model.LldpElement;
import org.opennms.netmgt.model.LldpElement.LldpChassisIdSubType;
import org.opennms.netmgt.snmp.AggregateTracker;
import org.opennms.netmgt.snmp.NamedSnmpVar;
import org.opennms.netmgt.snmp.SnmpResult;
import org.opennms.netmgt.snmp.SnmpStore;
import org.opennms.netmgt.snmp.SnmpValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class LldpLocalGroupTracker extends AggregateTracker {
private final static Logger LOG = LoggerFactory.getLogger(LldpLocalGroupTracker.class);
public final static String LLDP_LOC_CHASSISID_SUBTYPE_ALIAS = "lldpLocChassisIdSubtype";
public final static String LLDP_LOC_CHASSISID_SUBTYPE_OID = ".1.0.8802.1.1.2.1.3.1";
public final static String LLDP_LOC_CHASSISID_ALIAS = "lldpLocChassisId";
public final static String LLDP_LOC_CHASSISID_OID = ".1.0.8802.1.1.2.1.3.2";
public final static String LLDP_LOC_SYSNAME_ALIAS = "lldpLocSysName";
public final static String LLDP_LOC_SYSNAME_OID = ".1.0.8802.1.1.2.1.3.3";
public static NamedSnmpVar[] ms_elemList = null;
static {
ms_elemList = new NamedSnmpVar[3];
int ndx = 0;
/**
* <P>
* "The type of encoding used to identify the chassis
* associated with the local system."
* </P>
*/
ms_elemList[ndx++] = new NamedSnmpVar(NamedSnmpVar.SNMPINT32,LLDP_LOC_CHASSISID_SUBTYPE_ALIAS,LLDP_LOC_CHASSISID_SUBTYPE_OID);
/**
* <P>
* "The string value used to identify the chassis component
* associated with the local system."
* </P>
*/
ms_elemList[ndx++] = new NamedSnmpVar(NamedSnmpVar.SNMPOCTETSTRING,LLDP_LOC_CHASSISID_ALIAS,LLDP_LOC_CHASSISID_OID);
/**
* <P>
* "The string value used to identify the system name of the
* local system. If the local agent supports IETF RFC 3418,
* lldpLocSysName object should have the same value of sysName
* object."
* </P>
*/
ms_elemList[ndx++] = new NamedSnmpVar(NamedSnmpVar.SNMPOCTETSTRING,LLDP_LOC_SYSNAME_ALIAS,LLDP_LOC_SYSNAME_OID);
}
public static final String LLDP_LOC_OID = ".1.0.8802.1.1.2.1.3";
private SnmpStore m_store;
public LldpLocalGroupTracker() {
super(NamedSnmpVar.getTrackersFor(ms_elemList));
m_store = new SnmpStore(ms_elemList);
}
public Integer getLldpLocChassisidSubType() {
return m_store.getInt32(LLDP_LOC_CHASSISID_SUBTYPE_ALIAS);
}
public SnmpValue getLldpLocChassisid() {
return m_store.getValue(LLDP_LOC_CHASSISID_ALIAS);
}
public String getLldpLocSysname() {
return m_store.getDisplayString(LLDP_LOC_SYSNAME_ALIAS);
}
/** {@inheritDoc} */
protected void storeResult(SnmpResult res) {
m_store.storeResult(res);
}
/** {@inheritDoc} */
protected void reportGenErr(String msg) {
LOG.warn("Error retrieving lldpLocalGroup: {}",msg);
}
/** {@inheritDoc} */
protected void reportNoSuchNameErr(String msg) {
LOG.info("Error retrieving lldpLocalGroup: {}",msg);
}
public LldpElement getLldpElement() {
LldpElement lldpElement = new LldpElement();
lldpElement.setLldpChassisId(LldpHelper.decodeLldpChassisId(getLldpLocChassisid(), getLldpLocChassisidSubType()));
lldpElement.setLldpChassisIdSubType(LldpChassisIdSubType.get(getLldpLocChassisidSubType()));
lldpElement.setLldpSysname(getLldpLocSysname());
return lldpElement;
}
}