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 1b6e3d89e0
commit f556ba32ef
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' }
]
}
},
}
];
}
@ -84,57 +80,28 @@ sub new {
my ($class, %options) = @_;
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);
}
@ -152,23 +119,22 @@ sub manage_selection {
my $watermark = {};
while ($stdout =~ /^(Disk Pool Name.*?)(?=Disk Pool Name|\z)/msig) {
my $pool = $1;
$pool =~ /^Disk Pool Name\s*:\s*(.*?)\n/msi;
my $display = centreon::plugins::misc::trim($1);
$pool =~ /^High Watermark\s*:\s*(.*?)\n/msi;
$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();
}
@ -187,25 +153,25 @@ sub manage_selection {
#Flag : InternalUp
while ($stdout =~ /^(Disk Pool Name.*?)(?=Disk Pool Name|\z)/msig) {
my $volume = $1;
my ($pool_name, $volume_name, $usage, $status);
$pool_name = centreon::plugins::misc::trim($1) if ($volume =~ /^Disk Pool Name\s*:\s*(.*?)\n/msi);
$volume_name = centreon::plugins::misc::trim($1) if ($volume =~ /^Disk Volume Name\s*:\s*(.*?)\n/msi);
$status = $1 if ($volume =~ /^Status\s*:\s*(.*?)\n/msi);
$usage = $1 if ($volume =~ /^Use%\s*:\s*(.*?)\n/msi);
my $display = $pool_name . '.' . $volume_name;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$display !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
next;
}
$self->{volume}->{$display} = { display => $display, usage => $usage, status => $status, watermark => $watermark->{$pool_name} };
}
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,25 +24,23 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'drive', type => 0 }
];
$self->{maps_counters}->{drive} = [
{ label => 'cleaning', set => {
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' }
]
}
},
}
];
}
@ -50,39 +48,28 @@ sub new {
my ($class, %options) = @_;
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;
}
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();
}
@ -97,22 +84,22 @@ sub manage_selection {
foreach my $line (@lines) {
$line =~ /^(\S+)/;
my $name = $1;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
$self->{output}->output_add(long_msg => "drive '" . $name . "' checked.", debug => 1);
$self->{drive}->{total}++;
if ($line =~ /NEEDS CLEANING/i) {
$self->{drive}->{num_cleaning}++;
}
}
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
}
},
}
];
}
@ -65,54 +60,28 @@ sub new {
my ($class, %options) = @_;
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();
}
@ -125,7 +94,7 @@ sub manage_selection {
my ($robot_num, $drives) = ($1, $2);
while ($drives =~ /drive\s+\S+\s+(\d+)\s+\S+\s+\S+\s+(\S+)/msig) {
my $name = $robot_num . '.' . $1;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
@ -134,9 +103,9 @@ sub manage_selection {
$self->{drive}->{$name} = { display => $name, status => $2 };
}
}
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} = [
@ -151,25 +151,15 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
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' },
'filter-end-time:s' => { name => 'filter_end_time', default => 86400 },
'filter-start-time:s' => { name => 'filter_start_time' },
'ok-status:s' => { name => 'ok_status', default => '%{status} == 0' },
'warning-status:s' => { name => 'warning_status', default => '%{status} == 1' },
'critical-status:s' => { name => 'critical_status', default => '%{status} > 1' }
$options{options}->add_options(arguments => {
'exec-only' => { name => 'exec_only' },
'filter-policy-name:s' => { name => 'filter_policy_name' },
'filter-type:s' => { name => 'filter_type' },
'filter-end-time:s' => { name => 'filter_end_time', default => 86400 },
'filter-start-time:s' => { name => 'filter_start_time' },
'ok-status:s' => { name => 'ok_status', default => '%{status} == 0' },
'warning-status:s' => { name => 'warning_status', default => '%{status} == 1' },
'critical-status:s' => { name => 'critical_status', default => '%{status} > 1' }
});
return $self;
@ -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

@ -30,23 +30,11 @@ sub new {
my ($class, %options) = @_;
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,26 +47,27 @@ 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) {
$self->{output}->output_add(long_msg => "skipping policy '" . $_ . "': no type or no matching filter type");
next;
}
$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();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'active']);
}
@ -88,37 +77,34 @@ sub disco_show {
$self->manage_selection(%options);
foreach (sort keys %{$self->{policies}}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_ !~ /$self->{option_results}->{filter_name}/i);
$_ !~ /$self->{option_results}->{filter_name}/i);
$self->{output}->add_disco_entry(name => $_,
active => $self->{policies}->{$_}->{active}
);
$self->{output}->add_disco_entry(
name => $_,
active => $self->{policies}->{$_}->{active}
);
}
}
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,11 +24,10 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
if (defined($self->{instance_mode}->{option_results}->{free})) {
@ -42,11 +41,13 @@ sub custom_usage_perfdata {
$total_options{cast_int} = 1;
}
$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});
$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}
);
}
sub custom_usage_threshold {
@ -65,12 +66,13 @@ sub custom_usage_threshold {
sub custom_usage_output {
my ($self, %options) = @_;
my $msg = 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;
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}
);
}
sub custom_usage_calc {
@ -82,7 +84,7 @@ sub custom_usage_calc {
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
return 0;
}
@ -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
}
},
}
];
}
@ -109,39 +111,29 @@ sub new {
my ($class, %options) = @_;
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 => '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' },
$options{options}->add_options(arguments => {
'filter-scratch:s' => { name => 'filter_scratch', default => 'scratch' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' }
});
return $self;
}
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();
}
@ -152,25 +144,25 @@ sub manage_selection {
#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#000001 - HCART2 000001L5 - - NONE - - - --- VP-05WEEKS-EXT 9 VP-SCRATCH 1250 0 - 30/11/2012 15:30 29/02/2016 20:43 27/01/2013 17:57 02/03/2016 01:36 00/00/0000 00:00 0 - 00/00/0000 00:00 00/00/0000 00:00 - - 50 ---
#000002 - HCART2 000002L5 - XXX-NBU-XXX TLD 0 8 - 000_00000_TLD VP-SCRATCH 4 VP-05WEEKS-EXT
# Remove header
$stdout =~ s/\x00//msg;
$stdout =~ s/^.*?----.*?\n//ms;
foreach my $line (split /\n/, $stdout) {
$line =~ /^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\s+\S+\s+\S+\s+(\S+)\s+\S+\s+\S+\s+(\S+)/;
my ($robot_host, $robot_slot, $pool) = ($1, $2, $3);
next if ($robot_slot !~ /[0-9]/);
$self->{global}->{total}++;
if (defined($self->{option_results}->{filter_scratch}) && $self->{option_results}->{filter_scratch} ne '' &&
$pool !~ /$self->{option_results}->{filter_scratch}/i) {
$self->{global}->{used}++;
}
}
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) = @_;
@ -31,14 +31,16 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'dedup-status' => 'apps::backup::netbackup::local::mode::dedupstatus',
'drive-cleaning' => 'apps::backup::netbackup::local::mode::drivecleaning',
'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',
'dedup-status' => 'apps::backup::netbackup::local::mode::dedupstatus',
'drive-cleaning' => 'apps::backup::netbackup::local::mode::drivecleaning',
'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'
);
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
return $self;
}