wip: bluemind

This commit is contained in:
garnier-quentin 2020-04-27 10:55:55 +02:00
parent 188b7de5d7
commit cd39bc261a
6 changed files with 656 additions and 217 deletions

View File

@ -0,0 +1,183 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::bluemind::local::custom::api;
use strict;
use warnings;
use centreon::plugins::ssh;
use centreon::plugins::misc;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'BLUEMIND OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
$self->{ssh} = centreon::plugins::ssh->new(%options);
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {
my ($self, %options) = @_;
foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
if (!defined($self->{option_results}->{$opt}[$i])) {
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
}
}
}
}
}
}
sub get_hostname {
my ($self, %options) = @_;
return defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'local';
}
sub check_options {
my ($self, %options) = @_;
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
return 0;
}
sub execute_command {
my ($self, %options) = @_;
my $content;
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($content) = $self->{ssh}->execute(
hostname => $self->{option_results}->{hostname},
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
command_path => $self->{option_results}->{command_path},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef,
timeout => $self->{option_results}->{timeout},
sudo => $self->{option_results}->{sudo}
);
} else {
($content) = centreon::plugins::misc::execute(
output => $self->{output},
options => { timeout => $self->{option_results}->{timeout} },
sudo => $self->{option_results}->{sudo},
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
command_path => $self->{option_results}->{command_path},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef
);
}
my $results = {};
foreach (split /\n/, $content) {
next if (! /$options{filter}/);
my ($key, $value_str) = split /\s/;
foreach my $value (split /,/, $value_str) {
my ($field1, $field2) = split /=/, $value;
$results->{$key}->{$field1} = $field2;
}
}
return $results;
}
1;
__END__
=head1 NAME
bluemind
=head1 SYNOPSIS
bluemind
=head1 BLUEMIND OPTIONS
=over 8
=item B<--hostname>
Hostname to query.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information. Used it you have output in a file.
=item B<--command-path>
Command path.
=item B<--command-options>
Command options.
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,158 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::bluemind::local::mode::core;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_core_output {
my ($self, %options) = @_;
return 'Main engine ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_core', type => 0, cb_prefix_output => 'prefix_core_output' }
];
$self->{maps_counters}->{bm_core} = [
{ label => 'calls-received-success', nlabel => 'core.calls.received.success.count', display_ok => 0, set => {
key_values => [ { name => 'calls_success', diff => 1 } ],
output_template => 'success calls received: %s',
perfdatas => [
{ value => 'calls_success_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'calls-received-failed', nlabel => 'core.calls.received.failure.count', set => {
key_values => [ { name => 'calls_failure', diff => 1 } ],
output_template => 'failure calls received: %s',
perfdatas => [
{ value => 'calls_failure_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'heartbeat-broadcast', nlabel => 'core.heartbeat.broadcast.running.count', display_ok => 0, set => {
key_values => [ { name => 'heartbeat_broadcast', diff => 1 } ],
output_template => 'broadcast heartbeat running: %s',
perfdatas => [
{ value => 'heartbeat_broadcast_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'directory-cluster-events', nlabel => 'core.directory.cluster.events.count', display_ok => 0, set => {
key_values => [ { name => 'cluster_events', diff => 1 } ],
output_template => 'directory cluster events: %s',
perfdatas => [
{ value => 'cluster_events_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'request-handling-total', nlabel => 'core.request.handling.total.milliseconds', set => {
key_values => [ { name => 'request_handling_time_total', diff => 1 } ],
output_template => 'total request handling: %s ms',
perfdatas => [
{ value => 'request_handling_time_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'request-handling-mean', nlabel => 'core.request.handling.mean.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'request_handling_time_mean', diff => 1 } ],
output_template => 'mean request handling: %s ms',
perfdatas => [
{ value => 'request_handling_time_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-core.heartbeat.broadcast,state=core.state.running,meterType=Counter count=1854550
# bm-core.handlingDuration,meterType=Timer count=695244256,totalTime=1911292590914929,mean=2749095
# bm-core.callsCount,status=failure,meterType=Counter count=97
# bm-core.callsCount,status=success,meterType=Counter count=125244086
# bm-core.directory.cluster.events,meterType=Counter count=14300
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/bm-core.sock http://127.0.0.1/metrics',
filter => 'bm-core\.heartbeat\.broadcast|bm-core\.handlingDuration|bm-core\.callsCount|bm-core\.directory\.cluster\.events'
);
$self->{bm_core} = {};
foreach (keys %$result) {
$self->{bm_core}->{'calls_' . $1} = $result->{$_}->{count} if (/bm-core.callsCount.*status=(failure|success)/);
$self->{bm_core}->{cluster_events} = $result->{$_}->{count} if (/bm-core\.directory\.cluster\.events/);
if (/bm-core\.handlingDuration/) { # in nanoseconds
$self->{bm_core}->{request_handling_time_total} = $result->{$_}->{totalTime} / 1000000;
$self->{bm_core}->{request_handling_time_mean} = $result->{$_}->{mean} / 1000000;
}
$self->{bm_core}->{heartbeat_broadcast} = $result->{$_}->{count} if (/bm-core\.heartbeat\.broadcast.*running/);
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check main bluemind engine.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^calls'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'calls-received-success', 'calls-received-failed',
'heartbeat-broadcast', 'directory-cluster-events',
'request-handling-total', 'request-handling-mean'.
=back
=cut

View File

@ -0,0 +1,191 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::bluemind::local::mode::lmtpd;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_lmtpd_output {
my ($self, %options) = @_;
return 'Email delivery service ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_lmtpd', type => 0, cb_prefix_output => 'prefix_lmtpd_output' }
];
$self->{maps_counters}->{bm_lmtpd} = [
{ label => 'connections-active', nlabel => 'lmtpd.connections.active.count', set => {
key_values => [ { name => 'active_connections' } ],
output_template => 'active connections: %s',
perfdatas => [
{ value => 'active_connections_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'connections-total', nlabel => 'lmtpd.connections.total.count', display_ok => 0, set => {
key_values => [ { name => 'connections', diff => 1 } ],
output_template => 'total connections: %s',
perfdatas => [
{ value => 'connections_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'deliveries-success', nlabel => 'lmtpd.deliveries.success.count', display_ok => 0, set => {
key_values => [ { name => 'deliveries_ok', diff => 1 } ],
output_template => 'success deliveries: %s',
perfdatas => [
{ value => 'deliveries_ok_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'deliveries-failure', nlabel => 'lmtpd.deliveries.failure.count', display_ok => 0, set => {
key_values => [ { name => 'deliveries_ko', diff => 1 } ],
output_template => 'failure deliveries: %s',
perfdatas => [
{ value => 'deliveries_ko_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'emails-size-total', nlabel => 'lmtpd.emails.size.total.count', display_ok => 0, set => {
key_values => [ { name => 'email_size', diff => 1 } ],
output_template => 'total emails size: %s %s',
output_change_bytes => 1,
perfdatas => [
{ value => 'email_size_absolute', template => '%s', min => 0, unit => 'B' }
]
}
},
{ label => 'sessions-duration-total', nlabel => 'lmtpd.sessions.duration.total.milliseconds', set => {
key_values => [ { name => 'session_duration_total', diff => 1 } ],
output_template => 'total sessions duration: %s ms',
perfdatas => [
{ value => 'session_duration_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'sessions-duration-mean', nlabel => 'lmtpd.sessions.duration.mean.milliseconds', set => {
key_values => [ { name => 'session_duration_mean', diff => 1 } ],
output_template => 'mean sessions duration: %s ms',
perfdatas => [
{ value => 'session_duration_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'traffic-transport-latency-total', nlabel => 'lmtpd.traffic.transport.latency.total.milliseconds', set => {
key_values => [ { name => 'traffic_latency_total', diff => 1 } ],
output_template => 'total traffic transport latency: %s ms',
perfdatas => [
{ value => 'traffic_latency_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'traffic-transport-latency-mean', nlabel => 'lmtpd.traffic.transport.latency.mean.milliseconds', set => {
key_values => [ { name => 'traffic_latency_mean', diff => 1 } ],
output_template => 'mean traffic transport latency: %s ms',
perfdatas => [
{ value => 'traffic_latency_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-lmtpd.activeConnections,meterType=Gauge value=0
# bm-lmtpd.connectionCount,meterType=Counter count=1236057
# bm-lmtpd.deliveries,status=ko,meterType=Counter count=410
# bm-lmtpd.deliveries,status=ok,meterType=Counter count=1390933
# bm-lmtpd.emailSize,meterType=DistSum count=5020456,totalAmount=1170102671020,mean=233067
# bm-lmtpd.sessionDuration,meterType=Timer count=4941893,totalTime=1052591049892285,mean=212993492
# bm-lmtpd.traffic.transportLatency,meterType=Timer count=5017208,totalTime=272844528075000000,mean=54381745400
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/bm-lmtpd.sock http://127.0.0.1/metrics',
filter => 'activeConnections|connectionCount|deliveries|emailSize|sessionDuration|traffic\.transportLatency'
);
$self->{bm_lmtpd} = {};
foreach (keys %$result) {
$self->{bm_lmtpd}->{'deliveries_' . $1} = $result->{$_}->{count} if (/bm-lmtpd\.deliveries.*status=(ok|ko)/);
$self->{bm_lmtpd}->{active_connections} = $result->{$_}->{value} if (/bm-lmtpd\.activeConnections/);
$self->{bm_lmtpd}->{connections} = $result->{$_}->{count} if (/bm-lmtpd\.connectionCount/);
$self->{bm_lmtpd}->{email_size} = $result->{$_}->{totalAmount} if (/bm-lmtpd\.emailSize/);
if (/bm-lmtpd\.sessionDuration/) {
$self->{bm_lmtpd}->{session_duration_total} = $result->{$_}->{totalAmount} / 100000;
$self->{bm_lmtpd}->{session_duration_mean} = $result->{$_}->{mean} / 100000;
}
if (/bm-lmtpd\.traffic\.transportLatency/) {
$self->{bm_lmtpd}->{traffic_latency_total} = $result->{$_}->{totalAmount} / 100000;
$self->{bm_lmtpd}->{traffic_latency_mean} = $result->{$_}->{mean} / 100000;
}
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check email delivery service.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^deliveries'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'connections-active', 'connections-total',
'deliveries-success', 'deliveries-failure', 'emails-size-total',
'sessions-duration-total', 'sessions-duration-mean', 'traffic-transport-latency-total',
'traffic-transport-latency-mean'.
=back
=cut

View File

@ -0,0 +1,115 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::bluemind::local::mode::xmpp;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_xmpp_output {
my ($self, %options) = @_;
return 'Instant messaging service ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_xmpp', type => 0, cb_prefix_output => 'prefix_xmpp_output' }
];
$self->{maps_counters}->{bm_xmpp} = [
{ label => 'packets-all', nlabel => 'xmpp.packets.all.count', set => {
key_values => [ { name => 'packets_all', diff => 1 } ],
output_template => 'all packets sent: %s',
perfdatas => [
{ value => 'packets_all_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'packets-chat', nlabel => 'xmpp.packets.chat.count', display_ok => 0, set => {
key_values => [ { name => 'packets_chat', diff => 1 } ],
output_template => 'chat packets sent: %s',
perfdatas => [
{ value => 'packets_chat_absolute', template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-xmpp.packetsCount,type=all,meterType=Counter count=517791
# bm-xmpp.packetsCount,type=chat,meterType=Counter count=12
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/bm-xmpp.sock http://127.0.0.1/metrics',
filter => 'packetsCount'
);
$self->{bm_xmpp} = {};
foreach (keys %$result) {
$self->{bm_xmpp}->{'packets_' . $1} = $result->{$_}->{count} if (/bm-xmpp\.packetsCount.*type=(all|chat)/);
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check instant Messaging Service.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='chat'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'packets-all', 'packets-chat'.
=back
=cut

View File

@ -18,11 +18,11 @@
# limitations under the License.
#
package apps::bluemind::plugin;
package apps::bluemind::local::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_simple);
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
@ -31,10 +31,13 @@ sub new {
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'incoming' => 'apps::bluemind::mode::incoming',
);
$self->{modes} = {
'core' => 'apps::bluemind::local::mode::core',
'lmtpd' => 'apps::bluemind::local::mode::lmtpd',
'xmpp' => 'apps::bluemind::local::mode::xmpp'
};
$self->{custom_modes}{api} = 'apps::bluemind::local::custom::api';
return $self;
}
@ -45,6 +48,6 @@ __END__
=head1 PLUGIN DESCRIPTION
Check BlueMind through InfluxDB API
Check BlueMind through bm-metrics sockets
=cut

View File

@ -1,211 +0,0 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::bluemind::mode::incoming;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::statefile;
use JSON;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8086'},
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/db" },
"database:s" => { name => 'database' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{database})) {
$self->{output}->add_option_msg(short_msg => "Please set the database option");
$self->{output}->option_exit();
}
if ((!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= option");
$self->{output}->option_exit();
}
my $query = 'select sum("success") as "success_sum", sum("failure") as "failure_sum" from lmtpd.deliveries where time > '.$old_timestamp.'s and time < now()';
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{database}."/series";
$self->{option_results}->{get_param} = [];
push @{$self->{option_results}->{get_param}}, "q=" . $query, "p=" . $self->{option_results}->{password}, "u=" . $self->{option_results}->{username};
$self->{http}->set_options(%{$self->{option_results}});
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{statefile_value}->read(statefile => 'bluemind_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
my $new_datas = {};
$new_datas->{last_timestamp} = time();
$self->{statefile_value}->write(data => $new_datas);
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();
}
my $hwebcontent;
for my $ref (@{ $webcontent }) {
my $name = $ref->{name};
my @columns = @{ $ref->{columns} };
for my $points (@{ $ref->{points} }) {
my %hash;
@hash{ @columns } = @$points;
push @{ $hwebcontent->{$name} }, \%hash;
}
}
my $success_incoming_mails = defined($hwebcontent->{qw(lmtpd.deliveries)}->[0]->{success_sum}) ? $hwebcontent->{qw(lmtpd.deliveries)}->[0]->{success_sum} : '0';
my $failure_incoming_mails = defined($hwebcontent->{qw(lmtpd.deliveries)}->[0]->{failure_sum}) ? $hwebcontent->{qw(lmtpd.deliveries)}->[0]->{failure_sum} : '0';
# If not present: failure and success incoming mails are 0
if (!defined($success_incoming_mails)) {
$success_incoming_mails = 0;
}
if (!defined($failure_incoming_mails)) {
$failure_incoming_mails = 0;
}
my $exit = $self->{perfdata}->threshold_check(value => $failure_incoming_mails, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Success Incoming Mails: %d - Failure Incoming Mails: %d",$success_incoming_mails,$failure_incoming_mails));
$self->{output}->perfdata_add(label => 'success',
value => sprintf("%d", $success_incoming_mails),
min => 0,
);
$self->{output}->perfdata_add(label => 'failure',
value => sprintf("%d", $failure_incoming_mails),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0,
);
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check Bluemind incoming_mails (success and failure)
=over 8
=item B<--hostname>
IP Addr/FQDN of the Bluemind host
=item B<--port>
Port used by InfluxDB API (Default: '8086')
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--urlpath>
Set path to get influxdb information (Default: '/db')
=item B<--database>
InfluxDB Database name
=item B<--username>
Specify username for API authentification
=item B<--password>
Specify password for API authentification
=item B<--timeout>
Threshold for HTTP timeout (Default: 5)
=item B<--warning>
Warning Threshold for failure incoming mails
=item B<--critical>
Critical Threshold for failure incoming mails
=back
=cut