| 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::alcatel::omniswitch::snmp::mode::memory; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
$options{options}->add_options(arguments => { |
| 34 |
"warning:s" => { name => 'warning', default => '' }, |
| 35 |
"critical:s" => { name => 'critical', default => '' }, |
| 36 |
}); |
| 37 |
|
| 38 |
return $self; |
| 39 |
} |
| 40 |
|
| 41 |
sub check_options { |
| 42 |
my ($self, %options) = @_; |
| 43 |
$self->SUPER::init(%options); |
| 44 |
|
| 45 |
($self->{warn1m}, $self->{warn1h}) = split /,/, $self->{option_results}->{warning}; |
| 46 |
($self->{crit1m}, $self->{crit1h}) = split /,/, $self->{option_results}->{critical}; |
| 47 |
|
| 48 |
if (($self->{perfdata}->threshold_validate(label => 'warn1m', value => $self->{warn1m})) == 0) { |
| 49 |
$self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1m} . "'."); |
| 50 |
$self->{output}->option_exit(); |
| 51 |
} |
| 52 |
if (($self->{perfdata}->threshold_validate(label => 'warn1h', value => $self->{warn1h})) == 0) { |
| 53 |
$self->{output}->add_option_msg(short_msg => "Wrong warning (1hour) threshold '" . $self->{warn1h} . "'."); |
| 54 |
$self->{output}->option_exit(); |
| 55 |
} |
| 56 |
if (($self->{perfdata}->threshold_validate(label => 'crit1m', value => $self->{crit1m})) == 0) { |
| 57 |
$self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1m} . "'."); |
| 58 |
$self->{output}->option_exit(); |
| 59 |
} |
| 60 |
if (($self->{perfdata}->threshold_validate(label => 'crit5h', value => $self->{crit5})) == 0) { |
| 61 |
$self->{output}->add_option_msg(short_msg => "Wrong critical (1hour) threshold '" . $self->{crit1h} . "'."); |
| 62 |
$self->{output}->option_exit(); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
sub check_memory { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
my $exit1 = $self->{perfdata}->threshold_check(value => $options{'1min'}, threshold => [ { label => 'crit1m', exit_litteral => 'critical' }, |
| 70 |
{ label => 'warn1m', exit_litteral => 'warning' }, |
| 71 |
]); |
| 72 |
|
| 73 |
my $exit2 = $self->{perfdata}->threshold_check(value => $options{'1hour'}, threshold => [ { label => 'crit1h', exit_litteral => 'critical' }, |
| 74 |
{ label => 'warn1h', exit_litteral => 'warning' }, |
| 75 |
]); |
| 76 |
|
| 77 |
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); |
| 78 |
|
| 79 |
$self->{output}->output_add(severity => $exit, |
| 80 |
short_msg => sprintf("%s: %.2f%% (1min), %.2f%% (1hour)", $options{name}, $options{'1min'}, $options{'1hour'})); |
| 81 |
|
| 82 |
$self->{output}->perfdata_add(label => "mem1m" . $options{perf_label} , unit => '%', |
| 83 |
value => $options{'1min'}, |
| 84 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1m'), |
| 85 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1m'), |
| 86 |
min => 0, max => 100); |
| 87 |
$self->{output}->perfdata_add(label => "mem1h" . $options{perf_label} , unit => '%', |
| 88 |
value => $options{'1hour'}, |
| 89 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1h'), |
| 90 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1h'), |
| 91 |
min => 0, max => 100); |
| 92 |
} |
| 93 |
|
| 94 |
sub run { |
| 95 |
my ($self, %options) = @_; |
| 96 |
|
| 97 |
my $mapping = { |
| 98 |
aos6 => { |
| 99 |
entry_device => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1', |
| 100 |
entry_module => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.2.1.1', |
| 101 |
device => { |
| 102 |
healthDeviceMemory1MinAvg => { oid => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.10' }, |
| 103 |
healthDeviceMemory1HrAvg => { oid => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.11' }, |
| 104 |
}, |
| 105 |
module => { |
| 106 |
healthModuleMemory1MinAvg => { oid => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.2.1.1.11' }, |
| 107 |
healthModuleMemory1HrAvg => { oid => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.2.1.1.12' }, |
| 108 |
}, |
| 109 |
}, |
| 110 |
aos7 => { |
| 111 |
entry_module => '.1.3.6.1.4.1.6486.801.1.2.1.16.1.1.1.1.1', |
| 112 |
module => { |
| 113 |
healthModuleMemory1MinAvg => { oid => '.1.3.6.1.4.1.6486.801.1.2.1.16.1.1.1.1.1.8' }, |
| 114 |
healthModuleMemory1HrAvg => { oid => '.1.3.6.1.4.1.6486.801.1.2.1.16.1.1.1.1.1.9' }, |
| 115 |
}, |
| 116 |
}, |
| 117 |
}; |
| 118 |
|
| 119 |
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ |
| 120 |
{ oid => $mapping->{aos6}->{entry_device}, start => $mapping->{aos6}->{device}->{healthDeviceMemory1MinAvg}->{oid}, end => $mapping->{aos6}->{device}->{healthDeviceMemory1HrAvg}->{oid} }, |
| 121 |
{ oid => $mapping->{aos6}->{entry_module}, start => $mapping->{aos6}->{module}->{healthModuleMemory1MinAvg}->{oid}, end => $mapping->{aos6}->{module}->{healthModuleMemory1HrAvg}->{oid} }, |
| 122 |
{ oid => $mapping->{aos7}->{entry_module}, start => $mapping->{aos7}->{module}->{healthModuleMemory1MinAvg}->{oid}, end => $mapping->{aos7}->{module}->{healthModuleMemory1HrAvg}->{oid} }, |
| 123 |
], nothing_quit => 1); |
| 124 |
|
| 125 |
my $type = 'aos6'; |
| 126 |
if (scalar(keys %{$snmp_result->{ $mapping->{aos7}->{entry_module} }}) > 0) { |
| 127 |
$type = 'aos7'; |
| 128 |
} |
| 129 |
|
| 130 |
if (defined($mapping->{$type}->{device})) { |
| 131 |
my $result = $options{snmp}->map_instance(mapping => $mapping->{$type}->{device}, results => $snmp_result->{ $mapping->{$type}->{entry_device} }, instance => '0'); |
| 132 |
$self->check_memory( |
| 133 |
name => 'Device memory', |
| 134 |
perf_label => '_device', |
| 135 |
'1min' => $result->{healthDeviceMemory1MinAvg}, |
| 136 |
'1hour' => $result->{healthDeviceMemory1HrAvg} |
| 137 |
); |
| 138 |
} |
| 139 |
|
| 140 |
foreach my $oid ($options{snmp}->oid_lex_sort(keys %{$snmp_result->{ $mapping->{$type}->{entry_module} }})) { |
| 141 |
next if ($oid !~ /^$mapping->{$type}->{module}->{healthModuleMemory1MinAvg}->{oid}\.(.*)$/); |
| 142 |
my $result = $options{snmp}->map_instance(mapping => $mapping->{$type}->{module}, results => $snmp_result->{ $mapping->{$type}->{entry_module} }, instance => $1); |
| 143 |
|
| 144 |
$self->check_memory( |
| 145 |
name => "Module memory '$1'", |
| 146 |
perf_label => "_module_$1", |
| 147 |
'1min' => $result->{healthModuleMemory1MinAvg}, |
| 148 |
'1hour' => $result->{healthModuleMemory1HrAvg} |
| 149 |
); |
| 150 |
} |
| 151 |
|
| 152 |
$self->{output}->display(); |
| 153 |
$self->{output}->exit(); |
| 154 |
} |
| 155 |
|
| 156 |
1; |
| 157 |
|
| 158 |
__END__ |
| 159 |
|
| 160 |
=head1 MODE |
| 161 |
|
| 162 |
Check memory usage (AlcatelIND1Health.mib). |
| 163 |
|
| 164 |
=over 8 |
| 165 |
|
| 166 |
=item B<--warning> |
| 167 |
|
| 168 |
Warning threshold in percent (1m,1h). |
| 169 |
|
| 170 |
=item B<--critical> |
| 171 |
|
| 172 |
Critical threshold in percent (1m,1h). |
| 173 |
|
| 174 |
=back |
| 175 |
|
| 176 |
=cut |