update mikrotik signal code

This commit is contained in:
garnier-quentin 2019-11-26 13:55:58 +01:00
parent 272d36c1e7
commit fa0da256df
4 changed files with 70 additions and 129 deletions

View File

@ -230,6 +230,10 @@ my $mapping2 = {
cbQosTSCfgRate => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.1' }, # bps
cbQosTSCfgRate64 => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.11' }, # bps
};
my $mapping3 = {
cbQosQueueingCfgBandwidth => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.1' },
cbQosQueueingCfgBandwidthUnits => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.2' },
};
my $oid_cbQosIfIndex = '.1.3.6.1.4.1.9.9.166.1.1.1.1.4';
my $oid_cbQosConfigIndex = '.1.3.6.1.4.1.9.9.166.1.5.1.1.2';
@ -242,8 +246,7 @@ my $oid_cbQosPolicyMapName = '.1.3.6.1.4.1.9.9.166.1.6.1.1.1';
# Shaping : Linked to a classmap
my $oid_cbQosTSCfgEntry = '.1.3.6.1.4.1.9.9.166.1.13.1.1';
# Linked to a classmap
my $oid_cbQosQueueingCfgBandwidth = '.1.3.6.1.4.1.9.9.166.1.9.1.1.1';
my $oid_cbQosQueueingCfgBandwidthUnits = '.1.3.6.1.4.1.9.9.166.1.9.1.1.2';
my $oid_cbQosQueueingCfgEntry = '.1.3.6.1.4.1.9.9.166.1.9.1.1';
sub build_qos_information {
my ($self, %options) = @_;
@ -288,11 +291,10 @@ sub manage_selection {
{ oid => $oid_cbQosIfIndex },
{ oid => $oid_cbQosConfigIndex },
{ oid => $oid_cbQosCMName },
{ oid => $oid_cbQosQueueingCfgBandwidth },
{ oid => $oid_cbQosQueueingCfgBandwidthUnits },
{ oid => $oid_cbQosCMStatsEntry },
{ oid => $oid_cbQosQueueingCfgEntry, end => $mapping3->{cbQosQueueingCfgBandwidthUnits}->{oid} },
{ oid => $oid_cbQosCMStatsEntry, start => $mapping->{cbQosCMPrePolicyByteOverflow}->{oid}, end => $mapping->{cbQosCMDropByte64}->{oid} },
{ oid => $oid_cbQosParentObjectsIndex },
{ oid => $oid_cbQosTSCfgEntry },
{ oid => $oid_cbQosTSCfgEntry, end => $mapping2->{cbQosTSCfgRate64}->{oid} },
];
push @$request_oids, { oid => $self->{oids_label}->{$self->{option_results}->{oid_display}} }
if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display});
@ -309,7 +311,7 @@ sub manage_selection {
foreach (keys %{$self->{results}->{$oid_cbQosParentObjectsIndex}}) {
/(\d+)\.(\d+)$/;
my $config_index = $self->{results}->{$oid_cbQosConfigIndex}->{$oid_cbQosConfigIndex . '.' . $1 . '.' . $2};
if (defined($self->{results}->{$oid_cbQosQueueingCfgBandwidth}->{$oid_cbQosQueueingCfgBandwidth . '.' . $config_index})) {
if (defined($self->{results}->{$oid_cbQosQueueingCfgEntry}->{$mapping3->{cbQosQueueingCfgBandwidth}->{oid} . '.' . $config_index})) {
$link_queueing->{$1 . '.' . $self->{results}->{$oid_cbQosParentObjectsIndex}->{$_}} = $config_index;
} elsif (defined($self->{results}->{$oid_cbQosTSCfgEntry}->{$mapping2->{cbQosTSCfgRate}->{oid} . '.' . $config_index})) {
$link_shaping->{$1 . '.' . $self->{results}->{$oid_cbQosParentObjectsIndex}->{$_}} = $config_index;
@ -320,7 +322,7 @@ sub manage_selection {
next if (!/$mapping->{cbQosCMPrePolicyByte}->{oid}\.(\d+)\.(\d+)/);
my ($policy_index, $qos_object_index) = ($1, $2);
my $class_name = $classmap_name{$policy_index . '.' . $qos_object_index};
my $if_index = $self->{results}->{$oid_cbQosIfIndex}->{$oid_cbQosIfIndex . '.' . $policy_index};
if (!defined($self->{results}->{$self->{oids_label}->{$self->{option_results}->{oid_display}}}->{$self->{oids_label}->{$self->{option_results}->{oid_display}} . '.' . $if_index})) {
@ -333,7 +335,7 @@ sub manage_selection {
$self->{output}->output_add(long_msg => "skipping interface index '" . $if_index . "': no filter name.", debug => 1);
next;
}
my $qos_data = $self->build_qos_information(class_name => $class_name, policy_index => $policy_index, object_index => $qos_object_index,
link_queueing => $link_queueing, link_shaping => $link_shaping);

View File

@ -30,11 +30,10 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"oid-filter:s" => { name => 'oid_filter', default => 'ifname' },
"oid-display:s" => { name => 'oid_display', default => 'ifname' },
});
$options{options}->add_options(arguments => {
'oid-filter:s' => { name => 'oid_filter', default => 'ifname' },
'oid-display:s' => { name => 'oid_display', default => 'ifname' },
});
$self->{oids_label} = {
'ifdesc' => '.1.3.6.1.2.1.2.2.1.2',
@ -85,8 +84,10 @@ sub run {
}
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'Frequencies:');
$self->{output}->output_add(
severity => 'OK',
short_msg => 'Frequencies:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();

View File

@ -30,11 +30,10 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"oid-filter:s" => { name => 'oid_filter', default => 'ifname' },
"oid-display:s" => { name => 'oid_display', default => 'ifname' },
});
$options{options}->add_options(arguments => {
'oid-filter:s' => { name => 'oid_filter', default => 'ifname' },
'oid-display:s' => { name => 'oid_display', default => 'ifname' },
});
$self->{oids_label} = {
'ifdesc' => '.1.3.6.1.2.1.2.2.1.2',
@ -80,7 +79,7 @@ sub run {
my $display_value = $self->get_display_value(id => $_);
my $oid = $mktFrequenOid . $_;
my $snmp_result = $options{snmp}->get_leef(oids => [$oid]);
if(defined($snmp_result->{$oid})){
if (defined($snmp_result->{$oid})){
$self->{output}->output_add(long_msg => $display_value . " : " . $snmp_result->{$oid});
}
}

View File

@ -29,38 +29,34 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'signalstrength', type => 1, cb_prefix_output => 'prefix_mac_output', message_multiple => 'All signals are ok' },
{ name => 'signalnoise', type => 1, cb_prefix_output => 'prefix_mac_output', message_multiple => 'All signals are ok' }
{ name => 'wreg', type => 1, cb_prefix_output => 'prefix_wreg_output', message_multiple => 'All wireless registrations are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{signalstrength} = [
$self->{maps_counters}->{wreg} = [
{ label => 'rx-strength', set => {
key_values => [ { name => 'rx' }, { name => 'display' } ],
output_template => 'Signal Strength Rx : %s',
key_values => [ { name => 'mtxrWlRtabStrength' }, { name => 'display' } ],
output_template => 'signal strength Rx: %s dBm',
perfdatas => [
{ label => 'signal_rx', value => 'rx_absolute', template => '%s',
min => -90, max => -20, label_extra_instance => 1, instance_use => 'display_absolute' },
{ label => 'signal_rx', value => 'mtxrWlRtabStrength_absolute', template => '%s', unit => 'dBm',
label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'tx-strength', set => {
key_values => [ { name => 'tx' }, { name => 'display' } ],
output_template => 'Signal Strength Tx : %s',
key_values => [ { name => 'mtxrWlRtabTxStrength' }, { name => 'display' } ],
output_template => 'signal strength Tx: %s dBm',
perfdatas => [
{ label => 'signal_tx', value => 'tx_absolute', template => '%s',
min => -90, max => -20, label_extra_instance => 1, instance_use => 'display_absolute' },
{ label => 'signal_tx', value => 'mtxrWlRtabTxStrength_absolute', template => '%s', unit => 'dBm',
label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
}
];
$self->{maps_counters}->{signalnoise} = [
},
{ label => 'signal2noise', set => {
key_values => [ { name => 'regs2n' }, { name => 'display' } ],
output_template => 'Signal To Noise : %s',
key_values => [ { name => 'mtxrWlRtabSignalToNoise', no_value => 0 }, { name => 'display' } ],
output_template => 'signal to noise: %s dB',
perfdatas => [
{ label => 'signal_noise', value => 'regs2n_absolute', template => '%s',
min => 20, max => 80, label_extra_instance => 1, instance_use => 'display_absolute' },
{ label => 'signal_noise', value => 'mtxrWlRtabSignalToNoise_absolute', template => '%s', unit => 'dB',
label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
}
@ -69,98 +65,53 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"strength" => { name => "strength" },
"noise" => { name => "noise" }
});
$options{options}->add_options(arguments => {
});
return $self;
}
sub prefix_mac_output {
sub prefix_wreg_output {
my ($self, %options) = @_;
return "MAC '" . $options{instance_value}->{display} . "' ";
}
my $mapping = {
regmac => { oid => '.1.3.6.1.4.1.14988.1.1.1.2.1.1' },
rx => { oid => '.1.3.6.1.4.1.14988.1.1.1.2.1.3' },
tx => { oid => '.1.3.6.1.4.1.14988.1.1.1.2.1.19' },
regs2n => { oid => '.1.3.6.1.4.1.14988.1.1.1.2.1.12' },
mtxrWlRtabAddr => { oid => '.1.3.6.1.4.1.14988.1.1.1.2.1.1' },
mtxrWlRtabStrength => { oid => '.1.3.6.1.4.1.14988.1.1.1.2.1.3' }, # dBm
mtxrWlRtabSignalToNoise => { oid => '.1.3.6.1.4.1.14988.1.1.1.2.1.12' }, # dB
mtxrWlRtabTxStrength => { oid => '.1.3.6.1.4.1.14988.1.1.1.2.1.19' }, # dBm
};
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit();
}
my $oids = [ $mapping->{regmac} ];
if(defined($self->{option_results}->{strength})){
push @{$oids}, ($mapping->{rx}, $mapping->{tx});
}
if(defined($self->{option_results}->{noise})){
push @{$oids}, $mapping->{regs2n};
}
$self->{snmp} = $options{snmp};
$self->{signalstrength} = {};
my $interfaceTables = $self->{snmp}->get_multiple_table(oids => $oids);
my @KeyMac = $self->{snmp}->oid_lex_sort(keys %{$interfaceTables->{ $mapping->{regmac}->{oid} }});
my (@KeysRx, @KeysTx, @Keys2n);
if (defined($self->{option_results}->{strength})) {
@KeysRx = $self->{snmp}->oid_lex_sort(keys %{$interfaceTables->{ $mapping->{rx}->{oid} }});
@KeysTx = $self->{snmp}->oid_lex_sort(keys %{$interfaceTables->{ $mapping->{tx}->{oid} }});
} elsif (defined($self->{option_results}->{noise})){
@Keys2n = $self->{snmp}->oid_lex_sort(keys %{$interfaceTables->{ $mapping->{regs2n}->{oid} }});
}
foreach my $index (0 .. $#KeyMac) {
next if ($KeyMac[$index] !~ /^$mapping->{regmac}->{oid}\.(.*)$/);
next if (defined($self->{option_results}->{strength}) &&
$KeysRx[$index] !~ /^$mapping->{rx}->{oid}\.(.*)$/ &&
$KeysTx[$index] !~ /^$mapping->{tx}->{oid}\.(.*)$/);
next if (defined($self->{option_results}->{noise}) && $Keys2n[$index] !~ /^$mapping->{regs2n}->{oid}\.(.*)$/);
my $snmp_result = $options{snmp}->get_multiple_table(
oids => [
map({ oid => $_->{oid} }, values(%$mapping))
],
return_type => 1,
nothing_quit => 1
);
$self->{wreg} = {};
foreach my $oid (keys %$snmp_result) {
next if ($oid !~ /^$mapping->{mtxrWlRtabAddr}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping,
results => $interfaceTables,
instance => $instance);
my $mac = unpack('H*', $interfaceTables->{$mapping->{regmac}->{oid}}->{$KeyMac[$index]});
$mac =~ s/..\K\B/:/g;
if(defined($self->{option_results}->{strength})) {
$self->{signalstrength}->{$instance} = { display => $mac,
%$result
};
}
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if(defined($self->{option_results}->{noise})) {
$self->{signalnoise}->{$instance} = { display => $mac,
%$result
};
}
}
if (scalar(keys %{$self->{signalstrength}}) <= 0 && scalar(keys %{$self->{signalnoise}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No signal found.");
$self->{output}->option_exit();
}
my $macaddress = unpack('H*', $result->{mtxrWlRtabAddr});
$macaddress =~ s/(..)(?=.)/$1:/g;
$self->{cache_name} = "mikrotik_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port();
$self->{wreg}->{$instance} = {
display => $macaddress,
%$result
};
}
}
1;
@ -169,25 +120,13 @@ __END__
=head1 MODE
Check signal strength and signal to noise.
Check wireless registration signals.
=over 8
=item B<--noise>
=item B<--warning-*> B<--critical-*>
Gets values for signal to noise
=item B<--strength>
Gets values for signal strength
=item B<--warning-*>
Can be rx-strength, tx-strength or signal2noise
=item B<--critical-*>
Can be rx-strength, tx-strength or signal2noise
Can be: 'rx-strength', 'tx-strength', 'signal2noise'
=back