From b1bee0cca114aa0c88fd04caeca85ee9252426e7 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Fri, 25 Jul 2025 14:56:10 +0200 Subject: [PATCH] New pack LatenceTech : mode radio Co-authored-by: thibaults-centreon --- .../latencetech/restapi/mode/radio.pm | 157 ++++++++++++++++++ .../monitoring/latencetech/restapi/plugin.pm | 3 +- .../latencetech/restapi/mockoon.json | 33 ++++ .../latencetech/restapi/radio.robot | 55 ++++++ 4 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 src/apps/monitoring/latencetech/restapi/mode/radio.pm create mode 100644 tests/apps/monitoring/latencetech/restapi/radio.robot diff --git a/src/apps/monitoring/latencetech/restapi/mode/radio.pm b/src/apps/monitoring/latencetech/restapi/mode/radio.pm new file mode 100644 index 000000000..5d6d45513 --- /dev/null +++ b/src/apps/monitoring/latencetech/restapi/mode/radio.pm @@ -0,0 +1,157 @@ +# +# 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::radio; + +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 => 'snr-dbm', nlabel => 'signal.noise.ratio.db', set => { + key_values => [ { name => 'SINR_dB' }, { name => 'display' } ], + output_template => 'Signal noise ration: %.2fdb', + perfdatas => [ + { value => 'SINR_dB', template => '%.2f', + unit => 'dbm', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'rssi-dbm', nlabel => 'received.signalstrength.indicator.dbm', set => { + key_values => [ { name => 'RSSI_dBm' }, { name => 'display' } ], + output_template => 'Received Signal Strength Indicator: %.2fdbm', + perfdatas => [ + { value => 'RSSI_dBm', template => '%.2f', + unit => 'dbm', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'rsrp-dbm', nlabel => 'reference.signalreceive.power.dbm', set => { + key_values => [ { name => 'RSRP_dBm' }, { name => 'display' } ], + output_template => 'Reference signal receive power: %.2fdbm', + perfdatas => [ + { value => 'RSRP_dBm', template => '%.2f', + unit => 'dbm', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'rsrq-db', nlabel => 'reference.signalreceive.quality.dbm', set => { + key_values => [ { name => 'RSRQ_dB' }, { name => 'display' } ], + output_template => 'Reference signal receive quality: %.2fdb', + perfdatas => [ + { value => 'RSRQ_dB', template => '%.2f', + unit => 'db', 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 => '/radio'); + $self->{global}->{display} = $results->{agentID}; + foreach my $kpi (keys %{$results}) { + if (defined($results->{$kpi}) && $results->{$kpi} !~ 'Unknown') { + $self->{global}->{$kpi} = $results->{$kpi}; + } + } +} + +1; + +__END__ + +=head1 MODE + +Check agent radio statistics. + +=over 8 + +=item B<--agent-id> + +Set the ID of the agent (mandatory option). + +=item B<--warning-snr-dbm> + +Warning thresholds for signal noise ratio in dbm. + +=item B<--critical-snr-dbm> + +Critical thresholds for signal noise ratio in dbm. + +=item B<--warning-rssi-dbm> + +Warning thresholds for received signal strength indicator in dbm. + +=item B<--critical-rssi-dbm> + +Critical thresholds for received signal strength indicator in dbm. + +=item B<--warning-rsrp-dbm> + +Warning thresholds for reference signal receive power in dbm. + +=item B<--critical-rsrp-dbm> + +Critical thresholds for reference signal receive power in dbm. + +=item B<--warning-rsrq-db> + +Warning thresholds for reference signal receive quality in db. + +=item B<--critical-rsrq-db> + +Critical thresholds for reference signal receive quality in db. + +=back + +=cut diff --git a/src/apps/monitoring/latencetech/restapi/plugin.pm b/src/apps/monitoring/latencetech/restapi/plugin.pm index 7e558e1e7..4cf3d89d8 100644 --- a/src/apps/monitoring/latencetech/restapi/plugin.pm +++ b/src/apps/monitoring/latencetech/restapi/plugin.pm @@ -34,7 +34,8 @@ sub new { 'connectivity' => 'apps::monitoring::latencetech::restapi::mode::connectivity', 'discovery' => 'apps::monitoring::latencetech::restapi::mode::discovery', 'forecast' => 'apps::monitoring::latencetech::restapi::mode::forecast', - 'latency' => 'apps::monitoring::latencetech::restapi::mode::latency' + 'latency' => 'apps::monitoring::latencetech::restapi::mode::latency', + 'radio' => 'apps::monitoring::latencetech::restapi::mode::radio' }; $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 ae8c74566..4b9443395 100644 --- a/tests/apps/monitoring/latencetech/restapi/mockoon.json +++ b/tests/apps/monitoring/latencetech/restapi/mockoon.json @@ -328,6 +328,35 @@ } ], "responseMode": null + }, + { + "uuid": "6ba46385-639a-41c6-8890-c487af160499", + "type": "http", + "documentation": "", + "method": "get", + "endpoint": "api/v1/radio", + "responses": [ + { + "uuid": "0d20ae09-1365-42e9-913c-e75c0fcc7ba4", + "body": "{\n \"CustomerID\": \"0\",\n \"agentID\": \"1\",\n \"time\": \"2025-02-04T17:12:56.062Z\",\n \"networkName\": \"Bell\",\n \"networkType\": \"4G LTE\",\n \"cellID\": \"40\",\n \"SINR_dB\": \"2.147489\",\n \"RSSI_dBm\": \"-63\",\n \"RSRP_dBm\": \"-10\",\n \"RSRQ_dB\": \"-94\"\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": [ @@ -346,6 +375,10 @@ { "type": "route", "uuid": "febdf454-e06c-4f7c-9ff4-99eecdc98447" + }, + { + "type": "route", + "uuid": "6ba46385-639a-41c6-8890-c487af160499" } ], "proxyMode": false, diff --git a/tests/apps/monitoring/latencetech/restapi/radio.robot b/tests/apps/monitoring/latencetech/restapi/radio.robot new file mode 100644 index 000000000..cbb4990d2 --- /dev/null +++ b/tests/apps/monitoring/latencetech/restapi/radio.robot @@ -0,0 +1,55 @@ +*** Settings *** +Documentation Check the LatenceTech radio 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=radio +... --hostname=${HOSTNAME} +... --api-key=key +... --port=${APIPORT} +... --proto=http + + +*** Test Cases *** +Radio ${tc} + [Documentation] Check the agent radio statistics. + [Tags] apps monitoring latencetech restapi + + ${command} Catenate + ... ${cmd} + ... --customer-id=0 + ... --agent-id=1 + ... ${extraoptions} + Log ${cmd} + Ctn Run Command And Check Result As Strings ${command} ${expected_result} + + Examples: tc extraoptions expected_result -- + ... 1 ${EMPTY} + ... OK: Agent '1' Signal noise ration: 2.15db, Received Signal Strength Indicator: -63.00dbm, Reference signal receive power: -10.00dbm, Reference signal receive quality: -94.00db | '1#signal.noise.ratio.db'=2.15dbm;;;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;;;; '1#reference.signalreceive.power.dbm'=-10.00dbm;;;; '1#reference.signalreceive.quality.dbm'=-94.00db;;;; + ... 2 --warning-snr-dbm=1.5 + ... WARNING: Agent '1' Signal noise ration: 2.15db | '1#signal.noise.ratio.db'=2.15dbm;0:1.5;;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;;;; '1#reference.signalreceive.power.dbm'=-10.00dbm;;;; '1#reference.signalreceive.quality.dbm'=-94.00db;;;; + ... 3 --critical-snr-dbm=2.05 + ... CRITICAL: Agent '1' Signal noise ration: 2.15db | '1#signal.noise.ratio.db'=2.15dbm;;0:2.05;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;;;; '1#reference.signalreceive.power.dbm'=-10.00dbm;;;; '1#reference.signalreceive.quality.dbm'=-94.00db;;;; + ... 4 --warning-rssi-dbm=-65.5 + ... WARNING: Agent '1' Received Signal Strength Indicator: -63.00dbm | '1#signal.noise.ratio.db'=2.15dbm;;;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;0:-65.5;;; '1#reference.signalreceive.power.dbm'=-10.00dbm;;;; '1#reference.signalreceive.quality.dbm'=-94.00db;;;; + ... 5 --critical-rssi-dbm=-70.3 + ... CRITICAL: Agent '1' Received Signal Strength Indicator: -63.00dbm | '1#signal.noise.ratio.db'=2.15dbm;;;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;;0:-70.3;; '1#reference.signalreceive.power.dbm'=-10.00dbm;;;; '1#reference.signalreceive.quality.dbm'=-94.00db;;;; + ... 6 --warning-rsrp-dbm=-15.2 + ... WARNING: Agent '1' Reference signal receive power: -10.00dbm | '1#signal.noise.ratio.db'=2.15dbm;;;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;;;; '1#reference.signalreceive.power.dbm'=-10.00dbm;0:-15.2;;; '1#reference.signalreceive.quality.dbm'=-94.00db;;;; + ... 7 --critical-rsrp-dbm=-20.7 + ... CRITICAL: Agent '1' Reference signal receive power: -10.00dbm | '1#signal.noise.ratio.db'=2.15dbm;;;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;;;; '1#reference.signalreceive.power.dbm'=-10.00dbm;;0:-20.7;; '1#reference.signalreceive.quality.dbm'=-94.00db;;;; + ... 8 --warning-rsrq-db=-90.5 + ... WARNING: Agent '1' Reference signal receive quality: -94.00db | '1#signal.noise.ratio.db'=2.15dbm;;;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;;;; '1#reference.signalreceive.power.dbm'=-10.00dbm;;;; '1#reference.signalreceive.quality.dbm'=-94.00db;0:-90.5;;; + ... 9 --critical-rsrq-db=-95.2 + ... CRITICAL: Agent '1' Reference signal receive quality: -94.00db | '1#signal.noise.ratio.db'=2.15dbm;;;; '1#received.signalstrength.indicator.dbm'=-63.00dbm;;;; '1#reference.signalreceive.power.dbm'=-10.00dbm;;;; '1#reference.signalreceive.quality.dbm'=-94.00db;;0:-95.2;;