add(contrib): script to check modes execution (#3335)

This commit is contained in:
qgarnier 2021-12-22 11:37:17 +01:00 committed by GitHub
parent ee20c2f94d
commit e2d40f4c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 59 additions and 0 deletions

59
contrib/check_plugins.pl Executable file
View File

@ -0,0 +1,59 @@
#!/usr/bin/perl
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use strict;
use warnings;
use FindBin;
my $plugins = [];
sub check_directory {
my ($directory) = @_;
opendir(my $dh, $directory) || return ;
while (my $filename = readdir $dh) {
check_directory($directory . '/' . $filename) if ($filename !~ /^\./ && -d $directory . '/' . $filename);
if ($filename eq 'plugin.pm') {
push @$plugins, $directory . '/' . $filename;
}
}
closedir $dh;
}
my $plugin = "$FindBin::Bin/../centreon_plugins.pl";
check_directory("$FindBin::Bin/..");
foreach my $plugin_path (@$plugins) {
$plugin_path =~ s{$FindBin::Bin/../}{};
print "plugin: $plugin_path\n";
my $modes = `$plugin --plugin=$plugin_path --list-mode`;
if ($modes =~ /Modes Available:\n(.*)/ms) {
foreach my $mode (split /\n/, $1) {
$mode =~ s/\s+//g;
my $result = `$plugin --plugin=$plugin_path --mode=$mode`;
print " mode: $mode, result=$result";
}
} else {
print "error: $modes\n";
}
}
exit(0);