add output class method + openmetrics timestamp
This commit is contained in:
parent
2afebae79e
commit
c03cf36354
|
@ -55,7 +55,7 @@ sub get_assigned_value {
|
|||
|
||||
sub GetOptions {
|
||||
my (%opts) = @_;
|
||||
|
||||
|
||||
my $search_str = ',' . join(',', keys %opts) . ',';
|
||||
my $num_args = scalar(@ARGV);
|
||||
for (my $i = 0; $i < $num_args;) {
|
||||
|
|
|
@ -58,6 +58,9 @@ sub new {
|
|||
%{$self->{option_results}} = ();
|
||||
|
||||
$self->{option_msg} = [];
|
||||
|
||||
$self->{nodisplay} = 0;
|
||||
$self->{noexit_die} = 0;
|
||||
|
||||
$self->{is_output_xml} = 0;
|
||||
$self->{is_output_json} = 0;
|
||||
|
@ -376,6 +379,12 @@ sub output_xml {
|
|||
sub output_openmetrics {
|
||||
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();
|
||||
foreach my $perf (@{$self->{perfdatas}}) {
|
||||
next if (defined($self->{option_results}->{filter_perfdata}) &&
|
||||
|
@ -396,7 +405,7 @@ sub output_openmetrics {
|
|||
}
|
||||
$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_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})) {
|
||||
$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 {
|
||||
my ($self, %options) = @_;
|
||||
# $options{exit_litteral} = exit
|
||||
|
||||
if ($self->{noexit_die} == 1) {
|
||||
die 'exit';
|
||||
}
|
||||
if (defined($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}));
|
||||
}
|
||||
|
||||
sub parameter {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{attr})) {
|
||||
$self->{$options{attr}} = $options{value};
|
||||
}
|
||||
return $self->{$options{attr}};
|
||||
}
|
||||
|
||||
sub add_disco_entry {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue