From aa4608e30d6a59ccd6dc3cc257e094a80a8f3a63 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 18 Apr 2019 10:17:44 +0200 Subject: [PATCH] WIP: new perfdata system --- .../apps/vmware/connector/mode/datastoreusage.pm | 2 +- .../apps/vmware/connector/mode/memoryhost.pm | 2 +- .../apps/vmware/connector/mode/memoryvm.pm | 2 +- .../common/cisco/standard/snmp/mode/memory.pm | 2 +- .../centreon/plugins/templates/counter.pm | 8 +++++--- centreon-plugins/centreon/plugins/values.pm | 8 ++------ .../huawei/hmm/snmp/mode/components/cpu.pm | 16 +++++++++------- .../hmm/snmp/mode/components/temperature.pm | 15 +++++++++------ centreon-plugins/snmp_standard/mode/storage.pm | 2 +- .../storage/qnap/snmp/mode/volumeusage.pm | 2 +- 10 files changed, 31 insertions(+), 28 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm b/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm index b4ce80393..adc75e5c0 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm @@ -43,7 +43,7 @@ sub custom_status_calc { sub custom_usage_perfdata { my ($self, %options) = @_; - my ($label, $nlabel) = ('used', $self->{label}); + my ($label, $nlabel) = ('used', $self->{nlabel}); my $value_perf = $self->{result_values}->{used}; if (defined($self->{instance_mode}->{option_results}->{free})) { ($label, $nlabel) = ('free', 'datastore.space.free.bytes'); diff --git a/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm b/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm index ec37c1c4d..86f55708b 100644 --- a/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm @@ -43,7 +43,7 @@ sub custom_status_calc { sub custom_usage_perfdata { my ($self, %options) = @_; - my ($label, $nlabel) = ('used', $self->{label}); + my ($label, $nlabel) = ('used', $self->{nlabel}); my $value_perf = $self->{result_values}->{used}; if (defined($self->{instance_mode}->{option_results}->{free})) { ($label, $nlabel) = ('free', 'host.memory.free.bytes'); diff --git a/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm b/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm index 354beb0b9..7e420228f 100644 --- a/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm @@ -44,7 +44,7 @@ sub custom_status_calc { sub custom_usage_perfdata { my ($self, %options) = @_; - my ($label, $nlabel) = ('used', $self->{label}); + my ($label, $nlabel) = ('used', $self->{nlabel}); my $value_perf = $self->{result_values}->{used}; if (defined($self->{instance_mode}->{option_results}->{free})) { ($label, $nlabel) = ('free', 'vm.memory.free.bytes'); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm index 9311fc202..7bb996c40 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm @@ -28,7 +28,7 @@ use warnings; sub custom_usage_perfdata { my ($self, %options) = @_; - my ($label, $nlabel, $unit, $total) = ('used', $self->{label}, '%', 100); + my ($label, $nlabel, $unit, $total) = ('used', $self->{nlabel}, '%', 100); my $value_perf = $self->{result_values}->{prct_used}; my %total_options = (); if ($self->{result_values}->{total} != -1) { diff --git a/centreon-plugins/centreon/plugins/templates/counter.pm b/centreon-plugins/centreon/plugins/templates/counter.pm index 845cae685..3ca1c6c49 100644 --- a/centreon-plugins/centreon/plugins/templates/counter.pm +++ b/centreon-plugins/centreon/plugins/templates/counter.pm @@ -146,9 +146,11 @@ sub new { }); } } - $_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value}, - output => $self->{output}, perfdata => $self->{perfdata}, - label => $label, thlabel => $thlabel); + $_->{obj} = centreon::plugins::values->new( + statefile => $self->{statefile_value}, + output => $self->{output}, perfdata => $self->{perfdata}, + label => $_->{label}, nlabel => $_->{nlabel}, thlabel => $thlabel, + ); $_->{obj}->set(%{$_->{set}}); } } diff --git a/centreon-plugins/centreon/plugins/values.pm b/centreon-plugins/centreon/plugins/values.pm index 432602865..d72e44e23 100644 --- a/centreon-plugins/centreon/plugins/values.pm +++ b/centreon-plugins/centreon/plugins/values.pm @@ -35,6 +35,7 @@ sub new { $self->{output} = $options{output}; $self->{perfdata} = $options{perfdata}; $self->{label} = $options{label}; + $self->{nlabel} = $options{nlabel}; $self->{thlabel} = defined($options{thlabel}) ? $options{thlabel} : $self->{label}; $self->{perfdatas} = []; @@ -211,16 +212,11 @@ sub perfdata { $instances = $instance; } } - - my %nlabel_option = (); - if ($self->{output}->use_new_perfdata()) { - $nlabel_option{nlabel} = $self->{label}; - } $self->{output}->perfdata_add( label => $label, instances => $instances, - %nlabel_option, + nlabel => $self->{nlabel}, unit => $perf->{unit}, value => $cast_int == 1 ? int($self->{result_values}->{$perf->{value}}) : sprintf($template, $self->{result_values}->{$perf->{value}}), warning => $self->{perfdata}->get_perfdata_for_output(label => $warn, total => $th_total, cast_int => $cast_int), diff --git a/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/components/cpu.pm b/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/components/cpu.pm index f83deaed9..0a8183e16 100644 --- a/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/components/cpu.pm +++ b/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/components/cpu.pm @@ -78,12 +78,14 @@ sub check { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Cpu '%s' temperature is %s celsius degrees", $result->{bladeCPUMark}, $result->{bladeCPUTemperature})); } - $self->{output}->perfdata_add(label => 'temperature_' . $result->{bladeCPUMark}, unit => 'C', - value => $result->{bladeCPUTemperature}, - warning => $warn, - critical => $crit, - min => 0 - ); + $self->{output}->perfdata_add( + label => 'temperature', unit => 'C', + nlabel => 'hardware.cpu.temperature.celsius', + instances => $result->{bladeCPUMark}, + value => $result->{bladeCPUTemperature}, + warning => $warn, + critical => $crit, min => 0 + ); } $self->{output}->output_add(long_msg => sprintf("Cpu '%s' status is '%s' [instance = %s]", @@ -98,4 +100,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/components/temperature.pm index 120ae57b4..89dae2e8f 100644 --- a/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/server/huawei/hmm/snmp/mode/components/temperature.pm @@ -64,12 +64,15 @@ sub check { short_msg => sprintf("Temperature '%s' is '%s' celsius degrees", $result->{bladeTemperatureIndex}, $result->{bladeTemperatureReading})); } - $self->{output}->perfdata_add(label => 'temperature_' . $result->{bladeTemperatureIndex}, unit => 'C', - value => $result->{bladeTemperatureReading}, - warning => $warn, - critical => $crit - ); + $self->{output}->perfdata_add( + label => 'temperature', unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => $result->{bladeTemperatureIndex}, + value => $result->{bladeTemperatureReading}, + warning => $warn, + critical => $crit + ); } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/snmp_standard/mode/storage.pm b/centreon-plugins/snmp_standard/mode/storage.pm index f862d6c41..8ea8588cf 100644 --- a/centreon-plugins/snmp_standard/mode/storage.pm +++ b/centreon-plugins/snmp_standard/mode/storage.pm @@ -72,7 +72,7 @@ my %storage_types_manage = ( sub custom_usage_perfdata { my ($self, %options) = @_; - my ($label, $nlabel) = ('used', $self->{label}); + my ($label, $nlabel) = ('used', $self->{nlabel}); my $value_perf = $self->{result_values}->{used}; if (defined($self->{instance_mode}->{option_results}->{free})) { ($label, $nlabel) = ('free', 'storage.space.free.bytes'); diff --git a/centreon-plugins/storage/qnap/snmp/mode/volumeusage.pm b/centreon-plugins/storage/qnap/snmp/mode/volumeusage.pm index d075a24d6..940bae16d 100644 --- a/centreon-plugins/storage/qnap/snmp/mode/volumeusage.pm +++ b/centreon-plugins/storage/qnap/snmp/mode/volumeusage.pm @@ -28,7 +28,7 @@ use warnings; sub custom_usage_perfdata { my ($self, %options) = @_; - my ($label, $nlabel) = ('used', $self->{label}); + my ($label, $nlabel) = ('used', $self->{nlabel}); my $value_perf = $self->{result_values}->{used}; if (defined($self->{instance_mode}->{option_results}->{free})) { ($label, $nlabel) = ('free', 'memory.free.bytes');