1 | <?php |
||
2 | /** |
||
3 | * Ceraos.php |
||
4 | * |
||
5 | * Ceragon CeraOS |
||
6 | * |
||
7 | * This program is free software: you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation, either version 3 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * This program is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License |
||
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
19 | * |
||
20 | * @link https://www.librenms.org |
||
21 | * |
||
22 | * @copyright 2018 Tony Murray |
||
23 | * @author Tony Murray <[email protected]> |
||
24 | */ |
||
25 | |||
26 | namespace LibreNMS\OS; |
||
27 | |||
28 | use App\Models\Device; |
||
29 | use Illuminate\Support\Str; |
||
30 | use LibreNMS\Device\WirelessSensor; |
||
31 | use LibreNMS\Interfaces\Discovery\OSDiscovery; |
||
32 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessErrorsDiscovery; |
||
33 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery; |
||
34 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessMseDiscovery; |
||
35 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery; |
||
36 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessRateDiscovery; |
||
37 | use LibreNMS\Interfaces\Discovery\Sensors\WirelessXpiDiscovery; |
||
38 | use LibreNMS\OS; |
||
39 | |||
40 | class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFrequencyDiscovery, WirelessErrorsDiscovery, WirelessMseDiscovery, WirelessPowerDiscovery, WirelessRateDiscovery |
||
41 | { |
||
42 | public function discoverOS(Device $device): void |
||
43 | { |
||
44 | $device->hardware = $this->fetchHardware(); |
||
45 | |||
46 | $sn_oid = Str::contains($device->hardware, 'IP10') ? 'genEquipUnitIDUSerialNumber.0' : 'genEquipInventorySerialNumber.127'; |
||
47 | $device->serial = snmp_get($this->getDeviceArray(), $sn_oid, '-Oqv', 'MWRM-UNIT-MIB'); |
||
48 | |||
49 | $data = snmp_get_multi($this->getDeviceArray(), ['genEquipMngSwIDUVersionsRunningVersion.1', 'genEquipUnitLatitude.0', 'genEquipUnitLongitude.0'], '-OQU', 'MWRM-RADIO-MIB'); |
||
50 | $device->version = $data[1]['MWRM-UNIT-MIB::genEquipMngSwIDUVersionsRunningVersion'] ?? null; |
||
51 | |||
52 | // update location lat/lng |
||
53 | if ($device->location && (! empty($multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLatitude']) || ! empty($multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLongitude']))) { |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
54 | $device->location->lat = $multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLatitude'] ?? $device->location->lat; |
||
55 | $device->location->lng = $multi_get_array[0]['MWRM-UNIT-MIB::genEquipUnitLongitude'] ?? $device->location->lng; |
||
56 | $device->location->save(); |
||
57 | } |
||
58 | |||
59 | $num_radios = 0; |
||
60 | foreach (snmpwalk_group($this->getDeviceArray(), 'ifDescr', 'IF-MIB') as $interface) { |
||
61 | if ($interface['ifDescr'] == 'Radio') { |
||
62 | $num_radios++; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | $device->features = $num_radios . ' radios in unit'; |
||
67 | } |
||
68 | |||
69 | public function discoverWirelessXpi() |
||
70 | { |
||
71 | $ifNames = $this->getCacheByIndex('ifName', 'IF-MIB'); |
||
72 | |||
73 | $sensors = []; |
||
74 | $divisor = 100; |
||
75 | |||
76 | $xpi = snmpwalk_group($this->getDeviceArray(), 'genEquipRadioStatusXPI', 'MWRM-RADIO-MIB'); |
||
77 | foreach ($xpi as $index => $data) { |
||
78 | $sensors[] = new WirelessSensor( |
||
79 | 'xpi', |
||
80 | $this->getDeviceId(), |
||
81 | '.1.3.6.1.4.1.2281.10.7.1.1.5.' . $index, |
||
82 | 'ceraos', |
||
83 | $index, |
||
84 | $ifNames[$index], |
||
85 | $data['genEquipRadioStatusXPI'] / $divisor, |
||
86 | 1, |
||
87 | $divisor |
||
88 | ); |
||
89 | } |
||
90 | |||
91 | return $sensors; |
||
92 | } |
||
93 | |||
94 | public function discoverWirelessFrequency() |
||
95 | { |
||
96 | $sensors = []; |
||
97 | // MWRM-RADIO-MIB::genEquipRfuCfgTxFreq |
||
98 | $tx = snmpwalk_group($this->getDeviceArray(), 'genEquipRfuCfgTxFreq', 'MWRM-RADIO-MIB'); |
||
99 | $TxRadio = 0; |
||
100 | foreach ($tx as $index => $data) { |
||
101 | $TxRadio++; |
||
102 | $sensors[] = new WirelessSensor( |
||
103 | 'frequency', |
||
104 | $this->getDeviceId(), |
||
105 | '.1.3.6.1.4.1.2281.10.5.2.1.3.' . $index, |
||
106 | 'Ceraos-tx-radio ' . $TxRadio, |
||
107 | 1, |
||
108 | 'Tx Frequency Radio ' . $TxRadio, |
||
109 | null, |
||
110 | 1, |
||
111 | 1000 |
||
112 | ); |
||
113 | } |
||
114 | // MWRM-RADIO-MIB::genEquipRfuCfgRxFreq |
||
115 | $rx = snmpwalk_group($this->getDeviceArray(), 'genEquipRfuCfgRxFreq', 'MWRM-RADIO-MIB'); |
||
116 | $RxRadio = 0; |
||
117 | foreach ($rx as $index => $data) { |
||
118 | $RxRadio++; |
||
119 | $sensors[] = new WirelessSensor( |
||
120 | 'frequency', |
||
121 | $this->getDeviceId(), |
||
122 | '.1.3.6.1.4.1.2281.10.5.2.1.4.' . $index, |
||
123 | 'Ceraos-rx-radio ' . $RxRadio, |
||
124 | 1, |
||
125 | 'Rx Frequency Radio ' . $RxRadio, |
||
126 | null, |
||
127 | 1, |
||
128 | 1000 |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | return $sensors; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Discover wireless rate. This is in bps. Type is rate. |
||
137 | * Returns an array of LibreNMS\Device\Sensor objects that have been discovered |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | public function discoverWirelessRate() |
||
142 | { |
||
143 | $ifNames = $this->getCacheByIndex('ifName', 'IF-MIB'); |
||
144 | |||
145 | $sensors = []; |
||
146 | |||
147 | $tx = snmpwalk_group($this->getDeviceArray(), 'genEquipRadioMRMCCurrTxBitrate', 'MWRM-RADIO-MIB'); |
||
148 | foreach ($tx as $index => $data) { |
||
149 | $sensors[] = new WirelessSensor( |
||
150 | 'rate', |
||
151 | $this->getDeviceId(), |
||
152 | '.1.3.6.1.4.1.2281.10.7.4.1.1.7.' . $index, |
||
153 | 'ceraos-tx', |
||
154 | $index, |
||
155 | $ifNames[$index] . ' TX Bitrate', |
||
156 | $data['genEquipRadioMRMCCurrTxBitrate'], |
||
157 | 1000 |
||
158 | ); |
||
159 | } |
||
160 | |||
161 | $rx = snmpwalk_group($this->getDeviceArray(), 'genEquipRadioMRMCCurrRxBitrate', 'MWRM-RADIO-MIB'); |
||
162 | foreach ($rx as $index => $data) { |
||
163 | $sensors[] = new WirelessSensor( |
||
164 | 'rate', |
||
165 | $this->getDeviceId(), |
||
166 | '.1.3.6.1.4.1.2281.10.7.4.1.1.11.' . $index, |
||
167 | 'ceraos-rx', |
||
168 | $index, |
||
169 | $ifNames[$index] . ' RX Bitrate', |
||
170 | $data['genEquipRadioMRMCCurrRxBitrate'], |
||
171 | 1000 |
||
172 | ); |
||
173 | } |
||
174 | |||
175 | return $sensors; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Discover wireless bit errors. This is in total bits. Type is errors. |
||
180 | * Returns an array of LibreNMS\Device\Sensor objects that have been discovered |
||
181 | * |
||
182 | * @return array Sensors |
||
183 | */ |
||
184 | public function discoverWirelessErrors() |
||
185 | { |
||
186 | $ifNames = $this->getCacheByIndex('ifName', 'IF-MIB'); |
||
187 | |||
188 | $sensors = []; |
||
189 | |||
190 | $mse = snmpwalk_group($this->getDeviceArray(), 'genEquipRadioStatusDefectedBlocks', 'MWRM-RADIO-MIB'); |
||
191 | foreach ($mse as $index => $data) { |
||
192 | $sensors[] = new WirelessSensor( |
||
193 | 'errors', |
||
194 | $this->getDeviceId(), |
||
195 | '.1.3.6.1.4.1.2281.10.7.1.1.3.' . $index, |
||
196 | 'ceraos', |
||
197 | $index, |
||
198 | $ifNames[$index] . ' Defected Blocks', |
||
199 | $data['genEquipRadioStatusDefectedBlocks'] |
||
200 | ); |
||
201 | } |
||
202 | |||
203 | return $sensors; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Discover wireless MSE. Mean square error value in dB. Type is mse. |
||
208 | * Returns an array of LibreNMS\Device\Sensor objects that have been discovered |
||
209 | * |
||
210 | * @return array Sensors |
||
211 | */ |
||
212 | public function discoverWirelessMse() |
||
213 | { |
||
214 | $ifNames = $this->getCacheByIndex('ifName', 'IF-MIB'); |
||
215 | |||
216 | $sensors = []; |
||
217 | $divisor = 100; |
||
218 | |||
219 | $mse = snmpwalk_group($this->getDeviceArray(), 'genEquipRadioStatusMSE', 'MWRM-RADIO-MIB'); |
||
220 | foreach ($mse as $index => $data) { |
||
221 | $sensors[] = new WirelessSensor( |
||
222 | 'mse', |
||
223 | $this->getDeviceId(), |
||
224 | '.1.3.6.1.4.1.2281.10.7.1.1.2.' . $index, |
||
225 | 'ceraos', |
||
226 | $index, |
||
227 | $ifNames[$index], |
||
228 | $data['genEquipRadioStatusMSE'] / $divisor, |
||
229 | 1, |
||
230 | $divisor |
||
231 | ); |
||
232 | } |
||
233 | |||
234 | return $sensors; |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * Discover wireless tx or rx power. This is in dBm. Type is power. |
||
239 | * Returns an array of LibreNMS\Device\Sensor objects that have been discovered |
||
240 | * |
||
241 | * @return array |
||
242 | */ |
||
243 | public function discoverWirelessPower() |
||
244 | { |
||
245 | $ifNames = $this->getCacheByIndex('ifName', 'IF-MIB'); |
||
246 | |||
247 | $sensors = []; |
||
248 | |||
249 | $tx = snmpwalk_group($this->getDeviceArray(), 'genEquipRfuStatusTxLevel', 'MWRM-RADIO-MIB'); |
||
250 | foreach ($tx as $index => $data) { |
||
251 | $sensors[] = new WirelessSensor( |
||
252 | 'power', |
||
253 | $this->getDeviceId(), |
||
254 | '.1.3.6.1.4.1.2281.10.5.1.1.3.' . $index, |
||
255 | 'ceraos-tx', |
||
256 | $index, |
||
257 | $ifNames[$index] . ' TX Level', |
||
258 | $data['genEquipRfuStatusTxLevel'] |
||
259 | ); |
||
260 | } |
||
261 | |||
262 | $rx = snmpwalk_group($this->getDeviceArray(), 'genEquipRfuStatusRxLevel', 'MWRM-RADIO-MIB'); |
||
263 | foreach ($rx as $index => $data) { |
||
264 | $sensors[] = new WirelessSensor( |
||
265 | 'power', |
||
266 | $this->getDeviceId(), |
||
267 | '.1.3.6.1.4.1.2281.10.5.1.1.2.' . $index, |
||
268 | 'ceraos-rx', |
||
269 | $index, |
||
270 | $ifNames[$index] . ' RX Level', |
||
271 | $data['genEquipRfuStatusRxLevel'] |
||
272 | ); |
||
273 | } |
||
274 | |||
275 | return $sensors; |
||
276 | } |
||
277 | |||
278 | private function fetchHardware() |
||
279 | { |
||
280 | $sysObjectID = $this->getDevice()->sysObjectID; |
||
281 | |||
282 | if (Str::contains($sysObjectID, '.2281.1.10')) { |
||
283 | return 'IP10 Family'; |
||
284 | } elseif (Str::contains($sysObjectID, '.2281.1.20.1.1.2')) { |
||
285 | return 'IP-20A 1RU'; |
||
286 | } elseif (Str::contains($sysObjectID, '.2281.1.20.1.1.4')) { |
||
287 | return 'IP-20 Evolution LH 1RU'; |
||
288 | } elseif (Str::contains($sysObjectID, '.2281.1.20.1.1')) { |
||
289 | return 'IP-20N 1RU'; |
||
290 | } elseif (Str::contains($sysObjectID, '.2281.1.20.1.2.2')) { |
||
291 | return 'IP-20A 2RU'; |
||
292 | } elseif (Str::contains($sysObjectID, '.2281.1.20.1.2.4')) { |
||
293 | return 'IP-20 Evolution 2RU'; |
||
294 | } elseif (Str::contains($sysObjectID, '.2281.1.20.1.2')) { |
||
295 | return 'IP-20N 2RU'; |
||
296 | } elseif (Str::contains($sysObjectID, '.2281.1.20.1.3.1')) { |
||
297 | return 'IP-20G'; |
||
298 | } elseif (Str::contains($sysObjectID, '.2281.1.20.1.3.2')) { |
||
299 | return 'IP-20GX'; |
||
300 | } elseif (Str::contains($sysObjectID, '.2281.1.20.2.2.2')) { |
||
301 | return 'IP-20S'; |
||
302 | } elseif (Str::contains($sysObjectID, '.2281.1.20.2.2.3')) { |
||
303 | return 'IP-20E (hardware release 1)'; |
||
304 | } elseif (Str::contains($sysObjectID, '.2281.1.20.2.2.4')) { |
||
305 | return 'IP-20E (hardware release 2)'; |
||
306 | } elseif (Str::contains($sysObjectID, '.2281.1.20.2.2')) { |
||
307 | return 'IP-20C'; |
||
308 | } |
||
309 | |||
310 | return snmp_get($this->getDeviceArray(), 'genEquipInventoryCardName', '-Oqv', 'MWRM-UNIT-NAME'); |
||
311 | } |
||
312 | } |
||
313 |