line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Deploy::DiskFree; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
32862175
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
155
|
|
4
|
6
|
|
|
6
|
|
17
|
use warnings; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
175
|
|
5
|
6
|
|
|
6
|
|
22
|
use base 'Exporter'; |
|
6
|
|
|
|
|
53
|
|
|
6
|
|
|
|
|
645
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
25
|
use English qw(-no_match_vars); |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
47
|
|
8
|
6
|
|
|
6
|
|
3360
|
use FusionInventory::Agent::Tools; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
790
|
|
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
25
|
use UNIVERSAL::require; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
39
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( |
13
|
|
|
|
|
|
|
getFreeSpace |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub getFreeSpace { |
17
|
1
|
50
|
|
1
|
0
|
926
|
my $freeSpace = |
|
|
50
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$OSNAME eq 'MSWin32' ? _getFreeSpaceWindows(@_) : |
19
|
|
|
|
|
|
|
$OSNAME eq 'solaris' ? _getFreeSpaceSolaris(@_) : |
20
|
|
|
|
|
|
|
_getFreeSpace(@_); |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
18
|
return $freeSpace; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _getFreeSpaceWindows { |
26
|
0
|
|
|
0
|
|
0
|
my (%params) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
0
|
FusionInventory::Agent::Tools::Win32->require(); |
32
|
0
|
0
|
|
|
|
0
|
if ($EVAL_ERROR) { |
33
|
0
|
|
|
|
|
0
|
$logger->error( |
34
|
|
|
|
|
|
|
"Failed to load FusionInventory::Agent::Tools::Win32: $EVAL_ERROR" |
35
|
|
|
|
|
|
|
); |
36
|
0
|
|
|
|
|
0
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
my $letter; |
40
|
0
|
0
|
|
|
|
0
|
if ($params{path} !~ /^(\w):/) { |
41
|
0
|
|
|
|
|
0
|
$logger->error("Path parse error: ".$params{path}); |
42
|
0
|
|
|
|
|
0
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
$letter = $1.':'; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
my $freeSpace; |
47
|
0
|
|
|
|
|
0
|
foreach my $object (FusionInventory::Agent::Tools::Win32::getWMIObjects( |
48
|
|
|
|
|
|
|
moniker => 'winmgmts:{impersonationLevel=impersonate,(security)}!//./', |
49
|
|
|
|
|
|
|
class => 'Win32_LogicalDisk', |
50
|
|
|
|
|
|
|
properties => [ qw/Caption FreeSpace/ ] |
51
|
|
|
|
|
|
|
)) { |
52
|
0
|
0
|
|
|
|
0
|
next unless lc($object->{Caption}) eq lc($letter); |
53
|
0
|
|
|
|
|
0
|
my $t = $object->{FreeSpace}; |
54
|
0
|
0
|
0
|
|
|
0
|
if ($t && $t =~ /(\d+)\d{6}$/) { |
55
|
0
|
|
|
|
|
0
|
$freeSpace = $1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
return $freeSpace; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _getFreeSpaceSolaris { |
63
|
0
|
|
|
0
|
|
0
|
my (%params) = @_; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
0
|
return unless -d $params{path}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return getFirstMatch( |
68
|
|
|
|
|
|
|
command => "df -b $params{path}", |
69
|
|
|
|
|
|
|
pattern => qr/^\S+\s+(\d+)\d{3}[^\d]/, |
70
|
|
|
|
|
|
|
logger => $params{logger} |
71
|
0
|
|
|
|
|
0
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _getFreeSpace { |
75
|
1
|
|
|
1
|
|
2
|
my (%params) = @_; |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
9
|
return unless -d $params{path}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return getFirstMatch( |
80
|
|
|
|
|
|
|
command => "df -Pk $params{path}", |
81
|
|
|
|
|
|
|
pattern => qr/^\S+\s+\S+\s+\S+\s+(\d+)\d{3}[^\d]/, |
82
|
|
|
|
|
|
|
logger => $params{logger} |
83
|
1
|
|
|
|
|
9
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |