line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Deploy::DiskFree; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
39798405
|
use strict; |
|
6
|
|
|
|
|
32
|
|
|
6
|
|
|
|
|
250
|
|
4
|
6
|
|
|
6
|
|
48
|
use warnings; |
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
297
|
|
5
|
6
|
|
|
6
|
|
33
|
use base 'Exporter'; |
|
6
|
|
|
|
|
130
|
|
|
6
|
|
|
|
|
946
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
43
|
use English qw(-no_match_vars); |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
78
|
|
8
|
6
|
|
|
6
|
|
6529
|
use FusionInventory::Agent::Tools; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
1315
|
|
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
36
|
use UNIVERSAL::require; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
59
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( |
13
|
|
|
|
|
|
|
getFreeSpace |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub getFreeSpace { |
17
|
1
|
50
|
|
1
|
0
|
806
|
my $freeSpace = |
|
|
50
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$OSNAME eq 'MSWin32' ? _getFreeSpaceWindows(@_) : |
19
|
|
|
|
|
|
|
$OSNAME eq 'solaris' ? _getFreeSpaceSolaris(@_) : |
20
|
|
|
|
|
|
|
_getFreeSpace(@_); |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
30
|
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
|
|
5
|
my (%params) = @_; |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
16
|
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
|
|
|
|
|
11
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |