enh(mode): snmp numeric value output (#2680)

This commit is contained in:
Thibault S 2021-03-26 15:54:53 +01:00 committed by GitHub
parent 3a63f3641d
commit 3869787121
1 changed files with 44 additions and 45 deletions

View File

@ -47,7 +47,7 @@ sub new {
'perfdata-name:s' => { name => 'perfdata_name' }, 'perfdata-name:s' => { name => 'perfdata_name' },
'perfdata-min:s' => { name => 'perfdata_min' }, 'perfdata-min:s' => { name => 'perfdata_min' },
'perfdata-max:s' => { name => 'perfdata_max' }, 'perfdata-max:s' => { name => 'perfdata_max' },
'config-json:s' => { name => 'config_json' }, 'config-json:s' => { name => 'config_json' }
}); });
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
@ -199,10 +199,9 @@ sub check_data {
my $exit = $self->{perfdata}->threshold_check(value => $value, my $exit = $self->{perfdata}->threshold_check(value => $value,
threshold => [ { label => 'critical-' . $options{num}, exit_litteral => 'critical' }, { label => 'warning-' . $options{num}, exit_litteral => 'warning' } ]); threshold => [ { label => 'critical-' . $options{num}, exit_litteral => 'critical' }, { label => 'warning-' . $options{num}, exit_litteral => 'warning' } ]);
if (defined($options{entry}->{format_scale})) { if (defined($options{entry}->{format_scale})) {
my ($value_mod, $value_unit) = $self->{perfdata}->change_bytes(value => $value); my $network = $options{entry}->{format_scale_type} =~ /^network$/i ? { network => 1 } : {};
if ($options{entry}->{format_scale_type} =~ /^network$/i) { my ($value_mod, $value_unit) = $self->{perfdata}->change_bytes(value => $value, %{$network});
($value_mod, $value_unit) = $self->{perfdata}->change_bytes(value => $value, network => 1); $value_unit .= '/s' if (defined($options{entry}->{counter_per_seconds}));
}
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf($options{entry}->{format}, $value_mod . $value_unit)); short_msg => sprintf($options{entry}->{format}, $value_mod . $value_unit));
} else { } else {