| 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 apps::inin::mediaserver::snmp::mode::component; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::hardware); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_system { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{cb_hook2} = 'snmp_execute'; |
| 32 |
|
| 33 |
$self->{thresholds} = { |
| 34 |
device => [ |
| 35 |
['unknown', 'UNKNOWN'], |
| 36 |
['up', 'OK'], |
| 37 |
['down', 'CRITICAL'], |
| 38 |
['congested', 'WARNING'], |
| 39 |
['restarting', 'OK'], |
| 40 |
['quiescing', 'OK'], |
| 41 |
['testing', 'OK'], |
| 42 |
], |
| 43 |
}; |
| 44 |
|
| 45 |
$self->{components_path} = 'apps::inin::mediaserver::snmp::mode::components'; |
| 46 |
$self->{components_module} = ['device']; |
| 47 |
} |
| 48 |
|
| 49 |
sub new { |
| 50 |
my ($class, %options) = @_; |
| 51 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); |
| 52 |
bless $self, $class; |
| 53 |
|
| 54 |
$options{options}->add_options(arguments => |
| 55 |
{ |
| 56 |
}); |
| 57 |
|
| 58 |
return $self; |
| 59 |
} |
| 60 |
|
| 61 |
sub snmp_execute { |
| 62 |
my ($self, %options) = @_; |
| 63 |
|
| 64 |
$self->{snmp} = $options{snmp}; |
| 65 |
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); |
| 66 |
} |
| 67 |
|
| 68 |
1; |
| 69 |
|
| 70 |
=head1 MODE |
| 71 |
|
| 72 |
Check hardware devices. |
| 73 |
|
| 74 |
=over 8 |
| 75 |
|
| 76 |
=item B<--component> |
| 77 |
|
| 78 |
Which component to check (default: '.*'). |
| 79 |
Can be: 'device'. |
| 80 |
|
| 81 |
=item B<--no-component> |
| 82 |
|
| 83 |
Define the expected status if no components are found (default: critical). |
| 84 |
|
| 85 |
=item B<--threshold-overload> |
| 86 |
|
| 87 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). |
| 88 |
Example: --threshold-overload='device,WARNING,restarting' |
| 89 |
|
| 90 |
=back |
| 91 |
|
| 92 |
=cut |
| 93 |
|
| 94 |
package apps::inin::mediaserver::snmp::mode::components::device; |
| 95 |
|
| 96 |
use strict; |
| 97 |
use warnings; |
| 98 |
|
| 99 |
my %map_status = (1 => 'unknown', 2 => 'up', 3 => 'down', 4 => 'congested', |
| 100 |
5 => 'restarting', 6 => 'quiescing', 7 => 'testing' |
| 101 |
); |
| 102 |
|
| 103 |
my $mapping = { |
| 104 |
i3MsGeneralInfoOperStatus => { oid => '.1.3.6.1.4.1.2793.8227.1.2', map => \%map_status }, |
| 105 |
}; |
| 106 |
|
| 107 |
sub load { |
| 108 |
my ($self) = @_; |
| 109 |
|
| 110 |
push @{$self->{request}}, { oid => $mapping->{i3MsGeneralInfoOperStatus}->{oid} }; |
| 111 |
} |
| 112 |
|
| 113 |
sub check { |
| 114 |
my ($self) = @_; |
| 115 |
|
| 116 |
$self->{output}->output_add(long_msg => "Checking devices"); |
| 117 |
$self->{components}->{device} = {name => 'devices', total => 0, skip => 0}; |
| 118 |
return if ($self->check_filter(section => 'device')); |
| 119 |
|
| 120 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{i3MsGeneralInfoOperStatus}->{oid}}, instance => '0'); |
| 121 |
|
| 122 |
return if (!defined($result->{i3MsGeneralInfoOperStatus})); |
| 123 |
$self->{components}->{device}->{total}++; |
| 124 |
$self->{output}->output_add(long_msg => sprintf("device status is '%s' [instance = %s]", |
| 125 |
$result->{i3MsGeneralInfoOperStatus}, '0')); |
| 126 |
my $exit = $self->get_severity(section => 'device', value => $result->{i3MsGeneralInfoOperStatus}); |
| 127 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 128 |
$self->{output}->output_add(severity => $exit, |
| 129 |
short_msg => sprintf("Device status is '%s'", $result->{i3MsGeneralInfoOperStatus})); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
1; |