| 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::nortel::standard::snmp::mode::stack; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use POSIX; |
| 28 |
use network::nortel::standard::snmp::mode::components::resources qw($map_comp_status); |
| 29 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 30 |
|
| 31 |
my $unitdiv = { s => 1, w => 604800, d => 86400, h => 3600, m => 60 }; |
| 32 |
my $unitdiv_long = { s => 'seconds', w => 'weeks', d => 'days', h => 'hours', m => 'minutes' }; |
| 33 |
|
| 34 |
sub custom_expires_perfdata { |
| 35 |
my ($self, %options) = @_; |
| 36 |
|
| 37 |
$self->{output}->perfdata_add( |
| 38 |
nlabel => $self->{nlabel} . '.' . $unitdiv_long->{ $self->{instance_mode}->{option_results}->{unit} }, |
| 39 |
unit => $self->{instance_mode}->{option_results}->{unit}, |
| 40 |
instances => $self->{result_values}->{serial}, |
| 41 |
value => floor($self->{result_values}->{detected_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }), |
| 42 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 43 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 44 |
min => 0 |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
sub custom_expires_threshold { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return $self->{perfdata}->threshold_check( |
| 52 |
value => floor($self->{result_values}->{detected_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }), |
| 53 |
threshold => [ |
| 54 |
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, |
| 55 |
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }, |
| 56 |
{ label => 'unknown-'. $self->{thlabel}, exit_litteral => 'unknown' } |
| 57 |
] |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
sub custom_unit_status_output { |
| 62 |
my ($self, %options) = @_; |
| 63 |
|
| 64 |
return sprintf( |
| 65 |
'operational state: %s [admin state: %s]', |
| 66 |
$self->{result_values}->{operState}, |
| 67 |
$self->{result_values}->{adminState} |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
sub unit_long_output { |
| 72 |
my ($self, %options) = @_; |
| 73 |
|
| 74 |
return "checking stack unit '" . $options{instance} . "'"; |
| 75 |
} |
| 76 |
|
| 77 |
sub prefix_unit_output { |
| 78 |
my ($self, %options) = @_; |
| 79 |
|
| 80 |
return "Stack unit '" . $options{instance} . "' "; |
| 81 |
} |
| 82 |
|
| 83 |
sub set_counters { |
| 84 |
my ($self, %options) = @_; |
| 85 |
|
| 86 |
$self->{maps_counters_type} = [ |
| 87 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 88 |
{ name => 'units', type => 3, cb_prefix_output => 'prefix_unit_output', cb_long_output => 'unit_long_output', indent_long_output => ' ', message_multiple => 'All stack units are ok', |
| 89 |
group => [ |
| 90 |
{ name => 'unit_global', type => 0, skipped_code => { -10 => 1 } }, |
| 91 |
{ name => 'unit_detected', type => 0, skipped_code => { -10 => 1 } } |
| 92 |
] |
| 93 |
} |
| 94 |
]; |
| 95 |
|
| 96 |
$self->{maps_counters}->{global} = [ |
| 97 |
{ label => 'units-total', nlabel => 'stack.units.count', set => { |
| 98 |
key_values => [ { name => 'units' } ], |
| 99 |
output_template => 'Number of units: %s', |
| 100 |
perfdatas => [ |
| 101 |
{ template => '%s', min => 0 } |
| 102 |
] |
| 103 |
} |
| 104 |
} |
| 105 |
]; |
| 106 |
|
| 107 |
$self->{maps_counters}->{unit_global} = [ |
| 108 |
{ |
| 109 |
label => 'unit-status', |
| 110 |
type => 2, |
| 111 |
warning_default => '%{adminState} eq "enable" && %{operState} =~ /nonFatalErr|warning/i', |
| 112 |
critical_default => '%{adminState} eq "enable" && %{operState} =~ /fatalErr/i', |
| 113 |
set => { |
| 114 |
key_values => [ { name => 'operState' }, { name => 'adminState' }, { name => 'serial' } ], |
| 115 |
closure_custom_output => $self->can('custom_unit_status_output'), |
| 116 |
closure_custom_perfdata => sub { return 0; }, |
| 117 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 118 |
} |
| 119 |
} |
| 120 |
]; |
| 121 |
|
| 122 |
$self->{maps_counters}->{unit_detected} = [ |
| 123 |
{ label => 'unit-detected', nlabel => 'stack.unit.detected', set => { |
| 124 |
key_values => [ { name => 'detected_seconds' }, { name => 'detected_human' }, { name => 'serial' } ], |
| 125 |
output_template => 'detected: %s', |
| 126 |
output_use => 'detected_human', |
| 127 |
closure_custom_perfdata => $self->can('custom_expires_perfdata'), |
| 128 |
closure_custom_threshold_check => $self->can('custom_expires_threshold') |
| 129 |
} |
| 130 |
} |
| 131 |
]; |
| 132 |
} |
| 133 |
|
| 134 |
sub new { |
| 135 |
my ($class, %options) = @_; |
| 136 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 137 |
bless $self, $class; |
| 138 |
|
| 139 |
$options{options}->add_options(arguments => { |
| 140 |
'unit:s' => { name => 'unit', default => 's' } |
| 141 |
}); |
| 142 |
|
| 143 |
return $self; |
| 144 |
} |
| 145 |
|
| 146 |
sub check_options { |
| 147 |
my ($self, %options) = @_; |
| 148 |
$self->SUPER::check_options(%options); |
| 149 |
|
| 150 |
if ($self->{option_results}->{unit} eq '' || !defined($unitdiv->{$self->{option_results}->{unit}})) { |
| 151 |
$self->{option_results}->{unit} = 's'; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
my $mapping_admin_state = { |
| 156 |
1 => 'other', 2 => 'notAvail', 3 => 'disable', 4 => 'enable', 5 => 'reset', 6 => 'test' |
| 157 |
}; |
| 158 |
|
| 159 |
my $mapping = { |
| 160 |
serial => { oid => '.1.3.6.1.4.1.45.1.6.3.3.1.1.7' }, # s5ChasComSerNum |
| 161 |
lastChange => { oid => '.1.3.6.1.4.1.45.1.6.3.3.1.1.8' }, # s5ChasComLstChng |
| 162 |
adminState => { oid => '.1.3.6.1.4.1.45.1.6.3.3.1.1.9', map => $mapping_admin_state }, # s5ChasComAdminState |
| 163 |
operState => { oid => '.1.3.6.1.4.1.45.1.6.3.3.1.1.10', map => $map_comp_status } # s5ChasComOperState |
| 164 |
}; |
| 165 |
my $oid_s5ChasComEntry = '.1.3.6.1.4.1.45.1.6.3.3.1.1'; |
| 166 |
|
| 167 |
sub manage_selection { |
| 168 |
my ($self, %options) = @_; |
| 169 |
|
| 170 |
my $oid_s5ChasGrpType = '.1.3.6.1.4.1.45.1.6.3.2.1.1.2'; |
| 171 |
my $snmp_result = $options{snmp}->get_table( |
| 172 |
oid => $oid_s5ChasGrpType, |
| 173 |
nothing_quit => 1 |
| 174 |
); |
| 175 |
|
| 176 |
my $groups = {}; |
| 177 |
foreach (keys %$snmp_result) { |
| 178 |
next if ($snmp_result->{$_} ne '.1.3.6.1.4.1.45.1.6.1.2.8'); |
| 179 |
/^$oid_s5ChasGrpType\.(\d+)/; |
| 180 |
$groups->{$1} = 1; |
| 181 |
} |
| 182 |
|
| 183 |
$snmp_result = $options{snmp}->get_table( |
| 184 |
oid => $oid_s5ChasComEntry, |
| 185 |
start => $mapping->{serial}->{oid}, |
| 186 |
end => $mapping->{operState}->{oid} |
| 187 |
); |
| 188 |
|
| 189 |
$self->{global} = { units => 0 }; |
| 190 |
$self->{units} = {}; |
| 191 |
foreach (keys %$snmp_result) { |
| 192 |
next if (!(/^$mapping->{serial}->{oid}\.(\d+)\.(.*)$/ && defined($groups->{$1}))); |
| 193 |
|
| 194 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1 . '.' . $2); |
| 195 |
|
| 196 |
$self->{units}->{ $result->{serial} }->{unit_global} = $result; |
| 197 |
$self->{units}->{ $result->{serial} }->{unit_detected} = { |
| 198 |
detected_seconds => floor($result->{lastChange} / 100), |
| 199 |
detected_human => centreon::plugins::misc::change_seconds( |
| 200 |
value => floor($result->{lastChange} / 100) |
| 201 |
), |
| 202 |
serial => $result->{serial} |
| 203 |
}; |
| 204 |
$self->{global}->{units}++; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
1; |
| 209 |
|
| 210 |
__END__ |
| 211 |
|
| 212 |
=head1 MODE |
| 213 |
|
| 214 |
Check stack units. |
| 215 |
|
| 216 |
=over 8 |
| 217 |
|
| 218 |
=item B<--unknown-unit-status> |
| 219 |
|
| 220 |
Define the conditions to match for the status to be UNKNOWN. |
| 221 |
You can use the following variables: %{operState}, %{adminState}, %{serial} |
| 222 |
|
| 223 |
=item B<--warning-unit-status> |
| 224 |
|
| 225 |
Define the conditions to match for the status to be WARNING (default: '%{adminState} eq "enable" && %{operState} =~ /nonFatalErr|warning/i'). |
| 226 |
You can use the following variables: %{operState}, %{adminState}, %{serial} |
| 227 |
|
| 228 |
=item B<--critical-unit-status> |
| 229 |
|
| 230 |
Define the conditions to match for the status to be CRITICAL (default: '%{adminState} eq "enable" && %{operState} =~ /fatalErr/i'). |
| 231 |
You can use the following variables: %{operState}, %{adminState}, %{serial} |
| 232 |
|
| 233 |
=item B<--unit> |
| 234 |
|
| 235 |
Select the time unit for the performance data and thresholds. May be 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days, 'w' for weeks. Default is seconds. |
| 236 |
|
| 237 |
=item B<--warning-*> B<--critical-*> |
| 238 |
|
| 239 |
Thresholds. |
| 240 |
Can be: 'units-total', 'unit-detected'. |
| 241 |
|
| 242 |
=back |
| 243 |
|
| 244 |
=cut |