(plugin) cloud::kubernetes - wrong perfdata values
This commit is contained in:
parent
6fb9a654d2
commit
00c431dcdf
|
@ -106,6 +106,10 @@ sub execute {
|
|||
# See https://kubernetes.io/docs/reference/kubectl/cheatsheet/#kubectl-output-verbosity-and-debugging
|
||||
$cmd_options .= " --v='9'" if ($self->{output}->is_debug());
|
||||
|
||||
if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '') {
|
||||
$cmd_options = $self->{option_results}->{command_options};
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $cmd_options . "'", debug => 1);
|
||||
|
||||
my ($response, $exit_code) = centreon::plugins::misc::execute(
|
||||
|
|
|
@ -26,26 +26,27 @@ use strict;
|
|||
use warnings;
|
||||
use DateTime;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub custom_status_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'active',
|
||||
nlabel => 'cronjob.jobs.active.count',
|
||||
value => $self->{result_values}->{active},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Jobs Active: %s, Last schedule time: %s ago (%s)",
|
||||
return sprintf(
|
||||
"Jobs Active: %s, Last schedule time: %s ago (%s)",
|
||||
$self->{result_values}->{active},
|
||||
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{last_schedule}),
|
||||
$self->{result_values}->{last_schedule_time});
|
||||
$self->{result_values}->{last_schedule_time}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
|
@ -71,6 +72,12 @@ sub custom_status_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_cronjob_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "CronJob '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -80,46 +87,32 @@ sub set_counters {
|
|||
];
|
||||
|
||||
$self->{maps_counters}->{cronjobs} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [ { name => 'active' }, { name => 'last_schedule_time' }, { name => 'name' },
|
||||
{ name => 'namespace' } ],
|
||||
{ label => 'status', type => 2, set => {
|
||||
key_values => [
|
||||
{ name => 'active' }, { name => 'last_schedule_time' }, { name => 'name' },
|
||||
{ name => 'namespace' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_cronjob_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "CronJob '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
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' },
|
||||
"filter-namespace:s" => { name => 'filter_namespace' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' }
|
||||
});
|
||||
|
||||
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) = @_;
|
||||
|
||||
|
|
|
@ -24,96 +24,56 @@ 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_status_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'desired',
|
||||
nlabel => 'daemonset.pods.desired.count',
|
||||
value => $self->{result_values}->{desired},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'current',
|
||||
nlabel => 'daemonset.pods.current.count',
|
||||
value => $self->{result_values}->{current},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'available',
|
||||
nlabel => 'daemonset.pods.available.count',
|
||||
value => $self->{result_values}->{available},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'up_to_date',
|
||||
nlabel => 'daemonset.pods.uptodate.count',
|
||||
value => $self->{result_values}->{up_to_date},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'ready',
|
||||
nlabel => 'daemonset.pods.ready.count',
|
||||
value => $self->{result_values}->{ready},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'misscheduled',
|
||||
nlabel => 'daemonset.pods.misscheduled.count',
|
||||
value => $self->{result_values}->{misscheduled},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Pods Desired: %s, Current: %s, Available: %s, Up-to-date: %s, Ready: %s, Misscheduled: %s",
|
||||
return sprintf(
|
||||
"Pods Desired: %s, Current: %s, Available: %s, Up-to-date: %s, Ready: %s, Misscheduled: %s",
|
||||
$self->{result_values}->{desired},
|
||||
$self->{result_values}->{current},
|
||||
$self->{result_values}->{available},
|
||||
$self->{result_values}->{up_to_date},
|
||||
$self->{result_values}->{ready},
|
||||
$self->{result_values}->{misscheduled});
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
$self->{result_values}->{namespace} = $options{new_datas}->{$self->{instance} . '_namespace'};
|
||||
$self->{result_values}->{desired} = $options{new_datas}->{$self->{instance} . '_desired'};
|
||||
$self->{result_values}->{current} = $options{new_datas}->{$self->{instance} . '_current'};
|
||||
$self->{result_values}->{available} = $options{new_datas}->{$self->{instance} . '_available'};
|
||||
$self->{result_values}->{up_to_date} = $options{new_datas}->{$self->{instance} . '_up_to_date'};
|
||||
$self->{result_values}->{ready} = $options{new_datas}->{$self->{instance} . '_ready'};
|
||||
$self->{result_values}->{misscheduled} = $options{new_datas}->{$self->{instance} . '_misscheduled'};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'daemonsets', type => 1, cb_prefix_output => 'prefix_daemonset_output',
|
||||
message_multiple => 'All DaemonSets status are ok', skipped_code => { -11 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{daemonsets} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' }, { name => 'up_to_date' },
|
||||
{ name => 'available' }, { name => 'ready' }, { name => 'misscheduled' }, { name => 'name' },
|
||||
{ name => 'namespace' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{result_values}->{misscheduled}
|
||||
);
|
||||
}
|
||||
|
||||
sub prefix_daemonset_output {
|
||||
|
@ -122,28 +82,45 @@ sub prefix_daemonset_output {
|
|||
return "DaemonSet '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'daemonsets', type => 1, cb_prefix_output => 'prefix_daemonset_output',
|
||||
message_multiple => 'All DaemonSets status are ok', skipped_code => { -11 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{daemonsets} = [
|
||||
{
|
||||
label => 'status',
|
||||
type => 2,
|
||||
warning_default => '%{up_to_date} < %{desired}',
|
||||
critical_default => '%{available} < %{desired}',
|
||||
set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' }, { name => 'up_to_date' },
|
||||
{ name => 'available' }, { name => 'ready' }, { name => 'misscheduled' }, { name => 'name' },
|
||||
{ name => 'namespace' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
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' },
|
||||
"filter-namespace:s" => { name => 'filter_namespace' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{available} < %{desired}' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' }
|
||||
});
|
||||
|
||||
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) = @_;
|
||||
|
||||
|
@ -162,17 +139,24 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $daemonset->{metadata}->{namespace} . "': no matching filter namespace.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{daemonsets}->{$daemonset->{metadata}->{uid}} = {
|
||||
|
||||
$self->{daemonsets}->{ $daemonset->{metadata}->{uid} } = {
|
||||
name => $daemonset->{metadata}->{name},
|
||||
namespace => $daemonset->{metadata}->{namespace},
|
||||
desired => (defined($daemonset->{status}->{desiredNumberScheduled})) && $daemonset->{status}->{desiredNumberScheduled} =~ /(\d+)/ ? $1 : 0,
|
||||
current => (defined($daemonset->{status}->{currentNumberScheduled})) && $daemonset->{status}->{currentNumberScheduled} =~ /(\d+)/ ? $1 : 0,
|
||||
up_to_date => (defined($daemonset->{status}->{updatedNumberScheduled})) && $daemonset->{status}->{updatedNumberScheduled} =~ /(\d+)/ ? $1 : 0,
|
||||
available => (defined($daemonset->{status}->{numberAvailable})) && $daemonset->{status}->{numberAvailable} =~ /(\d+)/ ? $1 : 0,
|
||||
ready => (defined($daemonset->{status}->{numberReady})) && $daemonset->{status}->{numberReady} =~ /(\d+)/ ? $1 : 0,
|
||||
misscheduled => (defined($daemonset->{status}->{numberMisscheduled})) && $daemonset->{status}->{numberMisscheduled} =~ /(\d+)/ ? $1 : 0
|
||||
}
|
||||
namespace => $daemonset->{metadata}->{namespace}
|
||||
};
|
||||
|
||||
$self->{daemonsets}->{ $daemonset->{metadata}->{uid} }->{desired} =
|
||||
defined($daemonset->{status}->{desiredNumberScheduled}) && $daemonset->{status}->{desiredNumberScheduled} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{daemonsets}->{ $daemonset->{metadata}->{uid} }->{current} =
|
||||
defined($daemonset->{status}->{currentNumberScheduled}) && $daemonset->{status}->{currentNumberScheduled} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{daemonsets}->{ $daemonset->{metadata}->{uid} }->{up_to_date} =
|
||||
defined($daemonset->{status}->{updatedNumberScheduled}) && $daemonset->{status}->{updatedNumberScheduled} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{daemonsets}->{ $daemonset->{metadata}->{uid} }->{available} =
|
||||
defined($daemonset->{status}->{numberAvailable}) && $daemonset->{status}->{numberAvailable} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{daemonsets}->{ $daemonset->{metadata}->{uid} }->{ready} =
|
||||
defined($daemonset->{status}->{numberReady}) && $daemonset->{status}->{numberReady} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{daemonsets}->{ $daemonset->{metadata}->{uid} }->{misscheduled} =
|
||||
defined($daemonset->{status}->{numberMisscheduled}) && $daemonset->{status}->{numberMisscheduled} =~ /(\d+)/ ? $1 : 0;
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{daemonsets}}) <= 0) {
|
||||
|
|
|
@ -24,87 +24,49 @@ 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_status_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'desired',
|
||||
nlabel => 'deployment.replicas.desired.count',
|
||||
value => $self->{result_values}->{desired},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'current',
|
||||
nlabel => 'deployment.replicas.current.count',
|
||||
value => $self->{result_values}->{current},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'available',
|
||||
nlabel => 'deployment.replicas.available.count',
|
||||
value => $self->{result_values}->{available},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'ready',
|
||||
nlabel => 'deployment.replicas.ready.count',
|
||||
value => $self->{result_values}->{ready},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'up_to_date',
|
||||
nlabel => 'deployment.replicas.uptodate.count',
|
||||
value => $self->{result_values}->{up_to_date},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Replicas Desired: %s, Current: %s, Available: %s, Ready: %s, Up-to-date: %s",
|
||||
return sprintf(
|
||||
"Replicas Desired: %s, Current: %s, Available: %s, Ready: %s, Up-to-date: %s",
|
||||
$self->{result_values}->{desired},
|
||||
$self->{result_values}->{current},
|
||||
$self->{result_values}->{available},
|
||||
$self->{result_values}->{ready},
|
||||
$self->{result_values}->{up_to_date});
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
$self->{result_values}->{namespace} = $options{new_datas}->{$self->{instance} . '_namespace'};
|
||||
$self->{result_values}->{desired} = $options{new_datas}->{$self->{instance} . '_desired'};
|
||||
$self->{result_values}->{current} = $options{new_datas}->{$self->{instance} . '_current'};
|
||||
$self->{result_values}->{available} = $options{new_datas}->{$self->{instance} . '_available'};
|
||||
$self->{result_values}->{ready} = $options{new_datas}->{$self->{instance} . '_ready'};
|
||||
$self->{result_values}->{up_to_date} = $options{new_datas}->{$self->{instance} . '_up_to_date'};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'deployments', type => 1, cb_prefix_output => 'prefix_deployment_output',
|
||||
message_multiple => 'All Deployments status are ok', skipped_code => { -11 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{deployments} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' }, { name => 'up_to_date' },
|
||||
{ name => 'available' }, { name => 'ready' }, { name => 'name' }, { name => 'namespace' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{result_values}->{up_to_date}
|
||||
);
|
||||
}
|
||||
|
||||
sub prefix_deployment_output {
|
||||
|
@ -113,35 +75,50 @@ sub prefix_deployment_output {
|
|||
return "Deployment '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'deployments', type => 1, cb_prefix_output => 'prefix_deployment_output',
|
||||
message_multiple => 'All deployments status are ok', skipped_code => { -11 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{deployments} = [
|
||||
{
|
||||
label => 'status',
|
||||
type => 2,
|
||||
warning_default => '%{up_to_date} < %{desired}',
|
||||
critical_default => '%{available} < %{desired}',
|
||||
set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' }, { name => 'up_to_date' },
|
||||
{ name => 'available' }, { name => 'ready' }, { name => 'name' }, { name => 'namespace' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
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' },
|
||||
"filter-namespace:s" => { name => 'filter_namespace' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{available} < %{desired}' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' }
|
||||
});
|
||||
|
||||
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->{deployments} = {};
|
||||
|
||||
my $results = $options{custom}->kubernetes_list_deployments();
|
||||
|
||||
|
||||
$self->{deployments} = {};
|
||||
foreach my $deployment (@{$results}) {
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$deployment->{metadata}->{name} !~ /$self->{option_results}->{filter_name}/) {
|
||||
|
@ -154,15 +131,19 @@ sub manage_selection {
|
|||
next;
|
||||
}
|
||||
|
||||
$self->{deployments}->{$deployment->{metadata}->{uid}} = {
|
||||
$self->{deployments}->{ $deployment->{metadata}->{uid} } = {
|
||||
name => $deployment->{metadata}->{name},
|
||||
namespace => $deployment->{metadata}->{namespace},
|
||||
desired => $deployment->{spec}->{replicas},
|
||||
current => (defined($deployment->{status}->{replicas})) && $deployment->{status}->{replicas} =~ /(\d+)/ ? $1 : 0,
|
||||
ready => (defined($deployment->{status}->{readyReplicas})) && $deployment->{status}->{readyReplicas} =~ /(\d+)/ ? $1 : 0,
|
||||
up_to_date => (defined($deployment->{status}->{updatedReplicas})) && $deployment->{status}->{updatedReplicas} =~ /(\d+)/ ? $1 : 0,
|
||||
available => (defined($deployment->{status}->{availableReplicas})) && $deployment->{status}->{availableReplicas} =~ /(\d+)/ ? $1 : 0
|
||||
}
|
||||
desired => $deployment->{spec}->{replicas}
|
||||
};
|
||||
$self->{deployments}->{ $deployment->{metadata}->{uid} }->{current} =
|
||||
defined($deployment->{status}->{replicas}) && $deployment->{status}->{replicas} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{deployments}->{ $deployment->{metadata}->{uid} }->{ready} =
|
||||
defined($deployment->{status}->{readyReplicas}) && $deployment->{status}->{readyReplicas} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{deployments}->{ $deployment->{metadata}->{uid} }->{up_to_date} =
|
||||
defined($deployment->{status}->{updatedReplicas}) && $deployment->{status}->{updatedReplicas} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{deployments}->{ $deployment->{metadata}->{uid} }->{available} =
|
||||
defined($deployment->{status}->{availableReplicas}) && $deployment->{status}->{availableReplicas} =~ /(\d+)/ ? $1 : 0;
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{deployments}}) <= 0) {
|
||||
|
|
|
@ -55,7 +55,6 @@ sub long_output {
|
|||
return "Checking node '" . $options{instance_value}->{display} . "'";
|
||||
}
|
||||
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
|
|
@ -24,22 +24,21 @@ 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_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Phase is '%s'",
|
||||
$self->{result_values}->{phase});
|
||||
return sprintf(
|
||||
"Phase is '%s'",
|
||||
$self->{result_values}->{phase}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
sub prefix_pv_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
$self->{result_values}->{phase} = $options{new_datas}->{$self->{instance} . '_phase'};
|
||||
|
||||
return 0;
|
||||
return "Persistent Volume '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
|
@ -51,45 +50,29 @@ sub set_counters {
|
|||
];
|
||||
|
||||
$self->{maps_counters}->{pvs} = [
|
||||
{ label => 'status', set => {
|
||||
{ label => 'status', type => 2, critical_default => '%{phase} !~ /Bound|Available|Released/i', set => {
|
||||
key_values => [ { name => 'phase' }, { name => 'name' } ],
|
||||
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
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_pv_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Persistent Volume '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
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' },
|
||||
"filter-namespace:s" => { name => 'filter_namespace' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{phase} !~ /Bound|Available|Released/i' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' }
|
||||
});
|
||||
|
||||
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) = @_;
|
||||
|
||||
|
|
|
@ -30,44 +30,37 @@ sub custom_status_perfdata {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'desired',
|
||||
nlabel => 'replicaset.replicas.desired.count',
|
||||
value => $self->{result_values}->{desired},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'current',
|
||||
nlabel => 'replicaset.replicas.current.count',
|
||||
value => $self->{result_values}->{current},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'ready',
|
||||
nlabel => 'replicaset.replicas.ready.count',
|
||||
value => $self->{result_values}->{ready},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Replicas Desired: %s, Current: %s, Ready: %s",
|
||||
return sprintf(
|
||||
"Replicas Desired: %s, Current: %s, Ready: %s",
|
||||
$self->{result_values}->{desired},
|
||||
$self->{result_values}->{current},
|
||||
$self->{result_values}->{ready});
|
||||
$self->{result_values}->{ready}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
sub prefix_replicaset_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
$self->{result_values}->{namespace} = $options{new_datas}->{$self->{instance} . '_namespace'};
|
||||
$self->{result_values}->{desired} = $options{new_datas}->{$self->{instance} . '_desired'};
|
||||
$self->{result_values}->{current} = $options{new_datas}->{$self->{instance} . '_current'};
|
||||
$self->{result_values}->{ready} = $options{new_datas}->{$self->{instance} . '_ready'};
|
||||
|
||||
return 0;
|
||||
return "ReplicaSet '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
|
@ -79,46 +72,30 @@ sub set_counters {
|
|||
];
|
||||
|
||||
$self->{maps_counters}->{replicasets} = [
|
||||
{ label => 'status', set => {
|
||||
{ label => 'status', type => 2, critical_default => '%{ready} < %{desired}', set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' },
|
||||
{ name => 'ready' }, { name => 'name' }, { name => 'namespace' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_replicaset_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "ReplicaSet '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
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' },
|
||||
"filter-namespace:s" => { name => 'filter_namespace' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{ready} < %{desired}' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' }
|
||||
});
|
||||
|
||||
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) = @_;
|
||||
|
||||
|
@ -138,13 +115,15 @@ sub manage_selection {
|
|||
next;
|
||||
}
|
||||
|
||||
$self->{replicasets}->{$replicaset->{metadata}->{uid}} = {
|
||||
$self->{replicasets}->{ $replicaset->{metadata}->{uid} } = {
|
||||
name => $replicaset->{metadata}->{name},
|
||||
namespace => $replicaset->{metadata}->{namespace},
|
||||
desired => $replicaset->{spec}->{replicas},
|
||||
current => (defined($replicaset->{status}->{replicas})) && $replicaset->{status}->{replicas} =~ /(\d+)/ ? $1 : 0,
|
||||
ready => (defined($replicaset->{status}->{readyReplicas})) && $replicaset->{status}->{readyReplicas} =~ /(\d+)/ ? $1 : 0
|
||||
}
|
||||
desired => $replicaset->{spec}->{replicas}
|
||||
};
|
||||
$self->{replicasets}->{ $replicaset->{metadata}->{uid} }->{current} =
|
||||
defined($replicaset->{status}->{replicas}) && $replicaset->{status}->{replicas} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{replicasets}->{ $replicaset->{metadata}->{uid} }->{ready} =
|
||||
defined($replicaset->{status}->{readyReplicas}) && $replicaset->{status}->{readyReplicas} =~ /(\d+)/ ? $1 : 0;
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{replicasets}}) <= 0) {
|
||||
|
|
|
@ -24,71 +24,37 @@ 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_status_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'desired',
|
||||
nlabel => 'replicationcontroller.replicas.desired.count',
|
||||
value => $self->{result_values}->{desired},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'current',
|
||||
nlabel => 'replicationcontroller.replicas.current.count',
|
||||
value => $self->{result_values}->{current},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'ready',
|
||||
nlabel => 'replicationcontroller.replicas.ready.count',
|
||||
value => $self->{result_values}->{ready},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Replicas Desired: %s, Current: %s, Ready: %s",
|
||||
return sprintf(
|
||||
"Replicas Desired: %s, Current: %s, Ready: %s",
|
||||
$self->{result_values}->{desired},
|
||||
$self->{result_values}->{current},
|
||||
$self->{result_values}->{ready});
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
$self->{result_values}->{namespace} = $options{new_datas}->{$self->{instance} . '_namespace'};
|
||||
$self->{result_values}->{desired} = $options{new_datas}->{$self->{instance} . '_desired'};
|
||||
$self->{result_values}->{current} = $options{new_datas}->{$self->{instance} . '_current'};
|
||||
$self->{result_values}->{ready} = $options{new_datas}->{$self->{instance} . '_ready'};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'rcs', type => 1, cb_prefix_output => 'prefix_rc_output',
|
||||
message_multiple => 'All ReplicationControllers status are ok', skipped_code => { -11 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{rcs} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' },
|
||||
{ name => 'ready' }, { name => 'name' }, { name => 'namespace' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{result_values}->{ready}
|
||||
);
|
||||
}
|
||||
|
||||
sub prefix_rc_output {
|
||||
|
@ -97,28 +63,39 @@ sub prefix_rc_output {
|
|||
return "ReplicationController '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'rcs', type => 1, cb_prefix_output => 'prefix_rc_output',
|
||||
message_multiple => 'All ReplicationControllers status are ok', skipped_code => { -11 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{rcs} = [
|
||||
{ label => 'status', type => 2, critical_default => '%{ready} < %{desired}', set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' },
|
||||
{ name => 'ready' }, { name => 'name' }, { name => 'namespace' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
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' },
|
||||
"filter-namespace:s" => { name => 'filter_namespace' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{ready} < %{desired}' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' }
|
||||
});
|
||||
|
||||
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) = @_;
|
||||
|
||||
|
@ -137,16 +114,18 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $rc->{metadata}->{namespace} . "': no matching filter namespace.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{rcs}->{$rc->{metadata}->{uid}} = {
|
||||
|
||||
$self->{rcs}->{ $rc->{metadata}->{uid} } = {
|
||||
name => $rc->{metadata}->{name},
|
||||
namespace => $rc->{metadata}->{namespace},
|
||||
desired => $rc->{spec}->{replicas},
|
||||
current => (defined($rc->{status}->{replicas})) && $rc->{status}->{replicas} =~ /(\d+)/ ? $1 : 0,
|
||||
ready => (defined($rc->{status}->{readyReplicas})) && $rc->{status}->{readyReplicas} =~ /(\d+)/ ? $1 : 0
|
||||
}
|
||||
desired => $rc->{spec}->{replicas}
|
||||
};
|
||||
$self->{rcs}->{ $rc->{metadata}->{uid} }->{current} =
|
||||
defined($rc->{status}->{replicas}) && $rc->{status}->{replicas} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{rcs}->{ $rc->{metadata}->{uid} }->{ready} =
|
||||
defined($rc->{status}->{readyReplicas}) && $rc->{status}->{readyReplicas} =~ /(\d+)/ ? $1 : 0;
|
||||
}
|
||||
|
||||
|
||||
if (scalar(keys %{$self->{rcs}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No ReplicationControllers found.");
|
||||
$self->{output}->option_exit();
|
||||
|
|
|
@ -24,79 +24,43 @@ 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_status_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'desired',
|
||||
nlabel => 'statefulset.replicas.desired.count',
|
||||
value => $self->{result_values}->{desired},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'current',
|
||||
nlabel => 'statefulset.replicas.current.count',
|
||||
value => $self->{result_values}->{current},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'up_to_date',
|
||||
nlabel => 'statefulset.replicas.uptodate.count',
|
||||
value => $self->{result_values}->{up_to_date},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'ready',
|
||||
nlabel => 'statefulset.replicas.ready.count',
|
||||
value => $self->{result_values}->{ready},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
|
||||
instances => $self->{result_values}->{name}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Replicas Desired: %s, Current: %s, Up-to-date: %s, Ready: %s",
|
||||
return sprintf(
|
||||
"Replicas Desired: %s, Current: %s, Up-to-date: %s, Ready: %s",
|
||||
$self->{result_values}->{desired},
|
||||
$self->{result_values}->{current},
|
||||
$self->{result_values}->{up_to_date},
|
||||
$self->{result_values}->{ready});
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
$self->{result_values}->{namespace} = $options{new_datas}->{$self->{instance} . '_namespace'};
|
||||
$self->{result_values}->{desired} = $options{new_datas}->{$self->{instance} . '_desired'};
|
||||
$self->{result_values}->{current} = $options{new_datas}->{$self->{instance} . '_current'};
|
||||
$self->{result_values}->{up_to_date} = $options{new_datas}->{$self->{instance} . '_up_to_date'};
|
||||
$self->{result_values}->{ready} = $options{new_datas}->{$self->{instance} . '_ready'};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'statefulsets', type => 1, cb_prefix_output => 'prefix_statefulset_output',
|
||||
message_multiple => 'All StatefulSets status are ok', skipped_code => { -11 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{statefulsets} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' }, { name => 'up_to_date' },
|
||||
{ name => 'ready' }, { name => 'name' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{result_values}->{ready}
|
||||
);
|
||||
}
|
||||
|
||||
sub prefix_statefulset_output {
|
||||
|
@ -105,28 +69,44 @@ sub prefix_statefulset_output {
|
|||
return "StatefulSet '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'statefulsets', type => 1, cb_prefix_output => 'prefix_statefulset_output',
|
||||
message_multiple => 'All StatefulSets status are ok', skipped_code => { -11 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{statefulsets} = [
|
||||
{
|
||||
label => 'status',
|
||||
type => 2,
|
||||
warning_default => '%{up_to_date} < %{desired}',
|
||||
critical_default => '%{ready} < %{desired}',
|
||||
set => {
|
||||
key_values => [ { name => 'desired' }, { name => 'current' }, { name => 'up_to_date' },
|
||||
{ name => 'ready' }, { name => 'name' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
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' },
|
||||
"filter-namespace:s" => { name => 'filter_namespace' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{ready} < %{desired}' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-namespace:s' => { name => 'filter_namespace' }
|
||||
});
|
||||
|
||||
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) = @_;
|
||||
|
||||
|
@ -146,16 +126,19 @@ sub manage_selection {
|
|||
next;
|
||||
}
|
||||
|
||||
$self->{statefulsets}->{$statefulset->{metadata}->{uid}} = {
|
||||
$self->{statefulsets}->{ $statefulset->{metadata}->{uid} } = {
|
||||
name => $statefulset->{metadata}->{name},
|
||||
namespace => $statefulset->{metadata}->{namespace},
|
||||
desired => $statefulset->{spec}->{replicas},
|
||||
current => (defined($statefulset->{status}->{currentReplicas})) && $statefulset->{status}->{currentReplicas} =~ /(\d+)/ ? $1 : 0,
|
||||
ready => (defined($statefulset->{status}->{readyReplicas})) && $statefulset->{status}->{readyReplicas} =~ /(\d+)/ ? $1 : 0,
|
||||
up_to_date => (defined($statefulset->{status}->{updatedReplicas})) && $statefulset->{status}->{updatedReplicas} =~ /(\d+)/ ? $1 : 0
|
||||
}
|
||||
desired => $statefulset->{spec}->{replicas}
|
||||
};
|
||||
$self->{statefulsets}->{ $statefulset->{metadata}->{uid} }->{current} =
|
||||
defined($statefulset->{status}->{currentReplicas}) && $statefulset->{status}->{currentReplicas} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{statefulsets}->{ $statefulset->{metadata}->{uid} }->{ready} =
|
||||
defined($statefulset->{status}->{readyReplicas}) && $statefulset->{status}->{readyReplicas} =~ /(\d+)/ ? $1 : 0;
|
||||
$self->{statefulsets}->{ $statefulset->{metadata}->{uid} }->{up_to_date} =
|
||||
defined($statefulset->{status}->{updatedReplicas}) && $statefulset->{status}->{updatedReplicas} =~ /(\d+)/ ? $1 : 0;
|
||||
}
|
||||
|
||||
|
||||
if (scalar(keys %{$self->{statefulsets}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No StatefulSets found.");
|
||||
$self->{output}->option_exit();
|
||||
|
|
Loading…
Reference in New Issue