add output class method + openmetrics timestamp
This commit is contained in:
parent
c1886ea3cc
commit
3bdb3025c6
|
@ -59,6 +59,9 @@ sub new {
|
||||||
|
|
||||||
$self->{option_msg} = [];
|
$self->{option_msg} = [];
|
||||||
|
|
||||||
|
$self->{nodisplay} = 0;
|
||||||
|
$self->{noexit_die} = 0;
|
||||||
|
|
||||||
$self->{is_output_xml} = 0;
|
$self->{is_output_xml} = 0;
|
||||||
$self->{is_output_json} = 0;
|
$self->{is_output_json} = 0;
|
||||||
$self->{errors} = {OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, PENDING => 4};
|
$self->{errors} = {OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, PENDING => 4};
|
||||||
|
@ -376,6 +379,12 @@ sub output_xml {
|
||||||
sub output_openmetrics {
|
sub output_openmetrics {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
centreon::plugins::misc::mymodule_load(
|
||||||
|
output => $self->{output}, module => 'Time::HiRes',
|
||||||
|
error_msg => "Cannot load module 'Time::HiRes'."
|
||||||
|
);
|
||||||
|
|
||||||
|
my $time_ms = int(Time::HiRes::time() * 1000);
|
||||||
$self->change_perfdata();
|
$self->change_perfdata();
|
||||||
foreach my $perf (@{$self->{perfdatas}}) {
|
foreach my $perf (@{$self->{perfdatas}}) {
|
||||||
next if (defined($self->{option_results}->{filter_perfdata}) &&
|
next if (defined($self->{option_results}->{filter_perfdata}) &&
|
||||||
|
@ -396,7 +405,7 @@ sub output_openmetrics {
|
||||||
}
|
}
|
||||||
$bucket .= '}';
|
$bucket .= '}';
|
||||||
|
|
||||||
print $label . $bucket . ' ' . $perf->{value} . "\n";
|
print $label . $bucket . ' ' . $perf->{value} . ' ' . $time_ms . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,6 +457,7 @@ sub output_txt {
|
||||||
my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
|
my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
|
||||||
my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
|
my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
|
||||||
|
|
||||||
|
return if ($self->{nodisplay} == 1);
|
||||||
if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) {
|
if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) {
|
||||||
$self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET});
|
$self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET});
|
||||||
}
|
}
|
||||||
|
@ -573,8 +583,10 @@ sub option_exit {
|
||||||
|
|
||||||
sub exit {
|
sub exit {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
# $options{exit_litteral} = exit
|
|
||||||
|
|
||||||
|
if ($self->{noexit_die} == 1) {
|
||||||
|
die 'exit';
|
||||||
|
}
|
||||||
if (defined($options{exit_litteral})) {
|
if (defined($options{exit_litteral})) {
|
||||||
exit $self->{errors}->{uc($options{exit_litteral})};
|
exit $self->{errors}->{uc($options{exit_litteral})};
|
||||||
}
|
}
|
||||||
|
@ -770,6 +782,15 @@ sub to_utf8 {
|
||||||
return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, $self->{perlqq}));
|
return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, $self->{perlqq}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub parameter {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
if (defined($options{attr})) {
|
||||||
|
$self->{$options{attr}} = $options{value};
|
||||||
|
}
|
||||||
|
return $self->{$options{attr}};
|
||||||
|
}
|
||||||
|
|
||||||
sub add_disco_entry {
|
sub add_disco_entry {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue