(plugin) cloud::kubernetes - add name for node-status and pod-status (#3423)
This commit is contained in:
parent
2c3cca1e20
commit
f5f4b7bfd0
|
@ -24,53 +24,17 @@ 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 custom_condition_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Status is '%s', Reason: '%s', Message: '%s'",
|
||||
return sprintf(
|
||||
"Status is '%s', Reason: '%s', Message: '%s'",
|
||||
$self->{result_values}->{status},
|
||||
$self->{result_values}->{reason},
|
||||
$self->{result_values}->{message});
|
||||
}
|
||||
|
||||
sub custom_condition_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
|
||||
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
|
||||
$self->{result_values}->{reason} = $options{new_datas}->{$self->{instance} . '_reason'};
|
||||
$self->{result_values}->{message} = $options{new_datas}->{$self->{instance} . '_message'};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'nodes', type => 3, cb_prefix_output => 'prefix_output', cb_long_output => 'long_output',
|
||||
message_multiple => 'All Nodes status are ok', indent_long_output => ' ',
|
||||
group => [
|
||||
{ name => 'conditions', display_long => 1, cb_prefix_output => 'prefix_condition_output',
|
||||
message_multiple => 'Conditions are ok', type => 1, skipped_code => { -10 => 1 } },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{conditions} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [
|
||||
{ name => 'type' }, { name => 'status' }, { name => 'reason' }, { name => 'message' }
|
||||
],
|
||||
closure_custom_calc => $self->can('custom_condition_status_calc'),
|
||||
closure_custom_output => $self->can('custom_condition_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{result_values}->{message}
|
||||
);
|
||||
}
|
||||
|
||||
sub prefix_output {
|
||||
|
@ -91,37 +55,56 @@ sub long_output {
|
|||
return "Checking node '" . $options{instance_value}->{display} . "'";
|
||||
}
|
||||
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'nodes', type => 3, cb_prefix_output => 'prefix_output', cb_long_output => 'long_output',
|
||||
message_multiple => 'All Nodes status are ok', indent_long_output => ' ',
|
||||
group => [
|
||||
{ name => 'conditions', display_long => 1, cb_prefix_output => 'prefix_condition_output',
|
||||
message_multiple => 'Conditions are ok', type => 1, skipped_code => { -10 => 1 } },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{conditions} = [
|
||||
{
|
||||
label => 'status',
|
||||
type => 2,
|
||||
critical_default => '(%{type} =~ /Ready/i && %{status} !~ /True/i) || (%{type} =~ /.*Pressure/i && %{status} !~ /False/i)',
|
||||
set => {
|
||||
key_values => [
|
||||
{ name => 'type' }, { name => 'status' }, { name => 'reason' },
|
||||
{ name => 'message' }, { name => 'name' }
|
||||
],
|
||||
closure_custom_output => $self->can('custom_condition_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, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => {
|
||||
name => 'critical_status',
|
||||
default => '(%{type} =~ /Ready/i && %{status} !~ /True/i) || (%{type} =~ /.*Pressure/i && %{status} !~ /False/i)'
|
||||
},
|
||||
'filter-name:s' => { name => 'filter_name' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{nodes} = {};
|
||||
|
||||
my $results = $options{custom}->kubernetes_list_nodes();
|
||||
|
||||
|
||||
$self->{nodes} = {};
|
||||
foreach my $node (@{$results}) {
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$node->{metadata}->{name} !~ /$self->{option_results}->{filter_name}/) {
|
||||
|
@ -133,6 +116,7 @@ sub manage_selection {
|
|||
|
||||
foreach my $condition (@{$node->{status}->{conditions}}) {
|
||||
$self->{nodes}->{$node->{metadata}->{uid}}->{conditions}->{$condition->{type}} = {
|
||||
name => $node->{metadata}->{name},
|
||||
type => $condition->{type},
|
||||
status => $condition->{status},
|
||||
reason => $condition->{reason},
|
||||
|
@ -164,12 +148,12 @@ Filter node name (can be a regexp).
|
|||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{type}, %{status}, %{reason}, %{message}.
|
||||
Can used special variables like: %{type}, %{status}, %{reason}, %{message}, %{name}.
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status (Default: '(%{type} =~ /Ready/i && %{status} !~ /True/i) || (%{type} =~ /.*Pressure/i && %{status} !~ /False/i)').
|
||||
Can used special variables like: %{type}, %{status}, %{reason}, %{message}.
|
||||
Can used special variables like: %{type}, %{status}, %{reason}, %{message}, %{name}.
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ 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 custom_pod_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -66,7 +66,6 @@ sub custom_ready_perfdata {
|
|||
}
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'containers_ready',
|
||||
nlabel => 'containers.ready.count',
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
|
@ -160,39 +159,37 @@ sub set_counters {
|
|||
closure_custom_threshold_check => $self->can('custom_ready_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'pod-status', set => {
|
||||
{ label => 'pod-status', type => 2, critical_default => '%{status} !~ /running/i', set => {
|
||||
key_values => [ { name => 'status' }, { name => 'name' }, { name => 'namespace' } ],
|
||||
closure_custom_output => $self->can('custom_pod_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'total-restarts-count', nlabel => 'restarts.total.count', set => {
|
||||
key_values => [ { name => 'restarts_total' }, { name => 'name' } ],
|
||||
output_template => 'Restarts: %d',
|
||||
perfdatas => [
|
||||
{ label => 'restarts_count', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name' }
|
||||
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'name' }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{containers} = [
|
||||
{ label => 'container-status', set => {
|
||||
key_values => [ { name => 'status' }, { name => 'state' } ],
|
||||
{ label => 'container-status', type => 2, critical_default => '%{status} !~ /running/i || %{state} !~ /^ready$/', set => {
|
||||
key_values => [ { name => 'status' }, { name => 'state' }, { name => 'name' } ],
|
||||
closure_custom_calc => $self->can('custom_container_status_calc'),
|
||||
closure_custom_output => $self->can('custom_container_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'restarts-count', nlabel => 'containers.restarts.count', set => {
|
||||
key_values => [ { name => 'restarts' }, { name => 'perf' } ],
|
||||
output_template => 'Restarts: %d',
|
||||
perfdatas => [
|
||||
{ label => 'restarts_count', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'perf' }
|
||||
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'perf' }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -205,14 +202,10 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' },
|
||||
'extra-filter:s@' => { name => 'extra_filter' },
|
||||
'warning-pod-status:s' => { name => 'warning_pod_status', default => '' },
|
||||
'critical-pod-status:s' => { name => 'critical_pod_status', default => '%{status} !~ /running/i' },
|
||||
'warning-container-status:s' => { name => 'warning_container_status', default => '' },
|
||||
'critical-container-status:s' => { name => 'critical_container_status', default => '%{status} !~ /running/i || %{state} !~ /^ready$/' },
|
||||
'units:s' => { name => 'units', default => '%' }
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' },
|
||||
'extra-filter:s@' => { name => 'extra_filter' },
|
||||
'units:s' => { name => 'units', default => '%' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -227,9 +220,6 @@ sub check_options {
|
|||
next if ($filter !~ /(.*)=(.*)/);
|
||||
$self->{extra_filter}->{$1} = $2;
|
||||
}
|
||||
|
||||
$self->change_macros(macros => ['warning_pod_status', 'critical_pod_status',
|
||||
'warning_container_status', 'critical_container_status']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
|
|
Loading…
Reference in New Issue