Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions src/network/opengear/snmp/mode/listserialports.pm

This file was deleted.

129 changes: 92 additions & 37 deletions src/network/opengear/snmp/mode/serialports.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
# Copyright 2026-Present Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
Expand All @@ -21,10 +21,12 @@
package network::opengear::snmp::mode::serialports;

use base qw(centreon::plugins::templates::counter);
use centreon::plugins::constants qw/:counters :values/;
use centreon::plugins::misc qw/is_excluded/;

use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use Digest::SHA qw(sha256_hex);

sub custom_traffic_perfdata {
my ($self, %options) = @_;
Expand Down Expand Up @@ -114,7 +116,7 @@ sub set_counters {
my ($self, %options) = @_;

$self->{maps_counters_type} = [
{ name => 'interfaces', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', cb_init_counters => 'skip_counters', skipped_code => { -10 => 1 } },
{ name => 'interfaces', type => COUNTER_TYPE_INSTANCE, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', cb_init_counters => 'skip_counters', skipped_code => { NO_VALUE() => 1 } },
];

$self->{maps_counters}->{interfaces} = [
Expand Down Expand Up @@ -143,7 +145,9 @@ sub new {
bless $self, $class;

$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'filter-name:s' => { redirect => 'include_name' },
'include-name:s' => { name => 'include_name', default => ''},
'exclude-name:s' => { name => 'exclude_name', default => ''},
'units-traffic:s' => { name => 'units_traffic', default => 'percent_delta' },
'speed:s' => { name => 'speed' }
});
Expand Down Expand Up @@ -174,64 +178,100 @@ sub check_options {
}
}

my $mapping = {
rxBytes => { oid => '.1.3.6.1.4.1.25049.16.1.1.3' }, # ogSerialPortStatusRxBytes
txBytes => { oid => '.1.3.6.1.4.1.25049.16.1.1.4' }, # ogSerialPortStatusTxBytes
speed => { oid => '.1.3.6.1.4.1.25049.16.1.1.5' } # ogSerialPortStatusSpeed
};
our @mapping_list = (
{
oid => '.1.3.6.1.4.1.25049.16.1.1.11', # ogSerialPortStatusLabel
data => { rxBytes => { oid => '.1.3.6.1.4.1.25049.16.1.1.3' }, # ogSerialPortStatusRxBytes
txBytes => { oid => '.1.3.6.1.4.1.25049.16.1.1.4' }, # ogSerialPortStatusTxBytes
speed => { oid => '.1.3.6.1.4.1.25049.16.1.1.5' } # ogSerialPortStatusSpeed
}
},
{
oid => '.1.3.6.1.4.1.25049.10.19.2.2.1.2', # ogOmSerialPortLabel
data => { rxBytes => { oid => '.1.3.6.1.4.1.25049.10.19.2.2.1.11' }, # ogOmSerialPortRxBytes
txBytes => { oid => '.1.3.6.1.4.1.25049.10.19.2.2.1.12' }, # ogOmSerialPortTxBytes
speed => { oid => '.1.3.6.1.4.1.25049.10.19.2.2.1.3' } # ogOmSerialPortSpeed
}
}
);

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();
}
$self->{interfaces} = {};
my $is_disco = $self->{output}->is_disco_show();

my $oid_label = '.1.3.6.1.4.1.25049.16.1.1.11'; # ogSerialPortStatusLabel
my $snmp_result = $options{snmp}->get_table(
oid => $oid_label,
nothing_quit => 1
);
$self->{output}->option_exit(short_msg => 'Need to use SNMP v2c or v3.')
if $options{snmp}->is_snmpv1() && !$is_disco;

$self->{interfaces} = {};
foreach (keys %$snmp_result) {
/\.(\d+)$/;
my $instance = $1;
my $snmp_result;
my $mapping;

next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$snmp_result->{$_} !~ /$self->{option_results}->{filter_name}/);
foreach (@mapping_list) {
$snmp_result = $options{snmp}->get_table( oid => $_->{oid} );
if (ref $snmp_result eq 'HASH' && keys %$snmp_result) {
$mapping = $_;
last
}
}

$self->{interfaces}->{$instance} = { name => $snmp_result->{$_} };
if (ref $snmp_result eq 'HASH' && keys %$snmp_result) {
foreach (keys %$snmp_result) {
/\.(\d+)$/;
my $instance = $1;
next if is_excluded($snmp_result->{$_}, $self->{option_results}->{include_name}, $self->{option_results}->{exclude_name});
$self->{interfaces}->{$instance} = { name => $snmp_result->{$_} };
}
} elsif (!$is_disco) {
$self->{output}->option_exit(short_msg => 'No Opengear serial port SNMP entries found')
}

return if (scalar(keys %{$self->{interfaces}}) <= 0);
return if $is_disco;

$self->{output}->option_exit(short_msg => 'No maching Opengear serial port SNMP entries')
unless keys %{$self->{interfaces}};

$options{snmp}->load(
oids => [
map($_->{oid}, values(%$mapping))
map($_->{oid}, values(%{$mapping->{data}}))
],
instances => [ map($_, keys %{$self->{interfaces}}) ],
instance_regexp => '^(.*)$'
);
$snmp_result = $options{snmp}->get_leef();

foreach (keys %{$self->{interfaces}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
my $result = $options{snmp}->map_instance(mapping => $mapping->{data}, results => $snmp_result, instance => $_);

$self->{interfaces}->{$_}->{in} = $result->{rxBytes};
$self->{interfaces}->{$_}->{out} = $result->{txBytes};
$self->{interfaces}->{$_}->{speed_in} = defined($self->{option_results}->{speed}) ? $self->{option_results}->{speed} : $result->{speed};
$self->{interfaces}->{$_}->{speed_out} = defined($self->{option_results}->{speed}) ? $self->{option_results}->{speed} : $result->{speed};
$self->{interfaces}->{$_}->{speed_in} = $self->{option_results}->{speed} // $result->{speed};
$self->{interfaces}->{$_}->{speed_out} = $self->{option_results}->{speed} // $result->{speed};
}

$self->{cache_name} = 'opengear_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
md5_hex(
(defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : 'all') .
(defined($self->{option_results}->{filter_name}) ? $self->{option_results}->{filter_name} : 'all')
sha256_hex(
($self->{option_results}->{filter_counters} // 'all') . '_' .
($self->{option_results}->{include_name} ne '' ? $self->{option_results}->{include_name} : 'all') . '_' .
($self->{option_results}->{exclude_name} ne '' ? $self->{option_results}->{exclude_name} : 'all')
);
}

sub disco_format {
my ($self, %options) = @_;

$self->{output}->add_disco_format(elements => ['name']);
}

sub disco_show {
my ($self, %options) = @_;

$self->manage_selection(%options);
$self->{output}->add_disco_entry( name => $_->{name} )
foreach sort { $a->{name} cmp $b->{name} }
values %{$self->{interfaces}};
}

1;

__END__
Expand All @@ -246,18 +286,33 @@ Check serial ports.

Units of thresholds for the traffic (default: 'percent_delta') ('percent_delta', 'bps', 'counter').

=item B<--filter-name>
=item B<--include-name>

Filter serial port name (regexp can be used).

=item B<--exclude-name>

Exclude serial port name (regexp can be used).

=item B<--speed>

Set serial port speed (in Mb).

=item B<--warning-*> B<--critical-*>
=item B<--warning-traffic-in>

Threshold.

=item B<--critical-traffic-in>

Threshold.

=item B<--warning-traffic-out>

Threshold.

=item B<--critical-traffic-out>

Thresholds.
Can be: 'traffic-in', 'traffic-out'.
Threshold.

=back

Expand Down
3 changes: 1 addition & 2 deletions src/network/opengear/snmp/plugin.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
# Copyright 2026-Present Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
Expand Down Expand Up @@ -33,7 +33,6 @@ sub new {
'cpu-detailed' => 'network::opengear::snmp::mode::cpudetailed',
'interfaces' => 'network::opengear::snmp::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-serial-ports' => 'network::opengear::snmp::mode::listserialports',
'load' => 'network::opengear::snmp::mode::load',
'memory' => 'network::opengear::snmp::mode::memory',
'serial-ports' => 'network::opengear::snmp::mode::serialports',
Expand Down
61 changes: 61 additions & 0 deletions tests/network/opengear/snmp/serialports_cm8100.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
*** Settings ***
Documentation network::opengear::snmp::plugin

Resource ${CURDIR}${/}..${/}..${/}..${/}resources/import.resource

Suite Setup Ctn Generic Suite Setup
Suite Teardown Ctn Generic Suite Teardown
Test Timeout 120s


*** Variables ***
${CMD} ${CENTREON_PLUGINS}
... --plugin=network::opengear::snmp::plugin
... --mode=serial-ports
... --hostname=${HOSTNAME}
... --snmp-port=${SNMPPORT}
... --snmp-version=2
... --snmp-community=network/opengear/snmp/serialports_cm8100


*** Test Cases ***
Serialports CM8100 ${tc}
[Tags] network opengear snmp
${command} Catenate
... ${CMD}
... ${extra_options}

Ctn Run Command And Check Result As Strings ${command} ${expected_result}

Examples:
... tc
... extra_options
... expected_result
... --
... 1
... ${EMPTY}
... OK: All interfaces are ok
... 2
... --include-name=ANO02
... OK: Serial port 'ANO02' traffic in: Buffer creation, traffic out: Buffer creation
... 3
... --exclude-name=ANO02
... OK: Serial port 'ANO01' traffic in: Buffer creation, traffic out: Buffer creation
... 4
... --warning-traffic-in=1:
... WARNING: Serial port 'ANO01' traffic in: 0.00b/s (0.00%) - Serial port 'ANO02' traffic in: 0.00b/s (0.00%) | 'ANO01#serial_port.traffic.in.bitspersecond'=0.00;96:;;0;9600 'ANO01#serial_port.traffic.out.bitspersecond'=0.00;;;0;9600 'ANO02#serial_port.traffic.in.bitspersecond'=0.00;1152:;;0;115200 'ANO02#serial_port.traffic.out.bitspersecond'=0.00;;;0;115200
... 5
... --critical-traffic-in=1:
... CRITICAL: Serial port 'ANO01' traffic in: 0.00b/s (0.00%) - Serial port 'ANO02' traffic in: 0.00b/s (0.00%) | 'ANO01#serial_port.traffic.in.bitspersecond'=0.00;;96:;0;9600 'ANO01#serial_port.traffic.out.bitspersecond'=0.00;;;0;9600 'ANO02#serial_port.traffic.in.bitspersecond'=0.00;;1152:;0;115200 'ANO02#serial_port.traffic.out.bitspersecond'=0.00;;;0;115200
... 6
... --warning-traffic-out=1:
... WARNING: Serial port 'ANO01' traffic out: 0.00b/s (0.00%) - Serial port 'ANO02' traffic out: 0.00b/s (0.00%) | 'ANO01#serial_port.traffic.in.bitspersecond'=0.00;;;0;9600 'ANO01#serial_port.traffic.out.bitspersecond'=0.00;96:;;0;9600 'ANO02#serial_port.traffic.in.bitspersecond'=0.00;;;0;115200 'ANO02#serial_port.traffic.out.bitspersecond'=0.00;1152:;;0;115200
... 7
... --critical-traffic-out=1:
... CRITICAL: Serial port 'ANO01' traffic out: 0.00b/s (0.00%) - Serial port 'ANO02' traffic out: 0.00b/s (0.00%) | 'ANO01#serial_port.traffic.in.bitspersecond'=0.00;;;0;9600 'ANO01#serial_port.traffic.out.bitspersecond'=0.00;;96:;0;9600 'ANO02#serial_port.traffic.in.bitspersecond'=0.00;;;0;115200 'ANO02#serial_port.traffic.out.bitspersecond'=0.00;;1152:;0;115200
... 8
... --disco-format
... <?xml version="1.0" encoding="utf-8"?> <data> <element>name</element> </data>
... 9
... --disco-show
... <?xml version="1.0" encoding="utf-8"?> <data> <label name="ANO01"/> <label name="ANO02"/> </data>
Loading
Loading