| 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 network::sonus::sbc::snmp::mode::channels; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $msg; |
| 33 |
if ($self->{result_values}->{admstatus} eq 'disabled') { |
| 34 |
$msg = 'is disabled (admin)'; |
| 35 |
} else { |
| 36 |
$msg = 'oper status: ' . $self->{result_values}->{opstatus}; |
| 37 |
} |
| 38 |
|
| 39 |
return $msg; |
| 40 |
} |
| 41 |
|
| 42 |
sub prefix_channel_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return sprintf( |
| 46 |
"channel '%s/%s/%s/%s' ", |
| 47 |
$options{instance_value}->{shelf}, |
| 48 |
$options{instance_value}->{slot}, |
| 49 |
$options{instance_value}->{port}, |
| 50 |
$options{instance_value}->{channel} |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
sub prefix_global_output { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
return 'number of channels '; |
| 58 |
} |
| 59 |
|
| 60 |
sub set_counters { |
| 61 |
my ($self, %options) = @_; |
| 62 |
|
| 63 |
$self->{maps_counters_type} = [ |
| 64 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, |
| 65 |
{ name => 'channels', type => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'All channels are ok' } |
| 66 |
]; |
| 67 |
|
| 68 |
$self->{maps_counters}->{global} = [ |
| 69 |
{ label => 'channels-total', nlabel => 'channels.total.count', display_ok => 0, set => { |
| 70 |
key_values => [ { name => 'total' } ], |
| 71 |
output_template => 'total: %s', |
| 72 |
perfdatas => [ |
| 73 |
{ template => '%s', min => 0 } |
| 74 |
] |
| 75 |
} |
| 76 |
}, |
| 77 |
{ label => 'channels-outofservice', nlabel => 'channels.outofservice.count', display_ok => 0, set => { |
| 78 |
key_values => [ { name => 'outofservice' } ], |
| 79 |
output_template => 'out of service: %s', |
| 80 |
perfdatas => [ |
| 81 |
{ template => '%s', min => 0 } |
| 82 |
] |
| 83 |
} |
| 84 |
}, |
| 85 |
{ label => 'channels-idle', nlabel => 'channels.idle.count', display_ok => 0, set => { |
| 86 |
key_values => [ { name => 'idle' } ], |
| 87 |
output_template => 'idle: %s', |
| 88 |
perfdatas => [ |
| 89 |
{ template => '%s', min => 0 } |
| 90 |
] |
| 91 |
} |
| 92 |
}, |
| 93 |
{ label => 'channels-pending', nlabel => 'channels.pending.count', display_ok => 0, set => { |
| 94 |
key_values => [ { name => 'pending' } ], |
| 95 |
output_template => 'pending: %s', |
| 96 |
perfdatas => [ |
| 97 |
{ template => '%s', min => 0 } |
| 98 |
] |
| 99 |
} |
| 100 |
}, |
| 101 |
{ label => 'channels-waitingforroute', nlabel => 'channels.waiting_for_route.count', display_ok => 0, set => { |
| 102 |
key_values => [ { name => 'waitingforroute' } ], |
| 103 |
output_template => 'waiting for route: %s', |
| 104 |
perfdatas => [ |
| 105 |
{ template => '%s', min => 0 } |
| 106 |
] |
| 107 |
} |
| 108 |
}, |
| 109 |
{ label => 'channels-actionlist', nlabel => 'channels.action_list.count', display_ok => 0, set => { |
| 110 |
key_values => [ { name => 'actionlist' } ], |
| 111 |
output_template => 'action list: %s', |
| 112 |
perfdatas => [ |
| 113 |
{ template => '%s', min => 0 } |
| 114 |
] |
| 115 |
} |
| 116 |
}, |
| 117 |
{ label => 'channels-waitingfordigits', nlabel => 'channels.waiting_for_digits.count', display_ok => 0, set => { |
| 118 |
key_values => [ { name => 'waitingfordigits' } ], |
| 119 |
output_template => 'waiting for digits: %s', |
| 120 |
perfdatas => [ |
| 121 |
{ template => '%s', |
| 122 |
min => 0 } |
| 123 |
] |
| 124 |
} |
| 125 |
}, |
| 126 |
{ label => 'channels-remotesetup', nlabel => 'channels.remote_setup.count', display_ok => 0, set => { |
| 127 |
key_values => [ { name => 'remotesetup' } ], |
| 128 |
output_template => 'remote setup: %s', |
| 129 |
perfdatas => [ |
| 130 |
{ template => '%s', min => 0 } |
| 131 |
] |
| 132 |
} |
| 133 |
}, |
| 134 |
{ label => 'channels-peersetup', nlabel => 'channels.peer_setup.count', display_ok => 0, set => { |
| 135 |
key_values => [ { name => 'peersetup' } ], |
| 136 |
output_template => 'peer setup: %s', |
| 137 |
perfdatas => [ |
| 138 |
{ template => '%s', min => 0 } |
| 139 |
] |
| 140 |
} |
| 141 |
}, |
| 142 |
{ label => 'channels-alerting', nlabel => 'channels.alerting.count', display_ok => 0, set => { |
| 143 |
key_values => [ { name => 'alerting' } ], |
| 144 |
output_template => 'alerting: %s', |
| 145 |
perfdatas => [ |
| 146 |
{ template => '%s', min => 0 } |
| 147 |
] |
| 148 |
} |
| 149 |
}, |
| 150 |
{ label => 'channels-inbandinfo', nlabel => 'channels.inband_info.count', display_ok => 0, set => { |
| 151 |
key_values => [ { name => 'inbandinfo' } ], |
| 152 |
output_template => 'inband info: %s', |
| 153 |
perfdatas => [ |
| 154 |
{ template => '%s', min => 0 } |
| 155 |
] |
| 156 |
} |
| 157 |
}, |
| 158 |
{ label => 'channels-connected', nlabel => 'channels.connected.count', display_ok => 0, set => { |
| 159 |
key_values => [ { name => 'connected' } ], |
| 160 |
output_template => 'connected: %s', |
| 161 |
perfdatas => [ |
| 162 |
{ template => '%s', min => 0 } |
| 163 |
] |
| 164 |
} |
| 165 |
}, |
| 166 |
{ label => 'channels-tonegeneration', nlabel => 'channels.tone_generation.count', display_ok => 0, set => { |
| 167 |
key_values => [ { name => 'tonegeneration' } ], |
| 168 |
output_template => 'tone generation: %s', |
| 169 |
perfdatas => [ |
| 170 |
{ template => '%s', min => 0 } |
| 171 |
] |
| 172 |
} |
| 173 |
}, |
| 174 |
{ label => 'channels-releasing', nlabel => 'channels.releasing.count', display_ok => 0, set => { |
| 175 |
key_values => [ { name => 'releasing' } ], |
| 176 |
output_template => 'releasing: %s', |
| 177 |
perfdatas => [ |
| 178 |
{ template => '%s', min => 0 } |
| 179 |
] |
| 180 |
} |
| 181 |
}, |
| 182 |
{ label => 'channels-aborting', nlabel => 'channels.aborting.count', display_ok => 0, set => { |
| 183 |
key_values => [ { name => 'aborting' } ], |
| 184 |
output_template => 'aborting: %s', |
| 185 |
perfdatas => [ |
| 186 |
{ template => '%s', min => 0 } |
| 187 |
] |
| 188 |
} |
| 189 |
}, |
| 190 |
{ label => 'channels-resetting', nlabel => 'channels.resetting.count', display_ok => 0, set => { |
| 191 |
key_values => [ { name => 'resetting' } ], |
| 192 |
output_template => 'resetting: %s', |
| 193 |
perfdatas => [ |
| 194 |
{ template => '%s', min => 0 } |
| 195 |
] |
| 196 |
} |
| 197 |
}, |
| 198 |
{ label => 'channels-up', nlabel => 'channels.up.count', display_ok => 0, set => { |
| 199 |
key_values => [ { name => 'up' } ], |
| 200 |
output_template => 'up: %s', |
| 201 |
perfdatas => [ |
| 202 |
{ template => '%s', min => 0 } |
| 203 |
] |
| 204 |
} |
| 205 |
}, |
| 206 |
{ label => 'channels-down', nlabel => 'channels.down.count', display_ok => 0, set => { |
| 207 |
key_values => [ { name => 'down' } ], |
| 208 |
output_template => 'down: %s', |
| 209 |
perfdatas => [ |
| 210 |
{ template => '%s', min => 0 } |
| 211 |
] |
| 212 |
} |
| 213 |
} |
| 214 |
]; |
| 215 |
|
| 216 |
$self->{maps_counters}->{channels} = [ |
| 217 |
{ label => 'status', type => 2, critical_default => '%{admstatus} eq "enable" and %{opstatus} !~ /up|idle|connected/', set => { |
| 218 |
key_values => [ |
| 219 |
{ name => 'opstatus' }, { name => 'admstatus' }, |
| 220 |
{ name => 'shelf' }, { name => 'slot' }, { name => 'port' }, { name => 'channel' } |
| 221 |
], |
| 222 |
closure_custom_output => $self->can('custom_status_output'), |
| 223 |
closure_custom_perfdata => sub { return 0; }, |
| 224 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 225 |
} |
| 226 |
}, |
| 227 |
{ label => 'channel-lifetime', nlabel => 'channel.lifetime.seconds', set => { |
| 228 |
key_values => [ { name => 'seconds' }, { name => 'shelf' }, { name => 'slot' }, { name => 'port' }, { name => 'channel' } ], |
| 229 |
output_template => 'lifetime: %s seconds', |
| 230 |
closure_custom_perfdata => sub { |
| 231 |
my ($self, %options) = @_; |
| 232 |
|
| 233 |
$self->{output}->perfdata_add( |
| 234 |
nlabel => $self->{nlabel}, |
| 235 |
unit => 's', |
| 236 |
instances => [ |
| 237 |
'shelf' . $self->{result_values}->{shelf}, |
| 238 |
'slot' . $self->{result_values}->{slot}, |
| 239 |
'port' . $self->{result_values}->{port}, |
| 240 |
'channel' . $self->{result_values}->{channel}, |
| 241 |
], |
| 242 |
value => $self->{result_values}->{seconds}, |
| 243 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 244 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 245 |
min => 0 |
| 246 |
); |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
]; |
| 251 |
} |
| 252 |
|
| 253 |
sub new { |
| 254 |
my ($class, %options) = @_; |
| 255 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 256 |
bless $self, $class; |
| 257 |
|
| 258 |
$options{options}->add_options(arguments => { |
| 259 |
'filter-shelf-id:s' => { name => 'filter_shelf_id' }, |
| 260 |
'filter-slot-id:s' => { name => 'filter_slot_id' }, |
| 261 |
'filter-port-id:s' => { name => 'filter_port_id' }, |
| 262 |
'filter-channel-id:s' => { name => 'filter_channel_id' } |
| 263 |
}); |
| 264 |
|
| 265 |
return $self; |
| 266 |
} |
| 267 |
|
| 268 |
my %map_admin_status = ( |
| 269 |
0 => 'down', |
| 270 |
1 => 'up' |
| 271 |
); |
| 272 |
my %map_operation_status = ( |
| 273 |
0 => 'outOfService', |
| 274 |
1 => 'idle', |
| 275 |
2 => 'pending', |
| 276 |
3 => 'waitingForRoute', |
| 277 |
4 => 'actionList', |
| 278 |
5 => 'waitingForDigits', |
| 279 |
6 => 'remoteSetUp', |
| 280 |
7 => 'peerSetUp', |
| 281 |
8 => 'alerting', |
| 282 |
9 => 'inBandInfo', |
| 283 |
10 => 'connected', |
| 284 |
11 => 'toneGeneration', |
| 285 |
12 => 'releasing', |
| 286 |
13 => 'aborting', |
| 287 |
14 => 'resetting', |
| 288 |
15 => 'up', |
| 289 |
16 => 'down' |
| 290 |
); |
| 291 |
|
| 292 |
my $mapping = { |
| 293 |
uxChAdminState => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.5', map => \%map_admin_status }, |
| 294 |
uxChOperState => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.6', map => \%map_operation_status }, |
| 295 |
uxChInUseSeconds => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.7' } |
| 296 |
}; |
| 297 |
my $oid_uxChannelStatusEntry = '.1.3.6.1.4.1.177.15.1.5.6.1'; |
| 298 |
|
| 299 |
sub manage_selection { |
| 300 |
my ($self, %options) = @_; |
| 301 |
|
| 302 |
$self->{global} = { |
| 303 |
total => 0, outofservice => 0, idle => 0, |
| 304 |
pending => 0, waitingforroute => 0, actionlist => 0, |
| 305 |
waitingfordigits => 0, remotesetup => 0, peersetup => 0, |
| 306 |
alerting => 0, inbandinfo => 0, connected => 0, tonegeneration => 0, |
| 307 |
releasing => 0, aborting => 0, resetting => 0, up => 0, down => 0 |
| 308 |
}; |
| 309 |
|
| 310 |
my $snmp_result = $options{snmp}->get_table( |
| 311 |
oid => $oid_uxChannelStatusEntry, |
| 312 |
nothing_quit => 1 |
| 313 |
); |
| 314 |
|
| 315 |
$self->{channels} = {}; |
| 316 |
foreach my $oid (keys %$snmp_result) { |
| 317 |
next if($oid !~ /^$mapping->{uxChOperState}->{oid}\.(\d+)\.(\d+)\.(\d+)\.(\d+)$/); |
| 318 |
my ($shelf, $slot, $port, $channel) = ($1, $2, $3, $4); |
| 319 |
|
| 320 |
next if (defined($self->{option_results}->{filter_shelf_id}) && $self->{option_results}->{filter_shelf_id} ne '' && |
| 321 |
$shelf !~ /$self->{option_results}->{filter_shelf_id}/); |
| 322 |
next if (defined($self->{option_results}->{filter_slot_id}) && $self->{option_results}->{filter_slot_id} ne '' && |
| 323 |
$slot !~ /$self->{option_results}->{filter_slot_id}/); |
| 324 |
next if (defined($self->{option_results}->{filter_port_id}) && $self->{option_results}->{filter_port_id} ne '' && |
| 325 |
$port !~ /$self->{option_results}->{filter_port_id}/); |
| 326 |
next if (defined($self->{option_results}->{filter_channel_id}) && $self->{option_results}->{filter_channel_id} ne '' && |
| 327 |
$channel !~ /$self->{option_results}->{filter_channel_id}/); |
| 328 |
|
| 329 |
my $instance = $shelf . '.' . $slot . '.' . $port . '.' . $channel; |
| 330 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 331 |
|
| 332 |
$self->{global}->{total}++; |
| 333 |
my $oper_state = lc($result->{uxChOperState}); |
| 334 |
|
| 335 |
$self->{global}->{$oper_state}++; |
| 336 |
$self->{channels}->{$instance} = { |
| 337 |
shelf => $shelf, |
| 338 |
slot => $slot, |
| 339 |
port => $port, |
| 340 |
channel => $channel, |
| 341 |
opstatus => $result->{uxChOperState}, |
| 342 |
admstatus => $result->{uxChAdminState}, |
| 343 |
seconds => $result->{uxChInUseSeconds} |
| 344 |
}; |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
1; |
| 349 |
|
| 350 |
__END__ |
| 351 |
|
| 352 |
=head1 MODE |
| 353 |
|
| 354 |
Check channels. |
| 355 |
|
| 356 |
=over 8 |
| 357 |
|
| 358 |
=item B<--filter-counters> |
| 359 |
|
| 360 |
Only display some counters. |
| 361 |
|
| 362 |
=item B<--filter-shelf-id> |
| 363 |
|
| 364 |
Filter channels by shelf ID (can be a regexp). |
| 365 |
|
| 366 |
=item B<--filter-slot-id> |
| 367 |
|
| 368 |
Filter channels by slot ID (can be a regexp). |
| 369 |
|
| 370 |
=item B<--filter-port-id> |
| 371 |
|
| 372 |
Filter channels by port ID (can be a regexp). |
| 373 |
|
| 374 |
=item B<--filter-channel-id> |
| 375 |
|
| 376 |
Filter channels by channel ID (can be a regexp). |
| 377 |
|
| 378 |
=item B<--warning-status> |
| 379 |
|
| 380 |
Define the conditions to match for the status to be WARNING. |
| 381 |
You can use the following variables: %{admstatus}, %{opstatus}, %{display} |
| 382 |
|
| 383 |
=item B<--critical-status> |
| 384 |
|
| 385 |
Define the conditions to match for the status to be CRITICAL. |
| 386 |
You can use the following variables: %{admstatus}, %{opstatus}, %{display} |
| 387 |
|
| 388 |
=item B<--warning-*> B<--critical-*> |
| 389 |
|
| 390 |
Thresholds. |
| 391 |
Can be: 'channels-total', 'channels-outofservice', 'channels-idle', 'channels-pending', |
| 392 |
'channels-waitingforroute', 'channels-actionlist', 'channels-waitingfordigits', |
| 393 |
'channels-remotesetup', 'channels-peersetup', 'channels-alerting', |
| 394 |
'channels-inbandinfo', 'channels-connected', 'channels-tonegeneration', 'channels-releasing', |
| 395 |
'channels-aborting', 'channels-resetting', 'channels-up', 'channels-down', 'channel-lifetime'. |
| 396 |
|
| 397 |
=back |
| 398 |
|
| 399 |
=cut |