break(netbackup): use new ssh backend (#3230)

This commit is contained in:
qgarnier 2021-11-04 14:27:47 +01:00 committed by GitHub
parent 136f5fcce6
commit 31d5d6c3c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 191 additions and 514 deletions

View File

@ -25,21 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
return 'status : ' . $self->{result_values}->{status};
}
sub custom_usage_threshold {
@ -48,7 +39,13 @@ sub custom_usage_threshold {
if (!defined($self->{instance_mode}->{option_results}->{'critical-usage'}) || $self->{instance_mode}->{option_results}->{'critical-usage'} eq '') {
$self->{perfdata}->threshold_validate(label => 'critical-usage', value => $self->{result_values}->{watermark});
}
return $self->{perfdata}->threshold_check(value => $self->{result_values}->{usage}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $self->{perfdata}->threshold_check(value => $self->{result_values}->{usage}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
}
sub prefix_volume_output {
my ($self, %options) = @_;
return "Disk volume '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
@ -59,12 +56,11 @@ sub set_counters {
];
$self->{maps_counters}->{volume} = [
{ label => 'status', threshold => 0, set => {
{ label => 'status', type => 2, critical_default => '%{status} !~ /up/i', set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'usage', set => {
@ -72,11 +68,11 @@ sub set_counters {
output_template => 'Use: %s %%',
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
perfdatas => [
{ label => 'used', value => 'usage', template => '%s',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'used', template => '%s',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
]
}
}
},
];
}
@ -85,56 +81,27 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'nbdevquery' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-listdp -U' },
"command2:s" => { name => 'command2', default => 'nbdevquery' },
"command2-path:s" => { name => 'command2_path' },
"command2-options:s" => { name => 'command2_options', default => '-listdv -U -stype PureDisk' },
"exec-only" => { name => 'exec_only' },
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /up/i' },
$options{options}->add_options(arguments => {
'exec-only' => { name => 'exec_only' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_volume_output {
my ($self, %options) = @_;
return "Disk volume '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my ($stdout) = $options{custom}->execute_command(
command => 'nbdevquery',
command_options => '-listdp -U'
);
if (defined($self->{option_results}->{exec_only})) {
$self->{output}->output_add(severity => 'OK',
short_msg => $stdout);
$self->{output}->output_add(
severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
}
@ -159,16 +126,15 @@ sub manage_selection {
$watermark->{$display} = centreon::plugins::misc::trim($1);
}
($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command2},
command_path => $self->{option_results}->{command2_path},
command_options => $self->{option_results}->{command2_options});
($stdout) = $options{custom}->execute_command(
command => 'nbdevquery',
command_options => '-listdv -U -stype PureDisk'
);
if (defined($self->{option_results}->{exec_only})) {
$self->{output}->output_add(severity => 'OK',
short_msg => $stdout);
$self->{output}->output_add(
severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -205,7 +171,7 @@ sub manage_selection {
}
if (scalar(keys %{$self->{volume}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No volume found.");
$self->{output}->add_option_msg(short_msg => 'No volume found.');
$self->{output}->option_exit();
}
}
@ -218,62 +184,10 @@ __END__
Check deduplication status.
Commands used: 'nbdevquery -listdp -U' and 'nbdevquery -listdv -U -stype PureDisk'
=over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'nbdevquery').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: ' -listdp -U').
=item B<--command2>
Command to get information (Default: 'nbdevquery').
Can be changed if you have output in a file.
=item B<--command2-path>
Command path (Default: none).
=item B<--command2-options>
Command options (Default: '-listdv -U -stype PureDisk').
=item B<--exec-only>
Print command output

View File

@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
sub set_counters {
my ($self, %options) = @_;
@ -38,11 +37,10 @@ sub set_counters {
key_values => [ { name => 'num_cleaning' }, { name => 'total' } ],
output_template => '%d drives needs a reset mount time',
perfdatas => [
{ label => 'cleaning', value => 'num_cleaning', template => '%s',
min => 0, max => 'total' },
],
{ label => 'cleaning', template => '%s', min => 0, max => 'total' }
]
}
}
},
];
}
@ -51,20 +49,9 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'tpconfig' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-l' },
"exec-only" => { name => 'exec_only' },
"filter-name:s" => { name => 'filter_name' },
$options{options}->add_options(arguments => {
'exec-only' => { name => 'exec_only' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
@ -73,16 +60,16 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my ($stdout) = $options{custom}->execute_command(
command => 'tpconfig',
command_options => '-l'
);
if (defined($self->{option_results}->{exec_only})) {
$self->{output}->output_add(severity => 'OK',
short_msg => $stdout);
$self->{output}->output_add(
severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -112,7 +99,7 @@ sub manage_selection {
}
if (scalar(keys %{$self->{drive}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No drives found.");
$self->{output}->add_option_msg(short_msg => 'No drives found.');
$self->{output}->option_exit();
}
}
@ -125,49 +112,10 @@ __END__
Check drive cleaning.
Command used: tpconfig -l
=over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'tpconfig').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-l').
=item B<--exec-only>
Print command output

View File

@ -24,22 +24,18 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
return $msg;
return 'status: ' . $self->{result_values}->{status};
}
sub custom_status_calc {
sub prefix_drive_output {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
return "Drive '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
@ -50,14 +46,13 @@ sub set_counters {
];
$self->{maps_counters}->{drive} = [
{ label => 'status', threshold => 0, set => {
{ label => 'status', type => 2, critical_default => '%{status} !~ /up/i', set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
},
];
}
@ -66,53 +61,27 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'tpconfig' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-l' },
"exec-only" => { name => 'exec_only' },
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /up/i' },
$options{options}->add_options(arguments => {
'exec-only' => { name => 'exec_only' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_drive_output {
my ($self, %options) = @_;
return "Drive '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my ($stdout) = $options{custom}->execute_command(
command => 'tpconfig',
command_options => '-l'
);
if (defined($self->{option_results}->{exec_only})) {
$self->{output}->output_add(severity => 'OK',
short_msg => $stdout);
$self->{output}->output_add(
severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -136,7 +105,7 @@ sub manage_selection {
}
if (scalar(keys %{$self->{drive}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No drives found.");
$self->{output}->add_option_msg(short_msg => 'No drives found.');
$self->{output}->option_exit();
}
}
@ -149,49 +118,10 @@ __END__
Check drive status.
Command used: tpconfig -l
=over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'tpconfig').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-l').
=item B<--exec-only>
Print command output

View File

@ -104,10 +104,10 @@ sub set_counters {
key_values => [ { name => 'total' } ],
output_template => 'Total Jobs : %s',
perfdatas => [
{ label => 'total', value => 'total', template => '%s', min => 0 },
],
{ label => 'total', value => 'total', template => '%s', min => 0 }
]
}
}
},
];
$self->{maps_counters}->{job} = [
@ -152,16 +152,6 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command', default => 'bpdbjobs' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => '-report -most_columns' },
'exec-only' => { name => 'exec_only' },
'filter-policy-name:s' => { name => 'filter_policy_name' },
'filter-type:s' => { name => 'filter_type' },
@ -222,19 +212,15 @@ my %job_state = (
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "netbackup_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
$self->{cache_name} = 'netbackup_' . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_policy_name}) ? md5_hex($self->{option_results}->{filter_policy_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_start_time}) ? md5_hex($self->{option_results}->{filter_start_time}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{job_end_time}) ? md5_hex($self->{option_results}->{job_end_time}) : md5_hex('all'));
my ($stdout) = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
my ($stdout) = $options{custom}->execute_command(
command => 'bpdbjobs',
command_options => '-report -most_columns'
);
if (defined($self->{option_results}->{exec_only})) {
@ -304,49 +290,10 @@ __END__
Check job status.
Command used: bpdbjobs -report -most_columns
=over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'bpdbjobs').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-report -most_columns').
=item B<--exec-only>
Print command output

View File

@ -31,20 +31,8 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'bppllist' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '' },
"command2:s" => { name => 'command2', default => 'bpplinfo %{policy_name} -L' },
"filter-name:s" => { name => 'filter_name' },
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }
});
return $self;
@ -59,7 +47,6 @@ sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (sort keys %{$self->{policies}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_ !~ /$self->{option_results}->{filter_name}/i) {
@ -70,8 +57,10 @@ sub run {
$self->{output}->output_add(long_msg => "'" . $_ . "' [active = " . $self->{policies}->{$_}->{active} . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List policy:');
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List policy:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -90,7 +79,8 @@ sub disco_show {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_ !~ /$self->{option_results}->{filter_name}/i);
$self->{output}->add_disco_entry(name => $_,
$self->{output}->add_disco_entry(
name => $_,
active => $self->{policies}->{$_}->{active}
);
}
@ -99,26 +89,22 @@ sub disco_show {
sub manage_selection {
my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my ($stdout) = $options{custom}->execute_command(
command => 'bppllist'
);
$self->{policies} = {};
my @lines = split /\n/, $stdout;
foreach my $policy_name (@lines) {
my $command2 = $self->{option_results}->{command2};
$command2 =~ s/%\{policy_name\}/$policy_name/g;
my ($stdout2) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $command2);
($stdout) = $options{custom}->execute_command(
command => 'bpplinfo',
command_options => $policy_name . ' -L'
);
#Policy Type: NBU-Catalog (35)
#Active: yes
my $active = '';
$active = $1 if ($stdout2 =~ /^Active\s*:\s+(\S+)/msi);
$active = $1 if ($stdout =~ /^Active\s*:\s+(\S+)/msi);
$self->{policies}->{$policy_name} = { active => $active };
}
}
@ -131,54 +117,10 @@ __END__
List policies.
Command used: 'bppllist' and 'bpplinfo %{policy_name} -L'
=over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'bppllist').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: none).
=item B<--command2>
Command to get active policy information (Default: 'bpplinfo %{policy_name} -L').
Can be changed if you have output in a file.
=item B<--filter-name>
Filter policy name (can be a regexp).

View File

@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
sub custom_usage_perfdata {
my ($self, %options) = @_;
@ -42,11 +41,13 @@ sub custom_usage_perfdata {
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $label,
$self->{output}->perfdata_add(
label => $label,
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total});
min => 0, max => $self->{result_values}->{total}
);
}
sub custom_usage_threshold {
@ -66,11 +67,12 @@ sub custom_usage_threshold {
sub custom_usage_output {
my ($self, %options) = @_;
my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
return sprintf(
"Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$self->{result_values}->{total},
$self->{result_values}->{used}, $self->{result_values}->{prct_used},
$self->{result_values}->{free}, $self->{result_values}->{prct_free});
return $msg;
$self->{result_values}->{free}, $self->{result_values}->{prct_free}
);
}
sub custom_usage_calc {
@ -99,9 +101,9 @@ sub set_counters {
closure_custom_calc => \&custom_usage_calc,
closure_custom_output => \&custom_usage_output,
closure_custom_perfdata => \&custom_usage_perfdata,
closure_custom_threshold_check => \&custom_usage_threshold,
closure_custom_threshold_check => \&custom_usage_threshold
}
}
},
];
}
@ -111,19 +113,9 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'vmquery' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-a -w' },
"filter-scratch:s" => { name => 'filter_scratch', default => 'scratch' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
'filter-scratch:s' => { name => 'filter_scratch', default => 'scratch' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' }
});
return $self;
@ -132,16 +124,16 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my ($stdout) = $options{custom}->execute_command(
command => 'vmquery',
command_options => '-a -w'
);
if (defined($self->{option_results}->{exec_only})) {
$self->{output}->output_add(severity => 'OK',
short_msg => $stdout);
$self->{output}->output_add(
severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -170,7 +162,7 @@ sub manage_selection {
}
if ($self->{global}->{total} == 0) {
$self->{output}->add_option_msg(short_msg => "No tape found.");
$self->{output}->add_option_msg(short_msg => 'No tape found.');
$self->{output}->option_exit();
}
}
@ -183,6 +175,8 @@ __END__
Check tapes available in library.
Command used: vmquery -a -w
=over 8
=item B<--remote>

View File

@ -22,7 +22,7 @@ package apps::backup::netbackup::local::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_simple);
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
@ -36,9 +36,11 @@ sub new {
'drive-status' => 'apps::backup::netbackup::local::mode::drivestatus',
'job-status' => 'apps::backup::netbackup::local::mode::jobstatus',
'list-policies' => 'apps::backup::netbackup::local::mode::listpolicies',
'tape-usage' => 'apps::backup::netbackup::local::mode::tapeusage',
'tape-usage' => 'apps::backup::netbackup::local::mode::tapeusage'
);
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
return $self;
}