From 80a8cf4305aac9d895a97260d6f0b825eb850efd Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Fri, 7 Jul 2023 08:29:14 +0200 Subject: [PATCH 01/24] Revert "ci: temporary disable of some deliveries" This reverts commit 56d12994f363d671ac7cf4a211e183e620c6d0df. --- .github/workflows/plugin-delivery.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/plugin-delivery.yml b/.github/workflows/plugin-delivery.yml index dc84a4eb8..42a454899 100644 --- a/.github/workflows/plugin-delivery.yml +++ b/.github/workflows/plugin-delivery.yml @@ -67,7 +67,7 @@ jobs: strategy: fail-fast: false matrix: - distrib: [el7] + distrib: [el7, el8, el9] steps: - name: Checkout sources @@ -88,7 +88,7 @@ jobs: strategy: fail-fast: false matrix: - distrib: [el7] + distrib: [el7, el8] major_version: ["21.10", "22.04", "22.10"] steps: @@ -109,7 +109,6 @@ jobs: stability: ${{ inputs.stability }} deliver-deb: - if: ${{ inputs.stability == 'REMOVE-LINE' }} runs-on: [self-hosted, common] strategy: fail-fast: false @@ -129,7 +128,7 @@ jobs: artifactory_token: ${{ secrets.artifactory_token }} deliver-deb-legacy: - if: ${{ inputs.stability == 'RESET-TO-STABLE' }} + if: ${{ inputs.stability == 'stable' }} runs-on: [self-hosted, common] strategy: fail-fast: false From 7f1ecee9fdd03aa2d471dedfa42dc2c186e0c5ed Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 10 Jul 2023 10:43:30 +0200 Subject: [PATCH 02/24] (plugin) cloud::azure::database::mariadb - fix undefined value (#4550) --- .../azure/database/mariadb/mode/connections.pm | 11 +++++------ src/cloud/azure/database/mariadb/mode/cpu.pm | 9 ++++----- .../azure/database/mariadb/mode/ioconsumption.pm | 9 ++++----- src/cloud/azure/database/mariadb/mode/memory.pm | 9 ++++----- .../azure/database/mariadb/mode/replication.pm | 11 +++++------ src/cloud/azure/database/mariadb/mode/storage.pm | 16 ++++++++-------- src/cloud/azure/database/mariadb/mode/traffic.pm | 13 ++++++------- 7 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/cloud/azure/database/mariadb/mode/connections.pm b/src/cloud/azure/database/mariadb/mode/connections.pm index fccaed4bb..66af4fbb8 100644 --- a/src/cloud/azure/database/mariadb/mode/connections.pm +++ b/src/cloud/azure/database/mariadb/mode/connections.pm @@ -56,7 +56,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-metric:s' => { name => 'filter_metric' }, 'resource:s' => { name => 'resource' }, - 'resource-group:s' => { name => 'resource_group' }, + 'resource-group:s' => { name => 'resource_group' } }); return $self; @@ -73,11 +73,10 @@ sub check_options { my $resource = $self->{option_results}->{resource}; my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; - my $resource_type = $self->{option_results}->{resource_type}; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/(.*)\/(.*)$/) { + my $resource_type = 'servers'; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/servers\/(.*)$/) { $resource_group = $1; - $resource_type = 'servers'; - $resource = $3; + $resource = $2; } $self->{az_resource} = $resource; @@ -97,7 +96,7 @@ sub check_options { } my $resource_mapping = { - 'servers' => [ 'active_connections', 'connections_failed' ], + 'servers' => [ 'active_connections', 'connections_failed' ] }; my $metrics_mapping_transformed; diff --git a/src/cloud/azure/database/mariadb/mode/cpu.pm b/src/cloud/azure/database/mariadb/mode/cpu.pm index 4317fba9d..809663b31 100644 --- a/src/cloud/azure/database/mariadb/mode/cpu.pm +++ b/src/cloud/azure/database/mariadb/mode/cpu.pm @@ -50,7 +50,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-metric:s' => { name => 'filter_metric' }, 'resource:s' => { name => 'resource' }, - 'resource-group:s' => { name => 'resource_group' }, + 'resource-group:s' => { name => 'resource_group' } }); return $self; @@ -67,11 +67,10 @@ sub check_options { my $resource = $self->{option_results}->{resource}; my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; - my $resource_type = $self->{option_results}->{resource_type}; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/(.*)\/(.*)$/) { + my $resource_type = 'servers'; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/servers\/(.*)$/) { $resource_group = $1; - $resource_type = 'servers'; - $resource = $3; + $resource = $2; } $self->{az_resource} = $resource; diff --git a/src/cloud/azure/database/mariadb/mode/ioconsumption.pm b/src/cloud/azure/database/mariadb/mode/ioconsumption.pm index 59a7bb947..c61001c3f 100644 --- a/src/cloud/azure/database/mariadb/mode/ioconsumption.pm +++ b/src/cloud/azure/database/mariadb/mode/ioconsumption.pm @@ -50,7 +50,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-metric:s' => { name => 'filter_metric' }, 'resource:s' => { name => 'resource' }, - 'resource-group:s' => { name => 'resource_group' }, + 'resource-group:s' => { name => 'resource_group' } }); return $self; @@ -67,11 +67,10 @@ sub check_options { my $resource = $self->{option_results}->{resource}; my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; - my $resource_type = $self->{option_results}->{resource_type}; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/(.*)\/(.*)$/) { + my $resource_type = 'servers'; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/servers\/(.*)$/) { $resource_group = $1; - $resource_type = 'servers'; - $resource = $3; + $resource = $2; } $self->{az_resource} = $resource; diff --git a/src/cloud/azure/database/mariadb/mode/memory.pm b/src/cloud/azure/database/mariadb/mode/memory.pm index 82c392866..aa63bd2bb 100644 --- a/src/cloud/azure/database/mariadb/mode/memory.pm +++ b/src/cloud/azure/database/mariadb/mode/memory.pm @@ -50,7 +50,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-metric:s' => { name => 'filter_metric' }, 'resource:s' => { name => 'resource' }, - 'resource-group:s' => { name => 'resource_group' }, + 'resource-group:s' => { name => 'resource_group' } }); return $self; @@ -67,11 +67,10 @@ sub check_options { my $resource = $self->{option_results}->{resource}; my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; - my $resource_type = $self->{option_results}->{resource_type}; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/(.*)\/(.*)$/) { + my $resource_type = 'servers'; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/servers\/(.*)$/) { $resource_group = $1; - $resource_type = 'servers'; - $resource = $3; + $resource = $2; } $self->{az_resource} = $resource; diff --git a/src/cloud/azure/database/mariadb/mode/replication.pm b/src/cloud/azure/database/mariadb/mode/replication.pm index 30abda265..247522afb 100644 --- a/src/cloud/azure/database/mariadb/mode/replication.pm +++ b/src/cloud/azure/database/mariadb/mode/replication.pm @@ -49,7 +49,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-metric:s' => { name => 'filter_metric' }, 'resource:s' => { name => 'resource' }, - 'resource-group:s' => { name => 'resource_group' }, + 'resource-group:s' => { name => 'resource_group' } }); return $self; @@ -66,11 +66,10 @@ sub check_options { my $resource = $self->{option_results}->{resource}; my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; - my $resource_type = $self->{option_results}->{resource_type}; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/(.*)\/(.*)$/) { + my $resource_type = 'servers'; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/servers\/(.*)$/) { $resource_group = $1; - $resource_type = 'servers'; - $resource = $3; + $resource = $2; } $self->{az_resource} = $resource; @@ -90,7 +89,7 @@ sub check_options { } my $resource_mapping = { - 'servers' => [ 'seconds_behind_master' ], + 'servers' => [ 'seconds_behind_master' ] }; my $metrics_mapping_transformed; diff --git a/src/cloud/azure/database/mariadb/mode/storage.pm b/src/cloud/azure/database/mariadb/mode/storage.pm index 0dbeb6378..b9e5f675a 100644 --- a/src/cloud/azure/database/mariadb/mode/storage.pm +++ b/src/cloud/azure/database/mariadb/mode/storage.pm @@ -91,7 +91,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-metric:s' => { name => 'filter_metric' }, 'resource:s' => { name => 'resource' }, - 'resource-group:s' => { name => 'resource_group' }, + 'resource-group:s' => { name => 'resource_group' } }); return $self; @@ -108,11 +108,10 @@ sub check_options { my $resource = $self->{option_results}->{resource}; my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; - my $resource_type = $self->{option_results}->{resource_type}; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/(.*)\/(.*)$/) { + my $resource_type = 'servers'; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/servers\/(.*)$/) { $resource_group = $1; - $resource_type = 'servers'; - $resource = $3; + $resource = $2; } $self->{az_resource} = $resource; @@ -132,9 +131,10 @@ sub check_options { } my $resource_mapping = { - 'servers' => [ 'backup_storage_used', 'serverlog_storage_limit', 'serverlog_storage_percent', - 'serverlog_storage_usage', 'storage_limit', 'storage_percent', 'storage_used' - ], + 'servers' => [ + 'backup_storage_used', 'serverlog_storage_limit', 'serverlog_storage_percent', + 'serverlog_storage_usage', 'storage_limit', 'storage_percent', 'storage_used' + ] }; my $metrics_mapping_transformed; diff --git a/src/cloud/azure/database/mariadb/mode/traffic.pm b/src/cloud/azure/database/mariadb/mode/traffic.pm index d97181b89..0443a7393 100644 --- a/src/cloud/azure/database/mariadb/mode/traffic.pm +++ b/src/cloud/azure/database/mariadb/mode/traffic.pm @@ -34,14 +34,14 @@ sub get_metrics_mapping { 'label' => 'traffic-out', 'nlabel' => 'azmariadb.traffic.out.bytes', 'unit' => 'B', - 'min' => '0', + 'min' => '0' }, 'network_bytes_ingress' => { 'output' => 'Network In', 'label' => 'traffic-in', 'nlabel' => 'azmariadb.traffic.in.bytes', 'unit' => 'B', - 'min' => '0', + 'min' => '0' } }; @@ -56,7 +56,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-metric:s' => { name => 'filter_metric' }, 'resource:s' => { name => 'resource' }, - 'resource-group:s' => { name => 'resource_group' }, + 'resource-group:s' => { name => 'resource_group' } }); return $self; @@ -73,11 +73,10 @@ sub check_options { my $resource = $self->{option_results}->{resource}; my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; - my $resource_type = $self->{option_results}->{resource_type}; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/(.*)\/(.*)$/) { + my $resource_type = 'servers'; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.DBforMariaDB\/servers\/(.*)$/) { $resource_group = $1; - $resource_type = 'servers'; - $resource = $3; + $resource = $2; } $self->{az_resource} = $resource; From ffdbfd018a542c4199728478560d9a34bdc31d88 Mon Sep 17 00:00:00 2001 From: sdepassio <114986849+sdepassio@users.noreply.github.com> Date: Tue, 18 Jul 2023 10:22:21 +0200 Subject: [PATCH 03/24] Adapt plugins tests from bash to robot framework (#4487) --- .github/workflows/tests-functional.yml | 47 ++-- src/cloud/aws/cloudtrail/mode/countevents.pm | 4 +- tests/functional/cloud-aws-cloudtrail.robot | 215 ++++++++++++++++++ ...ud-azure-policyinsights-policystates.robot | 93 ++++++++ ...oud-azure-policyinsights-policystates.json | 201 ++++++++++++++++ 5 files changed, 532 insertions(+), 28 deletions(-) create mode 100644 tests/functional/cloud-aws-cloudtrail.robot create mode 100644 tests/functional/cloud-azure-policyinsights-policystates.robot create mode 100644 tests/resources/mockoon/cloud-azure-policyinsights-policystates.json diff --git a/.github/workflows/tests-functional.yml b/.github/workflows/tests-functional.yml index f90e0fa60..2ce749aac 100644 --- a/.github/workflows/tests-functional.yml +++ b/.github/workflows/tests-functional.yml @@ -1,4 +1,4 @@ -name: Functional tests +name: functional-tests concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -8,23 +8,27 @@ on: workflow_dispatch: pull_request: paths: + - '.github/workflows/tests-functional.yml' - 'src/**' - 'tests/functional/**' + - 'tests/resources/mockoon/**' jobs: - AWS_tests: + functional-tests-with-robot: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - - - name: Use Node.js + - name: Install Node.js uses: actions/setup-node@v2 with: node-version: "16.x" - name: Install Mockoon CLI - run: npm install -D @mockoon/cli + run: npm install -g -D @mockoon/cli + + - name: Install libs + run: sudo apt-get install libcurl4-openssl-dev - name: Install perl dependencies uses: shogo82148/actions-setup-perl@v1 @@ -35,40 +39,31 @@ jobs: DateTime Digest::MD5 Encode + ExtUtils::PkgConfig HTTP::ProxyPAC IO::Socket::SSL JSON::XS LWP::Protocol::https LWP::UserAgent MIME::Base64 + Net::Curl::Easy Paws POSIX Storable URI URI::Encode - - name: Run Mockoon CLI - run: npx mockoon-cli start --data tests/resources/mockoon/cloud-aws-cloudtrail.json --port 3000 + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - - name: Run plugin + - name: Install Robot Framework + run: pip3 install robotframework + shell: bash + + - name: Run Robot Framework tests run: | - sudo chmod -R +x tests/functional/ sudo mkdir -p /var/lib/centreon/centplugins/ sudo chmod 777 /var/lib/centreon/centplugins/ - TESTS="$(tests/functional/cloud/aws/cloudtrail/checktrailstatus.sh)" - echo "tests=$(echo $TESTS)" >> $GITHUB_OUTPUT - if [[ $TESTS = "OK:"* ]]; then - echo "OK" - else - echo $TESTS - exit 1 - fi - TESTS="$(tests/functional/cloud/aws/cloudtrail/countevents.sh)" - echo "tests=$(echo $TESTS)" >> $GITHUB_OUTPUT - if [[ $TESTS = "OK:"* ]]; then - echo "OK" - else - echo $TESTS - exit 1 - fi - shell: bash \ No newline at end of file + robot tests/functional/ diff --git a/src/cloud/aws/cloudtrail/mode/countevents.pm b/src/cloud/aws/cloudtrail/mode/countevents.pm index bb9891348..b09fae031 100644 --- a/src/cloud/aws/cloudtrail/mode/countevents.pm +++ b/src/cloud/aws/cloudtrail/mode/countevents.pm @@ -68,8 +68,8 @@ sub run { if (length($self->{option_results}->{event_type}) || length($self->{option_results}->{error_message})) { $count = 0; foreach my $event (@{$self->{events}}) { - if ((defined($self->{option_results}->{event_type}) && length($self->{option_results}->{event_type}) && ($event->{eventType} eq $self->{option_results}->{event_type})) - || (defined($self->{option_results}->{error_message}) && length($self->{option_results}->{error_message}) && ($event->{errorMessage} =~ $self->{option_results}->{error_message}))) { + if ((length($self->{option_results}->{event_type}) && ($event->{eventType} eq $self->{option_results}->{event_type})) + || (length($self->{option_results}->{error_message}) && length($event->{errorMessage}) && $event->{errorMessage} =~ $self->{option_results}->{error_message})) { $count++; } } diff --git a/tests/functional/cloud-aws-cloudtrail.robot b/tests/functional/cloud-aws-cloudtrail.robot new file mode 100644 index 000000000..6f0352f86 --- /dev/null +++ b/tests/functional/cloud-aws-cloudtrail.robot @@ -0,0 +1,215 @@ +*** Settings *** +Documentation AWS CloudTrail plugin + +Library OperatingSystem +Library Process +Library String + +Suite Setup Start Mockoon +Suite Teardown Stop Mockoon + + +*** Variables *** +${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}src${/}centreon_plugins.pl +${MOCKOON_JSON} ${CURDIR}${/}..${/}resources${/}mockoon${/}cloud-aws-cloudtrail.json + +${CMD} perl ${CENTREON_PLUGINS} --plugin=cloud::aws::cloudtrail::plugin --custommode=paws --region=eu-west --aws-secret-key=secret --aws-access-key=key + +&{checktrailstatus_value1} +... trailstatus=true +... trailname=TrailName +... result=OK: Trail is logging: 1 | 'trail_is_logging'=1;;;0; +&{checktrailstatus_value2} +... trailstatus=false +... trailname=TrailName +... result=CRITICAL: Trail is logging: 0 | 'trail_is_logging'=0;;;0; +@{checktrailstatus_values} &{checktrailstatus_value1} &{checktrailstatus_value2} + +&{countevents_value1} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=false +... eventtype= +... delta= +... errormessage= +... warningcount= +... criticalcount= +... result=OK: Number of events: 10.00 | 'events_count'=10.00;;;0; +&{countevents_value2} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=true +... eventtype= +... delta= +... errormessage= +... warningcount= +... criticalcount= +... result=OK: Number of events: 20.00 | 'events_count'=20.00;;;0; +&{countevents_value3} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=false +... eventtype=AwsApiCall +... delta= +... errormessage= +... warningcount= +... criticalcount= +... result=OK: Number of events: 4.00 | 'events_count'=4.00;;;0; +&{countevents_value4} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=true +... eventtype=AwsServiceEvent +... delta= +... errormessage= +... warningcount= +... criticalcount= +... result=OK: Number of events: 4.00 | 'events_count'=4.00;;;0; +&{countevents_value5} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=false +... eventtype=AwsApiCall +... delta=10 +... errormessage= +... warningcount= +... criticalcount= +... result=OK: Number of events: 4.00 | 'events_count'=4.00;;;0; +&{countevents_value6} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=false +... eventtype= +... delta= +... errormessage='Login error' +... warningcount= +... criticalcount= +... result=OK: Number of events: 3.00 | 'events_count'=3.00;;;0; +&{countevents_value7} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=false +... eventtype= +... delta= +... errormessage='.*error' +... warningcount= +... criticalcount= +... result=OK: Number of events: 4.00 | 'events_count'=4.00;;;0; +&{countevents_value8} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=false +... eventtype= +... delta= +... errormessage= +... warningcount=3 +... criticalcount= +... result=WARNING: Number of events: 10.00 | 'events_count'=10.00;;;0; +&{countevents_value9} +... AwsApiCall=4 +... AwsServiceEvent=2 +... AwsConsoleAction=1 +... AwsConsoleSignIn=3 +... NextToken=false +... eventtype= +... delta= +... errormessage= +... warningcount= +... criticalcount=5 +... result=CRITICAL: Number of events: 10.00 | 'events_count'=10.00;;;0; +@{countevents_values} +... &{countevents_value1} +... &{countevents_value2} +... &{countevents_value3} +... &{countevents_value4} +... &{countevents_value5} +... &{countevents_value6} +... &{countevents_value7} +... &{countevents_value8} +... &{countevents_value9} + + +*** Test Cases *** +AWS CloudTrail check trail status + [Documentation] Check AWS CloudTrail trail status + [Tags] cloud aws cloudtrail + FOR ${checktrailstatus_value} IN @{checktrailstatus_values} + ${output} = Run + ... ${CMD} --mode=checktrailstatus --endpoint=http://localhost:3000/cloudtrail/gettrailstatus/${checktrailstatus_value.trailstatus} --trail-name=${checktrailstatus_value.trailname} + Should Be Equal As Strings + ... ${output} + ... ${checktrailstatus_value.result} + ... msg=Wrong output result for check trail status of ${checktrailstatus_value} + END + +AWS CloudTrail count events + [Documentation] Check AWS CloudTrail count events + [Tags] cloud aws cloudtrail + FOR ${countevents_value} IN @{countevents_values} + ${command} = Catenate + ... ${CMD} + ... --mode=countevents + ... --endpoint=http://localhost:3000/cloudtrail/events/AwsApiCall/${countevents_value.AwsApiCall}/AwsServiceEvent/${countevents_value.AwsServiceEvent}/AwsConsoleAction/${countevents_value.AwsConsoleAction}/AwsConsoleSignIn/${countevents_value.AwsConsoleSignIn}/NextToken/${countevents_value.NextToken} + ${length} = Get Length ${countevents_value.eventtype} + IF ${length} > 0 + ${command} = Catenate ${command} --event-type=${countevents_value.eventtype} + END + ${length} = Get Length ${countevents_value.delta} + IF ${length} > 0 + ${command} = Catenate ${command} --delta=${countevents_value.delta} + END + ${length} = Get Length ${countevents_value.errormessage} + IF ${length} > 0 + ${command} = Catenate ${command} --error-message=${countevents_value.errormessage} + END + ${length} = Get Length ${countevents_value.warningcount} + IF ${length} > 0 + ${command} = Catenate ${command} --warning-count=${countevents_value.warningcount} + END + ${length} = Get Length ${countevents_value.criticalcount} + IF ${length} > 0 + ${command} = Catenate ${command} --critical-count=${countevents_value.criticalcount} + END + ${output} = Run ${command} + Should Be Equal As Strings + ... ${output} + ... ${countevents_value.result} + ... msg=Wrong output result for count events of ${countevents_value} + END + + +*** Keywords *** +Start Mockoon + ${executionresult} = Run Process + ... mockoon-cli + ... start + ... --data + ... ${MOCKOON_JSON} + ... --port + ... 3000 + ... --pname + ... azure-policyinsights + Should Be Empty ${executionresult.stderr} + +Stop Mockoon + ${executionresult} = Run Process + ... mockoon-cli + ... stop + ... mockoon-azure-policyinsights + Should Be Empty ${executionresult.stderr} diff --git a/tests/functional/cloud-azure-policyinsights-policystates.robot b/tests/functional/cloud-azure-policyinsights-policystates.robot new file mode 100644 index 000000000..8a06ec027 --- /dev/null +++ b/tests/functional/cloud-azure-policyinsights-policystates.robot @@ -0,0 +1,93 @@ +*** Settings *** +Documentation Azure PolicyInsights PolicyStates plugin + +Library OperatingSystem +Library Process +Library String + +Suite Setup Start Mockoon +Suite Teardown Stop Mockoon + + +*** Variables *** +${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}src${/}centreon_plugins.pl +${MOCKOON_JSON} ${CURDIR}${/}..${/}resources${/}mockoon${/}cloud-azure-policyinsights-policystates.json + +${LOGIN_ENDPOINT} http://localhost:3000/login +${CMD} perl ${CENTREON_PLUGINS} --plugin=cloud::azure::policyinsights::policystates::plugin --subscription=subscription --tenant=tenant --client-id=client_id --client-secret=secret --login-endpoint=${LOGIN_ENDPOINT} + +&{compliance_value1} +... endpoint=http://localhost:3000/ok +... policyname= +... resourcelocation= +... resourcetype= +... result=OK: Number of non compliant policies: 0 - All compliances states are ok | 'policies.non_compliant.count'=0;;;0; +&{compliance_value2} +... endpoint=http://localhost:3000/oknextlink +... policyname=9daedab3-fb2d-461e-b861-71790eead4f6 +... resourcelocation= +... resourcetype= +... result=OK: Number of non compliant policies: 0 - All compliances states are ok | 'policies.non_compliant.count'=0;;;0; +&{compliance_value3} +... endpoint=http://localhost:3000/nok1 +... policyname=9daedab3-fb2d-461e-b861-71790eead4f6 +... resourcelocation=fr +... resourcetype= +... result=CRITICAL: Compliance state for policy '9daedab3-fb2d-461e-b861-71790eead4f6' on resource 'mypubip1' is 'NonCompliant' | 'policies.non_compliant.count'=1;;;0; +&{compliance_value4} +... endpoint=http://localhost:3000/nok2 +... policyname=9daedab3-fb2d-461e-b861-71790eead4f6 +... resourcelocation=fr +... resourcetype=ip +... result=CRITICAL: Compliance state for policy '9daedab3-fb2d-461e-b861-71790eead4f6' on resource 'mypubip1' is 'NonCompliant' - Compliance state for policy '9daedab3-fb2d-461e-b861-71790eead4f6' on resource 'mypubip2' is 'NonCompliant' | 'policies.non_compliant.count'=2;;;0; +@{compliance_values} &{compliance_value1} &{compliance_value2} &{compliance_value3} &{compliance_value4} + + +*** Test Cases *** +Azure PolicyInsights PolicyStates compliance + [Documentation] Check Azure PolicyInsights PolicyStates compliance + [Tags] cloud azure policyinsights policystates + FOR ${compliance_value} IN @{compliance_values} + ${command} = Catenate + ... ${CMD} + ... --mode=compliance + ... --management-endpoint=${compliance_value.endpoint} + ${length} = Get Length ${compliance_value.policyname} + IF ${length} > 0 + ${command} = Catenate ${command} --policy-name=${compliance_value.policyname} + END + ${length} = Get Length ${compliance_value.resourcelocation} + IF ${length} > 0 + ${command} = Catenate ${command} --resource-location=${compliance_value.resourcelocation} + END + ${length} = Get Length ${compliance_value.resourcetype} + IF ${length} > 0 + ${command} = Catenate ${command} --resource-type=${compliance_value.resourcetype} + END + ${output} = Run ${command} + Should Be Equal As Strings + ... ${output} + ... ${compliance_value.result} + ... msg=Wrong output result for compliance of ${compliance_value} + END + + +*** Keywords *** +Start Mockoon + ${executionresult} = Run Process + ... mockoon-cli + ... start + ... --data + ... ${MOCKOON_JSON} + ... --port + ... 3000 + ... --pname + ... azure-policyinsights + Should Be Empty ${executionresult.stderr} + +Stop Mockoon + ${executionresult} = Run Process + ... mockoon-cli + ... stop + ... mockoon-azure-policyinsights + Should Be Empty ${executionresult.stderr} diff --git a/tests/resources/mockoon/cloud-azure-policyinsights-policystates.json b/tests/resources/mockoon/cloud-azure-policyinsights-policystates.json new file mode 100644 index 000000000..9163ce351 --- /dev/null +++ b/tests/resources/mockoon/cloud-azure-policyinsights-policystates.json @@ -0,0 +1,201 @@ +{ + "uuid": "101906e9-f832-416c-8781-880c33a0a778", + "lastMigration": 25, + "name": "Azure API", + "endpointPrefix": "", + "latency": 0, + "port": 3000, + "hostname": "0.0.0.0", + "folders": [], + "routes": [ + { + "uuid": "433aa2a7-20df-4682-88ef-4c87bd0882e1", + "documentation": "Azure login", + "method": "post", + "endpoint": "login/:tenant/oauth2/token", + "responses": [ + { + "uuid": "0c775d57-8661-4c4f-9f30-a3a134d6d09c", + "body": "{\n \"access_token\": \"token\",\n \"expires_on\": \"{{ faker 'random.numeric' 10 }}\"\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true + } + ], + "enabled": true, + "responseMode": null + }, + { + "uuid": "3f190dd9-690a-413a-bafa-5c9d369b7d22", + "documentation": "", + "method": "post", + "endpoint": "ok/subscriptions/:subscriptionId/providers/Microsoft.PolicyInsights/policyStates/:policyStatesResource/queryResults", + "responses": [ + { + "uuid": "06ebc038-a4f5-48d5-8fb8-2403915a9754", + "body": "{\r\n \"@odata.nextLink\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest\",\r\n \"@odata.count\": 2,\r\n \"value\": [\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myrg1/providers/Microsoft.Network/publicIPAddresses/mypubip1\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/Enable Monitoring in Azure Security Center\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": true,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"Enable Monitoring in Azure Security Center\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"Compliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n },\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myrg1/providers/Microsoft.Network/publicIPAddresses/mypubip2\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/9ac09b0657d942e5ad4041a6\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": true,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"9ac09b0657d942e5ad4041a6\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"Compliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n },\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"mypubip3\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/9ac09b0657d942e5ad4041a6\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": true,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"9ac09b0657d942e5ad4041a6\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"Compliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n }\r\n ]\r\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true + } + ], + "enabled": true, + "responseMode": null + }, + { + "uuid": "31c8940d-4623-444c-92e1-f340fe74b5b3", + "documentation": "", + "method": "post", + "endpoint": "nok1/subscriptions/:subscriptionId/providers/Microsoft.PolicyInsights/policyStates/:policyStatesResource/queryResults", + "responses": [ + { + "uuid": "64c245ca-0190-4b2e-89d5-87383148286c", + "body": "{\r\n \"@odata.nextLink\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest\",\r\n \"@odata.count\": 2,\r\n \"value\": [\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myrg1/providers/Microsoft.Network/publicIPAddresses/mypubip1\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/Enable Monitoring in Azure Security Center\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": false,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"Enable Monitoring in Azure Security Center\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"NonCompliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n },\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myrg1/providers/Microsoft.Network/publicIPAddresses/mypubip2\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/9ac09b0657d942e5ad4041a6\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": true,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"9ac09b0657d942e5ad4041a6\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"Compliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n }\r\n ]\r\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true + } + ], + "enabled": true, + "responseMode": null + }, + { + "uuid": "13bf6e0e-8843-4681-942e-404b01326f32", + "documentation": "", + "method": "post", + "endpoint": "nok2/subscriptions/:subscriptionId/providers/Microsoft.PolicyInsights/policyStates/:policyStatesResource/queryResults", + "responses": [ + { + "uuid": "709a35af-cf2b-41f7-a224-3a946ffce703", + "body": "{\r\n \"@odata.nextLink\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest\",\r\n \"@odata.count\": 2,\r\n \"value\": [\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myrg1/providers/Microsoft.Network/publicIPAddresses/mypubip1\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/Enable Monitoring in Azure Security Center\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": false,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"Enable Monitoring in Azure Security Center\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"NonCompliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n },\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myrg1/providers/Microsoft.Network/publicIPAddresses/mypubip2\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/9ac09b0657d942e5ad4041a6\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": false,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"9ac09b0657d942e5ad4041a6\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"NonCompliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n }\r\n ]\r\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true + } + ], + "enabled": true, + "responseMode": null + }, + { + "uuid": "1eb461f8-c128-432b-a7ca-7ddd71c28fa4", + "documentation": "", + "method": "post", + "endpoint": "oknextlink/subscriptions/:subscriptionId/providers/Microsoft.PolicyInsights/policyStates/:policyStatesResource/queryResults", + "responses": [ + { + "uuid": "a0daaaa4-9c21-4d4d-aa0a-a99da2de7479", + "body": "{\r\n \"@odata.nextLink\": \"http://localhost:3000/ok/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults\",\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest\",\r\n \"@odata.count\": 2,\r\n \"value\": [\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myrg1/providers/Microsoft.Network/publicIPAddresses/mypubip1\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/Enable Monitoring in Azure Security Center\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": true,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"Enable Monitoring in Azure Security Center\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"Compliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n },\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myrg1/providers/Microsoft.Network/publicIPAddresses/mypubip2\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/9ac09b0657d942e5ad4041a6\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": true,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"9ac09b0657d942e5ad4041a6\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"Compliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n },\r\n {\r\n \"@odata.id\": null,\r\n \"@odata.context\": \"https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity\",\r\n \"timestamp\": \"2019-10-09T17:48:05Z\",\r\n \"resourceId\": \"mypubip3\",\r\n \"policyAssignmentId\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/9ac09b0657d942e5ad4041a6\",\r\n \"policyDefinitionId\": \"/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"effectiveParameters\": null,\r\n \"isCompliant\": true,\r\n \"subscriptionId\": \"fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"resourceType\": \"/Microsoft.Network/publicIPAddresses\",\r\n \"resourceLocation\": \"eastus\",\r\n \"resourceGroup\": \"myrg1\",\r\n \"resourceTags\": \"tbd\",\r\n \"policyAssignmentName\": \"9ac09b0657d942e5ad4041a6\",\r\n \"policyAssignmentOwner\": \"tbd\",\r\n \"policyAssignmentParameters\": \"{}\",\r\n \"policyAssignmentScope\": \"/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852\",\r\n \"policyDefinitionName\": \"9daedab3-fb2d-461e-b861-71790eead4f6\",\r\n \"policyDefinitionAction\": \"AuditIfNotExists\",\r\n \"policyDefinitionCategory\": \"tbd\",\r\n \"policySetDefinitionId\": \"/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionName\": \"1f3afdf9-d0c9-4c3d-847f-89da613e70a8\",\r\n \"policySetDefinitionOwner\": null,\r\n \"policySetDefinitionCategory\": null,\r\n \"policySetDefinitionParameters\": null,\r\n \"managementGroupIds\": \"mymg,fff988bf-fff1-ffff-fffb-fffcd011db47\",\r\n \"policyDefinitionReferenceId\": null,\r\n \"complianceState\": \"Compliant\",\r\n \"policyDefinitionGroupNames\": [\r\n \"myGroup\"\r\n ],\r\n \"policyDefinitionVersion\": \"1.0.0-preview\",\r\n \"policySetDefinitionVersion\": \"2.0.1\",\r\n \"policyAssignmentVersion\": \"1.0.0\"\r\n }\r\n ]\r\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true + } + ], + "enabled": true, + "responseMode": null + } + ], + "rootChildren": [ + { + "type": "route", + "uuid": "433aa2a7-20df-4682-88ef-4c87bd0882e1" + }, + { + "type": "route", + "uuid": "3f190dd9-690a-413a-bafa-5c9d369b7d22" + }, + { + "type": "route", + "uuid": "1eb461f8-c128-432b-a7ca-7ddd71c28fa4" + }, + { + "type": "route", + "uuid": "31c8940d-4623-444c-92e1-f340fe74b5b3" + }, + { + "type": "route", + "uuid": "13bf6e0e-8843-4681-942e-404b01326f32" + } + ], + "proxyMode": false, + "proxyHost": "", + "proxyRemovePrefix": false, + "tlsOptions": { + "enabled": false, + "type": "CERT", + "pfxPath": "", + "certPath": "", + "keyPath": "", + "caPath": "", + "passphrase": "" + }, + "cors": true, + "headers": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "proxyReqHeaders": [ + { + "key": "", + "value": "" + } + ], + "proxyResHeaders": [ + { + "key": "", + "value": "" + } + ], + "data": [] +} \ No newline at end of file From 45363e861f1fab30e3829ad960a5e24edc735eba Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 18 Jul 2023 10:55:32 +0200 Subject: [PATCH 04/24] (plugin) apps::sahipro::restapi - metric v2 + help (#4562) --- src/apps/sahipro/restapi/mode/scenario.pm | 55 +++++++++++------------ src/apps/sahipro/restapi/plugin.pm | 1 - 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/apps/sahipro/restapi/mode/scenario.pm b/src/apps/sahipro/restapi/mode/scenario.pm index d164c1fdd..5f8fec658 100644 --- a/src/apps/sahipro/restapi/mode/scenario.pm +++ b/src/apps/sahipro/restapi/mode/scenario.pm @@ -90,7 +90,7 @@ sub set_counters { key_values => [ { name => 'time_taken' } ], output_template => 'execution time: %s ms', perfdatas => [ - { label => 'total_time', template => '%s', min => 0, unit => 'ms' } + { template => '%s', min => 0, unit => 'ms' } ] } }, @@ -98,7 +98,7 @@ sub set_counters { key_values => [ { name => 'total_steps' } ], output_template => 'total steps: %s', perfdatas => [ - { label => 'total_steps', template => '%s', min => 0 } + { template => '%s', min => 0 } ] } }, @@ -106,7 +106,7 @@ sub set_counters { key_values => [ { name => 'failures' } ], output_template => 'failures: %s', perfdatas => [ - { label => 'failures', template => '%s', min => 0 } + { template => '%s', min => 0 } ] } }, @@ -114,10 +114,10 @@ sub set_counters { key_values => [ { name => 'errors' } ], output_template => 'errors: %s', perfdatas => [ - { label => 'errors', template => '%s', min => 0 } + { template => '%s', min => 0 } ] } - }, + } ]; $self->{maps_counters}->{steps} = [ @@ -125,8 +125,7 @@ sub set_counters { key_values => [ { name => 'time_taken' }, { name => 'step' } ], output_template => 'execution time: %s ms', perfdatas => [ - { label => 'step_time', template => '%s', - min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'step' } + { template => '%s', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'step' } ] } } @@ -135,7 +134,7 @@ sub set_counters { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -156,8 +155,8 @@ sub new { 'warning-run-status:s' => { name => 'warning_run_status' }, 'critical-run-status:s' => { name => 'critical_run_status', default => '' } }); - - $self->{http} = centreon::plugins::http->new(%options); + + $self->{http} = centreon::plugins::http->new(%options, default_backend => 'curl'); $self->set_signal_handlers(); return $self; } @@ -203,12 +202,12 @@ sub check_options { $self->{option_results}->{retries_scenario_status} < 0) { $self->{option_results}->{retries_scenario_status} = 0; } - + if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && $self->{option_results}->{timeout} > 0) { alarm($self->{option_results}->{timeout}); } - + $self->{http}->set_options(port => $self->{option_results}->{sahi_port}, proto => $self->{option_results}->{sahi_proto}); } @@ -229,7 +228,7 @@ sub decode_xml_response { sub generate_user_defined_id { my ($self, %options) = @_; - + my ($seconds, $microseconds) = Time::HiRes::gettimeofday(); my $user_defined_id = strftime('%d%B%Y__%H_%M_%S_', localtime($seconds)); $user_defined_id .= $microseconds; @@ -463,19 +462,19 @@ IP Addr/FQDN of the host =item B<--sahi-port> -Port used (Default: 9999) +Port used (default: 9999) =item B<--sahi-proto> -Specify https if needed (Default: 'http') +Define HTTPS if needed (default: 'http') =item B<--sahi-endpoint> -Specify endpoint (Default: '/_s_/dyn/') +Define endpoint (default: '/_s_/dyn/') =item B<--sahi-suite> -Full path to scenario and scenario name (Required) +Define path for scenario files (required. Example: 'sahitests/small.suite') =item B<--sahi-http-timeout> @@ -483,35 +482,35 @@ Timeout for each HTTP requests (Default: 5) =item B<--sahi-threads> -Number of simultaneous browser instances that can be executed (Default: 1) +Number of simultaneous browser instances that can be executed (default: 1) =item B<--sahi-startwith> -Specify the start mode (Default: BROWSER) +Define the start mode (Default: BROWSER) =item B<--sahi-browsertype> -Browser on which scripts will be executed (Default: chrome) +Browser used for script executions (Default: chrome) =item B<--sahi-baseurl> -Url where the script should start +Define default Start URL for scripts =item B<--timeout> -Specify the global script timeout. If timeout is reached, scenario is killed. +Define the global script timeout. If timeout is reached, scenario is killed. =item B<--retries-scenario-status> -Specify the number of retries to get scenario status (if we fail to get the status). +Define the number of retries to get scenario status (if we fail to get the status). =item B<--interval-scenario-status> -Specify time interval to get scenario status in seconds (Default: 10). +Define time interval to get scenario status in seconds (default: 10). =item B<--unknown-run-status> -Threshold unknown for running scenario rest api response. +Unknown threshold for running scenario rest api response. (Default: '%{http_code} < 200 or %{http_code} >= 300') =item B<--warning-run-status> @@ -524,17 +523,17 @@ Critical threshold for running scenario rest api response. =item B<--warning-status> -Set warning threshold for scenario status. +Define the conditions to match for the status to be WARNING. You can use the following variables: %{status}. =item B<--critical-status> -Set critical threshold for scenario status (Default: '%{status} ne "SUCCESS"'). +Define the conditions to match for the status to be CRITICAL (default: '%{status} ne "SUCCESS"'). You can use the following variables: %{status}. =item B<--warning-*> B<--critical-*> -Set thresholds. +Thresholds. Can be: 'total-time', 'total-steps', 'failures', 'errors', 'step-time'. =back diff --git a/src/apps/sahipro/restapi/plugin.pm b/src/apps/sahipro/restapi/plugin.pm index 724cea800..e3d85cf3e 100644 --- a/src/apps/sahipro/restapi/plugin.pm +++ b/src/apps/sahipro/restapi/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $self->{modes} = { 'scenario' => 'apps::sahipro::restapi::mode::scenario' }; From 1c07247e6ba69196f2d541e4fec3a755fcb83b60 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 18 Jul 2023 10:55:46 +0200 Subject: [PATCH 05/24] (plugin) apps::monitoring::speedtest - use Ookla version (#4563) --- .../speedtest/mode/internetbandwidth.pm | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/apps/monitoring/speedtest/mode/internetbandwidth.pm b/src/apps/monitoring/speedtest/mode/internetbandwidth.pm index e7ced13cd..eda57e3a1 100644 --- a/src/apps/monitoring/speedtest/mode/internetbandwidth.pm +++ b/src/apps/monitoring/speedtest/mode/internetbandwidth.pm @@ -26,28 +26,40 @@ use strict; use warnings; use JSON::XS; -sub prefix_global_output { +sub prefix_ping_output { my ($self, %options) = @_; - return 'speedtest '; + return 'ping '; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } } + { name => 'ping', type => 0, cb_prefix_output => 'prefix_ping_output', skipped_code => { -10 => 1 } }, + { name => 'bandwidth', type => 0, skipped_code => { -10 => 1 } } ]; - $self->{maps_counters}->{global} = [ - { label => 'ping-time', nlabel => 'ping.time.milliseconds', set => { - key_values => [ { name => 'ping' } ], - output_template => 'ping time: %d ms', + $self->{maps_counters}->{ping} = [ + { label => 'ping-latency', nlabel => 'ping.latency.milliseconds', set => { + key_values => [ { name => 'latency' } ], + output_template => 'latency: %.3f ms', perfdatas => [ { template => '%.3f', unit => 'ms', min => 0 } ] } }, + { label => 'ping-jitter', nlabel => 'ping.jitter.milliseconds', set => { + key_values => [ { name => 'jitter' } ], + output_template => 'jitter: %.3f', + perfdatas => [ + { template => '%.3f', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{bandwidth} = [ { label => 'bandwidth-download', nlabel => 'internet.bandwidth.download.bitspersecond', set => { key_values => [ { name => 'download' } ], output_template => 'download: %s %s/s', @@ -83,8 +95,8 @@ sub manage_selection { my ($self, %options) = @_; my ($output) = $options{custom}->execute_command( - command => 'speedtest-cli', - command_options => '--json' + command => 'speedtest', + command_options => '--format=json' ); my $decoded; @@ -95,10 +107,15 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => 'Cannot decode response'); $self->{output}->option_exit(); } - $self->{global} = { - ping => $decoded->{ping}, - download => $decoded->{download}, - upload => $decoded->{upload} + + $self->{ping} = { + latency => $decoded->{ping}->{latency}, + jitter => $decoded->{ping}->{jitter} + }; + + $self->{bandwidth} = { + download => $decoded->{download}->{bytes}, + upload => $decoded->{upload}->{bytes} }; } @@ -110,14 +127,14 @@ __END__ Check internet bandwidth. -Command used: speedtest-cli --json +Command used: speedtest --format=json =over 8 =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'ping-time', 'bandwidth-download', 'bandwidth-upload'. +Can be: 'ping-jitter', 'ping-latency', 'bandwidth-download', 'bandwidth-upload'. =back From 2e526c3fdf64772c68b87aed8f0f929bb6ed8711 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 18 Jul 2023 11:07:26 +0200 Subject: [PATCH 06/24] (plugin) cloud::azure::web::appservice - mode memory remove privatebytes (#4557) --- src/cloud/azure/common/appservice/mode/memory.pm | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/cloud/azure/common/appservice/mode/memory.pm b/src/cloud/azure/common/appservice/mode/memory.pm index 4949decd6..8b93ea6fb 100644 --- a/src/cloud/azure/common/appservice/mode/memory.pm +++ b/src/cloud/azure/common/appservice/mode/memory.pm @@ -44,14 +44,6 @@ sub get_metrics_mapping { 'unit' => 'B', 'min' => '0', 'max' => '', - }, - 'privatebytes' => { - 'output' => 'Private Bytes', - 'label' => 'app-private-bytes', - 'nlabel' => 'appservice.memory.privatebytes.usage.bytes', - 'unit' => 'B', - 'min' => '0', - 'max' => '', } }; @@ -146,12 +138,12 @@ Set resource group (Required if resource's name is used). =item B<--warning-*> Warning threshold where '*' can be: -'app-average-memory', 'app-memory', 'app-private-bytes'. +'app-average-memory', 'app-memory'. =item B<--critical-*> Critical threshold where '*' can be:. -'app-average-memory', 'app-memory', 'app-private-bytes'. +'app-average-memory', 'app-memory'. =back From 7251cad3ab7010faddd0a6f983ff8a60bbf6b503 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 19 Jul 2023 16:35:50 +0200 Subject: [PATCH 07/24] (plugin) apps::protocols::snmp - mode collection add instance splitting system (#4568) --- src/apps/protocols/snmp/mode/collection.pm | 49 ++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/apps/protocols/snmp/mode/collection.pm b/src/apps/protocols/snmp/mode/collection.pm index 2284b7f37..123af08d1 100644 --- a/src/apps/protocols/snmp/mode/collection.pm +++ b/src/apps/protocols/snmp/mode/collection.pm @@ -244,12 +244,28 @@ sub collect_snmp_tables { foreach (keys %$snmp_result) { /$used_instance/; next if (defined($self->{snmp_collected}->{tables}->{ $table->{name} }->{$1})); - $self->{snmp_collected}->{tables}->{ $table->{name} }->{$1} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1); + my $instance = $1; + + $self->{snmp_collected}->{tables}->{ $table->{name} }->{$instance} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); foreach my $sample_name (keys %$sampling) { $self->{snmp_collected_sampling}->{tables}->{ $table->{name} } = {} if (!defined($self->{snmp_collected_sampling}->{tables}->{ $table->{name} })); - $self->{snmp_collected_sampling}->{tables}->{ $table->{name} }->{$1}->{$sample_name} = - $self->{snmp_collected}->{tables}->{ $table->{name} }->{$1}->{$sample_name}; + $self->{snmp_collected_sampling}->{tables}->{ $table->{name} }->{$instance}->{$sample_name} = + $self->{snmp_collected}->{tables}->{ $table->{name} }->{$instance}->{$sample_name}; + } + + if (defined($table->{instance_entries})) { + my @matches = ($_ =~ /$table->{instance_entries}->{re}/); + foreach my $entry (@{$table->{instance_entries}->{entries}}) { + next if ($entry->{capture} !~ /^[0-9]+$/); + + my $value = ''; + if (defined($matches[ $entry->{capture} - 1])) { + $value = $matches[ $entry->{capture} - 1]; + } + + $self->{snmp_collected}->{tables}->{ $table->{name} }->{$instance}->{ $entry->{name} } = $value; + } } } } @@ -387,6 +403,27 @@ sub collect_snmp_sampling { $self->{snmp_cache}->write(data => { snmp_collected_sampling => $self->{snmp_collected_sampling} }); } +sub display_variables { + my ($self, %options) = @_; + + $self->{output}->output_add(long_msg => '======> variables', debug => 1); + foreach my $tbl_name (keys %{$self->{snmp_collected}->{tables}}) { + my $expr = 'snmp.tables.' . $tbl_name; + foreach my $instance (keys %{$self->{snmp_collected}->{tables}->{$tbl_name}}) { + foreach my $attr (keys %{$self->{snmp_collected}->{tables}->{$tbl_name}->{$instance}}) { + $self->{output}->output_add( + long_msg => sprintf( + ' %s = %s', + $expr . ".[$instance].$attr", + $self->{snmp_collected}->{tables}->{$tbl_name}->{$instance}->{$attr} + ), + debug => 1 + ); + } + } + } +} + sub collect_snmp { my ($self, %options) = @_; @@ -411,8 +448,14 @@ sub collect_snmp { } $self->collect_snmp_sampling(snmp => $options{snmp}); + + if ($self->{output}->is_debug()) { + $self->display_variables(); + } } + + sub exist_table_name { my ($self, %options) = @_; From f99ad766629e0daeedadabf691ff88286fcda770 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 19 Jul 2023 16:36:08 +0200 Subject: [PATCH 08/24] (plugin) apps::backup::rubrik::restapi - mode jobs add cache and limit (#4566) --- src/apps/backup/rubrik/restapi/custom/api.pm | 82 ++++++++++++++++---- src/apps/backup/rubrik/restapi/mode/cache.pm | 76 ++++++++++++++++++ src/apps/backup/rubrik/restapi/mode/jobs.pm | 82 +++++++++++++++----- src/apps/backup/rubrik/restapi/plugin.pm | 1 + 4 files changed, 208 insertions(+), 33 deletions(-) create mode 100644 src/apps/backup/rubrik/restapi/mode/cache.pm diff --git a/src/apps/backup/rubrik/restapi/custom/api.pm b/src/apps/backup/rubrik/restapi/custom/api.pm index 4fab88e2c..3273759f6 100644 --- a/src/apps/backup/rubrik/restapi/custom/api.pm +++ b/src/apps/backup/rubrik/restapi/custom/api.pm @@ -55,13 +55,15 @@ sub new { 'unknown-http-status:s' => { name => 'unknown_http_status' }, 'warning-http-status:s' => { name => 'warning_http_status' }, 'critical-http-status:s' => { name => 'critical_http_status' }, - 'token:s' => { name => 'token' } + 'token:s' => { name => 'token' }, + 'cache-use' => { name => 'cache_use' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); $self->{output} = $options{output}; - $self->{http} = centreon::plugins::http->new(%options); + $self->{http} = centreon::plugins::http->new(%options, default_backend => 'curl'); + $self->{cache_connect} = centreon::plugins::statefile->new(%options); $self->{cache} = centreon::plugins::statefile->new(%options); return $self; @@ -91,12 +93,14 @@ sub check_options { $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; $self->{token} = $self->{option_results}->{token}; + $self->{cache}->check_options(option_results => $self->{option_results}); + if (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); $self->{output}->option_exit(); } if (defined($self->{token})) { - $self->{cache}->check_options(option_results => $self->{option_results}); + $self->{cache_connect}->check_options(option_results => $self->{option_results}); return 0 if ($self->{token} ne ''); } @@ -105,7 +109,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => 'Need to specify --secret option.'); $self->{output}->option_exit(); } - $self->{cache}->check_options(option_results => $self->{option_results}); + $self->{cache_connect}->check_options(option_results => $self->{option_results}); return 0; } @@ -140,9 +144,9 @@ sub get_connection_info { sub get_token { my ($self, %options) = @_; - my $has_cache_file = $self->{cache}->read(statefile => 'rubrik_api_' . md5_hex($self->{option_results}->{hostname} . '_' . $self->{api_username})); - my $token = $self->{cache}->get(name => 'token'); - my $md5_secret_cache = $self->{cache}->get(name => 'md5_secret'); + my $has_cache_file = $self->{cache_connect}->read(statefile => 'rubrik_api_' . md5_hex($self->{option_results}->{hostname} . '_' . $self->{api_username})); + my $token = $self->{cache_connect}->get(name => 'token'); + my $md5_secret_cache = $self->{cache_connect}->get(name => 'md5_secret'); my $md5_secret = md5_hex($self->{api_username} . $self->{api_password}); if ($has_cache_file == 0 || @@ -177,7 +181,7 @@ sub get_token { token => $decoded->{token}, md5_secret => $md5_secret }; - $self->{cache}->write(data => $datas); + $self->{cache_connect}->write(data => $datas); } return $token; @@ -186,9 +190,9 @@ sub get_token { sub get_service_account_token { my ($self, %options) = @_; - my $has_cache_file = $self->{cache}->read(statefile => 'rubrik_api_' . md5_hex($self->{option_results}->{hostname} . '_' . $self->{service_account})); - my $token = $self->{cache}->get(name => 'token'); - my $md5_secret_cache = $self->{cache}->get(name => 'md5_secret'); + my $has_cache_file = $self->{cache_connect}->read(statefile => 'rubrik_api_' . md5_hex($self->{option_results}->{hostname} . '_' . $self->{service_account})); + my $token = $self->{cache_connect}->get(name => 'token'); + my $md5_secret_cache = $self->{cache_connect}->get(name => 'md5_secret'); my $md5_secret = md5_hex($self->{service_account} . $self->{secret}); if ($has_cache_file == 0 || @@ -235,7 +239,7 @@ sub get_service_account_token { token => $decoded->{token}, md5_secret => $md5_secret }; - $self->{cache}->write(data => $datas); + $self->{cache_connect}->write(data => $datas); } return $token; @@ -245,7 +249,7 @@ sub clean_token { my ($self, %options) = @_; my $datas = { updated => time() }; - $self->{cache}->write(data => $datas); + $self->{cache_connect}->write(data => $datas); } sub credentials { @@ -374,6 +378,54 @@ sub request_api { return $result; } +sub write_cache_file { + my ($self, %options) = @_; + + $self->{cache}->read(statefile => 'cache_rubrik_' . $options{statefile} . '_' . md5_hex($self->get_connection_info())); + $self->{cache}->write(data => { + update_time => time(), + response => $options{response} + }); +} + +sub get_cache_file_response { + my ($self, %options) = @_; + + $self->{cache}->read(statefile => 'cache_rubrik_' . $options{statefile} . '_' . md5_hex($self->get_connection_info())); + my $response = $self->{cache}->get(name => 'response'); + if (!defined($response)) { + $self->{output}->add_option_msg(short_msg => 'Cache file missing'); + $self->{output}->option_exit(); + } + + return $response; +} + +sub cache_jobs_monitoring { + my ($self, %options) = @_; + + my $datas = $self->get_jobs_monitoring(disable_cache => 1, limit => $options{limit}); + $self->write_cache_file( + statefile => 'jobs_monitoring', + response => $datas + ); + + return $datas; +} + +sub get_jobs_monitoring { + my ($self, %options) = @_; + + return $self->get_cache_file_response(statefile => 'jobs_monitoring') + if (defined($self->{option_results}->{cache_use}) && !defined($options{disable_cache})); + + return $self->request_api( + endpoint => '/api/v1/job_monitoring', + label => 'jobMonitoringInfoList', + get_param => ['limit=' . $options{limit}] + ); +} + 1; __END__ @@ -428,6 +480,10 @@ Use token authentication. If option is empty, token is created. Set timeout in seconds (Default: 30). +=item B<--cache-use> + +Use the cache file (created with cache mode). + =back =head1 DESCRIPTION diff --git a/src/apps/backup/rubrik/restapi/mode/cache.pm b/src/apps/backup/rubrik/restapi/mode/cache.pm new file mode 100644 index 000000000..1c3f24eec --- /dev/null +++ b/src/apps/backup/rubrik/restapi/mode/cache.pm @@ -0,0 +1,76 @@ +# +# 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 apps::backup::rubrik::restapi::mode::cache; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'limit:s' => { name => 'limit' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{limit}) || $self->{option_results}->{limit} !~ /\d+/) { + $self->{option_results}->{limit} = 500; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{custom}->cache_jobs_monitoring(limit => $self->{option_results}->{limit}); + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'Cache files created successfully' + ); +} + +1; + +__END__ + +=head1 MODE + +Create cache files (job mode could use it with --cache-use option). + +=over 8 + +=item B<--limit> + +Define the number of entries to retrieve for the pagination (default: 500). + +=back + +=cut diff --git a/src/apps/backup/rubrik/restapi/mode/jobs.pm b/src/apps/backup/rubrik/restapi/mode/jobs.pm index 1e2925c13..83ca0a3f2 100644 --- a/src/apps/backup/rubrik/restapi/mode/jobs.pm +++ b/src/apps/backup/rubrik/restapi/mode/jobs.pm @@ -39,7 +39,7 @@ sub custom_last_exec_perfdata { $self->{output}->perfdata_add( nlabel => $self->{nlabel} . '.' . $unitdiv_long->{ $self->{instance_mode}->{option_results}->{unit} }, - instances => $self->{result_values}->{name}, + instances => [$self->{result_values}->{jobName}, $self->{result_values}->{jobType}], unit => $self->{instance_mode}->{option_results}->{unit}, value => $self->{result_values}->{lastExecSeconds} >= 0 ? floor($self->{result_values}->{lastExecSeconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }) : $self->{result_values}->{lastExecSeconds}, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), @@ -66,7 +66,7 @@ sub custom_duration_perfdata { $self->{output}->perfdata_add( nlabel => $self->{nlabel} . '.' . $unitdiv_long->{ $self->{instance_mode}->{option_results}->{unit} }, - instances => $self->{result_values}->{name}, + instances => [$self->{result_values}->{jobName}, $self->{result_values}->{jobType}], unit => $self->{instance_mode}->{option_results}->{unit}, value => floor($self->{result_values}->{durationSeconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), @@ -151,18 +151,29 @@ sub set_counters { $self->{maps_counters}->{failed} = [ { label => 'job-executions-failed-prct', nlabel => 'job.executions.failed.percentage', set => { - key_values => [ { name => 'failedPrct' } ], + key_values => [ { name => 'failedPrct' }, { name => 'jobName' }, { name => 'jobType' } ], output_template => 'number of failed executions: %.2f %%', - perfdatas => [ - { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } - ] + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => '%', + instances => [$self->{result_values}->{jobName}, $self->{result_values}->{jobType}], + value => sprintf('%.2f', $self->{result_values}->{failedPrct}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, + max => 100 + ); + } } } ]; $self->{maps_counters}->{timers} = [ { label => 'job-execution-last', nlabel => 'job.execution.last', set => { - key_values => [ { name => 'lastExecSeconds' }, { name => 'lastExecHuman' }, { name => 'name' } ], + key_values => [ { name => 'lastExecSeconds' }, { name => 'lastExecHuman' }, { name => 'jobName' }, { name => 'jobType' } ], output_template => 'last execution %s', output_use => 'lastExecHuman', closure_custom_perfdata => $self->can('custom_last_exec_perfdata'), @@ -170,7 +181,7 @@ sub set_counters { } }, { label => 'job-running-duration', nlabel => 'job.running.duration', set => { - key_values => [ { name => 'durationSeconds' }, { name => 'durationHuman' }, { name => 'name' } ], + key_values => [ { name => 'durationSeconds' }, { name => 'durationHuman' }, { name => 'jobName' }, { name => 'jobType' } ], output_template => 'running duration %s', output_use => 'durationHuman', closure_custom_perfdata => $self->can('custom_duration_perfdata'), @@ -206,7 +217,8 @@ sub new { 'filter-job-name:s' => { name => 'filter_job_name' }, 'filter-job-type:s' => { name => 'filter_job_type' }, 'filter-location-name:s' => { name => 'filter_location_name' }, - 'unit:s' => { name => 'unit', default => 's' } + 'unit:s' => { name => 'unit', default => 's' }, + 'limit:s' => { name => 'limit' } }); $self->{cache_exec} = centreon::plugins::statefile->new(%options); @@ -222,19 +234,21 @@ sub check_options { $self->{option_results}->{unit} = 's'; } + if (!defined($self->{option_results}->{limit}) || $self->{option_results}->{limit} !~ /\d+/) { + $self->{option_results}->{limit} = 500; + } + $self->{cache_exec}->check_options(option_results => $self->{option_results}, default_format => 'json'); } sub manage_selection { my ($self, %options) = @_; - my $jobs_exec = $options{custom}->request_api( - endpoint => '/api/v1/job_monitoring', - label => 'jobMonitoringInfoList' - ); + my $jobs_exec = $options{custom}->get_jobs_monitoring(limit => $self->{option_results}->{limit}); - $self->{cache_exec}->read(statefile => 'rubrik_' . $self->{mode} . '_' . + $self->{cache_exec}->read(statefile => 'rubrik_' . $self->{mode} . '_' . Digest::MD5::md5_hex( + $options{custom}->get_connection_info() . '_' . (defined($self->{option_results}->{filter_job_id}) ? $self->{option_results}->{filter_job_id} : '') . '_' . (defined($self->{option_results}->{filter_job_name}) ? $self->{option_results}->{filter_job_name} : '') . '_' . (defined($self->{option_results}->{filter_job_type}) ? $self->{option_results}->{filter_job_type} : '') @@ -256,10 +270,12 @@ sub manage_selection { next if (defined($self->{option_results}->{filter_location_name}) && $self->{option_results}->{filter_location_name} ne '' && $job_exec->{locationName} !~ /$self->{option_results}->{filter_location_name}/); + $job_exec->{jobType} = lc($job_exec->{jobType}); + if (!defined($self->{jobs}->{ $job_exec->{objectId} })) { $self->{jobs}->{ $job_exec->{objectId} } = { name => $job_exec->{objectName}, - jobType => lc($job_exec->{jobType}), + jobType => $job_exec->{jobType}, timers => {}, executions => {} }; @@ -284,6 +300,8 @@ sub manage_selection { } $self->{jobs}->{ $job_exec->{objectId} }->{failed} = { + jobName => $job_exec->{objectName}, + jobType => $job_exec->{jobType}, failedPrct => $total > 0 ? $failed * 100 / $total : 0 }; @@ -296,16 +314,21 @@ sub manage_selection { $last_exec->{startTime} =~ /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)/; my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6); - $last_exec_times->{ $job_exec->{objectId} } = $dt->epoch(); + $last_exec_times->{ $job_exec->{objectId} } = { + jobName => $job_exec->{objectName}, + jobType => $job_exec->{jobType}, + epoch => $dt->epoch() + }; } $self->{jobs}->{ $job_exec->{objectId} }->{timers} = { - name => $job_exec->{objectName}, - lastExecSeconds => defined($last_exec_times->{ $job_exec->{objectId} }) ? $ctime - $last_exec_times->{ $job_exec->{objectId} } : -1, + jobName => $job_exec->{objectName}, + jobType => $job_exec->{jobType}, + lastExecSeconds => defined($last_exec_times->{ $job_exec->{objectId} }) ? $ctime - $last_exec_times->{ $job_exec->{objectId} }->{epoch} : -1, lastExecHuman => 'never' }; if (defined($last_exec_times->{ $job_exec->{objectId} })) { - $self->{jobs}->{ $job_exec->{objectId} }->{timers}->{lastExecHuman} = centreon::plugins::misc::change_seconds(value => $ctime - $last_exec_times->{ $job_exec->{objectId} }); + $self->{jobs}->{ $job_exec->{objectId} }->{timers}->{lastExecHuman} = centreon::plugins::misc::change_seconds(value => $ctime - $last_exec_times->{ $job_exec->{objectId} }->{epoch}); } if (defined($older_running_exec)) { @@ -317,6 +340,21 @@ sub manage_selection { } } + foreach my $objectId (keys %$last_exec_times) { + next if (defined($self->{jobs}->{$objectId})); + + $self->{jobs}->{$objectId} = { + name => $last_exec_times->{$objectId}->{jobName}, + jobType => $last_exec_times->{$objectId}->{jobType}, + timers => { + jobName => $last_exec_times->{$objectId}->{jobName}, + jobType => $last_exec_times->{$objectId}->{jobType}, + lastExecSeconds => $ctime - $last_exec_times->{$objectId}->{epoch}, + lastExecHuman => centreon::plugins::misc::change_seconds(value => $ctime - $last_exec_times->{$objectId}->{epoch}) + } + }; + } + $self->{cache_exec}->write(data => { jobs => $last_exec_times }); @@ -353,6 +391,10 @@ Filter jobs by location name. Select the unit for last execution time threshold. May be 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days, 'w' for weeks. Default is seconds. +=item B<--limit> + +Define the number of entries to retrieve for the pagination (default: 500). + =item B<--unknown-execution-status> Set unknown threshold for last job execution status. @@ -365,7 +407,7 @@ You can use the following variables: %{status}, %{jobName} =item B<--critical-execution-status> -Set critical threshold for last job execution status (Default: %{status} =~ /Failure/i). +Set critical threshold for last job execution status (default: %{status} =~ /Failure/i). You can use the following variables: %{status}, %{jobName} =item B<--warning-*> B<--critical-*> diff --git a/src/apps/backup/rubrik/restapi/plugin.pm b/src/apps/backup/rubrik/restapi/plugin.pm index 488841b04..845801c62 100644 --- a/src/apps/backup/rubrik/restapi/plugin.pm +++ b/src/apps/backup/rubrik/restapi/plugin.pm @@ -30,6 +30,7 @@ sub new { bless $self, $class; $self->{modes} = { + 'cache' => 'apps::backup::rubrik::restapi::mode::cache', 'cluster' => 'apps::backup::rubrik::restapi::mode::cluster', 'compliance' => 'apps::backup::rubrik::restapi::mode::compliance', 'disks' => 'apps::backup::rubrik::restapi::mode::disks', From e557d62e6a0108bed55c7f98e4870504f5919637 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 21 Jul 2023 15:18:55 +0200 Subject: [PATCH 09/24] (plugin) hardware::ups::standard::rfc1628::snmp - mode alarms add test-status + mode output-lines add frequency (#4556) --- .../ups/powerware/snmp/mode/alarms.pm | 2 +- .../ups/standard/rfc1628/snmp/mode/alarms.pm | 110 +++++++++++++++++- .../standard/rfc1628/snmp/mode/outputlines.pm | 58 +++++---- 3 files changed, 141 insertions(+), 29 deletions(-) diff --git a/src/hardware/ups/powerware/snmp/mode/alarms.pm b/src/hardware/ups/powerware/snmp/mode/alarms.pm index 92736361f..aee1e5b33 100644 --- a/src/hardware/ups/powerware/snmp/mode/alarms.pm +++ b/src/hardware/ups/powerware/snmp/mode/alarms.pm @@ -194,4 +194,4 @@ Default: ^(?!(UtilityPowerRestored|NoticeCondition|ReturnFromLowBattery|AlarmEnt =back =cut - \ No newline at end of file + diff --git a/src/hardware/ups/standard/rfc1628/snmp/mode/alarms.pm b/src/hardware/ups/standard/rfc1628/snmp/mode/alarms.pm index 2ea0f5e3b..28872df09 100644 --- a/src/hardware/ups/standard/rfc1628/snmp/mode/alarms.pm +++ b/src/hardware/ups/standard/rfc1628/snmp/mode/alarms.pm @@ -24,12 +24,24 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use centreon::plugins::misc; + +sub custom_test_status_output { + my ($self, %options) = @_; + + return sprintf( + 'test status: %s [detail: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{detail} + ); +} sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0 } + { name => 'global', type => 0, skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ @@ -40,6 +52,18 @@ sub set_counters { { template => '%s', min => 0 } ] } + }, + { + label => 'test-status', + type => 2, + warning_default => '%{status} =~ /doneWarning|aborted/', + critical_default => '%{status} =~ /doneError/', + set => { + key_values => [ { name => 'status' }, { name => 'detail' } ], + closure_custom_output => $self->can('custom_test_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } } ] } @@ -49,23 +73,84 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => {}); + $options{options}->add_options(arguments => { + 'display-alarms' => { name => 'display_alarms' } + }); return $self; } +my $map_test = { + 1 => 'donePass', 2 => 'doneWarning', 3 => 'doneError', + 4 => 'aborted', 5 => 'inProgress', 6 => 'noTestsInitiated' +}; +my $map_alarm_desc = { + '.1.3.6.1.2.1.33.1.6.3.1' => 'batteryBad', + '.1.3.6.1.2.1.33.1.6.3.2' => 'onBattery', + '.1.3.6.1.2.1.33.1.6.3.3' => 'lowBattery', + '.1.3.6.1.2.1.33.1.6.3.4' => 'depletedBattery', + '.1.3.6.1.2.1.33.1.6.3.5' => 'tempBad', + '.1.3.6.1.2.1.33.1.6.3.6' => 'inputBad', + '.1.3.6.1.2.1.33.1.6.3.7' => 'outputBad', + '.1.3.6.1.2.1.33.1.6.3.8' => 'outputOverload', + '.1.3.6.1.2.1.33.1.6.3.9' => 'onBypass', + '.1.3.6.1.2.1.33.1.6.3.10' => 'bypassBad', + '.1.3.6.1.2.1.33.1.6.3.11' => 'outputOffAsRequested', + '.1.3.6.1.2.1.33.1.6.3.12' => 'upsOffAsRequested', + '.1.3.6.1.2.1.33.1.6.3.13' => 'chargerFailed', + '.1.3.6.1.2.1.33.1.6.3.14' => 'upsOutputOff', + '.1.3.6.1.2.1.33.1.6.3.15' => 'upsSystemOff', + '.1.3.6.1.2.1.33.1.6.3.16' => 'fanFailure', + '.1.3.6.1.2.1.33.1.6.3.17' => 'fuseFailure', + '.1.3.6.1.2.1.33.1.6.3.18' => 'generalFault', + '.1.3.6.1.2.1.33.1.6.3.19' => 'diagnosticTestFailed', + '.1.3.6.1.2.1.33.1.6.3.20' => 'communicationsLost', + '.1.3.6.1.2.1.33.1.6.3.21' => 'awaitingPower', + '.1.3.6.1.2.1.33.1.6.3.22' => 'shutdownPending', + '.1.3.6.1.2.1.33.1.6.3.23' => 'shutdownImminent', + '.1.3.6.1.2.1.33.1.6.3.24' => 'testInProgress' +}; + sub manage_selection { my ($self, %options) = @_; my $oid_upsAlarmsPresent = '.1.3.6.1.2.1.33.1.6.1.0'; + my $oid_upsTestResultsSummary = '.1.3.6.1.2.1.33.1.7.3.0'; + my $oid_upsTestResultsDetail = '.1.3.6.1.2.1.33.1.7.4.0'; my $snmp_result = $options{snmp}->get_leef( - oids => [ $oid_upsAlarmsPresent ], + oids => [ $oid_upsAlarmsPresent, $oid_upsTestResultsSummary, $oid_upsTestResultsDetail ], nothing_quit => 1 ); $self->{global} = { current_alarms => $snmp_result->{$oid_upsAlarmsPresent} }; + if (defined($snmp_result->{$oid_upsTestResultsSummary}) && defined($map_test->{ $snmp_result->{$oid_upsTestResultsSummary} })) { + $self->{global}->{status} = $map_test->{ $snmp_result->{$oid_upsTestResultsSummary} }; + $self->{global}->{detail} = defined($snmp_result->{$oid_upsTestResultsDetail}) && $snmp_result->{$oid_upsTestResultsDetail} ne '' ? + $snmp_result->{$oid_upsTestResultsDetail} : '-'; + } + + if ($snmp_result->{$oid_upsAlarmsPresent} > 0) { + my $oid_upsAlarmEntry = '.1.3.6.1.2.1.33.1.6.2.1'; + my $oid_upsAlarmDescr = '.1.3.6.1.2.1.33.1.6.2.1.2'; + my $oid_upsAlarmTime = '.1.3.6.1.2.1.33.1.6.2.1.3'; + + $snmp_result = $options{snmp}->get_table(oid => $oid_upsAlarmEntry); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$oid_upsAlarmDescr\.(.*)$/); + + if (defined($self->{option_results}->{display_alarms})) { + $self->{output}->output_add( + long_msg => sprintf( + 'alarm [since: %s]: %s', + centreon::plugins::misc::change_seconds(value => $snmp_result->{$oid_upsAlarmTime . '.' . $1}), + $map_alarm_desc->{ $snmp_result->{$oid_upsAlarmDescr . '.' . $1} } + ) + ); + } + } + } } 1; @@ -78,6 +163,25 @@ Check current alarms. =over 8 +=item B<--display-alarms> + +Display alarms in verbose output. + +=item B<--unknown-test-status> + +Define the conditions to match for the status to be UNKNOWN. +You can use the following variables: %{status}, %{detail} + +=item B<--warning-test-status> + +Define the conditions to match for the status to be WARNING (default: '%{status} =~ /doneWarning|aborted/'). +You can use the following variables: %{status}, %{detail} + +=item B<--critical-test-status> + +Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /doneError/'). +You can use the following variables: %{status}, %{detail} + =item B<--warning-*> B<--critical-*> Thresholds. diff --git a/src/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm b/src/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm index 707fb03a2..1c07362df 100644 --- a/src/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm +++ b/src/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm @@ -41,12 +41,20 @@ sub set_counters { { label => 'stdev', template => '%.2f' } ] } + }, + { label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => { + key_values => [ { name => 'frequency' } ], + output_template => 'frequence: %.2f Hz', + perfdatas => [ + { template => '%.2f', unit => 'Hz' } + ] + } } ]; $self->{maps_counters}->{oline} = [ { label => 'load', nlabel => 'line.output.load.percentage', set => { - key_values => [ { name => 'upsOutputPercentLoad' } ], + key_values => [ { name => 'outputPercentLoad' } ], output_template => 'load: %.2f %%', perfdatas => [ { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } @@ -54,7 +62,7 @@ sub set_counters { } }, { label => 'current', nlabel => 'line.output.current.ampere', set => { - key_values => [ { name => 'upsOutputCurrent' } ], + key_values => [ { name => 'outputCurrent' } ], output_template => 'current: %.2f A', perfdatas => [ { template => '%.2f', min => 0, unit => 'A', label_extra_instance => 1 } @@ -62,7 +70,7 @@ sub set_counters { } }, { label => 'voltage', nlabel => 'line.output.voltage.volt', set => { - key_values => [ { name => 'upsOutputVoltage' } ], + key_values => [ { name => 'outputVoltage' } ], output_template => 'voltage: %.2f V', perfdatas => [ { template => '%.2f', unit => 'V', label_extra_instance => 1 } @@ -70,7 +78,7 @@ sub set_counters { } }, { label => 'power', nlabel => 'line.output.power.watt', set => { - key_values => [ { name => 'upsOutputPower' } ], + key_values => [ { name => 'outputPower' } ], output_template => 'power: %.2f W', perfdatas => [ { template => '%.2f', unit => 'W', label_extra_instance => 1 } @@ -105,38 +113,41 @@ sub stdev { my $total = 0; my $num_present = scalar(keys %{$self->{oline}}); foreach my $instance (keys %{$self->{oline}}) { - next if (!defined($self->{oline}->{$instance}->{upsOutputPercentLoad})); - $total += $self->{oline}->{$instance}->{upsOutputPercentLoad}; + next if (!defined($self->{oline}->{$instance}->{outputPercentLoad})); + $total += $self->{oline}->{$instance}->{outputPercentLoad}; } my $mean = $total / $num_present; $total = 0; foreach my $instance (keys %{$self->{oline}}) { - next if (!defined($self->{oline}->{$instance}->{upsOutputPercentLoad})); - $total += ($mean - $self->{oline}->{$instance}->{upsOutputPercentLoad}) ** 2; + next if (!defined($self->{oline}->{$instance}->{outputPercentLoad})); + $total += ($mean - $self->{oline}->{$instance}->{outputPercentLoad}) ** 2; } my $stdev = sqrt($total / $num_present); - $self->{global} = { stdev => $stdev }; + $self->{global}->{stdev} = $stdev; } my $mapping = { - upsOutputVoltage => { oid => '.1.3.6.1.2.1.33.1.4.4.1.2' }, # in Volt - upsOutputCurrent => { oid => '.1.3.6.1.2.1.33.1.4.4.1.3' }, # in dA - upsOutputPower => { oid => '.1.3.6.1.2.1.33.1.4.4.1.4' }, # in Watt - upsOutputPercentLoad => { oid => '.1.3.6.1.2.1.33.1.4.4.1.5' } + outputVoltage => { oid => '.1.3.6.1.2.1.33.1.4.4.1.2' }, # in Volt + outputCurrent => { oid => '.1.3.6.1.2.1.33.1.4.4.1.3' }, # in dA + outputPower => { oid => '.1.3.6.1.2.1.33.1.4.4.1.4' }, # in Watt + outputPercentLoad => { oid => '.1.3.6.1.2.1.33.1.4.4.1.5' } }; -my $oid_upsOutputEntry = '.1.3.6.1.2.1.33.1.4.4.1'; +my $oid_outputFrequency = '.1.3.6.1.2.1.33.1.4.2.0'; # upsOutputFrequency +my $oid_outputEntry = '.1.3.6.1.2.1.33.1.4.4.1'; +my $oid_output = '.1.3.6.1.2.1.33.1.4'; # upsOutput sub manage_selection { my ($self, %options) = @_; $self->{oline} = {}; my $snmp_result = $options{snmp}->get_table( - oid => $oid_upsOutputEntry, + oid => $oid_output, nothing_quit => 1 ); + foreach my $oid (keys %$snmp_result) { - $oid =~ /^$oid_upsOutputEntry\.\d+\.(.*)$/; + next if ($oid !~ /^$oid_outputEntry\.\d+\.(.*)$/); my $instance = $1; next if (defined($self->{oline}->{$instance})); @@ -146,13 +157,15 @@ sub manage_selection { delete $result->{$_} if ($result->{$_} == 0); } } - $result->{upsOutputCurrent} *= 0.1 if (defined($result->{upsOutputCurrent})); + $result->{outputCurrent} *= 0.1 if (defined($result->{outputCurrent})); if (scalar(keys %$result) > 0) { $self->{oline}->{$instance} = { display => $instance, %$result }; } } + $self->{global} = {}; + $self->{global}->{frequency} = $snmp_result->{$oid_outputFrequency} * 0.1 if (defined($snmp_result->{$oid_outputFrequency})); if (scalar(keys %{$self->{oline}}) > 1) { $self->stdev(); } @@ -172,15 +185,10 @@ Check Output lines metrics (load, voltage, current and true power). Ignore counters equals to 0. -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Warning threshold. -Can be: 'load', 'voltage', 'current', 'power'. - -=item B<--critical-*> - -Critical threshold. -Can be: 'load', 'voltage', 'current', 'power'. +Threshold. +Can be: 'frequency', 'load', 'voltage', 'current', 'power'. =item B<--warning-stdev-3phases> From 92693dc6aed47f2b2bd13216fa379f721b01c049 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 21 Jul 2023 17:28:29 +0200 Subject: [PATCH 10/24] (plugin) storage::purestorage::flasharray::v2::restapi - fix illegal divsion by zero (#4565) --- .../purestorage/flasharray/v2/restapi/mode/volumes.pm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/storage/purestorage/flasharray/v2/restapi/mode/volumes.pm b/src/storage/purestorage/flasharray/v2/restapi/mode/volumes.pm index 293c87676..a77ca9041 100644 --- a/src/storage/purestorage/flasharray/v2/restapi/mode/volumes.pm +++ b/src/storage/purestorage/flasharray/v2/restapi/mode/volumes.pm @@ -196,15 +196,18 @@ sub manage_selection { name => $item->{name}, reduction => { data => $item->{space}->{data_reduction} - }, - space => { + } + }; + + if ($item->{provisioned} > 0) { + $self->{volumes}->{ $item->{name} }->{space} = { total => $item->{provisioned}, used => $item->{space}->{total_physical}, free => $item->{provisioned} - $item->{space}->{total_physical}, prct_used => $item->{space}->{total_physical} * 100 / $item->{provisioned}, prct_free => (100 - ($item->{space}->{total_physical} * 100 / $item->{provisioned})) - } - }; + }; + } } foreach my $perf (@$perfs) { From 8719c1edd168a362e8260ea8f8017af844ed0a96 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 24 Jul 2023 10:46:06 +0200 Subject: [PATCH 11/24] feat(ci): add workflow to package centreon-nrpe3 (#4569) Refs: MON-19408 --- .../docker/Dockerfile.packaging-plugins-alma8 | 2 +- .../docker/Dockerfile.packaging-plugins-alma9 | 2 +- .../Dockerfile.packaging-plugins-bullseye | 2 + .github/workflows/get-environment.yml | 2 + .github/workflows/nrpe.yml | 153 ++++++++++++++++++ nrpe/packaging/centreon-nrpe3-daemon.yaml | 92 +++++++++++ nrpe/packaging/centreon-nrpe3-plugin.yaml | 53 ++++++ nrpe/packaging/files/nrpe3.service.deb | 23 +++ nrpe/packaging/files/nrpe3.service.rpm | 23 +++ nrpe/packaging/files/nrpe3.sysconfig | 2 + .../files/nrpe3_add_centreon_cmd.patch | 29 ++++ .../centreon-nrpe3-daemon-postinstall.sh | 31 ++++ .../centreon-nrpe3-daemon-preinstall.sh | 4 + .../centreon-nrpe3-daemon-preremove.sh | 3 + 14 files changed, 419 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/nrpe.yml create mode 100644 nrpe/packaging/centreon-nrpe3-daemon.yaml create mode 100644 nrpe/packaging/centreon-nrpe3-plugin.yaml create mode 100644 nrpe/packaging/files/nrpe3.service.deb create mode 100644 nrpe/packaging/files/nrpe3.service.rpm create mode 100644 nrpe/packaging/files/nrpe3.sysconfig create mode 100644 nrpe/packaging/files/nrpe3_add_centreon_cmd.patch create mode 100644 nrpe/packaging/scripts/centreon-nrpe3-daemon-postinstall.sh create mode 100644 nrpe/packaging/scripts/centreon-nrpe3-daemon-preinstall.sh create mode 100644 nrpe/packaging/scripts/centreon-nrpe3-daemon-preremove.sh diff --git a/.github/docker/Dockerfile.packaging-plugins-alma8 b/.github/docker/Dockerfile.packaging-plugins-alma8 index e1f986e62..fa13fa291 100644 --- a/.github/docker/Dockerfile.packaging-plugins-alma8 +++ b/.github/docker/Dockerfile.packaging-plugins-alma8 @@ -10,7 +10,7 @@ baseurl=https://repo.goreleaser.com/yum/ enabled=1 gpgcheck=0' | tee /etc/yum.repos.d/goreleaser.repo -dnf -y install git gettext rpm-build dos2unix python3 epel-release nfpm jq zstd +dnf -y install gcc git gettext rpm-build dos2unix python3 epel-release nfpm openssl-devel jq zstd dnf -y install perl-App-cpanminus perl-JSON cpanm App::FatPacker cpanm File::Copy::Recursive diff --git a/.github/docker/Dockerfile.packaging-plugins-alma9 b/.github/docker/Dockerfile.packaging-plugins-alma9 index c7d393227..4e61f0b88 100644 --- a/.github/docker/Dockerfile.packaging-plugins-alma9 +++ b/.github/docker/Dockerfile.packaging-plugins-alma9 @@ -10,7 +10,7 @@ baseurl=https://repo.goreleaser.com/yum/ enabled=1 gpgcheck=0' | tee /etc/yum.repos.d/goreleaser.repo -dnf -y install git gettext rpm-build dos2unix python3 epel-release nfpm jq zstd +dnf -y install gcc git gettext rpm-build dos2unix python3 epel-release nfpm openssl-devel jq zstd dnf -y install perl-App-cpanminus perl-JSON cpanm App::FatPacker cpanm File::Copy::Recursive diff --git a/.github/docker/Dockerfile.packaging-plugins-bullseye b/.github/docker/Dockerfile.packaging-plugins-bullseye index 86136321a..a8cef0424 100644 --- a/.github/docker/Dockerfile.packaging-plugins-bullseye +++ b/.github/docker/Dockerfile.packaging-plugins-bullseye @@ -25,6 +25,7 @@ apt-get install -y \ dh-make \ aptitude \ ca-certificates \ + libssh-dev \ lintian \ pbuilder \ quilt \ @@ -33,6 +34,7 @@ apt-get install -y \ devscripts \ fakeroot \ curl \ + gcc \ git \ python3 \ libjson-perl \ diff --git a/.github/workflows/get-environment.yml b/.github/workflows/get-environment.yml index fe41e6e73..663da1814 100644 --- a/.github/workflows/get-environment.yml +++ b/.github/workflows/get-environment.yml @@ -54,6 +54,8 @@ jobs: if [[ "${{ inputs.version_file }}" == "" ]]; then VERSION=$(date '+%Y%m%d') + elif [[ "${{ inputs.version_file }}" == */*.yaml ]]; then + VERSION=$(grep 'version: ' ${{ inputs.version_file }} | cut -d' ' -f2 | tr -d '"') else VERSION=$(grep VERSION ${{ inputs.version_file }} | cut -d "'" -f 2) fi diff --git a/.github/workflows/nrpe.yml b/.github/workflows/nrpe.yml new file mode 100644 index 000000000..5174ad860 --- /dev/null +++ b/.github/workflows/nrpe.yml @@ -0,0 +1,153 @@ +name: nrpe + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +on: + workflow_dispatch: + pull_request: + paths: + - 'nrpe/packaging/**' + push: + branches: + - develop + - master + paths: + - 'nrpe/packaging/**' + tags: + - centreon-nrpe-* + +jobs: + get-environment: + uses: ./.github/workflows/get-environment.yml + with: + version_file: nrpe/packaging/centreon-nrpe3-daemon.yaml + + package: + needs: [get-environment] + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + include: + - package_extension: rpm + image: packaging-plugins-alma8 + distrib: el8 + - package_extension: rpm + image: packaging-plugins-alma9 + distrib: el9 + - package_extension: deb + image: packaging-plugins-bullseye + distrib: bullseye + + container: + image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }} + credentials: + username: ${{ secrets.DOCKER_REGISTRY_ID }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWD }} + + name: package ${{ matrix.distrib }} + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Download nrpe sources + run: | + curl -Lo - "https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-${{ needs.get-environment.outputs.version }}/nrpe-${{ needs.get-environment.outputs.version }}.tar.gz" | tar zxpf - + mv nrpe-${{ needs.get-environment.outputs.version }} nrpe-src + shell: bash + + - name: Compile sources + run: | + cd nrpe-src + + patch -p1 < ../nrpe/packaging/files/nrpe3_add_centreon_cmd.patch + + if [ "${{ matrix.package_extension }}" = "deb" ]; then + NAGIOS_PLUGINS_PATH="/usr/lib/nagios/plugins" + else + NAGIOS_PLUGINS_PATH="/usr/lib64/nagios/plugins" + fi + + CXXFLAGS="-Wall -Wextra" ./configure \ + --libexecdir="$NAGIOS_PLUGINS_PATH" \ + --localstatedir="/var/log/nrpe" \ + --sysconfdir="/etc/nrpe" \ + --enable-command-args \ + --with-nrpe-user="centreon-engine" \ + --with-nrpe-group="centreon-engine" \ + --with-nrpe-port="5666" \ + --with-nagios-user="centreon-engine" \ + --with-nagios-group="centreon-engine" + + make all + shell: bash + + - name: Generate debug files + run: | + cd nrpe-src/src + for file in "nrpe" "check_nrpe"; do + objcopy --only-keep-debug $file $file.debug + objcopy --strip-debug $file + objcopy --add-gnu-debuglink $file.debug $file + done + shell: bash + + - name: Package + uses: ./.github/actions/package + with: + nfpm_file_pattern: "nrpe/packaging/*.yaml" + distrib: ${{ matrix.distrib }} + package_extension: ${{ matrix.package_extension }} + version: ${{ needs.get-environment.outputs.version }} + release: ${{ needs.get-environment.outputs.release }} + commit_hash: ${{ github.sha }} + cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }} + rpm_gpg_key: ${{ secrets.RPM_GPG_SIGNING_KEY }} + rpm_gpg_signing_key_id: ${{ secrets.RPM_GPG_SIGNING_KEY_ID }} + rpm_gpg_signing_passphrase: ${{ secrets.RPM_GPG_SIGNING_PASSPHRASE }} + + deliver-rpm: + needs: [get-environment, package] + if: ${{ contains(fromJson('["stable", "testing", "unstable"]'), needs.get-environment.outputs.stability) }} + runs-on: [self-hosted, common] + + strategy: + matrix: + distrib: [el8, el9] + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Delivery + uses: ./.github/actions/rpm-delivery + with: + module_name: nrpe + distrib: ${{ matrix.distrib }} + cache_key: ${{ github.sha }}-${{ github.run_id }}-rpm-${{ matrix.distrib }} + stability: ${{ needs.get-environment.outputs.stability }} + artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} + + deliver-deb: + needs: [get-environment ,package] + if: ${{ contains(fromJson('["stable", "testing", "unstable"]'), needs.get-environment.outputs.stability) }} + runs-on: [self-hosted, common] + + strategy: + matrix: + distrib: [bullseye] + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Delivery + uses: ./.github/actions/deb-delivery + with: + distrib: ${{ matrix.distrib }} + cache_key: ${{ github.sha }}-${{ github.run_id }}-deb-${{ matrix.distrib }} + stability: ${{ needs.get-environment.outputs.stability }} + artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} diff --git a/nrpe/packaging/centreon-nrpe3-daemon.yaml b/nrpe/packaging/centreon-nrpe3-daemon.yaml new file mode 100644 index 000000000..f5b69df2e --- /dev/null +++ b/nrpe/packaging/centreon-nrpe3-daemon.yaml @@ -0,0 +1,92 @@ +name: "centreon-nrpe3-daemon" +arch: "amd64" +platform: "linux" +version_schema: "none" +version: "4.1.0" +release: "${RELEASE}${DIST}" +section: "default" +priority: "optional" +maintainer: "Centreon " +description: | + The centreon-nrpe packages contains the Nagios Remote Plug-ins Executor. + Daemon which can execute predefined commands on the remote host. + Commit: @COMMIT_HASH@ +vendor: "Centreon" +homepage: "https://centreon.com" +license: "GPLv2+" + +contents: + - src: "../../nrpe-src/src/nrpe" + dst: "/usr/sbin/centreon-nrpe3" + + - src: "../../nrpe-src/sample-config/nrpe.cfg" + dst: "/etc/nrpe/centreon-nrpe3.cfg" + type: config|noreplace + file_info: + mode: 0644 + + - src: "files/nrpe3.sysconfig" + dst: "/etc/sysconfig/centreon-nrpe3" + packager: rpm + file_info: + mode: 0644 + - src: "files/nrpe3.sysconfig" + dst: "/etc/default/centreon-nrpe3" + packager: deb + file_info: + mode: 0644 + + - src: "files/nrpe3.service.rpm" + dst: "/lib/systemd/system/centreon-nrpe3.service" + packager: rpm + file_info: + mode: 0644 + - src: "files/nrpe3.service.deb" + dst: "/lib/systemd/system/centreon-nrpe3.service" + packager: deb + file_info: + mode: 0644 + + - dst: "/var/log/nrpe" + type: dir + file_info: + mode: 0755 + owner: centreon-engine + group: centreon-engine + + - dst: "/var/log/nrpe/centplugins" + type: dir + file_info: + mode: 0755 + owner: centreon-engine + group: centreon-engine + +scripts: + preinstall: ./scripts/centreon-nrpe3-daemon-preinstall.sh + postinstall: ./scripts/centreon-nrpe3-daemon-postinstall.sh + preremove: ./scripts/centreon-nrpe3-daemon-preremove.sh + +overrides: + rpm: + replaces: + - centreon-nrpe3-daemon-debuginfo + - centreon-nrpe3-daemon-debugsource + conflicts: + - centreon-nrpe3-daemon-debuginfo + - centreon-nrpe3-daemon-debugsource + provides: + - centreon-nrpe3-daemon-debuginfo + - centreon-nrpe3-daemon-debugsource + deb: + replaces: + - centreon-nrpe3-daemon-dbgsym + conflicts: + - centreon-nrpe3-daemon-dbgsym + provides: + - centreon-nrpe3-daemon-dbgsym + +rpm: + summary: Nagios Remote Plugins Execution daemon + signature: + key_file: ${RPM_SIGNING_KEY_FILE} + key_id: ${RPM_SIGNING_KEY_ID} diff --git a/nrpe/packaging/centreon-nrpe3-plugin.yaml b/nrpe/packaging/centreon-nrpe3-plugin.yaml new file mode 100644 index 000000000..7b7df77fe --- /dev/null +++ b/nrpe/packaging/centreon-nrpe3-plugin.yaml @@ -0,0 +1,53 @@ +name: "centreon-nrpe3-plugin" +arch: "amd64" +platform: "linux" +version_schema: "none" +version: "4.1.0" +release: "${RELEASE}${DIST}" +section: "default" +priority: "optional" +maintainer: "Centreon " +description: | + Plug-in for Centreon monitoring system. + The centreon-nrpe packages contains the Nagios Remote Plug-ins Executor + Commit: @COMMIT_HASH@ +vendor: "Centreon" +homepage: "https://centreon.com" +license: "GPLv2+" + +contents: + - src: "../../nrpe-src/src/check_nrpe" + dst: "/usr/lib64/nagios/plugins/check_centreon_nrpe3" + packager: rpm + file_info: + mode: 0755 + - src: "../../nrpe-src/src/check_nrpe" + dst: "/usr/lib/nagios/plugins/check_centreon_nrpe3" + packager: deb + file_info: + mode: 0755 + +overrides: + rpm: + replaces: + - centreon-nrpe3-plugin-debuginfo + - centreon-nrpe3-plugin-debugsource + conflicts: + - centreon-nrpe3-plugin-debuginfo + - centreon-nrpe3-plugin-debugsource + provides: + - centreon-nrpe3-plugin-debuginfo + - centreon-nrpe3-plugin-debugsource + deb: + replaces: + - centreon-nrpe3-plugin-dbgsym + conflicts: + - centreon-nrpe3-plugin-dbgsym + provides: + - centreon-nrpe3-plugin-dbgsym + +rpm: + summary: Nagios plugin for NRPE + signature: + key_file: ${RPM_SIGNING_KEY_FILE} + key_id: ${RPM_SIGNING_KEY_ID} diff --git a/nrpe/packaging/files/nrpe3.service.deb b/nrpe/packaging/files/nrpe3.service.deb new file mode 100644 index 000000000..bfc1bfd1d --- /dev/null +++ b/nrpe/packaging/files/nrpe3.service.deb @@ -0,0 +1,23 @@ +[Unit] +Description=Nagios Remote Program Executor +Documentation=http://www.nagios.org/documentation +After=var-run.mount nss-lookup.target network.target local-fs.target time-sync.target +Before=getty@tty1.service plymouth-quit.service xdm.service +Conflicts=nrpe.socket +Requires=network.target + +[Service] +Type=forking +User=centreon-engine +Group=centreon-engine +EnvironmentFile=/etc/default/centreon-nrpe3 +ExecStart=/usr/sbin/centreon-nrpe3 -c /etc/nrpe/centreon-nrpe3.cfg -d $NRPE_OPT +Restart=on-abort +PIDFile=/var/log/nrpe/nrpe3.pid +ExecStopPost=/bin/rm -f /var/log/nrpe/nrpe3.pid +TimeoutStopSec=60 +PrivateTmp=false +OOMScoreAdjust=-500 + +[Install] +WantedBy=multi-user.target diff --git a/nrpe/packaging/files/nrpe3.service.rpm b/nrpe/packaging/files/nrpe3.service.rpm new file mode 100644 index 000000000..f98e04848 --- /dev/null +++ b/nrpe/packaging/files/nrpe3.service.rpm @@ -0,0 +1,23 @@ +[Unit] +Description=Nagios Remote Program Executor +Documentation=http://www.nagios.org/documentation +After=var-run.mount nss-lookup.target network.target local-fs.target time-sync.target +Before=getty@tty1.service plymouth-quit.service xdm.service +Conflicts=nrpe.socket +Requires=network.target + +[Service] +Type=forking +User=centreon-engine +Group=centreon-engine +EnvironmentFile=/etc/sysconfig/centreon-nrpe3 +ExecStart=/usr/sbin/centreon-nrpe3 -c /etc/nrpe/centreon-nrpe3.cfg -d $NRPE_OPT +Restart=on-abort +PIDFile=/var/log/nrpe/nrpe3.pid +ExecStopPost=/bin/rm -f /var/log/nrpe/nrpe3.pid +TimeoutStopSec=60 +PrivateTmp=false +OOMScoreAdjust=-500 + +[Install] +WantedBy=multi-user.target diff --git a/nrpe/packaging/files/nrpe3.sysconfig b/nrpe/packaging/files/nrpe3.sysconfig new file mode 100644 index 000000000..a1fe957b4 --- /dev/null +++ b/nrpe/packaging/files/nrpe3.sysconfig @@ -0,0 +1,2 @@ +# specify additional command line arguments for nrpe +NRPE_OPT="" diff --git a/nrpe/packaging/files/nrpe3_add_centreon_cmd.patch b/nrpe/packaging/files/nrpe3_add_centreon_cmd.patch new file mode 100644 index 000000000..a4777ae4c --- /dev/null +++ b/nrpe/packaging/files/nrpe3_add_centreon_cmd.patch @@ -0,0 +1,29 @@ +--- a/sample-config/nrpe.cfg.in 2018-09-14 13:40:08.496324915 +0200 ++++ b/sample-config/nrpe.cfg.in 2018-09-14 13:47:57.624296953 +0200 +@@ -40,7 +40,7 @@ + # number. The file is only written if the NRPE daemon is started by the root + # user and is running in standalone mode. + +-pid_file=@piddir@/nrpe.pid ++pid_file=@piddir@/nrpe3.pid + + + +@@ -119,7 +119,7 @@ + # + # Values: 0=do not allow arguments, 1=allow command arguments + +-dont_blame_nrpe=0 ++dont_blame_nrpe=1 + + + +@@ -300,7 +300,7 @@ + command[check_hda1]=@pluginsdir@/check_disk -w 20% -c 10% -p /dev/hda1 + command[check_zombie_procs]=@pluginsdir@/check_procs -w 5 -c 10 -s Z + command[check_total_procs]=@pluginsdir@/check_procs -w 150 -c 200 +- ++command[check_centreon_plugins]=/usr/lib/centreon/plugins/centreon_linux_local.pl --plugin=$ARG1$ --mode=$ARG2$ $ARG3$ + + # The following examples allow user-supplied arguments and can + # only be used if the NRPE daemon was compiled with support for diff --git a/nrpe/packaging/scripts/centreon-nrpe3-daemon-postinstall.sh b/nrpe/packaging/scripts/centreon-nrpe3-daemon-postinstall.sh new file mode 100644 index 000000000..e09f20b74 --- /dev/null +++ b/nrpe/packaging/scripts/centreon-nrpe3-daemon-postinstall.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +startNrpeDaemon() { + systemctl daemon-reload ||: + systemctl unmask centreon-nrpe3.service ||: + systemctl preset centreon-nrpe3.service ||: + systemctl enable centreon-nrpe3.service ||: + systemctl restart centreon-nrpe3.service ||: +} + +action="$1" +if [ "$1" = "configure" ] && [ -z "$2" ]; then + # Alpine linux does not pass args, and deb passes $1=configure + action="install" +elif [ "$1" = "configure" ] && [ -n "$2" ]; then + # deb passes $1=configure $2= + action="upgrade" +fi + +case "$action" in + "1" | "install") + startNrpeDaemon + ;; + "2" | "upgrade") + startNrpeDaemon + ;; + *) + # $1 == version being installed + startNrpeDaemon + ;; +esac diff --git a/nrpe/packaging/scripts/centreon-nrpe3-daemon-preinstall.sh b/nrpe/packaging/scripts/centreon-nrpe3-daemon-preinstall.sh new file mode 100644 index 000000000..7b06f7680 --- /dev/null +++ b/nrpe/packaging/scripts/centreon-nrpe3-daemon-preinstall.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +getent group centreon-engine > /dev/null 2>&1 || groupadd -r centreon-engine +getent passwd centreon-engine > /dev/null 2>&1 || useradd -g centreon-engine -m -d /var/lib/centreon-engine -r centreon-engine > /dev/null 2>&1 ||: diff --git a/nrpe/packaging/scripts/centreon-nrpe3-daemon-preremove.sh b/nrpe/packaging/scripts/centreon-nrpe3-daemon-preremove.sh new file mode 100644 index 000000000..da79e7631 --- /dev/null +++ b/nrpe/packaging/scripts/centreon-nrpe3-daemon-preremove.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +systemctl stop centreon-nrpe3.service ||: From f4a5f4ed889567f48b73368f207cee6c8bdaa495 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 25 Jul 2023 08:53:51 +0200 Subject: [PATCH 12/24] enh(plugin): better handle when graph cannot be retrieved (#4544) --- src/notification/email/mode/alert.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/notification/email/mode/alert.pm b/src/notification/email/mode/alert.pm index bc5e20447..f54ed6ef2 100644 --- a/src/notification/email/mode/alert.pm +++ b/src/notification/email/mode/alert.pm @@ -580,6 +580,8 @@ sub service_message { my $img; if ($self->{http}->get_code() !~ /200/ || $content =~ /^OK/) { $img = '

No graph

'; + } elsif ($content =~ /Access denied|Resource not found|Invalid token/) { + $img = '

Cannot retrieve graph: ' . $content . '

'; } else { $self->{payload_attachment}->{png} = $content; $img = '\n"; @@ -948,7 +950,7 @@ sub run { my $email; - if (defined($self->{payload_attachment}->{png}) && $self->{payload_attachment}->{png} ne '' && $self->{payload_attachment}->{png} ne 'Resource not found' ) { + if (defined($self->{payload_attachment}->{png}) && $self->{payload_attachment}->{png} ne '') { my $img_cid = $self->{option_results}->{host_name} . '_' . $self->{option_results}->{service_description}; $email = Email::MIME->create( From ffd0ef8129419c5491feb60ead38f4402b9cb961 Mon Sep 17 00:00:00 2001 From: Luth1ng <64541164+Luth1ng@users.noreply.github.com> Date: Tue, 25 Jul 2023 10:54:43 +0400 Subject: [PATCH 13/24] Update and rename alcatel-isam-device-collection.json to alcatel-isam-boards-collection.json (#4574) --- .../snmp/alcatel-isam-boards-collection.json | 258 ++++++++++++++++++ .../snmp/alcatel-isam-device-collection.json | 178 ------------ 2 files changed, 258 insertions(+), 178 deletions(-) create mode 100644 src/contrib/collection/snmp/alcatel-isam-boards-collection.json delete mode 100644 src/contrib/collection/snmp/alcatel-isam-device-collection.json diff --git a/src/contrib/collection/snmp/alcatel-isam-boards-collection.json b/src/contrib/collection/snmp/alcatel-isam-boards-collection.json new file mode 100644 index 000000000..df9e2cd22 --- /dev/null +++ b/src/contrib/collection/snmp/alcatel-isam-boards-collection.json @@ -0,0 +1,258 @@ +{ + "mapping": { + "eqptSlotPowerStatus": { + "1": "powerUp", + "2": "powerDown" + }, + "eqptBoardAdminStatus": { + "1": "unlock", + "2": "lock" + }, + "eqptBoardOperStatus": { + "1": "operUp", + "2": "operDown" + }, + "eqptBoardOperError": { + "1": "no-error", + "2": "type-mismatch", + "3": "board-missing", + "4": "board-installation-missing", + "5": "no-planned-board", + "6": "waiting-for-sw", + "7": "init-boot-failed", + "8": "init-download-failed", + "9": "init-connection-failed", + "10": "init-configuration-failed", + "11": "board-reset-protection", + "12": "invalid-parameter", + "13": "temperature-alarm", + "14": "tempshutdown", + "15": "defense", + "16": "board-not-licensed", + "17": "sem-power-fail", + "18": "sem-ups-fail", + "19": "board-in-incompatible-slot", + "21": "download-ongoing", + "255": "unknown-error" + }, + "eqptBoardAvailStatus": { + "1": "available", + "2": "inTest", + "3": "failed", + "4": "powerOff", + "5": "notInstalled", + "6": "offLine", + "7": "dependency" + }, + "eqptBoardRestart": { + "1": "with-selftest", + "2": "without-selftest", + "5": "hot-restart", + "255": "initialValue" + }, + "eqptBoardLastRestartCause": { + "1": "poweron", + "2": "unknown", + "3": "watchdog", + "4": "coldreset", + "5": "warmreset", + "6": "hotreset", + "7": "hotreload", + "8": "cleandata", + "9": "emergencybuild", + "10": "poweronreset", + "11": "commitfailure", + "12": "timezonemodified" + }, + "eqptBoardContainerOffset": { + "0": "iont:1/1", + "1": "nt-a", + "2": "nt-b", + "3": "lt:1/1/1", + "4": "lt:1/1/2", + "5": "lt:1/1/3", + "6": "lt:1/1/4", + "7": "lt:1/1/5", + "8": "lt:1/1/6", + "9": "lt:1/1/7", + "10": "lt:1/1/8", + "11": "lt:1/1/12", + "12": "lt:1/1/13", + "13": "lt:1/1/14", + "14": "lt:1/1/15", + "15": "lt:1/1/16", + "16": "lt:1/1/17", + "17": "lt:1/1/18", + "18": "lt:1/1/19" + } + }, + "constants": { + "warningStatus": "operDown", + "filtereqptSlotPlannedType": "NOT_PLANNED" + }, + "snmp": { + "tables": [ + { + "name": "eqptBoardEntry", + "oid": ".1.3.6.1.4.1.637.61.1.23.3.1", + "used_instance": "\\.(\\d+)$", + "entries" :[ + { "name": "eqptSlotPlannedType", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.2" }, + { "name": "eqptSlotActualType", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.3" }, + { "name": "eqptSlotPowerStatus", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.4", "map": "eqptSlotPowerStatus" }, + { "name": "eqptBoardAdminStatus", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.5", "map": "eqptBoardAdminStatus" }, + { "name": "eqptBoardOperStatus", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.6", "map": "eqptBoardOperStatus" }, + { "name": "eqptBoardOperError", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.7", "map": "eqptBoardOperError" }, + { "name": "eqptBoardAvailStatus", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.8", "map": "eqptBoardAvailStatus" }, + { "name": "eqptBoardRestart", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.9", "map": "eqptBoardRestart" }, + { "name": "eqptBoardContainerOffset", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.12", "map": "eqptBoardContainerOffset" }, + { "name": "eqptBoardInventoryTypeName", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.14" }, + { "name": "eqptBoardInventoryPBACode", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.15" }, + { "name": "eqptBoardInventorySerialNumber", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.19" }, + { "name": "eqptBoardLastRestartCause", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.24", "map": "eqptBoardLastRestartCause" }, + { "name": "eqptBoardLastRestartTime", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.25" } + ] + }, + { + "name": "eqptBoardThermalSensorEntry", + "oid": ".1.3.6.1.4.1.637.61.1.23.10.1", + "used_instance": "\\.(\\d+\\.\\d+)$", + "entries" :[ + { "name": "eqptBoardThermalSensorId", "oid": ".1.3.6.1.4.1.637.61.1.23.10.1.1" }, + { "name": "eqptBoardThermalSensorActualTemperature", "oid": ".1.3.6.1.4.1.637.61.1.23.10.1.2" }, + { "name": "eqptBoardThermalSensorTcaThresholdLow", "oid": ".1.3.6.1.4.1.637.61.1.23.10.1.3" }, + { "name": "eqptBoardThermalSensorTcaThresholdHigh", "oid": ".1.3.6.1.4.1.637.61.1.23.10.1.4" }, + { "name": "eqptBoardThermalSensorShutdownThresholdLow", "oid": ".1.3.6.1.4.1.637.61.1.23.10.1.5" }, + { "name": "eqptBoardThermalSensorShutdownThresholdHigh", "oid": ".1.3.6.1.4.1.637.61.1.23.10.1.6" } + ], + "instance_entries": { + "re": "\\.(\\d+)\\.(\\d+)$", + "entries": [ + { "name": "slotId", "capture": "1" }, + { "name": "thermalSensorId", "capture": "2" } + ] + } + } + ] + + }, + "selection": [ + { + "name": "operUp", + "functions": [ + { + "type": "count", + "src": "%(snmp.tables.eqptBoardEntry)", + "filter": "%(src.eqptBoardOperStatus) eq %(name)", + "save": "%(numOperUp)" + } + ], + "perfdatas": [ + { + "nlabel": "isam.device.%(name).count", + "value": "%(numOperUp)", + "min": 0 + + } + ], + "formatting": { + "printf_msg": "Number of %s cards: %d", + "printf_var": [ + "%(name)", + "%(numOperUp)" + ], + "display_ok": false + } + }, + { + "name": "operDown", + "functions": [ + { + "type": "count", + "src": "%(snmp.tables.eqptBoardEntry)", + "filter": "%(src.eqptSlotPlannedType) ne %(constants.filtereqptSlotPlannedType) and %(src.eqptBoardOperStatus) eq %(name)", + "save": "%(numOperDown)" + } + ], + "perfdatas": [ + { + "nlabel": "isam.device.%(name).count", + "value": "%(numOperDown)", + "min": 0 + + } + ], + "formatting": { + "printf_msg": "Number of %s cards: %d", + "printf_var": [ + "%(name)", + "%(numOperDown)" + ], + "display_ok": false + } + } + ], + "selection_loop": [ + { + "name": "eqptBoardTable", + "source": "%(snmp.tables.eqptBoardEntry)", + "expand_table": { + "eqptBoardEntry": "%(snmp.tables.eqptBoardEntry.[%(eqptBoardEntry.instance)])" + }, + "warning": "%(eqptBoardEntry.eqptSlotPlannedType) ne %(constants.filtereqptSlotPlannedType) and %(eqptBoardEntry.eqptBoardOperStatus) eq %(constants.warningStatus)", + "filter": "%(eqptBoardEntry.eqptSlotPlannedType) ne %(constants.filtereqptSlotPlannedType)", + "formatting": { + "printf_msg": "Card %s (%s): status is %s (%s), power status is %s, planned is %s", + "printf_var": [ + "%(eqptBoardEntry.eqptSlotActualType)", + "%(eqptBoardEntry.eqptBoardContainerOffset)", + "%(eqptBoardEntry.eqptBoardOperStatus)", + "%(eqptBoardEntry.eqptBoardOperError)", + "%(eqptBoardEntry.eqptSlotPowerStatus)", + "%(eqptBoardEntry.eqptSlotPlannedType)" + ], + "display_ok": true + } + }, + { + "name": "eqptBoardThermalSensorTable", + "source": "%(snmp.tables.eqptBoardThermalSensorEntry)", + "expand_table": { + "eqptBoardThermalSensorEntry": "%(snmp.tables.eqptBoardThermalSensorEntry.[%(eqptBoardThermalSensorEntry.instance)])", + "eqptBoardEntry": "%(snmp.tables.eqptBoardEntry.[%(eqptBoardThermalSensorEntry.slotId)])" + }, + "perfdatas": [ + { + "nlabel": "%(eqptBoardEntry.eqptBoardContainerOffset).%(eqptBoardThermalSensorEntry.thermalSensorId).temp", + "instances": + [ + "%(eqptBoardEntry.eqptBoardContainerOffset)", + "%(eqptBoardThermalSensorEntry.thermalSensorId)" + ], + "value": "%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorActualTemperature)", + "warning": "%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorTcaThresholdLow)", + "critical": "%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorShutdownThresholdLow)", + "min": 0, + "unit": "°C" + } + ], + "warning": "%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorActualTemperature) > (%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorShutdownThresholdLow) - %(eqptBoardThermalSensorEntry.eqptBoardThermalSensorShutdownThresholdLow) * 0.10)", + "critical": "%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorActualTemperature) > (%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorShutdownThresholdLow) - %(eqptBoardThermalSensorEntry.eqptBoardThermalSensorShutdownThresholdLow) * 0.05)", + "formatting": { + "printf_msg": "Card %s (%s): sensor #%s temperature is %s°C (shutdown at %s°C)\n", + "printf_var": [ + "%(eqptBoardEntry.eqptSlotActualType)", + "%(eqptBoardEntry.eqptBoardContainerOffset)", + "%(eqptBoardThermalSensorEntry.thermalSensorId)", + "%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorActualTemperature)", + "%(eqptBoardThermalSensorEntry.eqptBoardThermalSensorShutdownThresholdLow)" + ], + "display_ok": false + } + } + ], + "formatting": { + "custom_message_global": "All ISAM Boards are OK", + "separator": "-" + } +} diff --git a/src/contrib/collection/snmp/alcatel-isam-device-collection.json b/src/contrib/collection/snmp/alcatel-isam-device-collection.json deleted file mode 100644 index 33b0f53c3..000000000 --- a/src/contrib/collection/snmp/alcatel-isam-device-collection.json +++ /dev/null @@ -1,178 +0,0 @@ -{ - "mapping": { - "eqptSlotPowerStatus": { - "1": "powerUp", - "2": "powerDown" - }, - "eqptBoardAdminStatus": { - "1": "unlock", - "2": "lock" - }, - "eqptBoardOperStatus": { - "1": "operUp", - "2": "operDown" - }, - "eqptBoardOperError": { - "1": "no-error", - "2": "type-mismatch", - "3": "board-missing", - "4": "board-installation-missing", - "5": "no-planned-board", - "6": "waiting-for-sw", - "7": "init-boot-failed", - "8": "init-download-failed", - "9": "init-connection-failed", - "10": "init-configuration-failed", - "11": "board-reset-protection", - "12": "invalid-parameter", - "13": "temperature-alarm", - "14": "tempshutdown", - "15": "defense", - "16": "board-not-licensed", - "17": "sem-power-fail", - "18": "sem-ups-fail", - "19": "board-in-incompatible-slot", - "21": "download-ongoing", - "255": "unknown-error" - }, - "eqptBoardAvailStatus": { - "1": "available", - "2": "inTest", - "3": "failed", - "4": "powerOff", - "5": "notInstalled", - "6": "offLine", - "7": "dependency" - }, - "eqptBoardRestart": { - "1": "with-selftest", - "2": "without-selftest", - "5": "hot-restart", - "255": "initialValue" - }, - "eqptBoardLastRestartCause": { - "1": "poweron", - "2": "unknown", - "3": "watchdog", - "4": "coldreset", - "5": "warmreset", - "6": "hotreset", - "7": "hotreload", - "8": "cleandata", - "9": "emergencybuild", - "10": "poweronreset", - "11": "commitfailure", - "12": "timezonemodified" - } - }, - "constants": { - "criticalStatus": "operDown" - }, - "snmp": { - "tables": [ - { - "name": "eqptBoardEntry", - "oid": ".1.3.6.1.4.1.637.61.1.23.3.1", - "used_instance": "\\.(\\d+)$", - "entries" :[ - { "name": "eqptSlotPlannedType", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.2" }, - { "name": "eqptSlotActualType", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.3" }, - { "name": "eqptSlotPowerStatus", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.4", "map": "eqptSlotPowerStatus" }, - { "name": "eqptBoardAdminStatus", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.5", "map": "eqptBoardAdminStatus" }, - { "name": "eqptBoardOperStatus", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.6", "map": "eqptBoardOperStatus" }, - { "name": "eqptBoardOperError", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.7", "map": "eqptBoardOperError" }, - { "name": "eqptBoardAvailStatus", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.8", "map": "eqptBoardAvailStatus" }, - { "name": "eqptBoardRestart", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.9", "map": "eqptBoardRestart" }, - { "name": "eqptBoardContainerOffset", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.12" }, - { "name": "eqptBoardInventoryTypeName", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.14" }, - { "name": "eqptBoardInventoryPBACode", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.15" }, - { "name": "eqptBoardInventorySerialNumber", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.19" }, - { "name": "eqptBoardLastRestartCause", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.24", "map": "eqptBoardLastRestartCause" }, - { "name": "eqptBoardLastRestartTime", "oid": ".1.3.6.1.4.1.637.61.1.23.3.1.25" } - ] - } - ] - - }, - "selection": [ - { - "name": "operUp", - "functions": [ - { - "type": "count", - "src": "%(snmp.tables.eqptBoardEntry)", - "filter": "%(src.eqptBoardOperStatus) eq %(name)", - "save": "%(numOperUp)" - } - ], - "perfdatas": [ - { - "nlabel": "isam.device.%(name).count", - "value": "%(numOperUp)", - "min": 0 - - } - ], - "formatting": { - "printf_msg": "Number of %s device: %d", - "printf_var": [ - "%(name)", - "%(numOperUp)" - ], - "display_ok": false - } - }, - { - "name": "operDown", - "functions": [ - { - "type": "count", - "src": "%(snmp.tables.eqptBoardEntry)", - "filter": "%(src.eqptBoardOperStatus) eq %(name)", - "save": "%(numOperDown)" - } - ], - "perfdatas": [ - { - "nlabel": "isam.device.%(name).count", - "value": "%(numOperDown)", - "min": 0 - - } - ], - "formatting": { - "printf_msg": "Number of %s device: %d", - "printf_var": [ - "%(name)", - "%(numOperDown)" - ], - "display_ok": false - } - } - ], - "selection_loop": [ - { - "name": "eqptSlot ISAM", - "source": "%(snmp.tables.eqptBoardEntry)", - "expand_table": { - "eqptBoardEntry": "%(snmp.tables.eqptBoardEntry.[%(eqptBoardEntry.instance)])" - }, - "critical": "%(eqptBoardEntry.eqptBoardOperStatus) =~ /%(constants.criticalStatus)/", - "formatting": { - "printf_msg": "Card %s (slot%s): status is %s (%s), power status is %s", - "printf_var": [ - "%(eqptBoardEntry.eqptSlotActualType)", - "%(eqptBoardEntry.eqptBoardContainerOffset)", - "%(eqptBoardEntry.eqptBoardOperStatus)", - "%(eqptBoardEntry.eqptBoardOperError)", - "%(eqptBoardEntry.eqptSlotPowerStatus)" - ], - "display_ok": true - } - } - ], - "formatting": { - "custom_message_global": "All ISAM Boards are OK", - "separator": "-" - } -} From 9f778ed15b62079d8c6412a955ac70f9e72d65a4 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 25 Jul 2023 09:24:35 +0200 Subject: [PATCH 14/24] mode collection - handle negative value for perfdata (#4577) --- src/apps/protocols/http/mode/collection.pm | 2 +- src/apps/protocols/snmp/mode/collection.pm | 2 +- src/centreon/common/protocols/sql/mode/collection.pm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/protocols/http/mode/collection.pm b/src/apps/protocols/http/mode/collection.pm index 4a6391eb9..eb5a2475d 100644 --- a/src/apps/protocols/http/mode/collection.pm +++ b/src/apps/protocols/http/mode/collection.pm @@ -64,7 +64,7 @@ sub custom_select_perfdata { return if (!defined($self->{result_values}->{config}->{perfdatas})); foreach (@{$self->{result_values}->{config}->{perfdatas}}) { - next if (!defined($_->{value}) || $_->{value} !~ /^\d+(?:\.\d+)?$/); + next if (!defined($_->{value}) || $_->{value} !~ /^[+-]?\d+(?:\.\d+)?$/); $self->{output}->perfdata_add(%$_); } } diff --git a/src/apps/protocols/snmp/mode/collection.pm b/src/apps/protocols/snmp/mode/collection.pm index 123af08d1..51de19786 100644 --- a/src/apps/protocols/snmp/mode/collection.pm +++ b/src/apps/protocols/snmp/mode/collection.pm @@ -59,7 +59,7 @@ sub custom_select_perfdata { return if (!defined($self->{result_values}->{config}->{perfdatas})); foreach (@{$self->{result_values}->{config}->{perfdatas}}) { - next if (!defined($_->{value}) || $_->{value} !~ /^\d+(?:\.\d+)?$/); + next if (!defined($_->{value}) || $_->{value} !~ /^[+-]?\d+(?:\.\d+)?$/); $self->{output}->perfdata_add(%$_); } } diff --git a/src/centreon/common/protocols/sql/mode/collection.pm b/src/centreon/common/protocols/sql/mode/collection.pm index 4508c0737..911555f53 100644 --- a/src/centreon/common/protocols/sql/mode/collection.pm +++ b/src/centreon/common/protocols/sql/mode/collection.pm @@ -60,7 +60,7 @@ sub custom_select_perfdata { return if (!defined($self->{result_values}->{config}->{perfdatas})); foreach (@{$self->{result_values}->{config}->{perfdatas}}) { - next if (!defined($_->{value}) || $_->{value} !~ /^\d+(?:\.\d+)?$/); + next if (!defined($_->{value}) || $_->{value} !~ /^[+-]?\d+(?:\.\d+)?$/); $self->{output}->perfdata_add(%$_); } } From aff78244303bdf76f23238613b076ee54e987a5a Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 25 Jul 2023 15:44:51 +0200 Subject: [PATCH 15/24] (plugin) os::linux::local - mode process inacurrate memory usage (#4529) --- src/os/linux/local/mode/process.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/linux/local/mode/process.pm b/src/os/linux/local/mode/process.pm index 074a4b5c3..d63f48a7a 100644 --- a/src/os/linux/local/mode/process.pm +++ b/src/os/linux/local/mode/process.pm @@ -295,7 +295,7 @@ sub add_memory { next if ($options{content} !~ /==>\s*\/proc\/$pid\/statm.*?\n(.*?)(?:==>|\Z)/ms); my @values = split(/\s+/, $1); - my $memory_used = ($values[1] * $self->{option_results}->{page_size}) + ($values[5] * $self->{option_results}->{page_size}); + my $memory_used = ($values[1] * $self->{option_results}->{page_size}); $self->{processes}->{$pid}->{memory_used} = $memory_used; $self->{global}->{memory_used} += $memory_used; } From c1f9f9c545a7f85c34bc6b21fc73acbb84aef517 Mon Sep 17 00:00:00 2001 From: sdepassio <114986849+sdepassio@users.noreply.github.com> Date: Mon, 7 Aug 2023 11:08:52 +0200 Subject: [PATCH 16/24] Fix mockoon (use version 3 and not the latest) (#4592) --- .github/workflows/tests-functional.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests-functional.yml b/.github/workflows/tests-functional.yml index 2ce749aac..084fcebde 100644 --- a/.github/workflows/tests-functional.yml +++ b/.github/workflows/tests-functional.yml @@ -25,7 +25,7 @@ jobs: node-version: "16.x" - name: Install Mockoon CLI - run: npm install -g -D @mockoon/cli + run: npm install -g -D @mockoon/cli@3.1.0 - name: Install libs run: sudo apt-get install libcurl4-openssl-dev From 0772e7880cf51f8878f03e028d3c71a3a3f17bb9 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 7 Aug 2023 13:01:59 +0200 Subject: [PATCH 17/24] (plugin) network::audiocodes::snmp - add sbc-calls mode + metric v2 (#4567) * wip * wip * wip * wip --- .../snmp/mode/components/fantray.pm | 25 ++- .../audiocodes/snmp/mode/components/module.pm | 26 ++- .../audiocodes/snmp/mode/components/psu.pm | 27 ++- src/network/audiocodes/snmp/mode/cpu.pm | 78 +++++--- src/network/audiocodes/snmp/mode/hardware.pm | 5 +- .../audiocodes/snmp/mode/interfaces.pm | 182 ++++++++++++++++++ .../audiocodes/snmp/mode/listtrunks.pm | 59 +++--- src/network/audiocodes/snmp/mode/memory.pm | 72 ++++--- src/network/audiocodes/snmp/mode/sbccalls.pm | 177 +++++++++++++++++ .../audiocodes/snmp/mode/trunkstatus.pm | 124 +++++------- src/network/audiocodes/snmp/plugin.pm | 16 +- 11 files changed, 593 insertions(+), 198 deletions(-) create mode 100644 src/network/audiocodes/snmp/mode/interfaces.pm create mode 100644 src/network/audiocodes/snmp/mode/sbccalls.pm diff --git a/src/network/audiocodes/snmp/mode/components/fantray.pm b/src/network/audiocodes/snmp/mode/components/fantray.pm index a8c1003c3..e85b65b4a 100644 --- a/src/network/audiocodes/snmp/mode/components/fantray.pm +++ b/src/network/audiocodes/snmp/mode/components/fantray.pm @@ -29,11 +29,11 @@ my %map_status = ( 2 => 'warning', 3 => 'minor', 4 => 'major', - 5 => 'critical', + 5 => 'critical' ); my %map_existence = ( 1 => 'present', - 2 => 'missing', + 2 => 'missing' ); my $mapping = { @@ -59,20 +59,27 @@ sub check { next if ($oid !~ /^$mapping->{acSysFanTraySeverity}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysFanTrayEntry}, instance => $instance); - + next if ($result->{acSysFanTrayExistence} eq 'missing' && - $self->absent_problem(section => 'fantray', instance => $instance)); + $self->absent_problem(section => 'fantray', instance => $instance)); next if ($self->check_filter(section => 'fantray', instance => $instance)); $self->{components}->{fantray}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan tray '%s' status is '%s' [instance = %s]", - $instance, $result->{acSysFanTraySeverity}, $instance)); + $self->{output}->output_add( + long_msg => sprintf( + "fan tray '%s' status is '%s' [instance: %s]", + $instance, $result->{acSysFanTraySeverity}, $instance + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'fantray', value => $result->{acSysFanTraySeverity}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan tray '%s' status is '%s'", $instance, $result->{acSysFanTraySeverity})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Fan tray '%s' status is '%s'", $instance, $result->{acSysFanTraySeverity}) + ); } } } -1; \ No newline at end of file +1; diff --git a/src/network/audiocodes/snmp/mode/components/module.pm b/src/network/audiocodes/snmp/mode/components/module.pm index c0efe4bc0..093d450e0 100644 --- a/src/network/audiocodes/snmp/mode/components/module.pm +++ b/src/network/audiocodes/snmp/mode/components/module.pm @@ -30,16 +30,16 @@ my %map_status = ( 4 => 'moduleBackToServiceStart', 5 => 'moduleMismatch', 6 => 'moduleFaulty', - 7 => 'notApplicable', + 7 => 'notApplicable' ); my %map_existence = ( 1 => 'present', - 2 => 'missing', + 2 => 'missing' ); my $mapping = { acSysModulePresence => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.21.1.4', map => \%map_existence }, - acSysModuleFRUstatus => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.21.1.14', map => \%map_status }, + acSysModuleFRUstatus => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.21.1.14', map => \%map_status } }; my $oid_acSysModuleEntry = '.1.3.6.1.4.1.5003.9.10.10.4.21.1'; @@ -60,20 +60,26 @@ sub check { next if ($oid !~ /^$mapping->{acSysModuleFRUstatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysModuleEntry}, instance => $instance); - + next if ($result->{acSysModulePresence} eq 'missing' && - $self->absent_problem(section => 'module', instance => $instance)); + $self->absent_problem(section => 'module', instance => $instance)); next if ($self->check_filter(section => 'module', instance => $instance)); $self->{components}->{module}->{total}++; - $self->{output}->output_add(long_msg => sprintf("module '%s' status is '%s' [instance = %s]", - $instance, $result->{acSysModuleFRUstatus}, $instance)); + $self->{output}->output_add( + long_msg => sprintf( + "module '%s' status is '%s' [instance: %s]", + $instance, $result->{acSysModuleFRUstatus}, $instance + ) + ); my $exit = $self->get_severity(section => 'module', value => $result->{acSysModuleFRUstatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Module '%s' status is '%s'", $instance, $result->{acSysModuleFRUstatus})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Module '%s' status is '%s'", $instance, $result->{acSysModuleFRUstatus}) + ); } } } -1; \ No newline at end of file +1; diff --git a/src/network/audiocodes/snmp/mode/components/psu.pm b/src/network/audiocodes/snmp/mode/components/psu.pm index 1080f4a01..f10a24263 100644 --- a/src/network/audiocodes/snmp/mode/components/psu.pm +++ b/src/network/audiocodes/snmp/mode/components/psu.pm @@ -29,16 +29,16 @@ my %map_status = ( 3 => 'warning', 4 => 'minor', 5 => 'major', - 6 => 'critical', + 6 => 'critical' ); my %map_existence = ( 1 => 'present', - 2 => 'missing', + 2 => 'missing' ); my $mapping = { acSysPowerSupplyExistence => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.23.1.3', map => \%map_existence }, - acSysPowerSupplySeverity => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.23.1.6', map => \%map_status }, + acSysPowerSupplySeverity => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.23.1.6', map => \%map_status } }; my $oid_acSysPowerSupplyEntry = '.1.3.6.1.4.1.5003.9.10.10.4.23.1'; @@ -59,20 +59,27 @@ sub check { next if ($oid !~ /^$mapping->{acSysPowerSupplySeverity}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysPowerSupplyEntry}, instance => $instance); - + next if ($result->{acSysPowerSupplyExistence} eq 'missing' && - $self->absent_problem(section => 'psu', instance => $instance)); + $self->absent_problem(section => 'psu', instance => $instance)); next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]", - $instance, $result->{acSysPowerSupplySeverity}, $instance)); + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is '%s' [instance: %s]", + $instance, $result->{acSysPowerSupplySeverity}, $instance + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{acSysPowerSupplySeverity}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power supply '%s' status is '%s'", $instance, $result->{acSysPowerSupplySeverity})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", $instance, $result->{acSysPowerSupplySeverity}) + ); } } } -1; \ No newline at end of file +1; diff --git a/src/network/audiocodes/snmp/mode/cpu.pm b/src/network/audiocodes/snmp/mode/cpu.pm index 3b80e42d1..8fc384464 100644 --- a/src/network/audiocodes/snmp/mode/cpu.pm +++ b/src/network/audiocodes/snmp/mode/cpu.pm @@ -25,41 +25,58 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "CPU '" . $options{instance} . "' "; +} + sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'global', type => 0, message_separator => ' - ' }, + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU(s) average usages are ok', skipped_code => { -10 => 1 } } ]; + $self->{maps_counters}->{global} = [ { label => 'voip', nlabel => 'cpu.voip.utilization.percentage', set => { key_values => [ { name => 'voip' } ], - output_template => 'CPU VoIp Usage : %.2f %%', + output_template => 'CPU VoIp usage: %.2f %%', perfdatas => [ - { label => 'cpu_voip', value => 'voip', template => '%.2f', min => 0, max => 100, unit => '%' }, - ], + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] } }, { label => 'data', nlabel => 'cpu.data.utilization.percentage', set => { key_values => [ { name => 'data' } ], - output_template => 'CPU Data Usage : %.2f %%', + output_template => 'CPU data usage: %.2f %%', perfdatas => [ - { label => 'cpu_data', value => 'data', template => '%.2f', min => 0, max => 100, unit => '%' }, - ], + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] } - }, + } + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'core-cpu-utilization', nlabel => 'core.cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_usage' } ], + output_template => 'average usage is: %.2f%%', + perfdatas => [ + { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { }); + return $self; } @@ -68,11 +85,21 @@ sub manage_selection { my $oid_acSysStateVoIpCpuUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.10.0'; my $oid_acSysStateDataCpuUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.8.0'; - my $snmp_result = $options{snmp}->get_leef(oids => [ - $oid_acSysStateVoIpCpuUtilization, $oid_acSysStateDataCpuUtilization - ], nothing_quit => 1); - + my $snmp_result = $options{snmp}->get_leef( + oids => [$oid_acSysStateVoIpCpuUtilization, $oid_acSysStateDataCpuUtilization], + nothing_quit => 1 + ); + $self->{global} = { data => $snmp_result->{$oid_acSysStateDataCpuUtilization}, voip => $snmp_result->{$oid_acSysStateVoIpCpuUtilization} }; + + my $oid_acKpiCpuStatsCurrentCpuCpuUtilization = '.1.3.6.1.4.1.5003.15.2.4.1.2.1.1.2'; + $snmp_result = $options{snmp}->get_table(oid => $oid_acKpiCpuStatsCurrentCpuCpuUtilization); + + $self->{cpu} = {}; + foreach (keys %$snmp_result) { + /\.(\d+)$/; + $self->{cpu}->{$1} = { cpu_usage => $snmp_result->{$_} }; + } } 1; @@ -81,7 +108,7 @@ __END__ =head1 MODE -Check CPU usages. +Check CPU usage. =over 8 @@ -90,15 +117,10 @@ Check CPU usages. Only display some counters (regexp can be used). Example: --filter-counters='^voip$' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Warning threshold. -Can be: 'voip', 'data'. - -=item B<--critical-*> - -Critical threshold. -Can be: 'voip', 'data'. +Threshold. +Can be: 'voip', 'data', 'core-cpu-utilization'. =back diff --git a/src/network/audiocodes/snmp/mode/hardware.pm b/src/network/audiocodes/snmp/mode/hardware.pm index 8a05179d3..61c98e4e7 100644 --- a/src/network/audiocodes/snmp/mode/hardware.pm +++ b/src/network/audiocodes/snmp/mode/hardware.pm @@ -63,7 +63,7 @@ sub snmp_execute { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => {}); @@ -77,7 +77,7 @@ __END__ =head1 MODE -Check Hardware. +Check hardware. =over 8 @@ -100,7 +100,6 @@ Can be specific or global: --absent-problem=psu,1 Define the expected status if no components are found (default: critical). - =item B<--threshold-overload> Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). diff --git a/src/network/audiocodes/snmp/mode/interfaces.pm b/src/network/audiocodes/snmp/mode/interfaces.pm new file mode 100644 index 000000000..1865c7b74 --- /dev/null +++ b/src/network/audiocodes/snmp/mode/interfaces.pm @@ -0,0 +1,182 @@ +# +# 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 network::audiocodes::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-global> + +Check global port statistics (By default if no --add-* option is set). + +=item B<--add-status> + +Check interface status. + +=item B<--add-duplex-status> + +Check duplex status (with --warning-status and --critical-status). + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-errors> + +Check interface errors. + +=item B<--add-cast> + +Check interface cast. + +=item B<--add-speed> + +Check interface speed. + +=item B<--add-volume> + +Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). + +=item B<--check-metrics> + +If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"'). + +=item B<--warning-status> + +Define the conditions to match for the status to be WARNING. +You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--critical-status> + +Define the conditions to match for the status to be CRITICAL (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast', +'speed' (b/s). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter'). + +=item B<--nagvis-perfdata> + +Display traffic perfdata to be compatible with nagvis widget. + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interfaces'). + +=item B<--name> + +Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions. + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--map-speed-dsl> + +Get interface speed configuration for interface type 'adsl' and 'vdsl2'. + +Syntax: --map-speed-dsl=interface-src-name,interface-dsl-name + +E.g: --map-speed-dsl=Et0.835,Et0-vdsl2 + +=item B<--force-counters64> + +Force to use 64 bits counters only. Can be used to improve performance. + +=item B<--force-counters32> + +Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-display> + +Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> + +Regexp src to transform display value. + +=item B<--display-transform-dst> + +Regexp dst to transform display value. + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/src/network/audiocodes/snmp/mode/listtrunks.pm b/src/network/audiocodes/snmp/mode/listtrunks.pm index b90f5c1dd..bc7265241 100644 --- a/src/network/audiocodes/snmp/mode/listtrunks.pm +++ b/src/network/audiocodes/snmp/mode/listtrunks.pm @@ -30,10 +30,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); - $self->{trunks} = {}; + $options{options}->add_options(arguments => {}); + return $self; } @@ -43,13 +41,15 @@ sub check_options { } my %map_deactivate = (0 => 'notAvailable', 1 => 'deActivated', 2 => 'activated'); -my %map_alarm = (0 => 'greyDisabled', 1 => 'greenActive', 2 => 'redLosLof', -3 => 'blueAis', 4 => 'yellowRai', 5 => 'orangeDChannel', 6 => 'purpleLowerLayerDown', 7 => 'darkOrangeNFASAlarm'); +my %map_alarm = ( + 0 => 'greyDisabled', 1 => 'greenActive', 2 => 'redLosLof', + 3 => 'blueAis', 4 => 'yellowRai', 5 => 'orangeDChannel', 6 => 'purpleLowerLayerDown', 7 => 'darkOrangeNFASAlarm' +); my $mapping = { acTrunkStatusAlarm => { oid => '.1.3.6.1.4.1.5003.9.10.9.2.1.1.1.7', map => \%map_alarm }, acTrunkDeactivate => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.11', map => \%map_deactivate }, - acTrunkName => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.13' }, + acTrunkName => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.13' } }; sub manage_selection { @@ -58,10 +58,12 @@ sub manage_selection { my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping->{acTrunkStatusAlarm}->{oid} }, { oid => $mapping->{acTrunkDeactivate}->{oid} }, - { oid => $mapping->{acTrunkName}->{oid} }, + { oid => $mapping->{acTrunkName}->{oid} } ], - return_type => 1, nothing_quit => 1); + return_type => 1, nothing_quit => 1 + ); + my $results = {}; foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{acTrunkName}->{oid}\.(.*)$/); my $instance = $1; @@ -72,24 +74,35 @@ sub manage_selection { next; } - $self->{trunks}->{$instance} = - { name => $result->{acTrunkName}, status => $result->{acTrunkStatusAlarm}, state => $result->{acTrunkDeactivate} }; + $results->{$instance} = { + name => $result->{acTrunkName}, + status => $result->{acTrunkStatusAlarm}, + state => $result->{acTrunkDeactivate} + }; } + + return $results; } sub run { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach my $instance (sort keys %{$self->{trunks}}) { - $self->{output}->output_add(long_msg => '[name = ' . $self->{trunks}->{$instance}->{name} . - "] [status = '" . $self->{trunks}->{$instance}->{status} . "'] [state = '" . - $self->{trunks}->{$instance}->{state} . "']" - ); + my $results = $self->manage_selection(%options); + foreach my $instance (sort keys %$results) { + $self->{output}->output_add( + long_msg => sprintf( + '[name: %s] [status: %s] [state: %s]', + $results->{$instance}->{name}, + $results->{$instance}->{status}, + $results->{$instance}->{state} + ) + ); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'List trunks:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List trunks:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -103,10 +116,9 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach my $instance (sort keys %{$self->{trunks}}) { - $self->{output}->add_disco_entry(name => $self->{trunks}->{$instance}->{name}, - status => $self->{trunks}->{$instance}->{status}, state => $self->{trunks}->{$instance}->{state}); + my $results = $self->manage_selection(%options); + foreach my $instance (sort keys %$results) { + $self->{output}->add_disco_entry(%{$results->{$instance}}); } } @@ -123,4 +135,3 @@ List trunks. =back =cut - diff --git a/src/network/audiocodes/snmp/mode/memory.pm b/src/network/audiocodes/snmp/mode/memory.pm index 107c15a8e..e1128c130 100644 --- a/src/network/audiocodes/snmp/mode/memory.pm +++ b/src/network/audiocodes/snmp/mode/memory.pm @@ -25,41 +25,54 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Memory '; +} + sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'global', type => 0, message_separator => ' - ' }, + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } } ]; + $self->{maps_counters}->{global} = [ - { label => 'voip', nlabel => 'memory.voip.utilization.percentage', set => { + { label => 'voip', nlabel => 'memory.voip.usage.percentage', set => { key_values => [ { name => 'voip' } ], - output_template => 'Memory VoIp Usage : %.2f %%', + output_template => 'VoIp usage: %.2f %%', perfdatas => [ - { label => 'used_voip', value => 'voip', template => '%.2f', min => 0, max => 100, unit => '%' }, - ], + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] } }, - { label => 'data', nlabel => 'memory.data.utilization.percentage', set => { + { label => 'data', nlabel => 'memory.data.usage.percentage', set => { key_values => [ { name => 'data' } ], - output_template => 'Memory Data Usage : %.2f %%', + output_template => 'data usage: %.2f %%', perfdatas => [ - { label => 'used_data', value => 'data', template => '%.2f', min => 0, max => 100, unit => '%' }, - ], + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] } }, + { label => 'system', nlabel => 'memory.system.usage.percentage', set => { + key_values => [ { name => 'system' } ], + output_template => 'system usage: %.2f %%', + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] + } + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => {}); + return $self; } @@ -68,11 +81,17 @@ sub manage_selection { my $oid_acSysStateVoIpMemoryUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.11.0'; my $oid_acSysStateDataMemoryUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.9.0'; - my $snmp_result = $options{snmp}->get_leef(oids => [ - $oid_acSysStateVoIpMemoryUtilization, $oid_acSysStateDataMemoryUtilization - ], nothing_quit => 1); - - $self->{global} = { data => $snmp_result->{$oid_acSysStateDataMemoryUtilization}, voip => $snmp_result->{$oid_acSysStateVoIpMemoryUtilization} }; + my $oid_acKpiSystemStatsCurrentGlobalMemoryUtilization = '.1.3.6.1.4.1.5003.15.2.2.1.1.1.0'; + my $snmp_result = $options{snmp}->get_leef( + oids => [$oid_acSysStateVoIpMemoryUtilization, $oid_acSysStateDataMemoryUtilization, $oid_acKpiSystemStatsCurrentGlobalMemoryUtilization], + nothing_quit => 1 + ); + + $self->{global} = { + data => $snmp_result->{$oid_acSysStateDataMemoryUtilization}, + voip => $snmp_result->{$oid_acSysStateVoIpMemoryUtilization}, + system => $snmp_result->{$oid_acKpiSystemStatsCurrentGlobalMemoryUtilization} + }; } 1; @@ -90,15 +109,10 @@ Check memory usages. Only display some counters (regexp can be used). Example: --filter-counters='^voip$' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Warning threshold. -Can be: 'voip', 'data'. - -=item B<--critical-*> - -Critical threshold. -Can be: 'voip', 'data'. +Thresholds. +Can be: 'voip', 'data', 'system'. =back diff --git a/src/network/audiocodes/snmp/mode/sbccalls.pm b/src/network/audiocodes/snmp/mode/sbccalls.pm new file mode 100644 index 000000000..e05d2f821 --- /dev/null +++ b/src/network/audiocodes/snmp/mode/sbccalls.pm @@ -0,0 +1,177 @@ +# +# 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 network::audiocodes::snmp::mode::sbccalls; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5; + +sub prefix_calls_output { + my ($self, %options) = @_; + + return 'number of calls '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'call', type => 0, cb_prefix_output => 'prefix_calls_output', skipped_code => { -10 => 1 } }, + { name => 'session', type => 0, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{call} = [ + { label => 'sbc-calls-duration-average', nlabel => 'sbc.calls.duration.average.seconds', set => { + key_values => [ { name => 'callsAvgDuration' } ], + output_template => 'average duration: %s s', + perfdatas => [ + { template => '%s', min => 0, unit => 's' } + ] + } + }, + { label => 'sbc-calls-active-inbound', nlabel => 'sbc.calls.active.inbound.count', set => { + key_values => [ { name => 'callsInActive' } ], + output_template => 'active inbound: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }, + { label => 'sbc-calls-active-outbound', nlabel => 'sbc.calls.active.outbound.count', set => { + key_values => [ { name => 'callsOutActive' } ], + output_template => 'active outbound: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }, + { label => 'sbc-calls-established-inbound', nlabel => 'sbc.calls.established.inbound.count', set => { + key_values => [ { name => 'callsInTotalEst', diff => 1 } ], + output_template => 'established inbound: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }, + { label => 'sbc-calls-established-outbound', nlabel => 'sbc.calls.established.outbound.count', set => { + key_values => [ { name => 'callsOutTotalEst', diff => 1 } ], + output_template => 'established outbound: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }, + { label => 'sbc-calls-notestablished-inbound-failed', nlabel => 'sbc.calls.notestablished.inbound.failed.count', set => { + key_values => [ { name => 'callsInFailedNotEst', diff => 1 } ], + output_template => 'not established inbound failed: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }, + { label => 'sbc-calls-notestablished-outbound', nlabel => 'sbc.calls.notestablished.outbound.failed.count', set => { + key_values => [ { name => 'callsOutFailedNotEst', diff => 1 } ], + output_template => 'not established outbound failed: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{session} = [ + { label => 'sbc-sessions-active', nlabel => 'sbc.sessions.active.count', set => { + key_values => [ { name => 'active' } ], + output_template => 'active sessions: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $mapping = { + callsAvgDuration => { oid => '.1.3.6.1.4.1.5003.15.3.1.1.1.1' }, # acKpiSbcCallStatsCurrentGlobalAverageCallDuration + callsInActive => { oid => '.1.3.6.1.4.1.5003.15.3.1.1.1.2' }, # acKpiSbcCallStatsCurrentGlobalActiveCallsIn + callsOutActive => { oid => '.1.3.6.1.4.1.5003.15.3.1.1.1.3' }, # acKpiSbcCallStatsCurrentGlobalActiveCallsOut + callsInTotalEst => { oid => '.1.3.6.1.4.1.5003.15.3.1.1.1.8' }, # acKpiSbcCallStatsCurrentGlobalEstablishedCallsInTotal + callsOutTotalEst => { oid => '.1.3.6.1.4.1.5003.15.3.1.1.1.9' }, # acKpiSbcCallStatsCurrentGlobalEstablishedCallsOutTotal + callsInFailedNotEst => { oid => '.1.3.6.1.4.1.5003.15.3.1.1.1.19' }, # acKpiSbcCallStatsCurrentGlobalNotEstablishFailedCallsInTotal + callsOutFailedNotEst => { oid => '.1.3.6.1.4.1.5003.15.3.1.1.1.20' }, # acKpiSbcCallStatsCurrentGlobalNotEstablishFailedCallsOutTotal + activeSessions => { oid => '.1.3.6.1.4.1.5003.15.3.1.1.1.43' } # acKpiSbcCallStatsCurrentGlobalActiveSessions + }; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); + $self->{call} = $result; + $self->{session} = { active => $result->{activeSessions} }; + + $self->{cache_name} = 'audiocodes_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + Digest::MD5::md5_hex( + defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '' + ); +} + +1; + +__END__ + +=head1 MODE + +Check SBC calls. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^calls' + +=item B<--warning-*> B<--critical-*> + +Threshold. +Can be: 'sbc-calls-duration-average', 'sbc-calls-active-inbound', 'sbc-calls-active-outbound', +'sbc-calls-established-inbound', 'sbc-calls-established-outbound', +'sbc-calls-notestablished-inbound-failed', 'sbc-calls-notestablished-outbound', 'sbc-sessions-active'. + +=back + +=cut diff --git a/src/network/audiocodes/snmp/mode/trunkstatus.pm b/src/network/audiocodes/snmp/mode/trunkstatus.pm index 8b4b27ea9..ff5459182 100644 --- a/src/network/audiocodes/snmp/mode/trunkstatus.pm +++ b/src/network/audiocodes/snmp/mode/trunkstatus.pm @@ -25,101 +25,78 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - - my $msg = 'alarm status : ' . $self->{result_values}->{alarm} . ' [state: ' . $self->{result_values}->{state} . ']'; - return $msg; + + return 'alarm status : ' . $self->{result_values}->{alarm} . ' [state: ' . $self->{result_values}->{state} . ']'; } -sub custom_status_calc { +sub prefix_trunk_output { my ($self, %options) = @_; - $self->{result_values}->{alarm} = $options{new_datas}->{$self->{instance} . '_alarm'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{dchannel} = $options{new_datas}->{$self->{instance} . '_dchannel'}; - $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; - return 0; + return "Trunk '" . $options{instance_value}->{display} . "' "; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'trunk', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All trunks are ok' } + { name => 'trunk', type => 1, cb_prefix_output => 'prefix_trunk_output', message_multiple => 'All trunks are ok' } ]; - + $self->{maps_counters}->{trunk} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{state} =~ /activated/ and %{alarm} !~ /greenActive/i', set => { key_values => [ { name => 'display' }, { name => 'dchannel' }, { name => 'alarm' }, { name => 'state' } ], - closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'avg-calls', set => { + { label => 'avg-calls', nlabel => 'trunk.calls.average.count', set => { key_values => [ { name => 'acPMTrunkUtilizationAverage' }, { name => 'display' } ], - output_template => 'Average calls : %s', + output_template => 'average calls: %s', perfdatas => [ - { label => 'avg_calls', value => 'acPMTrunkUtilizationAverage', template => '%d', - min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display' }, - ], + { template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }, + ] } }, - { label => 'max-calls', set => { + { label => 'max-calls', nlabel => 'trunk.calls.max.count', set => { key_values => [ { name => 'acPMTrunkUtilizationMax' }, { name => 'display' } ], - output_template => 'Max calls : %s', + output_template => 'max calls: %s', perfdatas => [ - { label => 'max_calls', value => 'acPMTrunkUtilizationMax', template => '%d', - min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display' }, - ], + { template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }, + ] } }, - { label => 'count-calls', set => { + { label => 'count-calls', nlabel => 'trunk.calls.total.count', set => { key_values => [ { name => 'acPMTrunkUtilizationTotal', diff => 1 }, { name => 'display' } ], - output_template => 'Count calls : %s', + output_template => 'count calls: %s', perfdatas => [ - { label => 'count_calls', value => 'acPMTrunkUtilizationTotal', template => '%d', - min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display' }, - ], + { label => 'count_calls', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } - }, + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{state} =~ /activated/ and %{alarm} !~ /greenActive/i' }, - }); - + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -sub prefix_vpn_output { - my ($self, %options) = @_; - - return "Trunk '" . $options{instance_value}->{display} . "' "; -} - -my %map_alarm = (0 => 'greyDisabled', 1 => 'greenActive', 2 => 'redLosLof', -3 => 'blueAis', 4 => 'yellowRai', 5 => 'orangeDChannel', 6 => 'purpleLowerLayerDown', 7 => 'darkOrangeNFASAlarm'); +my %map_alarm = ( + 0 => 'greyDisabled', 1 => 'greenActive', 2 => 'redLosLof', + 3 => 'blueAis', 4 => 'yellowRai', 5 => 'orangeDChannel', 6 => 'purpleLowerLayerDown', 7 => 'darkOrangeNFASAlarm' +); my %map_dchannel = (0 => 'dChannelEstablished', 1 => 'dChannelNotEstablished', 10 => 'dChannelNotApplicable'); my %map_deactivate = (0 => 'notAvailable', 1 => 'deActivated', 2 => 'activated'); @@ -128,12 +105,12 @@ my $mapping = { acTrunkStatusDChannel => { oid => '.1.3.6.1.4.1.5003.9.10.9.2.1.1.1.6', map => \%map_dchannel }, acTrunkStatusAlarm => { oid => '.1.3.6.1.4.1.5003.9.10.9.2.1.1.1.7', map => \%map_alarm }, acTrunkDeactivate => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.11', map => \%map_deactivate }, - acTrunkName => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.13' }, + acTrunkName => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.13' } }, usage => { acPMTrunkUtilizationAverage => { oid => '.1.3.6.1.4.1.5003.10.10.2.21.1.4' }, acPMTrunkUtilizationMax => { oid => '.1.3.6.1.4.1.5003.10.10.2.21.1.5' }, - acPMTrunkUtilizationTotal => { oid => '.1.3.6.1.4.1.5003.10.10.2.21.1.12' }, + acPMTrunkUtilizationTotal => { oid => '.1.3.6.1.4.1.5003.10.10.2.21.1.12' } } }; @@ -155,33 +132,32 @@ sub manage_selection { $datas->{$_} = { %{$datas->{$_}}, %{$snmp_result->{ $mapping->{$_}->{$name}->{oid} }} }; } } + foreach (keys %{$snmp_result->{ $mapping->{status}->{acTrunkStatusAlarm}->{oid} }}) { /\.(\d+)$/; my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping->{status}, results => $datas->{status}, instance => $instance); my $result2 = $options{snmp}->map_instance(mapping => $mapping->{usage}, results => $datas->{usage}, instance => $instance . '.0'); - + my $display = defined($result->{acTrunkName}) && $result->{acTrunkName} ne '' ? $result->{acTrunkName} : $instance; - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $display !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1); - next; - } - + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $display !~ /$self->{option_results}->{filter_name}/); + $self->{trunk}->{$instance} = { display => $display, alarm => $result->{acTrunkStatusAlarm}, state => $result->{acTrunkDeactivate}, dchannel => $result->{acTrunkStatusDChannel}, - %$result2 }; + %$result2 + }; } - + if (scalar(keys %{$self->{trunk}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No trunk found."); $self->{output}->option_exit(); } - - $self->{cache_name} = "audiocodes_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + + $self->{cache_name} = 'audiocodes_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); } @@ -207,20 +183,14 @@ You can use the following variables: %{display}, %{alarm}, %{dchannel}, %{state} =item B<--critical-status> -Define the conditions to match for the status to be CRITICAL (Default: '%{state} =~ /activated/ and %{alarm} !~ /greenActive/i'). +Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /activated/ and %{alarm} !~ /greenActive/i'). You can use the following variables: %{display}, %{alarm}, %{dchannel}, %{state} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Warning threshold. +Thresholds. Can be: 'avg-calls', 'max-calls', 'count-calls'. -=item B<--critical-*> - -Critical threshold. -Can be: 'avg-calls', 'max-calls', 'count-calls'. - - =back =cut diff --git a/src/network/audiocodes/snmp/plugin.pm b/src/network/audiocodes/snmp/plugin.pm index 0b254baf5..4be5e750c 100644 --- a/src/network/audiocodes/snmp/plugin.pm +++ b/src/network/audiocodes/snmp/plugin.pm @@ -29,15 +29,15 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::audiocodes::snmp::mode::cpu', - 'hardware' => 'network::audiocodes::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-trunks' => 'network::audiocodes::snmp::mode::listtrunks', - 'memory' => 'network::audiocodes::snmp::mode::memory', - 'trunk-status' => 'network::audiocodes::snmp::mode::trunkstatus', + 'cpu' => 'network::audiocodes::snmp::mode::cpu', + 'hardware' => 'network::audiocodes::snmp::mode::hardware', + 'interfaces' => 'network::audiocodes::snmp::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-trunks' => 'network::audiocodes::snmp::mode::listtrunks', + 'memory' => 'network::audiocodes::snmp::mode::memory', + 'sbc-calls' => 'network::audiocodes::snmp::mode::sbccalls', + 'trunk-status' => 'network::audiocodes::snmp::mode::trunkstatus', ); return $self; From c2701eceb1043c8c8af9a5f47807cd1b3c962bd9 Mon Sep 17 00:00:00 2001 From: omercier <32134301+omercier@users.noreply.github.com> Date: Mon, 7 Aug 2023 13:08:55 +0200 Subject: [PATCH 18/24] fix(pkg): missing include of uptime module (#4593) --- .../centreon-plugin-Hardware-Sensors-Rittal-Cmc3-Snmp/pkg.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/centreon-plugin-Hardware-Sensors-Rittal-Cmc3-Snmp/pkg.json b/packaging/centreon-plugin-Hardware-Sensors-Rittal-Cmc3-Snmp/pkg.json index d07fb0010..a165e3153 100644 --- a/packaging/centreon-plugin-Hardware-Sensors-Rittal-Cmc3-Snmp/pkg.json +++ b/packaging/centreon-plugin-Hardware-Sensors-Rittal-Cmc3-Snmp/pkg.json @@ -5,6 +5,7 @@ "files": [ "centreon/plugins/script_snmp.pm", "centreon/plugins/snmp.pm", + "snmp_standard/mode/uptime.pm", "hardware/sensors/rittal/cmc3/snmp/" ] } From 31fe71833eab3b79a3b52e1f9449a2e9a2adefbf Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 7 Aug 2023 15:46:02 +0200 Subject: [PATCH 19/24] =?UTF-8?q?(plugin)=20apps::monitoring::iplabel::new?= =?UTF-8?q?test::restapi=20-=20mode=20scenarios=E2=80=A6=20(#4545)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (plugin) apps::monitoring::iplabel::newtest::restapi - mode scenarios add --timeframe option * applications-monitoring-iplabel-newtest-restapi - mode scenarios add --timeframe option * review * Update src/apps/monitoring/iplabel/newtest/restapi/mode/scenarios.pm --------- Co-authored-by: omercier <32134301+omercier@users.noreply.github.com> --- .../iplabel/newtest/restapi/mode/scenarios.pm | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/apps/monitoring/iplabel/newtest/restapi/mode/scenarios.pm b/src/apps/monitoring/iplabel/newtest/restapi/mode/scenarios.pm index e47e76b7f..69acc8249 100644 --- a/src/apps/monitoring/iplabel/newtest/restapi/mode/scenarios.pm +++ b/src/apps/monitoring/iplabel/newtest/restapi/mode/scenarios.pm @@ -25,7 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); -use POSIX; use DateTime; sub robot_long_output { @@ -115,7 +114,8 @@ sub new { $options{options}->add_options(arguments => { 'filter-robot-name:s' => { name => 'filter_robot_name' }, - 'filter-scenario-name:s' => { name => 'filter_scenario_name' } + 'filter-scenario-name:s' => { name => 'filter_scenario_name' }, + 'timeframe:s' => { name => 'timeframe' } }); return $self; @@ -129,11 +129,17 @@ sub manage_selection { (defined($self->{option_results}->{filter_robot_name}) ? md5_hex($self->{option_results}->{filter_robot_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_scenario_name}) ? md5_hex($self->{option_results}->{filter_scenario_name}) : md5_hex('all')); my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); - my $timespan = 5; - if (defined($last_timestamp)) { - $timespan = POSIX::ceil((time() - $last_timestamp) / 60); + + my $timespan = 300; + if (defined($self->{option_results}->{timeframe}) && $self->{option_results}->{timeframe} =~ /^(\d+)$/) { + $timespan = $1; + $last_timestamp = time() - $timespan; } else { - $last_timestamp = time() - (60 * 5); + if (defined($last_timestamp)) { + $timespan = time() - $last_timestamp; + } else { + $last_timestamp = time() - $timespan; + } } my $instances = $options{custom}->request_api(endpoint => '/api/instances'); @@ -299,6 +305,11 @@ Filter robots (can be a regexp). Filter scenarios (can be a regexp). +=item B<--timeframe> + +Define timeframe (duration to go back in time) in seconds (default value: 300 ). +The first range is calculated with this value then it's calculated from the last execution (stored in the cache file). + =item B<--warning-*> B<--critical-*> Thresholds. From c21dd75d02d48e5586c4896d822319392a7b57bb Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 7 Aug 2023 16:55:27 +0200 Subject: [PATCH 20/24] (plugin) hardware::ups::apc::snmp - metric v2 + option --replace-lasttime-format (#4551) --- .../deb.json | 5 +- .../pkg.json | 6 +- .../rpm.json | 5 +- .../ups/apc/snmp/mode/batterystatus.pm | 36 ++- src/hardware/ups/apc/snmp/mode/inputlines.pm | 217 +++++++++++++++--- src/hardware/ups/apc/snmp/mode/ntp.pm | 8 + src/hardware/ups/apc/snmp/mode/outputlines.pm | 65 +++--- src/hardware/ups/apc/snmp/mode/sensors.pm | 17 +- src/hardware/ups/apc/snmp/mode/uptime.pm | 77 +++++++ src/hardware/ups/apc/snmp/plugin.pm | 3 +- 10 files changed, 354 insertions(+), 85 deletions(-) create mode 100644 src/hardware/ups/apc/snmp/mode/uptime.pm diff --git a/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/deb.json b/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/deb.json index 663aaaceb..3eb4dc696 100644 --- a/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/deb.json +++ b/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/deb.json @@ -1,5 +1,6 @@ { "dependencies": [ - "libsnmp-perl" + "libsnmp-perl", + "libdatetime-format-strptime-perl" ] -} \ No newline at end of file +} diff --git a/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/pkg.json b/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/pkg.json index 9d61f4367..9a58a5c91 100644 --- a/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/pkg.json +++ b/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/pkg.json @@ -5,6 +5,8 @@ "files": [ "centreon/plugins/script_snmp.pm", "centreon/plugins/snmp.pm", - "hardware/ups/apc/snmp/" + "snmp_standard/mode/ntp.pm", + "snmp_standard/mode/uptime.pm", + "hardware/ups/apc/snmp/" ] -} \ No newline at end of file +} diff --git a/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/rpm.json b/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/rpm.json index 418a331fc..84e108169 100644 --- a/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/rpm.json +++ b/packaging/centreon-plugin-Hardware-Ups-Apc-Snmp/rpm.json @@ -1,5 +1,6 @@ { "dependencies": [ - "perl(SNMP)" + "perl(SNMP)", + "perl(DateTime::Format::Strptime)" ] -} \ No newline at end of file +} diff --git a/src/hardware/ups/apc/snmp/mode/batterystatus.pm b/src/hardware/ups/apc/snmp/mode/batterystatus.pm index 56a808d89..8008e8874 100644 --- a/src/hardware/ups/apc/snmp/mode/batterystatus.pm +++ b/src/hardware/ups/apc/snmp/mode/batterystatus.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use DateTime::Format::Strptime; use DateTime; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); @@ -187,15 +188,31 @@ sub set_counters { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { + 'replace-lasttime-format:s' => { name => 'replace_lasttime_format' } }); return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + my $pattern = '%m/%d/%Y'; + if (defined($self->{option_results}->{replace_lasttime_format}) && $self->{option_results}->{replace_lasttime_format} ne '') { + $pattern = $self->{option_results}->{replace_lasttime_format}; + } + + $self->{strp} = DateTime::Format::Strptime->new( + pattern => $pattern, + on_error => 'undef' + ); +} + my $map_battery_status = { 1 => 'unknown', 2 => 'batteryNormal', 3 => 'batteryLow' }; @@ -313,10 +330,17 @@ sub manage_selection { if (defined($result->{upsBasicBatteryTimeOnBattery})); $result2->{upsAdvBatteryRunTimeRemaining} = sprintf("%.0f", $result2->{upsAdvBatteryRunTimeRemaining} / 100 / 60) if (defined($result2->{upsAdvBatteryRunTimeRemaining})); + $result2->{upsAdvBatteryReplaceIndicator} = 'n/a' + if (!defined($result2->{upsAdvBatteryReplaceIndicator})); $self->{global} = { %$result, %$result2 }; - if (defined($result->{upsBasicBatteryLastReplaceDate}) && $result->{upsBasicBatteryLastReplaceDate} =~ /(\d{2})\/(\d{2})\/(\d{4})/) { - my $dt = DateTime->new(year => $3, month => $1, day => $2, hour => 0, minute => 0, second => 0); - $self->{global}->{last_replace_time} = time() - $dt->epoch; + + if (defined($result->{upsBasicBatteryLastReplaceDate}) && $result->{upsBasicBatteryLastReplaceDate} ne '') { + my $dt = $self->{strp}->parse_datetime($result->{upsBasicBatteryLastReplaceDate}); + if (defined($dt)) { + $self->{global}->{last_replace_time} = time() - $dt->epoch(); + } else { + $self->{output}->output_add(long_msg => "cannot parse date: " . $result->{upsBasicBatteryLastReplaceDate} . ' (please use option --replace-lasttime-format)'); + } } $self->add_battery_pack(snmp_result => $snmp_result); @@ -338,6 +362,10 @@ Check battery status and battery charge remaining. Only display some counters (regexp can be used). Example: --filter-counters='^status|load$' +=item B<--replace-lasttime-format> + +Define the date format (default: '%m/%d/%Y'). + =item B<--unknown-status> Define the conditions to match for the status to be UNKNOWN (Default: '%{status} =~ /unknown/i'). diff --git a/src/hardware/ups/apc/snmp/mode/inputlines.pm b/src/hardware/ups/apc/snmp/mode/inputlines.pm index 2e5da3a17..e02429391 100644 --- a/src/hardware/ups/apc/snmp/mode/inputlines.pm +++ b/src/hardware/ups/apc/snmp/mode/inputlines.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -32,68 +32,172 @@ sub custom_status_output { return sprintf("last input line fail cause is '%s'", $self->{result_values}->{last_cause}); } +sub input_long_output { + my ($self, %options) = @_; + + return sprintf( + "checking input line '%s' [type: %s]", + $options{instance_value}->{inputNum}, + $options{instance_value}->{inputType} + ); +} + +sub input_bpack_output { + my ($self, %options) = @_; + + return sprintf( + "input line '%s' [type: %s] ", + $options{instance_value}->{inputNum}, + $options{instance_value}->{inputType} + ); +} + +sub prefix_phase_output { + my ($self, %options) = @_; + + return "phase '" . $options{instance_value}->{phaseNum} . "' "; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0 }, + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'inputs', type => 3, cb_prefix_output => 'prefix_input_output', cb_long_output => 'input_long_output', indent_long_output => ' ', message_multiple => 'All inputs are ok', + group => [ + { name => 'input_global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'phases', display_long => 1, cb_prefix_output => 'prefix_phase_output', message_multiple => 'phases are ok', type => 1, skipped_code => { -10 => 1 } } + ] + } ]; $self->{maps_counters}->{global} = [ - { label => 'voltage', set => { + { label => 'voltage', nlabel => 'lines.input.voltage.volt', set => { key_values => [ { name => 'voltage' } ], output_template => 'voltage: %s V', perfdatas => [ - { label => 'voltage', value => 'voltage', template => '%s', - unit => 'V' }, - ], + { template => '%s', unit => 'V' } + ] } }, - { label => 'frequence', set => { + { label => 'frequence', nlabel => 'lines.input.frequence.hertz', set => { key_values => [ { name => 'frequency' } ], output_template => 'frequence: %s Hz', perfdatas => [ - { label => 'frequence', value => 'frequency', template => '%s', - unit => 'Hz' }, - ], + { template => '%s', unit => 'Hz' } + ] } }, - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, set => { key_values => [ { name => 'last_cause' } ], closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; + + $self->{maps_counters}->{input_global} = [ + { label => 'line-frequence', nlabel => 'line.input.frequence.hertz', set => { + key_values => [ { name => 'frequency' }, { name => 'inputNum' }, { name => 'inputType' } ], + output_template => 'frequence: %s Hz', + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'Hz', + instances => [$self->{result_values}->{inputType} . '.' . $self->{result_values}->{inputNum}], + value => sprintf('%s', $self->{result_values}->{frequency}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) + ); + } + } + } + ]; + + $self->{maps_counters}->{phases} = [ + { label => 'line-phase-voltage', nlabel => 'line.input.voltage.volt', set => { + key_values => [ + { name => 'voltage' }, { name => 'inputNum' }, + { name => 'inputType' }, { name => 'phaseNum' } + ], + output_template => 'voltage: %s V', + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'V', + instances => [$self->{result_values}->{inputType} . '.' . $self->{result_values}->{inputNum}, $self->{result_values}->{phaseNum}], + value => sprintf('%s', $self->{result_values}->{voltage}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) + ); + } } }, + { label => 'line-phase-current', nlabel => 'line.input.current.ampere', set => { + key_values => [ + { name => 'current' }, { name => 'inputNum' }, + { name => 'inputType' }, { name => 'phaseNum' } + ], + output_template => 'current: %s A', + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'A', + instances => [$self->{result_values}->{inputType} . '.' . $self->{result_values}->{inputNum}, $self->{result_values}->{phaseNum}], + value => sprintf('%s', $self->{result_values}->{current}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) + ); + } + } + }, + { label => 'line-phase-power', nlabel => 'line.input.power.watt', set => { + key_values => [ + { name => 'power' }, { name => 'inputNum' }, + { name => 'inputType' }, { name => 'phaseNum' } + ], + output_template => 'power: %.2f W', + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'W', + instances => [$self->{result_values}->{inputType} . '.' . $self->{result_values}->{inputNum}, $self->{result_values}->{phaseNum}], + value => sprintf('%.2f', $self->{result_values}->{power}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) + ); + } + } + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => { - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, - }); + $options{options}->add_options(arguments => {}); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - my $map_status = { 1 => 'noTransfer', 2 => 'highLineVoltage', 3 => 'brownout', 4 => 'blackout', 5 => 'smallMomentarySag', 6 => 'deepMomentarySag', 7 => 'smallMomentarySpike', 8 => 'largeMomentarySpike', 9 => 'selfTest', 10 => 'rateOfVoltageChange', }; +my $map_input_type = { 1 => 'unknown', 2 => 'main', 3 => 'bypass' }; my $mapping = { upsAdvInputLineVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.3.2.1' }, @@ -102,7 +206,16 @@ my $mapping = { upsAdvConfigHighTransferVolt => { oid => '.1.3.6.1.4.1.318.1.1.1.5.2.2' }, upsAdvConfigLowTransferVolt => { oid => '.1.3.6.1.4.1.318.1.1.1.5.2.3' }, upsHighPrecInputLineVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.3.3.1' }, - upsHighPrecInputFrequency => { oid => '.1.3.6.1.4.1.318.1.1.1.3.3.4' }, + upsHighPrecInputFrequency => { oid => '.1.3.6.1.4.1.318.1.1.1.3.3.4' } +}; +my $mapping_input = { + frequency => { oid => '.1.3.6.1.4.1.318.1.1.1.9.2.2.1.4' }, # upsPhaseInputFrequency + type => { oid => '.1.3.6.1.4.1.318.1.1.1.9.2.2.1.5', map => $map_input_type } # upsPhaseInputType +}; +my $mapping_input_phase = { + voltage => { oid => '.1.3.6.1.4.1.318.1.1.1.9.2.3.1.3' }, # upsPhaseInputVoltage + current => { oid => '.1.3.6.1.4.1.318.1.1.1.9.2.3.1.6' }, # upsPhaseInputCurrent + power => { oid => '.1.3.6.1.4.1.318.1.1.1.9.2.3.1.9' } # upsPhaseInputPower }; sub manage_selection { @@ -130,6 +243,53 @@ sub manage_selection { frequency => defined($result->{upsHighPrecInputFrequency}) && $result->{upsHighPrecInputFrequency} =~ /\d/ ? $result->{upsHighPrecInputFrequency} * 0.1 : $result->{upsAdvInputFrequency}, }; + + my $oid_inputTable = '.1.3.6.1.4.1.318.1.1.1.9.2.2.1'; + $snmp_result = $options{snmp}->get_table( + oid => $oid_inputTable, + start => $mapping_input->{frequency}->{oid}, + end => $mapping_input->{type}->{oid} + ); + + $self->{inputs} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping_input->{type}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping_input, results => $snmp_result, instance => $instance); + $self->{inputs}->{$instance} = { + inputNum => $instance, + inputType => $result->{type}, + input_global => { + inputNum => $instance, + inputType => $result->{type}, + frequency => defined($result->{frequency}) && $result->{frequency} != -1 ? $result->{frequency} * 0.1 : undef + }, + phases => {} + }; + } + + my $oid_inputPhaseTable = '.1.3.6.1.4.1.318.1.1.1.9.2.3.1'; + $snmp_result = $options{snmp}->get_table( + oid => $oid_inputPhaseTable, + start => $mapping_input_phase->{voltage}->{oid}, + end => $mapping_input_phase->{power}->{oid} + ); + + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping_input_phase->{voltage}->{oid}\.(\d+)\.(\d+)$/); + my ($input_num, $phase_num) = ($1, $2); + + my $result = $options{snmp}->map_instance(mapping => $mapping_input_phase, results => $snmp_result, instance => $input_num . '.' . $phase_num); + $self->{inputs}->{$input_num}->{phases}->{$phase_num} = { + inputNum => $input_num, + inputType => $self->{inputs}->{$input_num}->{inputType}, + phaseNum => $phase_num, + voltage => defined($result->{voltage}) && $result->{voltage} != -1 ? $result->{voltage} : undef, + current => defined($result->{current}) && $result->{current} != -1 ? $result->{current} * 0.1 : undef, + power => defined($result->{power}) && $result->{power} != -1 ? $result->{power} : undef + }; + } } 1; @@ -149,18 +309,19 @@ Example: --filter-counters='^frequence|voltage$' =item B<--warning-status> -Define the conditions to match for the status to be WARNING (Default: ''). +Define the conditions to match for the status to be WARNING. You can use the following variables: %{last_cause} =item B<--critical-status> -Define the conditions to match for the status to be CRITICAL (Default: ''). +Define the conditions to match for the status to be CRITICAL. You can use the following variables: %{last_cause} =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'voltage', 'frequence'. +Can be: 'voltage', 'frequence', 'line-frequence', +'line-phase-voltage', 'line-phase-current', 'line-phase-power'. =back diff --git a/src/hardware/ups/apc/snmp/mode/ntp.pm b/src/hardware/ups/apc/snmp/mode/ntp.pm index 709722e94..d9bf3ce6e 100644 --- a/src/hardware/ups/apc/snmp/mode/ntp.pm +++ b/src/hardware/ups/apc/snmp/mode/ntp.pm @@ -26,6 +26,14 @@ use strict; use warnings; use Date::Parse; +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + sub get_target_time { my ($self, %options) = @_; diff --git a/src/hardware/ups/apc/snmp/mode/outputlines.pm b/src/hardware/ups/apc/snmp/mode/outputlines.pm index 0836f906c..02e5c9572 100644 --- a/src/hardware/ups/apc/snmp/mode/outputlines.pm +++ b/src/hardware/ups/apc/snmp/mode/outputlines.pm @@ -24,66 +24,66 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - + return sprintf("output status is '%s'", $self->{result_values}->{status}); } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'global', type => 0, skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', + type => 2, + unknown_default => '%{status} =~ /unknown/i', + critical_default => '%{status} !~ /onLine|rebooting/i', + set => { key_values => [ { name => 'status' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'load', set => { + { label => 'load', nlabel => 'lines.output.load.percentage', set => { key_values => [ { name => 'load' } ], output_template => 'load: %s %%', perfdatas => [ - { label => 'load', value => 'load', template => '%s', - min => 0, max => 100, unit => '%' }, - ], + { template => '%s', min => 0, max => 100, unit => '%' } + ] } }, - { label => 'current', set => { + { label => 'current', nlabel => 'lines.output.current.ampere', set => { key_values => [ { name => 'current' } ], output_template => 'current: %s A', perfdatas => [ - { label => 'current', value => 'current', template => '%s', - min => 0, unit => 'A' }, - ], + { template => '%s', min => 0, unit => 'A' } + ] } }, - { label => 'voltage', set => { + { label => 'voltage', nlabel => 'lines.output.voltage.volt', set => { key_values => [ { name => 'voltage' } ], output_template => 'voltage: %s V', perfdatas => [ - { label => 'voltage', value => 'voltage', template => '%s', - unit => 'V' }, - ], + { template => '%s', unit => 'V' } + ] } }, - { label => 'frequence', set => { + { label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => { key_values => [ { name => 'frequency' } ], output_template => 'frequence: %s Hz', perfdatas => [ - { label => 'frequence', value => 'frequency', template => '%s', - unit => 'Hz' }, - ], + { template => '%s', unit => 'Hz' } + ] } - }, + } ]; } @@ -92,27 +92,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => { - 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /onLine|rebooting/i' }, - }); + $options{options}->add_options(arguments => {}); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); -} - my $map_status = { 1 => 'unknown', 2 => 'onLine', 3 => 'onBattery', 4 => 'onSmartBoost', 5 => 'timedSleeping', 6 => 'softwareBypass', 7 => 'off', 8 => 'rebooting', 9 => 'switchedBypass', 10 => 'hardwareFailureBypass', - 11 => 'sleepingUntilPowerReturn', 12 => 'onSmartTrim', + 11 => 'sleepingUntilPowerReturn', 12 => 'onSmartTrim' }; my $mapping = { @@ -124,7 +113,7 @@ my $mapping = { upsHighPrecOutputVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.1' }, # tenths of VAC upsHighPrecOutputFrequency => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.2' }, # tenths of Hz upsHighPrecOutputLoad => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.3' }, # tenths of percent - upsHighPrecOutputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.4' }, # tenths of amperes + upsHighPrecOutputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.4' } # tenths of amperes }; sub manage_selection { diff --git a/src/hardware/ups/apc/snmp/mode/sensors.pm b/src/hardware/ups/apc/snmp/mode/sensors.pm index ac28efd7d..267f8e80c 100644 --- a/src/hardware/ups/apc/snmp/mode/sensors.pm +++ b/src/hardware/ups/apc/snmp/mode/sensors.pm @@ -119,14 +119,14 @@ my $mapping = { uioSensorStatusSensorName => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.3' }, uioSensorStatusTemperatureDegC => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.6' }, uioSensorStatusHumidity => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.7' }, - uioSensorStatusAlarmStatus => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.9', map => $map_alarm_status }, + uioSensorStatusAlarmStatus => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.9', map => $map_alarm_status } }; my $mapping_iem = { iemStatusProbeName => { oid => '.1.3.6.1.4.1.318.1.1.10.2.3.2.1.2' }, iemStatusProbeStatus => { oid => '.1.3.6.1.4.1.318.1.1.10.2.3.2.1.3', map => $map_iem_status }, iemStatusProbeCurrentTemp => { oid => '.1.3.6.1.4.1.318.1.1.10.2.3.2.1.4' }, iemStatusProbeTempUnits => { oid => '.1.3.6.1.4.1.318.1.1.10.2.3.2.1.5', map => $map_iem_unit }, - iemStatusProbeCurrentHumid => { oid => '.1.3.6.1.4.1.318.1.1.10.2.3.2.1.6' }, + iemStatusProbeCurrentHumid => { oid => '.1.3.6.1.4.1.318.1.1.10.2.3.2.1.6' } }; my $oid_uioSensorStatusEntry = '.1.3.6.1.4.1.318.1.1.25.1.2.1'; my $oid_iemStatusProbesEntry = '.1.3.6.1.4.1.318.1.1.10.2.3.2.1'; @@ -179,9 +179,10 @@ sub check_uoi { ) ); } + $self->{output}->perfdata_add( - label => 'universal_temp', unit => 'C', - nlabel => 'sensor.universal.temperature.celsius', + nlabel => 'sensor.universal.temperature.celsius', + unit => 'C', instances => $result->{uioSensorStatusSensorName}, value => $result->{uioSensorStatusTemperatureDegC}, warning => $warn, @@ -202,9 +203,10 @@ sub check_uoi { ) ); } + $self->{output}->perfdata_add( - label => 'universal_humidity', unit => '%', nlabel => 'sensor.universal.humidity.percentage', + unit => '%', instances => $result->{uioSensorStatusSensorName}, value => $result->{uioSensorStatusHumidity}, warning => $warn, @@ -259,8 +261,8 @@ sub check_iem { ) ); } + $self->{output}->perfdata_add( - label => 'integrated_temp', unit => $result->{iemStatusProbeTempUnits} eq 'celsius' ? 'C' : 'F', nlabel => 'sensor.integrated.temperature.' . $result->{iemStatusProbeTempUnits}, instances => $result->{iemStatusProbeName}, @@ -283,9 +285,10 @@ sub check_iem { ) ); } + $self->{output}->perfdata_add( - label => 'integrated_humidity', unit => '%', nlabel => 'sensor.integrated.humidity.percentage', + unit => '%', instances => $result->{iemStatusProbeName}, value => $result->{iemStatusProbeCurrentHumid}, warning => $warn, diff --git a/src/hardware/ups/apc/snmp/mode/uptime.pm b/src/hardware/ups/apc/snmp/mode/uptime.pm new file mode 100644 index 000000000..c8a8d4d58 --- /dev/null +++ b/src/hardware/ups/apc/snmp/mode/uptime.pm @@ -0,0 +1,77 @@ +# +# 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 hardware::ups::apc::snmp::mode::uptime; + +use base qw(snmp_standard::mode::uptime); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check system uptime. + +=over 8 + +=item B<--warning-uptime> + +Warning threshold. + +=item B<--critical-uptime> + +Critical threshold. + +=item B<--add-sysdesc> + +Display system description. + +=item B<--force-oid> + +Can choose your oid (numeric format only). + +=item B<--check-overload> + +Uptime counter limit is 4294967296 and overflow. +With that option, we manage the counter going back. But there is a few chance we can miss a reboot. + +=item B<--reboot-window> + +To be used with check-overload option. Time in milliseconds (Default: 5000) +You increase the chance of not missing a reboot if you decrease that value. + +=item B<--unit> + +Select the unit for performance data and thresholds. May be 's' for seconds, 'm' for minutes, +'h' for hours, 'd' for days, 'w' for weeks. Default is seconds + +=back diff --git a/src/hardware/ups/apc/snmp/plugin.pm b/src/hardware/ups/apc/snmp/plugin.pm index 1a2ec907a..f4057801d 100644 --- a/src/hardware/ups/apc/snmp/plugin.pm +++ b/src/hardware/ups/apc/snmp/plugin.pm @@ -27,14 +27,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $self->{modes} = { 'battery-status' => 'hardware::ups::apc::snmp::mode::batterystatus', 'input-lines' => 'hardware::ups::apc::snmp::mode::inputlines', 'output-lines' => 'hardware::ups::apc::snmp::mode::outputlines', 'sensors' => 'hardware::ups::apc::snmp::mode::sensors', 'time' => 'hardware::ups::apc::snmp::mode::ntp', - 'uptime' => 'snmp_standard::mode::uptime' + 'uptime' => 'hardware::ups::apc::snmp::mode::uptime' }; return $self; From ceb2f5df46689d217f636fc8bad7c9e32628e3a8 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 7 Aug 2023 19:39:26 +0200 Subject: [PATCH 21/24] mode interfaces,/storage/inodes/diskusage - security fix (#4578) --- src/apps/vmware/vcsa/snmp/mode/interfaces.pm | 8 +- .../vmware/vcsa/snmp/mode/listinterfaces.pm | 8 +- src/apps/vmware/vcsa/snmp/mode/storage.pm | 8 +- .../common/bluearc/snmp/mode/interfaces.pm | 8 +- .../bluearc/snmp/mode/listinterfaces.pm | 8 +- .../cisco/standard/snmp/mode/interfaces.pm | 8 +- .../fortigate/snmp/mode/interfaces.pm | 8 +- .../common/h3c/snmp/mode/interfaces.pm | 8 +- .../adva/fsp3000/snmp/mode/interfaces.pm | 8 +- .../adva/fsp3000/snmp/mode/listinterfaces.pm | 8 +- .../aruba/cppm/snmp/mode/interfaces.pm | 8 +- src/network/atrica/snmp/mode/connections.pm | 8 +- .../atrica/snmp/mode/listconnections.pm | 11 +-- src/network/brocade/snmp/mode/interfaces.pm | 8 +- .../brocade/snmp/mode/listinterfaces.pm | 8 +- .../cambium/cnpilot/snmp/mode/interfaces.pm | 8 +- .../cambium/epmp/snmp/mode/interfaces.pm | 8 +- .../dell/nseries/snmp/mode/interfaces.pm | 8 +- .../dlink/standard/snmp/mode/interfaces.pm | 8 +- src/network/enterasys/snmp/mode/interfaces.pm | 8 +- src/network/extreme/snmp/mode/interfaces.pm | 8 +- .../fortinet/fortiadc/snmp/mode/interfaces.pm | 8 +- .../fortimail/snmp/mode/interfaces.pm | 8 +- .../fortiswitch/snmp/mode/interfaces.pm | 8 +- .../hp/moonshot/snmp/mode/interfaces.pm | 8 +- .../hp/procurve/snmp/mode/interfaces.pm | 8 +- src/network/huawei/snmp/mode/interfaces.pm | 8 +- .../juniper/common/junos/mode/interfaces.pm | 8 +- .../lenovo/rackswitch/snmp/mode/interfaces.pm | 8 +- src/network/libraesva/snmp/mode/interfaces.pm | 8 +- src/network/libraesva/snmp/mode/storage.pm | 8 +- .../microsens/g6/snmp/mode/interfaces.pm | 8 +- src/network/mikrotik/snmp/mode/interfaces.pm | 8 +- .../mrv/optiswitch/snmp/mode/interfaces.pm | 8 +- .../optiswitch/snmp/mode/listinterfaces.pm | 8 +- .../netgear/sseries/snmp/mode/interfaces.pm | 8 +- .../nortel/standard/snmp/mode/interfaces.pm | 8 +- src/network/oneaccess/snmp/mode/interfaces.pm | 8 +- src/network/opengear/snmp/mode/interfaces.pm | 8 +- src/network/raisecom/snmp/mode/interfaces.pm | 8 +- src/network/securactive/mode/bcn.pm | 78 +++++++++++-------- src/network/securactive/mode/listbcn.pm | 30 ++++--- src/network/sonus/sbc/snmp/mode/interfaces.pm | 8 +- src/network/sonus/sbc/snmp/mode/storage.pm | 8 +- src/network/viptela/snmp/mode/interfaces.pm | 8 +- src/os/picos/snmp/mode/interfaces.pm | 8 +- src/os/picos/snmp/mode/listinterfaces.pm | 8 +- src/os/windows/wsman/mode/liststorages.pm | 25 +++--- src/snmp_standard/mode/diskusage.pm | 22 ++++-- src/snmp_standard/mode/inodes.pm | 43 ++++++---- src/snmp_standard/mode/interfaces.pm | 22 ++++-- src/snmp_standard/mode/listdiskspath.pm | 35 ++++++--- src/snmp_standard/mode/listinterfaces.pm | 24 ++++-- src/snmp_standard/mode/liststorages.pm | 39 ++++++---- src/snmp_standard/mode/storage.pm | 23 ++++-- .../lenovo/iomega/snmp/mode/interfaces.pm | 8 +- 56 files changed, 354 insertions(+), 358 deletions(-) diff --git a/src/apps/vmware/vcsa/snmp/mode/interfaces.pm b/src/apps/vmware/vcsa/snmp/mode/interfaces.pm index 63832be13..fb19910ef 100644 --- a/src/apps/vmware/vcsa/snmp/mode/interfaces.pm +++ b/src/apps/vmware/vcsa/snmp/mode/interfaces.pm @@ -169,13 +169,11 @@ Define the OID that will be used to name the interfaces (default: ifDesc) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/apps/vmware/vcsa/snmp/mode/listinterfaces.pm b/src/apps/vmware/vcsa/snmp/mode/listinterfaces.pm index 67f31f66f..10f70659d 100644 --- a/src/apps/vmware/vcsa/snmp/mode/listinterfaces.pm +++ b/src/apps/vmware/vcsa/snmp/mode/listinterfaces.pm @@ -85,13 +85,11 @@ Define the OID to be used to filter interfaces (default: ifDesc) (values: ifDesc Define the OID that will be used to name the interfaces (default: ifDesc) (values: ifDesc, ifAlias, ifName). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--add-extra-oid> diff --git a/src/apps/vmware/vcsa/snmp/mode/storage.pm b/src/apps/vmware/vcsa/snmp/mode/storage.pm index 6ef2ccb3c..5451c92c9 100644 --- a/src/apps/vmware/vcsa/snmp/mode/storage.pm +++ b/src/apps/vmware/vcsa/snmp/mode/storage.pm @@ -102,13 +102,11 @@ Choose OID used to filter storage (default: hrStorageDescr) (values: hrStorageDe Choose OID used to display storage (default: hrStorageDescr) (values: hrStorageDescr, hrFSMountPoint). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the storage name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =item B<--show-cache> diff --git a/src/centreon/common/bluearc/snmp/mode/interfaces.pm b/src/centreon/common/bluearc/snmp/mode/interfaces.pm index 9a7822ace..fa94eb9f9 100644 --- a/src/centreon/common/bluearc/snmp/mode/interfaces.pm +++ b/src/centreon/common/bluearc/snmp/mode/interfaces.pm @@ -177,13 +177,11 @@ Define the OID that will be used to name the interfaces (default: ifDesc) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/centreon/common/bluearc/snmp/mode/listinterfaces.pm b/src/centreon/common/bluearc/snmp/mode/listinterfaces.pm index 32b9df694..bd0e9e2d0 100644 --- a/src/centreon/common/bluearc/snmp/mode/listinterfaces.pm +++ b/src/centreon/common/bluearc/snmp/mode/listinterfaces.pm @@ -85,13 +85,11 @@ Define the OID to be used to filter interfaces (default: ifDesc) (values: ifDesc Define the OID that will be used to name the interfaces (default: ifDesc) (values: ifDesc, ifAlias, ifName). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--add-extra-oid> diff --git a/src/centreon/common/cisco/standard/snmp/mode/interfaces.pm b/src/centreon/common/cisco/standard/snmp/mode/interfaces.pm index 101c11dad..a02d54a0a 100644 --- a/src/centreon/common/cisco/standard/snmp/mode/interfaces.pm +++ b/src/centreon/common/cisco/standard/snmp/mode/interfaces.pm @@ -448,13 +448,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm b/src/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm index df62ccd96..1734ef737 100644 --- a/src/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm +++ b/src/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm @@ -176,13 +176,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/centreon/common/h3c/snmp/mode/interfaces.pm b/src/centreon/common/h3c/snmp/mode/interfaces.pm index 5fa18ce3a..0200b9a00 100644 --- a/src/centreon/common/h3c/snmp/mode/interfaces.pm +++ b/src/centreon/common/h3c/snmp/mode/interfaces.pm @@ -299,13 +299,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/adva/fsp3000/snmp/mode/interfaces.pm b/src/network/adva/fsp3000/snmp/mode/interfaces.pm index 9fd2c7d18..675f11238 100644 --- a/src/network/adva/fsp3000/snmp/mode/interfaces.pm +++ b/src/network/adva/fsp3000/snmp/mode/interfaces.pm @@ -375,13 +375,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/adva/fsp3000/snmp/mode/listinterfaces.pm b/src/network/adva/fsp3000/snmp/mode/listinterfaces.pm index 43adb562c..6482a896c 100644 --- a/src/network/adva/fsp3000/snmp/mode/listinterfaces.pm +++ b/src/network/adva/fsp3000/snmp/mode/listinterfaces.pm @@ -141,13 +141,11 @@ Define the OID to be used to filter interfaces (default: ifDesc) (values: ifDesc Define the OID that will be used to name the interfaces (default: ifDesc) (values: ifDesc, ifAlias). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--add-extra-oid> diff --git a/src/network/aruba/cppm/snmp/mode/interfaces.pm b/src/network/aruba/cppm/snmp/mode/interfaces.pm index cb2f39952..f334dc0c0 100644 --- a/src/network/aruba/cppm/snmp/mode/interfaces.pm +++ b/src/network/aruba/cppm/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/atrica/snmp/mode/connections.pm b/src/network/atrica/snmp/mode/connections.pm index 500ed774d..e4aecf953 100644 --- a/src/network/atrica/snmp/mode/connections.pm +++ b/src/network/atrica/snmp/mode/connections.pm @@ -469,13 +469,11 @@ Define the OID that will be used to name the interfaces (default: atrConnCepGenD Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/atrica/snmp/mode/listconnections.pm b/src/network/atrica/snmp/mode/listconnections.pm index 853bc43eb..60f348c5c 100644 --- a/src/network/atrica/snmp/mode/listconnections.pm +++ b/src/network/atrica/snmp/mode/listconnections.pm @@ -85,8 +85,7 @@ sub default_oid_display_name { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, - no_speed => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_speed => 1); bless $self, $class; return $self; } @@ -131,13 +130,11 @@ Define the OID to be used to filter interfaces (default: atrConnCepGenDescr) (va Define the OID that will be used to name the interfaces (default: atrConnCepGenDescr) (values: atrConnIngDescr, atrConnCepGenDescr). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--add-extra-oid> diff --git a/src/network/brocade/snmp/mode/interfaces.pm b/src/network/brocade/snmp/mode/interfaces.pm index 78b160222..007174c4b 100644 --- a/src/network/brocade/snmp/mode/interfaces.pm +++ b/src/network/brocade/snmp/mode/interfaces.pm @@ -369,13 +369,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/brocade/snmp/mode/listinterfaces.pm b/src/network/brocade/snmp/mode/listinterfaces.pm index 0291fc74d..9ac49c4cc 100644 --- a/src/network/brocade/snmp/mode/listinterfaces.pm +++ b/src/network/brocade/snmp/mode/listinterfaces.pm @@ -162,13 +162,11 @@ Define the OID to be used to filter interfaces (default: ifName) (values: fcPort Define the OID that will be used to name the interfaces (default: ifName) (values: fcPortName, ifDesc, ifAlias, ifName). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--add-extra-oid> diff --git a/src/network/cambium/cnpilot/snmp/mode/interfaces.pm b/src/network/cambium/cnpilot/snmp/mode/interfaces.pm index 8cf064f16..41c8aa05b 100644 --- a/src/network/cambium/cnpilot/snmp/mode/interfaces.pm +++ b/src/network/cambium/cnpilot/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/cambium/epmp/snmp/mode/interfaces.pm b/src/network/cambium/epmp/snmp/mode/interfaces.pm index f0db08188..421227448 100644 --- a/src/network/cambium/epmp/snmp/mode/interfaces.pm +++ b/src/network/cambium/epmp/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/dell/nseries/snmp/mode/interfaces.pm b/src/network/dell/nseries/snmp/mode/interfaces.pm index dc18bb6de..b3707ae38 100644 --- a/src/network/dell/nseries/snmp/mode/interfaces.pm +++ b/src/network/dell/nseries/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/dlink/standard/snmp/mode/interfaces.pm b/src/network/dlink/standard/snmp/mode/interfaces.pm index 2df17e02d..fc8db2cfb 100644 --- a/src/network/dlink/standard/snmp/mode/interfaces.pm +++ b/src/network/dlink/standard/snmp/mode/interfaces.pm @@ -240,13 +240,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/enterasys/snmp/mode/interfaces.pm b/src/network/enterasys/snmp/mode/interfaces.pm index ff3ee112a..9b9999459 100644 --- a/src/network/enterasys/snmp/mode/interfaces.pm +++ b/src/network/enterasys/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/extreme/snmp/mode/interfaces.pm b/src/network/extreme/snmp/mode/interfaces.pm index 8619303b0..55b6baa60 100644 --- a/src/network/extreme/snmp/mode/interfaces.pm +++ b/src/network/extreme/snmp/mode/interfaces.pm @@ -193,13 +193,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/fortinet/fortiadc/snmp/mode/interfaces.pm b/src/network/fortinet/fortiadc/snmp/mode/interfaces.pm index 6f522638c..a644ed646 100644 --- a/src/network/fortinet/fortiadc/snmp/mode/interfaces.pm +++ b/src/network/fortinet/fortiadc/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/fortinet/fortimail/snmp/mode/interfaces.pm b/src/network/fortinet/fortimail/snmp/mode/interfaces.pm index 688792af9..29e200e8c 100644 --- a/src/network/fortinet/fortimail/snmp/mode/interfaces.pm +++ b/src/network/fortinet/fortimail/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ efine the OID that will be used to name the interfaces (default: ifName) (values Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/fortinet/fortiswitch/snmp/mode/interfaces.pm b/src/network/fortinet/fortiswitch/snmp/mode/interfaces.pm index edd4f3b9c..f1c903241 100644 --- a/src/network/fortinet/fortiswitch/snmp/mode/interfaces.pm +++ b/src/network/fortinet/fortiswitch/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/hp/moonshot/snmp/mode/interfaces.pm b/src/network/hp/moonshot/snmp/mode/interfaces.pm index 245030ac4..9ca88b399 100644 --- a/src/network/hp/moonshot/snmp/mode/interfaces.pm +++ b/src/network/hp/moonshot/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/hp/procurve/snmp/mode/interfaces.pm b/src/network/hp/procurve/snmp/mode/interfaces.pm index e8cf04aa0..8aba5b83c 100644 --- a/src/network/hp/procurve/snmp/mode/interfaces.pm +++ b/src/network/hp/procurve/snmp/mode/interfaces.pm @@ -386,13 +386,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/huawei/snmp/mode/interfaces.pm b/src/network/huawei/snmp/mode/interfaces.pm index e610acfa8..db7407f34 100644 --- a/src/network/huawei/snmp/mode/interfaces.pm +++ b/src/network/huawei/snmp/mode/interfaces.pm @@ -295,13 +295,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/juniper/common/junos/mode/interfaces.pm b/src/network/juniper/common/junos/mode/interfaces.pm index 92934463e..ae5f1c6d5 100644 --- a/src/network/juniper/common/junos/mode/interfaces.pm +++ b/src/network/juniper/common/junos/mode/interfaces.pm @@ -370,13 +370,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/lenovo/rackswitch/snmp/mode/interfaces.pm b/src/network/lenovo/rackswitch/snmp/mode/interfaces.pm index 35b8e8c2c..1b964fa19 100644 --- a/src/network/lenovo/rackswitch/snmp/mode/interfaces.pm +++ b/src/network/lenovo/rackswitch/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/libraesva/snmp/mode/interfaces.pm b/src/network/libraesva/snmp/mode/interfaces.pm index 3735b4322..d2d56bef7 100644 --- a/src/network/libraesva/snmp/mode/interfaces.pm +++ b/src/network/libraesva/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/libraesva/snmp/mode/storage.pm b/src/network/libraesva/snmp/mode/storage.pm index ccedfe2a8..858e9e2c7 100644 --- a/src/network/libraesva/snmp/mode/storage.pm +++ b/src/network/libraesva/snmp/mode/storage.pm @@ -102,13 +102,11 @@ Choose OID used to filter storage (default: hrStorageDescr) (values: hrStorageDe Choose OID used to display storage (default: hrStorageDescr) (values: hrStorageDescr, hrFSMountPoint). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the storage name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =item B<--show-cache> diff --git a/src/network/microsens/g6/snmp/mode/interfaces.pm b/src/network/microsens/g6/snmp/mode/interfaces.pm index ee430b2f2..775ec2ca9 100644 --- a/src/network/microsens/g6/snmp/mode/interfaces.pm +++ b/src/network/microsens/g6/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/mikrotik/snmp/mode/interfaces.pm b/src/network/mikrotik/snmp/mode/interfaces.pm index 02a33dd67..ff7279a60 100644 --- a/src/network/mikrotik/snmp/mode/interfaces.pm +++ b/src/network/mikrotik/snmp/mode/interfaces.pm @@ -266,13 +266,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/mrv/optiswitch/snmp/mode/interfaces.pm b/src/network/mrv/optiswitch/snmp/mode/interfaces.pm index 25aeddae0..8d814e282 100644 --- a/src/network/mrv/optiswitch/snmp/mode/interfaces.pm +++ b/src/network/mrv/optiswitch/snmp/mode/interfaces.pm @@ -529,13 +529,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/mrv/optiswitch/snmp/mode/listinterfaces.pm b/src/network/mrv/optiswitch/snmp/mode/listinterfaces.pm index b25186f5a..ce1b1944c 100644 --- a/src/network/mrv/optiswitch/snmp/mode/listinterfaces.pm +++ b/src/network/mrv/optiswitch/snmp/mode/listinterfaces.pm @@ -107,13 +107,11 @@ Define the OID to be used to filter interfaces (default: atrConnCepGenDescr) (va Define the OID that will be used to name the interfaces (default: atrConnCepGenDescr) (values: atrConnIngDescr, atrConnCepGenDescr). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--add-extra-oid> diff --git a/src/network/netgear/sseries/snmp/mode/interfaces.pm b/src/network/netgear/sseries/snmp/mode/interfaces.pm index 2f4891ec1..c6b9d5eda 100644 --- a/src/network/netgear/sseries/snmp/mode/interfaces.pm +++ b/src/network/netgear/sseries/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/nortel/standard/snmp/mode/interfaces.pm b/src/network/nortel/standard/snmp/mode/interfaces.pm index 8a031fd14..6602e006b 100644 --- a/src/network/nortel/standard/snmp/mode/interfaces.pm +++ b/src/network/nortel/standard/snmp/mode/interfaces.pm @@ -187,13 +187,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/oneaccess/snmp/mode/interfaces.pm b/src/network/oneaccess/snmp/mode/interfaces.pm index 00007056e..d3911e52d 100644 --- a/src/network/oneaccess/snmp/mode/interfaces.pm +++ b/src/network/oneaccess/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/opengear/snmp/mode/interfaces.pm b/src/network/opengear/snmp/mode/interfaces.pm index 1da4435a9..287dc3015 100644 --- a/src/network/opengear/snmp/mode/interfaces.pm +++ b/src/network/opengear/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/raisecom/snmp/mode/interfaces.pm b/src/network/raisecom/snmp/mode/interfaces.pm index b56005bfc..59e2537fa 100644 --- a/src/network/raisecom/snmp/mode/interfaces.pm +++ b/src/network/raisecom/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/securactive/mode/bcn.pm b/src/network/securactive/mode/bcn.pm index 293804f82..f02dc2a9c 100644 --- a/src/network/securactive/mode/bcn.pm +++ b/src/network/securactive/mode/bcn.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use Safe; my $oid_spvBCNName = '.1.3.6.1.4.1.36773.3.2.2.1.1.1'; my $oid_spvBCNGlobalStatus = '.1.3.6.1.4.1.36773.3.2.2.1.1.4'; @@ -42,16 +43,19 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "bcn:s" => { name => 'bcn' }, - "name" => { name => 'use_name' }, - "regexp" => { name => 'use_regexp' }, - "display-transform-src:s" => { name => 'display_transform_src' }, - "display-transform-dst:s" => { name => 'display_transform_dst' }, - }); + $options{options}->add_options(arguments => { + "bcn:s" => { name => 'bcn' }, + "name" => { name => 'use_name' }, + "regexp" => { name => 'use_regexp' }, + "display-transform-src:s" => { name => 'display_transform_src' }, + "display-transform-dst:s" => { name => 'display_transform_dst' } + }); + $self->{bcn_id_selected} = []; + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -102,28 +106,38 @@ sub run { $self->{snmp} = $options{snmp}; $self->manage_selection(); - $self->{snmp}->load(oids => [$oid_spvBCNGlobalStatus], - instances => $self->{bcn_id_selected}); + $self->{snmp}->load( + oids => [$oid_spvBCNGlobalStatus], + instances => $self->{bcn_id_selected} + ); my $result = $self->{snmp}->get_leef(); if (!defined($self->{option_results}->{bcn}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All BCN are ok.'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'All BCN are ok.' + ); } - + foreach my $instance (sort @{$self->{bcn_id_selected}}) { my $name = $self->{result_names}->{$oid_spvBCNName . '.' . $instance}; $name = $self->get_display_value(value => $name); my $status = $result->{$oid_spvBCNGlobalStatus . '.' . $instance}; my $exit_from_snmp = ${$bcn_status{$status}}[1]; - $self->{output}->output_add(long_msg => sprintf("BCN '%s' global status is '%s'", - $name, ${$bcn_status{$status}}[0])); + $self->{output}->output_add( + long_msg => sprintf( + "BCN '%s' global status is '%s'", + $name, ${$bcn_status{$status}}[0] + ) + ); if (!$self->{output}->is_status(value => $exit_from_snmp, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{bcn}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit_from_snmp, - short_msg => sprintf("BCN '%s' global status is '%s'", $name, ${$bcn_status{$status}}[0])); + $self->{output}->output_add( + severity => $exit_from_snmp, + short_msg => sprintf("BCN '%s' global status is '%s'", $name, ${$bcn_status{$status}}[0]) + ); } - + my $extra_label = ''; $extra_label = '_' . $name if (!defined($self->{option_results}->{bcn}) || defined($self->{option_results}->{use_regexp})); #$self->{output}->perfdata_add(label => 'eurt' . $extra_label, @@ -132,20 +146,25 @@ sub run { # critical => $critth, # min => 0); } - + $self->{output}->display(); $self->{output}->exit(); } sub get_display_value { my ($self, %options) = @_; - my $value = $options{value}; + our $assign_var = $options{value}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + + return $assign_var; } 1; @@ -160,25 +179,22 @@ Check BCN status. =item B<--bcn> -Set the bcn (number expected) ex: 1, 2,... (empty means 'check all bcn'). +Set the BCN (number expected) ex: 1, 2,... (empty means 'check all bcn'). =item B<--name> -Allows to use bcn name with option --bcn instead of bcn oid index. +Allows to use BCN name with option --bcn instead of bcn oid index. =item B<--regexp> -Allows to use regexp to filter bcn (with option --name). +Allows to use regexp to filter BCN (with option --name). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the BCN name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='-' --display-transform-dst='_' will replace all occurrences of '-' with '_' =back =cut - diff --git a/src/network/securactive/mode/listbcn.pm b/src/network/securactive/mode/listbcn.pm index 1fb8ed6a1..81a23857d 100644 --- a/src/network/securactive/mode/listbcn.pm +++ b/src/network/securactive/mode/listbcn.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use Safe; my $oid_spvBCNName = '.1.3.6.1.4.1.36773.3.2.2.1.1.1'; @@ -42,6 +43,9 @@ sub new { $self->{bcn_id_selected} = []; + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -104,13 +108,18 @@ sub run { sub get_display_value { my ($self, %options) = @_; - my $value = $options{value}; + our $assign_var = $options{value}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + + return $assign_var; } sub disco_format { @@ -147,25 +156,22 @@ List BCN. =item B<--bcn> -Set the bcn (number expected) ex: 1, 2,... (empty means 'check all bcn'). +Set the BCN (number expected) ex: 1, 2,... (empty means 'check all bcn'). =item B<--name> -Allows to use bcn name with option --bcn instead of bcn oid index. +Allows to use BCN name with option --bcn instead of bcn oid index. =item B<--regexp> -Allows to use regexp to filter bcn (with option --name). +Allows to use regexp to filter BCN (with option --name). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the BCN name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='-' --display-transform-dst='_' will replace all occurrences of '-' with '_' =back =cut - diff --git a/src/network/sonus/sbc/snmp/mode/interfaces.pm b/src/network/sonus/sbc/snmp/mode/interfaces.pm index d8c8f1e6f..df1a3d533 100644 --- a/src/network/sonus/sbc/snmp/mode/interfaces.pm +++ b/src/network/sonus/sbc/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/network/sonus/sbc/snmp/mode/storage.pm b/src/network/sonus/sbc/snmp/mode/storage.pm index cf60fb54b..0af99cc32 100644 --- a/src/network/sonus/sbc/snmp/mode/storage.pm +++ b/src/network/sonus/sbc/snmp/mode/storage.pm @@ -102,13 +102,11 @@ Choose OID used to filter storage (default: hrStorageDescr) (values: hrStorageDe Choose OID used to display storage (default: hrStorageDescr) (values: hrStorageDescr, hrFSMountPoint). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the storage name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =item B<--show-cache> diff --git a/src/network/viptela/snmp/mode/interfaces.pm b/src/network/viptela/snmp/mode/interfaces.pm index 0c7c8880e..8abcab397 100644 --- a/src/network/viptela/snmp/mode/interfaces.pm +++ b/src/network/viptela/snmp/mode/interfaces.pm @@ -165,13 +165,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/os/picos/snmp/mode/interfaces.pm b/src/os/picos/snmp/mode/interfaces.pm index 14e0fe777..3c82e7815 100644 --- a/src/os/picos/snmp/mode/interfaces.pm +++ b/src/os/picos/snmp/mode/interfaces.pm @@ -299,13 +299,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/os/picos/snmp/mode/listinterfaces.pm b/src/os/picos/snmp/mode/listinterfaces.pm index 161bad2a7..fdecfc95f 100644 --- a/src/os/picos/snmp/mode/listinterfaces.pm +++ b/src/os/picos/snmp/mode/listinterfaces.pm @@ -85,13 +85,11 @@ Define the OID to be used to filter interfaces (default: ifDesc) (values: ifDesc Define the OID that will be used to name the interfaces (default: ifDesc) (values: ifDesc, ifAlias, ifName). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--add-extra-oid> diff --git a/src/os/windows/wsman/mode/liststorages.pm b/src/os/windows/wsman/mode/liststorages.pm index 467302046..a93470387 100644 --- a/src/os/windows/wsman/mode/liststorages.pm +++ b/src/os/windows/wsman/mode/liststorages.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use Safe; sub new { my ($class, %options) = @_; @@ -35,6 +36,9 @@ sub new { 'display-transform-dst:s' => { name => 'display_transform_dst' } }); + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -55,16 +59,20 @@ my $map_types = { 6 => 'ramDisk' }; - sub get_display_value { my ($self, %options) = @_; - my $value = $options{name}; + our $assign_var = $options{name}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + + return $assign_var; } sub manage_selection { @@ -104,6 +112,7 @@ sub run { severity => 'OK', short_msg => 'List storages:' ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -134,13 +143,11 @@ List storages. =over 8 -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the storage name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =back diff --git a/src/snmp_standard/mode/diskusage.pm b/src/snmp_standard/mode/diskusage.pm index 3714ac7dc..e42858ddc 100644 --- a/src/snmp_standard/mode/diskusage.pm +++ b/src/snmp_standard/mode/diskusage.pm @@ -26,6 +26,7 @@ use strict; use warnings; use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); +use Safe; sub custom_usage_output { my ($self, %options) = @_; @@ -132,6 +133,9 @@ sub new { $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -343,13 +347,17 @@ sub get_selection { sub get_display_value { my ($self, %options) = @_; - my $value = $options{value}; + our $assign_var = $options{value}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + return $assign_var; } 1; @@ -383,13 +391,11 @@ Filter disks according to their device name. Time in minutes before reloading cache file (default: 180). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the disk name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =item B<--show-cache> diff --git a/src/snmp_standard/mode/inodes.pm b/src/snmp_standard/mode/inodes.pm index 52278cfbe..944756d89 100644 --- a/src/snmp_standard/mode/inodes.pm +++ b/src/snmp_standard/mode/inodes.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Safe; sub set_counters { my ($self, %options) = @_; @@ -67,6 +68,9 @@ sub new { 'display-transform-dst:s' => { name => 'display_transform_dst' }, }); + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -79,10 +83,15 @@ my $mapping = { sub manage_selection { my ($self, %options) = @_; - my $results = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping->{dskPath}->{oid} }, - { oid => $mapping->{dskDevice}->{oid} }, - { oid => $mapping->{dskPercentNode}->{oid} } ], - return_type => 1, nothing_quit => 1); + my $results = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping->{dskPath}->{oid} }, + { oid => $mapping->{dskDevice}->{oid} }, + { oid => $mapping->{dskPercentNode}->{oid} } + ], + return_type => 1, + nothing_quit => 1 + ); $self->{disk} = {}; foreach my $oid ($options{snmp}->oid_lex_sort(keys %{$results})) { next if ($oid !~ /^$mapping->{dskPath}->{oid}\.(.*)/); @@ -90,9 +99,9 @@ sub manage_selection { my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); $result->{dskPath} = $self->get_display_value(value => $result->{dskPath}); - + $self->{output}->output_add(long_msg => sprintf("disk path : '%s', device : '%s'", $result->{dskPath}, $result->{dskDevice}), debug => 1); - + if (!defined($result->{dskPercentNode})) { $self->{output}->output_add(long_msg => sprintf("skipping '%s' : no inode usage value", $result->{dskPath}), debug => 1); next; @@ -131,8 +140,7 @@ sub manage_selection { next; } } - - + $self->{disk}->{$result->{dskPath}} = { display => $result->{dskPath}, usage => $result->{dskPercentNode} @@ -147,13 +155,18 @@ sub manage_selection { sub get_display_value { my ($self, %options) = @_; - my $value = $options{value}; + our $assign_var = $options{value}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + + return $assign_var; } 1; @@ -191,13 +204,11 @@ Allows to use regexp to filter diskpath (with option --name). Allows to use regexp non case-sensitive (with --regexp). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the disk path name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =item B<--filter-device> diff --git a/src/snmp_standard/mode/interfaces.pm b/src/snmp_standard/mode/interfaces.pm index e1a4bea35..3451ba150 100644 --- a/src/snmp_standard/mode/interfaces.pm +++ b/src/snmp_standard/mode/interfaces.pm @@ -26,6 +26,7 @@ use strict; use warnings; use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); +use Safe; ######################### # Calc functions @@ -987,6 +988,9 @@ sub new { $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -1059,12 +1063,16 @@ sub check_options { sub get_display_value { my ($self, %options) = @_; - my $value = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $options{id}); + our $assign_var = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $options{id}); if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + return $assign_var; } sub check_oids_options_change { @@ -1729,13 +1737,11 @@ Define the OID that will be used to name the interfaces (default: ifName) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> diff --git a/src/snmp_standard/mode/listdiskspath.pm b/src/snmp_standard/mode/listdiskspath.pm index d9ec5d2f4..590b107fe 100644 --- a/src/snmp_standard/mode/listdiskspath.pm +++ b/src/snmp_standard/mode/listdiskspath.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use Safe; my $oid_dskPath = '.1.3.6.1.4.1.2021.9.1.2'; my $oid_dskTotalLow = '.1.3.6.1.4.1.2021.9.1.11'; @@ -46,6 +47,9 @@ sub new { $self->{diskpath_id_selected} = []; + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -75,8 +79,10 @@ sub run { $self->{output}->output_add(long_msg => "'" . $display_value . "' [id = " . $_ . ']'); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'List disk path:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List disk path:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -95,13 +101,18 @@ sub get_additional_information { sub get_display_value { my ($self, %options) = @_; - my $value = $self->{datas}->{'dskPath_' . $options{id}}; + our $assign_var = $self->{datas}->{'dskPath_' . $options{id}}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + + return $assign_var; } sub manage_selection { @@ -179,8 +190,10 @@ sub disco_show { } my $display_value = $self->get_display_value(id => $_); - $self->{output}->add_disco_entry(name => $display_value, - diskpathid => $_); + $self->{output}->add_disco_entry( + name => $display_value, + diskpathid => $_ + ); } } @@ -211,13 +224,11 @@ Allows to use regexp to filter diskpath (with option --name). Allows to use regexp non case-sensitive (with --regexp). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the disk path name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =item B<--skip-total-size-zero> diff --git a/src/snmp_standard/mode/listinterfaces.pm b/src/snmp_standard/mode/listinterfaces.pm index f7063f615..3940fdca5 100644 --- a/src/snmp_standard/mode/listinterfaces.pm +++ b/src/snmp_standard/mode/listinterfaces.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use Safe; use snmp_standard::mode::resources::types qw($map_iftype); my $oid_speed32 = '.1.3.6.1.2.1.2.2.1.5'; # in b/s @@ -113,6 +114,9 @@ sub new { $self->{interface_id_selected} = []; + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -223,12 +227,17 @@ sub get_additional_information { sub get_display_value { my ($self, %options) = @_; - my $value = $self->{datas}->{$self->{option_results}->{oid_display} . '_' . $options{id}}; + our $assign_var = $self->{datas}->{$self->{option_results}->{oid_display} . '_' . $options{id}}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + + return $assign_var; } sub manage_selection { @@ -365,6 +374,7 @@ sub disco_show { $extra_values->{type} = defined($result->{ $self->{oid_iftype} . '.' . $_ }) && defined($map_iftype->{ $result->{ $self->{oid_iftype} . '.' . $_ } }) ? $map_iftype->{ $result->{ $self->{oid_iftype} . '.' . $_ } } : 'unknown'; } + $self->{output}->add_disco_entry( name => $display_value, total => $interface_speed, @@ -415,13 +425,11 @@ Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--add-extra-oid> diff --git a/src/snmp_standard/mode/liststorages.pm b/src/snmp_standard/mode/liststorages.pm index 512302b54..8e5d1f3cd 100644 --- a/src/snmp_standard/mode/liststorages.pm +++ b/src/snmp_standard/mode/liststorages.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use Safe; my %oids_hrStorageTable = ( 'hrstoragedescr' => '.1.3.6.1.2.1.25.2.3.1.3', @@ -90,7 +91,10 @@ sub new { }); $self->{storage_id_selected} = []; - + + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -129,8 +133,10 @@ sub run { $self->{output}->output_add(long_msg => "'" . $display_value . "' [size = " . $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_} . "B] [id = $_]"); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'List storage:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List storage:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -144,13 +150,18 @@ sub get_additional_information { sub get_display_value { my ($self, %options) = @_; - my $value = $self->{datas}->{$self->{option_results}->{oid_display} . "_" . $options{id}}; + our $assign_var = $self->{datas}->{$self->{option_results}->{oid_display} . "_" . $options{id}}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + + return $assign_var; } sub manage_selection { @@ -262,9 +273,11 @@ sub disco_show { next if (!defined($storage_type) || ($storage_types_manage{$storage_type} !~ /$self->{option_results}->{filter_storage_type}/i)); - $self->{output}->add_disco_entry(name => $display_value, - total => $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}, - storageid => $_); + $self->{output}->add_disco_entry( + name => $display_value, + total => $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}, + storageid => $_ + ); } } @@ -300,13 +313,11 @@ Choose OID used to filter storage (default: hrStorageDescr) (values: hrStorageDe Choose OID used to display storage (default: hrStorageDescr) (values: hrStorageDescr, hrFSMountPoint). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the storage name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =item B<--filter-storage-type> diff --git a/src/snmp_standard/mode/storage.pm b/src/snmp_standard/mode/storage.pm index 8b49c6e4e..10b8b7308 100644 --- a/src/snmp_standard/mode/storage.pm +++ b/src/snmp_standard/mode/storage.pm @@ -26,6 +26,7 @@ use strict; use warnings; use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); +use Safe; my %oids_hrStorageTable = ( 'hrstoragedescr' => '.1.3.6.1.2.1.25.2.3.1.3', @@ -270,6 +271,9 @@ sub new { $self->{storage_id_selected} = []; $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + $self->{safe} = Safe->new(); + $self->{safe}->share('$assign_var'); + return $self; } @@ -577,13 +581,18 @@ sub get_selection { sub get_display_value { my ($self, %options) = @_; - my $value = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $options{id}); + our $assign_var = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_display} . "_" . $options{id}); if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); - eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + + $self->{safe}->reval("\$assign_var =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}", 1); + if ($@) { + die 'Unsafe code evaluation: ' . $@; + } } - return $value; + + return $assign_var; } 1; @@ -655,13 +664,11 @@ Choose OID used to filter storage (default: hrStorageDescr) (values: hrStorageDe Choose OID used to display storage (default: hrStorageDescr) (values: hrStorageDescr, hrFSMountPoint). -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. (security risk!!!) +Modify the storage name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) +Eg: adding --display-transform-src='dev' --display-transform-dst='run' will replace all occurrences of 'dev' with 'run' =item B<--show-cache> diff --git a/src/storage/lenovo/iomega/snmp/mode/interfaces.pm b/src/storage/lenovo/iomega/snmp/mode/interfaces.pm index b1ac6bf88..0a33f3b99 100644 --- a/src/storage/lenovo/iomega/snmp/mode/interfaces.pm +++ b/src/storage/lenovo/iomega/snmp/mode/interfaces.pm @@ -166,13 +166,11 @@ Define the OID that will be used to name the interfaces (default: ifDesc) (value Add an OID to display. -=item B<--display-transform-src> +=item B<--display-transform-src> B<--display-transform-dst> -Regexp src to transform display value. +Modify the interface name displayed by using a regular expression. -=item B<--display-transform-dst> - -Regexp dst to transform display value. +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' =item B<--show-cache> From 7e011ac95b23b42d06d2b142af159a2637bec3f8 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 8 Aug 2023 10:31:39 +0200 Subject: [PATCH 22/24] fix(pg/pkg): fix postgresql packaging dependencies (#4585) Co-authored-by: Colin Gagnaire --- .../centreon-plugin-Applications-Databases-Postgresql/deb.json | 1 + .../centreon-plugin-Applications-Databases-Postgresql/rpm.json | 1 + 2 files changed, 2 insertions(+) diff --git a/packaging/centreon-plugin-Applications-Databases-Postgresql/deb.json b/packaging/centreon-plugin-Applications-Databases-Postgresql/deb.json index bf3c085d1..667df5d62 100644 --- a/packaging/centreon-plugin-Applications-Databases-Postgresql/deb.json +++ b/packaging/centreon-plugin-Applications-Databases-Postgresql/deb.json @@ -1,5 +1,6 @@ { "dependencies": [ + "libdbd-pg-perl", "libdbi-perl" ] } \ No newline at end of file diff --git a/packaging/centreon-plugin-Applications-Databases-Postgresql/rpm.json b/packaging/centreon-plugin-Applications-Databases-Postgresql/rpm.json index 9bda8eaff..d67dfb282 100644 --- a/packaging/centreon-plugin-Applications-Databases-Postgresql/rpm.json +++ b/packaging/centreon-plugin-Applications-Databases-Postgresql/rpm.json @@ -1,5 +1,6 @@ { "dependencies": [ + "perl(DBD::Pg)", "perl(DBI)", "perl(Time::HiRes)", "perl(POSIX)" From 77a7fd9e84b935b42313f1c272fd4bf20dd22cc3 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 8 Aug 2023 15:29:31 +0200 Subject: [PATCH 23/24] (plugin) os::windows::snmp - refactor service mode (#4573) Co-authored-by: Colin Gagnaire --- src/os/windows/snmp/mode/service.pm | 318 +++++++++++++++++----------- 1 file changed, 196 insertions(+), 122 deletions(-) diff --git a/src/os/windows/snmp/mode/service.pm b/src/os/windows/snmp/mode/service.pm index 6d2e02f0a..2d5d91fce 100644 --- a/src/os/windows/snmp/mode/service.pm +++ b/src/os/windows/snmp/mode/service.pm @@ -20,35 +20,99 @@ package os::windows::snmp::mode::service; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); -my %map_installed_state = ( - 1 => 'uninstalled', - 2 => 'install-pending', - 3 => 'uninstall-pending', - 4 => 'installed' -); -my %map_operating_state = ( - 1 => 'active', - 2 => 'continue-pending', - 3 => 'pause-pending', - 4 => 'paused' -); +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "state is '" . $self->{result_values}->{operating_state}; + $msg .= "' [installed state: '" . $self->{result_values}->{installed_state} . "']"; + return $msg; +} + +sub prefix_services_output { + my ($self, %options) = @_; + + return "Service '" . $options{instance_value}->{name} . "' "; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Number of services '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'services', type => 1, cb_prefix_output => 'prefix_services_output', + message_multiple => 'All services are ok', skipped_code => { -10 => 1, -11 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'active', nlabel => 'services.active.count', display_ok => 0, set => { + key_values => [ { name => 'active' } ], + output_template => 'active: %d', + perfdatas => [ + { template => '%d', min => 0 } + ] + } + }, + { label => 'continue-pending', nlabel => 'services.continue.pending.count', display_ok => 0, set => { + key_values => [ { name => 'continue-pending' } ], + output_template => 'continue pending: %d', + perfdatas => [ + { template => '%d', min => 0 } + ] + } + }, + { label => 'pause-pending', nlabel => 'services.pause.pending.count', display_ok => 0, set => { + key_values => [ { name => 'pause-pending' } ], + output_template => 'pause pending: %d', + perfdatas => [ + { template => '%d', min => 0 } + ] + } + }, + { label => 'paused', nlabel => 'services.paused.count', display_ok => 0, set => { + key_values => [ { name => 'paused' } ], + output_template => 'Service paused: %d', + perfdatas => [ + { template => '%d', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{services} = [ + { label => 'status', type => 2, set => { + key_values => [ { name => 'operating_state' }, { name => 'installed_state' }, { name => 'name' } ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - 'warning:s' => { name => 'warning', }, - 'critical:s' => { name => 'critical', }, - 'service:s@' => { name => 'service', }, - 'regexp' => { name => 'use_regexp', }, - 'state:s' => { name => 'state' } + 'filter-name:s' => { name => 'filter_name' }, + 'warning:s' => { name => 'warning' }, # deprecated + 'critical:s' => { name => 'critical' }, # deprecated + 'service:s@' => { name => 'service' }, # deprecated + 'regexp' => { name => 'use_regexp' }, # deprecated + 'state:s' => { name => 'state' } # deprecated }); return $self; @@ -56,117 +120,112 @@ sub new { sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + + # Compatibility for deprecated options + if (defined($options{option_results}->{warning}) && $options{option_results}->{warning} ne '') { + $options{option_results}->{'warning-service-active-count'} = $options{option_results}->{warning}; + } + if (defined($options{option_results}->{critical}) && $options{option_results}->{critical} ne '') { + $options{option_results}->{'critical-service-active-count'} = $options{option_results}->{critical}; + } - if (!defined($self->{option_results}->{service})) { - $self->{output}->add_option_msg(short_msg => "Need to specify at least one '--service' option."); - $self->{output}->option_exit(); + my $delimiter = ''; + if (defined($options{option_results}->{service})) { + my $filter = ''; + for my $filter_service (@{$options{option_results}->{service}}) { + next if ($filter_service eq ''); + if (defined($options{option_results}->{use_regexp})) { + $filter.= $delimiter . $filter_service; + } else { + $filter .= $delimiter . quotemeta($filter_service); + } + + $delimiter = '|'; + } + + if ($filter ne '' && !defined($options{option_results}->{use_regexp})) { + $filter = '^(' . $filter . ')$'; + } + + if (!defined($options{option_results}->{'filter_name'}) || $options{option_results}->{'filter_name'} eq '') { + $options{option_results}->{'filter_name'} = $filter; + } + } + + if (defined($options{option_results}->{state}) && $options{option_results}->{state} ne '') { + $options{option_results}->{'critical-status'} = "%{operating_state} !~ /$options{option_results}->{state}/"; } - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } + $self->SUPER::check_options(%options); } -sub run { +sub manage_selection { my ($self, %options) = @_; + + my $map_installed_state = { + 1 => 'uninstalled', + 2 => 'install-pending', + 3 => 'uninstall-pending', + 4 => 'installed' + }; - my $oid_svSvcEntry = '.1.3.6.1.4.1.77.1.2.3.1'; - my $oid_svSvcInstalledState = '.1.3.6.1.4.1.77.1.2.3.1.2'; - my $oid_svSvcOperatingState = '.1.3.6.1.4.1.77.1.2.3.1.3'; - my $result = $options{snmp}->get_table(oid => $oid_svSvcEntry, start => $oid_svSvcInstalledState, end => $oid_svSvcOperatingState); - - my $services_match = {}; - $self->{output}->output_add( - severity => 'OK', - short_msg => 'All service states are ok' + my $map_operating_state = { + 1 => 'active', + 2 => 'continue-pending', + 3 => 'pause-pending', + 4 => 'paused' + }; + + my $mapping = { + installed_state => { oid => '.1.3.6.1.4.1.77.1.2.3.1.2', map => $map_installed_state }, # svSvcInstalledState + operating_state => { oid => '.1.3.6.1.4.1.77.1.2.3.1.3', map => $map_operating_state } # svSvcOperatingState + }; + my $table_svSvcEntry = '.1.3.6.1.4.1.77.1.2.3.1'; + + my $snmp_result = $options{snmp}->get_table( + oid => $table_svSvcEntry, + start => $mapping->{installed_state}->{oid}, + end => $mapping->{operating_state}->{oid}, + nothing_quit => 1 ); - use Encode; - foreach my $oid ($options{snmp}->oid_lex_sort(keys %$result)) { - next if ($oid !~ /^$oid_svSvcOperatingState\.(\d+)\.(.*)$/); + + $self->{global} = { + 'active' => 0, + 'continue-pending' => 0, + 'pause-pending' => 0, + 'paused' => 0 + }; + + $self->{services} = {}; + + foreach my $oid ($options{snmp}->oid_lex_sort(keys %$snmp_result)) { + next if ($oid !~ /^$mapping->{operating_state}->{oid}\.(\d+)\.(.*)$/); my $instance = $1 . '.' . $2; - my $svc_name = $self->{output}->decode(join('', map(chr($_), split(/\./, $2)))); - my $svc_installed_state = $result->{$oid_svSvcInstalledState . '.' . $instance}; - my $svc_operating_state = $result->{$oid_svSvcOperatingState . '.' . $instance}; - for (my $i = 0; $i < scalar(@{$self->{option_results}->{service}}); $i++) { - $services_match->{$i} = {} if (!defined($services_match->{$i})); - my $filter = $self->{option_results}->{service}->[$i]; - if (defined($self->{option_results}->{use_regexp}) && $svc_name =~ /$filter/) { - $services_match->{$i}->{$svc_name} = { - operating_state => $svc_operating_state, - installed_state => $svc_installed_state - } - } elsif ($svc_name eq $filter) { - $services_match->{$i}->{$svc_name} = { - operating_state => $svc_operating_state, - installed_state => $svc_installed_state - } - } - } - } - - for (my $i = 0; $i < scalar(@{$self->{option_results}->{service}}); $i++) { - my $numbers = 0; - my $svc_name_state_wrong = {}; - foreach my $svc_name (keys %{$services_match->{$i}}) { - my $operating_state = $services_match->{$i}->{$svc_name}->{operating_state}; - my $installed_state = $services_match->{$i}->{$svc_name}->{installed_state}; - $self->{output}->output_add(long_msg => - sprintf( - "Service '%s' match (pattern: '%s') [operating state = %s, installed state = %s]", - $svc_name, $self->{option_results}->{service}->[$i], - $map_operating_state{$operating_state}, - $map_installed_state{$installed_state} - ) - ); - if (defined($self->{option_results}->{state}) && $map_operating_state{$operating_state} !~ /$self->{option_results}->{state}/) { - delete $services_match->{$i}->{$svc_name}; - $svc_name_state_wrong->{$svc_name} = $operating_state; - next; - } - $numbers++; - } + my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $2)))); - my $exit = $self->{perfdata}->threshold_check( - value => $numbers, threshold => [ - { label => 'critical', exit_litteral => 'critical' }, - { label => 'warning', exit_litteral => 'warning' } - ] + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/); + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance ); - $self->{output}->output_add( - long_msg => sprintf( - "Service pattern '%s': service list %s", - $self->{option_results}->{service}->[$i], - join(', ', keys %{$services_match->{$i}}) - ) - ); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - if (scalar(keys %$svc_name_state_wrong) > 0) { - $self->{output}->output_add( - severity => $exit, - short_msg => sprintf( - "Service pattern '%s' problem: %s [following services match but has the wrong state]", - $self->{option_results}->{service}->[$i], - join(', ', keys %$svc_name_state_wrong) - ) - ); - } else { - $self->{output}->output_add( - severity => $exit, - short_msg => sprintf("Service problem '%s'", $self->{option_results}->{service}->[$i]) - ); - } - } + + $self->{services}->{$instance} = { + name => $name, + operating_state => $result->{operating_state}, + installed_state => $result->{installed_state} + }; + + $self->{global}->{ $result->{operating_state} }++; } - $self->{output}->display(); - $self->{output}->exit(); + if (scalar(keys %{$self->{services}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No service found."); + $self->{output}->option_exit(); + } } 1; @@ -175,29 +234,44 @@ __END__ =head1 MODE -Check Windows Services in SNMP +Check Windows services states =over 8 +=item B<--filter-name> + +Filter by service name (can be a regexp). + +=item B<--warning-status> B<--critical-status> + +Set WARNING or CRITICAL threshold for status. +You can use the following variables: %{operating_state}, %{installed_state}. + +=item B<--warning-*> B<--critical-*> + +Thresholds on services count. +Can be: 'active', 'continue-pending', +'pause-pending', 'paused'. + =item B<--warning> -Warning threshold. +DEPRECATED. Use --warning-active instead. =item B<--critical> -Critical threshold. +DEPRECATED. Use --critical-active instead. =item B<--service> -Services to check. (can set multiple times) +DEPRECATED. Use --filter-name instead. =item B<--regexp> -Allows to use regexp to filter services. +DEPRECATED. Use --filter-name instead. =item B<--state> -Service state. (Regexp allowed) +DEPRECATED. Use --critical/warning-status instead. =back From c43b8ae476fefe5c99e06ceb4d3db20ba360bfed Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 9 Aug 2023 17:47:02 +0200 Subject: [PATCH 24/24] (plugin) network::teltonika::snmp - handle new mib (#4579) --- src/network/teltonika/snmp/mode/interfaces.pm | 180 ++++++++++ src/network/teltonika/snmp/mode/modem.pm | 315 ++++++++++++++++++ src/network/teltonika/snmp/mode/system.pm | 202 ----------- src/network/teltonika/snmp/plugin.pm | 9 +- 4 files changed, 499 insertions(+), 207 deletions(-) create mode 100644 src/network/teltonika/snmp/mode/interfaces.pm create mode 100644 src/network/teltonika/snmp/mode/modem.pm delete mode 100644 src/network/teltonika/snmp/mode/system.pm diff --git a/src/network/teltonika/snmp/mode/interfaces.pm b/src/network/teltonika/snmp/mode/interfaces.pm new file mode 100644 index 000000000..cd1eaf547 --- /dev/null +++ b/src/network/teltonika/snmp/mode/interfaces.pm @@ -0,0 +1,180 @@ +# +# 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 network::teltonika::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-global> + +Check global port statistics (By default if no --add-* option is set). + +=item B<--add-status> + +Check interface status. + +=item B<--add-duplex-status> + +Check duplex status (with --warning-status and --critical-status). + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-errors> + +Check interface errors. + +=item B<--add-cast> + +Check interface cast. + +=item B<--add-speed> + +Check interface speed. + +=item B<--add-volume> + +Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). + +=item B<--check-metrics> + +If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"'). + +=item B<--warning-status> + +Define the conditions to match for the status to be WARNING. +You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--critical-status> + +Define the conditions to match for the status to be CRITICAL (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast', +'speed' (b/s). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter'). + +=item B<--nagvis-perfdata> + +Display traffic perfdata to be compatible with nagvis widget. + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interfaces'). + +=item B<--name> + +Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions. + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--map-speed-dsl> + +Get interface speed configuration for interface type 'adsl' and 'vdsl2'. + +Syntax: --map-speed-dsl=interface-src-name,interface-dsl-name + +E.g: --map-speed-dsl=Et0.835,Et0-vdsl2 + +=item B<--force-counters64> + +Force to use 64 bits counters only. Can be used to improve performance. + +=item B<--force-counters32> + +Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-display> + +Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> B<--display-transform-dst> + +Modify the interface name displayed by using a regular expression. + +Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/src/network/teltonika/snmp/mode/modem.pm b/src/network/teltonika/snmp/mode/modem.pm new file mode 100644 index 000000000..6e7661398 --- /dev/null +++ b/src/network/teltonika/snmp/mode/modem.pm @@ -0,0 +1,315 @@ +# +# Copyright 2018 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::teltonika::snmp::mode::modem; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + "connection state is '%s' [pin state: '%s'] [net state: '%s'][sim state: '%s']", + $self->{result_values}->{connectionState}, + $self->{result_values}->{pinState}, + $self->{result_values}->{netState}, + $self->{result_values}->{simState} + ); +} + +sub prefix_modem_output { + my ($self, %options) = @_; + + return sprintf( + "modem imsi '%s' [operator: %s] ", + $options{instance_value}->{imsi}, + $options{instance_value}->{operator} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'modems', type => 1, cb_prefix_output => 'prefix_modem_output', message_multiple => 'All modems are ok', skipped_code => { -10 => 1, -11 => 1 } } + ]; + + $self->{maps_counters}->{modems} = [ + { label => 'status', type => 2, critical_default => '%{connectionState} !~ /connected/i', set => { + key_values => [ { name => 'simState' }, { name => 'pinState' }, { name => 'netState' }, { name => 'connectionState' } ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + }, + { label => 'signal-strength', nlabel => 'modem.signal.strength.dbm', display_ok => 0, set => { + key_values => [ { name => 'signal' }, { name => 'imsi' }, { name => 'operator' } ], + output_template => 'signal strength: %s dBm', + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'dBm', + instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], + value => sprintf('%s', $self->{result_values}->{signal}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) + ); + } + } + }, + { label => 'temperature', nlabel => 'modem.temperature.celsius', display_ok => 0, set => { + key_values => [ { name => 'temperature' }, { name => 'imsi' }, { name => 'operator' } ], + output_template => 'temperature: %s C', + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'C', + instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], + value => sprintf('%s', $self->{result_values}->{temperature}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + ); + } + } + }, + { label => 'traffic-in', nlabel => 'modem.traffic.in.bitspersecond', display_ok => 0, set => { + key_values => [ { name => 'received', per_second => 1 }, { name => 'imsi' }, { name => 'operator' } ], + output_template => 'traffic in: %s %s/s', + output_change_bytes => 2, + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'b/s', + instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], + value => sprintf('%s', $self->{result_values}->{received}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); + } + } + }, + { label => 'traffic-out', nlabel => 'modem.traffic.out.bitspersecond', display_ok => 0, set => { + key_values => [ { name => 'sent', per_second => 1 }, { name => 'imsi' }, { name => 'operator' } ], + output_template => 'traffic out: %s %s/s', + output_change_bytes => 2, + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'b/s', + instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], + value => sprintf('%s', $self->{result_values}->{sent}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); + } + } + }, + { label => 'signal-receive-power', nlabel => 'modem.signal.receive.power.dbm', display_ok => 0, set => { + key_values => [ { name => 'rsrp' }, { name => 'imsi' }, { name => 'operator' } ], + output_template => 'signal receive power: %s dBm', + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'dBm', + instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], + value => sprintf('%s', $self->{result_values}->{rsrp}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) + ); + } + } + }, + { label => 'signal-receive-quality', nlabel => 'modem.signal.receive.quality.dbm', display_ok => 0, set => { + key_values => [ { name => 'rsrq' }, { name => 'imsi' }, { name => 'operator' } ], + output_template => 'signal receive quality: %s dBm', + closure_custom_perfdata => sub { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'dBm', + instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], + value => sprintf('%s', $self->{result_values}->{rsrq}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) + ); + } + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub teltonika_legacy { + my ($self, %options) = @_; + + my $mapping = { + imsi => { oid => '.1.3.6.1.4.1.48690.1.6' }, + simState => { oid => '.1.3.6.1.4.1.48690.2.1' }, + pinState => { oid => '.1.3.6.1.4.1.48690.2.2' }, + netState => { oid => '.1.3.6.1.4.1.48690.2.3' }, + signal => { oid => '.1.3.6.1.4.1.48690.2.4' }, + operator => { oid => '.1.3.6.1.4.1.48690.2.5' }, + connectionState => { oid => '.1.3.6.1.4.1.48690.2.7' }, + temperature => { oid => '.1.3.6.1.4.1.48690.2.9' }, + sent => { oid => '.1.3.6.1.4.1.48690.2.19' }, + received => { oid => '.1.3.6.1.4.1.48690.2.20' }, + rsrp => { oid => '.1.3.6.1.4.1.48690.2.23' }, + rsrq => { oid => '.1.3.6.1.4.1.48690.2.24' } + }; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); + $result->{simState} = defined($result->{simState}) ? $result->{simState} : '-'; + $result->{pinState} = defined($result->{pinState}) ? $result->{pinState} : '-'; + $result->{netState} = defined($result->{netState}) ? $result->{netState} : '-'; + $result->{temperature} = $result->{temperature} / 10; + $result->{sent} = $result->{sent} * 8; + $result->{received} = $result->{received} * 8; + + $self->{modems} = { 0 => $result }; +} + +sub teltonika_trb14x { + my ($self, %options) = @_; + + my $mapping = { + imsi => { oid => '.1.3.6.1.4.1.48690.2.2.1.8' }, + simState => { oid => '.1.3.6.1.4.1.48690.2.2.1.9' }, + pinState => { oid => '.1.3.6.1.4.1.48690.2.2.1.10' }, + netState => { oid => '.1.3.6.1.4.1.48690.2.2.1.11' }, + signal => { oid => '.1.3.6.1.4.1.48690.2.2.1.12' }, + operator => { oid => '.1.3.6.1.4.1.48690.2.2.1.13' }, + connectionState => { oid => '.1.3.6.1.4.1.48690.2.2.1.15' }, + temperature => { oid => '.1.3.6.1.4.1.48690.2.2.1.17' }, + rsrp => { oid => '.1.3.6.1.4.1.48690.2.2.1.20' }, + rsrq => { oid => '.1.3.6.1.4.1.48690.2.2.1.21' }, + sent => { oid => '.1.3.6.1.4.1.48690.2.2.1.22' }, + received => { oid => '.1.3.6.1.4.1.48690.2.2.1.23' } + }; + + my $oid_modemEntry = '.1.3.6.1.4.1.48690.2.2.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_modemEntry, + nothing_quit => 1 + ); + + $self->{modems} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{imsi}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $result->{simState} = defined($result->{simState}) ? $result->{simState} : '-'; + $result->{pinState} = defined($result->{pinState}) ? $result->{pinState} : '-'; + $result->{netState} = defined($result->{netState}) ? $result->{netState} : '-'; + $result->{temperature} = $result->{temperature} / 10; + $result->{sent} = $result->{sent} * 8; + $result->{received} = $result->{received} * 8; + + $self->{modems}->{$instance} = $result; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_hardwareRevision = '.1.3.6.1.4.1.48690.1.10.0'; # legacy + my $oid_fwVersion = '.1.3.6.1.4.1.48690.1.6.0'; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ $oid_hardwareRevision, $oid_fwVersion ], + nothing_quit => 1 + ); + + if (defined($snmp_result->{$oid_hardwareRevision})) { + $self->teltonika_legacy(snmp => $options{snmp}); + } else { + $self->teltonika_trb14x(snmp => $options{snmp}); + } + + $self->{cache_name} = 'teltonika_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check modem. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--warning-status> + +Define the conditions to match for the status to be WARNING. +You can use the following variables: %{simState}, %{pinState}, %{netState}, %{connectionState} + +=item B<--critical-status> + +Define the conditions to match for the status to be CRITICAL (default: '%{connectionState} !~ /connected/i'). +You can use the following variables: %{simState}, %{pinState}, %{netState}, %{connectionState} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'signal-strength', 'temperature', 'traffic-in', 'traffic-out' +'signal-receive-power', 'signal-receive-quality'. + +=back + +=cut diff --git a/src/network/teltonika/snmp/mode/system.pm b/src/network/teltonika/snmp/mode/system.pm deleted file mode 100644 index 2535b9fbf..000000000 --- a/src/network/teltonika/snmp/mode/system.pm +++ /dev/null @@ -1,202 +0,0 @@ -# -# Copyright 2018 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::teltonika::snmp::mode::system; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -use Digest::MD5 qw(md5_hex); - -sub custom_status_output { - my ($self, %options) = @_; - - my $msg = sprintf("connection state is '%s' [pin state: '%s'] [net state: '%s'][sim state: '%s']", - $self->{result_values}->{connection_state}, - $self->{result_values}->{pin_state}, - $self->{result_values}->{net_state}, - $self->{result_values}->{sim_state}, - ); - return $msg; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 0, skipped_code => { -10 => 1 } }, - ]; - $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'sim_state' }, { name => 'pin_state' }, { name => 'net_state' }, { name => 'connection_state' } ], - closure_custom_calc => \&catalog_status_calc, - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, - } - }, - { label => 'signal-strength', nlabel => 'system.signal.strength.dbm', display_ok => 0, set => { - key_values => [ { name => 'signal' } ], - output_template => 'signal strength: %s Dbm', - perfdatas => [ - { template => '%s', min => 0 , unit => 'Dbm' }, - ] - } - }, - { label => 'temperature', nlabel => 'system.temperature.celsius', display_ok => 0, set => { - key_values => [ { name => 'temperature' } ], - output_template => 'temperature: %s C', - perfdatas => [ - { template => '%s', min => 0 , unit => 'C' }, - ], - } - }, - { label => 'traffic-in', nlabel => 'system.traffic.in.bitspersecond', display_ok => 0, set => { - key_values => [ { name => 'traffic_in', per_second => 1 } ], - output_template => 'traffic in: %s %s/s', - output_change_bytes => 2, - perfdatas => [ - { template => '%s', min => 0, unit => 'b/s' }, - ], - } - }, - { label => 'traffic-out', nlabel => 'system.traffic.out.bitspersecond', display_ok => 0, set => { - key_values => [ { name => 'traffic_out', per_second => 1 } ], - output_template => 'traffic out: %s %s/s', - output_change_bytes => 2, - perfdatas => [ - { template => '%s', min => 0, unit => 'b/s' }, - ], - } - }, - { label => 'signal-receive-power', nlabel => 'system.signal.receive.power.dbm', display_ok => 0, set => { - key_values => [ { name => 'rsrp' } ], - output_template => 'signal receive power: %s Dbm', - perfdatas => [ - { template => '%s', min => 0 , unit => 'Dbm' }, - ], - } - }, - { label => 'signal-receive-quality', nlabel => 'system.signal.receive.quality.dbm', display_ok => 0, set => { - key_values => [ { name => 'rsrq' } ], - output_template => 'signal receive quality: %s Dbm', - perfdatas => [ - { template => '%s', min => 0 , unit => 'Dbm' }, - ], - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); - bless $self, $class; - - $options{options}->add_options(arguments => { - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{connection_state} !~ /connected/i' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -sub manage_selection { - my ($self, %options) = @_; - - my $oid_SimState = '.1.3.6.1.4.1.48690.2.1.0'; - my $oid_PinState = '.1.3.6.1.4.1.48690.2.2.0'; - my $oid_NetState = '.1.3.6.1.4.1.48690.2.3.0'; - my $oid_Signal = '.1.3.6.1.4.1.48690.2.4.0'; - my $oid_ConnectionState = '.1.3.6.1.4.1.48690.2.7.0'; - my $oid_Temperature = '.1.3.6.1.4.1.48690.2.9.0'; - my $oid_Sent = '.1.3.6.1.4.1.48690.2.19.0'; - my $oid_Received = '.1.3.6.1.4.1.48690.2.20.0'; - my $oid_RSRP = '.1.3.6.1.4.1.48690.2.23.0'; - my $oid_RSRQ = '.1.3.6.1.4.1.48690.2.24.0'; - my $result = $options{snmp}->get_leef( - oids => [ - $oid_SimState, $oid_PinState, $oid_NetState, $oid_ConnectionState, - $oid_Signal, $oid_Temperature, $oid_Sent, $oid_Received, - $oid_RSRP, $oid_RSRQ - ], - nothing_quit => 1 - ); - - $self->{cache_name} = "teltonika_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . - (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - - $self->{global} = { - sim_state => defined($result->{$oid_SimState}) ? $result->{$oid_SimState} : '-', - pin_state => defined($result->{$oid_PinState}) ? $result->{$oid_PinState} : '-', - net_state => defined($result->{$oid_NetState}) ? $result->{$oid_NetState} : '-', - connection_state => $result->{$oid_ConnectionState}, - signal => $result->{$oid_Signal}, - temperature => $result->{$oid_Temperature} / 10, - traffic_in => $result->{$oid_Received} * 8, - traffic_out => $result->{$oid_Sent} * 8, - rsrp => $result->{$oid_RSRP}, - rsrq => $result->{$oid_RSRQ}, - }; -} - -1; - -__END__ - -=head1 MODE - -Check system. - -=over 8 - -=item B<--filter-counters> - -Only display some counters (regexp can be used). -Example: --filter-counters='status' - -=item B<--warning-status> - -Define the conditions to match for the status to be WARNING (Default: ''). -You can use the following variables: %{sim_state}, %{pin_state}, %{net_state}, %{connection_state} - -=item B<--critical-status> - -Define the conditions to match for the status to be CRITICAL (Default: '%{connection_state} !~ /connected/i'). -You can use the following variables: %{sim_state}, %{pin_state}, %{net_state}, %{connection_state} - -=item B<--warning-*> B<--critical-*> - -Thresholds. -Can be: 'signal-strength', 'temperature', 'traffic-in', 'traffic-out' -'signal-receive-power', 'signal-receive-quality'. - -=back - -=cut diff --git a/src/network/teltonika/snmp/plugin.pm b/src/network/teltonika/snmp/plugin.pm index 3e5ab94c7..8e71c1237 100644 --- a/src/network/teltonika/snmp/plugin.pm +++ b/src/network/teltonika/snmp/plugin.pm @@ -29,12 +29,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'interfaces' => 'snmp_standard::mode::interfaces', + $self->{modes} = { + 'interfaces' => 'network::teltonika::snmp::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'system' => 'network::teltonika::snmp::mode::system', - ); + 'modem' => 'network::teltonika::snmp::mode::modem' + }; return $self; }