fix typo and some nlabel

This commit is contained in:
garnier-quentin 2021-02-09 13:51:23 +01:00
parent 141cbf8e54
commit fd201527aa
3 changed files with 18 additions and 28 deletions

View File

@ -29,18 +29,18 @@ use Time::HiRes qw(gettimeofday tv_interval);
sub prefix_output { sub prefix_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "SNMP Agent "; return 'SNMP Agent ';
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' }, { name => 'global', type => 0, cb_prefix_output => 'prefix_output' }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'rta', nlabel => 'response.time.average', set => { { label => 'rta', nlabel => 'roundtrip.time.average.milliseconds', set => {
key_values => [ { name => 'rta' } ], key_values => [ { name => 'rta' } ],
output_template => 'rta %.3fms', output_template => 'rta %.3fms',
perfdatas => [ perfdatas => [
@ -48,14 +48,14 @@ sub set_counters {
] ]
} }
}, },
{ label => 'rtmax', nlabel => 'response.time.max', display_ok => 0, set => { { label => 'rtmax', nlabel => 'roundtrip.time.maximum.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'rtmax' } ], key_values => [ { name => 'rtmax' } ],
perfdatas => [ perfdatas => [
{ label => 'rtmax', template => '%.3f', min => 0, unit => 'ms' } { label => 'rtmax', template => '%.3f', min => 0, unit => 'ms' }
] ]
} }
}, },
{ label => 'rtmin', nlabel => 'response.time.max', display_ok => 0, set => { { label => 'rtmin', nlabel => 'roundtrip.time.minimum.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'rtmin' } ], key_values => [ { name => 'rtmin' } ],
perfdatas => [ perfdatas => [
{ label => 'rtmin', template => '%.3f', min => 0, unit => 'ms' } { label => 'rtmin', template => '%.3f', min => 0, unit => 'ms' }
@ -77,12 +77,12 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"timeout:s" => { name => 'timeout' }, 'timeout:s' => { name => 'timeout' },
"packets:s" => { name => 'packets' } 'packets:s' => { name => 'packets' }
}); });
return $self; return $self;
} }
@ -98,7 +98,7 @@ sub check_options {
if (defined($self->{option_results}->{packets}) && $self->{option_results}->{packets} =~ /(\d+)/) { if (defined($self->{option_results}->{packets}) && $self->{option_results}->{packets} =~ /(\d+)/) {
$self->{option_packets} = $1; $self->{option_packets} = $1;
} }
$options{snmp}->set_snmp_connect_params(Timeout => $self->{option_timeout} * (10**6)); $options{snmp}->set_snmp_connect_params(Timeout => $self->{option_timeout} * (10**6));
$options{snmp}->set_snmp_connect_params(Retries => 0); $options{snmp}->set_snmp_connect_params(Retries => 0);
$options{snmp}->set_snmp_params(subsetleef => 1); $options{snmp}->set_snmp_params(subsetleef => 1);
@ -106,8 +106,8 @@ sub check_options {
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $sysDescr = ".1.3.6.1.2.1.1.1.0"; my $sysDescr = '.1.3.6.1.2.1.1.1.0';
my $total_time_elapsed = 0; my $total_time_elapsed = 0;
my $max_time_elapsed = 0; my $max_time_elapsed = 0;
my $min_time_elapsed = 0; my $min_time_elapsed = 0;
@ -116,7 +116,7 @@ sub manage_selection {
my $timing0 = [gettimeofday]; my $timing0 = [gettimeofday];
my $return = $options{snmp}->get_leef(oids => [$sysDescr], nothing_quit => 0, dont_quit => 1); my $return = $options{snmp}->get_leef(oids => [$sysDescr], nothing_quit => 0, dont_quit => 1);
my $timeelapsed = tv_interval($timing0, [gettimeofday]); my $timeelapsed = tv_interval($timing0, [gettimeofday]);
if (!defined($return)) { if (!defined($return)) {
$total_packet_lost++; $total_packet_lost++;
} else { } else {
@ -130,7 +130,7 @@ sub manage_selection {
rta => ($self->{option_packets} > $total_packet_lost) ? $total_time_elapsed * 1000 / ($self->{option_packets} - $total_packet_lost) : 0, rta => ($self->{option_packets} > $total_packet_lost) ? $total_time_elapsed * 1000 / ($self->{option_packets} - $total_packet_lost) : 0,
rtmax => $max_time_elapsed * 1000, rtmax => $max_time_elapsed * 1000,
rtmin => $min_time_elapsed * 1000, rtmin => $min_time_elapsed * 1000,
pl => int($total_packet_lost * 100 / $self->{option_packets}), pl => int($total_packet_lost * 100 / $self->{option_packets})
}; };
} }

View File

@ -30,16 +30,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("%s", $self->{result_values}->{message}); return sprintf('%s', $self->{result_values}->{message});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{message} = $options{new_datas}->{$self->{instance} . '_message'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
return 0;
} }
sub set_counters { sub set_counters {
@ -51,11 +42,10 @@ sub set_counters {
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ {
label => 'status', label => 'status',
type => 2 type => 2,
critical_default => '%{message} !~ /authentification succeeded/i', critical_default => '%{message} !~ /authentification succeeded/i',
set => { set => {
key_values => [ { name => 'status' }, { name => 'message' } ], key_values => [ { name => 'status' }, { name => 'message' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng closure_custom_threshold_check => \&catalog_status_threshold_ng
@ -76,7 +66,7 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
}); });

View File

@ -34,7 +34,7 @@ sub new {
'login' => 'apps::protocols::ssh::mode::login' 'login' => 'apps::protocols::ssh::mode::login'
}; };
$self->{custom_modes}{api} = 'centreon::common::protocols::ssh::custom::api'; $self->{custom_modes}->{api} = 'centreon::common::protocols::ssh::custom::api';
return $self; return $self;
} }