1 | <?php |
||
2 | |||
3 | namespace LibreNMS\OS; |
||
4 | |||
5 | use LibreNMS\Device\WirelessSensor; |
||
6 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery; |
||
7 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessMseDiscovery; |
||
8 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessRateDiscovery; |
||
9 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery; |
||
10 | use LibreNMS\OS; |
||
11 | |||
12 | class SmOs extends OS implements |
||
13 | WirelessRateDiscovery, |
||
14 | WirelessRssiDiscovery, |
||
15 | WirelessFrequencyDiscovery, |
||
16 | WirelessMseDiscovery |
||
17 | { |
||
18 | private $radioLabels; |
||
19 | private $linkLabels; |
||
20 | |||
21 | public function discoverWirelessRate() |
||
22 | { |
||
23 | $oids = snmpwalk_group($this->getDeviceArray(), 'linkTxETHCapacity', 'SIAE-RADIO-SYSTEM-MIB', 2); |
||
24 | $oids = snmpwalk_group($this->getDeviceArray(), 'linkRxETHCapacity', 'SIAE-RADIO-SYSTEM-MIB', 2, $oids); |
||
25 | $sensors = []; |
||
26 | |||
27 | foreach ($oids as $link => $radioEntry) { |
||
28 | $totalOids = ['rx' => [], 'tx' => []]; |
||
29 | |||
30 | foreach ($radioEntry as $radio => $entry) { |
||
31 | $index = "$link.$radio"; |
||
32 | if (isset($entry['linkTxETHCapacity'])) { |
||
33 | $txOid = '.1.3.6.1.4.1.3373.1103.80.17.1.10.' . $index; |
||
34 | $totalOids['tx'][] = $txOid; |
||
35 | $sensors[] = new WirelessSensor( |
||
36 | 'rate', |
||
37 | $this->getDeviceId(), |
||
38 | $txOid, |
||
39 | 'tx', |
||
40 | $index, |
||
41 | $this->getLinkLabel($link) . ' Tx ' . $this->getRadioLabel($radio), |
||
42 | $entry['linkTxETHCapacity'], |
||
43 | 1000 |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | if (isset($entry['linkRxETHCapacity'])) { |
||
48 | $rxOid = '.1.3.6.1.4.1.3373.1103.80.17.1.11.' . $index; |
||
49 | $totalOids['rx'][] = $rxOid; |
||
50 | $sensors[] = new WirelessSensor( |
||
51 | 'rate', |
||
52 | $this->getDeviceId(), |
||
53 | $rxOid, |
||
54 | 'rx', |
||
55 | $index, |
||
56 | $this->getLinkLabel($link) . ' Rx ' . $this->getRadioLabel($radio), |
||
57 | $entry['linkRxETHCapacity'], |
||
58 | 1000 |
||
59 | ); |
||
60 | } |
||
61 | } |
||
62 | |||
63 | if (! empty($totalOids['rx'])) { |
||
64 | $sensors[] = new WirelessSensor( |
||
65 | 'rate', |
||
66 | $this->getDeviceId(), |
||
67 | $totalOids['rx'], |
||
68 | 'total-rx', |
||
69 | $index, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
70 | $this->getLinkLabel($link) . ' Total Rx', |
||
71 | array_sum(array_column($radioEntry, 'linkRxETHCapacity')), |
||
72 | 1000 |
||
73 | ); |
||
74 | } |
||
75 | |||
76 | if (! empty($totalOids['tx'])) { |
||
77 | $sensors[] = new WirelessSensor( |
||
78 | 'rate', |
||
79 | $this->getDeviceId(), |
||
80 | $totalOids['tx'], |
||
81 | 'total-tx', |
||
82 | $index, |
||
83 | $this->getLinkLabel($link) . ' Total Tx', |
||
84 | array_sum(array_column($radioEntry, 'linkTxETHCapacity')), |
||
85 | 1000 |
||
86 | ); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | return $sensors; |
||
91 | } |
||
92 | |||
93 | public function discoverWirelessRssi() |
||
94 | { |
||
95 | $oids = snmpwalk_cache_oid($this->getDeviceArray(), 'radioPrx', [], 'SIAE-RADIO-SYSTEM-MIB'); |
||
96 | $sensors = []; |
||
97 | |||
98 | foreach ($oids as $index => $entry) { |
||
99 | $sensors[] = new WirelessSensor( |
||
100 | 'rssi', |
||
101 | $this->getDeviceId(), |
||
102 | '.1.3.6.1.4.1.3373.1103.80.12.1.3.' . $index, |
||
103 | 'sm-os', |
||
104 | $index, |
||
105 | $this->getRadioLabel($index), |
||
106 | $entry['radioPrx'] |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | return $sensors; |
||
111 | } |
||
112 | |||
113 | public function discoverWirelessFrequency() |
||
114 | { |
||
115 | $oids = snmpwalk_cache_oid($this->getDeviceArray(), 'radioTxFrequency', [], 'SIAE-RADIO-SYSTEM-MIB'); |
||
116 | $sensors = []; |
||
117 | |||
118 | foreach ($oids as $index => $entry) { |
||
119 | $sensors[] = new WirelessSensor( |
||
120 | 'frequency', |
||
121 | $this->getDeviceId(), |
||
122 | '.1.3.6.1.4.1.3373.1103.80.9.1.4.' . $index, |
||
123 | 'sm-os', |
||
124 | $index, |
||
125 | 'Tx ' . $this->getRadioLabel($index), |
||
126 | $entry['radioTxFrequency'], |
||
127 | 1, |
||
128 | 1000 |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | return $sensors; |
||
133 | } |
||
134 | |||
135 | public function discoverWirelessMse() |
||
136 | { |
||
137 | $oids = snmpwalk_cache_oid($this->getDeviceArray(), 'radioNormalizedMse', [], 'SIAE-RADIO-SYSTEM-MIB'); |
||
138 | $sensors = []; |
||
139 | |||
140 | foreach ($oids as $index => $entry) { |
||
141 | $sensors[] = new WirelessSensor( |
||
142 | 'mse', |
||
143 | $this->getDeviceId(), |
||
144 | '.1.3.6.1.4.1.3373.1103.80.12.1.5.' . $index, |
||
145 | 'sm-os', |
||
146 | $index, |
||
147 | $this->getRadioLabel($index), |
||
148 | $entry['radioNormalizedMse'] |
||
149 | ); |
||
150 | } |
||
151 | |||
152 | return $sensors; |
||
153 | } |
||
154 | |||
155 | public function getRadioLabel($index) |
||
156 | { |
||
157 | if (is_null($this->radioLabels)) { |
||
158 | $this->radioLabels = snmpwalk_group($this->getDeviceArray(), 'radioLabel', 'SIAE-RADIO-SYSTEM-MIB'); |
||
159 | } |
||
160 | |||
161 | return $this->radioLabels[$index]['radioLabel'] ?? $index; |
||
162 | } |
||
163 | |||
164 | public function getLinkLabel($index) |
||
165 | { |
||
166 | if (is_null($this->linkLabels)) { |
||
167 | $this->linkLabels = snmpwalk_group($this->getDeviceArray(), 'linkLabel', 'SIAE-RADIO-SYSTEM-MIB'); |
||
168 | } |
||
169 | |||
170 | return $this->linkLabels[$index]['linkLabel'] ?? $index; |
||
171 | } |
||
172 | } |
||
173 |