mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 15:44:21 +02:00
fix(mosquitto-mqtt): syntax and encoding (#5676)
Co-authored-by: Jochen Platzgummer <jochen.platzgummer@pgum.eu> Refs: CTOR-1786
This commit is contained in:
parent
de3749d79f
commit
ea71dd261a
@ -27,6 +27,7 @@ use warnings;
|
|||||||
use centreon::plugins::misc;
|
use centreon::plugins::misc;
|
||||||
use Time::HiRes qw(time);
|
use Time::HiRes qw(time);
|
||||||
use POSIX qw(floor);
|
use POSIX qw(floor);
|
||||||
|
use Encode;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -119,8 +120,12 @@ sub check_options {
|
|||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $topic = $self->{option_results}->{topic};
|
||||||
|
eval {
|
||||||
|
$topic = decode("utf8", $topic);
|
||||||
|
};
|
||||||
my $value = $options{mqtt}->query(
|
my $value = $options{mqtt}->query(
|
||||||
topic => $self->{option_results}->{topic}
|
topic => $topic
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!centreon::plugins::misc::is_empty($self->{option_results}->{extracted_pattern})) {
|
if (!centreon::plugins::misc::is_empty($self->{option_results}->{extracted_pattern})) {
|
||||||
|
@ -27,6 +27,7 @@ use warnings;
|
|||||||
use centreon::plugins::misc;
|
use centreon::plugins::misc;
|
||||||
use Time::HiRes qw(time);
|
use Time::HiRes qw(time);
|
||||||
use POSIX qw(floor);
|
use POSIX qw(floor);
|
||||||
|
use Encode;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -116,8 +117,12 @@ sub check_options {
|
|||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $topic = $self->{option_results}->{topic};
|
||||||
|
eval {
|
||||||
|
$topic = decode("utf8", $topic);
|
||||||
|
};
|
||||||
my $value = $options{mqtt}->query(
|
my $value = $options{mqtt}->query(
|
||||||
topic => $self->{option_results}->{topic}
|
topic => $topic
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!centreon::plugins::misc::is_empty($self->{option_results}->{format_custom})) {
|
if (!centreon::plugins::misc::is_empty($self->{option_results}->{format_custom})) {
|
||||||
|
@ -122,7 +122,7 @@ sub query {
|
|||||||
$self->{mqtt}->unsubscribe($options{topic});
|
$self->{mqtt}->unsubscribe($options{topic});
|
||||||
};
|
};
|
||||||
if (%mqtt_received) {
|
if (%mqtt_received) {
|
||||||
return %mqtt_received{$options{topic}};
|
return $mqtt_received{$options{topic}};
|
||||||
} else {
|
} else {
|
||||||
$self->{output}->add_option_msg(short_msg => 'No message in topic: ' . $options{topic});
|
$self->{output}->add_option_msg(short_msg => 'No message in topic: ' . $options{topic});
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user