diff --git a/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm b/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm index 4c5604953..1cbbe37ec 100644 --- a/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm +++ b/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm @@ -50,29 +50,6 @@ my $thresholds = { ], }; -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -127,8 +104,7 @@ sub run { my $result = $self->{snmp}->get_table(oid => $oid_bgpPeerTable, nothing_quit => 1); - if (defined $self->{option_results}->{peer}) { - + if (defined($self->{option_results}->{peer})) { my $bgpPeerState = $result->{$oid_bgpPeerState . '.' . $self->{option_results}->{peer}}; my $bgpPeerAdminStatus = $result->{$oid_bgpPeerAdminStatus . '.' . $self->{option_results}->{peer}}; my $bgpPeerRemoteAs = $result->{$oid_bgpPeerRemoteAs . '.' . $self->{option_results}->{peer}}; @@ -136,29 +112,28 @@ sub run { my $bgpLocalInfos = $result->{$oid_bgpPeerLocalAddr . '.' . $self->{option_results}->{peer}} . ':' . $result->{$oid_bgpPeerLocalPort . '.' . $self->{option_results}->{peer}}; my $bgpRemoteInfos = $result->{$oid_bgpPeerRemoteAddr. '.' . $self->{option_results}->{peer}} . ':' . $result->{$oid_bgpPeerRemotePort . '.' . $self->{option_results}->{peer}}; - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("Peer %s AdminState=%s Connection=%s [Remote Addr:%s AS:%d] [Last Update %d s]", $self->{option_results}->{peer}, $map_admin_state{$bgpPeerAdminStatus}, $map_peer_state{$bgpPeerState} , $bgpRemoteInfos, $bgpPeerRemoteAs, $bgpPeerInUpdateElpasedTime)); - + short_msg => sprintf("Peer %s AdminState=%s Connection=%s [Remote Addr:%s AS:%d] [Last Update %d s]", + $self->{option_results}->{peer}, $map_admin_state{$bgpPeerAdminStatus}, $map_peer_state{$bgpPeerState}, + $bgpRemoteInfos, $bgpPeerRemoteAs, $bgpPeerInUpdateElpasedTime)); if ($bgpPeerAdminStatus < 2) { $self->{output}->output_add(severity => 'CRITICAL', short_msg => sprintf("Peer '%s' AdminState is '%s' Remote AS: %s Remote Addr: %s", $self->{option_results}->{peer}, $map_admin_state{$bgpPeerAdminStatus}, $bgpPeerRemoteAs, $bgpRemoteInfos) ); - } elsif ($bgpPeerState != 6) { + } else { my $exit = $self->get_severity(section => 'peers', value => $map_peer_state{$bgpPeerState}); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Peer %s AdminState=%s Connection=%s [Remote Addr:%s AS:%d] [Last Update %d s]", $self->{option_results}->{peer}, $map_admin_state{$bgpPeerAdminStatus}, $map_peer_state{$bgpPeerState}, $bgpRemoteInfos, $bgpPeerRemoteAs, $bgpPeerInUpdateElpasedTime)); - - } - + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Peer %s AdminState=%s Connection=%s [Remote Addr:%s AS:%d] [Last Update %d s]", + $self->{option_results}->{peer}, $map_admin_state{$bgpPeerAdminStatus}, $map_peer_state{$bgpPeerState}, $bgpRemoteInfos, $bgpPeerRemoteAs, $bgpPeerInUpdateElpasedTime)); + } + } } else { - $self->{output}->output_add(severity => 'OK', short_msg => sprintf("All BGP peers are in an OK state")); foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_bgpPeerState\.(.*)$/); my $instance = $1; next if ($instance eq '0.0.0.0'); @@ -171,28 +146,50 @@ sub run { my $bgpRemoteInfos = $result->{$oid_bgpPeerRemoteAddr. '.' . $instance} . ':' . $result->{$oid_bgpPeerRemotePort . '.' . $instance}; if ($bgpPeerAdminStatus < 2) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Peer '%s' AdminState is '%s' Remote AS: %s Remote Addr: %s \n", + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Peer '%s' AdminState is '%s' Remote AS: %s Remote Addr: %s", $instance, $map_admin_state{$bgpPeerAdminStatus}, $bgpPeerRemoteAs, - $bgpRemoteInfos)); - } elsif ($bgpPeerState != 6) { + $bgpRemoteInfos)); + } else { my $exit = $self->get_severity(section => 'peers', value => $map_peer_state{$bgpPeerState}); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Peer %s AdminState=%s Connection=%s [Remote Addr:%s AS:%d] [Last Update %d s] \n", $instance, $map_admin_state{$bgpPeerAdminStatus}, $map_peer_state{$bgpPeerState}, $bgpRemoteInfos, $bgpPeerRemoteAs, $bgpPeerInUpdateElpasedTime)); - + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Peer %s AdminState=%s Connection=%s [Remote Addr:%s AS:%d] [Last Update %d s]", + $instance, $map_admin_state{$bgpPeerAdminStatus}, $map_peer_state{$bgpPeerState}, $bgpRemoteInfos, $bgpPeerRemoteAs, $bgpPeerInUpdateElpasedTime)); + } } - $self->{output}->output_add(long_msg => sprintf("Peer:%s Local:%s Remote:%s AS:%d AdminState:'%s' Connection:'%s' Last Update:%d sec \n", $instance, $bgpLocalInfos, $bgpRemoteInfos, $bgpPeerRemoteAs, $map_admin_state{$bgpPeerAdminStatus}, $map_peer_state{$bgpPeerState}, $bgpPeerInUpdateElpasedTime)); - - + $self->{output}->output_add(long_msg => sprintf("Peer:%s Local:%s Remote:%s AS:%d AdminState:'%s' Connection:'%s' Last Update:%d sec", + $instance, $bgpLocalInfos, $bgpRemoteInfos, $bgpPeerRemoteAs, $map_admin_state{$bgpPeerAdminStatus}, $map_peer_state{$bgpPeerState}, $bgpPeerInUpdateElpasedTime)); } - } $self->{output}->display(); $self->{output}->exit(); } +sub get_severity { + my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($self->{overload_th}->{$options{section}})) { + foreach (@{$self->{overload_th}->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i) { + $status = $_->{status}; + return $status; + } + } + } + foreach (@{$thresholds->{$options{section}}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + 1; __END__ diff --git a/centreon-plugins/centreon/plugins/output.pm b/centreon-plugins/centreon/plugins/output.pm index 045ad4b6d..d60e116a6 100644 --- a/centreon-plugins/centreon/plugins/output.pm +++ b/centreon-plugins/centreon/plugins/output.pm @@ -55,6 +55,7 @@ sub new { $self->{is_output_xml} = 0; $self->{is_output_json} = 0; $self->{errors} = {OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, PENDING => 4}; + $self->{errors_num} = {0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN', 4 => 'PENDING'}; $self->{myerrors} = {0 => "OK", 1 => "WARNING", 3 => "UNKNOWN", 7 => "CRITICAL"}; $self->{myerrors_mask} = {CRITICAL => 7, WARNING => 1, UNKNOWN => 3, OK => 0}; $self->{global_short_concat_outputs} = {OK => undef, WARNING => undef, CRITICAL => undef, UNKNOWN => undef, UNQUALIFIED_YET => undef}; @@ -533,8 +534,8 @@ sub get_litteral_status { my ($self, %options) = @_; if (defined($options{status})) { - if (defined($self->{myerrors}->{$options{status}})) { - return $self->{myerrors}->{$options{status}}; + if (defined($self->{errors_num}->{$options{status}})) { + return $self->{errors_num}->{$options{status}}; } return $options{status}; } else { diff --git a/centreon-plugins/centreon/plugins/script_custom.pm b/centreon-plugins/centreon/plugins/script_custom.pm index 4ca7765f0..9a6df7c66 100644 --- a/centreon-plugins/centreon/plugins/script_custom.pm +++ b/centreon-plugins/centreon/plugins/script_custom.pm @@ -66,6 +66,15 @@ sub new { return $self; } +sub load_custom_mode { + my ($self, %options) = @_; + + $self->is_custommode(custommode => $self->{custommode_name}); + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{custom_modes}{$self->{custommode_name}}, + error_msg => "Cannot load module --custommode."); + $self->{custommode_current} = $self->{custom_modes}{$self->{custommode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{custommode_name}); +} + sub init { my ($self, %options) = @_; # $options{version} = string version @@ -92,10 +101,10 @@ sub init { $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); if (defined($self->{custommode_name}) && $self->{custommode_name} ne '') { - $self->is_custommode(custommode => $self->{custommode_name}); - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{custom_modes}{$self->{custommode_name}}, - error_msg => "Cannot load module --custommode."); - $self->{custommode_current} = $self->{custom_modes}{$self->{custommode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{custommode_name}); + $self->load_custom_mode(); + } elsif (scalar(keys %{$self->{custom_modes}}) == 1) { + $self->{custommode_name} = (keys(%{$self->{custom_modes}}))[0]; + $self->load_custom_mode(); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--custommode'."); $self->{output}->option_exit(); diff --git a/centreon-plugins/cloud/docker/mode/listcontainers.pm b/centreon-plugins/cloud/docker/mode/listcontainers.pm index 2505a976f..2db673617 100644 --- a/centreon-plugins/cloud/docker/mode/listcontainers.pm +++ b/centreon-plugins/cloud/docker/mode/listcontainers.pm @@ -32,24 +32,26 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; + $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "timeout:s" => { name => 'timeout' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', default => '2376'}, + "proto:s" => { name => 'proto', default => 'https' }, + "urlpath:s" => { name => 'url_path', default => '/' }, + "credentials" => { name => 'credentials' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "ssl:s" => { name => 'ssl', }, + "cert-file:s" => { name => 'cert_file' }, + "key-file:s" => { name => 'key_file' }, + "cacert-file:s" => { name => 'cacert_file' }, + "exclude:s" => { name => 'exclude' }, + "timeout:s" => { name => 'timeout' }, }); $self->{http} = centreon::plugins::http->new(output => $self->{output}); + $self->{container_infos} = (); return $self; } @@ -64,7 +66,17 @@ sub check_options { $self->{http}->set_options(%{$self->{option_results}}) } -sub run { +sub check_exclude { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{status}}(\s|,|$)/) { + $self->{output}->output_add(long_msg => sprintf("Skipping ${options{status}} container.")); + return 1; + } +return 0; +} + +sub api_request { my ($self, %options) = @_; my $jsoncontent = $self->{http}->request(); @@ -83,21 +95,59 @@ sub run { } foreach my $val (@$webcontent) { - my $containername = $val->{Names}->[0]; - $containername =~ s/^\///; - my $containerid = $val->{Id}; - my $containerimage = $val->{Image}; my $containerstate; if (($val->{Status} =~ m/^Up/) && ($val->{Status} =~ m/^(?:(?!Paused).)*$/)) { - $containerstate = 'Running'; - } elsif ($val->{Status} =~ m/^Exited/) { - $containerstate = 'Exited'; - } elsif ($val->{Status} =~ m/\(Paused\)$/) { - $containerstate = 'Paused'; - } - $self->{output}->output_add(long_msg => sprintf("%s [id = %s , image = %s, state = %s]", - $containername, $containerid, $containerimage, $containerstate)); + return if ($self->check_exclude(status => 'Running')); + $containerstate = 'Running'; + } elsif ($val->{Status} =~ m/^Exited/) { + return if ($self->check_exclude(status => 'Exited')); + $containerstate = 'Exited'; + } elsif ($val->{Status} =~ m/\(Paused\)$/) { + return if ($self->check_exclude(status => 'Paused')); + $containerstate = 'Paused'; + } + my $containername = $val->{Names}->[0]; + $containername =~ s/^\///; + $self->{container_infos}->{$containername}->{id} = $val->{Id}; + $self->{container_infos}->{$containername}->{image} = $val->{Image}; + $self->{container_infos}->{$containername}->{state} = $containerstate; } +} + +sub disco_format { + my ($self, %options) = @_; + + my $names = ['name', 'id', 'image', 'state']; + $self->{output}->add_disco_format(elements => $names); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->api_request(); + + foreach my $containername (keys %{$self->{container_infos}}) { + $self->{output}->add_disco_entry(name => $containername, + id => $self->{container_infos}->{$containername}->{id}, + image => $self->{container_infos}->{$containername}->{image}, + state => $self->{container_infos}->{$containername}->{state}, + ); + } +} + +sub run { + my ($self, %options) = @_; + + $self->api_request(); + + foreach my $containername (keys %{$self->{container_infos}}) { + $self->{output}->output_add(long_msg => sprintf("%s [id = %s , image = %s, state = %s]", + $containername, + $self->{container_infos}->{$containername}->{id}, + $self->{container_infos}->{$containername}->{image}, + $self->{container_infos}->{$containername}->{state})); + } + $self->{output}->output_add(severity => 'OK', short_msg => 'List containers:'); @@ -160,6 +210,10 @@ Specify key to send to the webserver Specify root certificate to send to the webserver +=item B<--exlude> + +Exclude specific container's state (comma seperated list) (Example: --exclude=Paused,Running) + =item B<--timeout> Threshold for HTTP timeout (Default: 3) diff --git a/centreon-plugins/network/extreme/snmp/mode/cpu.pm b/centreon-plugins/network/extreme/snmp/mode/cpu.pm index 94311459b..bd8925471 100644 --- a/centreon-plugins/network/extreme/snmp/mode/cpu.pm +++ b/centreon-plugins/network/extreme/snmp/mode/cpu.pm @@ -48,7 +48,7 @@ my $maps_counters = { }, '002_30secs' => { set => { key_values => [ { name => 'extremeCpuMonitorSystemUtilization30secs' }, { name => 'num' }, ], - output_template => '10 seconds : %.2f %%', + output_template => '30 seconds : %.2f %%', perfdatas => [ { label => 'cpu_30secs', value => 'extremeCpuMonitorSystemUtilization30secs_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' }, @@ -57,7 +57,7 @@ my $maps_counters = { }, '003_1min' => { set => { key_values => [ { name => 'extremeCpuMonitorSystemUtilization1min' }, { name => 'num' }, ], - output_template => '10 seconds : %.2f %%', + output_template => '1 minute : %.2f %%', perfdatas => [ { label => 'cpu_1min', value => 'extremeCpuMonitorSystemUtilization1min_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' }, @@ -66,7 +66,7 @@ my $maps_counters = { }, '004_5min' => { set => { key_values => [ { name => 'extremeCpuMonitorSystemUtilization5mins' }, { name => 'num' }, ], - output_template => '10 seconds : %.2f %%', + output_template => '5 minutes : %.2f %%', perfdatas => [ { label => 'cpu_5min', value => 'extremeCpuMonitorSystemUtilization5mins_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' }, diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm index a626c9520..c9bceb96a 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm @@ -108,8 +108,6 @@ sub check_options { $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; } - - } sub run { @@ -149,7 +147,6 @@ sub run { $self->{output}->display(); $self->{output}->exit(); - } sub check_filter { diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdendurance.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdendurance.pm index d1ae7499a..1e1680a28 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdendurance.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdendurance.pm @@ -33,9 +33,9 @@ sub new { $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "filter:s@" => { name => 'filter' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, + "filter:s@" => { name => 'filter' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, }); return $self; @@ -53,14 +53,13 @@ sub check_options { } if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } - } sub run { @@ -85,21 +84,18 @@ sub run { my $exit = $self->{perfdata}->threshold_check(value => $details->{'percent-endurance-remaining'}, - threshold => [ { label => 'warning', 'exit_litteral' => 'warning' }, { label => 'critical', exit_litteral => 'critical' } ]); - - $self->{output}->perfdata_add(label => $item."_endurance", - value => $details->{'percent-endurance-remaining'}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - - if ($exit ne 'ok') { + threshold => [ { label => 'warning', exit_litteral => 'warning' }, { label => 'critical', exit_litteral => 'critical' } ]); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("SSD '%s' endurance is %i%%", $item, $details->{'percent-endurance-remaining'})); } - - } + $self->{output}->perfdata_add(label => $item . "_endurance", unit => '%', + value => $details->{'percent-endurance-remaining'}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, max => 100); + } $self->{output}->display(); $self->{output}->exit(); diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm index 5faaf70b8..2096ffd0c 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm @@ -24,144 +24,168 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::values; + +my $maps_counters = { + ssd => { + '000_global' => { set => { + key_values => [ { name => 'global_iops' }, { name => 'display' }, ], + output_template => 'Global IOPs : %s', + perfdatas => [ + { label => 'global_iops', value => 'global_iops_absolute', template => '%s', + min => 0, unit => 'iops', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + '001_read' => { set => { + key_values => [ { name => 'read_iops' }, { name => 'display' }, ], + output_template => 'Read IOPs : %s', + perfdatas => [ + { label => 'read_iops', value => 'read_iops_absolute', template => '%s', + min => 0, unit => 'iops', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + '002_write' => { set => { + key_values => [ { name => 'write_iops' }, { name => 'display' }, ], + output_template => 'Write IOPs : %s', + perfdatas => [ + { label => 'write_iops', value => 'write_iops_absolute', template => '%s', + min => 0, unit => 'iops', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + }, +}; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $self->{version} = '1.1'; + + $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter:s@" => { name => 'filter' }, - "warning-read:s" => { name => 'warning_read' }, - "critical-read:s" => { name => 'critical_read' }, - "warning-write:s" => { name => 'warning_write' }, - "critical-write:s" => { name => 'critical_write' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, + "filter-name:s" => { name => 'filter_name' }, }); + foreach my $key (('ssd')) { + foreach (keys %{$maps_counters->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); + } + } + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - - $self->{filter} = []; - foreach my $val (@{$self->{option_results}->{filter}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; - } - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - - if (($self->{perfdata}->threshold_validate(label => 'warning-read', value => $self->{option_results}->{warning_read})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-read threshold '" . $self->{option_results}->{warning_read} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-read', value => $self->{option_results}->{critical_read})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-read threshold '" . $self->{option_results}->{critical_read} . "'."); - $self->{output}->option_exit(); - } - - if (($self->{perfdata}->threshold_validate(label => 'warning-write', value => $self->{option_results}->{warning_write})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-write threshold '" . $self->{option_results}->{warning_write} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-write', value => $self->{option_results}->{critical_write})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-write threshold '" . $self->{option_results}->{critical_write} . "'."); - $self->{output}->option_exit(); - } - - + + foreach my $key (('ssd')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } + } } sub run { my ($self, %options) = @_; - my $xtremio = $options{custom}; - - my $urlbase = '/api/json/types/'; - my @items = $xtremio->get_items(url => $urlbase, - obj => 'ssds'); - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All SSDs Iops are OK'); - - foreach my $item (@items) { - next if ($self->check_filter(section => 'ssds', instance => $item)); - my $details = $xtremio->get_details(url => $urlbase, - obj => 'ssds', - name => $item); - - $self->{output}->output_add(long_msg => sprintf("SSD '%s' IOPS : Global=%i Read=%i Write=%i", - $item, $details->{'iops'}, $details->{'rd-iops'}, $details->{'wr-iops'})); - - my $exit1 = $self->{perfdata}->threshold_check(value => $details->{'iops'}, - threshold => [ { label => 'warning', 'exit_litteral' => 'warning' }, { label => 'critical', exit_litteral => 'critical' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $details->{'rd-iops'}, - threshold => [ { label => 'warning-read', 'exit_litteral' => 'warning' }, { label => 'critical-read', exit_litteral => 'critical' } ]); - my $exit3 = $self->{perfdata}->threshold_check(value => $details->{'wr-iops'}, - threshold => [ { label => 'warning-write', 'exit_litteral' => 'warning' }, { label => 'critical-write', exit_litteral => 'critical' } ]); - - my $exit = $self->{output}->get_most_critical(status => [$exit1, $exit2, $exit3]); - - $self->{output}->perfdata_add(label => $item."_iops", - value => $details->{'iops'}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - - $self->{output}->perfdata_add(label => $item."_rd-iops", - value => $details->{'rd-iops'}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_read'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_read'), - min => 0, max => 100); - - $self->{output}->perfdata_add(label => $item."_wr-iops", - value => $details->{'wr-iops'}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_write'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_write'), - min => 0, max => 100); - - if ($exit ne 'ok') { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("SSD '%s' IOPS : Global=%i Read=%i Write=%i", - $item, $details->{'iops'}, $details->{'rd-iops'}, $details->{'wr-iops'})); - } - - } - - $self->{output}->display(); - $self->{output}->exit(); - -} - -sub check_filter { - my ($self, %options) = @_; - - foreach (@{$self->{filter}}) { - if ($options{section} =~ /$_->{filter}/) { - if (!defined($options{instance}) && !defined($_->{instance})) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } + $self->{xtremio} = $options{custom}; + + $self->manage_selection(); + + my $multiple = 1; + if (scalar(keys %{$self->{ssd}}) == 1) { + $multiple = 0; } - return 0; + if ($multiple == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All SSDs usages are ok'); + } + + foreach my $id (sort keys %{$self->{ssd}}) { + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits = (); + foreach (sort keys %{$maps_counters->{ssd}}) { + my $obj = $maps_counters->{ssd}->{$_}->{obj}; + $obj->set(instance => $id); + + my ($value_check) = $obj->execute(values => $self->{ssd}->{$id}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; + + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(extra_instance => $multiple); + } + + $self->{output}->output_add(long_msg => "SSD '" . $self->{ssd}->{$id}->{display} . "' Usage $long_msg"); + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "SSD '" . $self->{ssd}->{$id}->{display} . "' Usage $short_msg" + ); + } + + if ($multiple == 0) { + $self->{output}->output_add(short_msg => "SSD '" . $self->{ssd}->{$id}->{display} . "' Usage $long_msg"); + } + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{ssd} = {}; + my $urlbase = '/api/json/types/'; + my @items = $self->{xtremio}->get_items(url => $urlbase, + obj => 'ssds'); + foreach my $item (@items) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $item !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "Skipping '" . $item . "': no matching name.", debug => 1); + next; + } + + my $details = $self->{xtremio}->get_details(url => $urlbase, + obj => 'ssds', + name => $item); + + $self->{ssd}->{$item} = { display => $item, global_iops => $details->{iops}, + read_iops => $details->{'rd-iops'}, write_iops => $details->{'wr-iops'} }; + } + + if (scalar(keys %{$self->{ssd}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No entry found."); + $self->{output}->option_exit(); + } } 1; @@ -170,38 +194,23 @@ __END__ =head1 MODE -Check IOPS (Global, Read, Write) on each SSDs +Check IOPS (Global, Read, Write) on each SSDs. =over 8 -=item B<--filter> +=item B<--warning-*> -Filter some parts (comma seperated list) -Can also exclude specific instance: --filter=ssds,SSDS-Number +Threshold warning. +Can be: 'global' (%), 'read' (%), 'write' (%). -=item B<--warning> +=item B<--critical-*> -Warning value on global IOPS +Threshold critical. +Can be: 'global' (%), 'read' (%), 'write' (%). -=item B<--critical> +=item B<--filter-name> -Critical value on global IOPS - -=item B<--warning-read> - -Warning value on read IOPS - -=item B<--critical-read> - -Critical value on read IOPS - -=item B<--warning-write> - -Warning value on write IOPS - -=item B<--critical-write> - -Critical value on write IOPS +Filter SSD name (can be a regexp). =back diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvscpu.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvscpu.pm index 3c8454ad4..2ead76f0d 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvscpu.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvscpu.pm @@ -60,7 +60,6 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - } sub run { @@ -86,20 +85,17 @@ sub run { my $exit = $self->{perfdata}->threshold_check(value => $details->{'cpu-usage'}, threshold => [ { label => 'warning', 'exit_litteral' => 'warning' }, { label => 'critical', exit_litteral => 'critical' } ]); - - $self->{output}->perfdata_add(label => 'cpu_'.$item, - value => $details->{'cpu-usage'}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - - if ($exit ne 'ok') { + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Xenvs '%s' cpu-Usage is %i%%", $item, $details->{'cpu-usage'})); } - + $self->{output}->perfdata_add(label => 'cpu_' . $item, unit => '%', + value => $details->{'cpu-usage'}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, max => 100); } $self->{output}->display(); diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvsstate.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvsstate.pm index 9942f4650..2e9a959d4 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvsstate.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/xenvsstate.pm @@ -84,7 +84,6 @@ sub check_options { $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; } - } sub run { @@ -119,7 +118,6 @@ sub run { $self->{output}->display(); $self->{output}->exit(); - } sub check_filter {