(plugin) cloud::azure::database::postgres - new (#4365)

This commit is contained in:
qgarnier 2023-04-19 13:48:57 +02:00 committed by David Boucher
parent 081ab14b59
commit b1c870c0e8
12 changed files with 1366 additions and 0 deletions

View File

@ -0,0 +1,5 @@
{
"dependencies": [
"libdatetime-perl"
]
}

View File

@ -0,0 +1,10 @@
{
"pkg_name": "centreon-plugin-Cloud-Azure-Database-Postgres-Api",
"pkg_summary": "Centreon Plugin to monitor Microsoft Azure Database for Postgres service using CLI or RestAPI",
"plugin_name": "centreon_azure_database_postgres_api.pl",
"files": [
"centreon/plugins/script_custom.pm",
"cloud/azure/custom/",
"cloud/azure/database/postgres/"
]
}

View File

@ -0,0 +1,6 @@
{
"dependencies": [
"perl(DateTime)",
"perl(Digest::SHA)"
]
}

View File

@ -0,0 +1,175 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::mode::connections;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'active_connections' => {
'output' => 'Active Connections',
'label' => 'connections-active',
'nlabel' => 'azpostgres.connections.active.count',
'unit' => '',
'min' => '0'
},
'connections_failed' => {
'output' => 'Failed Connections',
'label' => 'connections-failed',
'nlabel' => 'azpostgres.connections.failed.count',
'unit' => '',
'min' => '0'
},
'aborted_connections' => {
'output' => 'Aborted Connections',
'label' => 'connections-aborted',
'nlabel' => 'azpostgres.connections.aborted.count',
'unit' => '',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --resource-type option');
$self->{output}->option_exit();
}
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\.DBforPostgreSQL\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.DBforPostgreSQL';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Total'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
my $resource_mapping = {
'servers' => [ 'active_connections', 'connections_failed' ],
'flexibleServers' => [ 'active_connections', 'connections_failed' ]
};
my $metrics_mapping_transformed;
foreach my $metric_type (@{$resource_mapping->{$resource_type}}) {
$metrics_mapping_transformed->{$metric_type} = $self->{metrics_mapping}->{$metric_type};
}
foreach my $metric (keys %{$metrics_mapping_transformed}) {
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
push @{$self->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Database for PostgreSQL connections status.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=connections --custommode=api
--resource=<db_id> --resource-group=<resourcegroup_id> --aggregation='total'
--warning-connections-active='1000' --critical-connections-active='2000'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=connections --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.DBforPostgreSQL/servers/<db_id>'
--aggregation='total' --warning-connections-active='1000' --critical-connections-active='2000'
Default aggregation: 'total' / 'average', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource type (Default: 'servers'). Can be 'servers', 'flexibleServers'.
=item B<--warning-*> B<--critical-*>
Thresholds where '*' can be:
'connections-active', 'connections-failed', 'connections-aborted',
'connections-total'.
=back
=cut

View File

@ -0,0 +1,154 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::mode::cpu;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'cpu_percent' => {
'output' => 'CPU percent',
'label' => 'cpu-usage',
'nlabel' => 'azpostgresql.cpu.utilization.percentage',
'unit' => '%',
'min' => '0',
'max' => '100'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --resource-type option');
$self->{output}->option_exit();
}
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\.DBforPostgreSQL\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.DBforPostgreSQL';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Average'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
foreach my $metric (keys %{$self->{metrics_mapping}}) {
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
push @{$self->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Database for PostgreSQL CPU usage.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=cpu --custommode=api
--resource=<db_id> --resource-group=<resourcegroup_id> --aggregation='average'
--warning-cpu-usage='80' --critical-cpu-usage='90'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=cpu --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.DBforPostgreSQL/servers/<db_id>'
--aggregation='average' --warning-cpu-usage='80' --critical-cpu-usage='90'
Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource type (Default: 'servers'). Can be 'servers', 'flexibleServers'.
=item B<--warning-cpu-usage>
Set warning threshold for CPU utilization percentage.
=item B<--critical-cpu-usage>
Set critical threshold for CPU utilization percentage.
=back
=cut

View File

@ -0,0 +1,145 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::mode::discovery;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use JSON::XS;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'namespace:s' => { name => 'namespace' },
'type:s' => { name => 'type' },
'resource-group:s' => { name => 'resource_group' },
'location:s' => { name => 'location' },
'prettify' => { name => 'prettify' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->{namespace} = $self->{option_results}->{namespace};
$self->{type} = $self->{option_results}->{type};
$self->{location} = $self->{option_results}->{location};
$self->{resource_group} = $self->{option_results}->{resource_group};
}
sub run {
my ($self, %options) = @_;
my @disco_data;
my $disco_stats;
$disco_stats->{start_time} = time();
my $resources = $options{custom}->azure_list_resources(
namespace => $self->{namespace},
resource_type => $self->{type},
location => $self->{location},
resource_group => $self->{resource_group}
);
$disco_stats->{end_time} = time();
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
foreach my $resource (@{$resources}) {
next if ($resource->{type} !~ /Microsoft\.DBforPostgreSQL/);
$resource->{type} =~ s/Microsoft\.DBforPostgreSQL\///;
my $resource_group = '';
$resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup}));
$resource_group = $1 if ($resource_group eq '' && defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/);
$resource->{resourceGroup} = $resource_group;
foreach my $entry (keys %{$resource}) {
next if (ref($resource->{$entry}) ne "HASH");
my @array;
foreach my $key (keys %{$resource->{$entry}}) {
push @array, { key => $key, value => $resource->{$entry}->{$key} };
}
$resource->{$entry} = \@array;
}
push @disco_data, $resource;
}
$disco_stats->{discovered_items} = @disco_data;
$disco_stats->{results} = \@disco_data;
my $encoded_data;
eval {
if (defined($self->{option_results}->{prettify})) {
$encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats);
} else {
$encoded_data = JSON::XS->new->utf8->encode($disco_stats);
}
};
if ($@) {
$encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}';
}
$self->{output}->output_add(short_msg => $encoded_data);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Resources discovery.
=over 8
=item B<--namespace>
Specify resources namespace.
=item B<--type>
Specify resources type.
=item B<--resource-group>
Specify resources resource group.
=item B<--location>
Specify resources location.
=item B<--prettify>
Prettify JSON output.
=back
=cut

View File

@ -0,0 +1,154 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::mode::ioconsumption;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'disk_iops_consumed_percentage' => {
'output' => 'IO Percent',
'label' => 'ioconsumption-usage',
'nlabel' => 'azpostgres.ioconsumption.usage.percentage',
'unit' => '%',
'min' => '0',
'max' => '100'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --resource-type option');
$self->{output}->option_exit();
}
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\.DBforPostgreSQL\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.DBforPostgreSQL';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Maximum'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
foreach my $metric (keys %{$self->{metrics_mapping}}) {
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
push @{$self->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Database for PostgreSQL IO comsuption usage.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=io-consumption --custommode=api
--resource=<db_id> --resource-group=<resourcegroup_id> --aggregation='maximum'
--warning-ioconsumption-usage='80' --critical-ioconsumption-usage='90'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=io-consumption --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.DBforPostgreSQL/servers/<db_id>'
--aggregation='maximum' --warning-ioconsumption-usage='80' --critical-ioconsumption-usage='90'
Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource type (Default: 'servers'). Can be 'servers', 'flexibleServers'.
=item B<--warning-ioconsumption-usage>
Set warning threshold for IO comsuption usage.
=item B<--critical-ioconsumption-usage>
Set critical threshold for IO comsuption usage.
=back
=cut

View File

@ -0,0 +1,154 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::mode::memory;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'memory_percent' => {
'output' => 'Memory percent',
'label' => 'memory-usage',
'nlabel' => 'azpostgres.memory.usage.percentage',
'unit' => '%',
'min' => '0',
'max' => '100'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --resource-type option');
$self->{output}->option_exit();
}
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\.DBforPostgreSQL\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.DBforPostgreSQL';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Average'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
foreach my $metric (keys %{$self->{metrics_mapping}}) {
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
push @{$self->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Database for PostgreSQL memory usage.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=memory --custommode=api
--resource=<db_id> --resource-group=<resourcegroup_id> --aggregation='average'
--warning-memory-usage='80' --critical-memory-usage='90'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=memory --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.DBforPostgreSQL/servers/<db_id>'
--aggregation='average' --warning-memory-usage='80' --critical-memory-usage='90'
Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource type (Default: 'servers'). Can be 'servers', 'flexibleServers'.
=item B<--warning-memory-usage>
Set warning threshold for memory utilization percentage.
=item B<--critical-memory-usage>
Set critical threshold for memory utilization percentage.
=back
=cut

View File

@ -0,0 +1,160 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::mode::replication;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'physical_replication_delay_in_seconds' => {
'output' => 'Replication Lag In Seconds',
'label' => 'replication-lag',
'nlabel' => 'azpostgres.replication.lag.seconds',
'unit' => 's',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --resource-type option');
$self->{output}->option_exit();
}
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\.DBforPostgreSQL\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.DBforPostgreSQL';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Maximum'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
my $resource_mapping = {
'servers' => [ 'physical_replication_delay_in_seconds' ],
'flexibleServers' => [ 'physical_replication_delay_in_seconds' ]
};
my $metrics_mapping_transformed;
foreach my $metric_type (@{$resource_mapping->{$resource_type}}) {
$metrics_mapping_transformed->{$metric_type} = $self->{metrics_mapping}->{$metric_type};
}
foreach my $metric (keys %{$metrics_mapping_transformed}) {
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
push @{$self->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Database for PostgreSQL replication status.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=connections --custommode=api
--resource=<db_id> --resource-group=<resourcegroup_id> --aggregation='maximum'
--warning-replication-lag='1000' --critical-replication-lag='2000'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=connections --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.DBforPostgreSQL/servers/<db_id>'
--aggregation='maximum' --warning-replication-lag='1000' --critical-replication-lag='2000'
Default aggregation: 'maximum' / 'average', 'minimum' and 'total' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource type (Default: 'servers'). Can be 'servers', 'flexibleServers'.
=item B<--warning-*> B<--critical-*>
Thresholds where '*' can be:
'replication-lag'.
=back
=cut

View File

@ -0,0 +1,181 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::mode::storage;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'backup_storage_used' => {
'output' => 'Backup Storage used',
'label' => 'storage-backup',
'nlabel' => 'azpostgres.storage.backup.usage.bytes',
'unit' => 'B',
'min' => '0'
},
'txlogs_storage_used' => {
'output' => 'Server Log storage used',
'label' => 'serverlog-usage',
'nlabel' => 'azpostgres.storage.serverlog.usage.bytes',
'unit' => 'B',
'min' => '0'
},
'storage_percent' => {
'output' => 'Storage Percent',
'label' => 'storage-percent',
'nlabel' => 'azpostgres.storage.usage.percentage',
'unit' => '%',
'min' => '0'
},
'storage_used' => {
'output' => 'Storage Used',
'label' => 'storage-used',
'nlabel' => 'azpostgres.storage.usage.bytes',
'unit' => 'B',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --resource-type option');
$self->{output}->option_exit();
}
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\.DBforPostgreSQL\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.DBforPostgreSQL';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT15M';
$self->{az_aggregations} = ['Maximum'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
my $resource_mapping = {
'servers' => [ 'backup_storage_used', 'txlogs_storage_used', 'storage_percent', 'storage_used' ],
'flexibleServers' => [ 'backup_storage_used', 'txlogs_storage_used', 'storage_percent', 'storage_used' ]
};
my $metrics_mapping_transformed;
foreach my $metric_type (@{$resource_mapping->{$resource_type}}) {
$metrics_mapping_transformed->{$metric_type} = $self->{metrics_mapping}->{$metric_type};
}
foreach my $metric (keys %{$metrics_mapping_transformed}) {
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
push @{$self->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Database for PostgreSQL storage usage.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=storage --custommode=api
--resource=<db_id> --resource-group=<resourcegroup_id> --aggregation='maximum'
--warning-storage-used='1000' --critical-storage-used='2000'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=storage --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.DBforPostgreSQL/servers/<db_id>'
--aggregation='maximum' --warning-storage-used='1000' --critical-storage-used='2000'
Default aggregation: 'maximum' / 'average', 'minimum' and 'total' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource type (Default: 'servers'). Can be 'servers', 'flexibleServers'.
=item B<--warning-*> B<--critical-*>
Thresholds where '*' can be:
'storage-backup', 'serverlog-usage', 'storage-percent', 'storage-used'.
=back
=cut

View File

@ -0,0 +1,156 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::mode::traffic;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'network_bytes_egress' => {
'output' => 'Network Out',
'label' => 'traffic-out',
'nlabel' => 'azpostgres.traffic.out.bytes',
'unit' => 'B',
'min' => '0'
},
'network_bytes_ingress' => {
'output' => 'Network In',
'label' => 'traffic-in',
'nlabel' => 'azpostgres.traffic.in.bytes',
'unit' => 'B',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --resource-type option');
$self->{output}->option_exit();
}
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\.DBforPostgreSQL\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.DBforPostgreSQL';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Average'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
foreach my $metric (keys %{$self->{metrics_mapping}}) {
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
push @{$self->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Database for PostgreSQL network usage.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=traffic --custommode=api
--resource=<db_id> --resource-group=<resourcegroup_id> --aggregation='average'
--warning-traffic-out='80' --critical-traffic-out='90'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::database::postgres::plugin --mode=traffic --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.DBforPostgreSQL/servers/<db_id>'
--aggregation='average' --warning-traffic-out='80' --critical-traffic-out='90'
Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource type (Default: 'servers'). Can be 'servers', 'flexibleServers'.
=item B<--warning-*> B<--critical-*>
Thresholds where '*' can be: 'traffic-out', 'traffic-in'.
=back
=cut

View File

@ -0,0 +1,66 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::database::postgres::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new( package => __PACKAGE__, %options );
bless $self, $class;
$self->{modes} = {
'connections' => 'cloud::azure::database::postgres::mode::connections',
'cpu' => 'cloud::azure::database::postgres::mode::cpu',
'discovery' => 'cloud::azure::database::postgres::mode::discovery',
'io-consumption' => 'cloud::azure::database::postgres::mode::ioconsumption',
'memory' => 'cloud::azure::database::postgres::mode::memory',
'replication' => 'cloud::azure::database::postgres::mode::replication',
'storage' => 'cloud::azure::database::postgres::mode::storage',
'traffic' => 'cloud::azure::database::postgres::mode::traffic'
};
$self->{custom_modes}->{azcli} = 'cloud::azure::custom::azcli';
$self->{custom_modes}->{api} = 'cloud::azure::custom::api';
return $self;
}
sub init {
my ($self, %options) = @_;
$self->{options}->add_options(arguments => {
'api-version:s' => { name => 'api_version', default => '2018-01-01' }
});
$self->SUPER::init(%options);
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Microsoft Azure Database for PostgreSQL resources.
=cut