diff --git a/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm b/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm index e33818ae4..d10ec2f73 100644 --- a/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm @@ -68,7 +68,7 @@ sub set_counters { closure_custom_threshold_check => \&catalog_status_threshold, } }, - { label => 'restarts-count', set => { + { label => 'restarts-count', nlabel => 'kubernetes.container.restarts.count', set => { key_values => [ { name => 'restarts' }, { name => 'perf' } ], output_template => 'Restarts count : %d', perfdatas => [ @@ -92,16 +92,15 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "container:s" => { name => 'container', default => 'container=~".*"' }, - "pod:s" => { name => 'pod', default => 'pod=~".*"' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /running/ || %{state} !~ /ready/' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "metric-overload:s@" => { name => 'metric_overload' }, - "filter-counters:s" => { name => 'filter_counters' }, - }); + $options{options}->add_options(arguments => { + "container:s" => { name => 'container', default => 'container=~".*"' }, + "pod:s" => { name => 'pod', default => 'pod=~".*"' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /running/ || %{state} !~ /ready/' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "metric-overload:s@" => { name => 'metric_overload' }, + "filter-counters:s" => { name => 'filter_counters' }, + }); return $self; } @@ -146,34 +145,38 @@ sub manage_selection { $self->{containers} = {}; - my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{ready} . '",' . - $self->{option_results}->{container} . ',' . - $self->{option_results}->{pod} . - $self->{extra_filter} . '}, "__name__", "ready", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{running} . '",' . - $self->{option_results}->{container} . ',' . - $self->{option_results}->{pod} . - $self->{extra_filter} . '}, "__name__", "running", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{terminated} . '",' . - $self->{option_results}->{container} . ',' . - $self->{option_results}->{pod} . - $self->{extra_filter} . '}, "__name__", "terminated", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{terminated_reason} . '",' . - $self->{option_results}->{container} . ',' . - $self->{option_results}->{pod} . - $self->{extra_filter} . '}, "__name__", "terminated_reason", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{waiting} . '",' . - $self->{option_results}->{container} . ',' . - $self->{option_results}->{pod} . - $self->{extra_filter} . '}, "__name__", "waiting", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{waiting_reason} . '",' . - $self->{option_results}->{container} . ',' . - $self->{option_results}->{pod} . - $self->{extra_filter} . '}, "__name__", "waiting_reason", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{restarts} . '",' . - $self->{option_results}->{container} . ',' . - $self->{option_results}->{pod} . - $self->{extra_filter} . '}, "__name__", "restarts", "", "")' ]); + my $results = $options{custom}->query( + queries => [ + 'label_replace({__name__=~"' . $self->{metrics}->{ready} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $self->{extra_filter} . '}, "__name__", "ready", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{running} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $self->{extra_filter} . '}, "__name__", "running", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{terminated} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $self->{extra_filter} . '}, "__name__", "terminated", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{terminated_reason} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $self->{extra_filter} . '}, "__name__", "terminated_reason", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{waiting} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $self->{extra_filter} . '}, "__name__", "waiting", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{waiting_reason} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $self->{extra_filter} . '}, "__name__", "waiting_reason", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{restarts} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $self->{extra_filter} . '}, "__name__", "restarts", "", "")' + ] + ); foreach my $result (@{$results}) { next if (!defined($result->{metric}->{$self->{labels}->{pod}}) || !defined($result->{metric}->{$self->{labels}->{container}})); diff --git a/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm b/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm index bd3c20c44..749d86f88 100644 --- a/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm @@ -29,25 +29,48 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_perfdata { my ($self, %options) = @_; - my $extra_label = ''; - if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { - $extra_label .= '_' . $self->{result_values}->{display}; - } - - $self->{output}->perfdata_add(label => 'desired' . $extra_label, - value => $self->{result_values}->{desired}); - $self->{output}->perfdata_add(label => 'current' . $extra_label, - value => $self->{result_values}->{current}); - $self->{output}->perfdata_add(label => 'available' . $extra_label, - value => $self->{result_values}->{available}); - $self->{output}->perfdata_add(label => 'unavailable' . $extra_label, - value => $self->{result_values}->{unavailable}); - $self->{output}->perfdata_add(label => 'up_to_date' . $extra_label, - value => $self->{result_values}->{up_to_date}); - $self->{output}->perfdata_add(label => 'ready' . $extra_label, - value => $self->{result_values}->{ready}); - $self->{output}->perfdata_add(label => 'misscheduled' . $extra_label, - value => $self->{result_values}->{misscheduled}); + $self->{output}->perfdata_add( + label => 'desired', + nlabel => 'kubernetes.daemonset.nodes.desired.count', + value => $self->{result_values}->{desired}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'current', + nlabel => 'kubernetes.daemonset.nodes.current.count', + value => $self->{result_values}->{current}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'available', + nlabel => 'kubernetes.daemonset.nodes.available.count', + value => $self->{result_values}->{available}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'unavailable', + nlabel => 'kubernetes.daemonset.nodes.unavailable.count', + value => $self->{result_values}->{unavailable}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'up_to_date', + nlabel => 'kubernetes.daemonset.nodes.uptodate.count', + value => $self->{result_values}->{up_to_date}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'ready', + nlabel => 'kubernetes.daemonset.nodes.ready.count', + value => $self->{result_values}->{ready}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'misscheduled', + nlabel => 'kubernetes.daemonset.nodes.misscheduled.count', + value => $self->{result_values}->{misscheduled}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); } sub custom_status_output { @@ -112,14 +135,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "daemonset:s" => { name => 'daemonset', default => 'daemonset=~".*"' }, - "warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' }, - "critical-status:s" => { name => 'critical_status', default => '%{available} < %{desired}' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "metric-overload:s@" => { name => 'metric_overload' }, - }); + $options{options}->add_options(arguments => { + "daemonset:s" => { name => 'daemonset', default => 'daemonset=~".*"' }, + "warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' }, + "critical-status:s" => { name => 'critical_status', default => '%{available} < %{desired}' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "metric-overload:s@" => { name => 'metric_overload' }, + }); return $self; } @@ -164,27 +186,31 @@ sub manage_selection { $self->{daemonsets} = {}; - my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{desired} . '",' . - $self->{option_results}->{daemonset} . - $self->{extra_filter} . '}, "__name__", "desired", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{current} . '",' . - $self->{option_results}->{daemonset} . - $self->{extra_filter} . '}, "__name__", "current", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{available} . '",' . - $self->{option_results}->{daemonset} . - $self->{extra_filter} . '}, "__name__", "available", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{unavailable} . '",' . - $self->{option_results}->{daemonset} . - $self->{extra_filter} . '}, "__name__", "unavailable", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{up_to_date} . '",' . - $self->{option_results}->{daemonset} . - $self->{extra_filter} . '}, "__name__", "up_to_date", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{ready} . '",' . - $self->{option_results}->{daemonset} . - $self->{extra_filter} . '}, "__name__", "ready", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{misscheduled} . '",' . - $self->{option_results}->{daemonset} . - $self->{extra_filter} . '}, "__name__", "misscheduled", "", "")' ]); + my $results = $options{custom}->query( + queries => [ + 'label_replace({__name__=~"' . $self->{metrics}->{desired} . '",' . + $self->{option_results}->{daemonset} . + $self->{extra_filter} . '}, "__name__", "desired", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{current} . '",' . + $self->{option_results}->{daemonset} . + $self->{extra_filter} . '}, "__name__", "current", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{available} . '",' . + $self->{option_results}->{daemonset} . + $self->{extra_filter} . '}, "__name__", "available", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{unavailable} . '",' . + $self->{option_results}->{daemonset} . + $self->{extra_filter} . '}, "__name__", "unavailable", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{up_to_date} . '",' . + $self->{option_results}->{daemonset} . + $self->{extra_filter} . '}, "__name__", "up_to_date", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{ready} . '",' . + $self->{option_results}->{daemonset} . + $self->{extra_filter} . '}, "__name__", "ready", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{misscheduled} . '",' . + $self->{option_results}->{daemonset} . + $self->{extra_filter} . '}, "__name__", "misscheduled", "", "")' + ] + ); foreach my $result (@{$results}) { $self->{daemonsets}->{$result->{metric}->{$self->{labels}->{daemonset}}}->{display} = $result->{metric}->{$self->{labels}->{daemonset}}; diff --git a/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm b/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm index 27b17c37a..245f7d97f 100644 --- a/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm @@ -29,21 +29,36 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_perfdata { my ($self, %options) = @_; - my $extra_label = ''; - if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { - $extra_label .= '_' . $self->{result_values}->{display}; - } - - $self->{output}->perfdata_add(label => 'desired' . $extra_label, - value => $self->{result_values}->{desired}); - $self->{output}->perfdata_add(label => 'current' . $extra_label, - value => $self->{result_values}->{current}); - $self->{output}->perfdata_add(label => 'available' . $extra_label, - value => $self->{result_values}->{available}); - $self->{output}->perfdata_add(label => 'unavailable' . $extra_label, - value => $self->{result_values}->{unavailable}); - $self->{output}->perfdata_add(label => 'up_to_date' . $extra_label, - value => $self->{result_values}->{up_to_date}); + $self->{output}->perfdata_add( + label => 'desired', + nlabel => 'kubernetes.deployment.replicas.desired.count', + value => $self->{result_values}->{desired}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'current', + nlabel => 'kubernetes.deployment.replicas.current.count', + value => $self->{result_values}->{current}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'available', + nlabel => 'kubernetes.deployment.replicas.available.count', + value => $self->{result_values}->{available}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'unavailable', + nlabel => 'kubernetes.deployment.replicas.unavailable.count', + value => $self->{result_values}->{unavailable}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'up_to_date', + nlabel => 'kubernetes.deployment.replicas.uptodate.count', + value => $self->{result_values}->{up_to_date}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); } sub custom_status_output { @@ -103,14 +118,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "deployment:s" => { name => 'deployment', default => 'deployment=~".*"' }, - "warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' }, - "critical-status:s" => { name => 'critical_status', default => '%{available} < %{desired}' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "metric-overload:s@" => { name => 'metric_overload' }, - }); + $options{options}->add_options(arguments => { + "deployment:s" => { name => 'deployment', default => 'deployment=~".*"' }, + "warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' }, + "critical-status:s" => { name => 'critical_status', default => '%{available} < %{desired}' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "metric-overload:s@" => { name => 'metric_overload' }, + }); return $self; } @@ -153,21 +167,25 @@ sub manage_selection { $self->{deployments} = {}; - my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{desired} . '",' . - $self->{option_results}->{deployment} . - $self->{extra_filter} . '}, "__name__", "desired", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{current} . '",' . - $self->{option_results}->{deployment} . - $self->{extra_filter} . '}, "__name__", "current", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{available} . '",' . - $self->{option_results}->{deployment} . - $self->{extra_filter} . '}, "__name__", "available", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{unavailable} . '",' . - $self->{option_results}->{deployment} . - $self->{extra_filter} . '}, "__name__", "unavailable", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{up_to_date} . '",' . - $self->{option_results}->{deployment} . - $self->{extra_filter} . '}, "__name__", "up_to_date", "", "")' ]); + my $results = $options{custom}->query( + queries => [ + 'label_replace({__name__=~"' . $self->{metrics}->{desired} . '",' . + $self->{option_results}->{deployment} . + $self->{extra_filter} . '}, "__name__", "desired", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{current} . '",' . + $self->{option_results}->{deployment} . + $self->{extra_filter} . '}, "__name__", "current", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{available} . '",' . + $self->{option_results}->{deployment} . + $self->{extra_filter} . '}, "__name__", "available", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{unavailable} . '",' . + $self->{option_results}->{deployment} . + $self->{extra_filter} . '}, "__name__", "unavailable", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{up_to_date} . '",' . + $self->{option_results}->{deployment} . + $self->{extra_filter} . '}, "__name__", "up_to_date", "", "")' + ] + ); foreach my $result (@{$results}) { $self->{deployments}->{$result->{metric}->{$self->{labels}->{deployment}}}->{display} = $result->{metric}->{$self->{labels}->{deployment}}; diff --git a/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm b/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm index def61001d..b838ecb6a 100644 --- a/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm @@ -46,11 +46,12 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_init => 'skip_global', cb_prefix_output => 'prefix_global_output' }, - { name => 'namespaces', type => 1, cb_prefix_output => 'prefix_namespace_output', message_multiple => 'All namespaces status are ok', skipped_code => { -11 => 1 } }, + { name => 'namespaces', type => 1, cb_prefix_output => 'prefix_namespace_output', + message_multiple => 'All namespaces status are ok', skipped_code => { -11 => 1 } }, ]; $self->{maps_counters}->{global} = [ - { label => 'active', set => { + { label => 'active', nlabel => 'kubernetes.namespace.active.count', set => { key_values => [ { name => 'active' } ], output_template => 'Active : %d', perfdatas => [ @@ -59,7 +60,7 @@ sub set_counters { ], } }, - { label => 'terminating', set => { + { label => 'terminating', nlabel => 'kubernetes.namespace.terminating.count', set => { key_values => [ { name => 'terminating' } ], output_template => 'Terminating : %d', perfdatas => [ @@ -105,15 +106,14 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "namespace:s" => { name => 'namespace', default => 'namespace=~".*"' }, - "phase:s" => { name => 'phase', default => 'phase=~".*"' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{phase} !~ /Active/' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "metric-overload:s@" => { name => 'metric_overload' }, - }); + $options{options}->add_options(arguments => { + "namespace:s" => { name => 'namespace', default => 'namespace=~".*"' }, + "phase:s" => { name => 'phase', default => 'phase=~".*"' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{phase} !~ /Active/' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "metric-overload:s@" => { name => 'metric_overload' }, + }); return $self; } @@ -153,9 +153,13 @@ sub manage_selection { $self->{global} = { active => 0, terminating => 0 }; $self->{namespaces} = {}; - my $results = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{status} . '",' . - $self->{option_results}->{namespace} . - $self->{extra_filter} . '}' ]); + my $results = $options{custom}->query( + queries => [ + '{__name__=~"' . $self->{metrics}->{status} . '",' . + $self->{option_results}->{namespace} . + $self->{extra_filter} . '}' + ] + ); foreach my $result (@{$results}) { $self->{namespaces}->{$result->{metric}->{$self->{labels}->{namespace}}}->{display} = $result->{metric}->{$self->{labels}->{namespace}}; diff --git a/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm b/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm index 6f6f9b592..af9dc4a9f 100644 --- a/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm @@ -49,8 +49,7 @@ sub custom_usage_perfdata { my $label = 'allocated_pods'; my $value_perf = $self->{result_values}->{allocated}; - my $extra_label = ''; - $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{allocatable}; @@ -58,11 +57,13 @@ sub custom_usage_perfdata { } $self->{output}->perfdata_add( - label => $label . $extra_label, + label => $label, + nlabel => 'kubernetes.pods.allocated.count', value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{allocatable} + 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), + min => 0, max => $self->{result_values}->{allocatable}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, ); } @@ -75,23 +76,8 @@ sub custom_usage_threshold { $threshold_value = $self->{result_values}->{prct_allocated}; } $exit = $self->{perfdata}->threshold_check( - value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, - { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ] - ); - return $exit; -} - -sub custom_usage_threshold { - my ($self, %options) = @_; - - my ($exit, $threshold_value); - $threshold_value = $self->{result_values}->{allocated}; - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $threshold_value = $self->{result_values}->{prct_allocated}; - } - $exit = $self->{perfdata}->threshold_check( - value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, - { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ] + value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, + { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ] ); return $exit; } @@ -160,15 +146,14 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "node:s" => { name => 'node', default => 'node=~".*"' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Ready/ || %{schedulable} =~ /false/' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "metric-overload:s@" => { name => 'metric_overload' }, - "units:s" => { name => 'units', default => '' }, - }); + $options{options}->add_options(arguments => { + "node:s" => { name => 'node', default => 'node=~".*"' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Ready/ || %{schedulable} =~ /false/' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "metric-overload:s@" => { name => 'metric_overload' }, + "units:s" => { name => 'units', default => '' }, + }); return $self; } @@ -211,22 +196,26 @@ sub manage_selection { $self->{nodes} = {}; - my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{status} . '",' . - $self->{option_results}->{node} . ',' . - 'status="true"' . - $self->{extra_filter} . '}, "__name__", "status", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{unschedulable} . '",' . - $self->{option_results}->{node} . - $self->{extra_filter} . '}, "__name__", "unschedulable", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{capacity} . '",' . - $self->{option_results}->{node} . - $self->{extra_filter} . '}, "__name__", "capacity", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{allocatable} . '",' . - $self->{option_results}->{node} . - $self->{extra_filter} . '}, "__name__", "allocatable", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{allocated} . '",' . - $self->{option_results}->{node} . - $self->{extra_filter} . '}, "__name__", "allocated", "", "")' ]); + my $results = $options{custom}->query( + queries => [ + 'label_replace({__name__=~"' . $self->{metrics}->{status} . '",' . + $self->{option_results}->{node} . ',' . + 'status="true"' . + $self->{extra_filter} . '}, "__name__", "status", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{unschedulable} . '",' . + $self->{option_results}->{node} . + $self->{extra_filter} . '}, "__name__", "unschedulable", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{capacity} . '",' . + $self->{option_results}->{node} . + $self->{extra_filter} . '}, "__name__", "capacity", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{allocatable} . '",' . + $self->{option_results}->{node} . + $self->{extra_filter} . '}, "__name__", "allocatable", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{allocated} . '",' . + $self->{option_results}->{node} . + $self->{extra_filter} . '}, "__name__", "allocated", "", "")' + ] + ); foreach my $result (@{$results}) { $self->{nodes}->{$result->{metric}->{$self->{labels}->{node}}}->{display} = $result->{metric}->{$self->{labels}->{node}};