line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Deploy::CheckProcessor; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
32337981
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
84
|
|
4
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
104
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
10
|
use English qw(-no_match_vars); |
|
3
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
28
|
|
7
|
3
|
|
|
3
|
|
2470
|
use Digest::SHA; |
|
3
|
|
|
|
|
7413
|
|
|
3
|
|
|
|
|
116
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1073
|
use FusionInventory::Agent::Task::Deploy::DiskFree; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1369
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub process { |
12
|
0
|
|
|
0
|
0
|
|
my ($self, %params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# the code to return in case of failure of the check, |
15
|
|
|
|
|
|
|
# the default is 'ko' |
16
|
0
|
|
0
|
|
|
|
my $failureCode = $params{check}->{return} || "ko"; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $path = $params{check}->{path}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Expend the env vars from the path |
21
|
0
|
|
|
|
|
|
$path =~ s#\$(\w+)#$ENV{$1}#ge; |
|
0
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$path =~ s#%(\w+)%#$ENV{$1}#ge; |
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'winkeyExists') { |
25
|
0
|
0
|
|
|
|
|
return unless $OSNAME eq 'MSWin32'; |
26
|
0
|
|
|
|
|
|
require FusionInventory::Agent::Tools::Win32; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $path = $path; |
29
|
0
|
|
|
|
|
|
$path =~ s{\\}{/}g; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $r = FusionInventory::Agent::Tools::Win32::getRegistryKey(path => $path); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
return defined $r ? 'ok' : $failureCode; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'winkeyEquals') { |
37
|
0
|
0
|
|
|
|
|
return unless $OSNAME eq 'MSWin32'; |
38
|
0
|
|
|
|
|
|
require FusionInventory::Agent::Tools::Win32; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$path =~ s{\\}{/}g; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $r = FusionInventory::Agent::Tools::Win32::getRegistryValue(path => $path); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
0
|
|
|
|
return defined $r && $params{check}->{value} eq $r ? 'ok' : $failureCode; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'winkeyMissing') { |
48
|
0
|
0
|
|
|
|
|
return unless $OSNAME eq 'MSWin32'; |
49
|
0
|
|
|
|
|
|
require FusionInventory::Agent::Tools::Win32; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $path = $path; |
52
|
0
|
|
|
|
|
|
$path =~ s{\\}{/}g; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $r = FusionInventory::Agent::Tools::Win32::getRegistryKey(path => $path); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
return defined $r ? $failureCode : 'ok'; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'fileExists') { |
60
|
0
|
0
|
|
|
|
|
return -f $path ? 'ok' : $failureCode; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'fileSizeEquals') { |
64
|
0
|
|
|
|
|
|
my @s = stat($path); |
65
|
0
|
0
|
|
|
|
|
return @s ? 'ok' : $failureCode; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'fileSizeGreater') { |
69
|
0
|
|
|
|
|
|
my @s = stat($path); |
70
|
0
|
0
|
|
|
|
|
return $failureCode unless @s; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
return $params{check}->{value} < $s[7] ? 'ok' : $failureCode; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'fileSizeLower') { |
76
|
0
|
|
|
|
|
|
my @s = stat($path); |
77
|
0
|
0
|
|
|
|
|
return $failureCode unless @s; |
78
|
0
|
0
|
|
|
|
|
return $params{check}->{value} > $s[7] ? 'ok' : $failureCode; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'fileMissing') { |
82
|
0
|
0
|
|
|
|
|
return -f $path ? $failureCode : 'ok'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'freespaceGreater') { |
86
|
0
|
|
|
|
|
|
my $freespace = getFreeSpace(logger => $params{logger}, path => $path); |
87
|
0
|
0
|
|
|
|
|
return $freespace>$params{check}->{value}? "ok" : $failureCode; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'fileSHA512') { |
91
|
0
|
|
|
|
|
|
my $sha = Digest::SHA->new('512'); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $sha512 = ""; |
94
|
0
|
|
|
|
|
|
eval { |
95
|
0
|
|
|
|
|
|
$sha->addfile($path, 'b'); |
96
|
0
|
|
|
|
|
|
$sha512 = $sha->hexdigest; |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
return $sha512 eq $params{check}->{value} ? "ok" : $failureCode; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'directoryExists') { |
103
|
0
|
0
|
|
|
|
|
return -d $path ? 'ok' : $failureCode; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
if ($params{check}->{type} eq 'directoryMissing') { |
107
|
0
|
0
|
|
|
|
|
return -d $path ? $failureCode : 'ok'; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
print "Unknown check: `".$params{check}->{type}."'\n"; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return "ok"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |