Adding a custom initial detection for workstations

I have attempted to create a custom definition for our windows workstations

os: windows
type: workstation
text: 'Microsoft Windows'
ifname: true
processor_stacked: true
bad_hrSystemUptime: true
mib_dir: dell
over:
    - { graph: device_processor, text: 'Processor Usage' }
    - { graph: device_mempool, text: 'Memory Usage' }
    - { graph: device_storage, text: 'Storage Usage' }
discovery:
    -
        sysObjectID: .1.3.6.1.4.1.311.1.1.3
        snmpget:
            oid: .1.3.6.1.2.1.1.5.0 
            op: 'regex'
            value: 'workstation\d+us'

This appears to grab the workstations but it loses all the automatic stuff for windows removing the icon / processor definitions and whatnot.

Device OS changed: windows -> windowsworkstation
OS Version: 10 (22H2) -> 
Hardware: Intel x64 -> 
OS Features: Multiprocessor -> 
Icon: images/os/windows.svg -> images/os/generic.svg

I created a duplicate of LibreNMS/OS/windows.php as LibreNMS/OS/windowsworkstation.php which didnt make a difference also attempted to refresh the cache rm -f cache/os_defs.cache and created an extra icon with the correct name. What am I doing wrong here?

I have resolved this issue:

windowsworkstation.yaml

os: windowsworkstation
type: workstation
text: 'Microsoft Windows'
ifname: true
processor_stacked: true
bad_hrSystemUptime: true
icon: windows
mib_dir: dell
over:
    - { graph: device_processor, text: 'Processor Usage' }
    - { graph: device_mempool, text: 'Memory Usage' }
    - { graph: device_storage, text: 'Storage Usage' }
discovery:
    -
        sysObjectID: .1.3.6.1.4.1.311.1.1.3.1.1

WindowsWorkstation.php

<?php
/*
 * Windowsworkstation.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 <[email protected]>
 */

namespace LibreNMS\OS;

use App\Models\Device;
use LibreNMS\OS\Traits\ServerHardware;

class Windowsworkstation 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);
            }
        }

        $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;
    }
}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.