mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-26 23:24:27 +02:00
fix(plugin) cifs,sftp,ftp plugin now check recursively folders (#5015)
REF:CTOR-258
This commit is contained in:
parent
1fb1647965
commit
30286395ab
@ -106,27 +106,28 @@ sub countFiles {
|
||||
# Cannot list we skip
|
||||
next;
|
||||
}
|
||||
|
||||
# this loop is recursive, when we find a directory we add it to the list used by the for loop.
|
||||
# max_depth is used to limit the depth we search.
|
||||
# same behaviour as ftp and sftp protocol.
|
||||
foreach my $file (@$files) {
|
||||
next if ($file->[0] != SMBC_FILE && $file->[0] != SMBC_DIR);
|
||||
next if ($file->[1] eq '.' || $file->[1] eq '..');
|
||||
|
||||
my $name = $dir . '/' . $file->[1];
|
||||
|
||||
if (defined($self->{option_results}->{filter_file}) && $self->{option_results}->{filter_file} ne '' &&
|
||||
$name !~ /$self->{option_results}->{filter_file}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("skipping '%s'", $name), debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
if ($file->[0] == SMBC_DIR) {
|
||||
if (defined($self->{option_results}->{max_depth}) && $level + 1 <= $self->{option_results}->{max_depth}) {
|
||||
push @$list, { name => $name, level => $level + 1 };
|
||||
}
|
||||
} else {
|
||||
$self->{output}->output_add(long_msg => sprintf("Match '%s'", $name));
|
||||
$self->{global}->{detected}++;
|
||||
next;
|
||||
} elsif (!centreon::plugins::misc::is_empty($self->{option_results}->{filter_file})
|
||||
# if this is a file check the filter_file regex
|
||||
&& $name !~ /$self->{option_results}->{filter_file}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("skipping '%s'", $name), debug => 1);
|
||||
next;
|
||||
}
|
||||
$self->{output}->output_add(long_msg => sprintf("Match '%s'", $name));
|
||||
$self->{global}->{detected}++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,30 +126,33 @@ sub countFiles {
|
||||
# Cannot list we skip
|
||||
next;
|
||||
}
|
||||
|
||||
# this loop is recursive, when we find a directory we add it to the list used by the for loop.
|
||||
# max_depth is used to limit the depth we search.
|
||||
# same behaviour as cifs(samba) and sftp protocol.
|
||||
foreach my $line (@files) {
|
||||
# IIS: 05-13-15 10:59AM 1184403 test.jpg
|
||||
next if ($line !~ /(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(.*)/ &&
|
||||
$line !~ /^\s*\S+\s*\S+\s*(\S+)\s+(.*)/);
|
||||
$line !~ /^\s*\S+\s*\S+\s*(\S+)\s+(.*)/);
|
||||
my ($rights, $filename) = ($1, $2);
|
||||
my $bname = basename($filename);
|
||||
next if ($bname eq '.' || $bname eq '..');
|
||||
my $name = $dir . '/' . $bname;
|
||||
|
||||
if (defined($self->{option_results}->{filter_file}) && $self->{option_results}->{filter_file} ne '' &&
|
||||
$name !~ /$self->{option_results}->{filter_file}/) {
|
||||
if ($rights =~ /^(d|<DIR>)/i) {
|
||||
# in the case of a directory and the max level is not reached yet, we add it to the recursive browsing
|
||||
if (defined($self->{option_results}->{max_depth})
|
||||
&& $level + 1 <= $self->{option_results}->{max_depth}) {
|
||||
push @$list, { name => $name, level => $level + 1 };
|
||||
}
|
||||
next;
|
||||
} elsif (!centreon::plugins::misc::is_empty($self->{option_results}->{filter_file})
|
||||
&& $name !~ /$self->{option_results}->{filter_file}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping '%s'", $name));
|
||||
# in the case of a file that does not match the filter, we skip
|
||||
next;
|
||||
}
|
||||
|
||||
if ($rights =~ /^(d|<DIR>)/i) {
|
||||
if (defined($self->{option_results}->{max_depth}) && $level + 1 <= $self->{option_results}->{max_depth}) {
|
||||
push @$list, { name => $name, level => $level + 1};
|
||||
}
|
||||
} else {
|
||||
$self->{output}->output_add(long_msg => sprintf("Match '%s'", $name));
|
||||
$count++;
|
||||
}
|
||||
$self->{output}->output_add(long_msg => sprintf("Match '%s'", $name));
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,12 +34,12 @@ sub set_counters {
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'files-detected', nlabel => 'files.detected.count', set => {
|
||||
key_values => [ { name => 'detected' } ],
|
||||
output_template => 'number of files: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0 }
|
||||
]
|
||||
}
|
||||
key_values => [ { name => 'detected' } ],
|
||||
output_template => 'number of files: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
@ -111,25 +111,26 @@ sub countFiles {
|
||||
# Cannot list we skip
|
||||
next;
|
||||
}
|
||||
|
||||
# this loop is recursive, when we find a directory we add it to the list used by the for loop.
|
||||
# max_depth is used to limit the depth we search.
|
||||
# same behaviour as cifs(samba) and ftp protocol.
|
||||
foreach my $file (@{$rv->{files}}) {
|
||||
next if ($file->{name} eq '.' || $file->{name} eq '..');
|
||||
my $name = $dir . '/' . $file->{name};
|
||||
|
||||
if (defined($self->{option_results}->{filter_file}) && $self->{option_results}->{filter_file} ne '' &&
|
||||
$name !~ /$self->{option_results}->{filter_file}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("skipping '%s'", $name), debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
if ($file->{type} == 2) {
|
||||
# case of a directory
|
||||
if (defined($self->{option_results}->{max_depth}) && $level + 1 <= $self->{option_results}->{max_depth}) {
|
||||
push @$list, { name => $name, level => $level + 1 };
|
||||
}
|
||||
} else {
|
||||
$self->{output}->output_add(long_msg => sprintf("Match '%s'", $name));
|
||||
$self->{global}->{detected}++;
|
||||
next;
|
||||
} elsif (!centreon::plugins::misc::is_empty($self->{option_results}->{filter_file})
|
||||
&& $name !~ /$self->{option_results}->{filter_file}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("skipping '%s'", $name), debug => 1);
|
||||
next;
|
||||
}
|
||||
$self->{output}->output_add(long_msg => sprintf("Match '%s'", $name));
|
||||
$self->{global}->{detected}++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user