fix mikrotik firmware

This commit is contained in:
garnier-quentin 2020-12-01 11:12:20 +01:00
parent 330818ff2c
commit 2da6b2a018
1 changed files with 22 additions and 38 deletions

View File

@ -24,82 +24,66 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
"'%s': software is '%s', firmware is '%s'",
$self->{result_values}->{model},
$self->{result_values}->{software_version},
$self->{result_values}->{firmware_version}
);
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 1, cb_prefix_output => 'prefix_output' } { name => 'global', type => 0 }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'status', set => { { label => 'status', type => 2, warning_default => '%{firmware_version} ne %{software_version}', set => {
key_values => [ key_values => [
{ name => 'model' }, { name => 'software_version' }, { name => 'model' }, { name => 'software_version' },
{ name => 'firmware_version' }, { name => 'firmware_version_update' } { name => 'firmware_version' }, { name => 'firmware_version_update' }
], ],
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
} }
]; ];
} }
sub custom_status_output {
my ($self, %options) = @_;
return 'software is \'' . $self->{result_values}->{software_version} . '\', firmware is \'' . $self->{result_values}->{firmware_version} . '\''
}
sub prefix_output {
my ($self, %options) = @_;
return '\'' . $options{instance_value}->{model} . '\' : ';
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'warning-status:s' => { name => 'warning_status', default => '%{firmware_version} ne %{software_version}' },
'critical-status:s' => { name => 'critical_status', default => '' },
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
my $mapping = { my $mapping = {
sysDescr => { oid => '.1.3.6.1.2.1.1.1' }, model => { oid => '.1.3.6.1.2.1.1.1' }, # sysDescr
mtxrLicVersion => { oid => '.1.3.6.1.4.1.14988.1.1.4.4' }, software_version => { oid => '.1.3.6.1.4.1.14988.1.1.4.4' }, # mtxrLicVersion
mtxrFirmwareVersion => { oid => '.1.3.6.1.4.1.14988.1.1.7.4' }, firmware_version => { oid => '.1.3.6.1.4.1.14988.1.1.7.4' }, # mtxrFirmwareVersion
mtxrFirmwareUpgradeVersion => { oid => '.1.3.6.1.4.1.14988.1.1.7.7' } firmware_version_update => { oid => '.1.3.6.1.4.1.14988.1.1.7.7' } # mtxrFirmwareUpgradeVersion
}; };
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $results = $options{snmp}->get_leef( my $snmp_result = $options{snmp}->get_leef(
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
nothing_quit => 1 nothing_quit => 1
); );
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => 0); $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0);
$self->{global}->{0}->{model} = $result->{sysDescr};
$self->{global}->{0}->{software_version} = $result->{mtxrLicVersion};
$self->{global}->{0}->{firmware_version} = $result->{mtxrFirmwareVersion};
$self->{global}->{0}->{firmware_version_update} = $result->{mtxrFirmwareUpgradeVersion};
} }
1; 1;
@ -108,7 +92,7 @@ __END__
=head1 MODE =head1 MODE
Check firmware status Check firmware status.
=over 8 =over 8