File: Mem.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,424 kB
  • sloc: perl: 26,492; xml: 773; objc: 528; sh: 386; ansic: 333; makefile: 12
file content (89 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package Ocsinventory::Agent::Backend::OS::MacOS::Mem;
use strict;

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

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

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

    my $PhysicalMemory;

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

    # Workaround for MacOSX 10.5.7
    #if ($h->{'Memory Slots'}) {
    #  $h = $h->{'Memory Slots'};
    #}


    foreach my $memory (@$data){
        next unless $memory->{'_name'} =~ /^BANK|SODIMM|DIMM/;
        # tare out the slot number
        my $slot = $memory->{'_name'};
	# memory in 10.5
        if($slot =~ /^BANK (\d)\/DIMM\d/){
            $slot = $1;
        }
	# 10.4
	if($slot =~ /^SODIMM(\d)\/.*$/){
		$slot = $1;
	}
	# 10.4 PPC
	if($slot =~ /^DIMM(\d)\/.*$/){
		$slot = $1;
	}

	# 10.7
	if ($slot =~ /^DIMM (\d)/) {
		$slot = $1;
	}

        my $size = $memory->{'dimm_size'};

        my $desc = $memory->{'dimm_part_number'};

        if ($desc !~ /empty/ && $desc =~ s/^0x//) {
            # dimm_part_number is an hex string, convert it to ascii
            $desc =~ s/^0x//;
	    # Trim filling "00" from part number, which causes invalid XML down the line.
	    $desc =~ s/00//g;
            $desc = pack "H*", $desc;
            $desc =~ s/\s+$//;
            # New macs might have some specific characters, perform a regex to fix it
            $desc =~ s/(?!-)[[:punct:]]//g;
        }

        # if system_profiler lables the size in gigs, we need to trim it down to megs so it's displayed properly
        if($size =~ /GB$/){
                $size =~ s/GB$//;
                $size *= 1024;
        }
        $common->addMemory({
            'CAPACITY'      => $size,
            'SPEED'         => $memory->{'dimm_speed'},
            'TYPE'          => $memory->{'dimm_type'},
            'SERIALNUMBER'  => $memory->{'dimm_serial_number'},
            'DESCRIPTION'   => $desc,
            'NUMSLOTS'      => $slot,
            'CAPTION'       => 'Status: '.$memory->{'dimm_status'},
        });
    }

    # Send total memory size to inventory object
    my $sysctl_memsize=`sysctl -n hw.memsize`;
    $common->setHardware({
        MEMORY =>  $sysctl_memsize / 1024 / 1024,
    });
}
1;