1 | <?php |
||
2 | /* |
||
3 | * Unix.php |
||
4 | * |
||
5 | * -Description- |
||
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 | * @package LibreNMS |
||
21 | * @link https://www.librenms.org |
||
22 | * @copyright 2020 Tony Murray |
||
23 | * @author Tony Murray <[email protected]> |
||
24 | */ |
||
25 | |||
26 | namespace LibreNMS\OS\Shared; |
||
27 | |||
28 | use App\Models\Device; |
||
29 | use Illuminate\Support\Str; |
||
30 | use LibreNMS\Interfaces\Discovery\MempoolsDiscovery; |
||
31 | use LibreNMS\OS\Traits\ServerHardware; |
||
32 | use LibreNMS\OS\Traits\YamlOSDiscovery; |
||
33 | |||
34 | class Unix extends \LibreNMS\OS implements MempoolsDiscovery |
||
35 | { |
||
36 | use ServerHardware; |
||
37 | use YamlOSDiscovery { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
38 | YamlOSDiscovery::discoverOS as discoverYamlOS; |
||
39 | } |
||
40 | |||
41 | public function discoverOS(Device $device): void |
||
42 | { |
||
43 | // yaml discovery overrides this |
||
44 | if ($this->hasYamlDiscovery('os')) { |
||
45 | $this->discoverYamlOS($device); |
||
46 | $this->discoverServerHardware(); |
||
47 | $this->discoverExtends($device); |
||
48 | |||
49 | return; |
||
50 | } |
||
51 | |||
52 | preg_match('/ (\d+\.\d\S*) /', $device->sysDescr, $matches); |
||
53 | $device->version = $matches[1] ?? $device->version; |
||
54 | if (preg_match('/i[3-6]86/', $device->sysDescr)) { |
||
55 | $device->hardware = 'Generic x86'; |
||
56 | } elseif (Str::contains($device->sysDescr, 'x86_64')) { |
||
57 | $device->hardware = 'Generic x86 64-bit'; |
||
58 | } elseif (Str::contains($device->sysDescr, 'sparc32')) { |
||
59 | $device->hardware = 'Generic SPARC 32-bit'; |
||
60 | } elseif (Str::contains($device->sysDescr, 'sparc64')) { |
||
61 | $device->hardware = 'Generic SPARC 64-bit'; |
||
62 | } elseif (Str::contains($device->sysDescr, 'mips')) { |
||
63 | $device->hardware = 'Generic MIPS'; |
||
64 | } elseif (Str::contains($device->sysDescr, 'armv5')) { |
||
65 | $device->hardware = 'Generic ARMv5'; |
||
66 | } elseif (Str::contains($device->sysDescr, 'armv6')) { |
||
67 | $device->hardware = 'Generic ARMv6'; |
||
68 | } elseif (Str::contains($device->sysDescr, 'armv7')) { |
||
69 | $device->hardware = 'Generic ARMv7'; |
||
70 | } elseif (Str::contains($device->sysDescr, 'aarch64')) { |
||
71 | $device->hardware = 'Generic ARMv8 64-bit'; |
||
72 | } elseif (Str::contains($device->sysDescr, 'armv')) { |
||
73 | $device->hardware = 'Generic ARM'; |
||
74 | } |
||
75 | |||
76 | $this->discoverServerHardware(); |
||
77 | $this->discoverExtends($device); |
||
78 | } |
||
79 | |||
80 | protected function discoverExtends(Device $device) |
||
81 | { |
||
82 | // Distro "extend" support |
||
83 | $features_extend = snmp_get_multi_oid($this->getDeviceArray(), [ |
||
84 | '.1.3.6.1.4.1.8072.1.3.2.3.1.1.6.100.105.115.116.114.111', // NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.\"distro\" |
||
85 | '.1.3.6.1.4.1.2021.7890.1.3.1.1.6.100.105.115.116.114.111', // UCD-MIB shell |
||
86 | '.1.3.6.1.4.1.2021.7890.1.101.1', // exec |
||
87 | ], '-OUQn', 'NET-SNMP-EXTEND-MIB'); |
||
88 | $features = reset($features_extend); |
||
89 | $device->features = $features ?: $device->features; |
||
90 | |||
91 | // Try detect using the extended option (dmidecode) |
||
92 | $hardware_extend = snmp_get_multi_oid($this->getDeviceArray(), [ |
||
93 | '.1.3.6.1.4.1.8072.1.3.2.3.1.1.8.104.97.114.100.119.97.114.101', // NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.\"hardware\" |
||
94 | '.1.3.6.1.4.1.2021.7890.3.4.1.2.12.109.97.110.117.102.97.99.116.117.114.101.114.1', // UCD-MIB shell |
||
95 | '.1.3.6.1.4.1.2021.7890.3.101.1', // UCD-MIB exec |
||
96 | ], '-OUQn', 'NET-SNMP-EXTEND-MIB'); |
||
97 | $hardware = reset($hardware_extend); |
||
98 | |||
99 | if ($hardware) { |
||
100 | // NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.\"manufacturer\" |
||
101 | $manufacturer = snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.8072.1.3.2.3.1.1.12.109.97.110.117.102.97.99.116.117.114.101.114', '-Oqv', 'NET-SNMP-EXTEND-MIB'); |
||
102 | if ($manufacturer) { |
||
103 | $hardware = Str::start($hardware, $manufacturer . ' '); |
||
104 | } |
||
105 | |||
106 | $version_extend = snmp_get_multi_oid($this->getDeviceArray(), [ |
||
107 | '.1.3.6.1.4.1.8072.1.3.2.3.1.1.7.118.101.114.115.105.111.110', // NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.\"version\" |
||
108 | '.1.3.6.1.4.1.2021.7890.2.4.1.2.8.104.97.114.100.119.97.114.101.1', // UCD-MIB shell |
||
109 | '.1.3.6.1.4.1.2021.7890.2.101.1', // UCD-MIB exec |
||
110 | ], '-OUQn', 'NET-SNMP-EXTEND-MIB'); |
||
111 | $version = reset($version_extend); |
||
112 | if ($version) { |
||
113 | $hardware .= " [$version]"; |
||
114 | } |
||
115 | $device->hardware = $hardware; |
||
116 | } |
||
117 | |||
118 | $serial_extend = snmp_get_multi_oid($this->getDeviceArray(), [ |
||
119 | '.1.3.6.1.4.1.674.10892.1.300.10.1.11.1', // Dell |
||
120 | '.1.3.6.1.4.1.8072.1.3.2.3.1.1.6.115.101.114.105.97.108', // NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.\"serial\" |
||
121 | '.1.3.6.1.4.1.2021.7890.4.4.1.2.6.115.101.114.105.97.108.1', // UCD-MIB shell |
||
122 | ], '-OUQn', 'NET-SNMP-EXTEND-MIB:MIB-Dell-10892'); |
||
123 | $serial = reset($serial_extend); |
||
124 | $device->serial = $serial ?: $device->serial; |
||
125 | } |
||
126 | } |
||
127 |