From f579955ca5a08e098015f5229e17927c273f3786 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 28 Sep 2022 13:20:42 +0200 Subject: [PATCH] (plugin) network::brocade::snmp - use new perfdata (#3933) --- .../network/brocade/snmp/mode/cpu.pm | 56 ++++++++++--------- .../network/brocade/snmp/mode/hardware.pm | 4 +- .../network/brocade/snmp/mode/interfaces.pm | 2 +- .../network/brocade/snmp/mode/memory.pm | 56 ++++++++++--------- 4 files changed, 65 insertions(+), 53 deletions(-) diff --git a/centreon-plugins/network/brocade/snmp/mode/cpu.pm b/centreon-plugins/network/brocade/snmp/mode/cpu.pm index 425d0ad43..76477e164 100644 --- a/centreon-plugins/network/brocade/snmp/mode/cpu.pm +++ b/centreon-plugins/network/brocade/snmp/mode/cpu.pm @@ -27,14 +27,13 @@ use warnings; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical' } + }); return $self; } @@ -42,14 +41,14 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } } @@ -60,7 +59,7 @@ sub run { my $oid_swFwFabricWatchLicense = '.1.3.6.1.4.1.1588.2.1.1.1.10.1.0'; my $oid_swCpuUsage = '.1.3.6.1.4.1.1588.2.1.1.1.26.1.0'; my $result = $self->{snmp}->get_leef(oids => [$oid_swFwFabricWatchLicense, $oid_swCpuUsage], nothing_quit => 1); - + if (!defined($result->{$oid_swCpuUsage})) { if ($result->{$oid_swFwFabricWatchLicense} == 2) { $self->{output}->add_option_msg(short_msg => "Need Fabric Watch License to get information."); @@ -69,17 +68,25 @@ sub run { $self->{output}->add_option_msg(short_msg => "Cannot get information."); $self->{output}->option_exit(); } - - my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_swCpuUsage}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("CPU Usage: %.2f%%", $result->{$oid_swCpuUsage})); - $self->{output}->perfdata_add(label => "cpu", unit => '%', - value => $result->{$oid_swCpuUsage}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - + + my $exit = $self->{perfdata}->threshold_check( + value => $result->{$oid_swCpuUsage}, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("CPU Usage: %.2f%%", $result->{$oid_swCpuUsage}) + ); + $self->{output}->perfdata_add( + nlabel => 'cpu.utilization.percentage', + unit => '%', + value => $result->{$oid_swCpuUsage}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, + max => 100 + ); + $self->{output}->display(); $self->{output}->exit(); } @@ -105,4 +112,3 @@ Threshold critical in percent. =back =cut - \ No newline at end of file diff --git a/centreon-plugins/network/brocade/snmp/mode/hardware.pm b/centreon-plugins/network/brocade/snmp/mode/hardware.pm index 8599c1c49..5811b0732 100644 --- a/centreon-plugins/network/brocade/snmp/mode/hardware.pm +++ b/centreon-plugins/network/brocade/snmp/mode/hardware.pm @@ -56,7 +56,7 @@ sub set_system { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_load_components => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_load_components => 1, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => {}); @@ -189,8 +189,8 @@ sub check { } $self->{output}->perfdata_add( - label => 'sensor', unit => $map_unit{$result->{swSensorType}}, nlabel => 'hardware.sensor.' . $result->{swSensorType} . '.' . $map_unit{$result->{swSensorType}}, + unit => $map_unit{$result->{swSensorType}}, instances => $result->{swSensorInfo}, value => $result->{swSensorValue}, warning => $warn, diff --git a/centreon-plugins/network/brocade/snmp/mode/interfaces.pm b/centreon-plugins/network/brocade/snmp/mode/interfaces.pm index 5d061f880..c6c7d01ac 100644 --- a/centreon-plugins/network/brocade/snmp/mode/interfaces.pm +++ b/centreon-plugins/network/brocade/snmp/mode/interfaces.pm @@ -88,7 +88,7 @@ sub set_counters_errors { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perdata => 1); bless $self, $class; $options{options}->add_options(arguments => { diff --git a/centreon-plugins/network/brocade/snmp/mode/memory.pm b/centreon-plugins/network/brocade/snmp/mode/memory.pm index 2e2b45a17..034f3e01f 100644 --- a/centreon-plugins/network/brocade/snmp/mode/memory.pm +++ b/centreon-plugins/network/brocade/snmp/mode/memory.pm @@ -27,14 +27,13 @@ use warnings; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical' } + }); return $self; } @@ -42,14 +41,14 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } } @@ -60,7 +59,7 @@ sub run { my $oid_swFwFabricWatchLicense = '.1.3.6.1.4.1.1588.2.1.1.1.10.1.0'; my $oid_swMemUsage = '.1.3.6.1.4.1.1588.2.1.1.1.26.6.0'; my $result = $self->{snmp}->get_leef(oids => [$oid_swFwFabricWatchLicense, $oid_swMemUsage], nothing_quit => 1); - + if (!defined($result->{$oid_swMemUsage})) { if ($result->{$oid_swFwFabricWatchLicense} == 2) { $self->{output}->add_option_msg(short_msg => "Need Fabric Watch License to get information."); @@ -69,17 +68,25 @@ sub run { $self->{output}->add_option_msg(short_msg => "Cannot get information."); $self->{output}->option_exit(); } - - my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_swMemUsage}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Memory Usage: %.2f%% used", $result->{$oid_swMemUsage})); - $self->{output}->perfdata_add(label => "used", unit => '%', - value => $result->{$oid_swMemUsage}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - + + my $exit = $self->{perfdata}->threshold_check( + value => $result->{$oid_swMemUsage}, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Memory Usage: %.2f%% used", $result->{$oid_swMemUsage}) + ); + $self->{output}->perfdata_add( + nlabel => 'memory.usage.percentage', + unit => '%', + value => $result->{$oid_swMemUsage}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, + max => 100 + ); + $self->{output}->display(); $self->{output}->exit(); } @@ -105,4 +112,3 @@ Threshold critical in percent. =back =cut - \ No newline at end of file