From 75ddaab4b01d60aae4da293a90f1f99be66e2010 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 10:16:37 +0100 Subject: [PATCH 01/35] Add pod_spell_check test and githubaction --- .github/scripts/pod_spell_check.t | 19 +++++++++++++ .github/workflows/spellchecker.yml | 45 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .github/scripts/pod_spell_check.t create mode 100644 .github/workflows/spellchecker.yml diff --git a/.github/scripts/pod_spell_check.t b/.github/scripts/pod_spell_check.t new file mode 100644 index 0000000000..058bd56980 --- /dev/null +++ b/.github/scripts/pod_spell_check.t @@ -0,0 +1,19 @@ +use strict; +use warnings; +use Test::More; + +use Test::Spelling; +use Pod::Wordlist; + +add_stopwords(); +set_spell_cmd('hunspell -L'); # current preferred +# set_spell_cmd('aspell list'); +# set_spell_cmd('spell'); +# set_spell_cmd('ispell -l'); +my $cmd = has_working_spellchecker; +printf($cmd."\n"); +all_pod_files_spelling_ok( $ARGV[0]); + +__DATA__ +SNMP +SSH \ No newline at end of file diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml new file mode 100644 index 0000000000..31bf4c19de --- /dev/null +++ b/.github/workflows/spellchecker.yml @@ -0,0 +1,45 @@ +name: spell-checker + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +on: + workflow_dispatch: + pull_request: + paths: + - '.github/workflows/spellchecker.yml' + - 'src/**' + - '.github/scripts/pod_spell_check.t' + +jobs: + pod-spell-check: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + + - uses: dorny/paths-filter@v2 + id: filter + with: + base: ${{ github.ref }} + list-files: shell + filters: | + plugins: + - added|modified: src/** + + - name: Install Libraries + uses: shogo82148/actions-setup-perl@v1 + with: + perl-version: '5.34' + install-modules-with: cpm + install-modules: Test::More Test::Spelling Pod::Wordlist + + - name: Run spell check + run: | + apt-get install -y hunspell aspell spell ispell + for f in ${{ steps.filter.outputs.packages_files }}; do + perl .github/scripts/pod_spell_check.t $f + done + + shell: bash \ No newline at end of file From c67fc0ef4d829da3edff0f72b9ace087378accca Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 10:19:54 +0100 Subject: [PATCH 02/35] wip --- .github/workflows/spellchecker.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 31bf4c19de..897bb8d04d 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -41,5 +41,4 @@ jobs: for f in ${{ steps.filter.outputs.packages_files }}; do perl .github/scripts/pod_spell_check.t $f done - - shell: bash \ No newline at end of file + shell: bash From f630da47716e81dfdf5f444e1290db6c97ac1ac0 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 10:21:08 +0100 Subject: [PATCH 03/35] wip --- .github/workflows/spellchecker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 897bb8d04d..8b89dbe477 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -37,7 +37,7 @@ jobs: - name: Run spell check run: | - apt-get install -y hunspell aspell spell ispell + sudo apt-get install -y hunspell aspell spell ispell for f in ${{ steps.filter.outputs.packages_files }}; do perl .github/scripts/pod_spell_check.t $f done From 2c005e84e03d5c43bb864b88233ccf1d44254da9 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 10:28:55 +0100 Subject: [PATCH 04/35] add fake plugins change --- src/centreon/plugins/output_corrupted.pm | 1671 +++++++++++++++++ src/os/as400/connector/mode/jobs_corrupted.pm | 134 ++ src/snmp_standard/mode/ntp_corrupted.pm | 228 +++ 3 files changed, 2033 insertions(+) create mode 100644 src/centreon/plugins/output_corrupted.pm create mode 100644 src/os/as400/connector/mode/jobs_corrupted.pm create mode 100644 src/snmp_standard/mode/ntp_corrupted.pm diff --git a/src/centreon/plugins/output_corrupted.pm b/src/centreon/plugins/output_corrupted.pm new file mode 100644 index 0000000000..264f4876bf --- /dev/null +++ b/src/centreon/plugins/output_corrupted.pm @@ -0,0 +1,1671 @@ +# +# Copyright 2023 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 centreon::plugins::output; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{options})) { + print "Class Output: Need to specify 'options' argument to load.\n"; + exit 3; + } + + $options{options}->add_options(arguments => { + 'explode-perfdata-max:s@' => { name => 'explode_perfdata_max' }, + 'range-perfdata:s' => { name => 'range_perfdata' }, + 'filter-perfdata:s' => { name => 'filter_perfdata' }, + 'filter-perfdata-adv:s' => { name => 'filter_perfdata_adv' }, + 'change-perfdata:s@' => { name => 'change_perfdata' }, + 'extend-perfdata:s@' => { name => 'extend_perfdata' }, + 'extend-perfdata-group:s@'=> { name => 'extend_perfdata_group' }, + 'change-exit:s@' => { name => 'change_exit' }, + 'change-short-output:s@' => { name => 'change_short_output' }, + 'change-long-output:s@' => { name => 'change_long_output' }, + 'use-new-perfdata' => { name => 'use_new_perfdata' }, + 'filter-uom:s' => { name => 'filter_uom' }, + 'verbose' => { name => 'verbose' }, + 'debug' => { name => 'debug' }, + 'debug-stream' => { name => 'debug_stream' }, + 'opt-exit:s' => { name => 'opt_exit', default => 'unknown' }, + 'output-xml' => { name => 'output_xml' }, + 'output-json' => { name => 'output_json' }, + 'output-ignore-perfdata' => { name => 'output_ignore_perfdata' }, + 'output-ignore-label' => { name => 'output_ignore_label' }, + 'output-openmetrics' => { name => 'output_openmetrics' }, + 'output-file:s' => { name => 'output_file' }, + 'disco-format' => { name => 'disco_format' }, + 'disco-show' => { name => 'disco_show' }, + 'float-precision:s' => { name => 'float_precision', default => 8 }, + 'source-encoding:s' => { name => 'source_encoding' , default => 'UTF-8' } + }); + + $self->{option_results} = {}; + + $self->{option_msg} = []; + + $self->{nodisplay} = 0; + $self->{noexit_die} = 0; + + $self->{is_output_xml} = 0; + $self->{is_output_json} = 0; + $self->{errors} = {OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, PENDING => 4}; + $self->{errors_num} = {0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN', 4 => 'PENDING'}; + $self->{myerrors} = {0 => "OK", 1 => "WARNING", 3 => "UNKNOWN", 7 => "CRITICAL"}; + $self->{myerrors_mask} = {CRITICAL => 7, WARNING => 1, UNKNOWN => 3, OK => 0}; + $self->{global_short_concat_outputs} = {OK => undef, WARNING => undef, CRITICAL => undef, UNKNOWN => undef, UNQUALIFIED_YET => undef}; + $self->{global_short_outputs} = {OK => [], WARNING => [], CRITICAL => [], UNKNOWN => [], UNQUALIFIED_YET => []}; + $self->{global_long_output} = []; + $self->{perfdatas} = []; + $self->{explode_perfdatas} = {}; + $self->{change_perfdata} = {}; + $self->{explode_perfdata_total} = 0; + $self->{range_perfdata} = 0; + $self->{global_status} = 0; + $self->{encode_import} = 0; + $self->{perlqq} = 0; + $self->{safe_test} = 0; + + $self->{disco_elements} = []; + $self->{disco_entries} = []; + + $self->{plugin} = ''; + $self->{mode} = ''; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + # $options{option_results} = ref to options result + + %{$self->{option_results}} = %{$options{option_results}}; + $self->{option_results}->{opt_exit} = lc($self->{option_results}->{opt_exit}); + if (!$self->is_litteral_status(status => $self->{option_results}->{opt_exit})) { + $self->add_option_msg(short_msg => "Unknown value '" . $self->{option_results}->{opt_exit} . "' for --opt-exit."); + $self->option_exit(exit_litteral => 'unknown'); + } + # Go in XML Mode + if ($self->is_disco_show() || $self->is_disco_format()) { + # By Default XML + if (!defined($self->{option_results}->{output_json})) { + $self->{option_results}->{output_xml} = 1; + } + } + + if (defined($self->{option_results}->{range_perfdata})) { + $self->{range_perfdata} = $self->{option_results}->{range_perfdata}; + $self->{range_perfdata} = 1 if ($self->{range_perfdata} eq ''); + if ($self->{range_perfdata} !~ /^[012]$/) { + $self->add_option_msg(short_msg => "Wrong range-perfdata option '" . $self->{range_perfdata} . "'"); + $self->option_exit(); + } + } + + if (defined($self->{option_results}->{change_exit})) { + $self->{change_exit} = {}; + foreach (@{$self->{option_results}->{change_exit}}) { + my ($src, $dst) = split(/=/); + next if (!defined($src) || !defined($self->{errors}->{ uc($src) })); + next if (!defined($dst) || !defined($self->{errors}->{ uc($dst) })); + $self->{change_exit}->{uc($src)} = uc($dst); + } + } + + if (defined($self->{option_results}->{explode_perfdata_max})) { + if (${$self->{option_results}->{explode_perfdata_max}}[0] eq '') { + $self->{explode_perfdata_total} = 2; + } else { + $self->{explode_perfdata_total} = 1; + foreach (@{$self->{option_results}->{explode_perfdata_max}}) { + my ($perf_match, $perf_result) = split /,/; + if (!defined($perf_result)) { + $self->add_option_msg(short_msg => "Wrong explode-perfdata-max option '" . $_ . "' (syntax: match,value)"); + $self->option_exit(); + } + $self->{explode_perfdatas}->{$perf_match} = $perf_result; + } + } + } + + if (defined($self->{option_results}->{filter_perfdata_adv}) && $self->{option_results}->{filter_perfdata_adv} ne '') { + $self->{option_results}->{filter_perfdata_adv} =~ s/%\{(.*?)\}/\$values->{$1}/g; + $self->{option_results}->{filter_perfdata_adv} =~ s/%\((.*?)\)/\$values->{$1}/g; + $self->{option_results}->{filter_perfdata_adv} =~ s/alert_triggered\(\)/alert_triggered\(%\$values\)/g; + } + + $self->load_perfdata_extend_args(); + $self->{option_results}->{use_new_perfdata} = 1 if (defined($self->{option_results}->{output_openmetrics})); + + $self->{source_encoding} = (!defined($self->{option_results}->{source_encoding}) || $self->{option_results}->{source_encoding} eq '') ? + 'UTF-8' : $self->{option_results}->{source_encoding}; +} + +sub add_option_msg { + my ($self, %options) = @_; + # $options{short_msg} = string msg + # $options{long_msg} = string msg + $options{severity} = 'UNQUALIFIED_YET'; + + $self->output_add(%options); +} + +sub set_ignore_label { + my ($self, %options) = @_; + + $self->{option_results}->{output_ignore_label} = 1; +} + +sub set_status { + my ($self, %options) = @_; + # $options{exit_litteral} = string litteral exit + + # Nothing to do for 'UNQUALIFIED_YET' + if (!$self->{myerrors_mask}->{uc($options{exit_litteral})}) { + return ; + } + $self->{global_status} |= $self->{myerrors_mask}->{uc($options{exit_litteral})}; +} + +sub output_add { + my ($self, %params) = @_; + my %args = ( + severity => 'OK', + separator => ' - ', + debug => 0, + short_msg => undef, + long_msg => undef, + ); + my $options = { %args, %params }; + + if (defined($options->{short_msg})) { + chomp $options->{short_msg}; + if (defined($self->{global_short_concat_outputs}->{uc($options->{severity})})) { + $self->{global_short_concat_outputs}->{uc($options->{severity})} .= $options->{separator} . $options->{short_msg}; + } else { + $self->{global_short_concat_outputs}->{uc($options->{severity})} = $options->{short_msg}; + } + + push @{$self->{global_short_outputs}->{uc($options->{severity})}}, $options->{short_msg}; + $self->set_status(exit_litteral => $options->{severity}); + } + if (defined($options->{long_msg})) { + chomp $options->{long_msg}; + + push @{$self->{global_long_output}}, $options->{long_msg} if ($options->{debug} == 0 || defined($self->{option_results}->{debug})); + print $options->{long_msg} . "\n" if (defined($self->{option_results}->{debug_stream})); + } +} + +sub perfdata_add { + my ($self, %options) = @_; + + my $perfdata = { + label => '', value => '', unit => '', warning => '', critical => '', min => '', max => '', mode => $self->{mode} + }; + foreach (keys %options) { + next if (!defined($options{$_})); + $perfdata->{$_} = $options{$_}; + } + + if ((defined($self->{option_results}->{use_new_perfdata}) || defined($options{force_new_perfdata})) && + defined($options{nlabel})) { + $perfdata->{label} = $options{nlabel}; + } + if (defined($options{instances})) { + $options{instances} = [$options{instances}] if (!ref($options{instances})); + my ($external_instance_separator, $internal_instance_separator) = ('#', '~'); + if (defined($self->{option_results}->{use_new_perfdata}) || defined($options{force_new_perfdata})) { + $perfdata->{label} = join('~', @{$options{instances}}) . '#' . $perfdata->{label}; + } else { + $perfdata->{label} .= '_' . join('_', @{$options{instances}}); + } + } + + $perfdata->{label} =~ s/'/''/g; + push @{$self->{perfdatas}}, $perfdata; +} + +sub filter_perfdata { + my ($self, %options) = @_; + + return 1 if ( + defined($self->{option_results}->{filter_perfdata}) && + $options{perf}->{label} !~ /$self->{option_results}->{filter_perfdata}/ + ); + + return 1 if ( + defined($self->{option_results}->{filter_perfdata_adv}) && + $self->{option_results}->{filter_perfdata_adv} ne '' && + !$self->test_eval(test => $self->{option_results}->{filter_perfdata_adv}, values => $options{perf}) + ); + + return 0; +} + +sub range_perfdata { + my ($self, %options) = @_; + + return if ($self->{range_perfdata} == 0); + if ($self->{range_perfdata} == 1) { + for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) { + ${${$options{ranges}}[$i]} =~ s/^(@?)-?[0\.]+:/$1/; + } + } else { + for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) { + ${${$options{ranges}}[$i]} = ''; + } + } +} + +sub output_json { + my ($self, %options) = @_; + my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; + my $json_content = { + plugin => { + name => $self->{plugin}, + mode => $self->{mode}, + exit => $options{exit_litteral}, + outputs => [], + perfdatas => [] + } + }; + + foreach my $code_litteral (keys %{$self->{global_short_outputs}}) { + foreach (@{$self->{global_short_outputs}->{$code_litteral}}) { + my ($child_output, $child_type, $child_msg, $child_exit); + my $lcode_litteral = ($code_litteral eq 'UNQUALIFIED_YET' ? uc($options{exit_litteral}) : $code_litteral); + + push @{$json_content->{plugin}->{outputs}}, { + type => 1, + msg => ($options{nolabel} == 0 ? ($lcode_litteral . ': ') : '') . $_, + exit => $lcode_litteral + }; + } + } + + if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { + foreach (@{$self->{global_long_output}}) { + push @{$json_content->{plugin}->{outputs}}, { + type => 2, + msg => $_ + }; + } + } + + if ($options{force_ignore_perfdata} == 0) { + $self->change_perfdata(); + foreach my $perf (@{$self->{perfdatas}}) { + next if ($self->filter_perfdata(perf => $perf)); + $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]); + + my %values = (); + foreach my $key (keys %$perf) { + $perf->{$key} = '' if (defined($self->{option_results}->{filter_uom}) && $key eq 'unit' && + $perf->{$key} !~ /$self->{option_results}->{filter_uom}/); + $values{$key} = $perf->{$key}; + } + + push @{$json_content->{plugin}->{perfdatas}}, { + %values + }; + } + } + + print $self->{json_output}->encode($json_content); +} + +sub output_xml { + my ($self, %options) = @_; + my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; + my ($child_plugin_name, $child_plugin_mode, $child_plugin_exit, $child_plugin_output, $child_plugin_perfdata); + + my $root = $self->{xml_output}->createElement('plugin'); + $self->{xml_output}->setDocumentElement($root); + + $child_plugin_name = $self->{xml_output}->createElement('name'); + $child_plugin_name->appendText($self->{plugin}); + + $child_plugin_mode = $self->{xml_output}->createElement('mode'); + $child_plugin_mode->appendText($self->{mode}); + + $child_plugin_exit = $self->{xml_output}->createElement('exit'); + $child_plugin_exit->appendText($options{exit_litteral}); + + $child_plugin_output = $self->{xml_output}->createElement('outputs'); + $child_plugin_perfdata = $self->{xml_output}->createElement('perfdatas'); + + $root->addChild($child_plugin_name); + $root->addChild($child_plugin_mode); + $root->addChild($child_plugin_exit); + $root->addChild($child_plugin_output); + $root->addChild($child_plugin_perfdata); + + foreach my $code_litteral (keys %{$self->{global_short_outputs}}) { + foreach (@{$self->{global_short_outputs}->{$code_litteral}}) { + my ($child_output, $child_type, $child_msg, $child_exit); + my $lcode_litteral = ($code_litteral eq 'UNQUALIFIED_YET' ? uc($options{exit_litteral}) : $code_litteral); + + $child_output = $self->{xml_output}->createElement('output'); + $child_plugin_output->addChild($child_output); + + $child_type = $self->{xml_output}->createElement('type'); + $child_type->appendText(1); # short + + $child_msg = $self->{xml_output}->createElement('msg'); + $child_msg->appendText(($options{nolabel} == 0 ? ($lcode_litteral . ': ') : '') . $_); + $child_exit = $self->{xml_output}->createElement('exit'); + $child_exit->appendText($lcode_litteral); + + $child_output->addChild($child_type); + $child_output->addChild($child_exit); + $child_output->addChild($child_msg); + } + } + + if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { + foreach (@{$self->{global_long_output}}) { + my ($child_output, $child_type, $child_msg); + + $child_output = $self->{xml_output}->createElement('output'); + $child_plugin_output->addChild($child_output); + + $child_type = $self->{xml_output}->createElement('type'); + $child_type->appendText(2); # long + + $child_msg = $self->{xml_output}->createElement('msg'); + $child_msg->appendText($_); + + $child_output->addChild($child_type); + $child_output->addChild($child_msg); + } + } + + if ($options{force_ignore_perfdata} == 0) { + $self->change_perfdata(); + foreach my $perf (@{$self->{perfdatas}}) { + next if ($self->filter_perfdata(perf => $perf)); + $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]); + + my ($child_perfdata); + $child_perfdata = $self->{xml_output}->createElement('perfdata'); + $child_plugin_perfdata->addChild($child_perfdata); + foreach my $key (keys %$perf) { + $perf->{$key} = '' if (defined($self->{option_results}->{filter_uom}) && $key eq 'unit' && + $perf->{$key} !~ /$self->{option_results}->{filter_uom}/); + my $child = $self->{xml_output}->createElement($key); + $child->appendText($perf->{$key}); + $child_perfdata->addChild($child); + } + } + } + + print $self->{xml_output}->toString(1); +} + +sub output_openmetrics { + my ($self, %options) = @_; + + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => 'Time::HiRes', + error_msg => "Cannot load module 'Time::HiRes'." + ); + + my $time_ms = int(Time::HiRes::time() * 1000); + $self->change_perfdata(); + + foreach my $perf (@{$self->{perfdatas}}) { + next if ($self->filter_perfdata(perf => $perf)); + + $perf->{unit} = '' if ( + defined($self->{option_results}->{filter_uom}) && + $perf->{unit} !~ /$self->{option_results}->{filter_uom}/ + ); + $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]); + my $label = $perf->{label}; + my $instance; + if ($label =~ /^(.*?)#(.*)$/) { + ($perf->{instance}, $label) = ($1, $2); + } + my ($bucket, $append) = ('{plugin="' . $self->{plugin} . '",mode="' . $perf->{mode} . '"', ''); + foreach ('unit', 'warning', 'critical', 'min', 'max', 'instance') { + if (defined($perf->{$_}) && $perf->{$_} ne '') { + $bucket .= ',' . $_ . '="' . $perf->{$_} . '"'; + } + } + $bucket .= '}'; + + print $label . $bucket . ' ' . $perf->{value} . ' ' . $time_ms . "\n"; + } +} + +sub output_txt_short_display { + my ($self, %options) = @_; + + if (defined($self->{global_short_concat_outputs}->{CRITICAL})) { + print (($options{nolabel} == 0 ? 'CRITICAL: ' : '') . $self->{global_short_concat_outputs}->{CRITICAL} . " "); + } + if (defined($self->{global_short_concat_outputs}->{WARNING})) { + print (($options{nolabel} == 0 ? 'WARNING: ' : '') . $self->{global_short_concat_outputs}->{WARNING} . " "); + } + if (defined($self->{global_short_concat_outputs}->{UNKNOWN})) { + print (($options{nolabel} == 0 ? 'UNKNOWN: ' : '') . $self->{global_short_concat_outputs}->{UNKNOWN} . " "); + } + if (uc($options{exit_litteral}) eq 'OK') { + print (($options{nolabel} == 0 ? 'OK: ' : '') . (defined($self->{global_short_concat_outputs}->{OK}) ? $self->{global_short_concat_outputs}->{OK} : '') . " "); + } +} + +sub output_txt_short { + my ($self, %options) = @_; + + if (!defined($self->{option_results}->{change_short_output})) { + $self->output_txt_short_display(%options); + return ; + } + + my $stdout = ''; + { + local *STDOUT; + open STDOUT, '>', \$stdout; + $self->output_txt_short_display(%options); + } + + foreach (@{$self->{option_results}->{change_short_output}}) { + my ($pattern, $replace, $modifier) = split /~/; + next if (!defined($pattern)); + $replace = '' if (!defined($replace)); + $modifier = '' if (!defined($modifier)); + eval "\$stdout =~ s{$pattern}{$replace}$modifier"; + } + + print $stdout; +} + +sub output_txt { + my ($self, %options) = @_; + my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; + + return if ($self->{nodisplay} == 1); + if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) { + $self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET}); + } + + $self->output_txt_short(%options); + + if ($force_ignore_perfdata == 0) { + my $pipe = 0; + $self->change_perfdata(); + foreach my $perf (@{$self->{perfdatas}}) { + next if ($self->filter_perfdata(perf => $perf)); + $perf->{unit} = '' if (defined($self->{option_results}->{filter_uom}) && + $perf->{unit} !~ /$self->{option_results}->{filter_uom}/); + $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]); + if ($pipe == 0) { + print '|'; + $pipe = 1; + } + print " '" . $perf->{label} . "'=" . $perf->{value} . $perf->{unit} . ';' . $perf->{warning} . ';' . $perf->{critical} . ';' . $perf->{min} . ';' . $perf->{max}; + } + } + + print "\n"; + + if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { + if (scalar(@{$self->{global_long_output}})) { + print join("\n", @{$self->{global_long_output}}); + print "\n"; + } + } +} + +sub change_long_output { + my ($self, %options) = @_; + + return if (!(defined($self->{option_results}->{verbose}) || $options{force_long_output} == 1)); + return if (!defined($self->{option_results}->{change_long_output})); + + my $long_output = join("\n", @{$self->{global_long_output}}); + + foreach (@{$self->{option_results}->{change_long_output}}) { + my ($pattern, $replace, $modifier) = split /~/; + next if (!defined($pattern)); + $replace = '' if (!defined($replace)); + $modifier = '' if (!defined($modifier)); + eval "\$long_output =~ s{$pattern}{$replace}$modifier"; + } + + $self->{global_long_output} = [split(/\n/, $long_output)]; +} + +sub display { + my ($self, %options) = @_; + my $nolabel = (defined($options{nolabel}) || defined($self->{option_results}->{output_ignore_label})) ? 1 : 0; + my $force_ignore_perfdata = ((defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) || $self->{option_results}->{output_ignore_perfdata}) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; + $force_long_output = 1 if (defined($self->{option_results}->{debug})); + + if (defined($self->{option_results}->{output_openmetrics})) { + $self->perfdata_add(nlabel => 'plugin.mode.status', value => $self->{errors}->{$self->{myerrors}->{$self->{global_status}}}); + } + + if (defined($self->{option_results}->{change_long_output})) { + $self->change_long_output(force_long_output => $force_long_output); + } + + return if ($self->{nodisplay} == 1); + + if (defined($self->{option_results}->{output_file})) { + if (!open (STDOUT, '>', $self->{option_results}->{output_file})) { + $self->output_add( + severity => 'UNKNOWN', + short_msg => "cannot open file '" . $self->{option_results}->{output_file} . "': $!" + ); + } + } + if (defined($self->{option_results}->{output_xml})) { + $self->create_xml_document(); + if ($self->{is_output_xml}) { + $self->output_xml( + exit_litteral => $self->get_litteral_status(), + nolabel => $nolabel, + force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output + ); + return ; + } + } elsif (defined($self->{option_results}->{output_json})) { + $self->create_json_document(); + if ($self->{is_output_json}) { + $self->output_json( + exit_litteral => $self->get_litteral_status(), + nolabel => $nolabel, + force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output + ); + return ; + } + } elsif (defined($self->{option_results}->{output_openmetrics})) { + $self->output_openmetrics(); + return ; + } + + $self->output_txt( + exit_litteral => $self->get_litteral_status(), + nolabel => $nolabel, + force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output + ); +} + +sub die_exit { + my ($self, %options) = @_; + # $options{exit_litteral} = string litteral exit + # $options{nolabel} = interger label display + my $exit_litteral = defined($options{exit_litteral}) ? $options{exit_litteral} : $self->{option_results}->{opt_exit}; + my $nolabel = (defined($options{nolabel}) || defined($self->{option_results}->{output_ignore_label})) ? 1 : 0; + # ignore long output in the following case + $self->{option_results}->{verbose} = undef; + + if (defined($self->{option_results}->{output_xml})) { + $self->create_xml_document(); + if ($self->{is_output_xml}) { + $self->output_xml(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1); + $self->exit(exit_litteral => $exit_litteral); + } + } elsif (defined($self->{option_results}->{output_json})) { + $self->create_json_document(); + if ($self->{is_output_json}) { + $self->output_json(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1); + $self->exit(exit_litteral => $exit_litteral); + } + } + + $self->output_txt(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1); + $self->exit(exit_litteral => $exit_litteral); +} + +sub option_exit { + my ($self, %options) = @_; + # $options{exit_litteral} = string litteral exit + # $options{nolabel} = interger label display + my $exit_litteral = defined($options{exit_litteral}) ? $options{exit_litteral} : $self->{option_results}->{opt_exit}; + my $nolabel = (defined($options{nolabel}) || defined($self->{option_results}->{output_ignore_label})) ? 1 : 0; + + if (defined($self->{option_results}->{output_xml})) { + $self->create_xml_document(); + if ($self->{is_output_xml}) { + $self->output_xml(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1); + $self->exit(exit_litteral => $exit_litteral); + } + } elsif (defined($self->{option_results}->{output_json})) { + $self->create_json_document(); + if ($self->{is_output_json}) { + $self->output_json(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1); + $self->exit(exit_litteral => $exit_litteral); + } + } elsif (defined($self->{option_results}->{output_openmetrics})) { + $self->set_status(exit_litteral => $exit_litteral); + $self->output_openmetrics(); + $self->exit(exit_litteral => $exit_litteral); + } + + $self->output_txt(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1); + $self->exit(exit_litteral => $exit_litteral); +} + +sub exit { + my ($self, %options) = @_; + + if ($self->{noexit_die} == 1) { + die 'exit'; + } + + my $exit; + if (defined($options{exit_litteral})) { + $exit = uc($options{exit_litteral}); + } else { + $exit = $self->{myerrors}->{ $self->{global_status} }; + } + if (defined($self->{change_exit}) && defined($self->{change_exit}->{$exit})) { + $exit = $self->{change_exit}->{$exit}; + } + exit $self->{errors}->{$exit}; +} + +sub get_option { + my ($self, %options) = @_; + + return $self->{option_results}->{$options{option}}; +} + +sub get_most_critical { + my ($self, %options) = @_; + my $current_status = 0; # For 'OK' + + foreach (@{$options{status}}) { + if ($self->{myerrors_mask}->{uc($_)} > $current_status) { + $current_status = $self->{myerrors_mask}->{uc($_)}; + } + } + return $self->{myerrors}->{$current_status}; +} + +sub get_litteral_status { + my ($self, %options) = @_; + + if (defined($options{status})) { + if (defined($self->{errors_num}->{$options{status}})) { + return $self->{errors_num}->{$options{status}}; + } + return $options{status}; + } else { + return $self->{myerrors}->{$self->{global_status}}; + } +} + +sub is_status { + my ($self, %options) = @_; + # $options{value} = string status + # $options{litteral} = value is litteral + # $options{compare} = string status + + if (defined($options{litteral})) { + my $value = defined($options{value}) ? $options{value} : $self->get_litteral_status(); + + if (uc($value) eq uc($options{compare})) { + return 1; + } + return 0; + } + + my $value = defined($options{value}) ? $options{value} : $self->{global_status}; + my $dec_val = $self->{myerrors_mask}->{$value}; + my $lresult = $value & $dec_val; + # Need to manage 0 + if ($lresult > 0 || ($dec_val == 0 && $value == 0)) { + return 1; + } + return 0; +} + +sub is_litteral_status { + my ($self, %options) = @_; + # $options{status} = string status + + if (defined($self->{errors}->{uc($options{status})})) { + return 1; + } + + return 0; +} + +sub create_json_document { + my ($self) = @_; + + if (centreon::plugins::misc::mymodule_load( + no_quit => 1, module => 'JSON', + error_msg => "Cannot load module 'JSON'.") + ) { + print "Cannot load module 'JSON'\n"; + $self->exit(exit_litteral => 'unknown'); + } + $self->{is_output_json} = 1; + $self->{json_output} = JSON->new->utf8(); +} + +sub create_xml_document { + my ($self) = @_; + + if (centreon::plugins::misc::mymodule_load( + no_quit => 1, module => 'XML::LibXML', + error_msg => "Cannot load module 'XML::LibXML'.") + ) { + print "Cannot load module 'XML::LibXML'\n"; + $self->exit(exit_litteral => 'unknown'); + } + $self->{is_output_xml} = 1; + $self->{xml_output} = XML::LibXML::Document->new('1.0', 'utf-8'); +} + +sub plugin { + my ($self, %options) = @_; + # $options{name} = string name + + if (defined($options{name})) { + $self->{plugin} = $options{name}; + } + return $self->{plugin}; +} + +sub mode { + my ($self, %options) = @_; + + if (defined($options{name})) { + $self->{mode} = $options{name}; + } + return $self->{mode}; +} + +sub add_disco_format { + my ($self, %options) = @_; + + push @{$self->{disco_elements}}, @{$options{elements}}; +} + +sub display_disco_format { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{output_xml})) { + $self->create_xml_document(); + + my $root = $self->{xml_output}->createElement('data'); + $self->{xml_output}->setDocumentElement($root); + + foreach (@{$self->{disco_elements}}) { + my $child = $self->{xml_output}->createElement("element"); + $child->appendText($_); + $root->addChild($child); + } + + print $self->{xml_output}->toString(1); + } elsif (defined($self->{option_results}->{output_json})) { + $self->create_json_document(); + my $json_content = {data => [] }; + foreach (@{$self->{disco_elements}}) { + push @{$json_content->{data}}, $_; + } + + print $self->{json_output}->encode($json_content); + } +} + +sub display_disco_show { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{output_xml})) { + $self->create_xml_document(); + + my $root = $self->{xml_output}->createElement('data'); + $self->{xml_output}->setDocumentElement($root); + + foreach (@{$self->{disco_entries}}) { + my $child = $self->{xml_output}->createElement('label'); + foreach my $key (keys %$_) { + $child->setAttribute($key, $_->{$key}); + } + $root->addChild($child); + } + + print $self->{xml_output}->toString(1); + } elsif (defined($self->{option_results}->{output_json})) { + $self->create_json_document(); + my $json_content = {data => [] }; + foreach (@{$self->{disco_entries}}) { + my %values = (); + foreach my $key (keys %$_) { + $values{$key} = $_->{$key}; + } + push @{$json_content->{data}}, {%values}; + } + + print $self->{json_output}->encode($json_content); + } +} + +sub decode { + my ($self, $value) = @_; + + if ($self->{encode_import} == 0) { + # Some Perl version dont have the following module (like Perl 5.6.x) + my $rv = centreon::plugins::misc::mymodule_load( + no_quit => 1, + module => 'Encode', + error_msg => "Cannot load module 'Encode'." + ); + return $value if ($rv); + + $self->{encode_import} = 1; + eval '$self->{perlqq} = Encode::PERLQQ'; + } + + return centreon::plugins::misc::trim(Encode::decode($self->{source_encoding}, $value, $self->{perlqq})); +} + +sub parameter { + my ($self, %options) = @_; + + if (defined($options{attr})) { + $self->{$options{attr}} = $options{value}; + } + return $self->{$options{attr}}; +} + +sub add_disco_entry { + my ($self, %options) = @_; + + push @{$self->{disco_entries}}, {%options}; +} + +sub is_disco_format { + my ($self) = @_; + + if (defined($self->{option_results}->{disco_format})) { + return 1; + } + return 0; +} + +sub is_disco_show { + my ($self) = @_; + + if (defined($self->{option_results}->{disco_show})) { + return 1; + } + return 0; +} + +sub is_verbose { + my ($self) = @_; + + if (defined($self->{option_results}->{verbose})) { + return 1; + } + return 0; +} + +sub is_debug { + my ($self) = @_; + + if (defined($self->{option_results}->{debug}) || defined($self->{option_results}->{debug_stream})) { + return 1; + } + return 0; +} + +sub load_eval { + my ($self) = @_; + + my ($code) = centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => 'Safe', + no_quit => 1 + ); + if ($code == 0) { + $self->{safe} = Safe->new(); + $self->{safe}->share('$values'); + $self->{safe}->share('$assign_var'); + $self->{safe}->share_from('centreon::plugins::misc', ['alert_triggered']); + } + + $self->{safe_test} = 1; +} + +sub test_eval { + my ($self, %options) = @_; + + $self->load_eval() if ($self->{safe_test} == 0); + + my $result; + if (defined($self->{safe})) { + our $values = $options{values}; + $result = $self->{safe}->reval($options{test}, 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } + } elsif (defined($options{values})) { + my $values = $options{values}; + { + local $SIG{__WARN__} = sub {}; # ignore + + $result = eval "$options{test}"; + if ($@) { + die 'Code evaluation error: ' . $@; + } + } + } + + return $result; +} + +sub open_eval { + my ($self, %options) = @_; + + $self->load_eval() if ($self->{safe_test} == 0); + our $values = $options{values}; + $self->{safe}->reval("$options{eval}", 1); + + return $values; +} + +sub assign_eval { + my ($self, %options) = @_; + + $self->load_eval() if ($self->{safe_test} == 0); + + our $assign_var; + if (defined($self->{safe})) { + our $values = $options{values}; + $self->{safe}->reval("\$assign_var = $options{eval}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } + } else { + my $values = $options{values}; + eval "\$assign_var = $options{eval}"; + } + + return $assign_var; +} + +sub use_new_perfdata { + my ($self, %options) = @_; + + $self->{option_results}->{use_new_perfdata} = $options{value} + if (defined($options{value})); + if (defined($self->{option_results}->{use_new_perfdata})) { + return 1; + } + return 0; +} + +sub get_instance_perfdata_separator { + my ($self) = @_; + + if (defined($self->{option_results}->{use_new_perfdata})) { + return '~'; + } + return '_'; +} + +sub parse_pfdata_scale { + my ($self, %options) = @_; + + # --extend-perfdata=traffic_in,,scale(Mbps),mbps + my $args = { unit => 'auto' }; + if ($options{args} =~ /^([KMGTPEkmgtpe])?(B|b|bps|Bps|b\/s|auto)$/) { + $args->{quantity} = defined($1) ? $1 : ''; + $args->{unit} = $2; + } elsif ($options{args} ne '') { + return 1; + } + + return (0, $args); +} + +sub parse_pfdata_math { + my ($self, %options) = @_; + + # --extend-perfdata=perfx,,math(current + 10 - 100, 1) + my $args = { math => undef, apply_threshold => 0 }; + my ($math, $apply_threshold) = split /\|/, $options{args}; + if ($math =~ /^((?:[\s\.\-\+\*\/0-9\(\)]|current)+)$/) { + $args->{math} = $1; + } elsif ($options{args} ne '') { + return 1; + } + + if (defined($apply_threshold) && $apply_threshold =~ /^\s*(0|1)\s*$/ ) { + $args->{apply_threshold} = $1; + } + + return (0, $args); +} + +sub parse_pfdata_eval { + my ($self, %options) = @_; + + # --extend-perfdata=perfx,,eval(%(label) =~ s/a/A/g) + my $args = { expr => $options{args} }; + $args->{expr} =~ s/%\{(.*?)\}/\$values->{$1}/g; + $args->{expr} =~ s/%\((.*?)\)/\$values->{$1}/g; + return (0, $args); +} + +sub parse_group_pfdata { + my ($self, %options) = @_; + + $options{args} =~ s/^\s+//; + $options{args} =~ s/\s+$//; + my $args = { pattern_pf => $options{args} }; + return $args; +} + +sub parse_pfdata_min { + my ($self, %options) = @_; + + my $args = $self->parse_group_pfdata(%options); + return (0, $args); +} + +sub parse_pfdata_max { + my ($self, %options) = @_; + + my $args = $self->parse_group_pfdata(%options); + return (0, $args); +} + +sub parse_pfdata_average { + my ($self, %options) = @_; + + my $args = $self->parse_group_pfdata(%options); + return (0, $args); +} + +sub parse_pfdata_sum { + my ($self, %options) = @_; + + my $args = $self->parse_group_pfdata(%options); + return (0, $args); +} + +sub apply_pfdata_scale { + my ($self, %options) = @_; + + return if (${$options{perf}}->{unit} !~ /^([KMGTPEkmgtpe])?(B|b|bps|Bps|b\/s)$/); + + my ($src_quantity, $src_unit) = ($1, $2); + my ($value, $dst_quantity, $dst_unit) = centreon::plugins::misc::scale_bytesbit( + value => ${$options{perf}}->{value}, + src_quantity => $src_quantity, src_unit => $src_unit, dst_quantity => $options{args}->{quantity}, dst_unit => $options{args}->{unit} + ); + ${$options{perf}}->{value} = sprintf('%.2f', $value); + if (defined($dst_unit)) { + ${$options{perf}}->{unit} = $dst_quantity . $dst_unit; + } else { + ${$options{perf}}->{unit} = $options{args}->{quantity} . $options{args}->{unit}; + } + + if (defined(${$options{perf}}->{max}) && ${$options{perf}}->{max} ne '') { + ($value) = centreon::plugins::misc::scale_bytesbit(value => ${$options{perf}}->{max}, + src_quantity => $src_quantity, src_unit => $src_unit, + dst_quantity => defined($dst_unit) ? $dst_quantity : $options{args}->{quantity}, + dst_unit => defined($dst_unit) ? $dst_unit : $options{args}->{unit}); + ${$options{perf}}->{max} = sprintf('%.2f', $value); + } + + foreach my $threshold ('warning', 'critical') { + next if (${$options{perf}}->{$threshold} eq ''); + my ($status, $result) = centreon::plugins::misc::parse_threshold(threshold => ${$options{perf}}->{$threshold}); + next if ($status == 0); + + if ($result->{start} ne '' && $result->{infinite_neg} == 0) { + ($result->{start}) = centreon::plugins::misc::scale_bytesbit(value => $result->{start}, + src_quantity => $src_quantity, src_unit => $src_unit, + dst_quantity => defined($dst_unit) ? $dst_quantity : $options{args}->{quantity}, + dst_unit => defined($dst_unit) ? $dst_unit : $options{args}->{unit}); + } + if ($result->{end} ne '' && $result->{infinite_pos} == 0) { + ($result->{end}) = centreon::plugins::misc::scale_bytesbit(value => $result->{end}, + src_quantity => $src_quantity, src_unit => $src_unit, + dst_quantity => defined($dst_unit) ? $dst_quantity : $options{args}->{quantity}, + dst_unit => defined($dst_unit) ? $dst_unit : $options{args}->{unit}); + } + + ${$options{perf}}->{$threshold} = centreon::plugins::misc::get_threshold_litteral(%$result); + } +} + +sub apply_pfdata_invert { + my ($self, %options) = @_; + + return if (!defined(${$options{perf}}->{max}) || ${$options{perf}}->{max} eq ''); + + ${$options{perf}}->{value} = ${$options{perf}}->{max} - ${$options{perf}}->{value}; + foreach my $threshold ('warning', 'critical') { + next if (${$options{perf}}->{$threshold} eq ''); + my ($status, $result) = centreon::plugins::misc::parse_threshold(threshold => ${$options{perf}}->{$threshold}); + next if ($status == 0); + + my $tmp = { arobase => $result->{arobase}, infinite_pos => 0, infinite_neg => 0, start => $result->{start}, end => $result->{end} }; + $tmp->{infinite_neg} = 1 if ($result->{infinite_pos} == 1); + $tmp->{infinite_pos} = 1 if ($result->{infinite_neg} == 1); + + if ($result->{start} ne '' && $result->{infinite_neg} == 0) { + $tmp->{end} = ${$options{perf}}->{max} - $result->{start}; + } + if ($result->{end} ne '' && $result->{infinite_pos} == 0) { + $tmp->{start} = ${$options{perf}}->{max} - $result->{end}; + } + + ${$options{perf}}->{$threshold} = centreon::plugins::misc::get_threshold_litteral(%$tmp); + } +} + +sub apply_pfdata_percent { + my ($self, %options) = @_; + + return if (!defined(${$options{perf}}->{max}) || ${$options{perf}}->{max} eq ''); + + ${$options{perf}}->{value} = sprintf('%.2f', ${$options{perf}}->{value} * 100 / ${$options{perf}}->{max}); + ${$options{perf}}->{unit} = '%'; + foreach my $threshold ('warning', 'critical') { + next if (${$options{perf}}->{$threshold} eq ''); + my ($status, $result) = centreon::plugins::misc::parse_threshold(threshold => ${$options{perf}}->{$threshold}); + next if ($status == 0); + + if ($result->{start} ne '' && $result->{infinite_neg} == 0) { + $result->{start} = sprintf('%.2f', $result->{start} * 100 / ${$options{perf}}->{max}); + } + if ($result->{end} ne '' && $result->{infinite_pos} == 0) { + $result->{end} = sprintf('%.2f', $result->{end} * 100 / ${$options{perf}}->{max}); + } + + ${$options{perf}}->{$threshold} = centreon::plugins::misc::get_threshold_litteral(%$result); + } + + ${$options{perf}}->{max} = 100; +} + +sub apply_pfdata_eval { + my ($self, %options) = @_; + + ${$options{perf}} = $self->open_eval(eval => $options{args}->{expr}, values => ${$options{perf}}); +} + +sub apply_pfdata_math { + my ($self, %options) = @_; + + my $math = $options{args}->{math}; + $math =~ s/current/\$value/g; + + my $value = ${$options{perf}}->{value}; + eval "\${\$options{perf}}->{value} = $math"; + + return if ($options{args}->{apply_threshold} == 0); + + foreach my $threshold ('warning', 'critical') { + next if (${$options{perf}}->{$threshold} eq ''); + my ($status, $result) = centreon::plugins::misc::parse_threshold(threshold => ${$options{perf}}->{$threshold}); + next if ($status == 0); + + if ($result->{start} ne '' && $result->{infinite_neg} == 0) { + $value = $result->{start}; + eval "\$result->{start} = $math"; + } + if ($result->{end} ne '' && $result->{infinite_pos} == 0) { + $value = $result->{end}; + eval "\$result->{end} = $math"; + } + + ${$options{perf}}->{$threshold} = centreon::plugins::misc::get_threshold_litteral(%$result); + } + + ${$options{perf}}->{max} = 100; +} + +sub apply_pfdata_min { + my ($self, %options) = @_; + + my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\""); + my $min; + for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { + next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); + next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); + $min = $self->{perfdatas}->[$i]->{value} + if (!defined($min) || $min > $self->{perfdatas}->[$i]->{value}); + } + + ${$options{perf}}->{value} = $min + if (defined($min)); +} + +sub apply_pfdata_max { + my ($self, %options) = @_; + + my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\""); + my $max; + for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { + next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); + next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); + $max = $self->{perfdatas}->[$i]->{value} + if (!defined($max) || $max < $self->{perfdatas}->[$i]->{value}); + } + + ${$options{perf}}->{value} = $max + if (defined($max)); +} + +sub apply_pfdata_sum { + my ($self, %options) = @_; + + my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\""); + my ($sum, $num) = (0, 0); + for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { + next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); + next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); + $sum += $self->{perfdatas}->[$i]->{value}; + $num++; + } + + ${$options{perf}}->{value} = $sum + if ($num > 0); +} + +sub apply_pfdata_average { + my ($self, %options) = @_; + + my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\""); + my ($sum, $num) = (0, 0); + for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { + next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); + next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); + $sum += $self->{perfdatas}->[$i]->{value}; + $num++; + } + + ${$options{perf}}->{value} = sprintf("%.2f", ($sum / $num)) + if ($num > 0); +} + +sub apply_perfdata_thresholds { + my ($self, %options) = @_; + + foreach (('warning', 'critical')) { + next if (!defined($options{$_})); + + my @thresholds = split(':', $options{$_}, -1); + for (my $i = 0; $i < scalar(@thresholds); $i++) { + if ($thresholds[$i] =~ /(\d+(?:\.\d+)?)\s*%/) { + if (!defined($options{max}) || $options{max} eq '') { + $thresholds[$i] = ''; + next; + } + $thresholds[$i] = $1 * $options{max} / 100; + } elsif ($thresholds[$i] =~ /(\d+(?:\.\d+)?)/) { + $thresholds[$i] = $1; + } else { + $thresholds[$i] = ''; + } + } + + ${$options{perf}}->{$_} = join(':', @thresholds); + } +} + +sub load_perfdata_extend_args { + my ($self, %options) = @_; + + foreach ( + [$self->{option_results}->{change_perfdata}, 1], + [$self->{option_results}->{extend_perfdata}, 2], + [$self->{option_results}->{extend_perfdata_group}, 3], + ) { + next if (!defined($_->[0])); + foreach my $arg (@{$_->[0]}) { + $self->parse_perfdata_extend_args(arg => $arg, type => $_->[1]); + } + } +} + +sub parse_perfdata_extend_args { + my ($self, %options) = @_; + + # --extend-perfdata=searchlabel,newlabel,method[,[newuom],[min],[max],[warning],[critical]] + my ($pfdata_match, $pfdata_substitute, $method, $uom_sub, $min_sub, $max_sub, $warn_sub, $crit_sub) = + split /,/, $options{arg}; + return if ((!defined($pfdata_match) || $pfdata_match eq '') && $options{type} != 3); + + $self->{pfdata_extends} = [] if (!defined($self->{pfdata_extends})); + my $pfdata_extends = { + pfdata_match => defined($pfdata_match) && $pfdata_match ne '' ? $pfdata_match : undef, + pfdata_substitute => defined($pfdata_substitute) && $pfdata_substitute ne '' ? $pfdata_substitute : undef, + uom_sub => defined($uom_sub) && $uom_sub ne '' ? $uom_sub : undef, + min_sub => defined($min_sub) && $min_sub ne '' ? $min_sub : undef, + max_sub => defined($max_sub) && $max_sub ne '' ? $max_sub : undef, + warn_sub => defined($warn_sub) && $warn_sub ne '' ? $warn_sub : undef, + crit_sub => defined($crit_sub) && $crit_sub ne '' ? $crit_sub : undef, + type => $options{type} + }; + + if (defined($method) && $method ne '') { + if ($method !~ /^\s*(invert|percent|scale|math|min|max|average|sum|eval)\s*\(\s*(.*?)\s*\)\s*$/) { + $self->output_add(long_msg => "method in argument '$options{arg}' is unknown", debug => 1); + return ; + } + + $pfdata_extends->{method_name} = $1; + my $args = $2; + if (my $func = $self->can('parse_pfdata_' . $pfdata_extends->{method_name})) { + (my $status, $pfdata_extends->{method_args}) = $func->($self, args => $args); + if ($status == 1) { + $self->output_add(long_msg => "argument in method '$options{arg}' is unknown", debug => 1); + return ; + } + } + } + + push @{$self->{pfdata_extends}}, $pfdata_extends; +} + +sub apply_perfdata_explode { + my ($self, %options) = @_; + + return if ($self->{explode_perfdata_total} == 0); + foreach (@{$self->{perfdatas}}) { + next if ($_->{max} eq ''); + if ($self->{explode_perfdata_total} == 2) { + $self->perfdata_add(label => $_->{label} . '_max', value => $_->{max}, unit => $_->{unit}); + next; + } + foreach my $regexp (keys %{$self->{explode_perfdatas}}) { + if ($_->{label} =~ /$regexp/) { + $self->perfdata_add(label => $self->{explode_perfdatas}->{$regexp}, value => $_->{max}, unit => $_->{unit}); + last; + } + } + } +} + +sub apply_perfdata_extend { + my ($self, %options) = @_; + + foreach my $extend (@{$self->{pfdata_extends}}) { + my $new_pfdata = []; + + # Manage special case when type group and pfdata_match empty + if ($extend->{type} == 3 && (!defined($extend->{pfdata_match}) || $extend->{pfdata_match} eq '')) { + next if (!defined($extend->{pfdata_substitute}) || $extend->{pfdata_substitute} eq ''); + my $new_perf = { + label => $extend->{pfdata_substitute}, value => '', + unit => defined($extend->{uom_sub}) ? $extend->{uom_sub} : '', + warning => '', critical => '', + min => defined($extend->{min_sub}) ? $extend->{min_sub} : '', + max => defined($extend->{max_sub}) ? $extend->{max_sub} : '' + }; + + if (defined($extend->{method_name})) { + my $func = $self->can('apply_pfdata_' . $extend->{method_name}); + $func->($self, perf => \$new_perf, args => $extend->{method_args}); + } + + $self->apply_perfdata_thresholds( + perf => \$new_perf, + warning => $extend->{warn_sub}, + critical => $extend->{crit_sub}, + max => $new_perf->{max} + ); + if (length($new_perf->{value})) { + push @{$self->{perfdatas}}, $new_perf; + } + next; + } + + for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { + next if ($self->{perfdatas}->[$i]->{label} !~ /$extend->{pfdata_match}/); + + my $new_perf = { %{$self->{perfdatas}->[$i]} }; + if ($extend->{type} == 3) { + $new_perf = { label => $self->{perfdatas}->[$i]->{label}, value => '', unit => '', warning => '', critical => '', min => '', max => '' }; + } + + if (defined($extend->{pfdata_substitute})) { + eval "\$new_perf->{label} =~ s{$extend->{pfdata_match}}{$extend->{pfdata_substitute}}"; + } + + if (defined($extend->{method_name})) { + my $func = $self->can('apply_pfdata_' . $extend->{method_name}); + $func->($self, perf => \$new_perf, args => $extend->{method_args}); + } + + $new_perf->{unit} = $extend->{uom_sub} if (defined($extend->{uom_sub})); + $new_perf->{min} = $extend->{min_sub} if (defined($extend->{min_sub})); + $new_perf->{max} = $extend->{max_sub} if (defined($extend->{max_sub})); + $self->apply_perfdata_thresholds( + perf => \$new_perf, + warning => $extend->{warn_sub}, + critical => $extend->{crit_sub}, + max => $new_perf->{max} + ); + + if ($extend->{type} == 1) { + $self->{perfdatas}->[$i] = $new_perf; + } else { + push @$new_pfdata, $new_perf if (length($new_perf->{value})); + } + } + + push @{$self->{perfdatas}}, @$new_pfdata; + } +} + +sub change_perfdata { + my ($self, %options) = @_; + + $self->apply_perfdata_extend(); + $self->apply_perfdata_explode(); +} + +1; + +__END__ + +=head1 NAME + +Output class + +=head1 SYNOPSIS + +- + +=head1 OUTPUT OPTIONS + +=over 8 + +=item B<--verbose> + +Display verbse extended status information (long output). + +=item B<--debug> + +Display debug messages. + +=item B<--filter-perfdata> + +Filter perfdata that match the regexp. +Example: adding --filter-perfdata='avg' will remove all metrics that do not contain +'avg' from performance data. + +=item B<--filter-perfdata-adv> + +Filter perfdata based on a "if" condition using the following variables: +label, value, unit, warning, critical, min, max. +Variables must be written either %{variable} or %(variable). +Example: adding --filter-perfdata-adv='not (%(value) == 0 and %(max) eq "")' will +remove all metrics whose value equals 0 and that don't have a maximum value. + +=item B<--explode-perfdata-max> + +Create a new metric for each metric that comes with a maximum limit. The new +metric will be named identically with a '_max' suffix). +Example: it will split 'used_prct'=26.93%;0:80;0:90;0;100 +into 'used_prct'=26.93%;0:80;0:90;0;100 'used_prct_max'=100%;;;; + + +=item B<--change-perfdata> B<--extend-perfdata> + +Change or extend perfdata. +Syntax: --extend-perfdata=searchlabel,newlabel,target[,[newuom],[min],[max]] + +Common examples: + +=over 4 + +Convert storage free perfdata into used: --change-perfdata=free,used,invert() + +Convert storage free perfdata into used: --change-perfdata=used,free,invert() + +Scale traffic values automatically: --change-perfdata=traffic,,scale(auto) + +Scale traffic values in Mbps: --change-perfdata=traffic_in,,scale(Mbps),mbps + +Change traffic values in percent: --change-perfdata=traffic_in,,percent() + +=back + +=item B<--extend-perfdata-group> + +Add new aggregated metrics (min, max, average or sum) for groups of metrics defined by a regex match on the metrics' names. +Syntax: --extend-perfdata-group=regex,namesofnewmetrics,calculation[,[newuom],[min],[max]] +regex: regular expression +namesofnewmetrics: how the new metrics' names are composed (can use $1, $2... for groups defined by () in regex). +calculation: how the values of the new metrics should be calculated +newuom (optional): unit of measure for the new metrics +min (optional): lowest value the metrics can reach +max (optional): highest value the metrics can reach + +Common examples: + +=over 4 + +Sum wrong packets from all interfaces (with interface need --units-errors=absolute): --extend-perfdata-group=',packets_wrong,sum(packets_(discard|error)_(in|out))' + +Sum traffic by interface: --extend-perfdata-group='traffic_in_(.*),traffic_$1,sum(traffic_(in|out)_$1)' + +=back + +=item B<--change-short-output> B<--change-long-output> + +Modify the short/long output that is returned by the plugin. +Syntax: --change-short-output=pattern~replacement~modifier +Most commonly used modifiers are i (case insensitive) and g (replace all occurrences). +Example: adding --change-short-output='OK~Up~gi' will replace all occurrences of 'OK', 'ok', 'Ok' or 'oK' with 'Up' + +=item B<--change-exit> + +Replace an exit code with one of your choice. +Example: adding --change-exit=unknown=critical will result in a CRITICAL state +instead of an UNKNOWN state. + +=item B<--range-perfdata> + +Rewrite the ranges displayed in the perfdata. Accepted values: +0: nothing is changed. +1: if the lower value of the range is equal to 0, it is removed. +2: remove the thresholds from the perfdata. + +=item B<--filter-uom> + +Mask the units when they don't match the given regular expression. + +=item B<--opt-exit> + +Replace the exit code in case of an execution error (i.e. wrong option provided, +SSH connection refused, timeout, etc). Default: unknonw. + +=item B<--output-ignore-perfdata> + +Remove all the metrics from the service. The service will still have a status +and an output. + +=item B<--output-ignore-label> + +Remove the status label ("OK:", "WARNING:", "UNKNOWN:", CRITICAL:") from the +beginning of the output. +Example: 'OK: Ram Total:...' will become 'Ram Total:...' + +=item B<--output-xml> + +Return the output in XML format (to send to an XML API). + +=item B<--output-json> + +Return the output in JSON format (to send to a JSON API). + +=item B<--output-openmetrics> + +Return the output in OpenMetrics format (to send to a tool expecting this +format). + +=item B<--output-file> + +Write output in file (can be combined with json, xml and openmetrics options). +E.g.: --output-file=/tmp/output.txt will write the output in /tmp/output.txt. + +=item B<--disco-format> + +Applies only to modes beginning with 'list-'. +Returns the list of available macros to configure a service discovery rule +(formatted in XML). + +=item B<--disco-show> + +Applies only to modes beginning with 'list-'. +Returns the list of discovered objects (formatted in XML) for service discovery. + +=item B<--float-precision> + +Define the float precision for thresholds (default: 8). + +=item B<--source-encoding> + +Define the character encoding of the response sent by the monitored resource +Default: 'UTF-8'. + +=head1 DESCRIPTION + +B. + +=cut diff --git a/src/os/as400/connector/mode/jobs_corrupted.pm b/src/os/as400/connector/mode/jobs_corrupted.pm new file mode 100644 index 0000000000..6664752608 --- /dev/null +++ b/src/os/as400/connector/mode/jobs_corrupted.pm @@ -0,0 +1,134 @@ +# +# Copyright 2023 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::as400::connector::mode::jobs; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'jobs-total', nlabel => 'jobs.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'number of jobs: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-active-status:s' => { name => 'filter_active_status' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-subsystem:s' => { name => 'filter_subsystem' }, + 'display-jobs' => { name => 'display_jobs' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $jobs = $options{custom}->request_api(command => 'listJobs'); + + $self->{global} = { total => 0 }; + foreach my $entry (@{$jobs->{result}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $entry->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (name).", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_subsystem}) && $self->{option_results}->{filter_subsystem} ne '' && + $entry->{subSystem} !~ /$self->{option_results}->{filter_subsystem}/) { + $self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (subsystem).", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_active_status}) && $self->{option_results}->{filter_active_status} ne '' && + $entry->{activeStatus} !~ /$self->{option_results}->{filter_active_status}/) { + $self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (activeStatus).", debug => 1); + next; + } + + if (defined($self->{option_results}->{display_jobs})) { + $self->{output}->output_add( + long_msg => sprintf( + 'job %s [subsystem: %s] [active status: %s]', + $entry->{name}, + $entry->{subSystem}, + $entry->{activeStatus} + ) + ); + } + + $self->{global}->{total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check active jobz. + +=over 8 + +=item B<--filter-active-status> + +Filter jobs by ACTIVE_JOB_STATUS (can be a regexp). +Example: --filter-active-status='MSGW' to count jobs with MSGW. + +=item B<--filter-name> + +Filter jobs by name (can be a regexp). + +=item B<--filter-subsystem> + +Filter jobs by subsystem (can be a regexp). + +=item B<--display-jobs> + +Display jobs in vrbose output. + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'jobs-total'. + +=back + +=cut diff --git a/src/snmp_standard/mode/ntp_corrupted.pm b/src/snmp_standard/mode/ntp_corrupted.pm new file mode 100644 index 0000000000..a2f80d0cc1 --- /dev/null +++ b/src/snmp_standard/mode/ntp_corrupted.pm @@ -0,0 +1,228 @@ +# +# Copyright 2023 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::ntp; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use DateTime; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Time offset %d second(s): %s', + $self->{result_values}->{offset}, + $self->{result_values}->{date} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'offset', type => 0 } + ]; + + $self->{maps_counters}->{offset} = [ + { label => 'offset', nlabel => 'time.offset.seconds', set => { + key_values => [ { name => 'offset' }, { name => 'date' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'offset', template => '%d', unit => 's' } + ] + } + } + ]; +} + +sub default_date_oid { + my ($self, %options) = @_; + + return '.1.3.6.1.2.1.25.1.2.0'; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'oid:s' => { name => 'oid' }, + 'ntp-hostname:s' => { name => 'ntp_hostname' }, + 'ntp-port:s' => { name => 'ntp_port', default => 123 }, + 'timezone:s' => { name => 'timezone' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{ntp_hostname})) { + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => 'Net::NTP', + error_msg => "Cannot load module 'Net::NTP'." + ); + } +} + +sub get_from_epoch { + my ($self, %options) = @_; + + my $timezone = 'UTC'; + if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { + $timezone = $self->{option_results}->{timezone}; + } + + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); + my $dt = DateTime->from_epoch( + epoch => $options{date}, + %$tz + ); + my @remote_date = ($dt->year, $dt->month, $dt->day, $dt->hour, $dt->minute, $dt->second); + return ($dt->epoch, \@remote_date, $timezone); +} + +sub get_from_datetime { + my ($self, %options) = @_; + + my @remote_date = unpack('n C6 a C2', $options{date}); + my $timezone = 'UTC'; + if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { + $timezone = $self->{option_results}->{timezone}; + } elsif (defined($remote_date[9])) { + $timezone = sprintf('%s%02d%02d', $remote_date[7], $remote_date[8], $remote_date[9]); # format +0630 + } + + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); + my $dt = DateTime->new( + year => $remote_date[0], + month => $remote_date[1], + day => $remote_date[2], + hour => $remote_date[3], + minute => $remote_date[4], + second => $remote_date[5], + %$tz + ); + + return ($dt->epoch, \@remote_date, $timezone); +} + +sub get_target_time { + my ($self, %options) = @_; + + my $oid_date = $self->default_date_oid(); + if (defined($self->{option_results}->{oid}) && $self->{option_results}->{oid} ne '') { + $oid_date = $self->{option_results}->{oid}; + } + my $result = $options{snmp}->get_leef(oids => [ $oid_date ], nothing_quit => 1); + + if ($result->{$oid_date} =~ /^[0-9]{10}$/) { + return $self->get_from_epoch(date => $result->{$oid_date}); + } + + return $self->get_from_datetime(date => $result->{$oid_date}); +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($distant_time, $remote_date, $timezone) = $self->get_target_time(%options); + if ($distant_time == 0) { + $self->{output}->add_option_msg(short_msg => "Couldn't get system date: local time: 0"); + $self->{output}->option_exit(); + } + + my $ref_time; + if (defined($self->{option_results}->{ntp_hostname}) && $self->{option_results}->{ntp_hostname} ne '') { + my %ntp; + + eval { + %ntp = Net::NTP::get_ntp_response($self->{option_results}->{ntp_hostname}, $self->{option_results}->{ntp_port}); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Couldn't connect to ntp server: " . $@); + $self->{output}->option_exit(); + } + + $ref_time = $ntp{'Transmit Timestamp'}; + } else { + $ref_time = time(); + } + + my $offset = $distant_time - $ref_time; + my $remote_date_formated = sprintf( + 'Local Time : %02d-%02d-%02dT%02d:%02d:%02d (%s)', + $remote_date->[0], $remote_date->[1], $remote_date->[2], + $remote_date->[3], $remote_date->[4], $remote_date->[5], $timezone + ); + + $self->{offset} = { + offset => sprintf('%d', $offset), + date => $remote_date_formated + }; +} + +1; + +__END__ + +=head1 MODE + +Check time offset of server with ntp server. Use local time if ntp-host option is not set. +SNMP gives a date with second precision (no milliseconds). Time precision is not very accurate. +Use threshold with (+-) 2 seconds offset (minimum). + +=over 8 + +=item B<--oid> + +Override default OID. + +=item B<--warning-offset> + +Time offset warning threshold (in seconds). + +=item B<--critical-offset> + +Time offset critical Threshold (in seconds). + +=item B<--ntp-hostname> + +Set the ntp hostname (if not set, localtime is used). + +=item B<--ntp-port> + +Set the ntp port (default: 123). + +=item B<--timezone> + +Set the timezone of distant server. For Windows, you need to set it. +Can use format: 'Europe/London' or '+0100'. + +=back + +=cut From 1781c6d12c06b009c93bb1c19b16a0733dcaceba Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 10:45:53 +0100 Subject: [PATCH 05/35] wip --- .github/workflows/spellchecker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 8b89dbe477..baded6bc97 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -39,6 +39,7 @@ jobs: run: | sudo apt-get install -y hunspell aspell spell ispell for f in ${{ steps.filter.outputs.packages_files }}; do + echo perl .github/scripts/pod_spell_check.t $f perl .github/scripts/pod_spell_check.t $f done shell: bash From 03eede147002a3e0d92e1a9780675e391a3e0f39 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 10:49:36 +0100 Subject: [PATCH 06/35] wip --- .github/workflows/spellchecker.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index baded6bc97..08f2a4f4c8 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -39,7 +39,8 @@ jobs: run: | sudo apt-get install -y hunspell aspell spell ispell for f in ${{ steps.filter.outputs.packages_files }}; do - echo perl .github/scripts/pod_spell_check.t $f - perl .github/scripts/pod_spell_check.t $f + echo "perl .github/scripts/pod_spell_check.t $f" + output=$(perl .github/scripts/pod_spell_check.t $f) + echo $output done shell: bash From 268402231d8eb799d5198f9933a148cfaab7d9ed Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 10:53:34 +0100 Subject: [PATCH 07/35] wip --- src/snmp_standard/mode/cpu.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snmp_standard/mode/cpu.pm b/src/snmp_standard/mode/cpu.pm index 2ec2e3dbdb..140248c6cd 100644 --- a/src/snmp_standard/mode/cpu.pm +++ b/src/snmp_standard/mode/cpu.pm @@ -154,7 +154,7 @@ Warning thresholds for each CPU core =item B<--critical-core> -Critical thresholds for each CPU core +Critical thresholds for each CPU core. =back From ee3d6b2812c949c096296ffba8f17a528fb1463b Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 10:56:14 +0100 Subject: [PATCH 08/35] wip --- .github/workflows/spellchecker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 08f2a4f4c8..2295869027 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -38,7 +38,7 @@ jobs: - name: Run spell check run: | sudo apt-get install -y hunspell aspell spell ispell - for f in ${{ steps.filter.outputs.packages_files }}; do + for f in ${{ steps.filter.outputs.plugins_files }}; do echo "perl .github/scripts/pod_spell_check.t $f" output=$(perl .github/scripts/pod_spell_check.t $f) echo $output From c4f44f0a3eea4876cb27a5b40a7cb3715d9cbd68 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 21 Dec 2023 11:00:08 +0100 Subject: [PATCH 09/35] wip --- .github/workflows/spellchecker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 2295869027..e0a6f59fbf 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -41,6 +41,5 @@ jobs: for f in ${{ steps.filter.outputs.plugins_files }}; do echo "perl .github/scripts/pod_spell_check.t $f" output=$(perl .github/scripts/pod_spell_check.t $f) - echo $output done shell: bash From 2708fdca3ee9bdc45b28a54efa44827a49dde393 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Thu, 21 Dec 2023 14:41:13 +0100 Subject: [PATCH 10/35] test to have all the errors --- .github/workflows/spellchecker.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index e0a6f59fbf..0735f3cb24 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -36,6 +36,8 @@ jobs: install-modules: Test::More Test::Spelling Pod::Wordlist - name: Run spell check + id: run_check + continue-on-error: true run: | sudo apt-get install -y hunspell aspell spell ispell for f in ${{ steps.filter.outputs.plugins_files }}; do @@ -43,3 +45,7 @@ jobs: output=$(perl .github/scripts/pod_spell_check.t $f) done shell: bash + + - name: Check errors + if: steps.run_check.outcome != 'success' + run: exit 1 From 455dc1b6e0a6f79e64f1137be96d212ef549c18e Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Thu, 21 Dec 2023 14:43:56 +0100 Subject: [PATCH 11/35] update --- .github/workflows/spellchecker.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 0735f3cb24..cdc46572b6 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -28,18 +28,23 @@ jobs: plugins: - added|modified: src/** - - name: Install Libraries + - name: Install CPAN Libraries uses: shogo82148/actions-setup-perl@v1 with: perl-version: '5.34' install-modules-with: cpm install-modules: Test::More Test::Spelling Pod::Wordlist + - name: Install librairies + id: run_check + continue-on-error: true + run: sudo apt-get install -y hunspell aspell spell ispell + shell: bash + - name: Run spell check id: run_check continue-on-error: true run: | - sudo apt-get install -y hunspell aspell spell ispell for f in ${{ steps.filter.outputs.plugins_files }}; do echo "perl .github/scripts/pod_spell_check.t $f" output=$(perl .github/scripts/pod_spell_check.t $f) From 01f2815d7f13526cdd026da5331d779ba620e824 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Thu, 21 Dec 2023 14:45:19 +0100 Subject: [PATCH 12/35] fix --- .github/workflows/spellchecker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index cdc46572b6..d04e6fa5e4 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -36,7 +36,6 @@ jobs: install-modules: Test::More Test::Spelling Pod::Wordlist - name: Install librairies - id: run_check continue-on-error: true run: sudo apt-get install -y hunspell aspell spell ispell shell: bash From 935003cdca14afe29fa86d65eaebf825436df091 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Thu, 21 Dec 2023 15:39:01 +0100 Subject: [PATCH 13/35] update for all errors --- .github/workflows/spellchecker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index d04e6fa5e4..4b6c0aa68c 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -48,7 +48,7 @@ jobs: echo "perl .github/scripts/pod_spell_check.t $f" output=$(perl .github/scripts/pod_spell_check.t $f) done - shell: bash + shell: bash +e - name: Check errors if: steps.run_check.outcome != 'success' From 9b9b7c07601b5f308b32dfadcb5ae661ea2b7116 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Thu, 21 Dec 2023 15:41:06 +0100 Subject: [PATCH 14/35] update --- .github/workflows/spellchecker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 4b6c0aa68c..bffe9679a6 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -42,13 +42,13 @@ jobs: - name: Run spell check id: run_check - continue-on-error: true run: | + set +e for f in ${{ steps.filter.outputs.plugins_files }}; do echo "perl .github/scripts/pod_spell_check.t $f" output=$(perl .github/scripts/pod_spell_check.t $f) done - shell: bash +e + shell: bash - name: Check errors if: steps.run_check.outcome != 'success' From 504182d5dcd88342e10956f673ecef0b8c7845d6 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Thu, 21 Dec 2023 15:46:34 +0100 Subject: [PATCH 15/35] workflow ok --- .github/workflows/spellchecker.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index bffe9679a6..e32c31fe53 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -49,7 +49,3 @@ jobs: output=$(perl .github/scripts/pod_spell_check.t $f) done shell: bash - - - name: Check errors - if: steps.run_check.outcome != 'success' - run: exit 1 From 1786a1b242c98bc4d0ec1ee3176d091975771ecc Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Fri, 22 Dec 2023 11:17:44 +0100 Subject: [PATCH 16/35] Remove corrupted files --- src/centreon/plugins/output_corrupted.pm | 1671 ----------------- src/os/as400/connector/mode/jobs_corrupted.pm | 134 -- src/snmp_standard/mode/ntp_corrupted.pm | 228 --- 3 files changed, 2033 deletions(-) delete mode 100644 src/centreon/plugins/output_corrupted.pm delete mode 100644 src/os/as400/connector/mode/jobs_corrupted.pm delete mode 100644 src/snmp_standard/mode/ntp_corrupted.pm diff --git a/src/centreon/plugins/output_corrupted.pm b/src/centreon/plugins/output_corrupted.pm deleted file mode 100644 index 264f4876bf..0000000000 --- a/src/centreon/plugins/output_corrupted.pm +++ /dev/null @@ -1,1671 +0,0 @@ -# -# Copyright 2023 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 centreon::plugins::output; - -use strict; -use warnings; -use centreon::plugins::misc; - -sub new { - my ($class, %options) = @_; - my $self = {}; - bless $self, $class; - - if (!defined($options{options})) { - print "Class Output: Need to specify 'options' argument to load.\n"; - exit 3; - } - - $options{options}->add_options(arguments => { - 'explode-perfdata-max:s@' => { name => 'explode_perfdata_max' }, - 'range-perfdata:s' => { name => 'range_perfdata' }, - 'filter-perfdata:s' => { name => 'filter_perfdata' }, - 'filter-perfdata-adv:s' => { name => 'filter_perfdata_adv' }, - 'change-perfdata:s@' => { name => 'change_perfdata' }, - 'extend-perfdata:s@' => { name => 'extend_perfdata' }, - 'extend-perfdata-group:s@'=> { name => 'extend_perfdata_group' }, - 'change-exit:s@' => { name => 'change_exit' }, - 'change-short-output:s@' => { name => 'change_short_output' }, - 'change-long-output:s@' => { name => 'change_long_output' }, - 'use-new-perfdata' => { name => 'use_new_perfdata' }, - 'filter-uom:s' => { name => 'filter_uom' }, - 'verbose' => { name => 'verbose' }, - 'debug' => { name => 'debug' }, - 'debug-stream' => { name => 'debug_stream' }, - 'opt-exit:s' => { name => 'opt_exit', default => 'unknown' }, - 'output-xml' => { name => 'output_xml' }, - 'output-json' => { name => 'output_json' }, - 'output-ignore-perfdata' => { name => 'output_ignore_perfdata' }, - 'output-ignore-label' => { name => 'output_ignore_label' }, - 'output-openmetrics' => { name => 'output_openmetrics' }, - 'output-file:s' => { name => 'output_file' }, - 'disco-format' => { name => 'disco_format' }, - 'disco-show' => { name => 'disco_show' }, - 'float-precision:s' => { name => 'float_precision', default => 8 }, - 'source-encoding:s' => { name => 'source_encoding' , default => 'UTF-8' } - }); - - $self->{option_results} = {}; - - $self->{option_msg} = []; - - $self->{nodisplay} = 0; - $self->{noexit_die} = 0; - - $self->{is_output_xml} = 0; - $self->{is_output_json} = 0; - $self->{errors} = {OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, PENDING => 4}; - $self->{errors_num} = {0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN', 4 => 'PENDING'}; - $self->{myerrors} = {0 => "OK", 1 => "WARNING", 3 => "UNKNOWN", 7 => "CRITICAL"}; - $self->{myerrors_mask} = {CRITICAL => 7, WARNING => 1, UNKNOWN => 3, OK => 0}; - $self->{global_short_concat_outputs} = {OK => undef, WARNING => undef, CRITICAL => undef, UNKNOWN => undef, UNQUALIFIED_YET => undef}; - $self->{global_short_outputs} = {OK => [], WARNING => [], CRITICAL => [], UNKNOWN => [], UNQUALIFIED_YET => []}; - $self->{global_long_output} = []; - $self->{perfdatas} = []; - $self->{explode_perfdatas} = {}; - $self->{change_perfdata} = {}; - $self->{explode_perfdata_total} = 0; - $self->{range_perfdata} = 0; - $self->{global_status} = 0; - $self->{encode_import} = 0; - $self->{perlqq} = 0; - $self->{safe_test} = 0; - - $self->{disco_elements} = []; - $self->{disco_entries} = []; - - $self->{plugin} = ''; - $self->{mode} = ''; - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - # $options{option_results} = ref to options result - - %{$self->{option_results}} = %{$options{option_results}}; - $self->{option_results}->{opt_exit} = lc($self->{option_results}->{opt_exit}); - if (!$self->is_litteral_status(status => $self->{option_results}->{opt_exit})) { - $self->add_option_msg(short_msg => "Unknown value '" . $self->{option_results}->{opt_exit} . "' for --opt-exit."); - $self->option_exit(exit_litteral => 'unknown'); - } - # Go in XML Mode - if ($self->is_disco_show() || $self->is_disco_format()) { - # By Default XML - if (!defined($self->{option_results}->{output_json})) { - $self->{option_results}->{output_xml} = 1; - } - } - - if (defined($self->{option_results}->{range_perfdata})) { - $self->{range_perfdata} = $self->{option_results}->{range_perfdata}; - $self->{range_perfdata} = 1 if ($self->{range_perfdata} eq ''); - if ($self->{range_perfdata} !~ /^[012]$/) { - $self->add_option_msg(short_msg => "Wrong range-perfdata option '" . $self->{range_perfdata} . "'"); - $self->option_exit(); - } - } - - if (defined($self->{option_results}->{change_exit})) { - $self->{change_exit} = {}; - foreach (@{$self->{option_results}->{change_exit}}) { - my ($src, $dst) = split(/=/); - next if (!defined($src) || !defined($self->{errors}->{ uc($src) })); - next if (!defined($dst) || !defined($self->{errors}->{ uc($dst) })); - $self->{change_exit}->{uc($src)} = uc($dst); - } - } - - if (defined($self->{option_results}->{explode_perfdata_max})) { - if (${$self->{option_results}->{explode_perfdata_max}}[0] eq '') { - $self->{explode_perfdata_total} = 2; - } else { - $self->{explode_perfdata_total} = 1; - foreach (@{$self->{option_results}->{explode_perfdata_max}}) { - my ($perf_match, $perf_result) = split /,/; - if (!defined($perf_result)) { - $self->add_option_msg(short_msg => "Wrong explode-perfdata-max option '" . $_ . "' (syntax: match,value)"); - $self->option_exit(); - } - $self->{explode_perfdatas}->{$perf_match} = $perf_result; - } - } - } - - if (defined($self->{option_results}->{filter_perfdata_adv}) && $self->{option_results}->{filter_perfdata_adv} ne '') { - $self->{option_results}->{filter_perfdata_adv} =~ s/%\{(.*?)\}/\$values->{$1}/g; - $self->{option_results}->{filter_perfdata_adv} =~ s/%\((.*?)\)/\$values->{$1}/g; - $self->{option_results}->{filter_perfdata_adv} =~ s/alert_triggered\(\)/alert_triggered\(%\$values\)/g; - } - - $self->load_perfdata_extend_args(); - $self->{option_results}->{use_new_perfdata} = 1 if (defined($self->{option_results}->{output_openmetrics})); - - $self->{source_encoding} = (!defined($self->{option_results}->{source_encoding}) || $self->{option_results}->{source_encoding} eq '') ? - 'UTF-8' : $self->{option_results}->{source_encoding}; -} - -sub add_option_msg { - my ($self, %options) = @_; - # $options{short_msg} = string msg - # $options{long_msg} = string msg - $options{severity} = 'UNQUALIFIED_YET'; - - $self->output_add(%options); -} - -sub set_ignore_label { - my ($self, %options) = @_; - - $self->{option_results}->{output_ignore_label} = 1; -} - -sub set_status { - my ($self, %options) = @_; - # $options{exit_litteral} = string litteral exit - - # Nothing to do for 'UNQUALIFIED_YET' - if (!$self->{myerrors_mask}->{uc($options{exit_litteral})}) { - return ; - } - $self->{global_status} |= $self->{myerrors_mask}->{uc($options{exit_litteral})}; -} - -sub output_add { - my ($self, %params) = @_; - my %args = ( - severity => 'OK', - separator => ' - ', - debug => 0, - short_msg => undef, - long_msg => undef, - ); - my $options = { %args, %params }; - - if (defined($options->{short_msg})) { - chomp $options->{short_msg}; - if (defined($self->{global_short_concat_outputs}->{uc($options->{severity})})) { - $self->{global_short_concat_outputs}->{uc($options->{severity})} .= $options->{separator} . $options->{short_msg}; - } else { - $self->{global_short_concat_outputs}->{uc($options->{severity})} = $options->{short_msg}; - } - - push @{$self->{global_short_outputs}->{uc($options->{severity})}}, $options->{short_msg}; - $self->set_status(exit_litteral => $options->{severity}); - } - if (defined($options->{long_msg})) { - chomp $options->{long_msg}; - - push @{$self->{global_long_output}}, $options->{long_msg} if ($options->{debug} == 0 || defined($self->{option_results}->{debug})); - print $options->{long_msg} . "\n" if (defined($self->{option_results}->{debug_stream})); - } -} - -sub perfdata_add { - my ($self, %options) = @_; - - my $perfdata = { - label => '', value => '', unit => '', warning => '', critical => '', min => '', max => '', mode => $self->{mode} - }; - foreach (keys %options) { - next if (!defined($options{$_})); - $perfdata->{$_} = $options{$_}; - } - - if ((defined($self->{option_results}->{use_new_perfdata}) || defined($options{force_new_perfdata})) && - defined($options{nlabel})) { - $perfdata->{label} = $options{nlabel}; - } - if (defined($options{instances})) { - $options{instances} = [$options{instances}] if (!ref($options{instances})); - my ($external_instance_separator, $internal_instance_separator) = ('#', '~'); - if (defined($self->{option_results}->{use_new_perfdata}) || defined($options{force_new_perfdata})) { - $perfdata->{label} = join('~', @{$options{instances}}) . '#' . $perfdata->{label}; - } else { - $perfdata->{label} .= '_' . join('_', @{$options{instances}}); - } - } - - $perfdata->{label} =~ s/'/''/g; - push @{$self->{perfdatas}}, $perfdata; -} - -sub filter_perfdata { - my ($self, %options) = @_; - - return 1 if ( - defined($self->{option_results}->{filter_perfdata}) && - $options{perf}->{label} !~ /$self->{option_results}->{filter_perfdata}/ - ); - - return 1 if ( - defined($self->{option_results}->{filter_perfdata_adv}) && - $self->{option_results}->{filter_perfdata_adv} ne '' && - !$self->test_eval(test => $self->{option_results}->{filter_perfdata_adv}, values => $options{perf}) - ); - - return 0; -} - -sub range_perfdata { - my ($self, %options) = @_; - - return if ($self->{range_perfdata} == 0); - if ($self->{range_perfdata} == 1) { - for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) { - ${${$options{ranges}}[$i]} =~ s/^(@?)-?[0\.]+:/$1/; - } - } else { - for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) { - ${${$options{ranges}}[$i]} = ''; - } - } -} - -sub output_json { - my ($self, %options) = @_; - my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; - my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; - my $json_content = { - plugin => { - name => $self->{plugin}, - mode => $self->{mode}, - exit => $options{exit_litteral}, - outputs => [], - perfdatas => [] - } - }; - - foreach my $code_litteral (keys %{$self->{global_short_outputs}}) { - foreach (@{$self->{global_short_outputs}->{$code_litteral}}) { - my ($child_output, $child_type, $child_msg, $child_exit); - my $lcode_litteral = ($code_litteral eq 'UNQUALIFIED_YET' ? uc($options{exit_litteral}) : $code_litteral); - - push @{$json_content->{plugin}->{outputs}}, { - type => 1, - msg => ($options{nolabel} == 0 ? ($lcode_litteral . ': ') : '') . $_, - exit => $lcode_litteral - }; - } - } - - if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { - foreach (@{$self->{global_long_output}}) { - push @{$json_content->{plugin}->{outputs}}, { - type => 2, - msg => $_ - }; - } - } - - if ($options{force_ignore_perfdata} == 0) { - $self->change_perfdata(); - foreach my $perf (@{$self->{perfdatas}}) { - next if ($self->filter_perfdata(perf => $perf)); - $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]); - - my %values = (); - foreach my $key (keys %$perf) { - $perf->{$key} = '' if (defined($self->{option_results}->{filter_uom}) && $key eq 'unit' && - $perf->{$key} !~ /$self->{option_results}->{filter_uom}/); - $values{$key} = $perf->{$key}; - } - - push @{$json_content->{plugin}->{perfdatas}}, { - %values - }; - } - } - - print $self->{json_output}->encode($json_content); -} - -sub output_xml { - my ($self, %options) = @_; - my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; - my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; - my ($child_plugin_name, $child_plugin_mode, $child_plugin_exit, $child_plugin_output, $child_plugin_perfdata); - - my $root = $self->{xml_output}->createElement('plugin'); - $self->{xml_output}->setDocumentElement($root); - - $child_plugin_name = $self->{xml_output}->createElement('name'); - $child_plugin_name->appendText($self->{plugin}); - - $child_plugin_mode = $self->{xml_output}->createElement('mode'); - $child_plugin_mode->appendText($self->{mode}); - - $child_plugin_exit = $self->{xml_output}->createElement('exit'); - $child_plugin_exit->appendText($options{exit_litteral}); - - $child_plugin_output = $self->{xml_output}->createElement('outputs'); - $child_plugin_perfdata = $self->{xml_output}->createElement('perfdatas'); - - $root->addChild($child_plugin_name); - $root->addChild($child_plugin_mode); - $root->addChild($child_plugin_exit); - $root->addChild($child_plugin_output); - $root->addChild($child_plugin_perfdata); - - foreach my $code_litteral (keys %{$self->{global_short_outputs}}) { - foreach (@{$self->{global_short_outputs}->{$code_litteral}}) { - my ($child_output, $child_type, $child_msg, $child_exit); - my $lcode_litteral = ($code_litteral eq 'UNQUALIFIED_YET' ? uc($options{exit_litteral}) : $code_litteral); - - $child_output = $self->{xml_output}->createElement('output'); - $child_plugin_output->addChild($child_output); - - $child_type = $self->{xml_output}->createElement('type'); - $child_type->appendText(1); # short - - $child_msg = $self->{xml_output}->createElement('msg'); - $child_msg->appendText(($options{nolabel} == 0 ? ($lcode_litteral . ': ') : '') . $_); - $child_exit = $self->{xml_output}->createElement('exit'); - $child_exit->appendText($lcode_litteral); - - $child_output->addChild($child_type); - $child_output->addChild($child_exit); - $child_output->addChild($child_msg); - } - } - - if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { - foreach (@{$self->{global_long_output}}) { - my ($child_output, $child_type, $child_msg); - - $child_output = $self->{xml_output}->createElement('output'); - $child_plugin_output->addChild($child_output); - - $child_type = $self->{xml_output}->createElement('type'); - $child_type->appendText(2); # long - - $child_msg = $self->{xml_output}->createElement('msg'); - $child_msg->appendText($_); - - $child_output->addChild($child_type); - $child_output->addChild($child_msg); - } - } - - if ($options{force_ignore_perfdata} == 0) { - $self->change_perfdata(); - foreach my $perf (@{$self->{perfdatas}}) { - next if ($self->filter_perfdata(perf => $perf)); - $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]); - - my ($child_perfdata); - $child_perfdata = $self->{xml_output}->createElement('perfdata'); - $child_plugin_perfdata->addChild($child_perfdata); - foreach my $key (keys %$perf) { - $perf->{$key} = '' if (defined($self->{option_results}->{filter_uom}) && $key eq 'unit' && - $perf->{$key} !~ /$self->{option_results}->{filter_uom}/); - my $child = $self->{xml_output}->createElement($key); - $child->appendText($perf->{$key}); - $child_perfdata->addChild($child); - } - } - } - - print $self->{xml_output}->toString(1); -} - -sub output_openmetrics { - my ($self, %options) = @_; - - centreon::plugins::misc::mymodule_load( - output => $self->{output}, module => 'Time::HiRes', - error_msg => "Cannot load module 'Time::HiRes'." - ); - - my $time_ms = int(Time::HiRes::time() * 1000); - $self->change_perfdata(); - - foreach my $perf (@{$self->{perfdatas}}) { - next if ($self->filter_perfdata(perf => $perf)); - - $perf->{unit} = '' if ( - defined($self->{option_results}->{filter_uom}) && - $perf->{unit} !~ /$self->{option_results}->{filter_uom}/ - ); - $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]); - my $label = $perf->{label}; - my $instance; - if ($label =~ /^(.*?)#(.*)$/) { - ($perf->{instance}, $label) = ($1, $2); - } - my ($bucket, $append) = ('{plugin="' . $self->{plugin} . '",mode="' . $perf->{mode} . '"', ''); - foreach ('unit', 'warning', 'critical', 'min', 'max', 'instance') { - if (defined($perf->{$_}) && $perf->{$_} ne '') { - $bucket .= ',' . $_ . '="' . $perf->{$_} . '"'; - } - } - $bucket .= '}'; - - print $label . $bucket . ' ' . $perf->{value} . ' ' . $time_ms . "\n"; - } -} - -sub output_txt_short_display { - my ($self, %options) = @_; - - if (defined($self->{global_short_concat_outputs}->{CRITICAL})) { - print (($options{nolabel} == 0 ? 'CRITICAL: ' : '') . $self->{global_short_concat_outputs}->{CRITICAL} . " "); - } - if (defined($self->{global_short_concat_outputs}->{WARNING})) { - print (($options{nolabel} == 0 ? 'WARNING: ' : '') . $self->{global_short_concat_outputs}->{WARNING} . " "); - } - if (defined($self->{global_short_concat_outputs}->{UNKNOWN})) { - print (($options{nolabel} == 0 ? 'UNKNOWN: ' : '') . $self->{global_short_concat_outputs}->{UNKNOWN} . " "); - } - if (uc($options{exit_litteral}) eq 'OK') { - print (($options{nolabel} == 0 ? 'OK: ' : '') . (defined($self->{global_short_concat_outputs}->{OK}) ? $self->{global_short_concat_outputs}->{OK} : '') . " "); - } -} - -sub output_txt_short { - my ($self, %options) = @_; - - if (!defined($self->{option_results}->{change_short_output})) { - $self->output_txt_short_display(%options); - return ; - } - - my $stdout = ''; - { - local *STDOUT; - open STDOUT, '>', \$stdout; - $self->output_txt_short_display(%options); - } - - foreach (@{$self->{option_results}->{change_short_output}}) { - my ($pattern, $replace, $modifier) = split /~/; - next if (!defined($pattern)); - $replace = '' if (!defined($replace)); - $modifier = '' if (!defined($modifier)); - eval "\$stdout =~ s{$pattern}{$replace}$modifier"; - } - - print $stdout; -} - -sub output_txt { - my ($self, %options) = @_; - my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; - my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; - - return if ($self->{nodisplay} == 1); - if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) { - $self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET}); - } - - $self->output_txt_short(%options); - - if ($force_ignore_perfdata == 0) { - my $pipe = 0; - $self->change_perfdata(); - foreach my $perf (@{$self->{perfdatas}}) { - next if ($self->filter_perfdata(perf => $perf)); - $perf->{unit} = '' if (defined($self->{option_results}->{filter_uom}) && - $perf->{unit} !~ /$self->{option_results}->{filter_uom}/); - $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]); - if ($pipe == 0) { - print '|'; - $pipe = 1; - } - print " '" . $perf->{label} . "'=" . $perf->{value} . $perf->{unit} . ';' . $perf->{warning} . ';' . $perf->{critical} . ';' . $perf->{min} . ';' . $perf->{max}; - } - } - - print "\n"; - - if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { - if (scalar(@{$self->{global_long_output}})) { - print join("\n", @{$self->{global_long_output}}); - print "\n"; - } - } -} - -sub change_long_output { - my ($self, %options) = @_; - - return if (!(defined($self->{option_results}->{verbose}) || $options{force_long_output} == 1)); - return if (!defined($self->{option_results}->{change_long_output})); - - my $long_output = join("\n", @{$self->{global_long_output}}); - - foreach (@{$self->{option_results}->{change_long_output}}) { - my ($pattern, $replace, $modifier) = split /~/; - next if (!defined($pattern)); - $replace = '' if (!defined($replace)); - $modifier = '' if (!defined($modifier)); - eval "\$long_output =~ s{$pattern}{$replace}$modifier"; - } - - $self->{global_long_output} = [split(/\n/, $long_output)]; -} - -sub display { - my ($self, %options) = @_; - my $nolabel = (defined($options{nolabel}) || defined($self->{option_results}->{output_ignore_label})) ? 1 : 0; - my $force_ignore_perfdata = ((defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) || $self->{option_results}->{output_ignore_perfdata}) ? 1 : 0; - my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; - $force_long_output = 1 if (defined($self->{option_results}->{debug})); - - if (defined($self->{option_results}->{output_openmetrics})) { - $self->perfdata_add(nlabel => 'plugin.mode.status', value => $self->{errors}->{$self->{myerrors}->{$self->{global_status}}}); - } - - if (defined($self->{option_results}->{change_long_output})) { - $self->change_long_output(force_long_output => $force_long_output); - } - - return if ($self->{nodisplay} == 1); - - if (defined($self->{option_results}->{output_file})) { - if (!open (STDOUT, '>', $self->{option_results}->{output_file})) { - $self->output_add( - severity => 'UNKNOWN', - short_msg => "cannot open file '" . $self->{option_results}->{output_file} . "': $!" - ); - } - } - if (defined($self->{option_results}->{output_xml})) { - $self->create_xml_document(); - if ($self->{is_output_xml}) { - $self->output_xml( - exit_litteral => $self->get_litteral_status(), - nolabel => $nolabel, - force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output - ); - return ; - } - } elsif (defined($self->{option_results}->{output_json})) { - $self->create_json_document(); - if ($self->{is_output_json}) { - $self->output_json( - exit_litteral => $self->get_litteral_status(), - nolabel => $nolabel, - force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output - ); - return ; - } - } elsif (defined($self->{option_results}->{output_openmetrics})) { - $self->output_openmetrics(); - return ; - } - - $self->output_txt( - exit_litteral => $self->get_litteral_status(), - nolabel => $nolabel, - force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output - ); -} - -sub die_exit { - my ($self, %options) = @_; - # $options{exit_litteral} = string litteral exit - # $options{nolabel} = interger label display - my $exit_litteral = defined($options{exit_litteral}) ? $options{exit_litteral} : $self->{option_results}->{opt_exit}; - my $nolabel = (defined($options{nolabel}) || defined($self->{option_results}->{output_ignore_label})) ? 1 : 0; - # ignore long output in the following case - $self->{option_results}->{verbose} = undef; - - if (defined($self->{option_results}->{output_xml})) { - $self->create_xml_document(); - if ($self->{is_output_xml}) { - $self->output_xml(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1); - $self->exit(exit_litteral => $exit_litteral); - } - } elsif (defined($self->{option_results}->{output_json})) { - $self->create_json_document(); - if ($self->{is_output_json}) { - $self->output_json(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1); - $self->exit(exit_litteral => $exit_litteral); - } - } - - $self->output_txt(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1); - $self->exit(exit_litteral => $exit_litteral); -} - -sub option_exit { - my ($self, %options) = @_; - # $options{exit_litteral} = string litteral exit - # $options{nolabel} = interger label display - my $exit_litteral = defined($options{exit_litteral}) ? $options{exit_litteral} : $self->{option_results}->{opt_exit}; - my $nolabel = (defined($options{nolabel}) || defined($self->{option_results}->{output_ignore_label})) ? 1 : 0; - - if (defined($self->{option_results}->{output_xml})) { - $self->create_xml_document(); - if ($self->{is_output_xml}) { - $self->output_xml(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1); - $self->exit(exit_litteral => $exit_litteral); - } - } elsif (defined($self->{option_results}->{output_json})) { - $self->create_json_document(); - if ($self->{is_output_json}) { - $self->output_json(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1); - $self->exit(exit_litteral => $exit_litteral); - } - } elsif (defined($self->{option_results}->{output_openmetrics})) { - $self->set_status(exit_litteral => $exit_litteral); - $self->output_openmetrics(); - $self->exit(exit_litteral => $exit_litteral); - } - - $self->output_txt(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1); - $self->exit(exit_litteral => $exit_litteral); -} - -sub exit { - my ($self, %options) = @_; - - if ($self->{noexit_die} == 1) { - die 'exit'; - } - - my $exit; - if (defined($options{exit_litteral})) { - $exit = uc($options{exit_litteral}); - } else { - $exit = $self->{myerrors}->{ $self->{global_status} }; - } - if (defined($self->{change_exit}) && defined($self->{change_exit}->{$exit})) { - $exit = $self->{change_exit}->{$exit}; - } - exit $self->{errors}->{$exit}; -} - -sub get_option { - my ($self, %options) = @_; - - return $self->{option_results}->{$options{option}}; -} - -sub get_most_critical { - my ($self, %options) = @_; - my $current_status = 0; # For 'OK' - - foreach (@{$options{status}}) { - if ($self->{myerrors_mask}->{uc($_)} > $current_status) { - $current_status = $self->{myerrors_mask}->{uc($_)}; - } - } - return $self->{myerrors}->{$current_status}; -} - -sub get_litteral_status { - my ($self, %options) = @_; - - if (defined($options{status})) { - if (defined($self->{errors_num}->{$options{status}})) { - return $self->{errors_num}->{$options{status}}; - } - return $options{status}; - } else { - return $self->{myerrors}->{$self->{global_status}}; - } -} - -sub is_status { - my ($self, %options) = @_; - # $options{value} = string status - # $options{litteral} = value is litteral - # $options{compare} = string status - - if (defined($options{litteral})) { - my $value = defined($options{value}) ? $options{value} : $self->get_litteral_status(); - - if (uc($value) eq uc($options{compare})) { - return 1; - } - return 0; - } - - my $value = defined($options{value}) ? $options{value} : $self->{global_status}; - my $dec_val = $self->{myerrors_mask}->{$value}; - my $lresult = $value & $dec_val; - # Need to manage 0 - if ($lresult > 0 || ($dec_val == 0 && $value == 0)) { - return 1; - } - return 0; -} - -sub is_litteral_status { - my ($self, %options) = @_; - # $options{status} = string status - - if (defined($self->{errors}->{uc($options{status})})) { - return 1; - } - - return 0; -} - -sub create_json_document { - my ($self) = @_; - - if (centreon::plugins::misc::mymodule_load( - no_quit => 1, module => 'JSON', - error_msg => "Cannot load module 'JSON'.") - ) { - print "Cannot load module 'JSON'\n"; - $self->exit(exit_litteral => 'unknown'); - } - $self->{is_output_json} = 1; - $self->{json_output} = JSON->new->utf8(); -} - -sub create_xml_document { - my ($self) = @_; - - if (centreon::plugins::misc::mymodule_load( - no_quit => 1, module => 'XML::LibXML', - error_msg => "Cannot load module 'XML::LibXML'.") - ) { - print "Cannot load module 'XML::LibXML'\n"; - $self->exit(exit_litteral => 'unknown'); - } - $self->{is_output_xml} = 1; - $self->{xml_output} = XML::LibXML::Document->new('1.0', 'utf-8'); -} - -sub plugin { - my ($self, %options) = @_; - # $options{name} = string name - - if (defined($options{name})) { - $self->{plugin} = $options{name}; - } - return $self->{plugin}; -} - -sub mode { - my ($self, %options) = @_; - - if (defined($options{name})) { - $self->{mode} = $options{name}; - } - return $self->{mode}; -} - -sub add_disco_format { - my ($self, %options) = @_; - - push @{$self->{disco_elements}}, @{$options{elements}}; -} - -sub display_disco_format { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{output_xml})) { - $self->create_xml_document(); - - my $root = $self->{xml_output}->createElement('data'); - $self->{xml_output}->setDocumentElement($root); - - foreach (@{$self->{disco_elements}}) { - my $child = $self->{xml_output}->createElement("element"); - $child->appendText($_); - $root->addChild($child); - } - - print $self->{xml_output}->toString(1); - } elsif (defined($self->{option_results}->{output_json})) { - $self->create_json_document(); - my $json_content = {data => [] }; - foreach (@{$self->{disco_elements}}) { - push @{$json_content->{data}}, $_; - } - - print $self->{json_output}->encode($json_content); - } -} - -sub display_disco_show { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{output_xml})) { - $self->create_xml_document(); - - my $root = $self->{xml_output}->createElement('data'); - $self->{xml_output}->setDocumentElement($root); - - foreach (@{$self->{disco_entries}}) { - my $child = $self->{xml_output}->createElement('label'); - foreach my $key (keys %$_) { - $child->setAttribute($key, $_->{$key}); - } - $root->addChild($child); - } - - print $self->{xml_output}->toString(1); - } elsif (defined($self->{option_results}->{output_json})) { - $self->create_json_document(); - my $json_content = {data => [] }; - foreach (@{$self->{disco_entries}}) { - my %values = (); - foreach my $key (keys %$_) { - $values{$key} = $_->{$key}; - } - push @{$json_content->{data}}, {%values}; - } - - print $self->{json_output}->encode($json_content); - } -} - -sub decode { - my ($self, $value) = @_; - - if ($self->{encode_import} == 0) { - # Some Perl version dont have the following module (like Perl 5.6.x) - my $rv = centreon::plugins::misc::mymodule_load( - no_quit => 1, - module => 'Encode', - error_msg => "Cannot load module 'Encode'." - ); - return $value if ($rv); - - $self->{encode_import} = 1; - eval '$self->{perlqq} = Encode::PERLQQ'; - } - - return centreon::plugins::misc::trim(Encode::decode($self->{source_encoding}, $value, $self->{perlqq})); -} - -sub parameter { - my ($self, %options) = @_; - - if (defined($options{attr})) { - $self->{$options{attr}} = $options{value}; - } - return $self->{$options{attr}}; -} - -sub add_disco_entry { - my ($self, %options) = @_; - - push @{$self->{disco_entries}}, {%options}; -} - -sub is_disco_format { - my ($self) = @_; - - if (defined($self->{option_results}->{disco_format})) { - return 1; - } - return 0; -} - -sub is_disco_show { - my ($self) = @_; - - if (defined($self->{option_results}->{disco_show})) { - return 1; - } - return 0; -} - -sub is_verbose { - my ($self) = @_; - - if (defined($self->{option_results}->{verbose})) { - return 1; - } - return 0; -} - -sub is_debug { - my ($self) = @_; - - if (defined($self->{option_results}->{debug}) || defined($self->{option_results}->{debug_stream})) { - return 1; - } - return 0; -} - -sub load_eval { - my ($self) = @_; - - my ($code) = centreon::plugins::misc::mymodule_load( - output => $self->{output}, module => 'Safe', - no_quit => 1 - ); - if ($code == 0) { - $self->{safe} = Safe->new(); - $self->{safe}->share('$values'); - $self->{safe}->share('$assign_var'); - $self->{safe}->share_from('centreon::plugins::misc', ['alert_triggered']); - } - - $self->{safe_test} = 1; -} - -sub test_eval { - my ($self, %options) = @_; - - $self->load_eval() if ($self->{safe_test} == 0); - - my $result; - if (defined($self->{safe})) { - our $values = $options{values}; - $result = $self->{safe}->reval($options{test}, 1); - if ($@) { - die 'Unsafe code evaluation: ' . $@; - } - } elsif (defined($options{values})) { - my $values = $options{values}; - { - local $SIG{__WARN__} = sub {}; # ignore - - $result = eval "$options{test}"; - if ($@) { - die 'Code evaluation error: ' . $@; - } - } - } - - return $result; -} - -sub open_eval { - my ($self, %options) = @_; - - $self->load_eval() if ($self->{safe_test} == 0); - our $values = $options{values}; - $self->{safe}->reval("$options{eval}", 1); - - return $values; -} - -sub assign_eval { - my ($self, %options) = @_; - - $self->load_eval() if ($self->{safe_test} == 0); - - our $assign_var; - if (defined($self->{safe})) { - our $values = $options{values}; - $self->{safe}->reval("\$assign_var = $options{eval}", 1); - if ($@) { - die 'Unsafe code evaluation: ' . $@; - } - } else { - my $values = $options{values}; - eval "\$assign_var = $options{eval}"; - } - - return $assign_var; -} - -sub use_new_perfdata { - my ($self, %options) = @_; - - $self->{option_results}->{use_new_perfdata} = $options{value} - if (defined($options{value})); - if (defined($self->{option_results}->{use_new_perfdata})) { - return 1; - } - return 0; -} - -sub get_instance_perfdata_separator { - my ($self) = @_; - - if (defined($self->{option_results}->{use_new_perfdata})) { - return '~'; - } - return '_'; -} - -sub parse_pfdata_scale { - my ($self, %options) = @_; - - # --extend-perfdata=traffic_in,,scale(Mbps),mbps - my $args = { unit => 'auto' }; - if ($options{args} =~ /^([KMGTPEkmgtpe])?(B|b|bps|Bps|b\/s|auto)$/) { - $args->{quantity} = defined($1) ? $1 : ''; - $args->{unit} = $2; - } elsif ($options{args} ne '') { - return 1; - } - - return (0, $args); -} - -sub parse_pfdata_math { - my ($self, %options) = @_; - - # --extend-perfdata=perfx,,math(current + 10 - 100, 1) - my $args = { math => undef, apply_threshold => 0 }; - my ($math, $apply_threshold) = split /\|/, $options{args}; - if ($math =~ /^((?:[\s\.\-\+\*\/0-9\(\)]|current)+)$/) { - $args->{math} = $1; - } elsif ($options{args} ne '') { - return 1; - } - - if (defined($apply_threshold) && $apply_threshold =~ /^\s*(0|1)\s*$/ ) { - $args->{apply_threshold} = $1; - } - - return (0, $args); -} - -sub parse_pfdata_eval { - my ($self, %options) = @_; - - # --extend-perfdata=perfx,,eval(%(label) =~ s/a/A/g) - my $args = { expr => $options{args} }; - $args->{expr} =~ s/%\{(.*?)\}/\$values->{$1}/g; - $args->{expr} =~ s/%\((.*?)\)/\$values->{$1}/g; - return (0, $args); -} - -sub parse_group_pfdata { - my ($self, %options) = @_; - - $options{args} =~ s/^\s+//; - $options{args} =~ s/\s+$//; - my $args = { pattern_pf => $options{args} }; - return $args; -} - -sub parse_pfdata_min { - my ($self, %options) = @_; - - my $args = $self->parse_group_pfdata(%options); - return (0, $args); -} - -sub parse_pfdata_max { - my ($self, %options) = @_; - - my $args = $self->parse_group_pfdata(%options); - return (0, $args); -} - -sub parse_pfdata_average { - my ($self, %options) = @_; - - my $args = $self->parse_group_pfdata(%options); - return (0, $args); -} - -sub parse_pfdata_sum { - my ($self, %options) = @_; - - my $args = $self->parse_group_pfdata(%options); - return (0, $args); -} - -sub apply_pfdata_scale { - my ($self, %options) = @_; - - return if (${$options{perf}}->{unit} !~ /^([KMGTPEkmgtpe])?(B|b|bps|Bps|b\/s)$/); - - my ($src_quantity, $src_unit) = ($1, $2); - my ($value, $dst_quantity, $dst_unit) = centreon::plugins::misc::scale_bytesbit( - value => ${$options{perf}}->{value}, - src_quantity => $src_quantity, src_unit => $src_unit, dst_quantity => $options{args}->{quantity}, dst_unit => $options{args}->{unit} - ); - ${$options{perf}}->{value} = sprintf('%.2f', $value); - if (defined($dst_unit)) { - ${$options{perf}}->{unit} = $dst_quantity . $dst_unit; - } else { - ${$options{perf}}->{unit} = $options{args}->{quantity} . $options{args}->{unit}; - } - - if (defined(${$options{perf}}->{max}) && ${$options{perf}}->{max} ne '') { - ($value) = centreon::plugins::misc::scale_bytesbit(value => ${$options{perf}}->{max}, - src_quantity => $src_quantity, src_unit => $src_unit, - dst_quantity => defined($dst_unit) ? $dst_quantity : $options{args}->{quantity}, - dst_unit => defined($dst_unit) ? $dst_unit : $options{args}->{unit}); - ${$options{perf}}->{max} = sprintf('%.2f', $value); - } - - foreach my $threshold ('warning', 'critical') { - next if (${$options{perf}}->{$threshold} eq ''); - my ($status, $result) = centreon::plugins::misc::parse_threshold(threshold => ${$options{perf}}->{$threshold}); - next if ($status == 0); - - if ($result->{start} ne '' && $result->{infinite_neg} == 0) { - ($result->{start}) = centreon::plugins::misc::scale_bytesbit(value => $result->{start}, - src_quantity => $src_quantity, src_unit => $src_unit, - dst_quantity => defined($dst_unit) ? $dst_quantity : $options{args}->{quantity}, - dst_unit => defined($dst_unit) ? $dst_unit : $options{args}->{unit}); - } - if ($result->{end} ne '' && $result->{infinite_pos} == 0) { - ($result->{end}) = centreon::plugins::misc::scale_bytesbit(value => $result->{end}, - src_quantity => $src_quantity, src_unit => $src_unit, - dst_quantity => defined($dst_unit) ? $dst_quantity : $options{args}->{quantity}, - dst_unit => defined($dst_unit) ? $dst_unit : $options{args}->{unit}); - } - - ${$options{perf}}->{$threshold} = centreon::plugins::misc::get_threshold_litteral(%$result); - } -} - -sub apply_pfdata_invert { - my ($self, %options) = @_; - - return if (!defined(${$options{perf}}->{max}) || ${$options{perf}}->{max} eq ''); - - ${$options{perf}}->{value} = ${$options{perf}}->{max} - ${$options{perf}}->{value}; - foreach my $threshold ('warning', 'critical') { - next if (${$options{perf}}->{$threshold} eq ''); - my ($status, $result) = centreon::plugins::misc::parse_threshold(threshold => ${$options{perf}}->{$threshold}); - next if ($status == 0); - - my $tmp = { arobase => $result->{arobase}, infinite_pos => 0, infinite_neg => 0, start => $result->{start}, end => $result->{end} }; - $tmp->{infinite_neg} = 1 if ($result->{infinite_pos} == 1); - $tmp->{infinite_pos} = 1 if ($result->{infinite_neg} == 1); - - if ($result->{start} ne '' && $result->{infinite_neg} == 0) { - $tmp->{end} = ${$options{perf}}->{max} - $result->{start}; - } - if ($result->{end} ne '' && $result->{infinite_pos} == 0) { - $tmp->{start} = ${$options{perf}}->{max} - $result->{end}; - } - - ${$options{perf}}->{$threshold} = centreon::plugins::misc::get_threshold_litteral(%$tmp); - } -} - -sub apply_pfdata_percent { - my ($self, %options) = @_; - - return if (!defined(${$options{perf}}->{max}) || ${$options{perf}}->{max} eq ''); - - ${$options{perf}}->{value} = sprintf('%.2f', ${$options{perf}}->{value} * 100 / ${$options{perf}}->{max}); - ${$options{perf}}->{unit} = '%'; - foreach my $threshold ('warning', 'critical') { - next if (${$options{perf}}->{$threshold} eq ''); - my ($status, $result) = centreon::plugins::misc::parse_threshold(threshold => ${$options{perf}}->{$threshold}); - next if ($status == 0); - - if ($result->{start} ne '' && $result->{infinite_neg} == 0) { - $result->{start} = sprintf('%.2f', $result->{start} * 100 / ${$options{perf}}->{max}); - } - if ($result->{end} ne '' && $result->{infinite_pos} == 0) { - $result->{end} = sprintf('%.2f', $result->{end} * 100 / ${$options{perf}}->{max}); - } - - ${$options{perf}}->{$threshold} = centreon::plugins::misc::get_threshold_litteral(%$result); - } - - ${$options{perf}}->{max} = 100; -} - -sub apply_pfdata_eval { - my ($self, %options) = @_; - - ${$options{perf}} = $self->open_eval(eval => $options{args}->{expr}, values => ${$options{perf}}); -} - -sub apply_pfdata_math { - my ($self, %options) = @_; - - my $math = $options{args}->{math}; - $math =~ s/current/\$value/g; - - my $value = ${$options{perf}}->{value}; - eval "\${\$options{perf}}->{value} = $math"; - - return if ($options{args}->{apply_threshold} == 0); - - foreach my $threshold ('warning', 'critical') { - next if (${$options{perf}}->{$threshold} eq ''); - my ($status, $result) = centreon::plugins::misc::parse_threshold(threshold => ${$options{perf}}->{$threshold}); - next if ($status == 0); - - if ($result->{start} ne '' && $result->{infinite_neg} == 0) { - $value = $result->{start}; - eval "\$result->{start} = $math"; - } - if ($result->{end} ne '' && $result->{infinite_pos} == 0) { - $value = $result->{end}; - eval "\$result->{end} = $math"; - } - - ${$options{perf}}->{$threshold} = centreon::plugins::misc::get_threshold_litteral(%$result); - } - - ${$options{perf}}->{max} = 100; -} - -sub apply_pfdata_min { - my ($self, %options) = @_; - - my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\""); - my $min; - for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { - next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); - next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); - $min = $self->{perfdatas}->[$i]->{value} - if (!defined($min) || $min > $self->{perfdatas}->[$i]->{value}); - } - - ${$options{perf}}->{value} = $min - if (defined($min)); -} - -sub apply_pfdata_max { - my ($self, %options) = @_; - - my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\""); - my $max; - for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { - next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); - next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); - $max = $self->{perfdatas}->[$i]->{value} - if (!defined($max) || $max < $self->{perfdatas}->[$i]->{value}); - } - - ${$options{perf}}->{value} = $max - if (defined($max)); -} - -sub apply_pfdata_sum { - my ($self, %options) = @_; - - my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\""); - my ($sum, $num) = (0, 0); - for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { - next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); - next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); - $sum += $self->{perfdatas}->[$i]->{value}; - $num++; - } - - ${$options{perf}}->{value} = $sum - if ($num > 0); -} - -sub apply_pfdata_average { - my ($self, %options) = @_; - - my $pattern_pf = $self->assign_eval(eval => "\"$options{args}->{pattern_pf}\""); - my ($sum, $num) = (0, 0); - for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { - next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); - next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); - $sum += $self->{perfdatas}->[$i]->{value}; - $num++; - } - - ${$options{perf}}->{value} = sprintf("%.2f", ($sum / $num)) - if ($num > 0); -} - -sub apply_perfdata_thresholds { - my ($self, %options) = @_; - - foreach (('warning', 'critical')) { - next if (!defined($options{$_})); - - my @thresholds = split(':', $options{$_}, -1); - for (my $i = 0; $i < scalar(@thresholds); $i++) { - if ($thresholds[$i] =~ /(\d+(?:\.\d+)?)\s*%/) { - if (!defined($options{max}) || $options{max} eq '') { - $thresholds[$i] = ''; - next; - } - $thresholds[$i] = $1 * $options{max} / 100; - } elsif ($thresholds[$i] =~ /(\d+(?:\.\d+)?)/) { - $thresholds[$i] = $1; - } else { - $thresholds[$i] = ''; - } - } - - ${$options{perf}}->{$_} = join(':', @thresholds); - } -} - -sub load_perfdata_extend_args { - my ($self, %options) = @_; - - foreach ( - [$self->{option_results}->{change_perfdata}, 1], - [$self->{option_results}->{extend_perfdata}, 2], - [$self->{option_results}->{extend_perfdata_group}, 3], - ) { - next if (!defined($_->[0])); - foreach my $arg (@{$_->[0]}) { - $self->parse_perfdata_extend_args(arg => $arg, type => $_->[1]); - } - } -} - -sub parse_perfdata_extend_args { - my ($self, %options) = @_; - - # --extend-perfdata=searchlabel,newlabel,method[,[newuom],[min],[max],[warning],[critical]] - my ($pfdata_match, $pfdata_substitute, $method, $uom_sub, $min_sub, $max_sub, $warn_sub, $crit_sub) = - split /,/, $options{arg}; - return if ((!defined($pfdata_match) || $pfdata_match eq '') && $options{type} != 3); - - $self->{pfdata_extends} = [] if (!defined($self->{pfdata_extends})); - my $pfdata_extends = { - pfdata_match => defined($pfdata_match) && $pfdata_match ne '' ? $pfdata_match : undef, - pfdata_substitute => defined($pfdata_substitute) && $pfdata_substitute ne '' ? $pfdata_substitute : undef, - uom_sub => defined($uom_sub) && $uom_sub ne '' ? $uom_sub : undef, - min_sub => defined($min_sub) && $min_sub ne '' ? $min_sub : undef, - max_sub => defined($max_sub) && $max_sub ne '' ? $max_sub : undef, - warn_sub => defined($warn_sub) && $warn_sub ne '' ? $warn_sub : undef, - crit_sub => defined($crit_sub) && $crit_sub ne '' ? $crit_sub : undef, - type => $options{type} - }; - - if (defined($method) && $method ne '') { - if ($method !~ /^\s*(invert|percent|scale|math|min|max|average|sum|eval)\s*\(\s*(.*?)\s*\)\s*$/) { - $self->output_add(long_msg => "method in argument '$options{arg}' is unknown", debug => 1); - return ; - } - - $pfdata_extends->{method_name} = $1; - my $args = $2; - if (my $func = $self->can('parse_pfdata_' . $pfdata_extends->{method_name})) { - (my $status, $pfdata_extends->{method_args}) = $func->($self, args => $args); - if ($status == 1) { - $self->output_add(long_msg => "argument in method '$options{arg}' is unknown", debug => 1); - return ; - } - } - } - - push @{$self->{pfdata_extends}}, $pfdata_extends; -} - -sub apply_perfdata_explode { - my ($self, %options) = @_; - - return if ($self->{explode_perfdata_total} == 0); - foreach (@{$self->{perfdatas}}) { - next if ($_->{max} eq ''); - if ($self->{explode_perfdata_total} == 2) { - $self->perfdata_add(label => $_->{label} . '_max', value => $_->{max}, unit => $_->{unit}); - next; - } - foreach my $regexp (keys %{$self->{explode_perfdatas}}) { - if ($_->{label} =~ /$regexp/) { - $self->perfdata_add(label => $self->{explode_perfdatas}->{$regexp}, value => $_->{max}, unit => $_->{unit}); - last; - } - } - } -} - -sub apply_perfdata_extend { - my ($self, %options) = @_; - - foreach my $extend (@{$self->{pfdata_extends}}) { - my $new_pfdata = []; - - # Manage special case when type group and pfdata_match empty - if ($extend->{type} == 3 && (!defined($extend->{pfdata_match}) || $extend->{pfdata_match} eq '')) { - next if (!defined($extend->{pfdata_substitute}) || $extend->{pfdata_substitute} eq ''); - my $new_perf = { - label => $extend->{pfdata_substitute}, value => '', - unit => defined($extend->{uom_sub}) ? $extend->{uom_sub} : '', - warning => '', critical => '', - min => defined($extend->{min_sub}) ? $extend->{min_sub} : '', - max => defined($extend->{max_sub}) ? $extend->{max_sub} : '' - }; - - if (defined($extend->{method_name})) { - my $func = $self->can('apply_pfdata_' . $extend->{method_name}); - $func->($self, perf => \$new_perf, args => $extend->{method_args}); - } - - $self->apply_perfdata_thresholds( - perf => \$new_perf, - warning => $extend->{warn_sub}, - critical => $extend->{crit_sub}, - max => $new_perf->{max} - ); - if (length($new_perf->{value})) { - push @{$self->{perfdatas}}, $new_perf; - } - next; - } - - for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { - next if ($self->{perfdatas}->[$i]->{label} !~ /$extend->{pfdata_match}/); - - my $new_perf = { %{$self->{perfdatas}->[$i]} }; - if ($extend->{type} == 3) { - $new_perf = { label => $self->{perfdatas}->[$i]->{label}, value => '', unit => '', warning => '', critical => '', min => '', max => '' }; - } - - if (defined($extend->{pfdata_substitute})) { - eval "\$new_perf->{label} =~ s{$extend->{pfdata_match}}{$extend->{pfdata_substitute}}"; - } - - if (defined($extend->{method_name})) { - my $func = $self->can('apply_pfdata_' . $extend->{method_name}); - $func->($self, perf => \$new_perf, args => $extend->{method_args}); - } - - $new_perf->{unit} = $extend->{uom_sub} if (defined($extend->{uom_sub})); - $new_perf->{min} = $extend->{min_sub} if (defined($extend->{min_sub})); - $new_perf->{max} = $extend->{max_sub} if (defined($extend->{max_sub})); - $self->apply_perfdata_thresholds( - perf => \$new_perf, - warning => $extend->{warn_sub}, - critical => $extend->{crit_sub}, - max => $new_perf->{max} - ); - - if ($extend->{type} == 1) { - $self->{perfdatas}->[$i] = $new_perf; - } else { - push @$new_pfdata, $new_perf if (length($new_perf->{value})); - } - } - - push @{$self->{perfdatas}}, @$new_pfdata; - } -} - -sub change_perfdata { - my ($self, %options) = @_; - - $self->apply_perfdata_extend(); - $self->apply_perfdata_explode(); -} - -1; - -__END__ - -=head1 NAME - -Output class - -=head1 SYNOPSIS - -- - -=head1 OUTPUT OPTIONS - -=over 8 - -=item B<--verbose> - -Display verbse extended status information (long output). - -=item B<--debug> - -Display debug messages. - -=item B<--filter-perfdata> - -Filter perfdata that match the regexp. -Example: adding --filter-perfdata='avg' will remove all metrics that do not contain -'avg' from performance data. - -=item B<--filter-perfdata-adv> - -Filter perfdata based on a "if" condition using the following variables: -label, value, unit, warning, critical, min, max. -Variables must be written either %{variable} or %(variable). -Example: adding --filter-perfdata-adv='not (%(value) == 0 and %(max) eq "")' will -remove all metrics whose value equals 0 and that don't have a maximum value. - -=item B<--explode-perfdata-max> - -Create a new metric for each metric that comes with a maximum limit. The new -metric will be named identically with a '_max' suffix). -Example: it will split 'used_prct'=26.93%;0:80;0:90;0;100 -into 'used_prct'=26.93%;0:80;0:90;0;100 'used_prct_max'=100%;;;; - - -=item B<--change-perfdata> B<--extend-perfdata> - -Change or extend perfdata. -Syntax: --extend-perfdata=searchlabel,newlabel,target[,[newuom],[min],[max]] - -Common examples: - -=over 4 - -Convert storage free perfdata into used: --change-perfdata=free,used,invert() - -Convert storage free perfdata into used: --change-perfdata=used,free,invert() - -Scale traffic values automatically: --change-perfdata=traffic,,scale(auto) - -Scale traffic values in Mbps: --change-perfdata=traffic_in,,scale(Mbps),mbps - -Change traffic values in percent: --change-perfdata=traffic_in,,percent() - -=back - -=item B<--extend-perfdata-group> - -Add new aggregated metrics (min, max, average or sum) for groups of metrics defined by a regex match on the metrics' names. -Syntax: --extend-perfdata-group=regex,namesofnewmetrics,calculation[,[newuom],[min],[max]] -regex: regular expression -namesofnewmetrics: how the new metrics' names are composed (can use $1, $2... for groups defined by () in regex). -calculation: how the values of the new metrics should be calculated -newuom (optional): unit of measure for the new metrics -min (optional): lowest value the metrics can reach -max (optional): highest value the metrics can reach - -Common examples: - -=over 4 - -Sum wrong packets from all interfaces (with interface need --units-errors=absolute): --extend-perfdata-group=',packets_wrong,sum(packets_(discard|error)_(in|out))' - -Sum traffic by interface: --extend-perfdata-group='traffic_in_(.*),traffic_$1,sum(traffic_(in|out)_$1)' - -=back - -=item B<--change-short-output> B<--change-long-output> - -Modify the short/long output that is returned by the plugin. -Syntax: --change-short-output=pattern~replacement~modifier -Most commonly used modifiers are i (case insensitive) and g (replace all occurrences). -Example: adding --change-short-output='OK~Up~gi' will replace all occurrences of 'OK', 'ok', 'Ok' or 'oK' with 'Up' - -=item B<--change-exit> - -Replace an exit code with one of your choice. -Example: adding --change-exit=unknown=critical will result in a CRITICAL state -instead of an UNKNOWN state. - -=item B<--range-perfdata> - -Rewrite the ranges displayed in the perfdata. Accepted values: -0: nothing is changed. -1: if the lower value of the range is equal to 0, it is removed. -2: remove the thresholds from the perfdata. - -=item B<--filter-uom> - -Mask the units when they don't match the given regular expression. - -=item B<--opt-exit> - -Replace the exit code in case of an execution error (i.e. wrong option provided, -SSH connection refused, timeout, etc). Default: unknonw. - -=item B<--output-ignore-perfdata> - -Remove all the metrics from the service. The service will still have a status -and an output. - -=item B<--output-ignore-label> - -Remove the status label ("OK:", "WARNING:", "UNKNOWN:", CRITICAL:") from the -beginning of the output. -Example: 'OK: Ram Total:...' will become 'Ram Total:...' - -=item B<--output-xml> - -Return the output in XML format (to send to an XML API). - -=item B<--output-json> - -Return the output in JSON format (to send to a JSON API). - -=item B<--output-openmetrics> - -Return the output in OpenMetrics format (to send to a tool expecting this -format). - -=item B<--output-file> - -Write output in file (can be combined with json, xml and openmetrics options). -E.g.: --output-file=/tmp/output.txt will write the output in /tmp/output.txt. - -=item B<--disco-format> - -Applies only to modes beginning with 'list-'. -Returns the list of available macros to configure a service discovery rule -(formatted in XML). - -=item B<--disco-show> - -Applies only to modes beginning with 'list-'. -Returns the list of discovered objects (formatted in XML) for service discovery. - -=item B<--float-precision> - -Define the float precision for thresholds (default: 8). - -=item B<--source-encoding> - -Define the character encoding of the response sent by the monitored resource -Default: 'UTF-8'. - -=head1 DESCRIPTION - -B. - -=cut diff --git a/src/os/as400/connector/mode/jobs_corrupted.pm b/src/os/as400/connector/mode/jobs_corrupted.pm deleted file mode 100644 index 6664752608..0000000000 --- a/src/os/as400/connector/mode/jobs_corrupted.pm +++ /dev/null @@ -1,134 +0,0 @@ -# -# Copyright 2023 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::as400::connector::mode::jobs; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 0, skipped_code => { -10 => 1 } } - ]; - - $self->{maps_counters}->{global} = [ - { label => 'jobs-total', nlabel => 'jobs.total.count', set => { - key_values => [ { name => 'total' } ], - output_template => 'number of jobs: %s', - perfdatas => [ - { template => '%s', min => 0 } - ] - } - } - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); - bless $self, $class; - - $options{options}->add_options(arguments => { - 'filter-active-status:s' => { name => 'filter_active_status' }, - 'filter-name:s' => { name => 'filter_name' }, - 'filter-subsystem:s' => { name => 'filter_subsystem' }, - 'display-jobs' => { name => 'display_jobs' } - }); - - return $self; -} - -sub manage_selection { - my ($self, %options) = @_; - - my $jobs = $options{custom}->request_api(command => 'listJobs'); - - $self->{global} = { total => 0 }; - foreach my $entry (@{$jobs->{result}}) { - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $entry->{name} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (name).", debug => 1); - next; - } - if (defined($self->{option_results}->{filter_subsystem}) && $self->{option_results}->{filter_subsystem} ne '' && - $entry->{subSystem} !~ /$self->{option_results}->{filter_subsystem}/) { - $self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (subsystem).", debug => 1); - next; - } - if (defined($self->{option_results}->{filter_active_status}) && $self->{option_results}->{filter_active_status} ne '' && - $entry->{activeStatus} !~ /$self->{option_results}->{filter_active_status}/) { - $self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (activeStatus).", debug => 1); - next; - } - - if (defined($self->{option_results}->{display_jobs})) { - $self->{output}->output_add( - long_msg => sprintf( - 'job %s [subsystem: %s] [active status: %s]', - $entry->{name}, - $entry->{subSystem}, - $entry->{activeStatus} - ) - ); - } - - $self->{global}->{total}++; - } -} - -1; - -__END__ - -=head1 MODE - -Check active jobz. - -=over 8 - -=item B<--filter-active-status> - -Filter jobs by ACTIVE_JOB_STATUS (can be a regexp). -Example: --filter-active-status='MSGW' to count jobs with MSGW. - -=item B<--filter-name> - -Filter jobs by name (can be a regexp). - -=item B<--filter-subsystem> - -Filter jobs by subsystem (can be a regexp). - -=item B<--display-jobs> - -Display jobs in vrbose output. - -=item B<--warning-*> B<--critical-*> - -Thresholds. -Can be: 'jobs-total'. - -=back - -=cut diff --git a/src/snmp_standard/mode/ntp_corrupted.pm b/src/snmp_standard/mode/ntp_corrupted.pm deleted file mode 100644 index a2f80d0cc1..0000000000 --- a/src/snmp_standard/mode/ntp_corrupted.pm +++ /dev/null @@ -1,228 +0,0 @@ -# -# Copyright 2023 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::ntp; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::misc; -use DateTime; - -sub custom_usage_output { - my ($self, %options) = @_; - - return sprintf( - 'Time offset %d second(s): %s', - $self->{result_values}->{offset}, - $self->{result_values}->{date} - ); -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'offset', type => 0 } - ]; - - $self->{maps_counters}->{offset} = [ - { label => 'offset', nlabel => 'time.offset.seconds', set => { - key_values => [ { name => 'offset' }, { name => 'date' } ], - closure_custom_output => $self->can('custom_usage_output'), - perfdatas => [ - { label => 'offset', template => '%d', unit => 's' } - ] - } - } - ]; -} - -sub default_date_oid { - my ($self, %options) = @_; - - return '.1.3.6.1.2.1.25.1.2.0'; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => { - 'oid:s' => { name => 'oid' }, - 'ntp-hostname:s' => { name => 'ntp_hostname' }, - 'ntp-port:s' => { name => 'ntp_port', default => 123 }, - 'timezone:s' => { name => 'timezone' } - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - if (defined($self->{option_results}->{ntp_hostname})) { - centreon::plugins::misc::mymodule_load( - output => $self->{output}, module => 'Net::NTP', - error_msg => "Cannot load module 'Net::NTP'." - ); - } -} - -sub get_from_epoch { - my ($self, %options) = @_; - - my $timezone = 'UTC'; - if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { - $timezone = $self->{option_results}->{timezone}; - } - - my $tz = centreon::plugins::misc::set_timezone(name => $timezone); - my $dt = DateTime->from_epoch( - epoch => $options{date}, - %$tz - ); - my @remote_date = ($dt->year, $dt->month, $dt->day, $dt->hour, $dt->minute, $dt->second); - return ($dt->epoch, \@remote_date, $timezone); -} - -sub get_from_datetime { - my ($self, %options) = @_; - - my @remote_date = unpack('n C6 a C2', $options{date}); - my $timezone = 'UTC'; - if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { - $timezone = $self->{option_results}->{timezone}; - } elsif (defined($remote_date[9])) { - $timezone = sprintf('%s%02d%02d', $remote_date[7], $remote_date[8], $remote_date[9]); # format +0630 - } - - my $tz = centreon::plugins::misc::set_timezone(name => $timezone); - my $dt = DateTime->new( - year => $remote_date[0], - month => $remote_date[1], - day => $remote_date[2], - hour => $remote_date[3], - minute => $remote_date[4], - second => $remote_date[5], - %$tz - ); - - return ($dt->epoch, \@remote_date, $timezone); -} - -sub get_target_time { - my ($self, %options) = @_; - - my $oid_date = $self->default_date_oid(); - if (defined($self->{option_results}->{oid}) && $self->{option_results}->{oid} ne '') { - $oid_date = $self->{option_results}->{oid}; - } - my $result = $options{snmp}->get_leef(oids => [ $oid_date ], nothing_quit => 1); - - if ($result->{$oid_date} =~ /^[0-9]{10}$/) { - return $self->get_from_epoch(date => $result->{$oid_date}); - } - - return $self->get_from_datetime(date => $result->{$oid_date}); -} - -sub manage_selection { - my ($self, %options) = @_; - - my ($distant_time, $remote_date, $timezone) = $self->get_target_time(%options); - if ($distant_time == 0) { - $self->{output}->add_option_msg(short_msg => "Couldn't get system date: local time: 0"); - $self->{output}->option_exit(); - } - - my $ref_time; - if (defined($self->{option_results}->{ntp_hostname}) && $self->{option_results}->{ntp_hostname} ne '') { - my %ntp; - - eval { - %ntp = Net::NTP::get_ntp_response($self->{option_results}->{ntp_hostname}, $self->{option_results}->{ntp_port}); - }; - if ($@) { - $self->{output}->add_option_msg(short_msg => "Couldn't connect to ntp server: " . $@); - $self->{output}->option_exit(); - } - - $ref_time = $ntp{'Transmit Timestamp'}; - } else { - $ref_time = time(); - } - - my $offset = $distant_time - $ref_time; - my $remote_date_formated = sprintf( - 'Local Time : %02d-%02d-%02dT%02d:%02d:%02d (%s)', - $remote_date->[0], $remote_date->[1], $remote_date->[2], - $remote_date->[3], $remote_date->[4], $remote_date->[5], $timezone - ); - - $self->{offset} = { - offset => sprintf('%d', $offset), - date => $remote_date_formated - }; -} - -1; - -__END__ - -=head1 MODE - -Check time offset of server with ntp server. Use local time if ntp-host option is not set. -SNMP gives a date with second precision (no milliseconds). Time precision is not very accurate. -Use threshold with (+-) 2 seconds offset (minimum). - -=over 8 - -=item B<--oid> - -Override default OID. - -=item B<--warning-offset> - -Time offset warning threshold (in seconds). - -=item B<--critical-offset> - -Time offset critical Threshold (in seconds). - -=item B<--ntp-hostname> - -Set the ntp hostname (if not set, localtime is used). - -=item B<--ntp-port> - -Set the ntp port (default: 123). - -=item B<--timezone> - -Set the timezone of distant server. For Windows, you need to set it. -Can use format: 'Europe/London' or '+0100'. - -=back - -=cut From a18c2e8c7b58d1b00e83aaa1d2dfbdef47742dee Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Fri, 22 Dec 2023 11:18:57 +0100 Subject: [PATCH 17/35] Cpu changes --- src/snmp_standard/mode/cpu.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snmp_standard/mode/cpu.pm b/src/snmp_standard/mode/cpu.pm index 140248c6cd..2ec2e3dbdb 100644 --- a/src/snmp_standard/mode/cpu.pm +++ b/src/snmp_standard/mode/cpu.pm @@ -154,7 +154,7 @@ Warning thresholds for each CPU core =item B<--critical-core> -Critical thresholds for each CPU core. +Critical thresholds for each CPU core =back From 41d56187e1b2ed93507706df4dc0068e0b0e20a6 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Fri, 22 Dec 2023 11:19:51 +0100 Subject: [PATCH 18/35] Test ok check --- src/snmp_standard/mode/cpu.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/snmp_standard/mode/cpu.pm b/src/snmp_standard/mode/cpu.pm index 2ec2e3dbdb..bd8ec9e2a9 100644 --- a/src/snmp_standard/mode/cpu.pm +++ b/src/snmp_standard/mode/cpu.pm @@ -150,11 +150,11 @@ Critical threshold average CPU utilization. =item B<--warning-core> -Warning thresholds for each CPU core +Warning thresholds for each CPU core. =item B<--critical-core> -Critical thresholds for each CPU core +Critical thresholds for each CPU core. =back From b06d9ebb96a1583d247084d700be0b2d516a3b35 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Fri, 22 Dec 2023 11:22:46 +0100 Subject: [PATCH 19/35] Test ok check --- src/os/linux/local/mode/cpu.pm | 4 ++-- src/snmp_standard/mode/cpu.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/os/linux/local/mode/cpu.pm b/src/os/linux/local/mode/cpu.pm index a562ddab58..4bef9f9b4e 100644 --- a/src/os/linux/local/mode/cpu.pm +++ b/src/os/linux/local/mode/cpu.pm @@ -201,11 +201,11 @@ Critical threshold average CPU utilization. =item B<--warning-core> -Warning thresholds for each CPU core +Warning thresholds for each CPU core. =item B<--critical-core> -Critical thresholds for each CPU core +Critical thresholds for each CPU core. =back diff --git a/src/snmp_standard/mode/cpu.pm b/src/snmp_standard/mode/cpu.pm index bd8ec9e2a9..2ec2e3dbdb 100644 --- a/src/snmp_standard/mode/cpu.pm +++ b/src/snmp_standard/mode/cpu.pm @@ -150,11 +150,11 @@ Critical threshold average CPU utilization. =item B<--warning-core> -Warning thresholds for each CPU core. +Warning thresholds for each CPU core =item B<--critical-core> -Critical thresholds for each CPU core. +Critical thresholds for each CPU core =back From 2d5a96f6629a74d1f88c34a12af8c137d0932e03 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Fri, 22 Dec 2023 11:25:24 +0100 Subject: [PATCH 20/35] Test ok check --- src/os/linux/local/mode/cpu.pm | 4 ++-- src/os/linux/local/mode/listinterfaces.pm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/os/linux/local/mode/cpu.pm b/src/os/linux/local/mode/cpu.pm index 4bef9f9b4e..a562ddab58 100644 --- a/src/os/linux/local/mode/cpu.pm +++ b/src/os/linux/local/mode/cpu.pm @@ -201,11 +201,11 @@ Critical threshold average CPU utilization. =item B<--warning-core> -Warning thresholds for each CPU core. +Warning thresholds for each CPU core =item B<--critical-core> -Critical thresholds for each CPU core. +Critical thresholds for each CPU core =back diff --git a/src/os/linux/local/mode/listinterfaces.pm b/src/os/linux/local/mode/listinterfaces.pm index 42bdac479b..e8fbca82a5 100644 --- a/src/os/linux/local/mode/listinterfaces.pm +++ b/src/os/linux/local/mode/listinterfaces.pm @@ -144,7 +144,7 @@ __END__ =head1 MODE -List storages. +List storages Command used: /sbin/ip -s addr 2>&1 From a499b05fc33ad1b0cf8b682108d76220963313ea Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Fri, 22 Dec 2023 11:30:51 +0100 Subject: [PATCH 21/35] Test ok check --- src/os/linux/local/mode/listinterfaces.pm | 2 +- src/os/windows/snmp/mode/listservices.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/linux/local/mode/listinterfaces.pm b/src/os/linux/local/mode/listinterfaces.pm index e8fbca82a5..42bdac479b 100644 --- a/src/os/linux/local/mode/listinterfaces.pm +++ b/src/os/linux/local/mode/listinterfaces.pm @@ -144,7 +144,7 @@ __END__ =head1 MODE -List storages +List storages. Command used: /sbin/ip -s addr 2>&1 diff --git a/src/os/windows/snmp/mode/listservices.pm b/src/os/windows/snmp/mode/listservices.pm index 8816071abf..4578e68240 100644 --- a/src/os/windows/snmp/mode/listservices.pm +++ b/src/os/windows/snmp/mode/listservices.pm @@ -134,7 +134,7 @@ __END__ =head1 MODE -List Windows services. +List Windows services =over 8 From 309bb34bb50dbb41d572d5662303ea7213a4490d Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Fri, 22 Dec 2023 11:39:32 +0100 Subject: [PATCH 22/35] Only keep test --- src/os/windows/snmp/mode/listservices.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/windows/snmp/mode/listservices.pm b/src/os/windows/snmp/mode/listservices.pm index 4578e68240..8816071abf 100644 --- a/src/os/windows/snmp/mode/listservices.pm +++ b/src/os/windows/snmp/mode/listservices.pm @@ -134,7 +134,7 @@ __END__ =head1 MODE -List Windows services +List Windows services. =over 8 From ad558d821339035dcc75e8be3c74185dcc7cdc2e Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut <123162035+lucie-dubrunfaut@users.noreply.github.com> Date: Fri, 22 Dec 2023 16:05:41 +0100 Subject: [PATCH 23/35] Update .github/workflows/spellchecker.yml Co-authored-by: Kevin Duret --- .github/workflows/spellchecker.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index e32c31fe53..0b1b9906bc 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -37,7 +37,9 @@ jobs: - name: Install librairies continue-on-error: true - run: sudo apt-get install -y hunspell aspell spell ispell + run: | + sudo apt-get update + sudo apt-get install -y hunspell aspell spell ispell shell: bash - name: Run spell check From 4eab96e0b3954632e81123e5ae1d0bc357089030 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Tue, 16 Jan 2024 15:11:23 +0100 Subject: [PATCH 24/35] Improvements after doc team brefing --- .github/scripts/pod_spell_check.t | 17 +++++------------ .github/scripts/stopwords.t | 4 ++++ .github/workflows/spellchecker.yml | 4 ++-- src/network/oneaccess/snmp/mode/cpu.pm | 5 ++++- 4 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 .github/scripts/stopwords.t diff --git a/.github/scripts/pod_spell_check.t b/.github/scripts/pod_spell_check.t index 058bd56980..85eaaa5919 100644 --- a/.github/scripts/pod_spell_check.t +++ b/.github/scripts/pod_spell_check.t @@ -3,17 +3,10 @@ use warnings; use Test::More; use Test::Spelling; -use Pod::Wordlist; -add_stopwords(); -set_spell_cmd('hunspell -L'); # current preferred -# set_spell_cmd('aspell list'); -# set_spell_cmd('spell'); -# set_spell_cmd('ispell -l'); -my $cmd = has_working_spellchecker; -printf($cmd."\n"); -all_pod_files_spelling_ok( $ARGV[0]); +open(FILE, "<", "stopwords.t"); +add_stopwords(); +close(FILE); -__DATA__ -SNMP -SSH \ No newline at end of file +set_spell_cmd('hunspell -l'); +all_pod_files_spelling_ok( $ARGV[0]); \ No newline at end of file diff --git a/.github/scripts/stopwords.t b/.github/scripts/stopwords.t new file mode 100644 index 0000000000..19cbf46b17 --- /dev/null +++ b/.github/scripts/stopwords.t @@ -0,0 +1,4 @@ +--force-counters32 +OID +SNMP +SSH \ No newline at end of file diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 0b1b9906bc..a82f666bd3 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -33,13 +33,13 @@ jobs: with: perl-version: '5.34' install-modules-with: cpm - install-modules: Test::More Test::Spelling Pod::Wordlist + install-modules: Test::More Test::Spelling - name: Install librairies continue-on-error: true run: | sudo apt-get update - sudo apt-get install -y hunspell aspell spell ispell + sudo apt-get install -y hunspell shell: bash - name: Run spell check diff --git a/src/network/oneaccess/snmp/mode/cpu.pm b/src/network/oneaccess/snmp/mode/cpu.pm index f5b603d1f2..6a4b02d917 100644 --- a/src/network/oneaccess/snmp/mode/cpu.pm +++ b/src/network/oneaccess/snmp/mode/cpu.pm @@ -86,7 +86,7 @@ __END__ =head1 MODE -Check cpu usage (oneaccess-sys-mib). +Check CPU usage (oneaccess-sys-mib). =over 8 @@ -98,6 +98,9 @@ Warning threshold in percent. Critical threshold in percent. +sys cpu + + =back =cut From dd5d5e37c44cc4423fd05d5e7b794462d84f4c3d Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Tue, 16 Jan 2024 15:15:15 +0100 Subject: [PATCH 25/35] Wip --- .github/scripts/pod_spell_check.t | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/scripts/pod_spell_check.t b/.github/scripts/pod_spell_check.t index 85eaaa5919..20b763dcab 100644 --- a/.github/scripts/pod_spell_check.t +++ b/.github/scripts/pod_spell_check.t @@ -6,7 +6,8 @@ use Test::Spelling; open(FILE, "<", "stopwords.t"); add_stopwords(); -close(FILE); set_spell_cmd('hunspell -l'); -all_pod_files_spelling_ok( $ARGV[0]); \ No newline at end of file +all_pod_files_spelling_ok( $ARGV[0]); + +close(FILE); \ No newline at end of file From 027c4171334311fa3ce1bee9cfe70907a970d2fc Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Wed, 17 Jan 2024 15:54:31 +0100 Subject: [PATCH 26/35] Add a way to bypass the spellcheck in PR if needed using tag --- .github/workflows/spellchecker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index a82f666bd3..09125f1eba 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -11,6 +11,8 @@ on: - '.github/workflows/spellchecker.yml' - 'src/**' - '.github/scripts/pod_spell_check.t' + tags-ignore: + - do-not-spell-check jobs: pod-spell-check: From e07099a3ebe01346fa89b9fff5df3d1e53fcea33 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Wed, 17 Jan 2024 16:24:52 +0100 Subject: [PATCH 27/35] skip ga for "do-not-spell-check" label --- .github/workflows/spellchecker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 09125f1eba..ad8d21cc0f 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -11,11 +11,11 @@ on: - '.github/workflows/spellchecker.yml' - 'src/**' - '.github/scripts/pod_spell_check.t' - tags-ignore: - - do-not-spell-check jobs: pod-spell-check: + if: !contains(github.event.issue.labels.*.name, 'do-not-spell-check') + runs-on: ubuntu-22.04 steps: From ae7bf357541ee8bb378b80a5fa1b048931951002 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Wed, 17 Jan 2024 16:32:09 +0100 Subject: [PATCH 28/35] fix --- .github/workflows/spellchecker.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index ad8d21cc0f..81471c7359 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -14,8 +14,7 @@ on: jobs: pod-spell-check: - if: !contains(github.event.issue.labels.*.name, 'do-not-spell-check') - + if: ${{ !contains(github.event.issue.labels.*.name, 'do-not-spell-check') }} runs-on: ubuntu-22.04 steps: From 91dc66379a657dc5985e32e0e886a17eb9c4527f Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Wed, 17 Jan 2024 16:38:28 +0100 Subject: [PATCH 29/35] test --- src/network/oneaccess/snmp/mode/cpu.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/network/oneaccess/snmp/mode/cpu.pm b/src/network/oneaccess/snmp/mode/cpu.pm index 6a4b02d917..3fe9b742bf 100644 --- a/src/network/oneaccess/snmp/mode/cpu.pm +++ b/src/network/oneaccess/snmp/mode/cpu.pm @@ -101,6 +101,7 @@ Critical threshold in percent. sys cpu + =back =cut From cf2143a9c7fc4a212f948cd34716f8376c524dde Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Wed, 17 Jan 2024 16:47:18 +0100 Subject: [PATCH 30/35] update github actions versions --- .github/workflows/spellchecker.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 81471c7359..1f5ae16d06 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -18,9 +18,9 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - uses: dorny/paths-filter@v2 + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 id: filter with: base: ${{ github.ref }} @@ -30,7 +30,7 @@ jobs: - added|modified: src/** - name: Install CPAN Libraries - uses: shogo82148/actions-setup-perl@v1 + uses: shogo82148/actions-setup-perl@ea0507898383e7dbce382138da0c21af1849eb9e # v1.27.0 with: perl-version: '5.34' install-modules-with: cpm @@ -39,6 +39,8 @@ jobs: - name: Install librairies continue-on-error: true run: | + echo ${{ !contains(github.event.issue.labels.*.name, 'do-not-spell-check') }} + echo ${{ github.event.issue.labels.*.name }} sudo apt-get update sudo apt-get install -y hunspell shell: bash From ee058ac84ebcde356a4f64c61a252d4259b222bc Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Wed, 17 Jan 2024 16:54:22 +0100 Subject: [PATCH 31/35] fix: use pull_request event instead of issue --- .github/workflows/spellchecker.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/spellchecker.yml b/.github/workflows/spellchecker.yml index 1f5ae16d06..cc82951bf8 100644 --- a/.github/workflows/spellchecker.yml +++ b/.github/workflows/spellchecker.yml @@ -14,7 +14,7 @@ on: jobs: pod-spell-check: - if: ${{ !contains(github.event.issue.labels.*.name, 'do-not-spell-check') }} + if: ${{ !contains(github.event.pull_request.labels.*.name, 'do-not-spell-check') }} runs-on: ubuntu-22.04 steps: @@ -39,8 +39,6 @@ jobs: - name: Install librairies continue-on-error: true run: | - echo ${{ !contains(github.event.issue.labels.*.name, 'do-not-spell-check') }} - echo ${{ github.event.issue.labels.*.name }} sudo apt-get update sudo apt-get install -y hunspell shell: bash From 8f0ae7ba0a9eea6e09546addc2f6e31b76a6e7b3 Mon Sep 17 00:00:00 2001 From: Sophie Depassio Date: Wed, 17 Jan 2024 17:37:16 +0100 Subject: [PATCH 32/35] test --- src/network/oneaccess/snmp/mode/cpu.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/src/network/oneaccess/snmp/mode/cpu.pm b/src/network/oneaccess/snmp/mode/cpu.pm index 3fe9b742bf..6a4b02d917 100644 --- a/src/network/oneaccess/snmp/mode/cpu.pm +++ b/src/network/oneaccess/snmp/mode/cpu.pm @@ -101,7 +101,6 @@ Critical threshold in percent. sys cpu - =back =cut From 9e1b37391bad5d85f0051d33cabf3e8b4d5e70fe Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 18 Jan 2024 15:49:30 +0100 Subject: [PATCH 33/35] Remove trashs --- src/network/oneaccess/snmp/mode/cpu.pm | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/network/oneaccess/snmp/mode/cpu.pm b/src/network/oneaccess/snmp/mode/cpu.pm index 6a4b02d917..9b048d269e 100644 --- a/src/network/oneaccess/snmp/mode/cpu.pm +++ b/src/network/oneaccess/snmp/mode/cpu.pm @@ -98,9 +98,6 @@ Warning threshold in percent. Critical threshold in percent. -sys cpu - - =back =cut From d474fc60540f2cdb646604bfd461e6f1d1795e64 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Thu, 18 Jan 2024 16:47:24 +0100 Subject: [PATCH 34/35] Handle with stopword path --- .github/scripts/pod_spell_check.t | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/scripts/pod_spell_check.t b/.github/scripts/pod_spell_check.t index 20b763dcab..dd932714fc 100644 --- a/.github/scripts/pod_spell_check.t +++ b/.github/scripts/pod_spell_check.t @@ -1,13 +1,22 @@ use strict; use warnings; -use Test::More; +use Test::More; use Test::Spelling; -open(FILE, "<", "stopwords.t"); -add_stopwords(); +if (!@ARGV) { + die "Missing perl file to check."; +} -set_spell_cmd('hunspell -l'); -all_pod_files_spelling_ok( $ARGV[0]); +my $stopword_filename='.github/scripts/stopwords.t'; +if(defined($ARGV[1])){ + $stopword_filename=$ARGV[1]; +} +open(FILE, "<", $stopword_filename) + or die "Could not open $stopword_filename"; +printf("stopword file use : ".$stopword_filename." \n"); +add_stopwords(); +set_spell_cmd('hunspell -l'); +all_pod_files_spelling_ok($ARGV[0]); close(FILE); \ No newline at end of file From b21502643eaa4885d0b077bfcc9f61254f5723e9 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut Date: Tue, 23 Jan 2024 11:20:27 +0100 Subject: [PATCH 35/35] Update stopwords.t --- .github/scripts/stopwords.t | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/stopwords.t b/.github/scripts/stopwords.t index 19cbf46b17..10acbc4776 100644 --- a/.github/scripts/stopwords.t +++ b/.github/scripts/stopwords.t @@ -1,4 +1,5 @@ --force-counters32 OID +oneaccess-sys-mib SNMP -SSH \ No newline at end of file +SSH