mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 15:44:21 +02:00
+ WIP perfdata extend system
This commit is contained in:
parent
8b8ed15ec3
commit
29e8bce989
@ -402,6 +402,43 @@ sub convert_bytes {
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub parse_threshold {
|
||||||
|
my ($perf) = @_;
|
||||||
|
|
||||||
|
$perf = trim($perf);
|
||||||
|
|
||||||
|
my $arobase = 0;
|
||||||
|
my $infinite_neg = 0;
|
||||||
|
my $infinite_pos = 0;
|
||||||
|
my $value_start = "";
|
||||||
|
my $value_end = "";
|
||||||
|
my $global_status = 1;
|
||||||
|
|
||||||
|
if ($perf =~ /^(\@?)((?:~|(?:\+|-)?\d+(?:[\.,]\d+)?|):)?((?:\+|-)?\d+(?:[\.,]\d+)?)?$/) {
|
||||||
|
$value_start = $2 if (defined($2));
|
||||||
|
$value_end = $3 if (defined($3));
|
||||||
|
$arobase = 1 if (defined($1) && $1 eq '@');
|
||||||
|
$value_start =~ s/[\+:]//g;
|
||||||
|
$value_end =~ s/\+//;
|
||||||
|
if ($value_end eq '') {
|
||||||
|
$value_end = 1e500;
|
||||||
|
$infinite_pos = 1;
|
||||||
|
}
|
||||||
|
$value_start = 0 if ($value_start eq '');
|
||||||
|
$value_start =~ s/,/\./;
|
||||||
|
$value_end =~ s/,/\./;
|
||||||
|
|
||||||
|
if ($value_start eq '~') {
|
||||||
|
$value_start = -1e500;
|
||||||
|
$infinite_neg = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$global_status = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($global_status, $value_start, $value_end, $arobase, $infinite_neg, $infinite_pos);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -123,15 +123,7 @@ sub check_options {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($self->{option_results}->{change_perfdata})) {
|
$self->load_perfdata_extend_args();
|
||||||
foreach (@{$self->{option_results}->{change_perfdata}}) {
|
|
||||||
if (! /^(.+?),(.+)$/) {
|
|
||||||
$self->add_option_msg(short_msg => "Wrong change-perfdata option '" . $_ . "' (syntax: match,substitute)");
|
|
||||||
$self->option_exit();
|
|
||||||
}
|
|
||||||
$self->{change_perfdata}->{$1} = $2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add_option_msg {
|
sub add_option_msg {
|
||||||
@ -194,36 +186,6 @@ sub perfdata_add {
|
|||||||
push @{$self->{perfdatas}}, $perfdata;
|
push @{$self->{perfdatas}}, $perfdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub change_perfdatas {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
if ($self->{option_results}->{change_perfdata}) {
|
|
||||||
foreach (@{$self->{perfdatas}}) {
|
|
||||||
foreach my $filter (keys %{$self->{change_perfdata}}) {
|
|
||||||
if ($_->{label} =~ /$filter/) {
|
|
||||||
eval "\$_->{label} =~ s{$filter}{$self->{change_perfdata}->{$filter}}";
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return if ($self->{explode_perfdata_total} == 0);
|
|
||||||
foreach (@{$self->{perfdatas}}) {
|
|
||||||
next if ($_->{max} eq '');
|
|
||||||
if ($self->{explode_perfdata_total} == 2) {
|
|
||||||
$self->perfdata_add(label => $_->{label} . '_max', value => $_->{max});
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
foreach my $regexp (keys %{$self->{explode_perfdatas}}) {
|
|
||||||
if ($_->{label} =~ /$regexp/) {
|
|
||||||
$self->perfdata_add(label => $self->{explode_perfdatas}->{$regexp}, value => $_->{max});
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub range_perfdata {
|
sub range_perfdata {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
@ -746,6 +708,61 @@ sub is_disco_show {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --add-perfdata=used,,scale(auto)
|
||||||
|
# --add-perfdata=used,,scale(MB)
|
||||||
|
# --add-perfdata=traffic_in,,scale(Mbps),mbps
|
||||||
|
# --add-perfdata=used,,percent()
|
||||||
|
# --add-perfdata=perfx,,math(perfx+10-100)
|
||||||
|
# --add-perfdata=free,used,used()
|
||||||
|
# --add-perfdata=used,free,free()
|
||||||
|
# ^([KMGTP])?(B|b|bps|\/s|auto)$
|
||||||
|
|
||||||
|
# parse_threshold est dans misc maintenant.
|
||||||
|
|
||||||
|
sub load_perfdata_extend_args {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
if (defined($self->{option_results}->{change_perfdata})) {
|
||||||
|
foreach (@{$self->{option_results}->{change_perfdata}}) {
|
||||||
|
if (! /^(.+?),(.+)$/) {
|
||||||
|
$self->add_option_msg(short_msg => "Wrong change-perfdata option '" . $_ . "' (syntax: match,substitute)");
|
||||||
|
$self->option_exit();
|
||||||
|
}
|
||||||
|
$self->{change_perfdata}->{$1} = $2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub change_perfdatas {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
if ($self->{option_results}->{change_perfdata}) {
|
||||||
|
foreach (@{$self->{perfdatas}}) {
|
||||||
|
foreach my $filter (keys %{$self->{change_perfdata}}) {
|
||||||
|
if ($_->{label} =~ /$filter/) {
|
||||||
|
eval "\$_->{label} =~ s{$filter}{$self->{change_perfdata}->{$filter}}";
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return if ($self->{explode_perfdata_total} == 0);
|
||||||
|
foreach (@{$self->{perfdatas}}) {
|
||||||
|
next if ($_->{max} eq '');
|
||||||
|
if ($self->{explode_perfdata_total} == 2) {
|
||||||
|
$self->perfdata_add(label => $_->{label} . '_max', value => $_->{max});
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
foreach my $regexp (keys %{$self->{explode_perfdatas}}) {
|
||||||
|
if ($_->{label} =~ /$regexp/) {
|
||||||
|
$self->perfdata_add(label => $self->{explode_perfdatas}->{$regexp}, value => $_->{max});
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -22,6 +22,7 @@ package centreon::plugins::perfdata;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use centreon::plugins::misc;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -82,7 +83,8 @@ sub threshold_validate {
|
|||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
($status, $self->{threshold_label}->{$options{label}}->{start}, $self->{threshold_label}->{$options{label}}->{end}, $self->{threshold_label}->{$options{label}}->{arobase}, $self->{threshold_label}->{$options{label}}->{infinite_neg}, $self->{threshold_label}->{$options{label}}->{infinite_pos}) = $self->parse_threshold($options{value});
|
($status, $self->{threshold_label}->{$options{label}}->{start}, $self->{threshold_label}->{$options{label}}->{end}, $self->{threshold_label}->{$options{label}}->{arobase}, $self->{threshold_label}->{$options{label}}->{infinite_neg}, $self->{threshold_label}->{$options{label}}->{infinite_pos}) =
|
||||||
|
centreon::plugins::misc::parse_threshold($options{value});
|
||||||
|
|
||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
@ -113,43 +115,6 @@ sub trim {
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parse_threshold {
|
|
||||||
my ($self, $perf) = @_;
|
|
||||||
|
|
||||||
$perf = $self->trim($perf);
|
|
||||||
|
|
||||||
my $arobase = 0;
|
|
||||||
my $infinite_neg = 0;
|
|
||||||
my $infinite_pos = 0;
|
|
||||||
my $value_start = "";
|
|
||||||
my $value_end = "";
|
|
||||||
my $global_status = 1;
|
|
||||||
|
|
||||||
if ($perf =~ /^(\@?)((?:~|(?:\+|-)?\d+(?:[\.,]\d+)?|):)?((?:\+|-)?\d+(?:[\.,]\d+)?)?$/) {
|
|
||||||
$value_start = $2 if (defined($2));
|
|
||||||
$value_end = $3 if (defined($3));
|
|
||||||
$arobase = 1 if (defined($1) && $1 eq '@');
|
|
||||||
$value_start =~ s/[\+:]//g;
|
|
||||||
$value_end =~ s/\+//;
|
|
||||||
if ($value_end eq '') {
|
|
||||||
$value_end = 1e500;
|
|
||||||
$infinite_pos = 1;
|
|
||||||
}
|
|
||||||
$value_start = 0 if ($value_start eq '');
|
|
||||||
$value_start =~ s/,/\./;
|
|
||||||
$value_end =~ s/,/\./;
|
|
||||||
|
|
||||||
if ($value_start eq '~') {
|
|
||||||
$value_start = -1e500;
|
|
||||||
$infinite_neg = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$global_status = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ($global_status, $value_start, $value_end, $arobase, $infinite_neg, $infinite_pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub change_bytes {
|
sub change_bytes {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
my $divide = defined($options{network}) ? 1000 : 1024;
|
my $divide = defined($options{network}) ? 1000 : 1024;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user