| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package hardware::devices::camera::optelecom::snmp::mode::networks; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub device_long_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return sprintf( |
| 32 |
"checking device '%s'", |
| 33 |
$options{instance_value}->{deviceName} |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
sub prefix_device_output { |
| 38 |
my ($self, %options) = @_; |
| 39 |
|
| 40 |
return sprintf( |
| 41 |
"device '%s' ", |
| 42 |
$options{instance_value}->{deviceName} |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
sub prefix_network_output { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
return sprintf( |
| 50 |
"network '%s' ", |
| 51 |
$options{instance_value}->{ipAddress} |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
sub set_counters { |
| 56 |
my ($self, %options) = @_; |
| 57 |
|
| 58 |
$self->{maps_counters_type} = [ |
| 59 |
{ name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', |
| 60 |
indent_long_output => ' ', message_multiple => 'All devices are ok', |
| 61 |
group => [ |
| 62 |
{ name => 'networks', type => 1, cb_prefix_output => 'prefix_network_output', message_multiple => 'all networks are ok', skipped_code => { -10 => 1 } } |
| 63 |
] |
| 64 |
} |
| 65 |
]; |
| 66 |
|
| 67 |
$self->{maps_counters}->{networks} = [ |
| 68 |
{ label => 'traffic-in', nlabel => 'network.traffic.in.bitspersecond', set => { |
| 69 |
key_values => [ { name => 'trafficIn' }, { name => 'deviceName' }, { name => 'ipAddress' } ], |
| 70 |
output_template => 'in: %s %s/s', |
| 71 |
output_change_bytes => 2, |
| 72 |
closure_custom_perfdata => sub { |
| 73 |
my ($self, %options) = @_; |
| 74 |
|
| 75 |
$self->{output}->perfdata_add( |
| 76 |
nlabel => $self->{nlabel}, |
| 77 |
unit => 'b/s', |
| 78 |
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{ipAddress}], |
| 79 |
value => $self->{result_values}->{trafficIn}, |
| 80 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 81 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 82 |
min => 0 |
| 83 |
); |
| 84 |
} |
| 85 |
} |
| 86 |
}, |
| 87 |
{ label => 'traffic-out', nlabel => 'network.traffic.out.bitspersecond', set => { |
| 88 |
key_values => [ { name => 'trafficOut' }, { name => 'deviceName' }, { name => 'ipAddress' } ], |
| 89 |
output_template => 'out: %s %s/s', |
| 90 |
output_change_bytes => 2, |
| 91 |
closure_custom_perfdata => sub { |
| 92 |
my ($self, %options) = @_; |
| 93 |
|
| 94 |
$self->{output}->perfdata_add( |
| 95 |
nlabel => $self->{nlabel}, |
| 96 |
unit => 'b/s', |
| 97 |
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{ipAddress}], |
| 98 |
value => $self->{result_values}->{trafficOut}, |
| 99 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 100 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 101 |
min => 0 |
| 102 |
); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
]; |
| 107 |
} |
| 108 |
|
| 109 |
sub new { |
| 110 |
my ($class, %options) = @_; |
| 111 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 112 |
bless $self, $class; |
| 113 |
|
| 114 |
$options{options}->add_options(arguments => { |
| 115 |
'filter-device-name:s' => { name => 'filter_device_name' } |
| 116 |
}); |
| 117 |
|
| 118 |
return $self; |
| 119 |
} |
| 120 |
|
| 121 |
my $mapping_device = { |
| 122 |
serial => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.6' }, # optcSerialNumber |
| 123 |
userLabel1 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.8' }, # optcUserLabel1 |
| 124 |
userLabel2 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.9' } # optcUserLabel2 |
| 125 |
}; |
| 126 |
|
| 127 |
my $mapping_network = { |
| 128 |
ipAddress => { oid => '.1.3.6.1.4.1.17534.2.2.1.4.1.4' }, # optcIPAddress |
| 129 |
trafficOut => { oid => '.1.3.6.1.4.1.17534.2.2.1.5.1.1' }, # optcTotalTxBitrate |
| 130 |
trafficIn => { oid => '.1.3.6.1.4.1.17534.2.2.1.5.1.2' } # optcTotalRxBitrate |
| 131 |
}; |
| 132 |
|
| 133 |
sub manage_selection { |
| 134 |
my ($self, %options) = @_; |
| 135 |
|
| 136 |
my $oid_deviceTable = '.1.3.6.1.4.1.17534.2.2.1.1.1'; # optcSysInfoEntry |
| 137 |
my $snmp_result = $options{snmp}->get_table( |
| 138 |
oid => $oid_deviceTable, |
| 139 |
start => $mapping_device->{serial}->{oid}, |
| 140 |
end => $mapping_device->{userLabel2}->{oid}, |
| 141 |
nothing_quit => 1 |
| 142 |
); |
| 143 |
|
| 144 |
$self->{devices} = {}; |
| 145 |
foreach (keys %$snmp_result) { |
| 146 |
next if (! /^$mapping_device->{serial}->{oid}\.(.*)$/); |
| 147 |
my $instance = $1; |
| 148 |
my $result = $options{snmp}->map_instance(mapping => $mapping_device, results => $snmp_result, instance => $instance); |
| 149 |
|
| 150 |
my $name = defined($result->{userLabel1}) && $result->{userLabel1} ne '' ? $result->{userLabel1} : $result->{serial}; |
| 151 |
next if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' && |
| 152 |
$name !~ /$self->{option_results}->{filter_device_name}/); |
| 153 |
|
| 154 |
$self->{devices}->{$instance} = { deviceName => $name, networks => {} }; |
| 155 |
} |
| 156 |
|
| 157 |
my $oid_networkTable = '.1.3.6.1.4.1.17534.2.2.1.4.1'; # optcNetworkSettingsEntry |
| 158 |
my $oid_networkStatsTable = '.1.3.6.1.4.1.17534.2.2.1.5.1'; # optcNetworkStatisticsEntry |
| 159 |
$snmp_result = $options{snmp}->get_multiple_table( |
| 160 |
oids => [ { oid => $oid_networkTable }, { oid => $oid_networkStatsTable } ], |
| 161 |
return_type => 1 |
| 162 |
); |
| 163 |
foreach (keys %$snmp_result) { |
| 164 |
next if (! /^$mapping_network->{ipAddress}->{oid}\.(\d+).(\d+)$/); |
| 165 |
my ($deviceIndex, $netIndex) = ($1, $2); |
| 166 |
|
| 167 |
next if (!defined($self->{devices}->{$deviceIndex})); |
| 168 |
|
| 169 |
my $result = $options{snmp}->map_instance(mapping => $mapping_network, results => $snmp_result, instance => $deviceIndex . '.' . $netIndex); |
| 170 |
|
| 171 |
$self->{devices}->{$deviceIndex}->{networks}->{$netIndex} = { |
| 172 |
deviceName => $self->{devices}->{$deviceIndex}->{deviceName}, |
| 173 |
ipAddress => $result->{ipAddress}, |
| 174 |
trafficIn => $result->{trafficIn} * 1000, |
| 175 |
trafficOut => $result->{trafficOut} * 1000 |
| 176 |
}; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
1; |
| 181 |
|
| 182 |
__END__ |
| 183 |
|
| 184 |
=head1 MODE |
| 185 |
|
| 186 |
Check networks traffic. |
| 187 |
|
| 188 |
=over 8 |
| 189 |
|
| 190 |
=item B<--filter-device-name> |
| 191 |
|
| 192 |
Filter devices by name (can be a regexp). |
| 193 |
|
| 194 |
=item B<--warning-*> B<--critical-*> |
| 195 |
|
| 196 |
Thresholds. |
| 197 |
Can be: 'traffic-in', 'traffic-out'. |
| 198 |
|
| 199 |
=back |
| 200 |
|
| 201 |
=cut |