mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 15:44:21 +02:00
Fix #1388
This commit is contained in:
parent
7d4b4bb288
commit
d0e8f2ae5e
@ -38,6 +38,7 @@ sub new {
|
|||||||
'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' },
|
||||||
'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' },
|
||||||
@ -86,7 +87,7 @@ sub add_data {
|
|||||||
foreach (['oid_type', 'gauge'], ['counter_per_seconds'], ['format', 'current value is %s'],
|
foreach (['oid_type', 'gauge'], ['counter_per_seconds'], ['format', 'current value is %s'],
|
||||||
['format_custom', ''], ['format_scale'],
|
['format_custom', ''], ['format_scale'],
|
||||||
['perfdata_unit', ''], ['perfdata_name', 'value'],
|
['perfdata_unit', ''], ['perfdata_name', 'value'],
|
||||||
['perfdata_min', ''], ['perfdata_max', '']) {
|
['perfdata_min', ''], ['perfdata_max', ''], ['extracted_pattern', '']) {
|
||||||
if (defined($options{data}->{$_->[0]})) {
|
if (defined($options{data}->{$_->[0]})) {
|
||||||
$entry->{$_->[0]} = $options{data}->{$_->[0]};
|
$entry->{$_->[0]} = $options{data}->{$_->[0]};
|
||||||
} elsif (defined($_->[1])) {
|
} elsif (defined($_->[1])) {
|
||||||
@ -108,8 +109,10 @@ sub check_options {
|
|||||||
|
|
||||||
($self->{entries}, $self->{oids}) = ([], []);
|
($self->{entries}, $self->{oids}) = ([], []);
|
||||||
if (defined($self->{option_results}->{config_json}) && $self->{option_results}->{config_json} ne '') {
|
if (defined($self->{option_results}->{config_json}) && $self->{option_results}->{config_json} ne '') {
|
||||||
centreon::plugins::misc::mymodule_load(module => 'JSON',
|
centreon::plugins::misc::mymodule_load(
|
||||||
error_msg => "Cannot load module 'JSON'.");
|
module => 'JSON',
|
||||||
|
error_msg => "Cannot load module 'JSON'."
|
||||||
|
);
|
||||||
my $json = JSON->new;
|
my $json = JSON->new;
|
||||||
my $content;
|
my $content;
|
||||||
eval {
|
eval {
|
||||||
@ -143,11 +146,27 @@ sub check_data {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
if (!defined($self->{results}->{$options{entry}->{oid}})) {
|
if (!defined($self->{results}->{$options{entry}->{oid}})) {
|
||||||
$self->{output}->output_add(severity => "UNKNOWN",
|
$self->{output}->output_add(
|
||||||
short_msg => "Cannot find oid:" . $options{entry}->{oid});
|
severity => 'UNKNOWN',
|
||||||
|
short_msg => 'Cannot find oid:' . $options{entry}->{oid}
|
||||||
|
);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $value = $self->{results}->{$options{entry}->{oid}};
|
my $value = $self->{results}->{$options{entry}->{oid}};
|
||||||
|
if (defined($options{entry}->{extracted_pattern}) && $options{entry}->{extracted_pattern} ne '') {
|
||||||
|
if ($value =~ /$options{entry}->{extracted_pattern}/ && defined($1)) {
|
||||||
|
$value = $1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($value !~ /^\d+(\.\d+)?$/) {
|
||||||
|
$self->{output}->output_add(
|
||||||
|
severity => 'UNKNOWN',
|
||||||
|
short_msg => 'oid value is not numeric (' . $value . ')'
|
||||||
|
);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
if ($options{entry}->{oid_type} =~ /^counter$/i) {
|
if ($options{entry}->{oid_type} =~ /^counter$/i) {
|
||||||
my $old_timestamp = $self->{statefile_cache}->get(name => 'timestamp');
|
my $old_timestamp = $self->{statefile_cache}->get(name => 'timestamp');
|
||||||
my $old_value = $self->{statefile_cache}->get(name => 'value-' . $options{num});
|
my $old_value = $self->{statefile_cache}->get(name => 'value-' . $options{num});
|
||||||
@ -256,6 +275,10 @@ Can be 'counter' also. 'counter' will use a retention file.
|
|||||||
|
|
||||||
Convert counter value on a value per seconds (only with type 'counter').
|
Convert counter value on a value per seconds (only with type 'counter').
|
||||||
|
|
||||||
|
=item B<--extracted-pattern>
|
||||||
|
|
||||||
|
Set pattern to extracted a number.
|
||||||
|
|
||||||
=item B<--format>
|
=item B<--format>
|
||||||
|
|
||||||
Output format (Default: 'current value is %s')
|
Output format (Default: 'current value is %s')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user