source: ocsinventory-agent/trunk/fuentes/lib/Ocsinventory/Agent/Backend/OS/MacOS/CPU.pm @ 468

Last change on this file since 468 was 468, checked in by mabarracus, 4 years ago

Copyt trusty code

File size: 1.5 KB
Line 
1package Ocsinventory::Agent::Backend::OS::MacOS::CPU;
2use strict;
3
4sub check {
5    return(undef) unless -r '/usr/sbin/system_profiler';
6    return(undef) unless can_load("Mac::SysProfile");
7    return 1;
8}
9
10sub run {
11    my $params = shift;
12    my $common = $params->{common};
13
14    # create sysprofile obj. Return undef unless we get a return value
15    my $profile = Mac::SysProfile->new();
16    my $data = $profile->gettype('SPHardwareDataType');
17    return(undef) unless(ref($data) eq 'ARRAY');
18
19    my $h = $data->[0];
20
21    ######### CPU
22    my $processort  = $h->{'processor_name'} | $h->{'cpu_type'}; # 10.5 || 10.4
23    my $processorn  = $h->{'number_processors'} || $h->{'number_cpus'};
24    my $processors  = $h->{'current_processor_speed'} || $h->{'cpu_speed'};
25
26    # lamp spits out an sql error if there is something other than an int (MHZ) here....
27    if($processors =~ /GHz$/){
28            $processors =~ s/ GHz//;
29            # French Mac returns 2,60 Ghz instead of
30            # 2.60 Ghz :D
31            $processors =~ s/,/./;
32            $processors = ($processors * 1000);
33    }
34    if($processors =~ /MHz$/){
35            $processors =~ s/ MHz//;
36    }
37
38    ### mem convert it to meg's if it comes back in gig's
39    my $mem = $h->{'physical_memory'};
40    if($mem =~ /GB$/){
41        $mem =~ s/\sGB$//;
42        $mem = ($mem * 1024);
43    }
44    if($mem =~ /MB$/){
45        $mem =~ s/\sMB$//;
46    }
47
48
49    $common->setHardware({
50        PROCESSORT  => $processort,
51        PROCESSORN  => $processorn,
52        PROCESSORS  => $processors,
53        MEMORY      => $mem,
54    });
55}
56
571;
Note: See TracBrowser for help on using the repository browser.