diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/connections.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/connections.pm new file mode 100644 index 000000000..1b1ee8dab --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/connections.pm @@ -0,0 +1,161 @@ +# +# 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::mariadb::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' => 'azmariadb.connections.active.count', + 'unit' => '', + 'min' => '0' + }, + 'connections_failed' => { + 'output' => 'Failed Connections', + 'label' => 'connections-failed', + 'nlabel' => 'azmariadb.connections.failed.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' }, + }); + + 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 with --resource-group option or --resource .'); + $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\.DBforMariaDB\/(.*)\/(.*)$/) { + $resource_group = $1; + $resource_type = 'servers'; + $resource = $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'servers'; + $self->{az_resource_namespace} = 'Microsoft.DBforMariaDB'; + $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' ], + }; + + 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 MariaDB connections status. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=connections --custommode=api +--resource= --resource-group= --aggregation='total' +--warning-connections-active='1000' --critical-connections-active='2000' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=connections --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.DBforMariaDB/servers/' +--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<--warning-*> + +Warning threshold where '*' can be: +'connections-active', 'connections-failed'. + +=item B<--critical-*> + +Critical threshold where '*' can be: +'connections-active', 'connections-failed'. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/cpu.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/cpu.pm new file mode 100644 index 000000000..5731553d5 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/cpu.pm @@ -0,0 +1,144 @@ +# +# 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::mariadb::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' => 'azmariadb.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' }, + }); + + 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 with --resource-group option or --resource .'); + $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\.DBforMariaDB\/(.*)\/(.*)$/) { + $resource_group = $1; + $resource_type = 'servers'; + $resource = $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = $resource_type; + $self->{az_resource_namespace} = 'Microsoft.DBforMariaDB'; + $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 MariaDB CPU usage. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=cpu --custommode=api +--resource= --resource-group= --aggregation='average' +--warning-cpu-usage='80' --critical-cpu-usage='90' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=cpu --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.DBforMariaDB/servers/' +--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<--warning-cpu-usage> + +Set warning threshold for CPU utilization percentage. + +=item B<--critical-cpu-usage> + +Set critical threshold for CPU utilization percentage. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/discovery.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/discovery.pm new file mode 100644 index 000000000..23f7872fe --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/discovery.pm @@ -0,0 +1,56 @@ +# +# 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::mariadb::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.DBforMariaDB'; + $self->{type} = 'servers'; +} + +1; + +__END__ + +=head1 MODE + +Azure MariaDB Resources discovery. + +=over 8 + +=item B<--location> + +Specify resources location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/ioconsumption.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/ioconsumption.pm new file mode 100644 index 000000000..f9e46e5a3 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/ioconsumption.pm @@ -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::mariadb::mode::ioconsumption; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'io_consumption_percent' => { + 'output' => 'IO Percent', + 'label' => 'ioconsumption-usage', + 'nlabel' => 'azmariadb.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' }, + }); + + 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 with --resource-group option or --resource .'); + $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\.DBforMariaDB\/(.*)\/(.*)$/) { + $resource_group = $1; + $resource_type = 'servers'; + $resource = $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = $resource_type; + $self->{az_resource_namespace} = 'Microsoft.DBforMariaDB'; + $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 MariaDB IO comsuption usage. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=io-consumption --custommode=api +--resource= --resource-group= --aggregation='maximum' +--warning-ioconsumption-usage='80' --critical-ioconsumption-usage='90' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=io-consumption --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.DBforMariaDB/servers/' +--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<--warning-ioconsumption-usage> + +Set warning threshold for IO comsuption usage. + + +=item B<--critical-ioconsumption-usage> + +Set critical threshold for IO comsuption usage. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/memory.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/memory.pm new file mode 100644 index 000000000..d87d45322 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/memory.pm @@ -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::mariadb::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' => 'azmariadb.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' }, + }); + + 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 with --resource-group option or --resource .'); + $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\.DBforMariaDB\/(.*)\/(.*)$/) { + $resource_group = $1; + $resource_type = 'servers'; + $resource = $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = $resource_type; + $self->{az_resource_namespace} = 'Microsoft.DBforMariaDB'; + $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 MariaDB memory usage. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=memory --custommode=api +--resource= --resource-group= --aggregation='average' +--warning-memory-usage='80' --critical-memory-usage='90' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=memory --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.DBforMariaDB/servers/' +--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<--warning-memory-usage> + +Set warning threshold for memory utilization percentage. + + +=item B<--critical-memory-usage> + +Set critical threshold for memory utilization percentage. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/queries.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/queries.pm new file mode 100644 index 000000000..548b78095 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/queries.pm @@ -0,0 +1,141 @@ +# +# 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::mariadb::mode::queries; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'queries' => { + 'output' => 'Queries', + 'label' => 'queries', + 'nlabel' => 'azmariadb.queries.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' }, + }); + + 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 with --resource-group option or --resource .'); + $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\.DBforMariaDB\/flexibleServers\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'flexibleServers'; + $self->{az_resource_namespace} = 'Microsoft.DBforMariaDB'; + $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)); + } + } + } + + 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 MariaDB network usage. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=queries --custommode=api +--resource= --resource-group= --aggregation='total' +--warning-queries='80' --critical-queries='90' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::integration::servicebus::plugin --mode=queries --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.DBforMariaDB/servers/' +--aggregation='total' --warning-queries='80' --critical-queries='90' + +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<--warning-queries> + +Set warning threshold for queries count. + +=item B<--critical-queries> + +Set critical threshold for queries count. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/replication.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/replication.pm new file mode 100644 index 000000000..9313dcc39 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/replication.pm @@ -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::mariadb::mode::replication; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'seconds_behind_master' => { + 'output' => 'Seconds behind master', + 'label' => 'slave-latency-seconds', + 'nlabel' => 'azmariadb.slave.latency.seconds', + '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' }, + }); + + 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 with --resource-group option or --resource .'); + $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\.DBforMariaDB\/(.*)\/(.*)$/) { + $resource_group = $1; + $resource_type = 'servers'; + $resource = $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = $resource_type; + $self->{az_resource_namespace} = 'Microsoft.DBforMariaDB'; + $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' => [ 'seconds_behind_master' ], + }; + + 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 MariaDB replication status. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=connections --custommode=api +--resource= --resource-group= --aggregation='maximum' +--warning-replication-lag='1000' --critical-replication-lag='2000' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=connections --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.DBforMariaDB/servers/' +--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<--warning-*> + +Warning threshold where '*' can be: +'replication-lag-count'. + +=item B<--critical-*> + +Critical threshold where '*' can be: +'replication-lag-count'. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/storage.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/storage.pm new file mode 100644 index 000000000..00b3ef9c1 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/storage.pm @@ -0,0 +1,200 @@ +# +# 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::mariadb::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' => 'azmariadb.storage.backup.usage.bytes', + 'unit' => 'B', + 'min' => '0' + }, + 'serverlog_storage_limit' => { + 'output' => 'Server Log storage limit', + 'label' => 'serverlog-limit', + 'nlabel' => 'azmariadb.storage.serverlog.limit.bytes', + 'unit' => 'B', + 'min' => '0' + }, + 'serverlog_storage_percent' => { + 'output' => 'Server Log storage percent', + 'label' => 'serverlog-percent', + 'nlabel' => 'azmariadb.storage.serverlog.usage.percentage', + 'unit' => '%', + 'min' => '0' + }, + 'serverlog_storage_usage' => { + 'output' => 'Server Log storage used', + 'label' => 'servelog-usage', + 'nlabel' => 'azmariadb.storage.serverlog.usage.bytes', + 'unit' => 'B', + 'min' => '0' + }, + 'storage_limit' => { + 'output' => 'Storage Limit', + 'label' => 'storage-limit', + 'nlabel' => 'azmariadb.storage.limit.bytes', + 'unit' => 'B', + 'min' => '0' + }, + 'storage_percent' => { + 'output' => 'Storage Percent', + 'label' => 'storage-percent', + 'nlabel' => 'azmariadb.storage.usage.percentage', + 'unit' => '%', + 'min' => '0' + }, + 'storage_used' => { + 'output' => 'Storage Used', + 'label' => 'storage-used', + 'nlabel' => 'azmariadb.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' }, + }); + + 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 with --resource-group option or --resource .'); + $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\.DBforMariaDB\/(.*)\/(.*)$/) { + $resource_group = $1; + $resource_type = 'servers'; + $resource = $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = $resource_type; + $self->{az_resource_namespace} = 'Microsoft.DBforMariaDB'; + $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', 'serverlog_storage_limit', 'serverlog_storage_percent', + 'serverlog_storage_usage', 'storage_limit', '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 MariaDB storage usage. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=storage --custommode=api +--resource= --resource-group= --aggregation='maximum' +--warning-storage-used='1000' --critical-storage-used='2000' + +Using resource id : + +perl centreon-plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=storage --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.DBforMariaDB/servers/' +--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<--warning-*> + +Warning threshold where '*' can be: +'storage-backup', 'serverlog-limit', 'serverlog-percent', 'servelog-usage', +'storage-limit', 'storage-percent', 'storage-used'. + +=item B<--critical-*> + +Critical threshold where '*' can be: +'storage-backup', 'serverlog-limit', 'serverlog-percent', 'servelog-usage', +'storage-limit', 'storage-percent', 'storage-used'. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/mode/traffic.pm b/centreon-plugins/cloud/azure/database/mariadb/mode/traffic.pm new file mode 100644 index 000000000..381e5e4ca --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/mode/traffic.pm @@ -0,0 +1,151 @@ +# +# 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::mariadb::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' => 'azmariadb.traffic.out.bytes', + 'unit' => 'B', + 'min' => '0', + }, + 'network_bytes_ingress' => { + 'output' => 'Network In', + 'label' => 'traffic-in', + 'nlabel' => 'azmariadb.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' }, + }); + + 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 with --resource-group option or --resource .'); + $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\.DBforMariaDB\/(.*)\/(.*)$/) { + $resource_group = $1; + $resource_type = 'servers'; + $resource = $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = $resource_type; + $self->{az_resource_namespace} = 'Microsoft.DBforMariaDB'; + $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 MariaDB network usage. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=traffic --custommode=api +--resource= --resource-group= --aggregation='average' +--warning-traffic-out='80' --critical-traffic-out='90' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::mariadb::plugin --mode=traffic --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.DBforMariaDB/servers/' +--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<--warning-*> + +Warning threshold where '*' can be: 'traffic-out', 'traffic-in'. + + +=item B<--critical-*> + +Critical threshold where '*' can be: 'traffic-out', 'traffic-in'. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/mariadb/plugin.pm b/centreon-plugins/cloud/azure/database/mariadb/plugin.pm new file mode 100644 index 000000000..a3a49cb85 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/mariadb/plugin.pm @@ -0,0 +1,67 @@ +# +# 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::mariadb::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->{version} = '0.1'; + $self->{modes} = { + 'connections' => 'cloud::azure::database::mariadb::mode::connections', + 'cpu' => 'cloud::azure::database::mariadb::mode::cpu', + 'discovery' => 'cloud::azure::database::mariadb::mode::discovery', + 'io-consumption' => 'cloud::azure::database::mariadb::mode::ioconsumption', + 'memory' => 'cloud::azure::database::mariadb::mode::memory', + 'replication' => 'cloud::azure::database::mariadb::mode::replication', + 'storage' => 'cloud::azure::database::mariadb::mode::storage', + 'traffic' => 'cloud::azure::database::mariadb::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 MariaDB resources. + +=cut