diff --git a/apps/backup/quadstor/local/mode/listvtl.pm b/apps/backup/quadstor/local/mode/listvtl.pm new file mode 100644 index 000000000..48b95cc23 --- /dev/null +++ b/apps/backup/quadstor/local/mode/listvtl.pm @@ -0,0 +1,176 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package apps::backup::quadstor::local::mode::listvtl; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "remote" => { name => 'remote' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'vtconfig' }, + "command-path:s" => { name => 'command_path', default => '/quadstorvtl/bin' }, + "command-options:s" => { name => 'command_options', default => '-l' }, + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + + foreach (sort keys %{$self->{vtl}}) { + $self->{output}->output_add(long_msg => "'" . $_ . "' [type = " . $self->{vtl}->{$_}->{type} . "]"); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List VTL:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'type']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (sort keys %{$self->{vtl}}) { + $self->{output}->add_disco_entry(name => $_, + active => $self->{vtl}->{$_}->{type} + ); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + + #Name DevType Type + #BV00002 VTL IBM IBM System Storage TS3100 + $self->{vtl} = {}; + my @lines = split /\n/, $stdout; + shift @lines; + foreach (@lines) { + next if (! /^(\S+)\s+(\S+)/); + + my ($name, $type) = ($1, $2); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/i) { + $self->{output}->output_add(long_msg => "skipping vtl '" . $name . "': no matching filter"); + next; + } + + $self->{vtl}->{$name} = { type => $type }; + } +} + +1; + +__END__ + +=head1 MODE + +List VTL. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'vtconfig'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: '/quadstorvtl/bin'). + +=item B<--command-options> + +Command options (Default: '-l'). + +=item B<--filter-name> + +Filter vtl name (can be a regexp). + +=back + +=cut diff --git a/apps/backup/quadstor/local/mode/vtldiskusage.pm b/apps/backup/quadstor/local/mode/vtldiskusage.pm new file mode 100644 index 000000000..752d44dcd --- /dev/null +++ b/apps/backup/quadstor/local/mode/vtldiskusage.pm @@ -0,0 +1,340 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package apps::backup::quadstor::local::mode::vtldiskusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disks are ok' } + ]; + + $self->{maps_counters}->{disk} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'usage', set => { + key_values => [ { name => 'total' }, { name => 'used' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "remote" => { name => 'remote' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'bdconfig' }, + "command-path:s" => { name => 'command_path', default => '/quadstorvtl/bin' }, + "command-options:s" => { name => 'command_options', default => '-l -c' }, + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_disk_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + $self->{disk} = {}; + #ID Vendor Model SerialNumber Name Pool Size Used Status + #1 Msft Virtual /dev/sdb Default 1024.00 21.28 Active + #3 Msft Virtual /dev/sdc Default 1024.00 21.03 Active + #2 Msft Virtual /dev/sdd Default 1024.00 44.53 Active + #4 Msft Virtual /dev/sde Default 1024.00 165.06 Active + + my @lines = split /\n/, $stdout; + shift @lines; + foreach (@lines) { + next if (! /(\S+)\s+\S+\s+([0-9\.]+)\s+([0-9\.]+)\s+(\S+)\s*$/); + my ($name, $size, $used, $status) = ($1, $2, $3, $4); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/i) { + $self->{output}->output_add(long_msg => "skipping disk '" . $name . "': no matching filter"); + next; + } + + $self->{disk}->{$name} = { + display => $name, + total => $size * 1024 * 1024 * 1024, + used => $used * 1024 * 1024 * 1024, + status => $status, + }; + } + + if (scalar(keys %{$self->{disk}}) == 0) { + $self->{output}->add_option_msg(short_msg => "No disk found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check vtl disk usage. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'bdconfig'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: '/quadstorvtl/bin'). + +=item B<--command-options> + +Command options (Default: '-l -c'). + +=item B<--filter-name> + +Filter tape name. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'absolute'). + +=item B<--free> + +Thresholds are on free tape left. + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /active/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage'. + +=back + +=cut diff --git a/apps/backup/quadstor/local/mode/vtljobstatus.pm b/apps/backup/quadstor/local/mode/vtljobstatus.pm new file mode 100644 index 000000000..abfbead27 --- /dev/null +++ b/apps/backup/quadstor/local/mode/vtljobstatus.pm @@ -0,0 +1,375 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package apps::backup::quadstor::local::mode::vtljobstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use Digest::MD5 qw(md5_hex); + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = 'status : ' . $self->{result_values}->{status}; + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_long_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_long}) && $instance_mode->{option_results}->{critical_long} ne '' && + eval "$instance_mode->{option_results}->{critical_long}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_long}) && $instance_mode->{option_results}->{warning_long} ne '' && + eval "$instance_mode->{option_results}->{warning_long}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_long_output { + my ($self, %options) = @_; + my $msg = 'elapsed time : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{elapsed}); + + return $msg; +} + +sub custom_long_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{elapsed} = $options{new_datas}->{$self->{instance} . '_elapsed'}; + + return 0; +} + +my $last_status_frozen; + +sub custom_frozen_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_frozen}) && $instance_mode->{option_results}->{critical_frozen} ne '' && + eval "$instance_mode->{option_results}->{critical_frozen}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_frozen}) && $instance_mode->{option_results}->{warning_frozen} ne '' && + eval "$instance_mode->{option_results}->{warning_frozen}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + $last_status_frozen = $status; + return $status; +} + +sub custom_frozen_output { + my ($self, %options) = @_; + my $msg = 'frozen : no'; + + if (!$self->{output}->is_status(value => $last_status_frozen, compare => 'ok', litteral => 1)) { + $msg = 'frozen: yes'; + } + return $msg; +} + +sub custom_frozen_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{elapsed} = $options{new_datas}->{$self->{instance} . '_elapsed'}; + $self->{result_values}->{kb} = $options{new_datas}->{$self->{instance} . '_kb'} - $options{old_datas}->{$self->{instance} . '_kb'}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'jobs', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, + group => [ { name => 'job', cb_prefix_output => 'prefix_job_output', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{job} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'long', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' }, { name => 'elapsed' } ], + closure_custom_calc => $self->can('custom_long_calc'), + closure_custom_output => $self->can('custom_long_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_long_threshold'), + } + }, + { label => 'frozen', threshold => 0, set => { + key_values => [ { name => 'kb', diff => 1 }, { name => 'status' }, { name => 'display' }, { name => 'elapsed' } ], + closure_custom_calc => $self->can('custom_frozen_calc'), + closure_custom_output => $self->can('custom_frozen_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_frozen_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "remote" => { name => 'remote' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'impexp' }, + "command-path:s" => { name => 'command_path', default => '/quadstorvtl/bin' }, + "command-options:s" => { name => 'command_options', default => '-l' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /error/i' }, + "warning-long:s" => { name => 'warning_long' }, + "critical-long:s" => { name => 'critical_long' }, + "warning-frozen:s" => { name => 'warning_frozen' }, + "critical-frozen:s" => { name => 'critical_frozen' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_job_output { + my ($self, %options) = @_; + + return "job '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status', 'warning_long', 'critical_long', 'warning_frozen', 'critical_frozen')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "quadstor_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + $self->{jobs}->{global} = { job => {} }; + #JobID Type Source State Transfer Elapsed + #252 Import 701831L2 Error 36.00 GB 572 + #253 Export 701849L2 Completed 19.43 GB 262 + #254 Export 701850L2 Completed 16.05 GB 1072 + #255 Export 701854L2 Completed 6.31 GB 142 + my $current_time = time(); + my @lines = split /\n/, $stdout; + shift @lines; + foreach (@lines) { + next if (! /^(\d+)\s+\S+\s+(\S+)\s+(\S+)\s+([0-9\.]+)\s+\S+\s+(\d+)/); + + my ($job_id, $job_source, $job_state, $job_kb, $job_elapsed) = + ($1, $2, $3, $4, $5); + + my $name = $job_source . '.' . $job_id; + $self->{jobs}->{global}->{job}->{$name} = { + display => $name, + status => $job_state, + kb => $job_kb * 1024, + elapsed => $job_elapsed + }; + } + + if (scalar(keys %{$self->{jobs}->{global}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No job found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check job status. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'impexp'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: '/quadstorvtl/bin'). + +=item B<--command-options> + +Command options (Default: '-l'). + +=item B<--warning-status> + +Set warning threshold for status (Default: none) +Can used special variables like: %{display}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /error/i'). +Can used special variables like: %{display}, %{status} + +=item B<--warning-long> + +Set warning threshold for long jobs (Default: none) +Can used special variables like: %{display}, %{status}, %{elapsed} + +=item B<--critical-long> + +Set critical threshold for long jobs (Default: none). +Can used special variables like: %{display}, %{status}, %{elapsed} + +=item B<--warning-frozen> + +Set warning threshold for frozen jobs (Default: none) +Can used special variables like: %{display}, %{status}, %{elapsed}, %{kb} + +=item B<--critical-frozen> + +Set critical threshold for frozen jobs (Default: none). +Can used special variables like: %{display}, %{status}, %{elapsed}, %{kb} + +=back + +=cut diff --git a/apps/backup/quadstor/local/mode/vtltapeusage.pm b/apps/backup/quadstor/local/mode/vtltapeusage.pm new file mode 100644 index 000000000..51792aaa6 --- /dev/null +++ b/apps/backup/quadstor/local/mode/vtltapeusage.pm @@ -0,0 +1,357 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package apps::backup::quadstor::local::mode::vtltapeusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_used_prct'}; + + $self->{result_values}->{used} = $self->{result_values}->{total} * $self->{result_values}->{prct_used} / 100; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'tape', type => 1, cb_prefix_output => 'prefix_tape_output', message_multiple => 'All tapes are ok' } + ]; + + $self->{maps_counters}->{tape} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'usage', set => { + key_values => [ { name => 'total' }, { name => 'used_prct' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "remote" => { name => 'remote' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'vcconfig' }, + "command-path:s" => { name => 'command_path', default => '/quadstorvtl/bin' }, + "command-options:s" => { name => 'command_options', default => '-l -v %{vtl_name}' }, + "vtl-name:s" => { name => 'vtl_name' }, + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{vtl_name}) || $self->{option_results}->{vtl_name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to set vtl-name option."); + $self->{output}->option_exit(); + } + + $self->{option_results}->{command_options} =~ s/%\{vtl_name\}/$self->{option_results}->{vtl_name}/; + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_tape_output { + my ($self, %options) = @_; + + return "Tape '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + $self->{tape} = {}; + #Pool Label Element Address Vtype WORM Size Used% Status + #Default 701862L2 Unknown 0 LTO 2 200GB No 200 99 Vaulted + #Default 701899L2 Slot 1180 LTO 2 200GB No 200 0 Active + #Default 701900L2 Slot 1181 LTO 2 200GB No 200 0 Active + #Default 701901L2 Slot 1182 LTO 2 200GB No 200 0 Active + #Default 701902L2 Slot 1183 LTO 2 200GB No 200 0 Active + #Default 701903L2 Slot 1184 LTO 2 200GB No 200 0 Active + #Default 701904L2 Slot 1185 LTO 2 200GB No 200 0 Active + + my @lines = split /\n/, $stdout; + shift @lines; + foreach (@lines) { + next if (! /([0-9\.]+)\s+([0-9\.]+)\s+(\S+)\s*$/); + my ($size, $used_prct, $status) = ($1, $2, $3); + next if (! /^\S+\s+(\S+)\s+\S+\s+(\S+)/); + my $name = $1 . '.' . $2; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/i) { + $self->{output}->output_add(long_msg => "skipping vtl '" . $name . "': no matching filter"); + next; + } + + $self->{tape}->{$name} = { + display => $name, + total => $size * 1024 * 1024 * 1024, + used_prct => $used_prct, + status => $status, + }; + } + + if (scalar(keys %{$self->{tape}}) == 0) { + $self->{output}->add_option_msg(short_msg => "No tape found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check vtl tape usage. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'vcconfig'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: '/quadstorvtl/bin'). + +=item B<--command-options> + +Command options (Default: '-l -v %{vtl_name}'). + +=item B<--vtl-name> + +Set VTL name (Required). + +=item B<--filter-name> + +Filter tape name. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'absolute'). + +=item B<--free> + +Thresholds are on free tape left. + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /active/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage'. + +=back + +=cut diff --git a/apps/backup/quadstor/local/plugin.pm b/apps/backup/quadstor/local/plugin.pm new file mode 100644 index 000000000..b505c206a --- /dev/null +++ b/apps/backup/quadstor/local/plugin.pm @@ -0,0 +1,51 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package apps::backup::quadstor::local::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'list-vtl' => 'apps::backup::quadstor::local::mode::listvtl', + 'vtl-disk-usage' => 'apps::backup::quadstor::local::mode::vtldiskusage', + 'vtl-job-status' => 'apps::backup::quadstor::local::mode::vtljobstatus', + 'vtl-tape-usage' => 'apps::backup::quadstor::local::mode::vtltapeusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Quadstor through local commands (the plugin can use SSH). + +=cut diff --git a/apps/lync/2013/mssql/mode/poorcalls.pm b/apps/lync/2013/mssql/mode/poorcalls.pm index 6804f5122..aca8a260d 100644 --- a/apps/lync/2013/mssql/mode/poorcalls.pm +++ b/apps/lync/2013/mssql/mode/poorcalls.pm @@ -125,11 +125,11 @@ Minutes to lookback (From you to UTC) default: 65 =item B<--warning-*> -Set warning threshold for number of poor calls. Can be : 'total', 'user' +Set warning threshold for number of poor calls. Can be : 'global', 'user' =item B<--critical-*> -Set critical threshold for number of poor calls. Can be : 'total', 'user' +Set critical threshold for number of poor calls. Can be : 'global', 'user' =back diff --git a/apps/lync/2013/mssql/mode/sessionstypes.pm b/apps/lync/2013/mssql/mode/sessionstypes.pm index ea69d4c54..2544f9302 100644 --- a/apps/lync/2013/mssql/mode/sessionstypes.pm +++ b/apps/lync/2013/mssql/mode/sessionstypes.pm @@ -104,6 +104,17 @@ sub set_counters { } }, ]; + $self->{maps_counters}->{app_invite} = [ + { label => 'app-invite', set => { + key_values => [ { name => 'value' } ], + output_template => 'App Invite : %d', + perfdatas => [ + { label => 'app_invite', value => 'value_absolute', template => '%d', + unit => 'sessions', min => 0, label_extra_instance => 0 }, + ], + } + }, + ]; } diff --git a/apps/protocols/x509/mode/validity.pm b/apps/protocols/x509/mode/validity.pm index 352320bc3..d77dbb1b8 100644 --- a/apps/protocols/x509/mode/validity.pm +++ b/apps/protocols/x509/mode/validity.pm @@ -46,6 +46,7 @@ sub new { "subjectname:s" => { name => 'subjectname', default => '' }, "issuername:s" => { name => 'issuername', default => '' }, "timeout:s" => { name => 'timeout', default => 5 }, + 'ssl-opt:s%' => { name => 'ssl_opt' }, }); return $self; } @@ -74,6 +75,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Please set the validity-mode option (issuer, subject or expiration)"); $self->{output}->option_exit(); } + + $self->{ssl_opts} = ''; + if (defined($self->{option_results}->{ssl_opt})) { + foreach (keys %{$self->{option_results}->{ssl_opt}}) { + $self->{ssl_opts} .= "$_ => " . $self->{option_results}->{ssl_opt}->{$_} . ", "; + } + } } sub run { @@ -83,6 +91,7 @@ sub run { my $client = IO::Socket::SSL->new( PeerHost => $self->{option_results}->{hostname}, PeerPort => $self->{option_results}->{port}, + eval $self->{ssl_opts}, $self->{option_results}->{servername} ? ( SSL_hostname => $self->{option_results}->{servername} ):(), ); if (!defined($client)) { @@ -206,6 +215,10 @@ Subject Name pattern (support alternative subject name) Issuer Name pattern +=item B<--ssl-opt> + +Set SSL Options (--ssl-opt="SSL_verify_mode=SSL_VERIFY_NONE"). + =back =cut diff --git a/centreon/common/airespace/snmp/mode/apstatus.pm b/centreon/common/airespace/snmp/mode/apstatus.pm index 09b697323..4b5debcaf 100644 --- a/centreon/common/airespace/snmp/mode/apstatus.pm +++ b/centreon/common/airespace/snmp/mode/apstatus.pm @@ -108,6 +108,24 @@ sub set_counters { ], } }, + { label => 'total-enabled', set => { + key_values => [ { name => 'enable' } ], + output_template => 'Total ap enabled : %s', + perfdatas => [ + { label => 'total_enabled', value => 'enable_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-disabled', set => { + key_values => [ { name => 'disable' } ], + output_template => 'Total ap disabled : %s', + perfdatas => [ + { label => 'total_disabled', value => 'disable_absolute', template => '%s', + min => 0 }, + ], + } + }, ]; $self->{maps_counters}->{ap} = [ @@ -192,7 +210,7 @@ sub manage_selection { my ($self, %options) = @_; $self->{ap} = {}; - $self->{global} = { total => 0, associated => 0, disassociating => 0, downloading => 0 }; + $self->{global} = { total => 0, associated => 0, disassociating => 0, downloading => 0, enable => 0, disable => 0 }; $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_agentInventoryMachineModel }, { oid => $mapping->{bsnAPName}->{oid} }, { oid => $mapping2->{bsnAPOperationStatus}->{oid} }, @@ -215,6 +233,7 @@ sub manage_selection { $self->{global}->{total}++; $self->{global}->{$result2->{bsnAPOperationStatus}}++; + $self->{global}->{$result3->{bsnAPAdminStatus}}++; $self->{ap}->{$instance} = { display => $result->{bsnAPName}, opstatus => $result2->{bsnAPOperationStatus}, admstatus => $result3->{bsnAPAdminStatus}}; @@ -257,12 +276,12 @@ Can used special variables like: %{admstatus}, %{opstatus}, %{display} =item B<--warning-*> Threshold warning. -Can be: 'total', 'total-associated', 'total-disassociating'. +Can be: 'total', 'total-associated', 'total-disassociating', 'total-enabled', 'total-disabled'. =item B<--critical-*> Threshold critical. -Can be: 'total', 'total-associated', 'total-disassociating'. +Can be: 'total', 'total-associated', 'total-disassociating', 'total-enabled', 'total-disabled'. =back diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm index e9f7a1eda..6c1fb6525 100644 --- a/centreon/plugins/misc.pm +++ b/centreon/plugins/misc.pm @@ -320,14 +320,14 @@ sub trim { } sub powershell_encoded { - my ($value) = $_[0]; + my ($value) = $_[0]; - require Encode; - require MIME::Base64; - my $bytes = Encode::encode("utf16LE", $value); - my $script = MIME::Base64::encode_base64($bytes, "\n"); - $script =~ s/\n//g; - return $script; + require Encode; + require MIME::Base64; + my $bytes = Encode::encode("utf16LE", $value); + my $script = MIME::Base64::encode_base64($bytes, "\n"); + $script =~ s/\n//g; + return $script; } sub powershell_escape { @@ -389,6 +389,19 @@ sub change_seconds { return $str; } +sub convert_bytes { + my (%options) = @_; + my %expo = (k => 1, m => 2, g => 3, t => 4); + my $value = $options{value}; + my $base = defined($options{network}) ? 1000 : 1020; + + if ($options{unit} =~ /([kmgt])b/i) { + $value = $value * ($base ** $expo{lc($1)}); + } + + return $value; +} + 1; __END__ diff --git a/changelog b/changelog index 933270b82..9e934ce42 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +2017-07-XX Quentin Garnier + * Plugin added: Supermicro SNMP + * Plugin added: QuadStor VTL Local + 2017-06-13 Quentin Garnier * Plugin added: HP Eva CLI * Plugin added: Acme Packet SNMP diff --git a/cloud/docker/custom/dockerapi.pm b/cloud/docker/custom/dockerapi.pm deleted file mode 100644 index c7a15182c..000000000 --- a/cloud/docker/custom/dockerapi.pm +++ /dev/null @@ -1,218 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::custom::dockerapi; - -use strict; -use warnings; -use centreon::plugins::misc; -use centreon::plugins::http; -use JSON; - -sub new { - my ($class, %options) = @_; - my $self = {}; - bless $self, $class; - - if (!defined($options{output})) { - print "Class Custom: Need to specify 'output' argument.\n"; - exit 3; - } - if (!defined($options{options})) { - $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); - $options{output}->option_exit(); - } - - if (!defined($options{noptions})) { - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "proto:s" => { name => 'proto' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "proxyurl:s" => { name => 'proxyurl' }, - "proxypac:s" => { name => 'proxypac' }, - "timeout:s" => { name => 'timeout' }, - "ssl:s" => { name => 'ssl' }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "cert-pwd:s" => { name => 'cert_pwd' }, - "cert-pkcs12" => { name => 'cert_pkcs12' }, - }); - } - $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); - - $self->{output} = $options{output}; - $self->{mode} = $options{mode}; - $self->{http} = centreon::plugins::http->new(output => $self->{output}); - - return $self; - -} - -# Method to manage multiples -sub set_options { - my ($self, %options) = @_; - # options{options_result} - - $self->{option_results} = $options{option_results}; -} - -# Method to manage multiples -sub set_defaults { - my ($self, %options) = @_; - - # Manage default value - foreach (keys %{$options{default}}) { - if ($_ eq $self->{mode}) { - for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { - foreach my $opt (keys %{$options{default}->{$_}[$i]}) { - if (!defined($self->{option_results}->{$opt}[$i])) { - $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; - } - } - } - } - } -} - -sub check_options { - my ($self, %options) = @_; - - if (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { - $self->{output}->add_option_msg(short_msg => "You need to specify --hostname option."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{proto}) || $self->{option_results}->{proto} eq '') { - $self->{output}->add_option_msg(short_msg => "You need to specify --proto option."); - $self->{output}->option_exit(); - } - -} - -sub api_request { - my ($self, %options) = @_; - - $self->{option_results}->{url_path} = $options{urlpath}; - $self->{option_results}->{port} = $options{port}; - $self->{method} = 'GET'; - $self->{option_results}->{get_param} = []; - push @{$self->{option_results}->{get_param}}, "all=true", "stream=false"; - - $self->{http}->set_options(%{$self->{option_results}}); - - my $webcontent; - my $jsoncontent = $self->{http}->request(method => $self->{method}); - - my $json = JSON->new; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot retrieve any information"); - $self->{output}->option_exit(); - } - - return $webcontent; -} - -1; - -__END__ - -=head1 NAME - -Docker REST API - -=head1 SYNOPSIS - -Docker Rest API custom mode - -=head1 REST API OPTIONS - -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of the webserver host - -=item B<--proto> - -Specify https if needed (Default: 'http') - -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username for basic authentification (Mandatory if --credentials is specidied) - -=item B<--password> - -Specify password for basic authentification (Mandatory if --credentials is specidied) - -=item B<--proxyurl> - -Proxy URL - -=item B<--proxypac> - -Proxy pac file (can be an url or local file) - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 5) - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver - -=item B<--cert-pwd> - -Specify certificate's password - -=item B<--cert-pkcs12> - -Specify type of certificate (PKCS12) - -=back - -=head1 DESCRIPTION - -B. - -=cut diff --git a/cloud/docker/mode/blockio.pm b/cloud/docker/mode/blockio.pm deleted file mode 100644 index 267c20c71..000000000 --- a/cloud/docker/mode/blockio.pm +++ /dev/null @@ -1,219 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::blockio; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::statefile; -use centreon::plugins::http; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.1'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "warning-read:s" => { name => 'warning-read' }, - "critical-read:s" => { name => 'critical-read' }, - "warning-write:s" => { name => 'warning-write' }, - "critical-write:s" => { name => 'critical-write' }, - }); - - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - $self->{http} = centreon::plugins::http->new(output => $self->{output}); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - if ((!defined($self->{option_results}->{name})) && (!defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $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(); - } - - $self->{http}->set_options(%{$self->{option_results}}); - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - - my $new_datas = {}; - - if (defined($self->{option_results}->{id})) { - $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); - } elsif (defined($self->{option_results}->{name})) { - $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); - } - - my $urlpath; - if (defined($self->{option_results}->{id})) { - $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; - } - my $port = $self->{option_results}->{port}; - my $containerapi = $options{custom}; - - my $webcontent = $containerapi->api_request(urlpath => $urlpath, - port => $port); - - my $read_bytes = $webcontent->{blkio_stats}->{io_service_bytes_recursive}->[0]->{value}; - my $write_bytes = $webcontent->{blkio_stats}->{io_service_bytes_recursive}->[1]->{value}; - $new_datas->{read_bytes} = $read_bytes; - $new_datas->{write_bytes} = $write_bytes; - $new_datas->{last_timestamp} = time(); - my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); - - # First execution - if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - $self->{statefile_value}->write(data => $new_datas); - $self->{output}->display(); - $self->{output}->exit(); - } - - my $time_delta = $new_datas->{last_timestamp} - $old_timestamp; - if ($time_delta <= 0) { - # At least one second. two fast calls ;) - $time_delta = 1; - } - - my $old_read_bytes = $self->{statefile_value}->get(name => 'read_bytes'); - my $old_write_bytes = $self->{statefile_value}->get(name => 'write_bytes'); - - if ($new_datas->{read_bytes} < $old_read_bytes) { - # We set 0. Has reboot. - $old_read_bytes = 0; - } - if ($new_datas->{write_bytes} < $old_write_bytes) { - # We set 0. Has reboot. - $old_write_bytes = 0; - } - - my $delta_read_bytes = $read_bytes - $old_read_bytes; - my $delta_write_bytes = $write_bytes - $old_write_bytes; - my $read_absolute_per_sec = $delta_read_bytes / $time_delta; - my $write_absolute_per_sec = $delta_write_bytes / $time_delta; - - my $exit1 = $self->{perfdata}->threshold_check(value => $read_absolute_per_sec, threshold => [ { label => 'critical-read', 'exit_litteral' => 'critical' }, { label => 'warning-read', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $write_absolute_per_sec, threshold => [ { label => 'critical-write', 'exit_litteral' => 'critical' }, { label => 'warning-write', exit_litteral => 'warning' } ]); - - my ($read_value, $read_unit) = $self->{perfdata}->change_bytes(value => $read_absolute_per_sec, network => 1); - my ($write_value, $write_unit) = $self->{perfdata}->change_bytes(value => $write_absolute_per_sec, network => 1); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Read I/O : %s/s, Write I/O : %s/s", - $read_value . $read_unit, - $write_value . $write_unit)); - - $self->{output}->perfdata_add(label => 'read_io', unit => 'B/s', - value => sprintf("%.2f", $read_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-read'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-read'), - min => 0); - $self->{output}->perfdata_add(label => 'write_io', unit => 'B/s', - value => sprintf("%.2f", $write_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-write'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-write'), - min => 0); - - $self->{statefile_value}->write(data => $new_datas); - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Container's Block I/O usage - -=head2 DOCKER OPTIONS - -=item B<--port> - -Port used by Docker - -=item B<--id> - -Specify one container's id - -=item B<--name> - -Specify one container's name - -=head2 MODE OPTIONS - -=item B<--warning-read> - -Threshold warning in B/s for Read I/O. - -=item B<--critical-read> - -Threshold critical in B/s for Read I/O. - -=item B<--warning-write> - -Threshold warning in B/s for Write I/O. - -=item B<--critical-write> - -Threshold critical in B/s for Write I/O. - -=back - -=cut diff --git a/cloud/docker/mode/containerstate.pm b/cloud/docker/mode/containerstate.pm deleted file mode 100644 index 9d5850fcb..000000000 --- a/cloud/docker/mode/containerstate.pm +++ /dev/null @@ -1,226 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::containerstate; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my $thresholds = { - state => [ - ['Running', 'OK'], - ['Paused', 'WARNING'], - ['Restarting', 'WARNING'], - ['OOMKilled', 'CRITICAL'], - ['Dead', 'CRITICAL'], - ['Exited', 'CRITICAL'], - ], -}; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.1'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if ((defined($self->{option_results}->{name})) && ($self->{option_results}->{name} eq '')) { - $self->{output}->add_option_msg(short_msg => "You need to specify the name option"); - $self->{output}->option_exit(); - } - - if ((defined($self->{option_results}->{id})) && ($self->{option_results}->{id} eq '')) { - $self->{output}->add_option_msg(short_msg => "You need to specify the id option"); - $self->{output}->option_exit(); - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } -} - -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 run { - my ($self, %options) = @_; - - my $urlpath; - if (defined($self->{option_results}->{id})) { - $urlpath = "/containers/".$self->{option_results}->{id}."/json"; - } elsif (defined($self->{option_results}->{name})) { - $urlpath = "/containers/".$self->{option_results}->{name}."/json"; - } - my $port = $self->{option_results}->{port}; - my $containerapi = $options{custom}; - - my $webcontent = $containerapi->api_request(urlpath => $urlpath, - port => $port); - - my ($result,$containername,$containertime); - my $exit = 'OK'; - - if (defined($self->{option_results}->{id}) || defined($self->{option_results}->{name})) { - while ( my ($keys,$values) = each(%{$webcontent->{State}})) { - # Why not set a variable that contains the state? - if ($values eq 'true') { - $result = $keys; - $containername = $webcontent->{Name}; - $containername =~ s/^\///; - my ( $y, $m, $d, $h, $mi, $s ) = $webcontent->{State}->{StartedAt} =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/; - $containertime = $y."-".$m."-".$d." ".$h.":".$mi.":".$s; - last; - } - } - - $exit = $self->get_severity(section => 'state', value => $result); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Container %s is %s (started since %s)", $containername, $result, $containertime)); - } else { - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All containers are in Running state")); - - my ($nbrunning,$nbpaused,$nbexited) = '0'; - - foreach my $val (@$webcontent) { - $containername = $val->{Names}->[0]; - $containername =~ s/^\///; - - # Thanks to Docker API for the paused state... - if (($val->{Status} =~ m/^Up/) && ($val->{Status} =~ m/^(?:(?!Paused).)*$/)) { - $result = 'Running'; - $nbrunning++; - } elsif ($val->{Status} =~ m/^Exited/) { - $result = 'Exited'; - $nbexited++; - } elsif ($val->{Status} =~ m/\(Paused\)$/) { - $result = 'Paused'; - $nbpaused++; - } - - my $tmp_exit = $self->get_severity(section => 'state', value => $result); - $exit = $self->{output}->get_most_critical(status => [ $tmp_exit, $exit ]); - if (!$self->{output}->is_status(value => $tmp_exit, compare => 'OK', litteral => 1)) { - $self->{output}->output_add(long_msg => sprintf("Containers %s is in %s state", - $containername, $result)); - } - } - - if (!$self->{output}->is_status(value => $exit, compare => 'OK', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Some containers are in wrong state")); - } - $self->{output}->perfdata_add(label => "running", - value => $nbrunning, - min => 0, - ); - $self->{output}->perfdata_add(label => "paused", - value => $nbpaused, - min => 0, - ); - $self->{output}->perfdata_add(label => "exited", - value => $nbexited, - min => 0, - ); - } - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Container's state - -=head2 DOCKER OPTIONS - -item B<--port> - -Port used by Docker - -=item B<--id> - -Specify one container's id - -=item B<--name> - -Specify one container's name - -=head2 MODE OPTIONS - -=item B<--threshold-overload> - -Set to overload default threshold values (syntax: section,status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='state,CRITICAL,^(?!(Paused)$)' - -=back - -=cut diff --git a/cloud/docker/mode/cpu.pm b/cloud/docker/mode/cpu.pm deleted file mode 100644 index 32e0b48f1..000000000 --- a/cloud/docker/mode/cpu.pm +++ /dev/null @@ -1,201 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::cpu; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::statefile; -use centreon::plugins::http; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.1'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); - - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - $self->{http} = centreon::plugins::http->new(output => $self->{output}); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - - if ((!defined($self->{option_results}->{name})) && (!defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - - 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(); - } - - $self->{http}->set_options(%{$self->{option_results}}); - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{id})) { - $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); - } elsif (defined($self->{option_results}->{name})) { - $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); - } - - my $urlpath; - if (defined($self->{option_results}->{id})) { - $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; - } - my $port = $self->{option_results}->{port}; - my $containerapi = $options{custom}; - - my $webcontent = $containerapi->api_request(urlpath => $urlpath, - port => $port); - - my $cpu_totalusage = $webcontent->{cpu_stats}->{cpu_usage}->{total_usage}; - my $cpu_systemusage = $webcontent->{cpu_stats}->{system_cpu_usage}; - my @cpu_number = @{$webcontent->{cpu_stats}->{cpu_usage}->{percpu_usage}}; - my $cpu_throttledtime = $webcontent->{cpu_stats}->{throttling_data}->{throttled_time}; - - my $new_datas = {}; - $new_datas->{cpu_totalusage} = $cpu_totalusage; - $new_datas->{cpu_systemusage} = $cpu_systemusage; - $new_datas->{cpu_throttledtime} = $cpu_throttledtime; - my $old_cpu_totalusage = $self->{statefile_value}->get(name => 'cpu_totalusage'); - my $old_cpu_systemusage = $self->{statefile_value}->get(name => 'cpu_systemusage'); - my $old_cpu_throttledtime = $self->{statefile_value}->get(name => 'cpu_throttledtime'); - - if ((!defined($old_cpu_totalusage)) || (!defined($old_cpu_systemusage)) || (!defined($old_cpu_throttledtime))) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - $self->{statefile_value}->write(data => $new_datas); - $self->{output}->display(); - $self->{output}->exit(); - } - - if ($new_datas->{cpu_totalusage} < $old_cpu_totalusage) { - # We set 0. Has reboot. - $old_cpu_totalusage = 0; - } - if ($new_datas->{cpu_systemusage} < $old_cpu_systemusage) { - # We set 0. Has reboot. - $old_cpu_systemusage = 0; - } - - if ($new_datas->{cpu_throttledtime} < $old_cpu_throttledtime) { - # We set 0. Has reboot. - $old_cpu_throttledtime = 0; - } - - my $delta_totalusage = $cpu_totalusage - $old_cpu_totalusage; - my $delta_systemusage = $cpu_systemusage - $old_cpu_systemusage; - my $delta_throttledtime = $cpu_throttledtime - $old_cpu_throttledtime; - # Nano second to second - my $throttledtime = $delta_throttledtime / 10 ** 9; - my $prct_cpu = (($delta_totalusage / $delta_systemusage) * scalar(@cpu_number)) * 100; - - my $exit = $self->{perfdata}->threshold_check(value => $prct_cpu, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("CPU Usage is %.2f%% (Throttled Time: %.3fs)", $prct_cpu, $throttledtime)); - - $self->{output}->perfdata_add(label => "cpu", unit => '%', - value => $prct_cpu, - 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 => "throttled", unit => 's', - value => $throttledtime, - min => 0, - ); - - - $self->{statefile_value}->write(data => $new_datas); - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Container's CPU usage - -=head2 DOCKER OPTIONS - -=item B<--port> - -Port used by Docker - -=item B<--id> - -Specify one container's id - -=item B<--name> - -Specify one container's name - -=head2 MODE OPTIONS - -=item B<--warning> - -Threshold warning in percent. - -=item B<--critical> - -Threshold critical in percent. - -=back - -=cut diff --git a/cloud/docker/mode/image.pm b/cloud/docker/mode/image.pm deleted file mode 100644 index 1a8e5ffa0..000000000 --- a/cloud/docker/mode/image.pm +++ /dev/null @@ -1,225 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::image; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::http; -use JSON; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.1'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "image:s" => { name => 'image' }, - "registry-hostname:s" => { name => 'registry_hostname' }, - "registry-proto:s" => { name => 'registry_proto', default => 'https' }, - "registry-port:s" => { name => 'registry_port' }, - "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' }, - }); - - $self->{http} = centreon::plugins::http->new(output => $self->{output}); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - - if ((!defined($self->{option_results}->{name})) && (!defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - - if (!defined($self->{option_results}->{image})) { - $self->{output}->add_option_msg(short_msg => "Please set the image option"); - $self->{output}->option_exit(); - } - - if (!defined($self->{option_results}->{registry_hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the registry-hostname option"); - $self->{output}->option_exit(); - } - - if (!defined($self->{option_results}->{registry_proto})) { - $self->{output}->add_option_msg(short_msg => "Please set the registry-proto option"); - $self->{output}->option_exit(); - } - - $self->{http}->set_options(%{$self->{option_results}}); -} - -sub run { - my ($self, %options) = @_; - - my ($jsoncontent, $webcontent, $webcontent2); - - my $urlpath; - if (defined($self->{option_results}->{id})) { - $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; - } - my $port = $self->{option_results}->{port}; - my $containerapi = $options{custom}; - - $webcontent = $containerapi->api_request(urlpath => $urlpath, - port => $port); - - my $container_id = $webcontent->{Image}; - - $self->{option_results}->{url_path} = "/v1/repositories/".$self->{option_results}->{image}."/tags"; - $self->{option_results}->{port} = $self->{option_results}->{registry_port}; - $self->{option_results}->{proto} = $self->{option_results}->{registry_proto}; - $self->{option_results}->{hostname} = $self->{option_results}->{registry_hostname}; - $self->{http}->set_options(%{$self->{option_results}}); - - $jsoncontent = $self->{http}->request(); - - my $json2 = JSON->new; - - eval { - $webcontent2 = $json2->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); - } - - my $result; - - foreach (@{$webcontent2}) { - if (($container_id =~ /^$_->{layer}\w+$/)) { - $result="1"; - last; - } - } - - if ($result eq "1") { - $self->{output}->output_add(severity => "OK", - short_msg => sprintf("Container's image and Registry image are identical")); - } else { - $self->{output}->output_add(severity => "CRITICAL", - short_msg => sprintf("Container's image and Registry image are different")); - } - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Container's image viability with a registry - -=head2 DOCKER OPTIONS - -=item B<--port> - -Port used by Docker - -=item B<--id> - -Specify the container's id - -=item B<--name> - -Specify the container's name - -=head2 MODE OPTIONS - -=item B<--image> - -Specify the image's name - -=item B<--registry-hostname> - -IP Addr/FQDN of Docker's Registry - -=item B<--registry-port> - -Port used by Docker's Registry - -=item B<--registry-proto> - -Specify https if needed (Default: 'https') - -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username - -=item B<--password> - -Specify password - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 3) - -=back - -=cut diff --git a/cloud/docker/mode/info.pm b/cloud/docker/mode/info.pm deleted file mode 100644 index 3793c3fdf..000000000 --- a/cloud/docker/mode/info.pm +++ /dev/null @@ -1,108 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::info; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::http; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.1'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' } - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub run { - my ($self, %options) = @_; - - my $urlpath = "/info"; - my $port = $self->{option_results}->{port}; - my $containerapi = $options{custom}; - - my $webcontent = $containerapi->api_request(urlpath => $urlpath, - port => $port); - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("Docker is running")); - - $self->{output}->perfdata_add(label => "containers", - value => $webcontent->{Containers}, - min => 0, - ); - - $self->{output}->perfdata_add(label => "events_listener", - value => $webcontent->{NEventsListener}, - min => 0, - ); - - $self->{output}->perfdata_add(label => "file_descriptor", - value => $webcontent->{NFd}, - min => 0, - ); - - $self->{output}->perfdata_add(label => "go_routines", - value => $webcontent->{NGoroutines}, - min => 0, - ); - - $self->{output}->perfdata_add(label => "images", - value => $webcontent->{Images}, - min => 0, - ); - - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Docker information - -=head2 DOCKER OPTIONS - -=item B<--port> - -Port used by Docker - -=back - -=cut diff --git a/cloud/docker/mode/listcontainers.pm b/cloud/docker/mode/listcontainers.pm deleted file mode 100644 index 6223f8808..000000000 --- a/cloud/docker/mode/listcontainers.pm +++ /dev/null @@ -1,154 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::listcontainers; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.2'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "exclude:s" => { name => 'exclude' }, - }); - - $self->{container_infos} = (); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -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 listcontainer_request { - my ($self, %options) = @_; - - my $urlpath = "/containers/json"; - my $port = $self->{option_results}->{port}; - my $containerapi = $options{custom}; - - my $webcontent = $containerapi->api_request(urlpath => $urlpath, - port => $port); - - foreach my $val (@$webcontent) { - my $containerstate; - if (($val->{Status} =~ m/^Up/) && ($val->{Status} =~ m/^(?:(?!Paused).)*$/)) { - 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->listcontainer_request(%options); - - 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->listcontainer_request(%options); - - 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:'); - - $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -List Docker containers - -=head2 DOCKER OPTIONS - -=item B<--port> - -Port used by Docker - -=head2 MODE OPTIONS - -=item B<--exlude> - -Exclude specific container's state (comma seperated list) (Example: --exclude=Paused,Running) - -=back - -=cut diff --git a/cloud/docker/mode/listnodes.pm b/cloud/docker/mode/listnodes.pm deleted file mode 100644 index 56a69b525..000000000 --- a/cloud/docker/mode/listnodes.pm +++ /dev/null @@ -1,154 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::listnodes; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "exclude:s" => { name => 'exclude' }, - }); - - $self->{node_infos} = (); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -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}} nodes.")); - return 1; - } -return 0; -} - -sub listnode_request { - my ($self, %options) = @_; - - my $urlpath = "/nodes"; - my $port = $self->{option_results}->{port}; - - my $nodeapi = $options{custom}; - my $webcontent = $nodeapi->api_request(urlpath => $urlpath, - port => $port); - - foreach my $val (@$webcontent) { - next if ($self->check_exclude(status => $val->{Status}->{State})); - my $nodeid = $val->{ID}; - $self->{node_infos}->{$nodeid}->{hostname} = $val->{Description}->{Hostname}; - $self->{node_infos}->{$nodeid}->{role} = $val->{Spec}->{Role}; - $self->{node_infos}->{$nodeid}->{availability} = $val->{Spec}->{Availability}; - $self->{node_infos}->{$nodeid}->{state} = $val->{Status}->{State}; - if ($val->{Spec}->{Role} eq 'manager') { - $self->{node_infos}->{$nodeid}->{reachability} = $val->{ManagerStatus}->{Reachability}; - } else { - $self->{node_infos}->{$nodeid}->{reachability} = ''; - } - - } -} - -sub disco_format { - my ($self, %options) = @_; - - my $names = ['id', 'hostname', 'role', 'state', 'availability', 'reachability']; - $self->{output}->add_disco_format(elements => $names); -} - -sub disco_show { - my ($self, %options) = @_; - - $self->listnode_request(%options); - - foreach my $nodeid (keys %{$self->{node_infos}}) { - $self->{output}->add_disco_entry(id => $nodeid, - hostname => $self->{node_infos}->{$nodeid}->{hostname}, - role => $self->{node_infos}->{$nodeid}->{role}, - state => $self->{node_infos}->{$nodeid}->{state}, - availability => $self->{node_infos}->{$nodeid}->{availability}, - reachability => $self->{node_infos}->{$nodeid}->{reachability}, - ); - } -} - -sub run { - my ($self, %options) = @_; - - $self->listnode_request(%options); - - foreach my $nodeid (keys %{$self->{node_infos}}) { - $self->{output}->output_add(long_msg => sprintf("%s [hostname = %s , role = %s, state = %s, availability = %s, reachability = %s]", - $nodeid, - $self->{node_infos}->{$nodeid}->{hostname}, - $self->{node_infos}->{$nodeid}->{role}, - $self->{node_infos}->{$nodeid}->{state}, - $self->{node_infos}->{$nodeid}->{availability}, - $self->{node_infos}->{$nodeid}->{reachability})); - } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'List Swarm nodes:'); - - $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); - $self->{output}->exit(); - - exit 0; -} - -1; - -__END__ - -=head1 MODE - -List Docker Swarm nodes - -=head2 DOCKER OPTIONS - -=item B<--port> - -Port used by Docker - -=head2 MODE OPTIONS - -=item B<--exlude> - -Exclude specific node's state (comma seperated list) (Example: --exclude=disconnected) - -=back - -=cut diff --git a/cloud/docker/mode/memory.pm b/cloud/docker/mode/memory.pm deleted file mode 100644 index 1b8dd8317..000000000 --- a/cloud/docker/mode/memory.pm +++ /dev/null @@ -1,175 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::memory; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.1'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - - if ((!defined($self->{option_results}->{name})) && (!defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - - 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(); - } -} - -sub run { - my ($self, %options) = @_; - - my $urlpath; - if (defined($self->{option_results}->{id})) { - $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; - } - my $port = $self->{option_results}->{port}; - my $containerapi = $options{custom}; - - my $webcontent = $containerapi->api_request(urlpath => $urlpath, - port => $port); - - my $total_size = $webcontent->{memory_stats}->{limit}; - my $memory_used = $webcontent->{memory_stats}->{usage}; - my $memory_free = $webcontent->{memory_stats}->{limit} - $webcontent->{memory_stats}->{usage}; - my $prct_used = $memory_used * 100 / $total_size; - my $prct_free = 100 - $prct_used; - my $failed_counter = $webcontent->{memory_stats}->{failcnt}; - my $memory_cached = $webcontent->{memory_stats}->{stats}->{cache}; - my $memory_rss = $webcontent->{memory_stats}->{stats}->{rss}; - - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); - my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $memory_used); - my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $memory_free); - my ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $memory_cached); - my ($rss_value, $rss_unit) = $self->{perfdata}->change_bytes(value => $memory_rss); - - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s %.2f%%) Cached: %s RSS: %s Failed: %s", - $total_value . " " . $total_unit, - $used_value . " " . $used_unit, $prct_used, - $free_value . " " . $free_unit, $prct_free, - $cached_value . " " . $cached_unit, - $rss_value . " " . $rss_unit, - $failed_counter) - ); - - $self->{output}->perfdata_add(label => "used", - value => $webcontent->{memory_stats}->{usage}, - 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), - min => 0, - max => $webcontent->{memory_stats}->{limit}, - ); - - $self->{output}->perfdata_add(label => "cached", - value => $webcontent->{memory_stats}->{stats}->{cache}, - min => 0, - ); - - $self->{output}->perfdata_add(label => "rss", - value => $webcontent->{memory_stats}->{stats}->{rss}, - min => 0, - ); - - $self->{output}->perfdata_add(label => "failed", - value => $webcontent->{memory_stats}->{failcnt}, - min => 0, - ); - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Container's memory usage - -=head2 DOCKER OPTIONS - -=item B<--port> - -Port used by Docker - -=item B<--id> - -Specify one container's id - -=item B<--name> - -Specify one container's name - -=head2 MODE OPTIONS - -=item B<--warning> - -Threshold warning in percent. - -=item B<--critical> - -Threshold critical in percent. - -=back - -=cut diff --git a/cloud/docker/mode/nodestate.pm b/cloud/docker/mode/nodestate.pm deleted file mode 100644 index 9f7e6574e..000000000 --- a/cloud/docker/mode/nodestate.pm +++ /dev/null @@ -1,159 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::nodestate; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my $thresholds = { - state => [ - ['ready', 'OK'], - ['disconnected', 'WARNING'], - ['down', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ], -}; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "id:s" => { name => 'id' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if ((defined($self->{option_results}->{id})) && ($self->{option_results}->{id} eq '')) { - $self->{output}->add_option_msg(short_msg => "You need to specify the id option"); - $self->{output}->option_exit(); - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } -} - -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 run { - my ($self, %options) = @_; - - my $urlpath = "/nodes/".$self->{option_results}->{id}; - my $port = $self->{option_results}->{port}; - my $nodeapi = $options{custom}; - - my $webcontent = $nodeapi->api_request(urlpath => $urlpath, - port => $port); - - my $exit = $self->get_severity(section => 'state', value => $webcontent->{Status}->{State}); - - if (defined($webcontent->{ManagerStatus}->{Reachability})) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%s node is %s (Availability: %s - Reachability: %s)", - $webcontent->{Spec}->{Role}, - $webcontent->{Status}->{State}, - $webcontent->{Spec}->{Availability}, - $webcontent->{ManagerStatus}->{Reachability})); - } else { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%s node is %s (Availability: %s)", - $webcontent->{Spec}->{Role}, - $webcontent->{Status}->{State}, - $webcontent->{Spec}->{Availability})); - } - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Swarm Node's state - -=head2 DOCKER OPTIONS - -item B<--port> - -Port used by Docker - -=item B<--id> - -Specify one node's id - -=head2 MODE OPTIONS - -=item B<--threshold-overload> - -Set to overload default threshold values (syntax: section,status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='state,CRITICAL,^(?!(disconnected)$)' - -=back - -=cut diff --git a/cloud/docker/mode/traffic.pm b/cloud/docker/mode/traffic.pm deleted file mode 100644 index a183bf90b..000000000 --- a/cloud/docker/mode/traffic.pm +++ /dev/null @@ -1,218 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# 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. -# - -package cloud::docker::mode::traffic; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::statefile; -use centreon::plugins::http; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.1'; - $options{options}->add_options(arguments => - { - "port:s" => { name => 'port' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "warning-in:s" => { name => 'warning_in' }, - "critical-in:s" => { name => 'critical_in' }, - "warning-out:s" => { name => 'warning_out' }, - "critical-out:s" => { name => 'critical_out' }, - }); - - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - $self->{http} = centreon::plugins::http->new(output => $self->{output}); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - if ((!defined($self->{option_results}->{name})) && (!defined($self->{option_results}->{id}))) { - $self->{output}->add_option_msg(short_msg => "Please set the name or id option"); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning 'in' threshold '" . $self->{option_results}->{warning_in} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical 'in' threshold '" . $self->{option_results}->{critical_in} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning 'out' threshold '" . $self->{option_results}->{warning_out} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical 'out' threshold '" . $self->{option_results}->{critical_out} . "'."); - $self->{output}->option_exit(); - } - - $self->{http}->set_options(%{$self->{option_results}}); - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - - my $new_datas = {}; - - if (defined($self->{option_results}->{id})) { - $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); - } elsif (defined($self->{option_results}->{name})) { - $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); - } - - my $urlpath; - if (defined($self->{option_results}->{id})) { - $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; - } - my $port = $self->{option_results}->{port}; - my $containerapi = $options{custom}; - - my $webcontent = $containerapi->api_request(urlpath => $urlpath, - port => $port); - - my $rx_bytes = $webcontent->{network}->{rx_bytes}; - my $tx_bytes = $webcontent->{network}->{tx_bytes}; - $new_datas->{rx_bytes} = $rx_bytes; - $new_datas->{tx_bytes} = $tx_bytes; - $new_datas->{last_timestamp} = time(); - my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); - - if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - $self->{statefile_value}->write(data => $new_datas); - $self->{output}->display(); - $self->{output}->exit(); - } - - my $time_delta = $new_datas->{last_timestamp} - $old_timestamp; - if ($time_delta <= 0) { - # At least one second. two fast calls ;) - $time_delta = 1; - } - - my $old_rx_bytes = $self->{statefile_value}->get(name => 'rx_bytes'); - my $old_tx_bytes = $self->{statefile_value}->get(name => 'tx_bytes'); - - if ($new_datas->{rx_bytes} < $old_rx_bytes) { - # We set 0. Has reboot. - $old_rx_bytes = 0; - } - if ($new_datas->{tx_bytes} < $old_tx_bytes) { - # We set 0. Has reboot. - $old_tx_bytes = 0; - } - - my $delta_rx_bits = ($rx_bytes - $old_rx_bytes) * 8; - my $delta_tx_bits = ($tx_bytes - $old_tx_bytes) * 8; - my $rx_absolute_per_sec = $delta_rx_bits / $time_delta; - my $tx_absolute_per_sec = $delta_tx_bits / $time_delta; - - my $exit1 = $self->{perfdata}->threshold_check(value => $rx_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $tx_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]); - - my ($rx_value, $rx_unit) = $self->{perfdata}->change_bytes(value => $rx_absolute_per_sec, network => 1); - my ($tx_value, $tx_unit) = $self->{perfdata}->change_bytes(value => $tx_absolute_per_sec, network => 1); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Traffic In : %s/s, Out : %s/s", - $rx_value . $rx_unit, - $tx_value . $tx_unit)); - - $self->{output}->perfdata_add(label => 'traffic_in', unit => 'b/s', - value => sprintf("%.2f", $rx_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in'), - min => 0); - $self->{output}->perfdata_add(label => 'traffic_out', unit => 'b/s', - value => sprintf("%.2f", $tx_absolute_per_sec), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out'), - min => 0); - - $self->{statefile_value}->write(data => $new_datas); - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Container's Network traffic usage - -=head2 DOCKER OPTIONS - -=item B<--port> - -Port used by Docker - -=item B<--id> - -Specify one container's id - -=item B<--name> - -Specify one container's name - -=head2 MODE OPTIONS - -=item B<--warning-in> - -Threshold warning in b/s for 'in' traffic. - -=item B<--critical-in> - -Threshold critical in b/s for 'in' traffic. - -=item B<--warning-out> - -Threshold warning in b/s for 'out' traffic. - -=item B<--critical-out> - -Threshold critical in b/s for 'out' traffic. - -=back - -=cut diff --git a/cloud/docker/restapi/custom/api.pm b/cloud/docker/restapi/custom/api.pm new file mode 100644 index 000000000..13d4ba939 --- /dev/null +++ b/cloud/docker/restapi/custom/api.pm @@ -0,0 +1,356 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package cloud::docker::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::http; +use JSON::XS; +use FileHandle; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => + { + "hostname:s@" => { name => 'hostname' }, + "port:s" => { name => 'port', default => 8080 }, + "proto:s" => { name => 'proto' }, + "credentials" => { name => 'credentials' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "proxyurl:s" => { name => 'proxyurl' }, + "proxypac:s" => { name => 'proxypac' }, + "timeout:s" => { name => 'timeout', default => 10 }, + "ssl:s" => { name => 'ssl' }, + "cert-file:s" => { name => 'cert_file' }, + "key-file:s" => { name => 'key_file' }, + "cacert-file:s" => { name => 'cacert_file' }, + "cert-pwd:s" => { name => 'cert_pwd' }, + "cert-pkcs12" => { name => 'cert_pkcs12' }, + "api-display" => { name => 'api_display' }, + "api-write-file:s" => { name => 'api_write_file' }, + "api-read-file:s" => { name => 'api_read_file' }, + "reload-cache-time:s" => { name => 'reload_cache_time', default => 300 }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + + return $self; + +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + # return 1 = ok still hostname + # return 0 = no hostname left + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + + return 0 if (defined($self->{option_results}->{api_read_file}) && $self->{option_results}->{api_read_file} ne ''); + + if (!defined($self->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Need to specify hostname option."); + $self->{output}->option_exit(); + } + $self->{http} = {}; + foreach my $node_name (@{$self->{hostname}}) { + if ($node_name ne '') { + $self->{http}->{$node_name} = centreon::plugins::http->new(output => $self->{output}); + $self->{option_results}->{hostname} = $node_name; + $self->{http}->{$node_name}->set_options(%{$self->{option_results}}); + } + } + + return 0; +} + +sub api_display { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{api_display})) { + if (!defined($self->{option_results}->{api_write_file}) || $self->{option_results}->{api_write_file} eq '') { + $self->{output}->output_add(severity => 'OK', + short_msg => $options{content}); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + if (!open (FH, '>', $self->{option_results}->{api_write_file})) { + $self->output_add(severity => 'UNKNOWN', + short_msg => "cannot open file '" . $self->{option_results}->{api_write_file} . "': $!"); + + } + + FH->autoflush(1); + print FH $options{content}; + close FH; + $self->output_add(severity => 'OK', + short_msg => "Data written in file '" . $self->{option_results}->{api_write_file} . "': $!"); + $self->{output}->exit(); + } +} + +sub api_read_file { + my ($self, %options) = @_; + + my $file_content = do { + local $/ = undef; + if (!open my $fh, "<", $self->{option_results}->{api_read_file}) { + $self->{output}->add_option_msg(short_msg => "Could not open file $self->{option_results}->{api_read_file} : $!"); + $self->{output}->option_exit(); + } + <$fh>; + }; + + my $content; + eval { + $content = JSON::XS->new->utf8->decode($file_content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + + return $content; +} + +sub cache_containers { + my ($self, %options) = @_; + + my $has_cache_file = $options{statefile}->read(statefile => 'cache_docker_containers_' . join(':', @{$self->{hostname}}) . '_' . $self->{option_results}->{port}); + my $timestamp_cache = $options{statefile}->get(name => 'last_timestamp'); + my $containers = $options{statefile}->get(name => 'containers'); + if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($options{reload_cache_time})))) { + $containers = {}; + my $datas = { last_timestamp => time(), containers => $containers }; + + foreach my $node_name (keys %{$self->{http}}) { + my $list_containers = $self->internal_api_list_containers(node_name => $node_name); + foreach my $container (@$list_containers) { + $containers->{$container->{Id}} = { + State => $container->{State}, + NodeName => $node_name, + Name => join(':', @{$container->{Names}}), + }; + } + } + $options{statefile}->write(data => $containers); + } + + return $containers; +} + +sub internal_api_list_containers { + my ($self, %options) = @_; + + my $response = $self->{http}->{$options{node_name}}->request( + url_path => '/containers/json?all=true', + unknown_status => '', critical_status => '', warning_status => ''); + my $containers; + eval { + $containers = JSON::XS->new->utf8->decode($response); + }; + if ($@) { + $containers = []; + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Node '$options{node_name}': cannot decode json get containers response: $@"); + } + + return $containers; +} + +sub internal_api_get_container_stats { + my ($self, %options) = @_; + + my $response = $self->{http}->{$options{node_name}}->request( + url_path => '/containers/' . $options{container_id} . '/stats?stream=false', + unknown_status => '', critical_status => '', warning_status => ''); + my $container_stats; + eval { + $container_stats = JSON::XS->new->utf8->decode($response); + }; + if ($@) { + $container_stats = {}; + $self->output_add(severity => 'UNKNOWN', + short_msg => "Node '$options{node_name}': cannot decode json get container stats response: $@"); + } + + return $container_stats; +} + +sub api_get_containers { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{api_read_file}) && $self->{option_results}->{api_read_file} ne '') { + return $self->api_read_file(); + } + + my $content_total = $self->cache_containers(statefile => $options{statefile}); + if (defined($options{container_id}) && $options{container_id} ne '' && defined($content_total->{$options{container_id}})) { + $content_total->{$options{container_id}}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$options{container_id}}->{NodeName}, container_id => $options{container_id}); + } else { + foreach my $container_id (keys %{$content_total}) { + $content_total->{$container_id}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id); + } + } + + $self->api_display(); + return $content_total; +} + +1; + +__END__ + +=head1 NAME + +Docker REST API + +=head1 SYNOPSIS + +Docker Rest API custom mode + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +IP Addr/FQDN of the docker node (can be multiple). + +=item B<--port> + +Port used (Default: 8080) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--credentials> + +Specify this option if you access webpage over basic authentification + +=item B<--username> + +Specify username for basic authentification (Mandatory if --credentials is specidied) + +=item B<--password> + +Specify password for basic authentification (Mandatory if --credentials is specidied) + +=item B<--proxyurl> + +Proxy URL + +=item B<--proxypac> + +Proxy pac file (can be an url or local file) + +=item B<--timeout> + +Threshold for HTTP timeout (Default: 10) + +=item B<--ssl> + +Specify SSL version (example : 'sslv3', 'tlsv1'...) + +=item B<--cert-file> + +Specify certificate to send to the webserver + +=item B<--key-file> + +Specify key to send to the webserver + +=item B<--cacert-file> + +Specify root certificate to send to the webserver + +=item B<--cert-pwd> + +Specify certificate's password + +=item B<--cert-pkcs12> + +Specify type of certificate (PKCS12) + +=item B<--api-display> + +Print json api. + +=item B<--api-write-display> + +Print json api in a file (to be used with --api-display). + +=item B<--api-read-file> + +Read API from file. + +=item B<--reload-cache-time> + +Time in seconds before reloading list containers cache (default: 300) + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/cloud/docker/restapi/mode/containerusage.pm b/cloud/docker/restapi/mode/containerusage.pm new file mode 100644 index 000000000..a9827566d --- /dev/null +++ b/cloud/docker/restapi/mode/containerusage.pm @@ -0,0 +1,246 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package cloud::docker::restapi::mode::containerusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = 'status : ' . $self->{result_values}->{status} . ' [error: ' . $self->{result_values}->{error} . ']'; + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; + $self->{result_values}->{error} = $options{new_datas}->{$self->{instance} . '_error'}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output', message_multiple => 'All containers are ok', skipped_code => { -11 => 1 } }, + ]; + + $self->{maps_counters}->{output_stream} = [ + { label => 'container-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'name' }, { name => 'error' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'traffic-in', set => { + key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'name' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic In : %s %s/s', + perfdatas => [ + { label => 'traffic_in', value => 'traffic_in_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name_absolute' }, + ], + } + }, + { label => 'traffic-out', set => { + key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'name' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic Out : %s %s/s', + perfdatas => [ + { label => 'traffic_out', value => 'traffic_out_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name_absolute' }, + ], + } + }, + { label => 'dropped-in', set => { + key_values => [ { name => 'dropped_in', diff => 1 }, { name => 'name' } ], + output_template => 'Packets Dropped In : %s', + perfdatas => [ + { label => 'dropped_in', value => 'dropped_in_absolute', template => '%.2f', + min => 0, label_extra_instance => 1, instance_use => 'name_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "container-id:s" => { name => 'container_id' }, + "filter-name:s" => { name => 'filter_name' }, + "warning-container-status:s" => { name => 'warning_container_status' }, + "critical-container-status:s" => { name => 'critical_container_status', default => '%{status} !~ /Connecting|Connected/i || %{error} !~ /none/i' }, + }); + + $self->{statefile_cache_containers} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); + $self->{statefile_cache_containers}->check_options(%options); +} + +sub prefix_containers_output { + my ($self, %options) = @_; + + return "Container '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_container_status', 'critical_container_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{containers} = {}; + my $result = $options{custom}->api_get_containers(container_id => $self->{option_results}->{container_id}, statefile => $self->{statefile_cache_containers}); + use Data::Dumper; + print Data::Dumper::Dumper($result); + exit(1); + + foreach my $entry (@{$result->{outputs}}) { + my $name = $entry->{name} . '/' . $entry->{requested_stream_id}; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + + $self->{output_stream}->{$entry->{id}} = { + display => $name, + status => $entry->{status}, + traffic_in => $entry->{stats}->{net_recv}->{bytes} * 8, + traffic_out => $entry->{stats}->{net_send}->{bytes} * 8, + dropped_in => $entry->{stats}->{net_recv}->{dropped}, + }; + } + + if (scalar(keys %{$self->{containers}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No container found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "docker_" . $self->{mode} . '_' . $options{custom}->{hostname} . '_' . $options{custom}->{port} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check container usage. + +=over 8 + +=item B<--container-id> + +Exact container ID. + +=item B<--filter-name> + +Filter by container name (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^container-status$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'traffic-in', 'traffic-out', 'dropped-in'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'traffic-in', 'traffic-out', 'dropped-in'. + +=item B<--warning-container-status> + +Set warning threshold for status (Default: -) +Can used special variables like: %{id}, %{name}, %{status}. + +=item B<--critical-container-status> + +Set critical threshold for status (Default: '%{status} !~ /Connecting|Connected/i'). +Can used special variables like: %{id}, %{name}, %{status}. + + + +=back + +=cut diff --git a/cloud/docker/plugin.pm b/cloud/docker/restapi/plugin.pm similarity index 60% rename from cloud/docker/plugin.pm rename to cloud/docker/restapi/plugin.pm index 26fb0da07..9356bacc4 100644 --- a/cloud/docker/plugin.pm +++ b/cloud/docker/restapi/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::docker::plugin; +package cloud::docker::restapi::plugin; use strict; use warnings; @@ -31,19 +31,11 @@ sub new { $self->{version} = '0.3'; %{$self->{modes}} = ( - 'blockio' => 'cloud::docker::mode::blockio', - 'containerstate' => 'cloud::docker::mode::containerstate', - 'cpu' => 'cloud::docker::mode::cpu', - 'image' => 'cloud::docker::mode::image', - 'info' => 'cloud::docker::mode::info', - 'list-containers' => 'cloud::docker::mode::listcontainers', - 'list-nodes' => 'cloud::docker::mode::listnodes', - 'memory' => 'cloud::docker::mode::memory', - 'nodestate' => 'cloud::docker::mode::nodestate', - 'traffic' => 'cloud::docker::mode::traffic', + 'container-usage' => 'cloud::docker::restapi::mode::containerusage', + 'node-status' => 'cloud::docker::restapi::mode::nodestatus', ); - $self->{custom_modes}{dockerapi} = 'cloud::docker::custom::dockerapi'; + $self->{custom_modes}{api} = 'cloud::docker::restapi::custom::api'; return $self; } diff --git a/cloud/ovh/restapi/mode/quotausage.pm b/cloud/ovh/restapi/mode/quotausage.pm new file mode 100644 index 000000000..caa02bde5 --- /dev/null +++ b/cloud/ovh/restapi/mode/quotausage.pm @@ -0,0 +1,205 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package cloud::ovh::restapi::mode::quotausage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $instance_mode; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'service', type => 1, cb_prefix_output => 'prefix_services_output', message_multiple => 'All services are ok' } + ]; + + $self->{maps_counters}->{service} = [ + { label => 'usage', set => { + key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-service:s" => { name => 'filter_service' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +sub prefix_services_output { + my ($self, %options) = @_; + + return "Service '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{service} = {}; + my $result = $options{custom}->get(path => '/hosting/web'); + foreach my $service (@$result) { + if (defined($self->{option_results}->{filter_service}) && $self->{option_results}->{filter_service} ne '' && + $service !~ /$self->{option_results}->{filter_service}/) { + $self->{output}->output_add(long_msg => "skipping '" . $service . "': no matching filter.", debug => 1); + next; + } + + my $result2 = $options{custom}->get(path => '/hosting/web/' . $service); + my $used = centreon::plugins::misc::convert_bytes(value => $result2->{quotaUsed}->{value}, unit => $result2->{quotaUsed}->{unit}); + my $total = centreon::plugins::misc::convert_bytes(value => $result2->{quotaSize}->{value}, unit => $result2->{quotaSize}->{unit}); + $self->{service}->{$service} = { + display => $service, + used => $used, + total => $total + }; + } + + if (scalar(keys %{$self->{service}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No service found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check web hosting space. + +=over 8 + +=item B<--filter-service> + +Filter service name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage'. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut diff --git a/cloud/ovh/restapi/plugin.pm b/cloud/ovh/restapi/plugin.pm index 2fb0a60c7..c27a75843 100644 --- a/cloud/ovh/restapi/plugin.pm +++ b/cloud/ovh/restapi/plugin.pm @@ -31,7 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'sms' => 'cloud::ovh::restapi::mode::sms', + 'quota-usage' => 'cloud::ovh::restapi::mode::quotausage', + 'sms' => 'cloud::ovh::restapi::mode::sms', ); $self->{custom_modes}{api} = 'cloud::ovh::restapi::custom::api'; diff --git a/hardware/devices/video/appeartv/snmp/mode/alarms.pm b/hardware/devices/video/appeartv/snmp/mode/alarms.pm index 8130475cf..1a5febdc7 100644 --- a/hardware/devices/video/appeartv/snmp/mode/alarms.pm +++ b/hardware/devices/video/appeartv/snmp/mode/alarms.pm @@ -77,7 +77,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'alarms', type => 2, cb_long_output => 'alarms_long_output', message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] } ]; @@ -94,12 +94,6 @@ sub set_counters { ]; } -sub policy_long_output { - my ($self, %options) = @_; - - return "checking alarms"; -} - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -150,8 +144,6 @@ my $mapping = { msgSeverity => { oid => '.1.3.6.1.4.1.23916.3.1.4.1.13', map => \%map_severity }, }; -my $oid_clusVolumeEntry = '.1.3.6.1.4.1.9804.3.1.1.2.12.97.1'; - sub manage_selection { my ($self, %options) = @_; @@ -222,4 +214,3 @@ Only check new alarms. =back =cut - \ No newline at end of file diff --git a/hardware/server/hp/ilo/xmlapi/custom/api.pm b/hardware/server/hp/ilo/xmlapi/custom/api.pm index 71e57ec13..88a5f611f 100644 --- a/hardware/server/hp/ilo/xmlapi/custom/api.pm +++ b/hardware/server/hp/ilo/xmlapi/custom/api.pm @@ -326,7 +326,7 @@ Don't try to find ILO version. =item B<--ssl-opt> Set SSL Options (--ssl-opt="SSL_version=SSLv3"). -Default: --ssl-opt="SSL_version=SSL_VERIFY_NONE" +Default: --ssl-opt="SSL_verify_mode=SSL_VERIFY_NONE" =back diff --git a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm index 63d6baef8..6a5ea0b9e 100644 --- a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm +++ b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/eventlog.pm @@ -20,20 +20,78 @@ package hardware::server::ibm::mgmt_cards::imm::snmp::mode::eventlog; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; - use centreon::plugins::misc; use centreon::plugins::statefile; -my %severity_map = ( - 0 => 'error', - 1 => 'warning', - 2 => 'information', - 3 => 'other', -); +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("alarm [severity: %s] [text: %s] %s", $self->{result_values}->{severity}, + $self->{result_values}->{text}, $self->{result_values}->{generation_time}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{text} = $options{new_datas}->{$self->{instance} . '_eventLogString'}; + $self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_eventLogSeverity'}; + $self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'}; + $self->{result_values}->{generation_time} = $options{new_datas}->{$self->{instance} . '_generation_time'}; + return 0; +} + + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{alarm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'eventLogSeverity' }, { name => 'eventLogString' }, { name => 'since' }, { name => 'generation_time' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} sub new { my ($class, %options) = @_; @@ -42,136 +100,117 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "filter-severity:s" => { name => 'filter_severity', default => 'error' }, - "filter-message:s" => { name => 'filter_message' }, + { + "warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /warning/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /error/i' }, "memory" => { name => 'memory' }, - "warning" => { name => 'warning' }, + "timezone:s" => { name => 'timezone' }, }); + + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime', + error_msg => "Cannot load module 'DateTime'."); $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); if (defined($self->{option_results}->{memory})) { $self->{statefile_cache}->check_options(%options); } + + $self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); } - -sub run { +sub change_macros { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - my $datas = {}; - my $last_time; - my $exit = defined($self->{option_results}->{warning}) ? 'WARNING' : 'CRITICAL'; - my ($num_eventlog_checked, $num_errors) = (0, 0); - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->read(statefile => "cache_imm_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); - $self->{output}->output_add(severity => 'OK', - short_msg => "No new problems detected."); - $last_time = $self->{statefile_cache}->get(name => 'last_time'); - } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems detected."); - } - - #### Get OIDS - ## Not need to check from an index point (not so much values. and can clear) - - my $oid_eventLogEntry = '.1.3.6.1.4.1.2.3.51.3.2.1.1.1'; - my $oid_eventLogString = '.1.3.6.1.4.1.2.3.51.3.2.1.1.1.2'; - my $oid_eventLogSeverity = '.1.3.6.1.4.1.2.3.51.3.2.1.1.1.3'; - my $oid_eventLogDate = '.1.3.6.1.4.1.2.3.51.3.2.1.1.1.4'; # Month/Day/YEAR - my $oid_eventLogTime = '.1.3.6.1.4.1.2.3.51.3.2.1.1.1.5'; # Hour::Min::Sec - - my $result = $self->{snmp}->get_table(oid => $oid_eventLogEntry); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_eventLogString\.(\d+)$/); - my $instance = $1; - - my $message = centreon::plugins::misc::trim($result->{$oid_eventLogString . '.' . $instance}); - my $severity = $result->{$oid_eventLogSeverity . '.' . $instance}; - my $date = $result->{$oid_eventLogDate . '.' . $instance}; - my $time = $result->{$oid_eventLogTime . '.' . $instance}; - - my $date_compare = ''; - $date =~ /(\d+)\/(\d+)\/(\d+)/; - $date_compare = $3 . $1 . $2; - $time =~ /(\d+):(\d+):(\d+)/; - $date_compare .= $1 . $2 . $3; - - if (defined($self->{option_results}->{memory})) { - $datas->{last_time} = $date_compare; - next if (defined($last_time) && $datas->{last_time} <= $last_time); + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; } - - $num_eventlog_checked++; - - next if (defined($self->{option_results}->{filter_severity}) && $self->{option_results}->{filter_severity} ne '' && $severity_map{$severity} !~ /$self->{option_results}->{filter_severity}/); - next if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' && $message !~ /$self->{option_results}->{filter_message}/); - - $num_errors++; - $self->{output}->output_add(long_msg => sprintf("%s : %s", - $date . ' ' . $time, - $message - ) - ); - - } - - $self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_eventlog_checked)); - if ($num_errors != 0) { - # Message problem - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) - ); - } - - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->write(data => $datas); - } - - $self->{output}->display(); - $self->{output}->exit(); } +my %map_severity = (0 => 'error', 1 => 'warning', 2 => 'information', 3 => 'other'); + +my $mapping = { + eventLogString => { oid => '.1.3.6.1.4.1.2.3.51.3.2.1.1.1.2' }, + eventLogSeverity => { oid => '.1.3.6.1.4.1.2.3.51.3.2.1.1.1.3', map => \%map_severity }, + eventLogDate => { oid => '.1.3.6.1.4.1.2.3.51.3.2.1.1.1.4' }, # Month/Day/YEAR + eventLogTime => { oid => '.1.3.6.1.4.1.2.3.51.3.2.1.1.1.5' }, +}; +my $oid_eventLogEntry = '.1.3.6.1.4.1.2.3.51.3.2.1.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{alarms}->{global} = { alarm => {} }; + my $snmp_result = $options{snmp}->get_table(oid => $oid_eventLogEntry, nothing_quit => 1); + + my $last_time; + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => "cache_imm_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port(). '_' . $self->{mode}); + $last_time = $self->{statefile_cache}->get(name => 'last_time'); + } + + my ($i, $current_time) = (1, time()); + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{eventLogSeverity}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + my $date = $result->{eventLogDate} . ' ' . $result->{eventLogTime}; + $date =~ /^(\d+)\/(\d+)\/(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+)/; + + my $dt = DateTime->new(year => $3, month => $1, day => $2, hour => $4, minute => $5, second => $6, + time_zone => $self->{option_results}->{timezone}); + + next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch); + + my $diff_time = $current_time - $dt->epoch; + + $self->{alarms}->{global}->{alarm}->{$i} = { %$result, since => $diff_time, generation_time => centreon::plugins::misc::change_seconds(value => $diff_time) }; + $i++; + } + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->write(data => { last_time => $current_time }); + } +} + 1; __END__ =head1 MODE -Check eventlogs. +Check alarms. =over 8 -=item B<--warning> +=item B<--warning-status> -Use warning return instead 'critical'. +Set warning threshold for status (Default: '%{severity} =~ /warning/i') +Can used special variables like: %{severity}, %{text}, %{since} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{severity} =~ /error/i'). +Can used special variables like: %{severity}, %{text}, %{since} + +=item B<--timezone> + +Timezone of time options. Default is 'GMT'. =item B<--memory> -Only check new eventlogs. - -=item B<--filter-severity> - -Filter on severity. (Default: error) -Can be: error, warning, information, other. - -=item B<--filter-message> - -Filter on event message. (Default: none) +Only check new alarms. =back =cut - \ No newline at end of file diff --git a/hardware/server/supermicro/snmp/mode/hardware.pm b/hardware/server/supermicro/snmp/mode/hardware.pm new file mode 100644 index 000000000..a7bfbfce9 --- /dev/null +++ b/hardware/server/supermicro/snmp/mode/hardware.pm @@ -0,0 +1,334 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package hardware::server::supermicro::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(sensor\..*|memory|disk|cpu)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(sensor\..*)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sensor => [ + ['ok', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ], + default => [ + ['ok', 'OK'], + ['critical', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'hardware::server::supermicro::snmp::mode::components'; + $self->{components_module} = ['sensor', 'memory', 'disk', 'cpu']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'sensor', 'disk', 'memory'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=sensor,temperature.* + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='sensor.temperature,OK,warning' + +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='sensor.temperature,.*,30' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='sensor.temperature,.*,40' + +=back + +=cut + +package hardware::server::supermicro::snmp::mode::components::sensor; + +use strict; +use warnings; + +my %map_sensor_status = (0 => 'ok', 1 => 'warning', 2 => 'critical'); +my %map_sensor_type = ( + 0 => 'fan', 1 => 'voltage', 2 => 'temperature', 3 => 'discrete', +); +my %map_sensor_monitored = ( + 0 => 'not monitored', 1 => 'monitored', +); + +my $mapping = { + smHealthMonitorName => { oid => '.1.3.6.1.4.1.10876.2.1.1.1.1.2' }, + smHealthMonitorType => { oid => '.1.3.6.1.4.1.10876.2.1.1.1.1.3', map => \%map_sensor_type }, + smHealthMonitorReading => { oid => '.1.3.6.1.4.1.10876.2.1.1.1.1.4' }, + smHealthMonitorMonitor => { oid => '.1.3.6.1.4.1.10876.2.1.1.1.1.10', map => \%map_sensor_monitored }, + smHealthMonitorReadingUnit => { oid => '.1.3.6.1.4.1.10876.2.1.1.1.1.11' }, + smHealthMonitorStatus => { oid => '.1.3.6.1.4.1.10876.2.1.1.1.1.12', map => \%map_sensor_status }, +}; +my $oid_smHealthMonitorEntry = '.1.3.6.1.4.1.10876.2.1.1.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_smHealthMonitorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking sensors"); + $self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; + return if ($self->check_filter(section => 'sensor')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_smHealthMonitorEntry}})) { + next if ($oid !~ /^$mapping->{smHealthMonitorReading}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_smHealthMonitorEntry}, instance => $instance); + + next if (defined($result->{smHealthMonitorMonitor}) && $result->{smHealthMonitorMonitor} eq 'not monitored'); + + next if ($self->check_filter(section => 'sensor', instance => $result->{smHealthMonitorType} . '.' . $instance)); + + $self->{components}->{sensor}->{total}++; + $self->{output}->output_add(long_msg => sprintf("sensor '%s' status is '%s' [instance = %s, value = %s]", + $result->{smHealthMonitorName}, + defined($result->{smHealthMonitorStatus}) ? $result->{smHealthMonitorStatus} : 'undefined', + $result->{smHealthMonitorType} . '.' . $instance, + defined($result->{smHealthMonitorReading}) ? $result->{smHealthMonitorReading} : '-')); + + if (defined($result->{smHealthMonitorStatus})) { + my $exit = $self->get_severity(label => 'sensor', section => 'sensor.' . $result->{smHealthMonitorType}, value => $result->{smHealthMonitorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor '%s' status is '%s'", $result->{smHealthMonitorName}, $result->{smHealthMonitorStatus})); + } + } + + next if ($result->{smHealthMonitorReading} !~ /[0-9]/); + $result->{smHealthMonitorReadingUnit} = '' if (defined($result->{smHealthMonitorReadingUnit}) && $result->{smHealthMonitorReadingUnit} =~ /N\/A/i); + + my $component = 'sensor.' . $result->{smHealthMonitorType}; + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{smHealthMonitorReading}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Sensor '%s' is %s %s", $result->{smHealthMonitorName}, $result->{smHealthMonitorReading}, + defined($result->{smHealthMonitorReadingUnit}) ? $result->{smHealthMonitorReadingUnit} : '')); + } + $self->{output}->perfdata_add(label => $component . '_' . $result->{smHealthMonitorName}, unit => $result->{smHealthMonitorReadingUnit}, + value => $result->{smHealthMonitorReading}, + warning => $warn, + critical => $crit); + } +} + +1; + +package hardware::server::supermicro::snmp::mode::components::memory; + +use strict; +use warnings; + +my %map_memory_status = (0 => 'ok', 2 => 'critical'); + +my $mapping_memory = { + memTag => { oid => '.1.3.6.1.4.1.10876.100.1.3.1.1' }, + memDeviceStatus => { oid => '.1.3.6.1.4.1.10876.100.1.3.1.3', map => \%map_memory_status }, +}; +my $oid_memEntry = '.1.3.6.1.4.1.10876.100.1.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_memEntry, end => $mapping_memory->{memDeviceStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking memories"); + $self->{components}->{memory} = {name => 'memory', total => 0, skip => 0}; + return if ($self->check_filter(section => 'memory')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_memEntry}})) { + next if ($oid !~ /^$mapping_memory->{memDeviceStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping_memory, results => $self->{results}->{$oid_memEntry}, instance => $instance); + + next if ($self->check_filter(section => 'memory', instance => $instance)); + + $self->{components}->{memory}->{total}++; + $self->{output}->output_add(long_msg => sprintf("memory '%s' status is '%s' [instance = %s]", + $result->{memTag}, + $result->{memDeviceStatus}, $instance)); + + my $exit = $self->get_severity(label => 'default', section => 'memory', value => $result->{memDeviceStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Memory '%s' status is '%s'", $result->{memTag}, $result->{memDeviceStatus})); + } + } +} + +1; + +package hardware::server::supermicro::snmp::mode::components::disk; + +use strict; +use warnings; + +my %map_disk_status = (0 => 'ok', 2 => 'critical', 3 => 'unknown'); + +my $mapping_disk = { + diskName => { oid => '.1.3.6.1.4.1.10876.100.1.4.1.2' }, + diskSmartStatus => { oid => '.1.3.6.1.4.1.10876.100.1.4.1.4', map => \%map_disk_status }, +}; +my $oid_diskEntry = '.1.3.6.1.4.1.10876.100.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_diskEntry, end => $mapping_disk->{diskSmartStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking disks"); + $self->{components}->{disk} = {name => 'disk', total => 0, skip => 0}; + return if ($self->check_filter(section => 'disk')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_diskEntry}})) { + next if ($oid !~ /^$mapping_disk->{diskSmartStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping_disk, results => $self->{results}->{$oid_diskEntry}, instance => $instance); + + next if ($self->check_filter(section => 'disk', instance => $instance)); + + $self->{components}->{memory}->{total}++; + $self->{output}->output_add(long_msg => sprintf("disk '%s' status is '%s' [instance = %s]", + $result->{diskName}, + $result->{diskSmartStatus}, $instance)); + + my $exit = $self->get_severity(label => 'default', section => 'disk', value => $result->{diskSmartStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Disk '%s' status is '%s'", $result->{diskName}, $result->{diskSmartStatus})); + } + } +} + +1; + +package hardware::server::supermicro::snmp::mode::components::cpu; + +use strict; +use warnings; + +my %map_cpu_status = (0 => 'ok', 2 => 'critical'); + +my $mapping_cpu = { + cpuDeviceStatus => { oid => '.1.3.6.1.4.1.10876.100.1.2.1.5', map => \%map_cpu_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping_cpu->{cpuDeviceStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking cpu"); + $self->{components}->{cpu} = {name => 'cpu', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cpu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping_cpu->{cpuDeviceStatus}->{oid}}})) { + $oid =~ /^$mapping_cpu->{cpuDeviceStatus}->{oid}\.(.*)$/; + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping_cpu, results => $self->{results}->{$mapping_cpu->{cpuDeviceStatus}->{oid}}, instance => $instance); + + next if ($self->check_filter(section => 'cpu', instance => $instance)); + + $self->{components}->{cpu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("cpu '%s' status is '%s' [instance = %s]", + $instance, + $result->{cpuDeviceStatus}, $instance)); + + my $exit = $self->get_severity(label => 'default', section => 'cpu', value => $result->{cpuDeviceStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("CPU '%s' status is '%s'", $instance, $result->{cpuDeviceStatus})); + } + } +} + +1; diff --git a/hardware/server/supermicro/snmp/plugin.pm b/hardware/server/supermicro/snmp/plugin.pm new file mode 100644 index 000000000..8748fa04d --- /dev/null +++ b/hardware/server/supermicro/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package hardware::server::supermicro::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'hardware' => 'hardware::server::supermicro::snmp::mode::hardware', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Supermicro servers in SNMP (need SuperDoctor Agent). + +=cut diff --git a/network/alcatel/isam/snmp/mode/components/sfp.pm b/network/alcatel/isam/snmp/mode/components/sfp.pm index d73020bb9..58ea7f679 100644 --- a/network/alcatel/isam/snmp/mode/components/sfp.pm +++ b/network/alcatel/isam/snmp/mode/components/sfp.pm @@ -71,7 +71,7 @@ sub check { $self->{components}->{sfp}->{total}++; $self->{output}->output_add(long_msg => sprintf("sfp '%s' signal status is '%s' [instance = %s]", $name, $result2->{sfpDiagLOS}, $slot_id . '.' . $sfp_faceplate_num)); - $exit = $self->get_severity(section => 'sfp', value => $result2->{sfpDiagLOS}); + $exit = $self->get_severity(section => 'sfp', instance => $slot_id . '.' . $sfp_faceplate_num, value => $result2->{sfpDiagLOS}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("sfp '%s' signal status is '%s'", $name, $result2->{sfpDiagLOS})); @@ -154,4 +154,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/network/alcatel/isam/snmp/mode/hardware.pm b/network/alcatel/isam/snmp/mode/hardware.pm index 0d13abdf0..906cda298 100644 --- a/network/alcatel/isam/snmp/mode/hardware.pm +++ b/network/alcatel/isam/snmp/mode/hardware.pm @@ -97,7 +97,7 @@ If total (with skipped) is 0. (Default: 'critical' returns). Set to overload default threshold values (syntax: section,[instance,]status,regexp) It used before default thresholds (order stays). -Example: --threshold-overload='psu,CRITICAL,^(?!(presentOK)$)' +Example: --threshold-overload='sfp,OK,^los$' =item B<--warning> @@ -111,4 +111,4 @@ Example: --warning='sfp.temperature,1.1,40' =back -=cut \ No newline at end of file +=cut diff --git a/network/checkpoint/snmp/mode/cpu.pm b/network/checkpoint/snmp/mode/cpu.pm index 220e14fce..0232be381 100644 --- a/network/checkpoint/snmp/mode/cpu.pm +++ b/network/checkpoint/snmp/mode/cpu.pm @@ -69,7 +69,7 @@ sub run { my $exit = $self->{perfdata}->threshold_check(value => $totalCpuUsed, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("CPU Usage: %d (System: %d User: %d Idle: %d)", $totalCpuUsed, $result->{$oid_procUsrTime}, $result->{$oid_procSysTime}, $result->{$oid_procIdleTime} )); + short_msg => sprintf("CPU Usage: %d (System: %d User: %d Idle: %d)", $totalCpuUsed, $result->{$oid_procSysTime}, $result->{$oid_procUsrTime}, $result->{$oid_procIdleTime} )); $self->{output}->perfdata_add(label => "cpu", unit => '%', value => $totalCpuUsed, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), diff --git a/network/cisco/asa/mode/failover.pm b/network/cisco/asa/snmp/mode/failover.pm similarity index 99% rename from network/cisco/asa/mode/failover.pm rename to network/cisco/asa/snmp/mode/failover.pm index 2fef70077..287458c5f 100644 --- a/network/cisco/asa/mode/failover.pm +++ b/network/cisco/asa/snmp/mode/failover.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::cisco::asa::mode::failover; +package network::cisco::asa::snmp::mode::failover; use base qw(centreon::plugins::templates::counter); @@ -211,4 +211,4 @@ Can be: 'active-units'. =back =cut - \ No newline at end of file + diff --git a/network/cisco/asa/plugin.pm b/network/cisco/asa/snmp/plugin.pm similarity index 92% rename from network/cisco/asa/plugin.pm rename to network/cisco/asa/snmp/plugin.pm index e86070999..d6dc6df1a 100644 --- a/network/cisco/asa/plugin.pm +++ b/network/cisco/asa/snmp/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::cisco::asa::plugin; +package network::cisco::asa::snmp::plugin; use strict; use warnings; @@ -32,11 +32,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( 'cpu' => 'centreon::common::cisco::standard::snmp::mode::cpu', - 'failover' => 'network::cisco::asa::mode::failover', + 'failover' => 'network::cisco::asa::snmp::mode::failover', 'interfaces' => 'snmp_standard::mode::interfaces', 'ipsec-tunnel' => 'centreon::common::cisco::standard::snmp::mode::ipsectunnel', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', + 'sensors' => 'snmp_standard::mode::entity', 'sessions' => 'centreon::common::cisco::standard::snmp::mode::sessions', ); diff --git a/network/cisco/ironport/snmp/mode/keysexpire.pm b/network/cisco/ironport/snmp/mode/keysexpire.pm new file mode 100644 index 000000000..fe266afca --- /dev/null +++ b/network/cisco/ironport/snmp/mode/keysexpire.pm @@ -0,0 +1,119 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package network::cisco::ironport::snmp::mode::keysexpire; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'keys', type => 1, cb_prefix_output => 'prefix_keys_output', message_multiple => 'All keys are ok' } + ]; + + $self->{maps_counters}->{keys} = [ + { label => 'seconds', set => { + key_values => [ { name => 'seconds' }, { name => 'msg' }, { name => 'display' } ], + output_template => '%s remaining before expiration', + output_use => 'msg_absolute', + closure_custom_perfdata => sub { return 0; }, + } + }, + ]; +} + +sub prefix_keys_output { + my ($self, %options) = @_; + + return "Key '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +my $mapping = { + keyDescription => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.2' }, + keyIsPerpetual => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.3' }, + keySecondsUntilExpire => { oid => '.1.3.6.1.4.1.15497.1.1.1.12.1.4' }, +}; +my $oid_keyExpirationEntry = '.1.3.6.1.4.1.15497.1.1.1.12.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{keys} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_keyExpirationEntry, + nothing_quit => 1); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{keySecondsUntilExpire}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + next if ($result->{keyIsPerpetual} == 1); + + $self->{keys}->{$instance} = { + display => $result->{keyDescription}, + seconds => $result->{keySecondsUntilExpire}, + msg => centreon::plugins::misc::change_seconds(value => $result->{keySecondsUntilExpire}), + }; + } + + if (scalar(keys %{$self->{keys}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No key found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check number of seconds remaining before the expiration of keys. + +=over 8 + +=item B<--warning-seconds> + +Threshold warning in seconds. + +=item B<--critical-seconds> + +Threshold critical in seconds. + +=back + +=cut + diff --git a/network/cisco/ironport/snmp/plugin.pm b/network/cisco/ironport/snmp/plugin.pm index 7b8635c92..0ff3946c1 100644 --- a/network/cisco/ironport/snmp/plugin.pm +++ b/network/cisco/ironport/snmp/plugin.pm @@ -33,6 +33,7 @@ sub new { %{$self->{modes}} = ( 'cpu' => 'network::cisco::ironport::snmp::mode::cpu', 'hardware' => 'network::cisco::ironport::snmp::mode::hardware', + 'keys-expire' => 'network::cisco::ironport::snmp::mode::keysexpire', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::cisco::ironport::snmp::mode::memory', diff --git a/network/fortinet/fortimanager/snmp/mode/devicestatus.pm b/network/fortinet/fortimanager/snmp/mode/devicestatus.pm index 732db8654..2a2cb40b8 100644 --- a/network/fortinet/fortimanager/snmp/mode/devicestatus.pm +++ b/network/fortinet/fortimanager/snmp/mode/devicestatus.pm @@ -45,7 +45,7 @@ sub set_counters { closure_custom_threshold_check => $self->can('custom_status_threshold'), } }, - { label => 'device-connection-status', threshold => 0, set => { + { label => 'device-con-status', threshold => 0, set => { key_values => [ { name => 'fmDeviceEntConnectState' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { output_label => 'Connection Status', name_status => 'fmDeviceEntConnectState' }, diff --git a/os/linux/local/mode/directlvmusage.pm b/os/linux/local/mode/directlvmusage.pm new file mode 100644 index 000000000..0a28bf8da --- /dev/null +++ b/os/linux/local/mode/directlvmusage.pm @@ -0,0 +1,209 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package os::linux::local::mode::directlvmusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'dlvm', type => 1, cb_prefix_output => 'prefix_dlvm_output', message_multiple => 'All direct LVM are ok' } + ]; + + $self->{maps_counters}->{dlvm} = [ + { label => 'data-usage', set => { + key_values => [ { name => 'data' }, { name => 'display' } ], + output_template => 'Data Usage : %.2f %%', + perfdatas => [ + { label => 'data_used', value => 'data_absolute', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'meta-usage', set => { + key_values => [ { name => 'meta' }, { name => 'display' } ], + output_template => 'Meta Usage : %.2f %%', + perfdatas => [ + { label => 'meta_used', value => 'meta_absolute', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_dlvm_output { + my ($self, %options) = @_; + + return "Direct LVM '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "remote" => { name => 'remote' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'lvs' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '--separator="," 2>&1' }, + "filter-lv:s" => { name => 'filter_lv', }, + "filter-vg:s" => { name => 'filter_vg', }, + }); + $self->{result} = {}; + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + no_quit => 1 + ); + $self->{dlvm} = {}; + + # LV,VG,Attr,LSize,Pool,Origin,Data%,Meta%,Move,Log,Cpy%Sync,Convert + # thinpool,docker,twi-aot---,71.25g,,,1.95,0.06,,,, + # lv_controlm,vg_sys,-wi-ao----,5.00g,,,,,,,, + # ... + my @lines = split /\n/, $stdout; + shift @lines; + foreach my $line (@lines) { + my @fields = split /,/, $line; + my ($vg, $lv, $data, $meta) = ($fields[1], $fields[0], $fields[6], $fields[7]); + next if (!defined($data) || $data !~ /[0-9]/); + + my $display = centreon::plugins::misc::trim($vg) . '.' . centreon::plugins::misc::trim($lv); + if (defined($self->{option_results}->{filter_lv}) && $self->{option_results}->{filter_lv} ne '' && + $lv !~ /$self->{option_results}->{filter_lv}/) { + $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_vg}) && $self->{option_results}->{filter_vg} ne '' && + $vg !~ /$self->{option_results}->{filter_vg}/) { + $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1); + next; + } + + $self->{dlvm}->{$display} = { display => $display, data => $data, meta => $meta }; + } + + if (scalar(keys %{$self->{dlvm}}) <= 0) { + if ($exit_code != 0) { + $self->{output}->output_add(long_msg => "command output:" . $stdout); + } + $self->{output}->add_option_msg(short_msg => "No direct lvm found (filters or command issue)"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check directl lvm usage. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'lvs'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '--separator="," 2>&1'). + +=item B<--warning-*> + +Threshold warning. +Can be: 'data-usage' (%), 'meta-usage' (%). + +=item B<--critical-*> + +Threshold critical. +Can be: 'data-usage' (%), 'meta-usage' (%). + +=item B<--filter-vg> + +Filter virtual group (regexp can be used). + +=item B<--filter-lv> + +Filter logical volume (regexp can be used). + +=back + +=cut diff --git a/os/linux/local/plugin.pm b/os/linux/local/plugin.pm index 45216bb80..7b55cde2f 100644 --- a/os/linux/local/plugin.pm +++ b/os/linux/local/plugin.pm @@ -35,6 +35,7 @@ sub new { 'cpu-detailed' => 'os::linux::local::mode::cpudetailed', 'cmd-return' => 'os::linux::local::mode::cmdreturn', 'connections' => 'os::linux::local::mode::connections', + 'directlvm-usage' => 'os::linux::local::mode::directlvmusage', 'diskio' => 'os::linux::local::mode::diskio', 'files-size' => 'os::linux::local::mode::filessize', 'files-date' => 'os::linux::local::mode::filesdate', diff --git a/snmp_standard/mode/entity.pm b/snmp_standard/mode/entity.pm new file mode 100644 index 000000000..de889ac4f --- /dev/null +++ b/snmp_standard/mode/entity.pm @@ -0,0 +1,232 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package snmp_standard::mode::entity; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(sensor\..*)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(sensor\..*)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sensor => [ + ['unavailable', 'OK'], + ['ok', 'OK'], + ['nonoperational', 'WARNING'], + ], + }; + + $self->{components_path} = 'snmp_standard::mode::components'; + $self->{components_module} = ['sensor']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "sensor-scale" => { name => 'sensor_scale' }, + }); + + return $self; +} + +sub snmp_execute { + my ($self, %options) = @_; + + my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7'; + $self->{snmp} = $options{snmp}; + push @{$self->{request}}, { oid => $oid_entPhysicalName}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +1; + +=head1 MODE + +Check entity sensors (ENTITY-SENSOR-MIB). + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'sensor'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=sensor,celsius.* + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='sensor.celsius,OK,nonoperational' + +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='sensor.celsius,.*,30' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='sensor.celsius,.*,40' + +=item B<--sensor-scale> + +Apply scaling value (some equipments are buggy. So we don't use scale by default). + +=back + +=cut + +package snmp_standard::mode::components::sensor; + +use strict; +use warnings; + +my %map_sensor_status = (1 => 'ok', 2 => 'unavailable', 3 => 'nonoperational'); +my %map_sensor_type = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'voltsAC', + 4 => 'voltsDC', + 5 => 'amperes', + 6 => 'watts', + 7 => 'hertz', + 8 => 'celsius', + 9 => 'percentRH', + 10 => 'rpm', + 11 => 'cmm', + 12 => 'truthvalue', + 13 => 'specialEnum', + 14 => 'dBm', +); +my %map_sensor_scale = ( + 1 => -24, # yocto, + 2 => -21, # zepto + 3 => -18, # atto + 4 => -15, # femto + 5 => -12, # pico + 6 => -9, # nano + 7 => -6, # micro + 8 => -3, # milli + 9 => 0, #units + 10 => 3, #kilo + 11 => 6, #mega + 12 => 9, #giga + 13 => 12, #tera + 14 => 18, #exa + 15 => 15, #peta + 16 => 21, #zetta + 17 => 24, #yotta +); +my %perfdata_unit = ('other' => '', 'unknown' => '', 'voltsAC' => 'V', + 'voltsDC' => 'V', 'amperes' => 'A', 'watts' => 'W', + 'hertz' => 'Hz', 'celsius' => 'C', 'percentRH' => '%', + 'rpm' => 'rpm', 'cmm' => '', 'truthvalue' => '', + 'specialEnum' => '', 'dBm' => 'dBm', +); + +my $mapping = { + entPhySensorType => { oid => '.1.3.6.1.2.1.99.1.1.1.1', map => \%map_sensor_type }, + entPhySensorScale => { oid => '.1.3.6.1.2.1.99.1.1.1.2', map => \%map_sensor_scale }, + entPhySensorPrecision => { oid => '.1.3.6.1.2.1.99.1.1.1.3' }, + entPhySensorValue => { oid => '.1.3.6.1.2.1.99.1.1.1.4' }, + entPhySensorOperStatus => { oid => '.1.3.6.1.2.1.99.1.1.1.5', map => \%map_sensor_status }, +}; +my $oid_entPhySensorEntry = '.1.3.6.1.2.1.99.1.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_entPhySensorEntry, end => $mapping->{entPhySensorOperStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking sensors"); + $self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; + return if ($self->check_filter(section => 'sensor')); + + my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7'; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_entPhysicalName}})) { + next if ($oid !~ /^$oid_entPhysicalName\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_entPhySensorEntry}, instance => $instance); + next if (!defined($result->{entPhySensorOperStatus})); + + next if ($self->check_filter(section => 'sensor', instance => $result->{entPhySensorType} . '.' . $instance)); + + my $name = $self->{results}->{$oid_entPhysicalName}->{$oid}; + # It seems there is no scale + if (!defined($self->{option_results}->{sensor_scale})) { + $result->{entPhySensorValue} = defined($result->{entPhySensorValue}) ? + $result->{entPhySensorValue} * (10 ** -($result->{entPhySensorPrecision})) : undef; + } else { + $result->{entPhySensorValue} = defined($result->{entPhySensorValue}) ? + $result->{entPhySensorValue} * (10 ** ($result->{entPhySensorScale}) * (10 ** -($result->{entPhySensorPrecision}))) : undef; + } + + $self->{components}->{sensor}->{total}++; + $self->{output}->output_add(long_msg => sprintf("sensor '%s' status is '%s' [instance = %s, value = %s]", + $name, $result->{entPhySensorOperStatus}, $result->{entPhySensorType} . '.' . $instance, + defined($result->{entPhySensorValue}) ? $result->{entPhySensorValue} : '-')); + my $exit = $self->get_severity(label => 'sensor', section => 'sensor.' . $result->{entPhySensorType}, value => $result->{entPhySensorOperStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor '%s' status is '%s'", $name, $result->{entPhySensorOperStatus})); + } + + next if (!defined($result->{entPhySensorValue}) || $result->{entPhySensorValue} !~ /[0-9]/); + + my $component = 'sensor.' . $result->{entPhySensorType}; + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{entPhySensorValue}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Sensor '%s/%s' is %s %s", $name, $instance, $result->{entPhySensorValue}, $perfdata_unit{$result->{entPhySensorType}})); + } + $self->{output}->perfdata_add(label => $component . '_' . $name, unit => $perfdata_unit{$result->{entPhySensorType}}, + value => $result->{entPhySensorValue}, + warning => $warn, + critical => $crit); + } +} + +1; diff --git a/storage/qsan/nas/snmp/mode/components/fan.pm b/storage/qsan/nas/snmp/mode/components/fan.pm index f6402ee30..b36a959d5 100644 --- a/storage/qsan/nas/snmp/mode/components/fan.pm +++ b/storage/qsan/nas/snmp/mode/components/fan.pm @@ -22,16 +22,16 @@ package storage::qsan::nas::snmp::mode::components::fan; use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); -my $mapping = { - ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, - ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, - ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, - ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, -}; -my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - -sub load {} +sub load { + my ($self) = @_; + + if ($self->{monitor_loaded} == 0) { + storage::qsan::nas::snmp::mode::components::resources::load_monitor(request => $self->{request}); + $self->{monitor_loaded} = 1; + } +} sub check { my ($self) = @_; @@ -41,11 +41,12 @@ sub check { return if ($self->check_filter(section => 'fan')); my ($exit, $warn, $crit, $checked); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_monitorEntry}})) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results_monitor}})) { next if ($oid !~ /^$mapping->{ems_type}->{oid}\.(.*)$/); my $instance = $1; - next if ($self->{results}->{$oid_monitorEntry}->{$oid} !~ /Cooling/i); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_monitorEntry}, instance => $instance); + next if ($self->{results_monitor}->{$oid} !~ /Cooling/i); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_monitor}, instance => $instance); next if ($self->check_filter(section => 'fan', instance => $instance)); @@ -76,4 +77,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/storage/qsan/nas/snmp/mode/components/psu.pm b/storage/qsan/nas/snmp/mode/components/psu.pm index b8f0c663f..c11feb7d8 100644 --- a/storage/qsan/nas/snmp/mode/components/psu.pm +++ b/storage/qsan/nas/snmp/mode/components/psu.pm @@ -22,16 +22,16 @@ package storage::qsan::nas::snmp::mode::components::psu; use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); -my $mapping = { - ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, - ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, - ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, - ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, -}; -my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - -sub load {} +sub load { + my ($self) = @_; + + if ($self->{monitor_loaded} == 0) { + storage::qsan::nas::snmp::mode::components::resources::load_monitor(request => $self->{request}); + $self->{monitor_loaded} = 1; + } +} sub check { my ($self) = @_; @@ -41,12 +41,12 @@ sub check { return if ($self->check_filter(section => 'psu')); my ($exit, $warn, $crit, $checked); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_monitorEntry}})) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results_monitor}})) { next if ($oid !~ /^$mapping->{ems_type}->{oid}\.(.*)$/); my $instance = $1; - next if ($self->{results}->{$oid_monitorEntry}->{$oid} !~ /Power Supply/i); + next if ($self->{results_monitor}->{$oid} !~ /Power Supply/i); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_monitorEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_monitor}, instance => $instance); next if ($self->check_filter(section => 'psu', instance => $instance)); @@ -61,4 +61,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/storage/qsan/nas/snmp/mode/components/resources.pm b/storage/qsan/nas/snmp/mode/components/resources.pm new file mode 100644 index 000000000..2e80e1857 --- /dev/null +++ b/storage/qsan/nas/snmp/mode/components/resources.pm @@ -0,0 +1,47 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# 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. +# + +package storage::qsan::nas::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $mapping; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw($mapping); + +$mapping = { + ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, + ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, + ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, + ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, +}; + +sub load_monitor { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{ems_type}->{oid} }, + { oid => $mapping->{ems_item}->{oid} }, { oid => $mapping->{ems_value}->{oid} }, + { oid => $mapping->{ems_status}->{oid} }; +} + +1; diff --git a/storage/qsan/nas/snmp/mode/components/temperature.pm b/storage/qsan/nas/snmp/mode/components/temperature.pm index 73ca93f44..28d3a3ddd 100644 --- a/storage/qsan/nas/snmp/mode/components/temperature.pm +++ b/storage/qsan/nas/snmp/mode/components/temperature.pm @@ -22,16 +22,16 @@ package storage::qsan::nas::snmp::mode::components::temperature; use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); -my $mapping = { - ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, - ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, - ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, - ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, -}; -my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - -sub load {} +sub load { + my ($self) = @_; + + if ($self->{monitor_loaded} == 0) { + storage::qsan::nas::snmp::mode::components::resources::load_monitor(request => $self->{request}); + $self->{monitor_loaded} = 1; + } +} sub check { my ($self) = @_; @@ -41,12 +41,12 @@ sub check { return if ($self->check_filter(section => 'temperature')); my ($exit, $warn, $crit, $checked); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_monitorEntry}})) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results_monitor}})) { next if ($oid !~ /^$mapping->{ems_type}->{oid}\.(.*)$/); my $instance = $1; - next if ($self->{results}->{$oid_monitorEntry}->{$oid} !~ /Temperature/i); + next if ($self->{results_monitor}->{$oid} !~ /Temperature/i); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_monitorEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_monitor}, instance => $instance); next if ($self->check_filter(section => 'temperature', instance => $instance)); # +72.0 (C) (hyst = +5.0 (C), high = +90.0 (C)) @@ -76,4 +76,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/storage/qsan/nas/snmp/mode/components/voltage.pm b/storage/qsan/nas/snmp/mode/components/voltage.pm index 042cfe84a..62548693e 100644 --- a/storage/qsan/nas/snmp/mode/components/voltage.pm +++ b/storage/qsan/nas/snmp/mode/components/voltage.pm @@ -22,16 +22,16 @@ package storage::qsan::nas::snmp::mode::components::voltage; use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); -my $mapping = { - ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, - ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, - ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, - ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, -}; -my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - -sub load {} +sub load { + my ($self) = @_; + + if ($self->{monitor_loaded} == 0) { + storage::qsan::nas::snmp::mode::components::resources::load_monitor(request => $self->{request}); + $self->{monitor_loaded} = 1; + } +} sub check { my ($self) = @_; @@ -41,12 +41,12 @@ sub check { return if ($self->check_filter(section => 'voltage')); my ($exit, $warn, $crit, $checked); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_monitorEntry}})) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results_monitor}})) { next if ($oid !~ /^$mapping->{ems_type}->{oid}\.(.*)$/); my $instance = $1; - next if ($self->{results}->{$oid_monitorEntry}->{$oid} !~ /Voltage/i); + next if ($self->{results_monitor}->{$oid} !~ /Voltage/i); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_monitorEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_monitor}, instance => $instance); next if ($self->check_filter(section => 'voltage', instance => $instance)); #+0.99 V (min = +0.75 V, max = +1.35 V) @@ -76,4 +76,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/storage/qsan/nas/snmp/mode/hardware.pm b/storage/qsan/nas/snmp/mode/hardware.pm index 577343d44..d86c6be6d 100644 --- a/storage/qsan/nas/snmp/mode/hardware.pm +++ b/storage/qsan/nas/snmp/mode/hardware.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::hardware); use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); sub set_system { my ($self, %options) = @_; @@ -45,6 +46,7 @@ sub set_system { ], }; + $self->{monitor_loaded} = 0; $self->{components_path} = 'storage::qsan::nas::snmp::mode::components'; $self->{components_module} = ['disk', 'voltage', 'temperature', 'psu', 'fan']; } @@ -53,9 +55,11 @@ sub snmp_execute { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; - my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - push @{$self->{request}}, { oid => $oid_monitorEntry }; $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + if ($self->{monitor_loaded} == 1) { + $self->{results_monitor} = { %{$self->{results}->{$mapping->{ems_type}->{oid}}}, %{$self->{results}->{$mapping->{ems_item}->{oid}}}, + %{$self->{results}->{$mapping->{ems_value}->{oid}}}, %{$self->{results}->{$mapping->{ems_status}->{oid}}} }; + } } sub new {