From 3d378d80b135e0ae5f8cdea7394e77c78fcf6af9 Mon Sep 17 00:00:00 2001
From: garnier-quentin <garnier.quentin@gmail.com>
Date: Wed, 8 Jul 2020 12:01:07 +0200
Subject: [PATCH] try to update synology

---
 storage/synology/snmp/mode/components/fan.pm    | 12 +++++-------
 storage/synology/snmp/mode/components/psu.pm    |  7 +++++--
 storage/synology/snmp/mode/components/system.pm | 11 +++++++----
 storage/synology/snmp/mode/hardware.pm          |  9 ++++++++-
 4 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/storage/synology/snmp/mode/components/fan.pm b/storage/synology/snmp/mode/components/fan.pm
index 3699237ee..080dc5fb4 100644
--- a/storage/synology/snmp/mode/components/fan.pm
+++ b/storage/synology/snmp/mode/components/fan.pm
@@ -34,9 +34,7 @@ my $oid_fan = '.1.3.6.1.4.1.6574.1.4';
 sub load {
     my ($self) = @_;
     
-    push @{$self->{request}}, {
-        oid => $oid_fan
-    };
+    push @{$self->{request_leef}}, $mapping->{synoSystemsystemFanStatus}->{oid} . '.0', $mapping->{synoSystemcpuFanStatus}->{oid} . '.0';
 }
 
 sub check {
@@ -45,9 +43,9 @@ sub check {
     $self->{output}->output_add(long_msg => "Checking cpu fan");
     $self->{components}->{fan} = {name => 'fan', total => 0, skip => 0};
     return if ($self->check_filter(section => 'fan'));
-    
-    my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fan}, instance => '0');
-    if (!$self->check_filter(section => 'fan', instance => 'cpu')) {
+
+    my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_leef}, instance => '0');
+    if (defined($result->{synoSystemcpuFanStatus}) && !$self->check_filter(section => 'fan', instance => 'cpu')) {
         $self->{components}->{fan}->{total}++;
 
         $self->{output}->output_add(
@@ -65,7 +63,7 @@ sub check {
         }
     }
     
-    if (!$self->check_filter(section => 'fan', instance => 'system')) {
+    if (defined($result->{synoSystemsystemFanStatus}) && !$self->check_filter(section => 'fan', instance => 'system')) {
         $self->{components}->{fan}->{total}++;
         $self->{output}->output_add(
             long_msg => sprintf(
diff --git a/storage/synology/snmp/mode/components/psu.pm b/storage/synology/snmp/mode/components/psu.pm
index 79de4b355..a72f56a1b 100644
--- a/storage/synology/snmp/mode/components/psu.pm
+++ b/storage/synology/snmp/mode/components/psu.pm
@@ -32,7 +32,7 @@ my $mapping = {
 sub load {
     my ($self) = @_;
     
-    push @{$self->{request}}, { oid => $mapping->{synoSystempowerStatus}->{oid} };
+    push @{$self->{request_leef}}, $mapping->{synoSystempowerStatus}->{oid} . '.0';
 }
 
 sub check {
@@ -41,9 +41,12 @@ sub check {
     $self->{output}->output_add(long_msg => "Checking power supply");
     $self->{components}->{psu} = {name => 'psu', total => 0, skip => 0};
     return if ($self->check_filter(section => 'psu'));
+
+    my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_leef}, instance => '0');
+    return if (!defined($result->{synoSystempowerStatus}));
+
     $self->{components}->{psu}->{total}++;
 
-    my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{synoSystempowerStatus}->{oid}}, instance => '0');
     $self->{output}->output_add(
         long_msg => sprintf(
             "power supply status is %s.",
diff --git a/storage/synology/snmp/mode/components/system.pm b/storage/synology/snmp/mode/components/system.pm
index 86cd527d0..faa0d7942 100644
--- a/storage/synology/snmp/mode/components/system.pm
+++ b/storage/synology/snmp/mode/components/system.pm
@@ -26,13 +26,13 @@ use warnings;
 my $map_status = { 1 => 'Normal', 2 => 'Failed' };
 
 my $mapping = {
-    synoSystemsystemStatus => { oid => '.1.3.6.1.4.1.6574.1.1', map => $map_status  }
+    synoSystemsystemStatus => { oid => '.1.3.6.1.4.1.6574.1.1', map => $map_status }
 };
 
 sub load {
     my ($self) = @_;
-    
-    push @{$self->{request}}, { oid => $mapping->{synoSystemsystemStatus}->{oid} };
+
+    push @{$self->{request_leef}}, $mapping->{synoSystemsystemStatus}->{oid} . '.0';
 }
 
 sub check {
@@ -41,9 +41,12 @@ sub check {
     $self->{output}->output_add(long_msg => "Checking system partition status");
     $self->{components}->{system} = {name => 'system', total => 0, skip => 0};
     return if ($self->check_filter(section => 'system'));
+
+    my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_leef}, instance => '0');
+    return if (!defined($result->{synoSystemsystemStatus}));
+
     $self->{components}->{system}->{total}++;
 
-    my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{synoSystemsystemStatus}->{oid}}, instance => '0');
     $self->{output}->output_add(
         long_msg => sprintf(
             "system partition status is %s.",
diff --git a/storage/synology/snmp/mode/hardware.pm b/storage/synology/snmp/mode/hardware.pm
index cb6d2bbd2..53558005f 100644
--- a/storage/synology/snmp/mode/hardware.pm
+++ b/storage/synology/snmp/mode/hardware.pm
@@ -72,13 +72,20 @@ sub set_system {
     
     $self->{components_path} = 'storage::synology::snmp::mode::components';
     $self->{components_module} = ['psu', 'fan', 'disk', 'raid', 'system'];
+
+    $self->{request_leef} = [];
 }
 
 sub snmp_execute {
     my ($self, %options) = @_;
     
     $self->{snmp} = $options{snmp};
-    $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
+    if (scalar(@{$self->{request}}) > 0) {
+        $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
+    }
+    if (scalar(@{$self->{request_leef}}) > 0) {
+        $self->{results_leef} = $self->{snmp}->get_leef(oids => $self->{request_leef});
+    }
 }
 
 sub new {