WIP: new perfdata system

This commit is contained in:
garnier-quentin 2019-04-18 10:17:44 +02:00
parent ace44c7272
commit 7e1501b21c
10 changed files with 31 additions and 28 deletions

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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) {

View File

@ -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}});
}
}

View File

@ -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),

View File

@ -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;
1;

View File

@ -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;
1;

View File

@ -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');

View File

@ -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');