From 0275a85c772c38d81e8bc26c0de2f3561cc05ba3 Mon Sep 17 00:00:00 2001 From: itoussies <65223458+itoussies@users.noreply.github.com> Date: Tue, 9 Feb 2021 13:46:02 +0100 Subject: [PATCH] enh(plugin)apps-protocol-ssh-metricsv2 (#2583) --- apps/protocols/ssh/mode/login.pm | 32 +++++++++++++------------------- apps/protocols/ssh/plugin.pm | 6 +++--- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/apps/protocols/ssh/mode/login.pm b/apps/protocols/ssh/mode/login.pm index 68601cb12..b6b8459d7 100644 --- a/apps/protocols/ssh/mode/login.pm +++ b/apps/protocols/ssh/mode/login.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -49,22 +49,26 @@ sub set_counters { { name => 'global', type => 0, message_separator => ' - ' }, ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', + type => 2 + critical_default => '%{message} !~ /authentification succeeded/i', + set => { key_values => [ { name => 'status' }, { name => 'message' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'time', set => { + { label => 'time', nlabel => 'response.time.seconds' , set => { key_values => [ { name => 'time_elapsed' } ], output_template => 'Response time %.3fs', perfdatas => [ - { label => 'time', value => 'time_elapsed', template => '%.3f', unit => 's', min => 0 }, - ], + { label => 'time', template => '%.3f', unit => 's', min => 0 } + ] } - }, + } ]; } @@ -73,22 +77,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{message} !~ /authentification succeeded/i' }, - }); + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/apps/protocols/ssh/plugin.pm b/apps/protocols/ssh/plugin.pm index 96dd1d912..1beb5feaa 100644 --- a/apps/protocols/ssh/plugin.pm +++ b/apps/protocols/ssh/plugin.pm @@ -30,9 +30,9 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'login' => 'apps::protocols::ssh::mode::login', - ); + $self->{modes} = { + 'login' => 'apps::protocols::ssh::mode::login' + }; $self->{custom_modes}{api} = 'centreon::common::protocols::ssh::custom::api'; return $self;