From 18a4c2a9facd4b6838acd52b33218284edd6ee09 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 28 Oct 2020 15:58:46 +0100 Subject: [PATCH] enhance mikrotik (#2299) --- .../mikrotik/snmp/mode/components/current.pm | 20 +++++----- .../mikrotik/snmp/mode/components/fan.pm | 15 ++++--- .../mikrotik/snmp/mode/components/psu.pm | 20 +++++----- .../snmp/mode/components/temperature.pm | 40 ++++++++++--------- .../mikrotik/snmp/mode/components/voltage.pm | 19 +++++---- 5 files changed, 63 insertions(+), 51 deletions(-) diff --git a/centreon-plugins/network/mikrotik/snmp/mode/components/current.pm b/centreon-plugins/network/mikrotik/snmp/mode/components/current.pm index afc210440..ceed74011 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/components/current.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/components/current.pm @@ -68,15 +68,7 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => 0); - if (defined($result->{mtxrHlCurrent}) && $result->{mtxrHlCurrent} =~ /[0-9]+/) { - check_current( - $self, - value => $result->{mtxrHlCurrent} / 100, - instance => 1, - name => 'system' - ); - } - + my $gauge_ok = 0; foreach (keys %{$self->{results}}) { next if (! /^$mapping_gauge->{unit}->{oid}\.(\d+)/); next if ($map_gauge_unit->{ $self->{results}->{$_} } ne 'dA'); @@ -88,6 +80,16 @@ sub check { instance => $1, name => $result->{name} ); + $gauge_ok = 1; + } + + if ($gauge_ok == 0 && defined($result->{mtxrHlCurrent}) && $result->{mtxrHlCurrent} =~ /[0-9]+/) { + check_current( + $self, + value => $result->{mtxrHlCurrent} / 100, + instance => 1, + name => 'system' + ); } } diff --git a/centreon-plugins/network/mikrotik/snmp/mode/components/fan.pm b/centreon-plugins/network/mikrotik/snmp/mode/components/fan.pm index 5208b542c..233a9b7db 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/components/fan.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/components/fan.pm @@ -67,19 +67,22 @@ sub check { return if ($self->check_filter(section => 'fan')); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => 0); - if (defined($result->{mtxrHlFanSpeed1}) && $result->{mtxrHlFanSpeed1} =~ /[0-9]+/) { - check_fan($self, value => $result->{mtxrHlFanSpeed1}, instance => 1); - } - if (defined($result->{mtxrHlFanSpeed2}) && $result->{mtxrHlFanSpeed2} =~ /[0-9]+/) { - check_fan($self, value => $result->{mtxrHlFanSpeed2}, instance => 2); - } + my $gauge_ok = 0; foreach (keys %{$self->{results}}) { next if (! /^$mapping_gauge->{unit}->{oid}\.(\d+)/); next if ($map_gauge_unit->{ $self->{results}->{$_} } ne 'rpm'); $result = $self->{snmp}->map_instance(mapping => $mapping_gauge, results => $self->{results}, instance => $1); check_fan($self, value => $result->{value}, instance => $result->{name}); + $gauge_ok = 1; + } + + if ($gauge_ok == 0 && defined($result->{mtxrHlFanSpeed1}) && $result->{mtxrHlFanSpeed1} =~ /[0-9]+/) { + check_fan($self, value => $result->{mtxrHlFanSpeed1}, instance => 1); + } + if ($gauge_ok == 0 && defined($result->{mtxrHlFanSpeed2}) && $result->{mtxrHlFanSpeed2} =~ /[0-9]+/) { + check_fan($self, value => $result->{mtxrHlFanSpeed2}, instance => 2); } } diff --git a/centreon-plugins/network/mikrotik/snmp/mode/components/psu.pm b/centreon-plugins/network/mikrotik/snmp/mode/components/psu.pm index 3492c91e1..9e8a71869 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/components/psu.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/components/psu.pm @@ -98,15 +98,7 @@ sub check { check_psu($self, value => $result->{mtxrHlPowerSupplyState}, type => 'primary'); check_psu($self, value => $result->{mtxrHlBackupPowerSupplyState}, type => 'backup'); - if (defined($result->{mtxrHlPower}) && $result->{mtxrHlPower} =~ /[0-9]+/) { - check_power( - $self, - value => $result->{mtxrHlPower} / 100, - instance => 1, - name => 'system' - ); - } - + my $gauge_ok = 0; foreach (keys %{$self->{results}}) { next if (! /^$mapping_gauge->{unit}->{oid}\.(\d+)/); next if ($map_gauge_unit->{ $self->{results}->{$_} } ne 'dW'); @@ -118,6 +110,16 @@ sub check { instance => $1, name => $result->{name} ); + $gauge_ok = 1; + } + + if ($gauge_ok == 0 && defined($result->{mtxrHlPower}) && $result->{mtxrHlPower} =~ /[0-9]+/) { + check_power( + $self, + value => $result->{mtxrHlPower} / 100, + instance => 1, + name => 'system' + ); } } diff --git a/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm b/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm index 9ca9232f4..6e2ace0fd 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm @@ -72,25 +72,7 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => 0); - if (defined($result->{mtxrHlTemperature}) && $result->{mtxrHlTemperature} =~ /[0-9]+/) { - check_temperature( - $self, - value => $result->{mtxrHlTemperature} / 10, - instance => 1, - name => 'system', - description => 'system temperature (SoC or PCB)' - ); - } - if (defined($result->{mtxrHlProcessorTemperature}) && $result->{mtxrHlProcessorTemperature} =~ /[0-9]+/) { - check_temperature( - $self, - value => $result->{mtxrHlProcessorTemperature} / 10, - instance => 2, - name => 'processor', - description => 'processor temperature' - ); - } - + my $gauge_ok = 0; foreach (keys %{$self->{results}}) { next if (! /^$mapping_gauge->{unit}->{oid}\.(\d+)/); next if ($map_gauge_unit->{ $self->{results}->{$_} } ne 'celsius'); @@ -103,6 +85,26 @@ sub check { name => $result->{name}, description => "sensor temperature '$result->{name}'" ); + $gauge_ok = 1; + } + + if ($gauge_ok == 0 && defined($result->{mtxrHlTemperature}) && $result->{mtxrHlTemperature} =~ /[0-9]+/) { + check_temperature( + $self, + value => $result->{mtxrHlTemperature} / 10, + instance => 1, + name => 'system', + description => 'system temperature (SoC or PCB)' + ); + } + if ($gauge_ok == 0 && defined($result->{mtxrHlProcessorTemperature}) && $result->{mtxrHlProcessorTemperature} =~ /[0-9]+/) { + check_temperature( + $self, + value => $result->{mtxrHlProcessorTemperature} / 10, + instance => 2, + name => 'processor', + description => 'processor temperature' + ); } } diff --git a/centreon-plugins/network/mikrotik/snmp/mode/components/voltage.pm b/centreon-plugins/network/mikrotik/snmp/mode/components/voltage.pm index e52db218b..e41b688de 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/components/voltage.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/components/voltage.pm @@ -67,15 +67,8 @@ sub check { return if ($self->check_filter(section => 'voltage')); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => 0); - if (defined($result->{mtxrHlVoltage}) && $result->{mtxrHlVoltage} =~ /[0-9]+/) { - check_voltage( - $self, - value => $result->{mtxrHlVoltage} / 10, - instance => 1, - name => 'system' - ); - } + my $gauge_ok = 0; foreach (keys %{$self->{results}}) { next if (! /^$mapping_gauge->{unit}->{oid}\.(\d+)/); next if ($map_gauge_unit->{ $self->{results}->{$_} } ne 'dV'); @@ -87,6 +80,16 @@ sub check { instance => $1, name => $result->{name} ); + $gauge_ok = 1; + } + + if ($gauge_ok == 0 && defined($result->{mtxrHlVoltage}) && $result->{mtxrHlVoltage} =~ /[0-9]+/) { + check_voltage( + $self, + value => $result->{mtxrHlVoltage} / 10, + instance => 1, + name => 'system' + ); } }