(plugin) network::oneaccess::snmp - add mode cells-radio (#3576)

This commit is contained in:
qgarnier 2022-04-01 13:56:58 +02:00 committed by GitHub
parent 4d62a19070
commit 7f5c066f1e
5 changed files with 564 additions and 54 deletions

View File

@ -0,0 +1,319 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::oneaccess::snmp::mode::cellsradio;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_signal_perfdata {
my ($self) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
instances => [
$self->{result_values}->{cellId},
$self->{result_values}->{operator}
],
value => $self->{result_values}->{ $self->{key_values}->[0]->{name} },
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0
);
}
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'sim status: %s [imsi: %s] [signal quality: %s]',
$self->{result_values}->{simStatus},
$self->{result_values}->{imsi},
$self->{result_values}->{signalQuality}
);
}
sub cell_long_output {
my ($self, %options) = @_;
return sprintf(
"checking cellular radio module '%s' [operator: %s]",
$options{instance_value}->{cellId},
$options{instance_value}->{operator}
);
}
sub prefix_cell_output {
my ($self, %options) = @_;
return sprintf(
"cellular radio module '%s' [operator: %s] ",
$options{instance_value}->{cellId},
$options{instance_value}->{operator}
);
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Number of cellular radio modules ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{ name => 'cells', type => 3, cb_prefix_output => 'prefix_cell_output', cb_long_output => 'cell_long_output',
indent_long_output => ' ', message_multiple => 'All cellular radio modules are ok',
group => [
{ name => 'status', type => 0, skipped_code => { -10 => 1 } },
{ name => 'signal', type => 0, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'modules-cellradio-detected', display_ok => 0, nlabel => 'modules.cellradio.detected.count', set => {
key_values => [ { name => 'detected' } ],
output_template => 'detected: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{status} = [
{
label => 'status',
type => 2,
warning_default => '%{signalQuality} =~ /poor/',
critical_default => '%{simStatus} eq "notPresent" || %{signalQuality} =~ /none/',
set => {
key_values => [
{ name => 'cellId' }, { name => 'operator' }, { name => 'imsi' },
{ name => 'simStatus' }, { name => 'signalQuality' }
],
closure_custom_output => $self->can('custom_status_output'),
output_template => "sim status: %s",
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{signal} = [
{ label => 'module-cellradio-rsrp', nlabel => 'module.cellradio.rsrp.dbm', set => {
key_values => [ { name => 'rsrp' }, { name => 'cellId' }, { name => 'operator' } ],
output_template => 'rsrp: %s dBm',
closure_custom_perfdata => $self->can('custom_signal_perfdata')
}
},
{ label => 'module-cellradio-rssi', nlabel => 'module.cellradio.rssi.dbm', set => {
key_values => [ { name => 'rssi' }, { name => 'cellId' }, { name => 'operator' } ],
output_template => 'rssi: %s dBm',
closure_custom_perfdata => $self->can('custom_signal_perfdata')
}
},
{ label => 'module-cellradio-snr', nlabel => 'module.cellradio.snr.db', set => {
key_values => [ { name => 'snr' }, { name => 'cellId' }, { name => 'operator' } ],
output_template => 'snr: %s dB',
closure_custom_perfdata => $self->can('custom_signal_perfdata')
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-cell-id:s' => { name => 'filter_cell_id' }
});
return $self;
}
my $mapping_id = {
imei => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.14' }, # oacCellIMEI
meid => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.15' } # oacCellMEID
};
my $mapping = {
simStatus => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.20' }, # oacCellSIMStatus
imsi => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.21' }, # oacCellIMSI
operator => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.40' }, # oacCellSelectedOperator
rssi => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.41' }, # oacCellSignalStrength
rsrp => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.44' }, # oacCellRSRP
snr => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.45' }, # oacCellSNR
techno => { oid => '.1.3.6.1.4.1.13191.10.3.9.2.1.46' } # oacCellRadioAccessTechnology
};
sub get_signal_quality {
my ($self, %options) = @_;
my $quality = '-';
if ($options{techno} =~ /4G/) {
if ($options{rsrp} < -140) {
$quality = 'none';
} elsif ($options{rsrp} < -120) {
$quality = 'poor';
} elsif ($options{rsrp} < -105) {
$quality = 'fair';
} elsif ($options{rsrp} < -90) {
$quality = 'good';
} else {
$quality = 'excellent';
}
} elsif ($options{techno} =~ /3G/) {
if ($options{rssi} < -111) {
$quality = 'none';
} elsif ($options{rssi} < -105) {
$quality = 'poor';
} elsif ($options{rssi} < -99) {
$quality = 'fair';
} elsif ($options{rssi} < -89) {
$quality = 'good';
} else {
$quality = 'excellent';
}
} elsif ($options{techno} =~ /2G/) {
if ($options{rssi} < -111) {
$quality = 'none';
} elsif ($options{rssi} < -95) {
$quality = 'poor';
} elsif ($options{rssi} < -85) {
$quality = 'fair';
} elsif ($options{rssi} < -75) {
$quality = 'good';
} else {
$quality = 'excellent';
}
}
return $quality;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = { detected => 0 };
$self->{cells} = {};
my $oid_radioTable = '.1.3.6.1.4.1.13191.10.3.9.2'; # oacCellRadioModuleTable
my $snmp_result = $options{snmp}->get_table(
oid => $oid_radioTable,
start => $mapping_id->{imei}->{oid},
end => $mapping_id->{meid}->{oid},
nothing_quit => 1
);
foreach my $oid (keys %$snmp_result) {
next if ($oid !~ /^$mapping_id->{imei}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping_id, results => $snmp_result, instance => $instance);
my $cell_id = $result->{imei} =~ /^(?:[0-9]+)$/ ? $result->{imei} : $result->{meid};
next if (defined($self->{option_results}->{filter_cell_id}) && $self->{option_results}->{filter_cell_id} ne '' &&
$cell_id !~ /$self->{option_results}->{filter_cell_id}/);
$self->{cells}->{$instance} = {
cellId => $cell_id,
status => { cellId => $cell_id },
signal => { cellId => $cell_id }
};
}
return if (scalar(keys %{$self->{cells}}) <= 0);
$options{snmp}->load(
oids => [ map($_->{oid}, values(%$mapping)) ],
instances => [ map($_, keys %{$self->{cells}}) ],
instance_regexp => '^(.*)$'
);
$snmp_result = $options{snmp}->get_leef();
foreach (keys %{$self->{cells}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
$self->{cells}->{$_}->{operator} = $result->{operator};
$self->{cells}->{$_}->{status}->{operator} = $result->{operator};
$self->{cells}->{$_}->{status}->{imsi} = defined($result->{imsi}) && $result->{imsi} =~ /^(?:[0-9]+)$/ ? $result->{imsi} : '-';
$self->{cells}->{$_}->{signal}->{operator} = $result->{operator};
$self->{cells}->{$_}->{status}->{simStatus} = $result->{simStatus} =~ /is present/ ? 'present' : 'notPresent';
$self->{cells}->{$_}->{status}->{signalQuality} = $self->get_signal_quality(
techno => $result->{techno},
rsrp => $result->{rsrp},
rssi => $result->{rssi}
);
if ($self->{cells}->{$_}->{status}->{simStatus} eq 'present') {
$self->{cells}->{$_}->{signal}->{rssi} = $result->{rssi};
$self->{cells}->{$_}->{signal}->{rsrp} = $result->{rsrp};
$self->{cells}->{$_}->{signal}->{snr} = $result->{snr};
}
$self->{global}->{detected}++;
}
}
1;
__END__
=head1 MODE
Check cellular radio modules.
=over 8
=item B<--filter-cell-id>
Filter cell modules by id (IMEI or MEID).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{simStatus}, %{signalQuality}, %{cellId}, %{operator}, %{imsi}
=item B<--warning-status>
Set warning threshold for status (Default: '%{signalQuality} =~ /poor/').
Can used special variables like: %{simStatus}, %{signalQuality}, %{cellId}, %{operator}, %{imsi}
=item B<--critical-status>
Set critical threshold for status (Default: '%{simStatus} eq "notPresent" || %{signalQuality} =~ /none/').
Can used special variables like: %{simStatus}, %{signalQuality}, %{cellId}, %{operator}, %{imsi}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'modules-cellradio-detected', 'module-cellradio-rsrp',
'module-cellradio-rssi', 'module-cellradio-snr'.
=back
=cut

View File

@ -27,14 +27,13 @@ use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$options{options}->add_options(arguments => {
'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' }
});
return $self;
}
@ -55,22 +54,28 @@ sub check_options {
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $oid_oacSysCpuUsed = '.1.3.6.1.4.1.13191.10.3.3.1.2.1.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_oacSysCpuUsed], nothing_quit => 1);
my $result = $options{snmp}->get_leef(oids => [$oid_oacSysCpuUsed], nothing_quit => 1);
my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_oacSysCpuUsed},
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("CPU Usage: %d %%", $result->{$oid_oacSysCpuUsed}));
$self->{output}->perfdata_add(label => "cpu", unit => '%',
value => $result->{$oid_oacSysCpuUsed},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0, max => 100);
my $exit = $self->{perfdata}->threshold_check(
value => $result->{$oid_oacSysCpuUsed},
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
);
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf("CPU Usage: %d %%", $result->{$oid_oacSysCpuUsed})
);
$self->{output}->perfdata_add(
nlabel => 'cpu.utilization.percentage',
unit => '%',
value => $result->{$oid_oacSysCpuUsed},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0, max => 100
);
$self->{output}->display();
$self->{output}->exit();
}
@ -96,4 +101,3 @@ Threshold critical in percent.
=back
=cut

View File

@ -0,0 +1,182 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::oneaccess::snmp::mode::interfaces;
use base qw(snmp_standard::mode::interfaces);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
return $self;
}
1;
__END__
=head1 MODE
Check interfaces.
=over 8
=item B<--add-global>
Check global port statistics (By default if no --add-* option is set).
=item B<--add-status>
Check interface status.
=item B<--add-duplex-status>
Check duplex status (with --warning-status and --critical-status).
=item B<--add-traffic>
Check interface traffic.
=item B<--add-errors>
Check interface errors.
=item B<--add-cast>
Check interface cast.
=item B<--add-speed>
Check interface speed.
=item B<--add-volume>
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard',
'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast',
'speed' (b/s).
=item B<--units-traffic>
Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter').
=item B<--units-errors>
Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter').
=item B<--units-cast>
Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter').
=item B<--nagvis-perfdata>
Display traffic perfdata to be compatible with nagvis widget.
=item B<--interface>
Set the interface (number expected) ex: 1,2,... (empty means 'check all interface').
=item B<--name>
Allows to use interface name with option --interface instead of interface oid index (Can be a regexp)
=item B<--speed>
Set interface speed for incoming/outgoing traffic (in Mb).
=item B<--speed-in>
Set interface speed for incoming traffic (in Mb).
=item B<--speed-out>
Set interface speed for outgoing traffic (in Mb).
=item B<--map-speed-dsl>
Get interface speed configuration for interface type 'adsl' and 'vdsl2'.
Syntax: --map-speed-dsl=interface-src-name,interface-dsl-name
E.g: --map-speed-dsl=Et0.835,Et0-vdsl2
=item B<--force-counters64>
Force to use 64 bits counters only. Can be used to improve performance.
=item B<--force-counters32>
Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy.
=item B<--reload-cache-time>
Time in minutes before reloading cache file (default: 180).
=item B<--oid-filter>
Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
=item B<--oid-display>
Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
=item B<--oid-extra-display>
Add an OID to display.
=item B<--display-transform-src>
Regexp src to transform display value.
=item B<--display-transform-dst>
Regexp dst to transform display value.
=item B<--show-cache>
Display cache interface datas.
=back
=cut

View File

@ -27,14 +27,13 @@ use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$options{options}->add_options(arguments => {
'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' }
});
return $self;
}
@ -42,7 +41,7 @@ sub new {
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
@ -55,37 +54,44 @@ sub check_options {
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $oid_oacSysMemoryTotal = '.1.3.6.1.4.1.13191.10.3.3.1.1.3.0';
my $oid_oacSysMemoryUsed = '.1.3.6.1.4.1.13191.10.3.3.1.1.4.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_oacSysMemoryTotal, $oid_oacSysMemoryUsed], nothing_quit => 1);
my $result = $options{snmp}->get_leef(oids => [$oid_oacSysMemoryTotal, $oid_oacSysMemoryUsed], nothing_quit => 1);
my $total = $result->{$oid_oacSysMemoryTotal};
my $used = $result->{$oid_oacSysMemoryUsed} * $total / 100;
my $free = $total - $used;
my $prct_used = $result->{$oid_oacSysMemoryUsed};
my $prct_free = 100 - $prct_used;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $total);
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $used);
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $free);
my $exit = $self->{perfdata}->threshold_check(value => $prct_used,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $prct_used,
$total_free_value . " " . $total_free_unit, $prct_free));
$self->{output}->perfdata_add(label => "used", unit => 'B',
value => sprintf("%d", $used),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total, cast_int => 1),
min => 0, max => $total
);
my $exit = $self->{perfdata}->threshold_check(
value => $prct_used,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
);
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $prct_used,
$total_free_value . " " . $total_free_unit, $prct_free
)
);
$self->{output}->perfdata_add(
nlabel => 'memory.usage.bytes',
unit => 'B',
value => sprintf('%d', $used),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total, cast_int => 1),
min => 0, max => $total
);
$self->{output}->display();
$self->{output}->exit();
}
@ -111,4 +117,3 @@ Threshold critical in percent.
=back
=cut

View File

@ -29,13 +29,13 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.5';
%{$self->{modes}} = (
'cpu' => 'network::oneaccess::snmp::mode::cpu',
'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'memory' => 'network::oneaccess::snmp::mode::memory',
);
$self->{modes} = {
'cpu' => 'network::oneaccess::snmp::mode::cpu',
'cells-radio' => 'network::oneaccess::snmp::mode::cellsradio',
'interfaces' => 'network::oneaccess::snmp::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'memory' => 'network::oneaccess::snmp::mode::memory'
};
return $self;
}