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