centreon-plugins/snmp_standard/mode/swap.pm

151 lines
5.0 KiB
Perl
Raw Normal View History

2013-12-13 16:14:12 +01:00
#
2020-01-06 15:19:23 +01:00
# Copyright 2020 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
2013-12-13 16:14:12 +01:00
package snmp_standard::mode::swap;
2013-12-13 16:14:12 +01:00
2019-06-13 14:20:21 +02:00
use base qw(centreon::plugins::templates::counter);
2013-12-13 16:14:12 +01:00
use strict;
use warnings;
2019-06-13 14:20:21 +02:00
sub custom_swap_output {
my ($self, %options) = @_;
my $msg = sprintf("Swap Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)",
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}),
$self->{result_values}->{prct_used_absolute},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}),
$self->{result_values}->{prct_free_absolute});
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'swap', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{swap} = [
{ label => 'usage', nlabel => 'swap.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_swap_output'),
perfdatas => [
{ label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 },
],
}
},
{ label => 'usage-free', display_ok => 0, nlabel => 'swap.free.bytes', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_swap_output'),
perfdatas => [
{ label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 },
],
}
},
{ label => 'usage-prct', display_ok => 0, nlabel => 'swap.usage.percentage', set => {
key_values => [ { name => 'prct_used' } ],
output_template => 'Used : %.2f %%',
perfdatas => [
2019-06-13 16:35:18 +02:00
{ label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100,
2019-06-13 14:20:21 +02:00
unit => '%' },
],
}
},
];
}
2013-12-13 16:14:12 +01:00
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
2019-06-13 14:20:21 +02:00
$options{options}->add_options(arguments => {
'no-swap:s' => { name => 'no_swap' },
});
2013-12-13 16:14:12 +01:00
return $self;
}
sub check_options {
my ($self, %options) = @_;
2019-06-13 14:20:21 +02:00
$self->SUPER::check_options(%options);
2013-12-13 16:14:12 +01:00
2019-06-13 14:20:21 +02:00
$self->{no_swap} = 'critical';
2014-06-23 15:05:42 +02:00
if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') {
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'.");
$self->{output}->option_exit();
}
2019-06-13 14:20:21 +02:00
$self->{no_swap} = $self->{option_results}->{no_swap};
2014-06-23 15:05:42 +02:00
}
2013-12-13 16:14:12 +01:00
}
2019-06-13 14:20:21 +02:00
sub manage_selection {
2013-12-13 16:14:12 +01:00
my ($self, %options) = @_;
my $oid_memTotalSwap = '.1.3.6.1.4.1.2021.4.3.0'; # KB
my $oid_memAvailSwap = '.1.3.6.1.4.1.2021.4.4.0'; # KB
2019-06-13 14:20:21 +02:00
my $result = $options{snmp}->get_leef(oids => [$oid_memTotalSwap, $oid_memAvailSwap], nothing_quit => 1);
2013-12-13 16:14:12 +01:00
2014-06-23 15:05:42 +02:00
if ($result->{$oid_memTotalSwap} == 0) {
$self->{output}->output_add(severity => $self->{no_swap},
2019-06-13 14:20:21 +02:00
short_msg => 'No active swap');
return ;
2014-06-23 15:05:42 +02:00
}
2013-12-13 16:14:12 +01:00
2019-06-13 14:20:21 +02:00
my $free = $result->{$oid_memAvailSwap} * 1024;
my $total = $result->{$oid_memTotalSwap} * 1024;
my $prct_used = ($total - $free) * 100 / $total;
$self->{swap} = {
total => $total,
used => $total - $free,
free => $free,
prct_used => $prct_used,
prct_free => 100 - $prct_used,
};
2013-12-13 16:14:12 +01:00
}
1;
__END__
=head1 MODE
Check swap memory (UCD-SNMP-MIB).
2013-12-13 16:14:12 +01:00
=over 8
2014-06-23 15:05:42 +02:00
=item B<--no-swap>
Threshold if no active swap (default: 'critical').
2019-06-13 14:20:21 +02:00
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
2013-12-13 16:14:12 +01:00
=back
=cut