(plugin) apps::centreon::local - convert queue_file_enabled to yes/no (#3464)

This commit is contained in:
qgarnier 2022-02-07 09:14:34 +01:00 committed by GitHub
parent 5838c306b0
commit ecd1e325d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 32 deletions

View File

@ -26,7 +26,7 @@ use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
use JSON; use JSON;
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 { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -35,21 +35,19 @@ sub custom_status_output {
if ($self->{result_values}->{type} eq 'input') { if ($self->{result_values}->{type} eq 'input') {
$msg = sprintf("state : %s", $self->{result_values}->{state}); $msg = sprintf("state : %s", $self->{result_values}->{state});
} else { } else {
$msg = sprintf("state : %s [status : %s] [queue file enabled : %s]", $msg = sprintf(
$self->{result_values}->{state}, $self->{result_values}->{status}, $self->{result_values}->{queue_file_enabled}); "state : %s [status : %s] [queue file enabled : %s]",
$self->{result_values}->{state}, $self->{result_values}->{status}, $self->{result_values}->{queue_file_enabled}
);
} }
return $msg; return $msg;
} }
sub custom_status_calc {
sub prefix_endpoint_output {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{queue_file_enabled} = $options{new_datas}->{$self->{instance} . '_queue_file_enabled'}; return "Endpoint $options{instance_value}->{type} '" . $options{instance_value}->{display} . "' ";
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
} }
sub set_counters { sub set_counters {
@ -60,12 +58,11 @@ sub set_counters {
]; ];
$self->{maps_counters}->{endpoint} = [ $self->{maps_counters}->{endpoint} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, critical_default => '%{type} eq "output" and %{queue_file_enabled} =~ /yes/i', set => {
key_values => [ { name => 'queue_file_enabled' }, { name => 'state' }, { name => 'status' }, { name => 'type' }, { name => 'display' } ], key_values => [ { name => 'queue_file_enabled' }, { name => 'state' }, { name => 'status' }, { name => 'type' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'speed-events', set => { { label => 'speed-events', set => {
@ -73,8 +70,8 @@ sub set_counters {
output_template => 'Speed Events: %s/s', output_template => 'Speed Events: %s/s',
perfdatas => [ perfdatas => [
{ label => 'speed_events', value => 'speed_events', template => '%s', { label => 'speed_events', value => 'speed_events', template => '%s',
unit => 'events/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => 'events/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'queued-events', set => { { label => 'queued-events', set => {
@ -82,8 +79,8 @@ sub set_counters {
output_template => 'Queued Events: %s', output_template => 'Queued Events: %s',
perfdatas => [ perfdatas => [
{ label => 'queued_events', value => 'queued_events', template => '%s', { label => 'queued_events', value => 'queued_events', template => '%s',
unit => 'events', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => 'events', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'unacknowledged-events', set => { { label => 'unacknowledged-events', set => {
@ -91,10 +88,10 @@ sub set_counters {
output_template => 'Unacknowledged Events: %s', output_template => 'Unacknowledged Events: %s',
perfdatas => [ perfdatas => [
{ label => 'unacknowledged_events', value => 'unacknowledged_events', template => '%s', { label => 'unacknowledged_events', value => 'unacknowledged_events', template => '%s',
unit => 'events', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => 'events', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
} }
@ -112,9 +109,7 @@ sub new {
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 }, 'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' }, 'sudo' => { name => 'sudo' },
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' }
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{type} eq "output" and %{queue_file_enabled} =~ /yes/i' },
}); });
return $self; return $self;
@ -128,13 +123,6 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Please set broker-stats-file option."); $self->{output}->add_option_msg(short_msg => "Please set broker-stats-file option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_endpoint_output {
my ($self, %options) = @_;
return "Endpoint $options{instance_value}->{type} '" . $options{instance_value}->{display} . "' ";
} }
sub manage_selection { sub manage_selection {
@ -174,6 +162,10 @@ sub manage_selection {
my $type = 'output'; my $type = 'output';
$type = 'input' if (!defined($json->{$entry}->{status})); $type = 'input' if (!defined($json->{$entry}->{status}));
my $queue_enabled = '-';
if (defined($json->{$entry}->{queue_file_enabled})) {
$queue_enabled = $json->{$entry}->{queue_file_enabled} ? 'yes' : 'no';
}
$self->{endpoint}->{$endpoint} = { $self->{endpoint}->{$endpoint} = {
display => $endpoint, display => $endpoint,
state => $state, state => $state,
@ -182,7 +174,7 @@ sub manage_selection {
speed_events => $json->{$entry}->{event_processing_speed}, speed_events => $json->{$entry}->{event_processing_speed},
queued_events => $json->{$entry}->{queued_events}, queued_events => $json->{$entry}->{queued_events},
unacknowledged_events => $json->{$entry}->{bbdo_unacknowledged_events}, unacknowledged_events => $json->{$entry}->{bbdo_unacknowledged_events},
queue_file_enabled => defined($json->{$entry}->{queue_file_enabled}) ? $json->{$entry}->{queue_file_enabled} : '-', queue_file_enabled => $queue_enabled
}; };
} }
} }