mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
I added Server 2022 and Windows 10/11 22H2 (and a few other popular but older windows builds that people might still have in use). I also propose changing the naming of windows machines to better reflect the release and version of windows. This naming is derived from this page: https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions For example, for Windows Server it was previously set to something like 'Windows Server 2019 1809 (NT 6.3)' which is incorrect as MS stopped using NT 6.3 since Windows 10 version 1507. Now it'll display as 'Windows Server 2019 (1809)'. The kernel/version is in parentheses and isn't also in the main part of the name as it's redundant/duplicated information.
153 lines
5.4 KiB
PHP
153 lines
5.4 KiB
PHP
<?php
|
|
/*
|
|
* Windows.php
|
|
*
|
|
* -Description-
|
|
*
|
|
* This program 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.
|
|
*
|
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
* @package LibreNMS
|
|
* @link https://www.librenms.org
|
|
* @copyright 2020 Tony Murray
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
*/
|
|
|
|
namespace LibreNMS\OS;
|
|
|
|
use App\Models\Device;
|
|
use LibreNMS\OS\Traits\ServerHardware;
|
|
|
|
class Windows extends \LibreNMS\OS
|
|
{
|
|
use ServerHardware;
|
|
|
|
public function discoverOS(Device $device): void
|
|
{
|
|
if (preg_match('/Hardware: (?<hardware>.*) +- Software: .* Version (?<nt>\S+) +\(Build( Number:)? (?<build>\S+) (?<smp>\S+)/', $device->sysDescr, $matches)) {
|
|
$device->hardware = $this->parseHardware($matches['hardware'] ?? null);
|
|
$device->features = $matches['smp'] ?? null;
|
|
|
|
$build = $matches['build'] ?? null;
|
|
if ($device->sysObjectID == '.1.3.6.1.4.1.311.1.1.3.1.1') {
|
|
$device->version = $this->getClientVersion($build, $matches['version'] ?? null);
|
|
} elseif ($device->sysObjectID == '.1.3.6.1.4.1.311.1.1.3.1.2') {
|
|
$device->version = $this->getServerVersion($build);
|
|
} elseif ($device->sysObjectID == '.1.3.6.1.4.1.311.1.1.3.1.3') {
|
|
$device->version = $this->getDatacenterVersion($build);
|
|
}
|
|
}
|
|
|
|
$this->discoverServerHardware();
|
|
}
|
|
|
|
private function parseHardware($processor)
|
|
{
|
|
preg_match('/(?<generic>\S+) Family (?<family>\d+) Model (?<model>\d+) Stepping (?<stepping>\d+)/', $processor, $matches);
|
|
|
|
$generic = [
|
|
'AMD64' => 'AMD x64',
|
|
'Intel64' => 'Intel x64',
|
|
'EM64T' => 'Intel x64',
|
|
'x86' => 'Generic x86',
|
|
'ia64' => 'Intel Itanium IA64',
|
|
];
|
|
|
|
return $generic[$matches['generic']] ?? null;
|
|
}
|
|
|
|
private function getClientVersion($build, $version)
|
|
{
|
|
$default = $build > 10000 ? '10 (NT 6.3)' : null;
|
|
$default = $build > 22000 ? '11 Insider (NT 6.3)' : null;
|
|
|
|
$builds = [
|
|
'22621' => '11 (22H2)',
|
|
'22000' => '11 (21H2)',
|
|
'19045' => '10 (22H2)',
|
|
'19044' => '10 (21H2)',
|
|
'19043' => '10 (21H1)',
|
|
'19042' => '10 (20H2)',
|
|
'19041' => '10 (2004)',
|
|
'18363' => '10 (1909)',
|
|
'18362' => '10 (1903)',
|
|
'17763' => '10 (1809)',
|
|
'17134' => '10 (1803)',
|
|
'16299' => '10 (1709)',
|
|
'15063' => '10 (1703)',
|
|
'14393' => '10 (1607)',
|
|
'10586' => '10 (1511)',
|
|
'10240' => '10 version 1507 (NT 10.0)',
|
|
'9600' => '8.1 (NT 6.3)',
|
|
'9200' => $version == '6.3' ? '8.1 (NT 6.3)' : '8 (NT 6.2)',
|
|
'7601' => '7 SP1 (NT 6.1)',
|
|
'7600' => '7 (NT 6.1)',
|
|
'6002' => 'Vista SP2 (NT 6.0)',
|
|
'6001' => 'Vista SP1 (NT 6.0)',
|
|
'6000' => 'Vista (NT 6.0)',
|
|
'3790' => 'XP x64 (NT 5.2)',
|
|
'2600' => 'XP (NT 5.1)',
|
|
'2195' => '2000 (NT 5.0)',
|
|
'1381' => 'NT 4.0 Workstation',
|
|
'1057' => 'NT 3.51 Workstation',
|
|
];
|
|
|
|
return $builds[$build] ?? $default;
|
|
}
|
|
|
|
private function getServerVersion($build)
|
|
{
|
|
$builds = [
|
|
'20348' => 'Server 2022 (21H2)',
|
|
'17763' => 'Server 2019 (1809)',
|
|
'16299' => 'Server 2016 (1709)',
|
|
'14393' => 'Server 2016 (1607)',
|
|
'9600' => 'Server 2012 R2 (NT 6.3)',
|
|
'9200' => 'Server 2012 (NT 6.2)',
|
|
'7601' => 'Server 2008 R2 SP1 (NT 6.1)',
|
|
'7600' => 'Server 2008 R2 (NT 6.1)',
|
|
'6003' => 'Server 2008 SP2 (NT 6.0)',
|
|
'6002' => 'Server 2008 SP2 (NT 6.0)',
|
|
'6001' => 'Server 2008 (NT 6.0)',
|
|
'3790' => 'Server 2003 (NT 5.2)',
|
|
'2195' => '2000 Server (NT 5.0)',
|
|
'1381' => 'NT Server 4.0',
|
|
'1057' => 'NT Server 3.51',
|
|
];
|
|
|
|
return $builds[$build] ?? null;
|
|
}
|
|
|
|
private function getDatacenterVersion($build)
|
|
{
|
|
$builds = [
|
|
'20348' => 'Server 2022 Datacenter (21H2)',
|
|
'17763' => 'Server 2019 Datacenter (1809)',
|
|
'16299' => 'Server 2016 Datacenter (1709)',
|
|
'14393' => 'Server 2016 Datacenter (1607)',
|
|
'9600' => 'Server 2012 R2 Datacenter (NT 6.3)',
|
|
'9200' => 'Server 2012 Datacenter (NT 6.2)',
|
|
'7601' => 'Server 2008 Datacenter R2 SP1 (NT 6.1)',
|
|
'7600' => 'Server 2008 Datacenter R2 (NT 6.1)',
|
|
'6002' => 'Server 2008 Datacenter SP2 (NT 6.0)',
|
|
'6001' => 'Server 2008 Datacenter (NT 6.0)',
|
|
'3790' => 'Server 2003 Datacenter (NT 5.2)',
|
|
'2195' => '2000 Datacenter Server (NT 5.0)',
|
|
'1381' => 'NT Datacenter 4.0',
|
|
'1057' => 'NT Datacenter 3.51',
|
|
];
|
|
|
|
return $builds[$build] ?? null;
|
|
}
|
|
}
|