This commit is contained in:
Quentin Garnier 2014-06-23 15:32:47 +02:00
parent 445d3a41fe
commit 361a687615
5 changed files with 85 additions and 22 deletions

View File

@ -262,6 +262,30 @@ sub powershell_encoded {
return $script;
}
sub minimal_version {
my ($version_src, $version_dst) = @_;
# No Version. We skip
if (!defined($version_src) || !defined($version_dst) ||
$version_src !~ /^[0-9]+(?:\.[0-9\.])*$/ || $version_dst !~ /^[0-9x]+(?:\.[0-9x\.])*$/) {
return 1;
}
my @version_src = split /\./, $version_src;
my @versions = split /\./, $version_dst;
for (my $i = 0; $i < scalar(@versions); $i++) {
return 1 if ($versions[$i] eq 'x');
return 1 if (!defined($version_src[$i]));
$version_src[$i] =~ /^([0-9]*)/;
next if ($versions[$i] == int($1));
return 0 if ($versions[$i] > int($1));
return 1 if ($versions[$i] < int($1));
}
return 1;
}
1;
__END__

View File

@ -50,9 +50,10 @@ sub new {
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode:s' => { name => 'mode' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
}
);
$self->{version} = '1.0';
@ -60,8 +61,9 @@ sub new {
$self->{default} = undef;
$self->{options}->parse_options();
$self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
$self->{mode_name} = $self->{options}->get_option(argument => 'mode');
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
$self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
$self->{options}->clean();
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
@ -113,6 +115,10 @@ sub init {
$self->{mode}->version();
$self->{output}->option_exit(nolabel => 1);
}
if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
$self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ". $self->{mode}->{version});
$self->{output}->option_exit();
}
$self->{options}->parse_options();
$self->{option_results} = $self->{options}->get_options();
@ -192,6 +198,10 @@ Specify a mode with the path (separated by '::').
List available modes.
=item B<--mode-version>
Check minimal version of mode. If not, unknown error.
=item B<--version>
Display plugin version.

View File

@ -52,9 +52,10 @@ sub new {
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode:s' => { name => 'mode' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
}
);
$self->{version} = '1.0';
@ -62,8 +63,9 @@ sub new {
$self->{default} = undef;
$self->{options}->parse_options();
$self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
$self->{mode_name} = $self->{options}->get_option(argument => 'mode');
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
$self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
$self->{options}->clean();
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
@ -118,10 +120,14 @@ sub init {
$self->{mode}->version();
$self->{output}->option_exit(nolabel => 1);
}
if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
$self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ". $self->{mode}->{version});
$self->{output}->option_exit();
}
$self->{options}->parse_options();
$self->{option_results} = $self->{options}->get_options();
$self->{snmp}->check_options(option_results => $self->{option_results});
$self->{mode}->check_options(option_results => $self->{option_results}, default => $self->{default});
}
@ -200,6 +206,10 @@ Specify a mode with the path (separated by '::').
List available modes.
=item B<--mode-version>
Check minimal version of mode. If not, unknown error.
=item B<--version>
Display plugin version.

View File

@ -51,12 +51,13 @@ sub new {
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' },
'list-sqlmode' => { name => 'list_sqlmode' },
'multiple' => { name => 'multiple' },
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' },
'list-sqlmode' => { name => 'list_sqlmode' },
'multiple' => { name => 'multiple' },
}
);
$self->{version} = '1.0';
@ -136,6 +137,10 @@ sub init {
$self->{mode}->version();
$self->{output}->option_exit(nolabel => 1);
}
if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
$self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ". $self->{mode}->{version});
$self->{output}->option_exit();
}
$self->{options}->parse_options();
$self->{option_results} = $self->{options}->get_options();
@ -255,6 +260,10 @@ List available modes.
Display plugin version.
=item B<--mode-version>
Check minimal version of mode. If not, unknown error.
=item B<--dyn-mode>
Specify a mode with the path (separated by '::').

View File

@ -52,9 +52,10 @@ sub new {
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode:s' => { name => 'mode' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
}
);
$self->{version} = '1.0';
@ -62,8 +63,9 @@ sub new {
$self->{default} = undef;
$self->{options}->parse_options();
$self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
$self->{mode_name} = $self->{options}->get_option(argument => 'mode');
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
$self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
$self->{options}->clean();
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
@ -118,6 +120,10 @@ sub init {
$self->{mode}->version();
$self->{output}->option_exit(nolabel => 1);
}
if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
$self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ". $self->{mode}->{version});
$self->{output}->option_exit();
}
$self->{options}->parse_options();
$self->{option_results} = $self->{options}->get_options();
@ -204,6 +210,10 @@ List available modes.
Display plugin version.
=item B<--mode-version>
Check minimal version of mode. If not, unknown error.
=back
=head1 DESCRIPTION