This commit is contained in:
garnier-quentin 2020-09-21 08:52:52 +02:00
parent 774e74886e
commit a83e4d3d2f
7 changed files with 92 additions and 108 deletions

View File

@ -30,15 +30,15 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{
"warning:s" => { name => 'warning' }, "warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' }, "critical:s" => { name => 'critical' },
"swap" => { name => 'check_swap' }, "swap" => { name => 'check_swap' },
"warning-swap:s" => { name => 'warning_swap' }, "warning-swap:s" => { name => 'warning_swap' },
"critical-swap:s" => { name => 'critical_swap' }, "critical-swap:s" => { name => 'critical_swap' },
"no-swap:s" => { name => 'no_swap' }, "no-swap:s" => { name => 'no_swap' }
}); });
$self->{no_swap} = 'critical'; $self->{no_swap} = 'critical';
return $self; return $self;
} }
@ -93,8 +93,10 @@ sub run {
push @$oids, ($oid_memTotalSwap, $oid_memAvailSwap); push @$oids, ($oid_memTotalSwap, $oid_memAvailSwap);
} }
my $result = $self->{snmp}->get_leef(oids => $oids, my $result = $self->{snmp}->get_leef(
nothing_quit => 1); oids => $oids,
nothing_quit => 1
);
my $cached_used = $result->{$oid_memCached} * 1024; my $cached_used = $result->{$oid_memCached} * 1024;
my $physical_used = ($result->{$oid_memTotalReal} * 1024) - ($result->{$oid_memAvailReal} * 1024); my $physical_used = ($result->{$oid_memTotalReal} * 1024) - ($result->{$oid_memAvailReal} * 1024);
@ -112,25 +114,35 @@ sub run {
my ($nobuf_value, $nobuf_unit) = $self->{perfdata}->change_bytes(value => $nobuf_used); my ($nobuf_value, $nobuf_unit) = $self->{perfdata}->change_bytes(value => $nobuf_used);
my ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $cached_used); my ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $cached_used);
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(
short_msg => sprintf("Ram Total: %s, Used (-cache): %s (%.2f%%), Cached: %s", severity => $exit,
short_msg => sprintf(
"Ram Total: %s, Used (-cache): %s (%.2f%%), Cached: %s",
$total_value . " " . $total_unit, $total_value . " " . $total_unit,
$nobuf_value . " " . $nobuf_unit, $prct_used, $nobuf_value . " " . $nobuf_unit, $prct_used,
$cached_value . " " . $cached_unit)); $cached_value . " " . $cached_unit
)
);
$self->{output}->perfdata_add(label => "cached", nlabel => 'memory.cached.bytes', unit => 'B', $self->{output}->perfdata_add(
label => "cached", nlabel => 'memory.cached.bytes', unit => 'B',
value => $cached_used, value => $cached_used,
min => 0); min => 0
$self->{output}->perfdata_add(label => "used", nlabel => 'memory.usage.bytes', unit => 'B', );
$self->{output}->perfdata_add(
label => "used", nlabel => 'memory.usage.bytes', unit => 'B',
value => $nobuf_used, value => $nobuf_used,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1),
min => 0, max => $total_size); min => 0, max => $total_size
);
if (defined($self->{option_results}->{check_swap})) { if (defined($self->{option_results}->{check_swap})) {
if ($result->{$oid_memTotalSwap} == 0) { if ($result->{$oid_memTotalSwap} == 0) {
$self->{output}->output_add(severity => $self->{no_swap}, $self->{output}->output_add(
short_msg => 'No active swap.'); severity => $self->{no_swap},
short_msg => 'No active swap.'
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -145,17 +157,23 @@ sub run {
my ($swap_used_value, $swap_used_unit) = $self->{perfdata}->change_bytes(value => $swap_used); my ($swap_used_value, $swap_used_unit) = $self->{perfdata}->change_bytes(value => $swap_used);
my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used)); my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used));
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(
short_msg => sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", severity => $exit,
short_msg => sprintf(
"Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_value . " " . $total_unit, $total_value . " " . $total_unit,
$swap_used_value . " " . $swap_used_unit, $prct_used, $swap_used_value . " " . $swap_used_unit, $prct_used,
$swap_free_value . " " . $swap_free_unit, (100 - $prct_used))); $swap_free_value . " " . $swap_free_unit, (100 - $prct_used)
)
);
$self->{output}->perfdata_add(label => "swap", nlabel => 'swap.usage.bytes', unit => 'B', $self->{output}->perfdata_add(
label => "swap", nlabel => 'swap.usage.bytes', unit => 'B',
value => $swap_used, value => $swap_used,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-swap', total => $total_size, cast_int => 1), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-swap', total => $total_size, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-swap', total => $total_size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-swap', total => $total_size, cast_int => 1),
min => 0, max => $total_size); min => 0, max => $total_size
);
} }
$self->{output}->display(); $self->{output}->display();

View File

