Agent/Backend/OS/MacOS/Ports.pm

Registered by Andreas Xenos

Dmidecode does not exist n Mac computers. This module is migrated to MacOS directory and it returns results through system_profiler from the types: SPUSBDataType, SPFireWireDataType, SPThunderboltDataType, SPEthernetDataType

Blueprint information

Status:
Complete
Approver:
mortheres
Priority:
Medium
Drafter:
None
Direction:
Needs approval
Assignee:
Andreas Xenos
Definition:
Approved
Series goal:
Accepted for stable-2.0
Implementation:
Implemented
Milestone target:
None
Started by
mortheres
Completed by
mortheres

Sprints

Whiteboard

package Ocsinventory::Agent::Backend::OS::MacOS::Ports;

sub check {
    return(undef) unless -r '/usr/sbin/system_profiler'; # check perms
    return (undef) unless can_load("Mac::SysProfile");
    return 1;
}

sub run {
    my $params = shift;
    my $common = $params->{common};

 my @types = qw(SPUSBDataType SPFireWireDataType SPThunderboltDataType SPEthernetDataType);
 my $dataType = 0;

 for (@types) {

           # create the profile object and return undef unless we get something back
        my $pro = Mac::SysProfile->new();
        my $data = $pro->gettype($types[$dataType]);
        return(undef) unless(ref($data) eq 'ARRAY');

        foreach my $port (@$data) {

           my ($caption, $description, $name, $type) = '';
           if ($dataType == 0) {
                        $name = $port->{'usb_bus_number'};
                        $type = 'USB';
       $description = $port->{'controller_location'} . ", PCI Device ID: " . $port->{'pci_device'};
           } elsif ($dataType == 1) {
       $name = 'FireWire';
                        $type = 'FireWire Bus';
       $description = 'Max Speed: ' . $port->{'max_device_speed'};
           } elsif ($dataType == 2) {
       $name = $port->{'device_name_key'};
                        if ($name ne '') {
                           $type = 'Thunderbolt';
          $description = 'UID: ' . $port->{'switch_uid_key'};
                        }
           } elsif ($dataType == 3) {
                        $name = $port->{'_name'};
                        if ($name ne '') {
                           $name = $port->{'spethernet_device-id'} if ($name eq 'ethernet');
          $type = 'Ethernet Controller';
          $description = 'BSD: ' . $port->{'spethernet_BSD_Name'};
                        }
           }

              $common->addPorts({
                'CAPTION' => $caption,
                  'DESCRIPTION' => $description,
                 'NAME' => $name,
                  'TYPE' => $type,
              });
        }
        $dataType++;
 }

}

1;

---------------------------------------------------------------------------------------------------------------------------------------
Hi Andreas,

Thanks a lot for your proposal and code.

 I decided to rename as Controllers.pm because I think the data are more related to controllers instead of ports. I made some code cleaning too for better code reading and maintainance. I have commented the SPUSBDataType line because I have to find a clean and generic patch (instead of create an hard coded SPUSBDataType statement in Sysprofile.pm) to propose it to Mac::Sysprofile maintainer to make SPUSBDataType works...So there is no USB data for the moment...

I have commited all of this in Launchpad stable branch : http://bazaar.launchpad.net/~ocsinventory-dev/ocsinventory-unix-agent/stable-2.0/revision/1091

To make Controllers.pm works as expected, you need to use the latest Launchpad 1090 commit because I add a DESCRIPTION missing field in addController() subroutine from Common.pm .

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.