<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package GLPI::Agent::Task::Inventory::Win32::Controllers;

use strict;
use warnings;

use parent 'GLPI::Agent::Task::Inventory::Module';

use GLPI::Agent::Tools::Generic;
use GLPI::Agent::Tools::Win32;

use constant    category    =&gt; "controller";

sub isEnabled {
    return 1;
}

sub doInventory {
    my (%params) = @_;

    my $inventory = $params{inventory};

    my $physical = $inventory-&gt;getHardware('VMSYSTEM') eq 'Physical';

    foreach my $controller (_getControllers(
        logger  =&gt; $params{logger},
        datadir =&gt; $params{datadir}
    )) {
        $inventory-&gt;addEntry(
            section =&gt; 'CONTROLLERS',
            entry   =&gt; $controller
        );

        if ($physical &amp;&amp; $controller-&gt;{NAME} =~ /QEMU/i) {
            $inventory-&gt;setHardware ({
                VMSYSTEM =&gt; 'QEMU'
            });
        }
    }
}

sub _getControllers {
    my @controllers;
    my %seen;

    foreach my $controller (_getControllersFromWMI(@_)) {

        if ($controller-&gt;{deviceid} =~ /PCI\\VEN_(\S{4})&amp;DEV_(\S{4})/) {
            $controller-&gt;{VENDORID} = lc($1);
            $controller-&gt;{PRODUCTID} = lc($2);
        }

        if ($controller-&gt;{deviceid} =~ /&amp;SUBSYS_(\S{4})(\S{4})/) {
            $controller-&gt;{PCISUBSYSTEMID} = lc($2 . ':' . $1);
        }

        # only devices with a PCIID sounds resonable
        next unless $controller-&gt;{VENDORID} &amp;&amp; $controller-&gt;{PRODUCTID};

        # avoid duplicates
        next if $seen{$controller-&gt;{VENDORID}}-&gt;{$controller-&gt;{PRODUCTID}}++;

        delete $controller-&gt;{deviceid};

        my $vendor_id    = lc($controller-&gt;{VENDORID});
        my $device_id    = lc($controller-&gt;{PRODUCTID});
        my $subdevice_id = lc($controller-&gt;{PCISUBSYSTEMID});

        my $vendor = getPCIDeviceVendor(id =&gt; $vendor_id, @_);
        if ($vendor) {
            $controller-&gt;{MANUFACTURER} = $vendor-&gt;{name};

            if ($vendor-&gt;{devices}-&gt;{$device_id}) {
                my $entry = $vendor-&gt;{devices}-&gt;{$device_id};
                $controller-&gt;{CAPTION} = $entry-&gt;{name};

                $controller-&gt;{NAME} =
                    $subdevice_id &amp;&amp; $entry-&gt;{subdevices}-&gt;{$subdevice_id} ?

                    $entry-&gt;{subdevices}-&gt;{$subdevice_id}-&gt;{name} :
                    $entry-&gt;{name};
            }
        }

        push @controllers, $controller;
    }

    return @controllers;
}

sub _getControllersFromWMI {
    my @controllers;

    foreach my $class (qw/
        Win32_FloppyController Win32_IDEController Win32_SCSIController
        Win32_VideoController Win32_InfraredDevice Win32_USBController
        Win32_1394Controller Win32_PCMCIAController CIM_LogicalDevice
    /) {

        foreach my $object (getWMIObjects(
            class      =&gt; $class,
            properties =&gt; [ qw/
                Name Manufacturer Caption DeviceID
            /]
        )) {

            push @controllers, {
                NAME         =&gt; $object-&gt;{Name},
                MANUFACTURER =&gt; $object-&gt;{Manufacturer},
                CAPTION      =&gt; $object-&gt;{Caption},
                TYPE         =&gt; $object-&gt;{Caption},
                deviceid     =&gt; $object-&gt;{DeviceID},
            };
        }
    }

    return @controllers;
}

1;
</pre></body></html>