diff --git a/network/mikrotik/snmp/mode/components/current.pm b/network/mikrotik/snmp/mode/components/current.pm index 6c74247e2..f7f178256 100644 --- a/network/mikrotik/snmp/mode/components/current.pm +++ b/network/mikrotik/snmp/mode/components/current.pm @@ -27,13 +27,7 @@ my $mapping = { mtxrHlCurrent => { oid => '.1.3.6.1.4.1.14988.1.1.3.13' }, }; -my $oid_mtxrHealth = '.1.3.6.1.4.1.14988.1.1.3'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_mtxrHealth }; -} +sub load {} sub check { my ($self) = @_; @@ -44,7 +38,7 @@ sub check { my $instance = 0; my ($exit, $warn, $crit, $checked); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_mtxrHealth}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); if (defined($result->{mtxrHlCurrent}) && $result->{mtxrHlCurrent} =~ /[0-9]+/) { diff --git a/network/mikrotik/snmp/mode/components/fan.pm b/network/mikrotik/snmp/mode/components/fan.pm index ee730333a..c5dd733a4 100644 --- a/network/mikrotik/snmp/mode/components/fan.pm +++ b/network/mikrotik/snmp/mode/components/fan.pm @@ -28,13 +28,7 @@ my $mapping = { mtxrHlFanSpeed2 => { oid => '.1.3.6.1.4.1.14988.1.1.3.18' }, }; -my $oid_mtxrHealth = '.1.3.6.1.4.1.14988.1.1.3'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_mtxrHealth }; -} +sub load {} sub check { my ($self) = @_; @@ -45,7 +39,7 @@ sub check { my $instance = 0; my ($exit, $warn, $crit, $checked); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_mtxrHealth}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); if (defined($result->{mtxrHlFanSpeed1}) && $result->{mtxrHlFanSpeed1} =~ /[0-9]+/) { diff --git a/network/mikrotik/snmp/mode/components/power.pm b/network/mikrotik/snmp/mode/components/psu.pm similarity index 51% rename from network/mikrotik/snmp/mode/components/power.pm rename to network/mikrotik/snmp/mode/components/psu.pm index 7610d23e2..7ec16fcf0 100644 --- a/network/mikrotik/snmp/mode/components/power.pm +++ b/network/mikrotik/snmp/mode/components/psu.pm @@ -18,39 +18,60 @@ # limitations under the License. # -package network::mikrotik::snmp::mode::components::power; +package network::mikrotik::snmp::mode::components::psu; use strict; use warnings; +my $map_status = { 0 => 'false', 1 => 'true' }; + my $mapping = { - mtxrHlPower => { oid => '.1.3.6.1.4.1.14988.1.1.3.12' }, + mtxrHlPower => { oid => '.1.3.6.1.4.1.14988.1.1.3.12' }, + mtxrHlPowerSupplyState => { oid => '.1.3.6.1.4.1.14988.1.1.3.15', map => $map_status }, + mtxrHlBackupPowerSupplyState => { oid => '.1.3.6.1.4.1.14988.1.1.3.16', map => $map_status }, }; -my $oid_mtxrHealth = '.1.3.6.1.4.1.14988.1.1.3'; +sub load {} -sub load { - my ($self) = @_; +sub check_psu { + my ($self, %options) = @_; - push @{$self->{request}}, { oid => $oid_mtxrHealth }; + return if (!defined($options{value})); + + $self->{output}->output_add( + long_msg => sprintf( + "psu %s status is '%s'", + $options{type}, $options{value}, + ) + ); + + my $exit = $self->get_severity(section => 'psu.' . $options{type}, value => $options{value}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("psu %s status is '%s'", $options{type}, $options{value})); + } + + $self->{components}->{psu}->{total}++; } sub check { my ($self) = @_; - $self->{output}->output_add(long_msg => "Checking power"); - $self->{components}->{power} = {name => 'power', total => 0, skip => 0}; - return if ($self->check_filter(section => 'power')); + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psu', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); - my $instance = 0; + my $instance = '0'; my ($exit, $warn, $crit, $checked); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_mtxrHealth}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + check_psu($self, value => $result->{mtxrHlPowerSupplyState}, type => 'primary'); + check_psu($self, value => $result->{mtxrHlBackupPowerSupplyState}, type => 'backup'); if (defined($result->{mtxrHlPower}) && $result->{mtxrHlPower} =~ /[0-9]+/) { - $self->{output}->output_add(long_msg => sprintf("Power is '%s' W", $result->{mtxrHlPower})); - ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'power', instance => $instance, value => $result->{mtxrHlPower}); + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'psu', instance => $instance, value => $result->{mtxrHlPower}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Power is '%s' W", $result->{mtxrHlPower})); @@ -59,7 +80,7 @@ sub check { value => $result->{mtxrHlPower}, warning => $warn, critical => $crit); - $self->{components}->{power}->{total}++; + $self->{components}->{psu}->{total}++; } } diff --git a/network/mikrotik/snmp/mode/components/temperature.pm b/network/mikrotik/snmp/mode/components/temperature.pm index b294921ec..89fd24587 100644 --- a/network/mikrotik/snmp/mode/components/temperature.pm +++ b/network/mikrotik/snmp/mode/components/temperature.pm @@ -28,13 +28,7 @@ my $mapping = { mtxrHlProcessorTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.11' }, }; -my $oid_mtxrHealth = '.1.3.6.1.4.1.14988.1.1.3'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_mtxrHealth }; -} +sub load {} sub check { my ($self) = @_; @@ -45,7 +39,7 @@ sub check { my $instance = 0; my ($exit, $warn, $crit, $checked); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_mtxrHealth}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); if (defined($result->{mtxrHlTemperature}) && $result->{mtxrHlTemperature} =~ /[0-9]+/) { diff --git a/network/mikrotik/snmp/mode/components/voltage.pm b/network/mikrotik/snmp/mode/components/voltage.pm index 85d428992..25949e3e7 100644 --- a/network/mikrotik/snmp/mode/components/voltage.pm +++ b/network/mikrotik/snmp/mode/components/voltage.pm @@ -27,13 +27,7 @@ my $mapping = { mtxrHlVoltage => { oid => '.1.3.6.1.4.1.14988.1.1.3.8' }, }; -my $oid_mtxrHealth = '.1.3.6.1.4.1.14988.1.1.3'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_mtxrHealth }; -} +sub load {} sub check { my ($self) = @_; @@ -44,7 +38,7 @@ sub check { my $instance = 0; my ($exit, $warn, $crit, $checked); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_mtxrHealth}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); if (defined($result->{mtxrHlVoltage}) && $result->{mtxrHlVoltage} =~ /[0-9]+/) { diff --git a/network/mikrotik/snmp/mode/environment.pm b/network/mikrotik/snmp/mode/environment.pm index af3551795..ef3896a90 100644 --- a/network/mikrotik/snmp/mode/environment.pm +++ b/network/mikrotik/snmp/mode/environment.pm @@ -28,19 +28,30 @@ use warnings; sub set_system { my ($self, %options) = @_; - $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|voltage|fan|current|power)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|voltage|fan|current|psu)$'; $self->{cb_hook2} = 'snmp_execute'; + $self->{thresholds} = { + 'psu.primary' => [ + ['true', 'OK'], + ['false', 'CRITICAL'], + ], + 'psu.backup' => [ + ['true', 'OK'], + ['false', 'CRITICAL'], + ], + }; $self->{components_path} = 'network::mikrotik::snmp::mode::components'; - $self->{components_module} = ['current', 'fan', 'power', 'temperature', 'voltage']; + $self->{components_module} = ['current', 'fan', 'psu', 'temperature', 'voltage']; } sub snmp_execute { my ($self, %options) = @_; + my $oid_mtxrHealth = '.1.3.6.1.4.1.14988.1.1.3'; $self->{snmp} = $options{snmp}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + $self->{results} = $self->{snmp}->get_table(oid => $oid_mtxrHealth); } sub new { @@ -49,10 +60,9 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); - + $options{options}->add_options(arguments => { + }); + return $self; } @@ -86,7 +96,6 @@ Can be specific or global: --absent-problem=fan,1 Return an error if no compenents are checked. If total (with skipped) is 0. (Default: 'critical' returns). - =item B<--warning> Set warning threshold for 'temperature', 'fan', 'voltage' (syntax: type,regexp,threshold)