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

@ -33,21 +33,21 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'oid:s' => { name => 'oid' }, 'oid:s' => { name => 'oid' },
'oid-type:s' => { name => 'oid_type' }, 'oid-type:s' => { name => 'oid_type' },
'counter-per-seconds' => { name => 'counter_per_seconds' }, 'counter-per-seconds' => { name => 'counter_per_seconds' },
'warning:s' => { name => 'warning' }, 'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' }, 'critical:s' => { name => 'critical' },
'extracted-pattern:s' => { name => 'extracted_pattern' }, 'extracted-pattern:s' => { name => 'extracted_pattern' },
'format:s' => { name => 'format' }, 'format:s' => { name => 'format' },
'format-custom:s' => { name => 'format_custom' }, 'format-custom:s' => { name => 'format_custom' },
'format-scale' => { name => 'format_scale' }, 'format-scale' => { name => 'format_scale' },
'format-scale-type:s' => { name => 'format_scale_type' }, 'format-scale-type:s' => { name => 'format_scale_type' },
'perfdata-unit:s' => { name => 'perfdata_unit' }, 'perfdata-unit:s' => { name => 'perfdata_unit' },
'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 {