@ -30,7 +30,7 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( $self->{modes} = {
'cpu' => 'snmp_standard::mode::cpu', 'cpu' => 'snmp_standard::mode::cpu',
'cpu-detailed' => 'snmp_standard::mode::cpudetailed', 'cpu-detailed' => 'snmp_standard::mode::cpudetailed',
'diskio' => 'snmp_standard::mode::diskio', 'diskio' => 'snmp_standard::mode::diskio',
@ -48,8 +48,8 @@ sub new {
'swap' => 'snmp_standard::mode::swap', 'swap' => 'snmp_standard::mode::swap',
'time' => 'snmp_standard::mode::ntp', 'time' => 'snmp_standard::mode::ntp',
'tcpcon' => 'snmp_standard::mode::tcpcon', 'tcpcon' => 'snmp_standard::mode::tcpcon',
'uptime' => 'snmp_standard::mode::uptime', 'uptime' => 'snmp_standard::mode::uptime'
); };
return $self; return $self;
} }

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -46,11 +46,15 @@ sub set_counters {
]; ];
$self->{maps_counters}->{mountpoints} = [ $self->{maps_counters}->{mountpoints} = [
{ label => 'status', set => { {
label => 'status',
type => 2,
critical_default => '%{options} !~ /^rw/i && %{type} !~ /tmpfs|squashfs/i',
set => {
key_values => [ { name => 'display' }, { name => 'options' }, { name => 'type' } ], key_values => [ { name => 'display' }, { name => 'options' }, { name => 'type' } ],
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
} }
]; ];
@ -64,21 +68,12 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-device:s' => { name => 'filter_device' }, 'filter-device:s' => { name => 'filter_device' },
'filter-mountpoint:s' => { name => 'filter_mountpoint' }, 'filter-mountpoint:s' => { name => 'filter_mountpoint' },
'filter-type:s' => { name => 'filter_type' }, 'filter-type:s' => { name => 'filter_type' }
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{options} !~ /^rw/i && %{type} !~ /tmpfs|squashfs/i' }
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -114,12 +109,12 @@ sub manage_selection {
$self->{mountpoints}->{$mountpoint} = { $self->{mountpoints}->{$mountpoint} = {
display => $mountpoint, display => $mountpoint,
type => $type, type => $type,
options => $options, options => $options
}; };
} }
if (scalar(keys %{$self->{mountpoints}}) <= 0) { if (scalar(keys %{$self->{mountpoints}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No mount points found"); $self->{output}->add_option_msg(short_msg => 'No mount points found');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
} }

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
my %state_map_ntpq = ( my %state_map_ntpq = (
'<sp>' => 'discarded due to high stratum and/or failed sanity checks', '<sp>' => 'discarded due to high stratum and/or failed sanity checks',
@ -149,12 +149,12 @@ sub set_counters {
]; ];
$self->{maps_counters}->{peers} = [ $self->{maps_counters}->{peers} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, set => {
key_values => [ { name => 'state' }, { name => 'type' }, { name => 'reach' }, { name => 'display' } ], key_values => [ { name => 'state' }, { name => 'type' }, { name => 'reach' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'offset', display_ok => 0, set => { { label => 'offset', display_ok => 0, set => {
@ -192,10 +192,7 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'ntp-mode:s' => { name => 'ntp_mode', default => 'ntpq' }, 'ntp-mode:s' => { name => 'ntp_mode', default => 'ntpq' },
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'filter-state:s' => { name => 'filter_state' }, 'filter-state:s' => { name => 'filter_state' }
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
}); });
return $self; return $self;
@ -217,8 +214,6 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "ntp mode '" . $self->{option_results}->{ntp_mode} . "' not implemented" ); $self->{output}->add_option_msg(short_msg => "ntp mode '" . $self->{option_results}->{ntp_mode} . "' not implemented" );
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
} }
sub manage_selection { sub manage_selection {

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
sub custom_status_output { sub custom_status_output {
@ -68,11 +68,11 @@ sub set_counters {
]; ];
$self->{maps_counters}->{interface} = [ $self->{maps_counters}->{interface} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, critical_default => '%{status} ne "RU"', set => {
key_values => [ { name => 'status' }, { name => 'display' } ], key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'in-discard', set => { { label => 'in-discard', set => {
@ -130,10 +130,7 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-state:s' => { name => 'filter_state', }, 'filter-state:s' => { name => 'filter_state', },
'filter-interface:s' => { name => 'filter_interface' }, 'filter-interface:s' => { name => 'filter_interface' },
'no-loopback' => { name => 'no_loopback', }, 'no-loopback' => { name => 'no_loopback' }
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} ne "RU"' }
}); });
return $self; return $self;
@ -145,13 +142,6 @@ sub prefix_interface_output {
return "Interface '" . $options{instance_value}->{display} . "' "; return "Interface '" . $options{instance_value}->{display} . "' ";
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
}
sub do_selection { sub do_selection {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -82,11 +82,11 @@ sub set_counters {
} }
]; ];
$self->{maps_counters}->{sc} = [ $self->{maps_counters}->{sc} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, critical_default => '%{active} =~ /failed/i', set => {
key_values => [ { name => 'load' }, { name => 'active' }, { name => 'sub' }, { name => 'boot' }, { name => 'display' } ], key_values => [ { name => 'load' }, { name => 'active' }, { name => 'sub' }, { name => 'boot' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
} }
]; ];
@ -98,21 +98,12 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' }
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{active} =~ /failed/i' }
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_sc_output { sub prefix_sc_output {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
sub custom_status_output { sub custom_status_output {
@ -104,11 +104,11 @@ sub set_counters {
]; ];
$self->{maps_counters}->{interface} = [ $self->{maps_counters}->{interface} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, critical_default => '%{status} ne "RU"', set => {
key_values => [ { name => 'status' }, { name => 'display' } ], key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'in', set => { { label => 'in', set => {
@ -140,10 +140,7 @@ sub new {
'filter-interface:s' => { name => 'filter_interface' }, 'filter-interface:s' => { name => 'filter_interface' },
'units:s' => { name => 'units', default => 'b/s' }, 'units:s' => { name => 'units', default => 'b/s' },
'speed:s' => { name => 'speed' }, 'speed:s' => { name => 'speed' },
'no-loopback' => { name => 'no_loopback', }, 'no-loopback' => { name => 'no_loopback' }
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} ne "RU"' },
}); });
return $self; return $self;
@ -172,8 +169,6 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "To use percent, you need to set --speed option."); $self->{output}->add_option_msg(short_msg => "To use percent, you need to set --speed option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
} }
sub do_selection { sub do_selection {