From 53a16dacd81ed1848265d868e66fe10cd5a71c11 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Date: Thu, 22 Dec 2016 12:54:17 +0100 Subject: [PATCH 1/3] To remove the line breaks in the description. Example: '.1.3.6.1.2.1.47.1.1.1.1.2.4954' => 'FixedModule-1 Port-5', '.1.3.6.1.2.1.47.1.1.1.1.2.21598' => 'PowerSupply-1 Sensor-1 ', '.1.3.6.1.2.1.47.1.1.1.1.2.4953' => 'FixedModule-1 Port-4', '.1.3.6.1.2.1.47.1.1.1.1.2.149' => 'Nexus5020 Chassis', --- centreon/common/cisco/standard/snmp/mode/environment.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/centreon/common/cisco/standard/snmp/mode/environment.pm b/centreon/common/cisco/standard/snmp/mode/environment.pm index bbc007155..57c30a10c 100644 --- a/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -123,6 +123,9 @@ sub snmp_execute { push @{$self->{request}}, { oid => $oid_entPhysicalDescr }, { oid => $oid_ciscoEnvMonPresent }; $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + foreach my $k (keys(%{$self->{results}->{$oid_entPhysicalDescr}})) { + $self->{results}->{$oid_entPhysicalDescr}->{$k} =~ s/^\s+|\s+$|[\n\r]+//g; + } $self->{output}->output_add(long_msg => sprintf("Environment type: %s", defined($self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}) && defined($map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} ) ? $map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} : 'unknown')); From 7452038113fb04f11efa6967e3d7b11b1ee3eb2a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Date: Thu, 22 Dec 2016 15:07:06 +0100 Subject: [PATCH 2/3] Use centreon::plugins::misc::trim() --- centreon/common/cisco/standard/snmp/mode/environment.pm | 4 ++-- centreon/plugins/misc.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon/common/cisco/standard/snmp/mode/environment.pm b/centreon/common/cisco/standard/snmp/mode/environment.pm index 57c30a10c..764d66bf6 100644 --- a/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -123,8 +123,8 @@ sub snmp_execute { push @{$self->{request}}, { oid => $oid_entPhysicalDescr }, { oid => $oid_ciscoEnvMonPresent }; $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); - foreach my $k (keys(%{$self->{results}->{$oid_entPhysicalDescr}})) { - $self->{results}->{$oid_entPhysicalDescr}->{$k} =~ s/^\s+|\s+$|[\n\r]+//g; + while (my ($key, $value) = each %{$self->{results}->{$oid_entPhysicalDescr}}) { + $self->{results}->{$oid_entPhysicalDescr}->{$key} = centreon::plugins::misc::trim($value); } $self->{output}->output_add(long_msg => sprintf("Environment type: %s", defined($self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}) && defined($map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} ) ? diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm index a32abb0b7..add26b8ed 100644 --- a/centreon/plugins/misc.pm +++ b/centreon/plugins/misc.pm @@ -314,8 +314,8 @@ sub trim { # Sometimes there is a null character $value =~ s/\x00$//; - $value =~ s/^[ \t]+//; - $value =~ s/[ \t]+$//; + $value =~ s/^[ \t\n]+//; + $value =~ s/[ \t\n]+$//; return $value; } From 6d32a62c21220aaf4e6acbddc421517ed2334e52 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Date: Thu, 22 Dec 2016 17:11:10 +0100 Subject: [PATCH 3/3] use centreon::plugins::misc; --- centreon/common/cisco/standard/snmp/mode/environment.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/centreon/common/cisco/standard/snmp/mode/environment.pm b/centreon/common/cisco/standard/snmp/mode/environment.pm index 764d66bf6..cac1560e6 100644 --- a/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::hardware); use strict; use warnings; +use centreon::plugins::misc; sub set_system { my ($self, %options) = @_;