mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-22 05:04:44 +02:00
Secure plugins (#2691)
This commit is contained in:
parent
68c0bead7d
commit
b0b55a27cc
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
|
||||
|
||||
sub custom_status_threshold {
|
||||
my ($self, %options) = @_;
|
||||
@ -37,13 +36,13 @@ sub custom_status_threshold {
|
||||
|
||||
# To exclude some OK
|
||||
if (defined($self->{instance_mode}->{option_results}->{ok_status}) && $self->{instance_mode}->{option_results}->{ok_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{ok_status}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{ok_status})) {
|
||||
$status = 'ok';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_status}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{critical_status})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_status}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{warning_status})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -57,7 +56,8 @@ sub custom_status_threshold {
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf('status : %s (%s) [type: %s] [remote hostname: %s] [vmname: %s] [plan name: %s] [end time: %s]',
|
||||
return sprintf(
|
||||
'status : %s (%s) [type: %s] [remote hostname: %s] [vmname: %s] [plan name: %s] [end time: %s]',
|
||||
$self->{result_values}->{status} == 1 ? 'ok' : 'failed',
|
||||
$self->{result_values}->{status},
|
||||
$self->{result_values}->{type},
|
||||
@ -66,7 +66,6 @@ sub custom_status_output {
|
||||
$self->{result_values}->{plan_name},
|
||||
scalar(localtime($self->{result_values}->{end_time}))
|
||||
);
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
@ -90,13 +89,14 @@ sub set_counters {
|
||||
|
||||
$self->{maps_counters}->{job} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'status' }, { name => 'display' },
|
||||
key_values => [
|
||||
{ name => 'status' }, { name => 'display' },
|
||||
{ name => 'type' }, { name => 'rhostname' }, { name => 'vmname' }, { name => 'plan_name' },
|
||||
{ name => 'elapsed_time' }, { name => 'end_time' } ],
|
||||
closure_custom_calc => \&catalog_status_calc,
|
||||
{ name => 'elapsed_time' }, { name => 'end_time' }
|
||||
],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold')
|
||||
}
|
||||
},
|
||||
];
|
||||
@ -115,7 +115,7 @@ sub new {
|
||||
'ok-status:s' => { name => 'ok_status', default => '%{status} == 1' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{status} != 1' },
|
||||
'timezone:s' => { name => 'timezone' },
|
||||
'timezone:s' => { name => 'timezone' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -26,35 +26,7 @@ use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
sub custom_status_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
# To exclude some OK
|
||||
if (defined($self->{instance_mode}->{option_results}->{ok_status}) && $self->{instance_mode}->{option_results}->{ok_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{ok_status}") {
|
||||
$status = 'ok';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_status}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_status}") {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_threshold_ng);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
@ -62,16 +34,6 @@ sub custom_status_output {
|
||||
return 'Status : ' . $self->{result_values}->{status};
|
||||
}
|
||||
|
||||
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'};
|
||||
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
|
||||
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_long_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
@ -94,25 +56,8 @@ sub custom_long_calc {
|
||||
|
||||
sub custom_frozen_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_frozen}) && $self->{instance_mode}->{option_results}->{critical_frozen} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_frozen}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_frozen}) && $self->{instance_mode}->{option_results}->{warning_frozen} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_frozen}") {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
|
||||
my $status = catalog_status_threshold_ng($self, %options);
|
||||
$self->{instance_mode}->{last_status_frozen} = $status;
|
||||
return $status;
|
||||
}
|
||||
@ -167,30 +112,35 @@ sub set_counters {
|
||||
|
||||
$self->{maps_counters}->{job} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'status' }, { name => 'display' }, { name => 'type' }, { name => 'state' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
key_values => [
|
||||
{ name => 'status' }, { name => 'display' }, { name => 'type' }, { name => 'state' }
|
||||
],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
}
|
||||
},
|
||||
{ label => 'long', threshold => 0, set => {
|
||||
key_values => [ { name => 'status' }, { name => 'display' }, { name => 'elapsed' }, { name => 'type' },
|
||||
{ name => 'state' } ],
|
||||
{ label => 'long', type => 2, set => {
|
||||
key_values => [
|
||||
{ name => 'status' }, { name => 'display' }, { name => 'elapsed' }, { name => 'type' },
|
||||
{ name => 'state' }
|
||||
],
|
||||
closure_custom_calc => $self->can('custom_long_calc'),
|
||||
closure_custom_output => $self->can('custom_long_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'frozen', threshold => 0, set => {
|
||||
key_values => [ { name => 'kb', diff => 1 }, { name => 'status' },
|
||||
{ label => 'frozen', type => 2, critical_default => '%{state} =~ /active|queue/ && %{kb} == 0', set => {
|
||||
key_values => [
|
||||
{ name => 'kb', diff => 1 }, { name => 'status' },
|
||||
{ name => 'display' }, { name => 'elapsed' }, { name => 'type' }, { name => 'state' },
|
||||
{ name => 'parentid' }, { name => 'schedule' }, { name => 'jobid' } ],
|
||||
{ name => 'parentid' }, { name => 'schedule' }, { name => 'jobid' }
|
||||
],
|
||||
closure_custom_calc => $self->can('custom_frozen_calc'),
|
||||
closure_custom_output => $self->can('custom_frozen_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_frozen_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_frozen_threshold')
|
||||
}
|
||||
}
|
||||
];
|
||||
@ -219,11 +169,7 @@ sub new {
|
||||
'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' },
|
||||
'warning-long:s' => { name => 'warning_long' },
|
||||
'critical-long:s' => { name => 'critical_long' },
|
||||
'warning-frozen:s' => { name => 'warning_frozen' },
|
||||
'critical-frozen:s' => { name => 'critical_frozen', default => '%{state} =~ /active|queue/ && %{kb} == 0' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{status} > 1' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
@ -233,10 +179,7 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => [
|
||||
'ok_status', 'warning_status', 'critical_status', 'warning_long',
|
||||
'critical_long', 'warning_frozen', 'critical_frozen']
|
||||
);
|
||||
$self->change_macros(macros => ['ok_status', 'warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub policy_long_output {
|
||||
|
@ -26,61 +26,24 @@ use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
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_long_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg = 'elapsed time : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{elapsed});
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_long_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
$self->{result_values}->{elapsed} = $options{new_datas}->{$self->{instance} . '_elapsed'};
|
||||
|
||||
return 0;
|
||||
return 'elapsed time : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{elapsed});
|
||||
}
|
||||
|
||||
sub custom_frozen_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_frozen}) && $self->{instance_mode}->{option_results}->{critical_frozen} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_frozen}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_frozen}) && $self->{instance_mode}->{option_results}->{warning_frozen} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_frozen}") {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
|
||||
my $status = catalog_status_threshold_ng($self, %options);
|
||||
$self->{instance_mode}->{last_status_frozen} = $status;
|
||||
return $status;
|
||||
}
|
||||
@ -106,6 +69,12 @@ sub custom_frozen_calc {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_job_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "job '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
@ -116,20 +85,18 @@ sub set_counters {
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{job} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
{ label => 'status', type => 2, critical_default => '%{status} =~ /error/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 => 'long', threshold => 0, set => {
|
||||
{ label => 'long', threshold => 2, set => {
|
||||
key_values => [ { name => 'status' }, { name => 'display' }, { name => 'elapsed' } ],
|
||||
closure_custom_calc => $self->can('custom_long_calc'),
|
||||
closure_custom_output => $self->can('custom_long_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'frozen', threshold => 0, set => {
|
||||
@ -148,54 +115,36 @@ 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 => 'impexp' },
|
||||
"command-path:s" => { name => 'command_path', default => '/quadstorvtl/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => '-l' },
|
||||
"warning-status:s" => { name => 'warning_status' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /error/i' },
|
||||
"warning-long:s" => { name => 'warning_long' },
|
||||
"critical-long:s" => { name => 'critical_long' },
|
||||
"warning-frozen:s" => { name => 'warning_frozen' },
|
||||
"critical-frozen:s" => { name => 'critical_frozen' },
|
||||
});
|
||||
$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 => 'impexp' },
|
||||
'command-path:s' => { name => 'command_path', default => '/quadstorvtl/bin' },
|
||||
'command-options:s' => { name => 'command_options', default => '-l' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status', 'warning_long', 'critical_long', 'warning_frozen', 'critical_frozen']);
|
||||
}
|
||||
|
||||
sub prefix_job_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "job '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{cache_name} = "quadstor_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
|
||||
$self->{cache_name} = 'quadstor_' . $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'));
|
||||
|
||||
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) = 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}
|
||||
);
|
||||
$self->{jobs}->{global} = { job => {} };
|
||||
#JobID Type Source State Transfer Elapsed
|
||||
#252 Import 701831L2 Error 36.00 GB 572
|
||||
|
@ -40,9 +40,8 @@ sub custom_hosts_calc {
|
||||
|
||||
sub custom_hosts_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg = '';
|
||||
$msg .= "[up:".$self->{result_values}->{total_up}."][down:".$self->{result_values}->{total_down}."][unreachable:".$self->{result_values}->{total_unreachable}."]";
|
||||
return $msg
|
||||
|
||||
return "[up:".$self->{result_values}->{total_up}."][down:".$self->{result_values}->{total_down}."][unreachable:".$self->{result_values}->{total_unreachable}."]";
|
||||
}
|
||||
|
||||
sub custom_hosts_perfdata {
|
||||
@ -68,10 +67,10 @@ sub custom_hosts_threshold {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_total}) && $self->{instance_mode}->{option_results}->{critical_total} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_total}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{critical_total})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_total}) && $self->{instance_mode}->{option_results}->{warning_total} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_total}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{warning_total})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -123,10 +122,10 @@ sub custom_services_threshold {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_total}) && $self->{instance_mode}->{option_results}->{critical_total} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_total}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{critical_total})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_total}) && $self->{instance_mode}->{option_results}->{warning_total} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_total}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{warning_total})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -229,10 +228,10 @@ sub custom_groups_threshold {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_groups}) && $self->{instance_mode}->{option_results}->{critical_groups} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_groups}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{critical_groups})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_groups}) && $self->{instance_mode}->{option_results}->{warning_groups} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_groups}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{warning_groups})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -273,8 +272,10 @@ sub set_counters {
|
||||
|
||||
$self->{maps_counters}->{logicalgroups} = [
|
||||
{ label => 'group-svc-global', threshold => 0, set => {
|
||||
key_values => [ { name => 'ok' }, { name => 'unknown' }, { name => 'critical' }, { name => 'warning' },
|
||||
{ name => 'up' }, { name => 'down' }, { name => 'unreachable' }, { name => 'display' } ],
|
||||
key_values => [
|
||||
{ name => 'ok' }, { name => 'unknown' }, { name => 'critical' }, { name => 'warning' },
|
||||
{ name => 'up' }, { name => 'down' }, { name => 'unreachable' }, { name => 'display' }
|
||||
],
|
||||
closure_custom_calc => $self->can('custom_groups_calc'),
|
||||
closure_custom_output => $self->can('custom_groups_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_groups_threshold'),
|
||||
|
@ -28,56 +28,86 @@ use List::Util qw (min max sum);
|
||||
use JSON;
|
||||
my $config_data;
|
||||
|
||||
sub get_printf_vars {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
# compat
|
||||
if (ref($options{printf_var}) ne 'ARRAY') {
|
||||
$options{printf_var} = [split /,/, $options{printf_var}];
|
||||
}
|
||||
|
||||
my $message;
|
||||
my $vars = [];
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
foreach my $var (@{$options{printf_var}}) {
|
||||
$var =~ s/\$self->\{result_values\}/\$values/;
|
||||
push @$vars, $self->{output}->assign_eval(eval => $var, values => $options{values});
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'eval printf_var problem: ' . $message);
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
sub custom_metric_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg;
|
||||
my $message;
|
||||
my $output;
|
||||
|
||||
if ($self->{result_values}->{type} eq 'unique') {
|
||||
if (defined($config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_var}) && defined($config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg})) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
$msg = sprintf("$config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg}",
|
||||
eval "$config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_var}");
|
||||
};
|
||||
if (defined($config_data->{selection}->{ $self->{result_values}->{instance} }->{formatting}->{printf_var}) && defined($config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg})) {
|
||||
my $vars = $self->{instance_mode}->get_printf_vars(
|
||||
printf_var => $config_data->{selection}->{ $self->{result_values}->{instance} }->{formatting}->{printf_var},
|
||||
values => $self->{result_values}
|
||||
);
|
||||
$output = sprintf(
|
||||
$config_data->{selection}->{ $self->{result_values}->{instance} }->{formatting}->{printf_msg},
|
||||
@$vars
|
||||
);
|
||||
} elsif (defined($config_data->{filters}->{formatting}->{printf_var}) && defined($config_data->{filters}->{formatting}->{printf_msg})) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
$msg = sprintf("$config_data->{filters}->{formatting}->{printf_msg}", eval "$config_data->{filters}->{formatting}->{printf_var}");
|
||||
};
|
||||
my $vars = $self->{instance_mode}->get_printf_vars(
|
||||
printf_var => $config_data->{filters}->{formatting}->{printf_var},
|
||||
values => $self->{result_values}
|
||||
);
|
||||
$output = sprintf(
|
||||
$config_data->{filters}->{formatting}->{printf_msg},
|
||||
@$vars
|
||||
);
|
||||
} else {
|
||||
$msg = sprintf("Metric '%s' value is '%s'", $self->{result_values}->{instance}, $self->{result_values}->{value});
|
||||
$output = sprintf("Metric '%s' value is '%s'", $self->{result_values}->{instance}, $self->{result_values}->{value});
|
||||
}
|
||||
}
|
||||
|
||||
if ($self->{result_values}->{type} eq 'global') {
|
||||
if (defined($config_data->{virtualcurve}->{$self->{result_values}->{instance}}->{formatting})) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
$msg = sprintf("$config_data->{virtualcurve}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg}",
|
||||
eval "$config_data->{virtualcurve}->{$self->{result_values}->{instance}}->{formatting}->{printf_var}");
|
||||
};
|
||||
if (defined($config_data->{virtualcurve}->{ $self->{result_values}->{instance} }->{formatting})) {
|
||||
my $vars = $self->{instance_mode}->get_printf_vars(
|
||||
printf_var => $config_data->{virtualcurve}->{ $self->{result_values}->{instance} }->{formatting}->{printf_var},
|
||||
values => $self->{result_values}
|
||||
);
|
||||
$output = sprintf(
|
||||
$config_data->{virtualcurve}->{ $self->{result_values}->{instance} }->{formatting}->{printf_msg},
|
||||
@$vars
|
||||
);
|
||||
} elsif (defined($config_data->{formatting}->{printf_var}) && defined($config_data->{formatting}->{printf_msg})) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
$msg = sprintf("$config_data->{formatting}->{printf_msg}", eval "$config_data->{formatting}->{printf_var}");
|
||||
};
|
||||
my $vars = $self->{instance_mode}->get_printf_vars(
|
||||
printf_var => $config_data->{formatting}->{printf_var},
|
||||
values => $self->{result_values}
|
||||
);
|
||||
$output = sprintf(
|
||||
$config_data->{formatting}->{printf_msg},
|
||||
@$vars
|
||||
);
|
||||
} else {
|
||||
$msg = sprintf("Metric '%s' value is '%s'", $self->{result_values}->{instance}, $self->{result_values}->{value});
|
||||
$output = sprintf("Metric '%s' value is '%s'", $self->{result_values}->{instance}, $self->{result_values}->{value});
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'printf expression problem: ' . $message);
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $msg;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
sub custom_metric_calc {
|
||||
@ -333,9 +363,10 @@ sub manage_selection {
|
||||
max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max');
|
||||
|
||||
if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none') {
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none' && defined($config_data->{virtualcurve}->{$vcurve}->{custom})) ?
|
||||
eval "$config_data->{virtualcurve}->{$vcurve}->{custom}" :
|
||||
eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}";
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = (
|
||||
$config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none' && defined($config_data->{virtualcurve}->{$vcurve}->{custom})) ?
|
||||
eval "$config_data->{virtualcurve}->{$vcurve}->{custom}" :
|
||||
eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}";
|
||||
}
|
||||
|
||||
$self->{vmetrics}->{$vcurve}->{unit} = (defined($config_data->{virtualcurve}->{$vcurve}->{unit})) ? $config_data->{virtualcurve}->{$vcurve}->{unit} : '';
|
||||
|
@ -58,7 +58,7 @@ sub change_macros {
|
||||
|
||||
foreach (('warning', 'critical')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ sub change_macros {
|
||||
|
||||
foreach (('warning', 'critical')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ sub change_macros {
|
||||
|
||||
foreach (('warning', 'critical')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ sub change_macros {
|
||||
|
||||
foreach (('warning', 'critical')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ sub change_macros {
|
||||
|
||||
foreach (('warning', 'critical')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ sub change_macros {
|
||||
|
||||
foreach (('warning', 'critical')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ sub change_macros {
|
||||
|
||||
foreach (('warning', 'critical')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ sub manage_selection {
|
||||
|
||||
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);
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
@ -86,8 +86,10 @@ sub run {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [state = " . $self->{nodes}->{$name}->{state} . "]");
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List Nodes:');
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => 'List nodes:'
|
||||
);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -121,11 +121,13 @@ sub disco_show {
|
||||
|
||||
$self->manage_selection(disco => 1);
|
||||
foreach my $id (sort keys %{$self->{resources}}) {
|
||||
$self->{output}->add_disco_entry(name => $self->{resources}->{$id}->{name},
|
||||
state => $self->{resources}->{$id}->{state},
|
||||
id => $id,
|
||||
owner_node => $self->{resources}->{$id}->{owner_node},
|
||||
class => $self->{resources}->{$id}->{class});
|
||||
$self->{output}->add_disco_entry(
|
||||
name => $self->{resources}->{$id}->{name},
|
||||
state => $self->{resources}->{$id}->{state},
|
||||
id => $id,
|
||||
owner_node => $self->{resources}->{$id}->{owner_node},
|
||||
class => $self->{resources}->{$id}->{class}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,36 +25,18 @@ use base qw(centreon::plugins::templates::counter);
|
||||
use strict;
|
||||
use warnings;
|
||||
use Win32::OLE;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'rg', type => 1, cb_prefix_output => 'prefix_rg_output', message_multiple => 'All resource groups are ok' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{rg} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'state' }, { name => 'display' }, { name => 'owner_node' }, { name => 'preferred_owners' } ],
|
||||
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 => $self->can('custom_threshold_output'),
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
my $instance_current;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub is_preferred_node {
|
||||
if (!defined($instance_current->{result_values}->{preferred_owners}) ||
|
||||
scalar(@{$instance_current->{result_values}->{preferred_owners}}) == 0) {
|
||||
my (%options) = @_;
|
||||
|
||||
if (!defined($options{preferred_owners}) ||
|
||||
scalar(@{$options{preferred_owners}}) == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
foreach my $pref_node (@{$instance_current->{result_values}->{preferred_owners}}) {
|
||||
if ($pref_node eq $instance_current->{result_values}->{owner_node}) {
|
||||
foreach my $pref_node (@{$options{preferred_owners}}) {
|
||||
if ($pref_node eq $options{owner_node}) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -62,45 +44,16 @@ sub is_preferred_node {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_threshold_output {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
$instance_current = $self;
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_status}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_status}") {
|
||||
$status = 'warning';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{unknown_status}) && $self->{instance_mode}->{option_results}->{unknown_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{unknown_status}") {
|
||||
$status = 'unknown';
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $pref_nodes = 'any';
|
||||
if (defined($instance_current->{result_values}->{preferred_owners}) &&
|
||||
scalar(@{$instance_current->{result_values}->{preferred_owners}}) > 0) {
|
||||
$pref_nodes = join(', ', @{$instance_current->{result_values}->{preferred_owners}});
|
||||
if (defined($self->{result_values}->{preferred_owners}) &&
|
||||
scalar(@{$self->{result_values}->{preferred_owners}}) > 0) {
|
||||
$pref_nodes = join(', ', @{$self->{result_values}->{preferred_owners}});
|
||||
}
|
||||
|
||||
my $msg = 'state : ' . $self->{result_values}->{state} . ' [node: ' . $self->{result_values}->{owner_node} . '] [preferred nodes: ' . $pref_nodes . ']';
|
||||
return $msg;
|
||||
return 'state: ' . $self->{result_values}->{state} . ' [node: ' . $self->{result_values}->{owner_node} . '] [preferred nodes: ' . $pref_nodes . ']';
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
@ -110,6 +63,10 @@ sub custom_status_calc {
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
$self->{result_values}->{owner_node} = $options{new_datas}->{$self->{instance} . '_owner_node'};
|
||||
$self->{result_values}->{preferred_owners} = $options{new_datas}->{$self->{instance} . '_preferred_owners'};
|
||||
$self->{result_values}->{is_preferred_node} = is_preferred_node(
|
||||
preferred_owners => $self->{result_values}->{preferred_owners},
|
||||
owner_node => $self->{result_values}->{owner_node}
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -119,18 +76,38 @@ sub prefix_rg_output {
|
||||
return "Resource group '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'rg', type => 1, cb_prefix_output => 'prefix_rg_output', message_multiple => 'All resource groups are ok' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{rg} = [
|
||||
{
|
||||
label => 'status', type => 2,
|
||||
unknown_default => '%{state} =~ /unknown/',
|
||||
warning_default => '%{is_preferred_node} == 0',
|
||||
critical_default => '%{state} =~ /failed|offline/',
|
||||
set => {
|
||||
key_values => [ { name => 'state' }, { name => 'display' }, { name => 'owner_node' }, { name => 'preferred_owners' } ],
|
||||
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_ng
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '%{state} =~ /unknown/' },
|
||||
"warning-status:s" => { name => 'warning_status', default => 'not is_preferred_node()' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{state} =~ /failed|offline/' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -139,7 +116,12 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
|
||||
# compatibility
|
||||
foreach (('unknown_status', 'warning_status', 'critical_status')) {
|
||||
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') {
|
||||
$self->{option_results}->{$_} =~ s/is_preferred_node\(\)/\$values->{is_preferred_node}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my %map_state = (
|
||||
@ -148,7 +130,7 @@ my %map_state = (
|
||||
1 => 'offline',
|
||||
2 => 'failed',
|
||||
3 => 'partial online',
|
||||
4 => 'pending',
|
||||
4 => 'pending'
|
||||
);
|
||||
|
||||
sub manage_selection {
|
||||
@ -161,12 +143,10 @@ sub manage_selection {
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $query = "Select * from MSCluster_ResourceGroupToPreferredNode";
|
||||
my $query = 'Select * from MSCluster_ResourceGroupToPreferredNode';
|
||||
my $resultset = $wmi->ExecQuery($query);
|
||||
my $preferred_nodes = {};
|
||||
foreach my $obj (in $resultset) {
|
||||
use Data::Dumper;
|
||||
|
||||
# MSCluster_ResourceGroup.Name="xxx"
|
||||
if ($obj->GroupComponent =~ /MSCluster_ResourceGroup.Name="(.*?)"/i) {
|
||||
my $rg = $1;
|
||||
@ -178,7 +158,7 @@ sub manage_selection {
|
||||
}
|
||||
|
||||
$self->{rg} = {};
|
||||
$query = "Select * from MSCluster_ResourceGroup";
|
||||
$query = 'Select * from MSCluster_ResourceGroup';
|
||||
$resultset = $wmi->ExecQuery($query);
|
||||
foreach my $obj (in $resultset) {
|
||||
my $name = $obj->{Name};
|
||||
@ -192,8 +172,10 @@ sub manage_selection {
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{rg}->{$id} = { display => $name, state => $state, owner_node => $owner_node,
|
||||
preferred_owners => defined($preferred_nodes->{$name}) ? $preferred_nodes->{$name} : [] };
|
||||
$self->{rg}->{$id} = {
|
||||
display => $name, state => $state, owner_node => $owner_node,
|
||||
preferred_owners => defined($preferred_nodes->{$name}) ? $preferred_nodes->{$name} : []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +200,7 @@ Can used special variables like: %{state}, %{display}, %{owner_node}
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status (Default: 'not is_preferred_node()').
|
||||
Set warning threshold for status (Default: '%{is_preferred_node} == 0').
|
||||
Can used special variables like: %{state}, %{display}, %{owner_node}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
@ -41,7 +41,7 @@ sub custom_content_output {
|
||||
my $msg = 'HTTP test(s)';
|
||||
if (!$self->{output}->is_status(value => $self->{instance_mode}->{content_status}, compare => 'ok', litteral => 1)) {
|
||||
my $filter = $self->{instance_mode}->{option_results}->{lc($self->{instance_mode}->{content_status}) . '-content'};
|
||||
$filter =~ s/\$self->\{result_values\}->/%/g;
|
||||
$filter =~ s/\$values->/%/g;
|
||||
$msg = sprintf("Content test [filter: '%s']", $filter);
|
||||
}
|
||||
|
||||
|
@ -28,56 +28,86 @@ use List::Util qw (min max sum);
|
||||
use JSON;
|
||||
my $config_data;
|
||||
|
||||
sub get_printf_vars {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
# compat
|
||||
if (ref($options{printf_var}) ne 'ARRAY') {
|
||||
$options{printf_var} = [split /,/, $options{printf_var}];
|
||||
}
|
||||
|
||||
my $message;
|
||||
my $vars = [];
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
foreach my $var (@{$options{printf_var}}) {
|
||||
$var =~ s/\$self->\{result_values\}/\$values/;
|
||||
push @$vars, $self->{output}->assign_eval(eval => $var, values => $options{values});
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'eval printf_var problem: ' . $message);
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
sub custom_metric_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg;
|
||||
my $message;
|
||||
|
||||
my $output;
|
||||
if ($self->{result_values}->{type} eq 'unique') {
|
||||
if (defined($config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_var}) && defined($config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg})) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
$msg = sprintf("$config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg}",
|
||||
eval "$config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_var}");
|
||||
};
|
||||
my $vars = $self->{instance_mode}->get_printf_vars(
|
||||
printf_var => $config_data->{selection}->{ $self->{result_values}->{instance} }->{formatting}->{printf_var},
|
||||
values => $self->{result_values}
|
||||
);
|
||||
$output = sprintf(
|
||||
$config_data->{selection}->{ $self->{result_values}->{instance} }->{formatting}->{printf_msg},
|
||||
@$vars
|
||||
);
|
||||
} elsif (defined($config_data->{formatting}->{printf_var}) && defined($config_data->{formatting}->{printf_msg})) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
$msg = sprintf("$config_data->{formatting}->{printf_msg}", eval "$config_data->{formatting}->{printf_var}");
|
||||
};
|
||||
my $vars = $self->{instance_mode}->get_printf_vars(
|
||||
printf_var => $config_data->{formatting}->{printf_var},
|
||||
values => $self->{result_values}
|
||||
);
|
||||
$output = sprintf(
|
||||
$config_data->{formatting}->{printf_msg},
|
||||
@$vars
|
||||
);
|
||||
} else {
|
||||
$msg = sprintf("Metric '%s' value is '%s'", $self->{result_values}->{instance}, $self->{result_values}->{value});
|
||||
$output = sprintf("Metric '%s' value is '%s'", $self->{result_values}->{instance}, $self->{result_values}->{value});
|
||||
}
|
||||
}
|
||||
|
||||
if ($self->{result_values}->{type} eq 'global') {
|
||||
if (defined($config_data->{virtualcurve}->{$self->{result_values}->{instance}}->{formatting})) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
$msg = sprintf("$config_data->{virtualcurve}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg}",
|
||||
eval "$config_data->{virtualcurve}->{$self->{result_values}->{instance}}->{formatting}->{printf_var}");
|
||||
};
|
||||
my $vars = $self->{instance_mode}->get_printf_vars(
|
||||
printf_var => $config_data->{virtualcurve}->{ $self->{result_values}->{instance} }->{formatting}->{printf_var},
|
||||
values => $self->{result_values}
|
||||
);
|
||||
$output = sprintf(
|
||||
$config_data->{virtualcurve}->{ $self->{result_values}->{instance} }->{formatting}->{printf_msg},
|
||||
@$vars
|
||||
);
|
||||
} elsif (defined($config_data->{formatting}->{printf_var}) && defined($config_data->{formatting}->{printf_msg})) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
$msg = sprintf("$config_data->{formatting}->{printf_msg}", eval "$config_data->{formatting}->{printf_var}");
|
||||
};
|
||||
my $vars = $self->{instance_mode}->get_printf_vars(
|
||||
printf_var => $config_data->{formatting}->{printf_var},
|
||||
values => $self->{result_values}
|
||||
);
|
||||
$output = sprintf(
|
||||
$config_data->{formatting}->{printf_msg},
|
||||
@$vars
|
||||
);
|
||||
} else {
|
||||
$msg = sprintf("Metric '%s' value is '%s'", $self->{result_values}->{instance}, $self->{result_values}->{value});
|
||||
$output = sprintf("Metric '%s' value is '%s'", $self->{result_values}->{instance}, $self->{result_values}->{value});
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'printf expression problem: ' . $message);
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $msg;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
sub custom_metric_calc {
|
||||
@ -109,15 +139,15 @@ sub custom_metric_calc {
|
||||
sub custom_metric_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(label => $self->{result_values}->{instance},
|
||||
value => $self->{result_values}->{perfdata_value},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => ($self->{result_values}->{type} eq 'unique') ? 'warning-metric' : 'warning-global-'.$self->{result_values}->{instance}),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => ($self->{result_values}->{type} eq 'unique') ? 'critical-metric' : 'critical-global-'.$self->{result_values}->{instance}),
|
||||
unit => $self->{result_values}->{perfdata_unit},
|
||||
min => $self->{result_values}->{min},
|
||||
max => $self->{result_values}->{max},
|
||||
);
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => $self->{result_values}->{instance},
|
||||
value => $self->{result_values}->{perfdata_value},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => ($self->{result_values}->{type} eq 'unique') ? 'warning-metric' : 'warning-global-'.$self->{result_values}->{instance}),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => ($self->{result_values}->{type} eq 'unique') ? 'critical-metric' : 'critical-global-'.$self->{result_values}->{instance}),
|
||||
unit => $self->{result_values}->{perfdata_unit},
|
||||
min => $self->{result_values}->{min},
|
||||
max => $self->{result_values}->{max},
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_metric_threshold {
|
||||
@ -126,9 +156,13 @@ sub custom_metric_threshold {
|
||||
my $label_warn = ($self->{result_values}->{type} eq 'unique') ? 'warning-metric' : 'warning-global-'.$self->{result_values}->{instance};
|
||||
my $label_crit = ($self->{result_values}->{type} eq 'unique') ? 'critical-metric' : 'critical-global-'.$self->{result_values}->{instance};
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{perfdata_value},
|
||||
threshold => [ { label => $label_crit, exit_litteral => 'critical' },
|
||||
{ label => $label_warn, exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{perfdata}->threshold_check(
|
||||
value => $self->{result_values}->{perfdata_value},
|
||||
threshold => [
|
||||
{ label => $label_crit, exit_litteral => 'critical' },
|
||||
{ label => $label_warn, exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
@ -143,7 +177,7 @@ sub set_counters {
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_output => $self->can('custom_metric_output'),
|
||||
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold')
|
||||
}
|
||||
}
|
||||
];
|
||||
@ -154,7 +188,7 @@ sub set_counters {
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_output => $self->can('custom_metric_output'),
|
||||
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold')
|
||||
}
|
||||
}
|
||||
];
|
||||
@ -165,10 +199,10 @@ sub new {
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"config:s" => { name => 'config' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'config:s' => { name => 'config' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -292,14 +326,18 @@ sub manage_selection {
|
||||
|
||||
next if (!defined($self->{vmetrics}->{$vcurve}->{values}) || scalar(@{$self->{vmetrics}->{$vcurve}->{values}}) == 0);
|
||||
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value},
|
||||
sum(@{$self->{vmetrics}->{$vcurve}->{values}}) / scalar(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'avg');
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value},
|
||||
sum(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'sum');
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value},
|
||||
min(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'min');
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value},
|
||||
max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max');
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf(
|
||||
$config_data->{formatting}->{printf_metric_value},
|
||||
sum(@{$self->{vmetrics}->{$vcurve}->{values}}) / scalar(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'avg');
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf(
|
||||
$config_data->{formatting}->{printf_metric_value},
|
||||
sum(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'sum');
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf(
|
||||
$config_data->{formatting}->{printf_metric_value},
|
||||
min(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'min');
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf(
|
||||
$config_data->{formatting}->{printf_metric_value},
|
||||
max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max');
|
||||
$self->{vmetrics}->{$vcurve}->{aggregated_value} = eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}" if (defined($config_data->{virtualcurve}->{$vcurve}->{custom}));
|
||||
|
||||
$self->{vmetrics}->{$vcurve}->{unit} = (defined($config_data->{virtualcurve}->{$vcurve}->{unit})) ? $config_data->{virtualcurve}->{$vcurve}->{unit} : '';
|
||||
|
@ -36,14 +36,15 @@ sub custom_select_threshold {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
our $expand = $self->{result_values}->{expand};
|
||||
if (defined($self->{result_values}->{config}->{critical}) && $self->{result_values}->{config}->{critical} &&
|
||||
eval "$self->{result_values}->{config}->{critical}") {
|
||||
$self->{safe}->reval($self->{result_values}->{config}->{critical})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{result_values}->{config}->{warning}) && $self->{result_values}->{config}->{warning} ne '' &&
|
||||
eval "$self->{result_values}->{config}->{warning}") {
|
||||
$self->{safe}->reval($self->{result_values}->{config}->{warning})) {
|
||||
$status = 'warning';
|
||||
} elsif (defined($self->{result_values}->{config}->{unknown}) && $self->{result_values}->{config}->{unknown} &&
|
||||
eval "$self->{result_values}->{config}->{unknown}") {
|
||||
$self->{safe}->reval($self->{result_values}->{config}->{unknown})) {
|
||||
$status = 'unknown';
|
||||
}
|
||||
if ($@) {
|
||||
@ -128,6 +129,8 @@ sub new {
|
||||
'filter-selection:s%' => { name => 'filter_selection' },
|
||||
});
|
||||
|
||||
$self->{safe} = Safe->new();
|
||||
$self->{safe}->share('$expand');
|
||||
$self->{snmp_cache} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
@ -732,7 +735,7 @@ sub prepare_variables {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return undef if (!defined($options{value}));
|
||||
$options{value} =~ s/%\(([a-z-A-Z0-9\.]+?)\)/\$self->{result_values}->{expand}->{'$1'}/g;
|
||||
$options{value} =~ s/%\(([a-z-A-Z0-9\.]+?)\)/\$expand->{'$1'}/g;
|
||||
return $options{value};
|
||||
}
|
||||
|
||||
@ -740,8 +743,14 @@ sub check_filter {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return 0 if (!defined($options{filter}) || $options{filter} eq '');
|
||||
$options{filter} =~ s/%\(([a-z-A-Z0-9\.]+?)\)/\$self->{expand}->{'$1'}/g;
|
||||
return 0 if (eval "$options{filter}");
|
||||
our $expand = $self->{expand};
|
||||
$options{filter} =~ s/%\(([a-z-A-Z0-9\.]+?)\)/\$expand->{'$1'}/g;
|
||||
my $result = $self->{safe}->reval("$options{filter}");
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => 'Unsafe code evaluation: ' . $@);
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
return 0 if ($result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ sub connector_response_status {
|
||||
}
|
||||
|
||||
foreach (('unknown_connector_status', 'warning_connector_status', 'critical_connector_status')) {
|
||||
$self->{$_} =~ s/%\{(.*?)\}/\$self->{result}->{$1}/g;
|
||||
$self->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
|
||||
# Check response
|
||||
@ -170,13 +170,13 @@ sub connector_response_status {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{critical_connector_status}) && $self->{critical_connector_status} ne '' &&
|
||||
eval "$self->{critical_connector_status}") {
|
||||
$self->{output}->test_eval(test => $self->{critical_connector_status}, values => $self->{result})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{warning_connector_status}) && $self->{warning_connector_status} ne '' &&
|
||||
eval "$self->{warning_connector_status}") {
|
||||
$self->{output}->test_eval(test => $self->{warning_connector_status}, values => $self->{result})) {
|
||||
$status = 'warning';
|
||||
} elsif (defined($self->{unknown_connector_status}) && $self->{unknown_connector_status} ne '' &&
|
||||
eval "$self->{unknown_connector_status}") {
|
||||
$self->{output}->test_eval(test => $self->{unknown_connector_status}, values => $self->{result})) {
|
||||
$status = 'unknown';
|
||||
}
|
||||
};
|
||||
|
@ -36,14 +36,12 @@ sub custom_status_threshold {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
my $label = $self->{label};
|
||||
$label =~ s/-/_/g;
|
||||
if (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") {
|
||||
if (defined($self->{instance_mode}->{option_results}->{'critical-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'critical-' . $self->{label}} ne '' &&
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'critical-' . $self->{label}})) {
|
||||
$self->{instance_mode}->{dc_critical}++;
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") {
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'warning-' . $self->{label}} ne '' &&
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'warning-' . $self->{label}})) {
|
||||
$self->{instance_mode}->{dc_warning}++;
|
||||
$status = 'warning';
|
||||
}
|
||||
@ -58,7 +56,7 @@ sub custom_status_threshold {
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf(
|
||||
return sprintf(
|
||||
'alarm [%s] [%s] [%s] [%s] %s/%s',
|
||||
$self->{result_values}->{status},
|
||||
$self->{result_values}->{type},
|
||||
@ -67,8 +65,6 @@ sub custom_status_output {
|
||||
$self->{result_values}->{name},
|
||||
$self->{result_values}->{description}
|
||||
);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_dcmetrics_perfdata {
|
||||
@ -131,7 +127,11 @@ sub set_counters {
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{alarm} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
{
|
||||
label => 'status', type => 2,
|
||||
warning_default => '%{status} =~ /yellow/i',
|
||||
critical_default => '%{status} =~ /red/i',
|
||||
set => {
|
||||
key_values => [
|
||||
{ name => 'entity_name' }, { name => 'status' },
|
||||
{ name => 'time' }, { name => 'description' }, { name => 'name' }, { name => 'type' }, { name => 'since' }
|
||||
@ -144,7 +144,7 @@ sub set_counters {
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{dc_metrics} = [
|
||||
{ label => 'alarm-warning', threshold => 0, set => {
|
||||
{ label => 'alarm-warning', type => 2, set => {
|
||||
key_values => [ { name => 'name' } ],
|
||||
output_template => '',
|
||||
closure_custom_threshold_check => sub { return 'ok' },
|
||||
@ -152,7 +152,7 @@ sub set_counters {
|
||||
closure_custom_perfdata => $self->can('custom_dcmetrics_perfdata')
|
||||
}
|
||||
},
|
||||
{ label => 'alarm-critical', threshold => 0, set => {
|
||||
{ label => 'alarm-critical', type => 2, set => {
|
||||
key_values => [ { name => 'name' } ],
|
||||
output_template => '',
|
||||
closure_custom_threshold_check => sub { return 'ok' },
|
||||
@ -188,16 +188,16 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"datacenter:s" => { name => 'datacenter' },
|
||||
"filter" => { name => 'filter' },
|
||||
"filter-time:s" => { name => 'filter_time', },
|
||||
"memory" => { name => 'memory', },
|
||||
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' },
|
||||
'datacenter:s' => { name => 'datacenter' },
|
||||
'filter' => { name => 'filter' },
|
||||
'filter-time:s' => { name => 'filter_time' },
|
||||
'memory' => { name => 'memory' }
|
||||
});
|
||||
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse',
|
||||
error_msg => "Cannot load module 'Date::Parse'.");
|
||||
centreon::plugins::misc::mymodule_load(
|
||||
output => $self->{output}, module => 'Date::Parse',
|
||||
error_msg => "Cannot load module 'Date::Parse'."
|
||||
);
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
return $self;
|
||||
@ -207,7 +207,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
if (defined($self->{option_results}->{memory})) {
|
||||
$self->{statefile_cache}->check_options(%options);
|
||||
}
|
||||
|
@ -36,14 +36,12 @@ sub custom_status_threshold {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
my $label = $self->{label};
|
||||
$label =~ s/-/_/g;
|
||||
if (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") {
|
||||
if (defined($self->{instance_mode}->{option_results}->{'critical-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'critical-' . $self->{label}} ne '' &&
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'critical-' . $self->{label}})) {
|
||||
$self->{instance_mode}->{host_critical}++;
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") {
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'warning-' . $self->{label}} ne '' &&
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'warning-' . $self->{label}})) {
|
||||
$self->{instance_mode}->{host_warning}++;
|
||||
$status = 'warning';
|
||||
}
|
||||
@ -58,7 +56,8 @@ sub custom_status_threshold {
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("alarm [%s] [%s] [%s] [%s] %s/%s",
|
||||
return sprintf(
|
||||
"alarm [%s] [%s] [%s] [%s] %s/%s",
|
||||
$self->{result_values}->{status},
|
||||
$self->{result_values}->{type},
|
||||
$self->{result_values}->{entity_name},
|
||||
@ -66,8 +65,6 @@ sub custom_status_output {
|
||||
$self->{result_values}->{name},
|
||||
$self->{result_values}->{description}
|
||||
);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_esxhost_perfdata {
|
||||
@ -129,9 +126,15 @@ sub set_counters {
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{alarm} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'entity_name' }, { name => 'status' },
|
||||
{ name => 'time' }, { name => 'description' }, { name => 'name' }, { name => 'type' }, { name => 'since' } ],
|
||||
{
|
||||
label => 'status', type => 2,
|
||||
warning_default => '%{status} =~ /yellow/i',
|
||||
critical_default => '%{status} =~ /red/i',
|
||||
set => {
|
||||
key_values => [
|
||||
{ name => 'entity_name' }, { name => 'status' },
|
||||
{ name => 'time' }, { name => 'description' }, { name => 'name' }, { name => 'type' }, { name => 'since' }
|
||||
],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold')
|
||||
@ -140,7 +143,7 @@ sub set_counters {
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{esxhost_metrics} = [
|
||||
{ label => 'alarm-warning', threshold => 0, set => {
|
||||
{ label => 'alarm-warning', type => 2, set => {
|
||||
key_values => [ { name => 'name' } ],
|
||||
output_template => '',
|
||||
closure_custom_threshold_check => sub { return 'ok' },
|
||||
@ -148,7 +151,7 @@ sub set_counters {
|
||||
closure_custom_perfdata => $self->can('custom_esxhost_perfdata')
|
||||
}
|
||||
},
|
||||
{ label => 'alarm-critical', threshold => 0, set => {
|
||||
{ label => 'alarm-critical', type => 2, set => {
|
||||
key_values => [ { name => 'name' } ],
|
||||
output_template => '',
|
||||
closure_custom_threshold_check => sub { return 'ok' },
|
||||
@ -183,20 +186,19 @@ sub new {
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"esx-hostname:s" => { name => 'esx_hostname' },
|
||||
"filter" => { name => 'filter' },
|
||||
"scope-datacenter:s" => { name => 'scope_datacenter' },
|
||||
"scope-cluster:s" => { name => 'scope_cluster' },
|
||||
"filter-time:s" => { name => 'filter_time', },
|
||||
"memory" => { name => 'memory', },
|
||||
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'esx-hostname:s' => { name => 'esx_hostname' },
|
||||
'filter' => { name => 'filter' },
|
||||
'scope-datacenter:s' => { name => 'scope_datacenter' },
|
||||
'scope-cluster:s' => { name => 'scope_cluster' },
|
||||
'filter-time:s' => { name => 'filter_time' },
|
||||
'memory' => { name => 'memory' }
|
||||
});
|
||||
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse',
|
||||
error_msg => "Cannot load module 'Date::Parse'.");
|
||||
centreon::plugins::misc::mymodule_load(
|
||||
output => $self->{output}, module => 'Date::Parse',
|
||||
error_msg => "Cannot load module 'Date::Parse'."
|
||||
);
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
@ -205,7 +207,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
if (defined($self->{option_results}->{memory})) {
|
||||
$self->{statefile_cache}->check_options(%options);
|
||||
}
|
||||
@ -216,8 +217,10 @@ sub manage_selection {
|
||||
|
||||
$self->{global} = { yellow => 0, red => 0 };
|
||||
$self->{esxhost} = {};
|
||||
my $response = $options{custom}->execute(params => $self->{option_results},
|
||||
command => 'alarmhost');
|
||||
my $response = $options{custom}->execute(
|
||||
params => $self->{option_results},
|
||||
command => 'alarmhost'
|
||||
);
|
||||
|
||||
my $last_time;
|
||||
if (defined($self->{option_results}->{memory})) {
|
||||
|
@ -81,10 +81,10 @@ sub check {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' &&
|
||||
eval "$self->{option_results}->{critical}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning}) && $self->{option_results}->{warning} ne '' &&
|
||||
eval "$self->{option_results}->{warning}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{warning}, values => $self->{data})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -92,21 +92,29 @@ sub check {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("ActiveSync scenario '%s' to '%s' is '%s'",
|
||||
$self->{data}->{scenario}, $options{mailbox}, $self->{data}->{result}));
|
||||
$self->{output}->output_add(
|
||||
severity => $status,
|
||||
short_msg => sprintf(
|
||||
"ActiveSync scenario '%s' to '%s' is '%s'",
|
||||
$self->{data}->{scenario}, $options{mailbox}, $self->{data}->{result}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($self->{data}->{latency} =~ /^(\d+)/) {
|
||||
$self->{output}->perfdata_add(label => $self->{data}->{scenario}, unit => 's',
|
||||
value => sprintf("%.3f", $1 / 1000),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(
|
||||
label => $self->{data}->{scenario}, unit => 's',
|
||||
value => sprintf("%.3f", $1 / 1000),
|
||||
min => 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,13 +56,13 @@ exit 0
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Imap to '" . $options{mailbox} . "' is ok.");
|
||||
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => "Imap to '" . $options{mailbox} . "' is ok."
|
||||
);
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) {
|
||||
@ -79,10 +79,10 @@ sub check {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' &&
|
||||
eval "$self->{option_results}->{critical}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning}) && $self->{option_results}->{warning} ne '' &&
|
||||
eval "$self->{option_results}->{warning}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{warning}, values => $self->{data})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -90,9 +90,13 @@ sub check {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("Imap scenario '%s' to '%s' is '%s'",
|
||||
$self->{data}->{scenario}, $options{mailbox}, $self->{data}->{result}));
|
||||
$self->{output}->output_add(
|
||||
severity => $status,
|
||||
short_msg => sprintf(
|
||||
"Imap scenario '%s' to '%s' is '%s'",
|
||||
$self->{data}->{scenario}, $options{mailbox}, $self->{data}->{result}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($self->{data}->{latency} =~ /^(\d+)/) {
|
||||
@ -105,8 +109,10 @@ sub check {
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,14 +49,14 @@ exit 0
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][result= Success ][error=...]
|
||||
|
||||
if ($options{stdout} !~ /^\[name=(.*?)\]\[server=(.*?)\]\[result=(.*?)\]\[error=(.*)\]$/) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations'
|
||||
);
|
||||
return ;
|
||||
}
|
||||
$self->{data} = {};
|
||||
@ -64,10 +64,16 @@ sub check {
|
||||
(centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
|
||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "MAPI connection to '" . $options{mailbox} . "' is '" . $self->{data}->{result} . "'.");
|
||||
$self->{output}->output_add(long_msg => sprintf("Database: %s, Server: %s\nError: %s",
|
||||
$self->{data}->{database}, $self->{data}->{server}, $self->{data}->{error}));
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => "MAPI connection to '" . $options{mailbox} . "' is '" . $self->{data}->{result} . "'."
|
||||
);
|
||||
$self->{output}->output_add(
|
||||
long_msg => sprintf(
|
||||
"Database: %s, Server: %s\nError: %s",
|
||||
$self->{data}->{database}, $self->{data}->{server}, $self->{data}->{error}
|
||||
)
|
||||
);
|
||||
|
||||
my ($status, $message) = ('ok');
|
||||
eval {
|
||||
@ -75,10 +81,10 @@ sub check {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' &&
|
||||
eval "$self->{option_results}->{critical}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning}) && $self->{option_results}->{warning} ne '' &&
|
||||
eval "$self->{option_results}->{warning}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{warning}, values => $self->{data})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -86,9 +92,13 @@ sub check {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("MAPI connection to '%s' is '%s'",
|
||||
$options{mailbox}, $self->{data}->{result}));
|
||||
$self->{output}->output_add(
|
||||
severity => $status,
|
||||
short_msg => sprintf(
|
||||
"MAPI connection to '%s' is '%s'",
|
||||
$options{mailbox}, $self->{data}->{result}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,12 +65,13 @@ exit 0
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[id= XXXX ][type= Success][[message=...]]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("Outlook webservices to '%s' are ok.", $options{mailbox}));
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => sprintf("Outlook webservices to '%s' are ok.", $options{mailbox})
|
||||
);
|
||||
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
@ -87,10 +88,10 @@ sub check {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' &&
|
||||
eval "$self->{option_results}->{critical}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning}) && $self->{option_results}->{warning} ne '' &&
|
||||
eval "$self->{option_results}->{warning}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{warning}, values => $self->{data})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -98,15 +99,21 @@ sub check {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("Check id '%s' status is '%s' [message: %s]",
|
||||
$self->{data}->{id}, $self->{data}->{type}, $self->{data}->{message}));
|
||||
$self->{output}->output_add(
|
||||
severity => $status,
|
||||
short_msg => sprintf(
|
||||
"Check id '%s' status is '%s' [message: %s]",
|
||||
$self->{data}->{id}, $self->{data}->{type}, $self->{data}->{message}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,12 +57,13 @@ exit 0
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[url= http://xxxx/ ][scenario= Options ][result= Ignored ][latency= ][[error=...]]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "OWA to '" . $options{mailbox} . "' is ok.");
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => "OWA to '" . $options{mailbox} . "' is ok."
|
||||
);
|
||||
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
@ -79,10 +80,10 @@ sub check {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' &&
|
||||
eval "$self->{option_results}->{critical}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning}) && $self->{option_results}->{warning} ne '' &&
|
||||
eval "$self->{option_results}->{warning}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{warning}, values => $self->{data})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -90,21 +91,29 @@ sub check {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("OWA scenario '%s' to '%s' is '%s' [url: %s]",
|
||||
$self->{data}->{scenario}, $options{mailbox}, $self->{data}->{result}, $self->{data}->{url}));
|
||||
$self->{output}->output_add(
|
||||
severity => $status,
|
||||
short_msg => sprintf(
|
||||
"OWA scenario '%s' to '%s' is '%s' [url: %s]",
|
||||
$self->{data}->{scenario}, $options{mailbox}, $self->{data}->{result}, $self->{data}->{url}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($self->{data}->{latency} =~ /^(\d+)/) {
|
||||
$self->{output}->perfdata_add(label => $self->{data}->{url} . '_' . $self->{data}->{scenario}, unit => 's',
|
||||
value => sprintf("%.3f", $1 / 1000),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(
|
||||
label => $self->{data}->{url} . '_' . $self->{data}->{scenario}, unit => 's',
|
||||
value => sprintf("%.3f", $1 / 1000),
|
||||
min => 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,12 +50,13 @@ exit 0
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[Server= XXXX ][check= ReplayService][result= Passed ][isvalid= Yes][[error=...]]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "All replication health tests are ok.");
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => "All replication health tests are ok."
|
||||
);
|
||||
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
@ -73,10 +74,10 @@ sub check {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' &&
|
||||
eval "$self->{option_results}->{critical}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning}) && $self->{option_results}->{warning} ne '' &&
|
||||
eval "$self->{option_results}->{warning}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{warning}, values => $self->{data})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -84,15 +85,21 @@ sub check {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("Replication test '%s' status on '%s' is '%s' [error: %s]",
|
||||
$self->{data}->{check}, $self->{data}->{server}, $self->{data}->{result}, $self->{data}->{error}));
|
||||
$self->{output}->output_add(
|
||||
severity => $status,
|
||||
short_msg => sprintf(
|
||||
"Replication test '%s' status on '%s' is '%s' [error: %s]",
|
||||
$self->{data}->{check}, $self->{data}->{server}, $self->{data}->{result}, $self->{data}->{error}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,12 +52,13 @@ exit 0
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[role= Mailbox Server Role ][requiredservicesrunning= True ][servicesrunning= IISAdmin,MSExchangeADTopology,MSExchangeSA,... ][servicesnotrunning= ]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "All role services are ok.");
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => "All role services are ok."
|
||||
);
|
||||
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
@ -75,10 +76,10 @@ sub check {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' &&
|
||||
eval "$self->{option_results}->{critical}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning}) && $self->{option_results}->{warning} ne '' &&
|
||||
eval "$self->{option_results}->{warning}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{warning}, values => $self->{data})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -86,15 +87,21 @@ sub check {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("Role '%s' services problem [services not running: %s]",
|
||||
$self->{data}->{role}, $self->{data}->{servicesnotrunning}));
|
||||
$self->{output}->output_add(
|
||||
severity => $status,
|
||||
short_msg => sprintf(
|
||||
"Role '%s' services problem [services not running: %s]",
|
||||
$self->{data}->{role}, $self->{data}->{servicesnotrunning}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ package centreon::common::protocols::sql::mode::sqlstring;
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
@ -33,26 +33,16 @@ sub set_counters {
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{rows} = [
|
||||
{ label => 'string', threshold => 0, set => {
|
||||
{ label => 'string', type => 2, set => {
|
||||
key_values => [ { name => 'key_field' }, { name => 'value_field' } ],
|
||||
closure_custom_calc => $self->can('custom_string_calc'),
|
||||
closure_custom_output => $self->can('custom_string_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_string_threshold'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng,
|
||||
closure_custom_perfdata => sub { return 0; }
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub custom_string_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{key_field} = $options{new_datas}->{$self->{instance} . '_key_field'};
|
||||
$self->{result_values}->{value_field} = $options{new_datas}->{$self->{instance} . '_value_field'};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_string_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
@ -75,46 +65,19 @@ sub custom_string_output {
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_string_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_string}) && $self->{instance_mode}->{option_results}->{critical_string} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_string}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_string}) && $self->{instance_mode}->{option_results}->{warning_string} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_string}") {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'threshold regex issue: ' . $message);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"sql-statement:s" => { name => 'sql_statement' },
|
||||
"key-column:s" => { name => 'key_column' },
|
||||
"value-column:s" => { name => 'value_column' },
|
||||
"warning-string:s" => { name => 'warning_string', default => '' },
|
||||
"critical-string:s" => { name => 'critical_string', default => '' },
|
||||
"printf-format:s" => { name => 'printf_format' },
|
||||
"printf-value:s" => { name => 'printf_value' },
|
||||
"dual-table" => { name => 'dual_table' },
|
||||
"empty-sql-string:s" => { name => 'empty_sql_string', default => 'No row returned or --key-column/--value-column do not correctly match selected field' },
|
||||
'sql-statement:s' => { name => 'sql_statement' },
|
||||
'key-column:s' => { name => 'key_column' },
|
||||
'value-column:s' => { name => 'value_column' },
|
||||
'printf-format:s' => { name => 'printf_format' },
|
||||
'printf-value:s' => { name => 'printf_value' },
|
||||
'dual-table' => { name => 'dual_table' },
|
||||
'empty-sql-string:s' => { name => 'empty_sql_string', default => 'No row returned or --key-column/--value-column do not correctly match selected field' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
@ -128,19 +91,17 @@ sub check_options {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify '--sql-statement' option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->change_macros(macros => ['warning_string', 'critical_string']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
$self->{sql} = $options{sql};
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => $self->{option_results}->{sql_statement});
|
||||
|
||||
$options{sql}->connect();
|
||||
$options{sql}->query(query => $self->{option_results}->{sql_statement});
|
||||
$self->{rows} = {};
|
||||
my $row_count = 0;
|
||||
|
||||
while (my $row = $self->{sql}->fetchrow_hashref()) {
|
||||
while (my $row = $options{sql}->fetchrow_hashref()) {
|
||||
if (defined($self->{option_results}->{dual_table})) {
|
||||
$row->{$self->{option_results}->{value_column}} = delete $row->{keys %{$row}};
|
||||
foreach (keys %{$row}) {
|
||||
@ -148,17 +109,21 @@ sub manage_selection {
|
||||
}
|
||||
}
|
||||
if (!defined($self->{option_results}->{key_column})) {
|
||||
$self->{rows}->{$self->{option_results}->{value_column} . $row_count} = { key_field => $row->{$self->{option_results}->{value_column}},
|
||||
value_field => $row->{$self->{option_results}->{value_column}}};
|
||||
$self->{rows}->{$self->{option_results}->{value_column} . $row_count} = {
|
||||
key_field => $row->{ $self->{option_results}->{value_column} },
|
||||
value_field => $row->{ $self->{option_results}->{value_column} }
|
||||
};
|
||||
$row_count++;
|
||||
} else {
|
||||
$self->{rows}->{$self->{option_results}->{key_column} . $row_count} = { key_field => $row->{$self->{option_results}->{key_column}},
|
||||
value_field => $row->{$self->{option_results}->{value_column}}};
|
||||
$self->{rows}->{$self->{option_results}->{key_column} . $row_count} = {
|
||||
key_field => $row->{ $self->{option_results}->{key_column} },
|
||||
value_field => $row->{ $self->{option_results}->{value_column} }
|
||||
};
|
||||
$row_count++;
|
||||
}
|
||||
}
|
||||
|
||||
$self->{sql}->disconnect();
|
||||
$options{sql}->disconnect();
|
||||
if (scalar(keys %{$self->{rows}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => $self->{option_results}->{empty_sql_string});
|
||||
$self->{output}->option_exit();
|
||||
|
@ -59,7 +59,7 @@ sub check_options {
|
||||
|
||||
foreach (('unknown_status', 'warning_status', 'critical_status')) {
|
||||
if (defined($options{request}->{$_})) {
|
||||
$options{request}->{$_} =~ s/%\{http_code\}/\$self->{response_code}/g;
|
||||
$options{request}->{$_} =~ s/%\{http_code\}/\$values->{code}/g;
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,13 +394,13 @@ sub request {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($options{request}->{critical_status}) && $options{request}->{critical_status} ne '' &&
|
||||
eval "$options{request}->{critical_status}") {
|
||||
$self->{output}->test_eval(test => $options{request}->{critical_status}, values => { code => $self->{response_code} })) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($options{request}->{warning_status}) && $options{request}->{warning_status} ne '' &&
|
||||
eval "$options{request}->{warning_status}") {
|
||||
$self->{output}->test_eval(test => $options{request}->{warning_status}, values => { code => $self->{response_code} })) {
|
||||
$status = 'warning';
|
||||
} elsif (defined($options{request}->{unknown_status}) && $options{request}->{unknown_status} ne '' &&
|
||||
eval "$options{request}->{unknown_status}") {
|
||||
$self->{output}->test_eval(test => $options{request}->{unknown_status}, values => { code => $self->{response_code} })) {
|
||||
$status = 'unknown';
|
||||
}
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ sub check_options {
|
||||
|
||||
foreach (('unknown_status', 'warning_status', 'critical_status')) {
|
||||
if (defined($options{request}->{$_})) {
|
||||
$options{request}->{$_} =~ s/%\{http_code\}/\$self->{response}->code/g;
|
||||
$options{request}->{$_} =~ s/%\{http_code\}/\$values->{code}/g;
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,14 +257,15 @@ sub request {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
my $code = $self->{response}->code();
|
||||
if (defined($request_options->{critical_status}) && $request_options->{critical_status} ne '' &&
|
||||
eval "$request_options->{critical_status}") {
|
||||
$self->{output}->test_eval(test => $request_options->{critical_status}, values => { code => $code })) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($request_options->{warning_status}) && $request_options->{warning_status} ne '' &&
|
||||
eval "$request_options->{warning_status}") {
|
||||
$self->{output}->test_eval(test => $request_options->{warning_status}, values => { code => $code })) {
|
||||
$status = 'warning';
|
||||
} elsif (defined($request_options->{unknown_status}) && $request_options->{unknown_status} ne '' &&
|
||||
eval "$request_options->{unknown_status}") {
|
||||
$self->{output}->test_eval(test => $request_options->{unknown_status}, values => { code => $code })) {
|
||||
$status = 'unknown';
|
||||
}
|
||||
};
|
||||
|
@ -83,6 +83,7 @@ sub new {
|
||||
$self->{global_status} = 0;
|
||||
$self->{encode_import} = 0;
|
||||
$self->{perlqq} = 0;
|
||||
$self->{safe_test} = 0;
|
||||
|
||||
$self->{disco_elements} = [];
|
||||
$self->{disco_entries} = [];
|
||||
@ -869,6 +870,60 @@ sub is_debug {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub load_eval {
|
||||
my ($self) = @_;
|
||||
|
||||
my ($code) = centreon::plugins::misc::mymodule_load(
|
||||
output => $self->{output}, module => 'Safe',
|
||||
no_quit => 1
|
||||
);
|
||||
if ($code == 0) {
|
||||
$self->{safe} = Safe->new();
|
||||
$self->{safe}->share('$values');
|
||||
$self->{safe}->share('$assign_var');
|
||||
}
|
||||
}
|
||||
|
||||
sub test_eval {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->load_eval() if ($self->{safe_test} == 0);
|
||||
|
||||
my $result;
|
||||
if (defined($self->{safe})) {
|
||||
our $values = $options{values};
|
||||
$result = $self->{safe}->reval($options{test}, 1);
|
||||
if ($@) {
|
||||
die 'Unsafe code evaluation: ' . $@;
|
||||
}
|
||||
} else {
|
||||
my $values = $options{values};
|
||||
$result = eval "$options{test}";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub assign_eval {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->load_eval() if ($self->{safe_test} == 0);
|
||||
|
||||
our $assign_var;
|
||||
if (defined($self->{safe})) {
|
||||
our $values = $options{values};
|
||||
$self->{safe}->reval("\$assign_var = $options{eval}", 1);
|
||||
if ($@) {
|
||||
die 'Unsafe code evaluation: ' . $@;
|
||||
}
|
||||
} else {
|
||||
my $values = $options{values};
|
||||
eval "\$assign_var = $options{eval}";
|
||||
}
|
||||
|
||||
return $assign_var;
|
||||
}
|
||||
|
||||
sub use_new_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
@ -1090,8 +1145,7 @@ sub apply_pfdata_math {
|
||||
sub apply_pfdata_min {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $pattern_pf;
|
||||
eval "\$pattern_pf = \"$options{args}->{pattern_pf}\"";
|
||||
my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\"");
|
||||
my $min;
|
||||
for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) {
|
||||
next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/);
|
||||
@ -1107,8 +1161,7 @@ sub apply_pfdata_min {
|
||||
sub apply_pfdata_max {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $pattern_pf;
|
||||
eval "\$pattern_pf = \"$options{args}->{pattern_pf}\"";
|
||||
my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\"");
|
||||
my $max;
|
||||
for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) {
|
||||
next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/);
|
||||
@ -1124,8 +1177,7 @@ sub apply_pfdata_max {
|
||||
sub apply_pfdata_sum {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $pattern_pf;
|
||||
eval "\$pattern_pf = \"$options{args}->{pattern_pf}\"";
|
||||
my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\"");
|
||||
my ($sum, $num) = (0, 0);
|
||||
for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) {
|
||||
next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/);
|
||||
@ -1141,8 +1193,7 @@ sub apply_pfdata_sum {
|
||||
sub apply_pfdata_average {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $pattern_pf;
|
||||
eval "\$pattern_pf = \"$options{args}->{pattern_pf}\"";
|
||||
my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\"");
|
||||
my ($sum, $num) = (0, 0);
|
||||
for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) {
|
||||
next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/);
|
||||
|
@ -197,7 +197,7 @@ sub read {
|
||||
}
|
||||
|
||||
if ($self->{storable} == 1) {
|
||||
open FILE, $self->{statefile_dir} . '/' . $self->{statefile};
|
||||
open FILE, '<', $self->{statefile_dir} . '/' . $self->{statefile};
|
||||
eval {
|
||||
$self->{datas} = Storable::fd_retrieve(*FILE);
|
||||
};
|
||||
|
@ -39,16 +39,16 @@ sub catalog_status_threshold {
|
||||
my $label = $self->{label};
|
||||
$label =~ s/-/_/g;
|
||||
if (defined($self->{instance_mode}->{option_results}->{'ok_' . $label}) && $self->{instance_mode}->{option_results}->{'ok_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'ok_' . $label}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'ok_' . $label})) {
|
||||
$status = 'ok';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'critical_' . $label})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'warning_' . $label})) {
|
||||
$status = 'warning';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'unknown_' . $label}) && $self->{instance_mode}->{option_results}->{'unknown_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'unknown_' . $label}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'unknown_' . $label})) {
|
||||
$status = 'unknown';
|
||||
}
|
||||
};
|
||||
@ -68,15 +68,14 @@ sub catalog_status_threshold_ng {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
my $label = $self->{label};
|
||||
if (defined($self->{instance_mode}->{option_results}->{'critical-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'critical-' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'critical-' . $self->{label}}") {
|
||||
if (defined($self->{instance_mode}->{option_results}->{'critical-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'critical-' . $self->{label}} ne '' &&
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'critical-' . $self->{label}})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning-' . $label}) && $self->{instance_mode}->{option_results}->{'warning-' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'warning-' . $label}") {
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'warning-' . $self->{label}} ne '' &&
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'warning-' . $self->{label}})) {
|
||||
$status = 'warning';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'unknown-' . $label}) && $self->{instance_mode}->{option_results}->{'unknown-' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'unknown-' . $label}") {
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'unknown-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'unknown-' . $self->{label}} ne '' &&
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{'unknown-' . $self->{label}})) {
|
||||
$status = 'unknown';
|
||||
}
|
||||
};
|
||||
|
@ -755,7 +755,7 @@ sub change_macros {
|
||||
|
||||
foreach (@{$options{macros}}) {
|
||||
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package centreon::plugins::values;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
# Warning message with sprintf and too much arguments.
|
||||
# Really annoying. Need to disable that warning
|
||||
no if ($^V gt v5.22.0), 'warnings' => 'redundant';
|
||||
@ -55,6 +56,7 @@ sub new {
|
||||
$self->{last_timestamp} = undef;
|
||||
|
||||
$self->{result_values} = {};
|
||||
$self->{safe_test} = 0;
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -231,6 +233,36 @@ sub perfdata {
|
||||
}
|
||||
}
|
||||
|
||||
sub eval {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($self->{safe_test} == 0) {
|
||||
my ($code) = centreon::plugins::misc::mymodule_load(
|
||||
output => $self->{output}, module => 'Safe',
|
||||
no_quit => 1
|
||||
);
|
||||
if ($code == 0) {
|
||||
$self->{safe} = Safe->new();
|
||||
$self->{safe}->share('$values');
|
||||
}
|
||||
$self->{safe_test} = 1;
|
||||
}
|
||||
|
||||
my $result;
|
||||
if (defined($self->{safe})) {
|
||||
our $values = $self->{result_values};
|
||||
$result = $self->{safe}->reval($options{value}, 1);
|
||||
if ($@) {
|
||||
die 'Unsafe code evaluation: ' . $@;
|
||||
}
|
||||
} else {
|
||||
my $values = $self->{result_values};
|
||||
$result = eval "$options{value}";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub execute {
|
||||
my ($self, %options) = @_;
|
||||
my $old_datas = {};
|
||||
|
@ -26,13 +26,13 @@ use strict;
|
||||
use warnings;
|
||||
|
||||
my %map_type = (
|
||||
"instance" => "InstanceId",
|
||||
"asg" => "AutoScalingGroupName",
|
||||
'instance' => 'InstanceId',
|
||||
'asg' => 'AutoScalingGroupName'
|
||||
);
|
||||
|
||||
my %map_status = (
|
||||
0 => 'passed',
|
||||
1 => 'failed',
|
||||
1 => 'failed'
|
||||
);
|
||||
|
||||
sub prefix_metric_output {
|
||||
@ -51,10 +51,10 @@ sub custom_status_threshold {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_status}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{critical_status})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_status}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{warning_status})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
@ -68,8 +68,7 @@ sub custom_status_threshold {
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = $self->{result_values}->{metric} . ": " . $self->{result_values}->{status};
|
||||
return $msg;
|
||||
return $self->{result_values}->{metric} . ": " . $self->{result_values}->{status};
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
@ -88,15 +87,16 @@ sub set_counters {
|
||||
];
|
||||
|
||||
foreach my $metric ('StatusCheckFailed_Instance', 'StatusCheckFailed_System') {
|
||||
my $entry = { label => lc($metric), threshold => 0, set => {
|
||||
key_values => [ { name => $metric }, { name => 'display' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_calc_extra_options => { metric => $metric },
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||||
}
|
||||
};
|
||||
my $entry = {
|
||||
label => lc($metric), threshold => 0, set => {
|
||||
key_values => [ { name => $metric }, { name => 'display' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_calc_extra_options => { metric => $metric },
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold')
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{metric}}, $entry;
|
||||
}
|
||||
}
|
||||
@ -107,10 +107,10 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"type:s" => { name => 'type' },
|
||||
"name:s@" => { name => 'name' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /failed/i' },
|
||||
'type:s' => { name => 'type' },
|
||||
'name:s@' => { name => 'name' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /failed/i' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
use Time::Local;
|
||||
|
||||
sub custom_active_perfdata {
|
||||
@ -38,11 +39,13 @@ sub custom_active_perfdata {
|
||||
$self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
|
||||
$self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900));
|
||||
|
||||
$self->{output}->perfdata_add(label => 'active_mailboxes', nlabel => 'exchange.mailboxes.active.count',
|
||||
value => $self->{result_values}->{active},
|
||||
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),
|
||||
unit => 'mailboxes', min => 0, max => $self->{result_values}->{total});
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'active_mailboxes', nlabel => 'exchange.mailboxes.active.count',
|
||||
value => $self->{result_values}->{active},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
unit => 'mailboxes', min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_active_threshold {
|
||||
@ -52,9 +55,13 @@ sub custom_active_threshold {
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_active};
|
||||
}
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $threshold_value,
|
||||
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{perfdata}->threshold_check(
|
||||
value => $threshold_value,
|
||||
threshold => [
|
||||
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
return $exit;
|
||||
|
||||
}
|
||||
@ -62,12 +69,13 @@ sub custom_active_threshold {
|
||||
sub custom_active_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("Active mailboxes on %s : %d/%d (%.2f%%)",
|
||||
$self->{result_values}->{report_date},
|
||||
$self->{result_values}->{active},
|
||||
$self->{result_values}->{total},
|
||||
$self->{result_values}->{prct_active});
|
||||
return $msg;
|
||||
return sprintf(
|
||||
'Active mailboxes on %s : %d/%d (%.2f%%)',
|
||||
$self->{result_values}->{report_date},
|
||||
$self->{result_values}->{active},
|
||||
$self->{result_values}->{total},
|
||||
$self->{result_values}->{prct_active}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_active_calc {
|
||||
@ -87,34 +95,13 @@ sub custom_usage_perfdata {
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
$self->{output}->perfdata_add(label => 'used' . $extra_label, nlabel => $self->{result_values}->{display} . '#exchange.mailboxes.usage.bytes',
|
||||
unit => 'B',
|
||||
value => $self->{result_values}->{used},
|
||||
min => 0);
|
||||
}
|
||||
|
||||
sub custom_status_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_status}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_status}") {
|
||||
$status = 'warning';
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
}
|
||||
|
||||
return $status;
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'used' . $extra_label,
|
||||
nlabel => $self->{result_values}->{display} . '#exchange.mailboxes.usage.bytes',
|
||||
unit => 'B',
|
||||
value => $self->{result_values}->{used},
|
||||
min => 0
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
@ -125,12 +112,13 @@ sub custom_status_output {
|
||||
my ($prohibit_send_quota_value, $prohibit_send_quota_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{prohibit_send_quota});
|
||||
my ($prohibit_send_receive_quota_value, $prohibit_send_receive_quota_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{prohibit_send_receive_quota});
|
||||
|
||||
my $msg = sprintf("Used: %s Issue Warning Quota: %s Prohibit Send Quota: %s Prohibit Send/Receive Quota: %s",
|
||||
$used_value . " " . $used_unit,
|
||||
$issue_warning_quota_value . " " . $issue_warning_quota_unit,
|
||||
$prohibit_send_quota_value . " " . $prohibit_send_quota_unit,
|
||||
$prohibit_send_receive_quota_value . " " . $prohibit_send_receive_quota_unit);
|
||||
return $msg;
|
||||
return sprintf(
|
||||
"Used: %s Issue Warning Quota: %s Prohibit Send Quota: %s Prohibit Send/Receive Quota: %s",
|
||||
$used_value . " " . $used_unit,
|
||||
$issue_warning_quota_value . " " . $issue_warning_quota_unit,
|
||||
$prohibit_send_quota_value . " " . $prohibit_send_quota_unit,
|
||||
$prohibit_send_receive_quota_value . " " . $prohibit_send_receive_quota_unit
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
@ -191,31 +179,39 @@ sub set_counters {
|
||||
output_template => 'Usage (inactive mailboxes): %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'total_usage_inactive', value => 'storage_used_inactive', template => '%d',
|
||||
min => 0, unit => 'B' },
|
||||
],
|
||||
{ label => 'total_usage_inactive', template => '%d', min => 0, unit => 'B' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{mailboxes} = [
|
||||
{ label => 'usage', set => {
|
||||
key_values => [ { name => 'storage_used' }, { name => 'issue_warning_quota' },
|
||||
{ name => 'prohibit_send_quota' }, { name => 'prohibit_send_receive_quota' }, { name => 'name' } ],
|
||||
{
|
||||
label => 'status',
|
||||
type => 2,
|
||||
warning_default => '%{used} > %{issue_warning_quota}',
|
||||
critical_default => '%{used} > %{prohibit_send_quota}',
|
||||
set => {
|
||||
key_values => [
|
||||
{ name => 'storage_used' }, { name => 'issue_warning_quota' },
|
||||
{ name => 'prohibit_send_quota' }, { name => 'prohibit_send_receive_quota' },
|
||||
{ name => 'name' }
|
||||
],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'items', nlabel => 'exchange.mailboxes.items.count', set => {
|
||||
key_values => [ { name => 'items' }, { name => 'name' } ],
|
||||
output_template => 'Items: %d',
|
||||
perfdatas => [
|
||||
{ label => 'items', value => 'items', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name' },
|
||||
],
|
||||
{ label => 'items', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
@ -225,23 +221,14 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-mailbox:s" => { name => 'filter_mailbox' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '%{used} > %{issue_warning_quota}' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{used} > %{prohibit_send_quota}' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"filter-counters:s" => { name => 'filter_counters', default => 'active|total' },
|
||||
'filter-mailbox:s' => { name => 'filter_mailbox' },
|
||||
'units:s' => { name => 'units', default => '%' },
|
||||
'filter-counters:s' => { name => 'filter_counters', default => 'active|total' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -26,20 +26,19 @@ use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::plugins::statefile;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
{ name => 'sap', type => 1, cb_prefix_output => 'prefix_sap_output', message_multiple => 'All SAP are ok', skipped_code => { -10 => 1 } },
|
||||
{ name => 'sap', type => 1, cb_prefix_output => 'prefix_sap_output', message_multiple => 'All SAP are ok', skipped_code => { -10 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{sap} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
{ label => 'status', type => 2, critical_default => '%{admin} =~ /up/i and %{status} !~ /up/i', set => {
|
||||
key_values => [ { name => 'status' }, { name => 'admin' }, { 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 => $self->can('custom_status_threshold')
|
||||
@ -60,7 +59,7 @@ sub set_counters {
|
||||
closure_custom_perfdata => $self->can('custom_sap_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_sap_threshold')
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
@ -128,11 +127,12 @@ sub custom_total_traffic_output {
|
||||
($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{speed}, network => 1);
|
||||
}
|
||||
|
||||
my $msg = sprintf("Total Traffic %s : %s/s (%s on %s)",
|
||||
ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit,
|
||||
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-',
|
||||
defined($total_value) ? $total_value . $total_unit : '-');
|
||||
return $msg;
|
||||
return sprintf(
|
||||
"Total Traffic %s : %s/s (%s on %s)",
|
||||
ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit,
|
||||
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-',
|
||||
defined($total_value) ? $total_value . $total_unit : '-'
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_total_traffic_calc {
|
||||
@ -165,49 +165,19 @@ sub custom_total_traffic_calc {
|
||||
|
||||
sub custom_status_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
my $label = $self->{label};
|
||||
$label =~ s/-/_/g;
|
||||
if (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") {
|
||||
$status = 'warning';
|
||||
}
|
||||
|
||||
$self->{instance_mode}->{last_status} = 0;
|
||||
if ($self->{result_values}->{admin} eq 'up') {
|
||||
$self->{instance_mode}->{last_status} = 1;
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
my $status = catalog_status_threshold_ng($self, %options);
|
||||
$self->{instance_mode}->{last_status} = 0;
|
||||
if ($self->{result_values}->{admin} eq 'up') {
|
||||
$self->{instance_mode}->{last_status} = 1;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg = 'Status : ' . $self->{result_values}->{status} . ' (admin: ' . $self->{result_values}->{admin} . ')';
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{admin} = $options{new_datas}->{$self->{instance} . '_admin'};
|
||||
$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} . ' (admin: ' . $self->{result_values}->{admin} . ')';
|
||||
}
|
||||
|
||||
sub custom_sap_perfdata {
|
||||
@ -254,11 +224,12 @@ sub custom_sap_output {
|
||||
($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{speed}, network => 1);
|
||||
}
|
||||
|
||||
my $msg = sprintf("Traffic %s : %s/s (%s on %s)",
|
||||
ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit,
|
||||
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-',
|
||||
defined($total_value) ? $total_value . $total_unit : '-');
|
||||
return $msg;
|
||||
return sprintf(
|
||||
"Traffic %s : %s/s (%s on %s)",
|
||||
ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit,
|
||||
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-',
|
||||
defined($total_value) ? $total_value . $total_unit : '-'
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_sap_calc {
|
||||
@ -288,9 +259,7 @@ sub new {
|
||||
'speed-out:s' => { name => 'speed_out' },
|
||||
'speed-total-in:s' => { name => 'speed_total_in' },
|
||||
'speed-total-out:s' => { name => 'speed_total_out' },
|
||||
'units-traffic:s' => { name => 'units_traffic', default => '%' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{admin} =~ /up/i and %{status} !~ /up/i' },
|
||||
'units-traffic:s' => { name => 'units_traffic', default => '%' }
|
||||
});
|
||||
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||
@ -301,7 +270,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
$self->{statefile_cache}->check_options(%options);
|
||||
}
|
||||
|
||||
@ -340,12 +308,14 @@ sub reload_cache {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $datas = { last_timestamp => time() };
|
||||
my $snmp_result = $options{snmp}->get_multiple_table(oids => [
|
||||
my $snmp_result = $options{snmp}->get_multiple_table(
|
||||
oids => [
|
||||
{ oid => $oid_sapDescription },
|
||||
{ oid => $oid_svcDescription },
|
||||
{ oid => $oid_ifName },
|
||||
{ oid => $oid_ifName }
|
||||
],
|
||||
nothing_quit => 1);
|
||||
nothing_quit => 1
|
||||
);
|
||||
$datas->{snmp_result} = $snmp_result;
|
||||
|
||||
if (scalar(keys %{$datas->{snmp_result}->{$oid_sapDescription}}) <= 0) {
|
||||
@ -376,7 +346,6 @@ sub manage_selection {
|
||||
|
||||
$self->{global} = {};
|
||||
$self->{sap} = {};
|
||||
|
||||
foreach my $oid (keys %{$snmp_result->{$oid_sapDescription}}) {
|
||||
next if ($oid !~ /^$oid_sapDescription\.(.*?)\.(.*?)\.(.*?)$/);
|
||||
# $SvcId and $SapEncapValue is the same. We use service table
|
||||
@ -399,7 +368,8 @@ sub manage_selection {
|
||||
IfName => $IfName,
|
||||
SvcId => $SvcId,
|
||||
SapPortId => $SapPortId,
|
||||
SapEncapValue => $SapEncapValue);
|
||||
SapEncapValue => $SapEncapValue
|
||||
);
|
||||
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||
@ -413,7 +383,8 @@ sub manage_selection {
|
||||
$options{snmp}->load(oids => [$mapping->{fadSapStatsIngressOctets}->{oid},
|
||||
$mapping->{fadSapStatsEgressOctets}->{oid},
|
||||
$mapping->{sapAdminStatus}->{oid}, $mapping->{sapOperStatus}->{oid}],
|
||||
instances => [keys %{$self->{sap}}], instance_regexp => '(\d+\.\d+\.\d+)$');
|
||||
instances => [keys %{$self->{sap}}], instance_regexp => '(\d+\.\d+\.\d+)$'
|
||||
);
|
||||
|
||||
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
@ -433,7 +404,7 @@ sub manage_selection {
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{cache_name} = "alcatel_isam_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
|
||||
$self->{cache_name} = 'alcatel_isam_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
|
||||
}
|
||||
|
@ -318,16 +318,18 @@ sub add_result_global {
|
||||
$self->{global} = { total_port => 0, global_link_up => 0, global_link_down => 0, global_admin_up => 0,
|
||||
global_admin_down => 0, global_oper_up => 0, global_oper_down => 0};
|
||||
foreach (@{$self->{array_interface_selected}}) {
|
||||
my $linkstatus = $self->{oid_linkstatus_mapping}->{$self->{results}->{$self->{oid_linkstatus} . '.' . $_}};
|
||||
my $opstatus = $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $_}};
|
||||
my $admstatus = $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $_}};
|
||||
my $values = {
|
||||
linkstatus => $self->{oid_linkstatus_mapping}->{$self->{results}->{$self->{oid_linkstatus} . '.' . $_}},
|
||||
opstatus => $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $_}},
|
||||
admstatus => $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $_}}
|
||||
};
|
||||
foreach (('global_link_up', 'global_link_down', 'global_admin_up', 'global_admin_down', 'global_oper_up', 'global_oper_down')) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { return ; };
|
||||
local $SIG{__DIE__} = sub { return ; };
|
||||
|
||||
if (defined($self->{option_results}->{$_ . '_rule'}) && $self->{option_results}->{$_ . '_rule'} ne '' &&
|
||||
eval "$self->{option_results}->{$_ . '_rule'}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{$_ . '_rule'}, values => $values)) {
|
||||
$self->{global}->{$_}++;
|
||||
}
|
||||
};
|
||||
|
@ -25,114 +25,22 @@ use base qw(centreon::plugins::templates::counter);
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'ib', type => 1, cb_prefix_output => 'prefix_ib_output', message_multiple => 'All infiniband interfaces are ok', cb_init => 'skip_empty_ib', skipped_code => { -10 => 1 } },
|
||||
{ name => 'ibgw', type => 1, cb_prefix_output => 'prefix_ibgw_output', message_multiple => 'All gateway infiniband interfaces are ok', cb_init => 'skip_empty_ibgw', skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{ib} = [
|
||||
{ label => 'ib-status', threshold => 0, 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 => $self->can('custom_status_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'in', set => {
|
||||
key_values => [ { name => 'in', diff => 1 }, { name => 'display' }, { name => 'speed_in' } ],
|
||||
closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
|
||||
closure_custom_output => $self->can('custom_ib_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ib_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_ib_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'out', set => {
|
||||
key_values => [ { name => 'out', diff => 1 }, { name => 'display' }, { name => 'speed_out' } ],
|
||||
closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
|
||||
closure_custom_output => $self->can('custom_ib_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ib_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_ib_threshold')
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{ibgw} = [
|
||||
{ label => 'ibgw-status', threshold => 0, 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 => $self->can('custom_status_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'in', set => {
|
||||
key_values => [ { name => 'in', diff => 1 }, { name => 'display' }, { name => 'speed_in' } ],
|
||||
closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
|
||||
closure_custom_output => $self->can('custom_ib_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ib_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_ib_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'out', set => {
|
||||
key_values => [ { name => 'out', diff => 1 }, { name => 'display' }, { name => 'speed_out' } ],
|
||||
closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
|
||||
closure_custom_output => $self->can('custom_ib_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ib_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_ib_threshold')
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub custom_status_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'ok';
|
||||
my $message;
|
||||
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
my $label = $self->{label};
|
||||
$label =~ s/-/_/g;
|
||||
if (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") {
|
||||
$status = 'warning';
|
||||
}
|
||||
|
||||
$self->{instance_mode}->{last_status} = 0;
|
||||
if ($self->{result_values}->{status} ne 'down') {
|
||||
$self->{instance_mode}->{last_status} = 1;
|
||||
}
|
||||
};
|
||||
if (defined($message)) {
|
||||
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||
$self->{instance_mode}->{last_status} = 0;
|
||||
if ($self->{result_values}->{status} ne 'down') {
|
||||
$self->{instance_mode}->{last_status} = 1;
|
||||
}
|
||||
|
||||
return $status;
|
||||
return catalog_status_threshold_ng($self, %options);
|
||||
}
|
||||
|
||||
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_ib_perfdata {
|
||||
@ -178,11 +86,12 @@ sub custom_ib_output {
|
||||
($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{speed}, network => 1);
|
||||
}
|
||||
|
||||
my $msg = sprintf("Traffic %s : %s/s (%s on %s)",
|
||||
ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit,
|
||||
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-',
|
||||
defined($total_value) ? $total_value . $total_unit : '-');
|
||||
return $msg;
|
||||
return sprintf(
|
||||
"Traffic %s : %s/s (%s on %s)",
|
||||
ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit,
|
||||
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-',
|
||||
defined($total_value) ? $total_value . $total_unit : '-'
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_ib_calc {
|
||||
@ -204,33 +113,83 @@ sub custom_ib_calc {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'ib', type => 1, cb_prefix_output => 'prefix_ib_output', message_multiple => 'All infiniband interfaces are ok', cb_init => 'skip_empty_ib', skipped_code => { -10 => 1 } },
|
||||
{ name => 'ibgw', type => 1, cb_prefix_output => 'prefix_ibgw_output', message_multiple => 'All gateway infiniband interfaces are ok', cb_init => 'skip_empty_ibgw', skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{ib} = [
|
||||
{ label => 'ib-status', type => 2, critical_default => '%{status} !~ /active/i', set => {
|
||||
key_values => [ { name => 'status' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'in', set => {
|
||||
key_values => [ { name => 'in', diff => 1 }, { name => 'display' }, { name => 'speed_in' } ],
|
||||
closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
|
||||
closure_custom_output => $self->can('custom_ib_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ib_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_ib_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'out', set => {
|
||||
key_values => [ { name => 'out', diff => 1 }, { name => 'display' }, { name => 'speed_out' } ],
|
||||
closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
|
||||
closure_custom_output => $self->can('custom_ib_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ib_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_ib_threshold')
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{ibgw} = [
|
||||
{ label => 'ibgw-status', type => 2, critical_default => '%{status} !~ /up/i', set => {
|
||||
key_values => [ { name => 'status' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_status_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'in', set => {
|
||||
key_values => [ { name => 'in', diff => 1 }, { name => 'display' }, { name => 'speed_in' } ],
|
||||
closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
|
||||
closure_custom_output => $self->can('custom_ib_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ib_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_ib_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'out', set => {
|
||||
key_values => [ { name => 'out', diff => 1 }, { name => 'display' }, { name => 'speed_out' } ],
|
||||
closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
|
||||
closure_custom_output => $self->can('custom_ib_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ib_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_ib_threshold')
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-ib-name:s' => { name => 'filter_ib_name' },
|
||||
'filter-ibgw-name:s' => { name => 'filter_ibgw_name' },
|
||||
'warning-ib-status:s' => { name => 'warning_ib_status', default => '' },
|
||||
'critical-ib-status:s' => { name => 'critical_ib_status', default => '%{status} !~ /active/i' },
|
||||
'warning-ibgw-status:s' => { name => 'warning_ibgw_status', default => '' },
|
||||
'critical-ibgw-status:s' => { name => 'critical_ibgw_status', default => '%{status} !~ /up/i' },
|
||||
'speed-in:s' => { name => 'speed_in' },
|
||||
'speed-out:s' => { name => 'speed_out' },
|
||||
'units-traffic:s' => { name => 'units_traffic', default => '%' }
|
||||
'filter-ib-name:s' => { name => 'filter_ib_name' },
|
||||
'filter-ibgw-name:s' => { name => 'filter_ibgw_name' },
|
||||
'speed-in:s' => { name => 'speed_in' },
|
||||
'speed-out:s' => { name => 'speed_out' },
|
||||
'units-traffic:s' => { name => 'units_traffic', default => '%' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_ib_status', 'critical_ib_status', 'warning_ibgw_status', 'critical_ibgw_status']);
|
||||
}
|
||||
|
||||
sub prefix_ib_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -67,7 +67,7 @@ sub new {
|
||||
"ntlm" => { name => 'ntlm' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"timeout:s" => { name => 'timeout' }
|
||||
});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
$self->{payload_attachment} = { fields => [] };
|
||||
@ -94,8 +94,7 @@ sub check_options {
|
||||
|
||||
foreach (('graph_url', 'link_url')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{option_results}->{$1}/g;
|
||||
eval "\$self->{option_results}->{\$_} = \"$self->{option_results}->{$_}\"";
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/$self->{option_results}->{$1}/eg;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ sub new {
|
||||
"link-url:s" => { name => 'link_url' },
|
||||
"centreon-url:s" => { name => 'centreon_url' },
|
||||
"centreon-token:s" => { name => 'centreon_token' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"timeout:s" => { name => 'timeout' }
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
@ -87,8 +87,7 @@ sub check_options {
|
||||
|
||||
foreach (('graph_url', 'link_url')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{option_results}->{$1}/g;
|
||||
eval "\$self->{option_results}->{\$_} = \"$self->{option_results}->{$_}\"";
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/$self->{option_results}->{$1}/eg;
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,9 +160,11 @@ sub format_payload {
|
||||
|
||||
my $json = JSON::XS->new->utf8;
|
||||
|
||||
my $payload = { chat_id =>$self->{option_results}->{chat_id},
|
||||
parse_mode => 'HTML',
|
||||
text => $self->{message} };
|
||||
my $payload = {
|
||||
chat_id =>$self->{option_results}->{chat_id},
|
||||
parse_mode => 'HTML',
|
||||
text => $self->{message}
|
||||
};
|
||||
eval {
|
||||
$self->{payload_str} = $json->encode($payload);
|
||||
};
|
||||
@ -184,15 +185,16 @@ sub run {
|
||||
$self->format_payload();
|
||||
|
||||
my $url_path = '/bot' . $self->{option_results}->{bot_token} . $self->{option_results}->{url_path};
|
||||
my $response = $self->{http}->request(url_path => $url_path,
|
||||
method => 'POST', query_form_post => $self->{payload_str});
|
||||
my $response = $self->{http}->request(
|
||||
url_path => $url_path,
|
||||
method => 'POST', query_form_post => $self->{payload_str}
|
||||
);
|
||||
|
||||
my $decoded;
|
||||
eval {
|
||||
$decoded = JSON::XS->new->utf8->decode($response);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->output_add(long_msg => $response, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
@ -40,10 +40,10 @@ sub custom_threshold_output {
|
||||
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{critical_status}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{critical_status})) {
|
||||
$status = 'critical';
|
||||
} elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' &&
|
||||
eval "$self->{instance_mode}->{option_results}->{warning_status}") {
|
||||
$self->eval(value => $self->{instance_mode}->{option_results}->{warning_status})) {
|
||||
$status = 'warning';
|
||||
}
|
||||
|
||||
@ -1327,7 +1327,7 @@ sub add_result_global {
|
||||
|
||||
foreach (('global_admin_up_rule', 'global_admin_down_rule', 'global_oper_up_rule', 'global_oper_down_rule')) {
|
||||
if (defined($self->{option_results}->{$_})) {
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$$1/g;
|
||||
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1336,15 +1336,17 @@ sub add_result_global {
|
||||
global_oper_up => 0, global_oper_down => 0
|
||||
};
|
||||
foreach (@{$self->{array_interface_selected}}) {
|
||||
my $opstatus = $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $_}};
|
||||
my $admstatus = $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $_}};
|
||||
my $values = {
|
||||
opstatus => $self->{oid_opstatus_mapping}->{ $self->{results}->{$self->{oid_opstatus} . '.' . $_} },
|
||||
admstatus => $self->{oid_adminstatus_mapping}->{ $self->{results}->{$self->{oid_adminstatus} . '.' . $_} }
|
||||
};
|
||||
foreach (('global_admin_up', 'global_admin_down', 'global_oper_up', 'global_oper_down')) {
|
||||
eval {
|
||||
local $SIG{__WARN__} = sub { return ; };
|
||||
local $SIG{__DIE__} = sub { return ; };
|
||||
|
||||
if (defined($self->{option_results}->{$_ . '_rule'}) && $self->{option_results}->{$_ . '_rule'} ne '' &&
|
||||
eval "$self->{option_results}->{$_ . '_rule'}") {
|
||||
$self->{output}->test_eval(test => $self->{option_results}->{$_ . '_rule'}, values => $values)) {
|
||||
$self->{global}->{$_}++;
|
||||
}
|
||||
};
|
||||
|
@ -243,7 +243,7 @@ sub change_macros {
|
||||
|
||||
my $value = $self->{option_results}->{'format_' . $options{severity}};
|
||||
while ($value =~ /%\{(.*?)\}/g) {
|
||||
$value =~ s/%\{($1)\}/\$self->{macros}->{$1}/g;
|
||||
$value =~ s/%\{($1)\}/$self->{macros}->{$1}/eg;
|
||||
}
|
||||
|
||||
return $value;
|
||||
@ -276,9 +276,10 @@ sub display_severity {
|
||||
}
|
||||
|
||||
my $display = $self->change_macros(severity => $options{severity});
|
||||
eval "\$display = \"$display\"";
|
||||
$self->{output}->output_add(severity => $options{severity},
|
||||
short_msg => $display);
|
||||
$self->{output}->output_add(
|
||||
severity => $options{severity},
|
||||
short_msg => $display
|
||||
);
|
||||
}
|
||||
|
||||
sub display_result {
|
||||
|
Loading…
x
Reference in New Issue
Block a user