New pack LatenceTech : mode forecast

Co-authored-by: thibaults-centreon <tscheitenberger@centreon.com>
This commit is contained in:
Sophie Depassio 2025-07-25 09:57:08 +02:00
parent 608dc607f8
commit 6b2e02bbd9
4 changed files with 190 additions and 3 deletions

View File

@ -0,0 +1,111 @@
#
# 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::forecast;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_output {
my ($self, %options) = @_;
return "Agent '" . $options{instance_value}->{display} . "' ";
}
sub custom_forecast_output {
my ($self, %options) = @_;
return sprintf('Projected latency %.2fms (forecasting interval: %.2fms, confidence level: %s)',
$self->{result_values}->{projectedLatencyMs}, $self->{result_values}->{forecastingIntervalMs}, $self->{result_values}->{confidenceLevel});
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{global} = [
{ label => 'projected-latency', nlabel => 'latency.projected.time.milliseconds', set => {
key_values => [ { name => 'projectedLatencyMs' }, { name => 'display' }, { name => 'confidenceLevel' }, { name => 'forecastingIntervalMs' }],
closure_custom_output => $self->can('custom_forecast_output'),
perfdatas => [
{ value => 'projectedLatencyMs', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => '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 => '/forecast');
$self->{global}->{display} = $results->{agentID};
foreach my $kpi (keys %{$results}) {
$self->{global}->{$kpi} = $results->{$kpi};
}
}
1;
__END__
=head1 MODE
Check agent forecast statistics.
=over 8
=item B<--agent-id>
Set the ID of the agent (mandatory option).
=item B<--warning-projected-latency>
Warning thresholds for projected latency.
=item B<--critical-projected-latency>
Critical thresholds for projected latency.
=back
=cut

View File

@ -31,9 +31,9 @@ sub new {
$self->{version} = '1.0';
$self->{modes} = {
'connectivity' => 'apps::monitoring::latencetech::restapi::mode::connectivity',
'discovery' => 'apps::monitoring::latencetech::restapi::mode::discovery'
'discovery' => 'apps::monitoring::latencetech::restapi::mode::discovery',
'forecast' => 'apps::monitoring::latencetech::restapi::mode::forecast'
};
$self->{custom_modes}->{api} = 'apps::monitoring::latencetech::restapi::custom::api';

View File

@ -0,0 +1,43 @@
*** Settings ***
Documentation Check the LatenceTech forecast 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=forecast
... --hostname=${HOSTNAME}
... --api-key=key
... --port=${APIPORT}
... --proto=http
*** Test Cases ***
forecast ${tc}
[Documentation] Check the agent forecast 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' Projected latency 10.63ms (forecasting interval: 6.94ms, confidence level: 50.74) | '2#latency.projected.time.milliseconds'=10.63ms;;;0;
... 2 --warning-projected-latency=5
... WARNING: Agent '2' Projected latency 10.63ms (forecasting interval: 6.94ms, confidence level: 50.74) | '2#latency.projected.time.milliseconds'=10.63ms;0:5;;0;
... 3 --critical-projected-latency=10
... CRITICAL: Agent '2' Projected latency 10.63ms (forecasting interval: 6.94ms, confidence level: 50.74) | '2#latency.projected.time.milliseconds'=10.63ms;;0:10;0;

View File

@ -1,7 +1,7 @@
{
"uuid": "b09e1a07-2cb1-462d-a3ce-a1de418a25c7",
"lastMigration": 32,
"name": "Mockoon",
"name": "LatenceTech",
"endpointPrefix": "",
"latency": 0,
"port": 3000,
@ -127,6 +127,35 @@
}
],
"responseMode": null
},
{
"uuid": "06ed6f2b-578e-4beb-94e0-f37f5c436038",
"type": "http",
"documentation": "",
"method": "get",
"endpoint": "api/v1/forecast",
"responses": [
{
"uuid": "8740d870-74b8-4846-a90b-1a27f8b59d45",
"body": "{\n \"CustomerID\": \"0\",\n \"agentID\": \"2\",\n \"time\": \"2025-07-25T07:52:01.849Z\",\n \"projectedLatencyMs\": 10.63,\n \"forecastingIntervalMs\": 6.94,\n \"confidenceLevel\": 50.74\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": [
@ -137,6 +166,10 @@
{
"type": "route",
"uuid": "a8045b6a-886a-4ba0-a2b4-9c9d425f9124"
},
{
"type": "route",
"uuid": "06ed6f2b-578e-4beb-94e0-f37f5c436038"
}
],
"proxyMode": false,