From e861e4d32ae10ac686fc169225146dc23113aa27 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Fri, 25 Jul 2025 15:13:19 +0200 Subject: [PATCH] New pack LatenceTech : mode throughput Co-authored-by: thibaults-centreon --- .../latencetech/restapi/mode/throughput.pm | 155 ++++++++++++++++++ .../monitoring/latencetech/restapi/plugin.pm | 3 +- .../latencetech/restapi/mockoon.json | 33 ++++ .../latencetech/restapi/throughput.robot | 53 ++++++ 4 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 src/apps/monitoring/latencetech/restapi/mode/throughput.pm create mode 100644 tests/apps/monitoring/latencetech/restapi/throughput.robot diff --git a/src/apps/monitoring/latencetech/restapi/mode/throughput.pm b/src/apps/monitoring/latencetech/restapi/mode/throughput.pm new file mode 100644 index 000000000..d1cafac7d --- /dev/null +++ b/src/apps/monitoring/latencetech/restapi/mode/throughput.pm @@ -0,0 +1,155 @@ +# +# Copyright 2025 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::monitoring::latencetech::restapi::mode::throughput; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_output' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'lifbe-download', nlabel => 'lifbe.download.bandwidth.mbps', set => { + key_values => [ { name => 'lifbeDownload' }, { name => 'display' } ], + output_template => 'LifBE Download: %.2fmbps', + perfdatas => [ + { value => 'lifbeDownload', template => '%.2f', + min => 0, unit => 'mbps', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'lifbe-upload', nlabel => 'lifbe.upload.bandwidth.mbps', set => { + key_values => [ { name => 'lifbeUpload' }, { name => 'display' } ], + output_template => 'LifBE Upload: %.2fmbps', + perfdatas => [ + { value => 'lifbeUpload', template => '%.2f', + min => 0, unit => 'mbps', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'jitter-download', nlabel => 'jitter.download.time.milliseconds', set => { + key_values => [ { name => 'jitterDownload' }, { name => 'display' } ], + output_template => 'Jitter Download Time: %.2fms', + perfdatas => [ + { value => 'jitterDownload', template => '%.2f', + min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'jitter-upload', nlabel => 'jitter.upload.time.milliseconds', set => { + key_values => [ { name => 'jitterUpload' }, { name => 'display' } ], + output_template => 'Jitter Upload Time: %.2fms', + perfdatas => [ + { value => 'jitterUpload', template => '%.2f', + min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }, + ], + } + } + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Agent '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + my $results = $options{custom}->request_api(endpoint => '/lifbe'); + $self->{global}->{display} = $results->{agentID}; + foreach my $kpi (keys %{$results}) { + $self->{global}->{$kpi} = $results->{$kpi}; + } +} + +1; + +__END__ + +=head1 MODE + +Check agent throughput statistics. + +=over 8 + +=item B<--agent-id> + +Set the ID of the agent (mandatory option). + +=item B<--warning-lifbe-download> + +Warning thresholds for LifBE download bandwidth (in Mbps). + +=item B<--critical-lifbe-download> + +Critical thresholds for LifBE download bandwidth (in Mbps). + +=item B<--warning-lifbe-upload> + +Warning thresholds for LifBE upload bandwidth (in Mbps). + +=item B<--critical-lifbe-upload> + +Critical thresholds for LifBE upload bandwidth (in Mbps). + +=item B<--warning-jitter-download> + +Warning thresholds for jitter download time (in milliseconds). + +=item B<--critical-jitter-download> + +Critical thresholds for jitter download time (in milliseconds). + +=item B<--warning-jitter-upload> + +Warning thresholds for jitter upload time (in milliseconds). + +=item B<--critical-jitter-upload> + +Critical thresholds for jitter upload time (in milliseconds). + +=back + +=cut diff --git a/src/apps/monitoring/latencetech/restapi/plugin.pm b/src/apps/monitoring/latencetech/restapi/plugin.pm index 4cf3d89d8..733bc3b22 100644 --- a/src/apps/monitoring/latencetech/restapi/plugin.pm +++ b/src/apps/monitoring/latencetech/restapi/plugin.pm @@ -35,7 +35,8 @@ sub new { 'discovery' => 'apps::monitoring::latencetech::restapi::mode::discovery', 'forecast' => 'apps::monitoring::latencetech::restapi::mode::forecast', 'latency' => 'apps::monitoring::latencetech::restapi::mode::latency', - 'radio' => 'apps::monitoring::latencetech::restapi::mode::radio' + 'radio' => 'apps::monitoring::latencetech::restapi::mode::radio', + 'throughput' => 'apps::monitoring::latencetech::restapi::mode::throughput' }; $self->{custom_modes}->{api} = 'apps::monitoring::latencetech::restapi::custom::api'; diff --git a/tests/apps/monitoring/latencetech/restapi/mockoon.json b/tests/apps/monitoring/latencetech/restapi/mockoon.json index 4b9443395..1ac80ff0c 100644 --- a/tests/apps/monitoring/latencetech/restapi/mockoon.json +++ b/tests/apps/monitoring/latencetech/restapi/mockoon.json @@ -357,6 +357,35 @@ } ], "responseMode": null + }, + { + "uuid": "232fe410-d4af-42c9-8efa-919b0c576625", + "type": "http", + "documentation": "", + "method": "get", + "endpoint": "api/v1/lifbe", + "responses": [ + { + "uuid": "93141e59-7bca-44f8-b094-72f56ffec4f6", + "body": "{\n \"CustomerID\": \"0\",\n \"agentID\": \"2\",\n \"time\": \"2025-07-25T13:53:19.725Z\",\n \"lifbeDownload\": 531.58,\n \"lifbeUpload\": 47.05,\n \"jitterDownload\": 1.17,\n \"jitterUpload\": 3.38,\n \"packetLossDownload\": 0,\n \"packetLossUpload\": 0,\n \"networkInterface\": \"MOBILE\",\n \"networkType\": \"MOBILE_5G\"\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null } ], "rootChildren": [ @@ -379,6 +408,10 @@ { "type": "route", "uuid": "6ba46385-639a-41c6-8890-c487af160499" + }, + { + "type": "route", + "uuid": "232fe410-d4af-42c9-8efa-919b0c576625" } ], "proxyMode": false, diff --git a/tests/apps/monitoring/latencetech/restapi/throughput.robot b/tests/apps/monitoring/latencetech/restapi/throughput.robot new file mode 100644 index 000000000..28b49aaff --- /dev/null +++ b/tests/apps/monitoring/latencetech/restapi/throughput.robot @@ -0,0 +1,53 @@ +*** Settings *** +Documentation Check the LatenceTech throughput mode with api custom mode + +Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}resources/import.resource + +Suite Setup Start Mockoon ${MOCKOON_JSON} +Suite Teardown Stop Mockoon +Test Timeout 120s + +*** Variables *** +${MOCKOON_JSON} ${CURDIR}${/}mockoon.json + +${cmd} ${CENTREON_PLUGINS} +... --plugin=apps::monitoring::latencetech::restapi::plugin +... --custommode=api +... --mode=throughput +... --hostname=${HOSTNAME} +... --api-key=key +... --port=${APIPORT} +... --proto=http + +*** Test Cases *** +Throughput ${tc} + [Documentation] Check agent throughput statistics. + [Tags] apps monitoring latencetech restapi + + ${command} Catenate + ... ${cmd} + ... --customer-id=0 + ... --agent-id=2 + ... ${extraoptions} + Log ${cmd} + Ctn Run Command And Check Result As Strings ${command} ${expected_result} + + Examples: tc extraoptions expected_result -- + ... 1 ${EMPTY} + ... OK: Agent '2' LifBE Download: 531.58mbps, LifBE Upload: 47.05mbps, Jitter Download Time: 1.17ms, Jitter Upload Time: 3.38ms | '2#lifbe.download.bandwidth.mbps'=531.58mbps;;;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;;;0; '2#jitter.download.time.milliseconds'=1.17ms;;;0; '2#jitter.upload.time.milliseconds'=3.38ms;;;0; + ... 2 --warning-lifbe-download=500 + ... WARNING: Agent '2' LifBE Download: 531.58mbps | '2#lifbe.download.bandwidth.mbps'=531.58mbps;0:500;;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;;;0; '2#jitter.download.time.milliseconds'=1.17ms;;;0; '2#jitter.upload.time.milliseconds'=3.38ms;;;0; + ... 3 --critical-lifbe-download=450 + ... CRITICAL: Agent '2' LifBE Download: 531.58mbps | '2#lifbe.download.bandwidth.mbps'=531.58mbps;;0:450;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;;;0; '2#jitter.download.time.milliseconds'=1.17ms;;;0; '2#jitter.upload.time.milliseconds'=3.38ms;;;0; + ... 4 --warning-lifbe-upload=45 + ... WARNING: Agent '2' LifBE Upload: 47.05mbps | '2#lifbe.download.bandwidth.mbps'=531.58mbps;;;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;0:45;;0; '2#jitter.download.time.milliseconds'=1.17ms;;;0; '2#jitter.upload.time.milliseconds'=3.38ms;;;0; + ... 5 --critical-lifbe-upload=40 + ... CRITICAL: Agent '2' LifBE Upload: 47.05mbps | '2#lifbe.download.bandwidth.mbps'=531.58mbps;;;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;;0:40;0; '2#jitter.download.time.milliseconds'=1.17ms;;;0; '2#jitter.upload.time.milliseconds'=3.38ms;;;0; + ... 6 --warning-jitter-download=0.9 + ... WARNING: Agent '2' Jitter Download Time: 1.17ms | '2#lifbe.download.bandwidth.mbps'=531.58mbps;;;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;;;0; '2#jitter.download.time.milliseconds'=1.17ms;0:0.9;;0; '2#jitter.upload.time.milliseconds'=3.38ms;;;0; + ... 7 --critical-jitter-download=1.1 + ... CRITICAL: Agent '2' Jitter Download Time: 1.17ms | '2#lifbe.download.bandwidth.mbps'=531.58mbps;;;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;;;0; '2#jitter.download.time.milliseconds'=1.17ms;;0:1.1;0; '2#jitter.upload.time.milliseconds'=3.38ms;;;0; + ... 8 --warning-jitter-upload=3 + ... WARNING: Agent '2' Jitter Upload Time: 3.38ms | '2#lifbe.download.bandwidth.mbps'=531.58mbps;;;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;;;0; '2#jitter.download.time.milliseconds'=1.17ms;;;0; '2#jitter.upload.time.milliseconds'=3.38ms;0:3;;0; + ... 9 --critical-jitter-upload=3.25 + ... CRITICAL: Agent '2' Jitter Upload Time: 3.38ms | '2#lifbe.download.bandwidth.mbps'=531.58mbps;;;0; '2#lifbe.upload.bandwidth.mbps'=47.05mbps;;;0; '2#jitter.download.time.milliseconds'=1.17ms;;;0; '2#jitter.upload.time.milliseconds'=3.38ms;;0:3.25;0;