From ada1b33ee0d0932970e054902323d7419f252e7b Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Thu, 6 Jan 2022 08:52:33 +0100 Subject: [PATCH] (plugin) cloud::azure::sqldatabase/sqlserver - refactoring, discovery, new modes (#3378) --- .../database/sqldatabase/mode/appresources.pm | 159 ++++++++++++++ .../database/sqldatabase/mode/connections.pm | 165 ++++++++++++++ .../database/sqldatabase/mode/databasesize.pm | 202 ------------------ .../sqldatabase/mode/databasestatus.pm | 165 -------------- .../database/sqldatabase/mode/deadlocks.pm | 150 +++++++++++++ .../database/sqldatabase/mode/discovery.pm | 60 ++++++ .../azure/database/sqldatabase/mode/health.pm | 81 +++++++ .../database/sqldatabase/mode/sessions.pm | 150 +++++++++++++ .../database/sqldatabase/mode/storage.pm | 159 ++++++++++++++ .../database/sqldatabase/mode/workers.pm | 150 +++++++++++++ .../azure/database/sqldatabase/plugin.pm | 19 +- .../azure/database/sqlserver/mode/health.pm | 81 +++++++ .../database/sqlserver/mode/serverstatus.pm | 158 -------------- .../cloud/azure/database/sqlserver/plugin.pm | 10 +- 14 files changed, 1172 insertions(+), 537 deletions(-) create mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/appresources.pm create mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/connections.pm delete mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/databasesize.pm delete mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/databasestatus.pm create mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/deadlocks.pm create mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/discovery.pm create mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/health.pm create mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/sessions.pm create mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/storage.pm create mode 100644 centreon-plugins/cloud/azure/database/sqldatabase/mode/workers.pm create mode 100644 centreon-plugins/cloud/azure/database/sqlserver/mode/health.pm delete mode 100644 centreon-plugins/cloud/azure/database/sqlserver/mode/serverstatus.pm diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/appresources.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/appresources.pm new file mode 100644 index 000000000..81bc87ae4 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/appresources.pm @@ -0,0 +1,159 @@ +# +# 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::sqldatabase::mode::appresources; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'app_cpu_percent' => { + 'output' => 'App CPU percent ', + 'label' => 'app-cpu', + 'nlabel' => 'sqldatabase.serverless.app.cpu.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '' + }, + 'app_memory_percent' => { + 'output' => 'App Memory percent', + 'label' => 'app-memory', + 'nlabel' => 'sqldatabase.serverless.app.memory.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '' + } + }; + + 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' }, + 'server:s' => { name => 'server' } + }); + 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 and --server option OR --resource .'); + $self->{output}->option_exit(); + } + + + my $resource = $self->{option_results}->{resource}; + my $server = $self->{option_results}->{server}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Sql\/servers\/(.*)\/databases\/(.*)$/) { + $resource_group = $1; + $resource = $2 . '/databases/' . $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'servers'; + $self->{az_resource_namespace} = 'Microsoft.Sql'; + $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 SQL Database app resource consumption (Serverless DB only). + +Metrics are only available for: +- vCore based model - General purpose + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=app-resources --custommode=api +--resource= --resource-group= --server= --aggregation='average' +--critical-app-cpu='80'' --critical-app-memory='90' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=app-resources --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases/' +--aggregation='average' --critical-app-cpu='80'' --critical-app-memory='90' + +Default aggregation: 'average', other are not identified as relevant nor available by Microsoft. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). It is the database name. + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--server> + +Set server name (Required if resource's name is used). + +=item B<--warning-*> + +Warning threshold where '*' can be: 'app-cpu', 'app-memory'. + +=item B<--critical-*> + +Critical threshold where '*' can be: 'app-cpu', 'app-memory'. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/connections.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/connections.pm new file mode 100644 index 000000000..75eede740 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/connections.pm @@ -0,0 +1,165 @@ +# +# 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::sqldatabase::mode::connections; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'blocked_by_firewall' => { + 'output' => 'Blocked by firewall ', + 'label' => 'connection-blocked', + 'nlabel' => 'sqldatabase.connection.blocked.count', + 'min' => '0', + 'max' => '' + }, + 'connection_failed' => { + 'output' => 'Connection failed ', + 'label' => 'connection-failed', + 'nlabel' => 'sqldatabase.connection.failed.count', + 'min' => '0', + 'max' => '' + }, + 'connection_successful' => { + 'output' => 'Connection successful ', + 'label' => 'connection-successful', + 'nlabel' => 'sqldatabase.connection.successful.count', + 'min' => '0', + 'max' => '' + } + }; + + 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' }, + 'server:s' => { name => 'server' } + }); + 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 and --server option OR --resource .'); + $self->{output}->option_exit(); + } + my $resource = $self->{option_results}->{resource}; + my $server = $self->{option_results}->{server}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Sql\/servers\/(.*)\/databases\/(.*)$/) { + $resource_group = $1; + $server = $2; + $resource = $2 . '/databases/' . $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'servers'; + $self->{az_resource_namespace} = 'Microsoft.Sql'; + $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 connections to Azure SQL database. + +Metrics are available with: +- Tier 'DTU based' - Basic, Standard, Premium +- vCore based model - General purpose & Business critical +- HyperScale + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=connections --custommode=api +--resource= --resource-group= --server= --aggregation='total' +--warning-connection-failed='10'' --critical-connection-failed='30' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=connections --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases/' +--aggregation='total' --warning-connection-failed='10'' --critical-connection-failed='30' + +Default aggregation: 'maximum', other are not identified as relevant nor available by Microsoft. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). It is the database name. + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--server> + +Set server name (Required if resource's name is used). + +=item B<--warning-*> + +Warning threshold where '*' can be: 'connection-failed', 'connection-successful'. + +=item B<--critical-*> + +Critical threshold where '*' can be: 'connection-failed', 'connection-successful'. + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasesize.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasesize.pm deleted file mode 100644 index 377f0ea32..000000000 --- a/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasesize.pm +++ /dev/null @@ -1,202 +0,0 @@ -# -# 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::sqldatabase::mode::databasesize; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub prefix_metric_output { - my ($self, %options) = @_; - - return "Database '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All usage metrics are ok", skipped_code => { -10 => 1 } }, - ]; - - foreach my $aggregation ('minimum', 'maximum', 'average') { - foreach my $metric ('storage_percent') { - my $metric_perf = lc($metric); - my $metric_label = lc($metric); - $metric_perf =~ s/ /_/g; - $metric_label =~ s/[ |_]/-/g; - my $entry = { label => $metric_label . '-' . $aggregation, set => { - key_values => [ { name => $metric_perf . '_' . $aggregation }, { name => 'display' }, { name => 'stat' } ], - output_template => 'Database size percentage: %.2f %%', - perfdatas => [ - { label => $metric_perf . '_' . $aggregation, value => $metric_perf . '_' . $aggregation , - template => '%.2f', unit => '%', label_extra_instance => 1, instance_use => 'display', - min => 0, max => 100 }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - } -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - if (!defined($self->{option_results}->{resource})) { - $self->{output}->add_option_msg(short_msg => "Need to specify either --resource with --resource-group option or --resource ."); - $self->{output}->option_exit(); - } - - $self->{az_resource} = $self->{option_results}->{resource}; - $self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group})); - $self->{az_resource_type} = 'servers'; - $self->{az_resource_namespace} = 'Microsoft.Sql'; - $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 ('storage_percent') { - 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; - } -} - -sub manage_selection { - my ($self, %options) = @_; - - my %metric_results; - foreach my $resource (@{$self->{az_resource}}) { - my $resource_group = $self->{az_resource_group}; - my $resource_name = $resource; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Sql\/servers\/(.*)\/databases\/(.*)$/) { - $resource_group = $1; - $resource_name = $2 . '/databases/' . $3; - } - - ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name, - resource_group => $resource_group, - resource_type => $self->{az_resource_type}, - resource_namespace => $self->{az_resource_namespace}, - metrics => $self->{az_metrics}, - aggregations => $self->{az_aggregations}, - timeframe => $self->{az_timeframe}, - interval => $self->{az_interval}, - ); - - foreach my $metric (@{$self->{az_metrics}}) { - my $metric_name = lc($metric); - $metric_name =~ s/ /_/g; - foreach my $aggregation (@{$self->{az_aggregations}}) { - next if (!defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); - - $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{display} = $resource_name; - $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{stat} = lc($aggregation); - $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_name . "_" . lc($aggregation)} = defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) ? $metric_results{$resource_name}->{$metric_name}->{lc($aggregation)} : 0; - } - } - } - - if (scalar(keys %{$self->{metric}}) <= 0) { - $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check databases usage metrics. - -Example: - -Using resource name : - -perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --custommode=azcli --mode=database-size ---resource=MYDATABASE --resource-group=MYHOSTGROUP --aggregation='maximum' ---critical-storage-percent-maximum='รง0' --verbose - -Using resource id : - -perl centreon_plugins.pl --plugin=cloud::azure::compute::virtualmachine::plugin --custommode=azcli --mode=cpu ---resource='/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Sql/servers/xxx/databases/xxx' ---aggregation='maximum' --critical-storage-percent-maximum='90' --verbose - -Default aggregation: 'maximum' / '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<--filter-metric> - -Filter metrics (Can be: 'storage_percent') (Can be a regexp). - -=item B<--warning-$metric$-$aggregation$> - -Thresholds warning ($metric$ can be: 'storage-percent', -$aggregation$ can be: 'minimum', 'maximum', 'average'). - -=item B<--critical-$metric$-$aggregation$> - -Thresholds critical ($metric$ can be: 'storage-percent', -$aggregation$ can be: 'minimum', 'maximum', 'average'). - -=back - -=cut diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasestatus.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasestatus.pm deleted file mode 100644 index bf9b28eb2..000000000 --- a/centreon-plugins/cloud/azure/database/sqldatabase/mode/databasestatus.pm +++ /dev/null @@ -1,165 +0,0 @@ -# -# 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::sqldatabase::mode::databasestatus; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); - -sub custom_status_output { - my ($self, %options) = @_; - - my $msg = sprintf("Status '%s'", - $self->{result_values}->{status}); - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - return 0; -} - -sub prefix_database_output { - my ($self, %options) = @_; - - return "Database '" . $options{instance_value}->{display} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'databases', type => 1, cb_prefix_output => 'prefix_database_output', message_multiple => 'All databases are ok' }, - ]; - - $self->{maps_counters}->{databases} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'status' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "resource-group:s" => { name => 'resource_group' }, - "server:s" => { name => 'server' }, - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} ne "Online"' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - if (!defined($self->{option_results}->{resource_group}) || $self->{option_results}->{resource_group} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --resource-group option"); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{server}) || $self->{option_results}->{server} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --server option"); - $self->{output}->option_exit(); - } - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -sub manage_selection { - my ($self, %options) = @_; - - $self->{databases} = {}; - my $databases = $options{custom}->azure_list_sqldatabases( - resource_group => $self->{option_results}->{resource_group}, - server => $self->{option_results}->{server} - ); - foreach my $database (@{$databases}) { - next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' - && $database->{name} !~ /$self->{option_results}->{filter_name}/); - - $self->{databases}->{$database->{id}} = { - display => $database->{name}, - status => ($database->{status}) ? $database->{status} : $database->{properties}->{status}, - }; - } - - if (scalar(keys %{$self->{databases}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No SQL databases found."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check SQL databases status. - -Example: -perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --custommode=azcli --mode=database-status ---resource-group='MYRESOURCEGROUP' --server='MyServer' --verbose - -=over 8 - -=item B<--resource-group> - -Set resource group (Required). - -=item B<--server> - -Set SQL server (Required). - -=item B<--filter-name> - -Filter database name (Can be a regexp). - -=item B<--warning-status> - -Set warning threshold for status (Default: ''). -Can used special variables like: %{status}, %{display} - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{status} ne "Online"'). -Can used special variables like: %{status}, %{display} - -=back - -=cut diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/deadlocks.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/deadlocks.pm new file mode 100644 index 000000000..cd357a7f9 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/deadlocks.pm @@ -0,0 +1,150 @@ +# +# 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::sqldatabase::mode::deadlocks; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'deadlocks' => { + 'output' => 'Deadlocks ', + 'label' => 'deadlocks', + 'nlabel' => 'sqldatabase.deadlocks.count', + 'min' => '0', + 'max' => '' + } + }; + + 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' }, + 'server:s' => { name => 'server' } + }); + 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 and --server option OR --resource .'); + $self->{output}->option_exit(); + } + my $resource = $self->{option_results}->{resource}; + my $server = $self->{option_results}->{server}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Sql\/servers\/(.*)\/databases\/(.*)$/) { + $resource_group = $1; + $server = $2; + $resource = $2 . '/databases/' . $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'servers'; + $self->{az_resource_namespace} = 'Microsoft.Sql'; + $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 deadlocks happening on Azure SQL Databases. +Metrics are available with: +- Tier 'DTU based' - Basic, Standard, Premium +- vCore based model - General purpose & Business critical +- HyperScale + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=deadlocks --custommode=api +--resource= --resource-group= --server= --aggregation='total' +--critical-deadlock='0' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=deadlocks --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases/' +--aggregation='total' --critical-deadlock='0' + +Default aggregation: 'total', other are not identified as relevant nor available by Microsoft. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). It is the database name. + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--server> + +Set server name (Required if resource's name is used). + +=item B<--warning-deadlocks> + +Warning threshold. + +=item B<--critical-deadlocks> + +Critical threshold. + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/discovery.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/discovery.pm new file mode 100644 index 000000000..ca00ee976 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# 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::sqldatabase::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.Sql'; + $self->{type} = 'servers/databases'; +} + +1; + +__END__ + +=head1 MODE + +SQL Databases discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/health.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/health.pm new file mode 100644 index 000000000..be30acf42 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/health.pm @@ -0,0 +1,81 @@ +# +# 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::sqldatabase::mode::health; + +use base qw(cloud::azure::management::monitor::mode::health); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Sql'; + $self->{type} = 'servers/databases'; +} + +1; + +__END__ + +=head1 MODE + +Check SQL Database health status. +(Useful to determine host status) + +=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-status> + +Set warning threshold for status (Default: ''). + +Can used special variables like: %{status}, %{summary} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /^Unavailable$/'). + +Can used special variables like: %{status}, %{summary} + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{status} =~ /^Unknown$/'). + +Can used special variables like: %{status}, %{summary} + +=item B<--ok-status> + +Set ok threshold for status (Default: '%{status} =~ /^Available$/'). + +Can used special variables like: %{status}, %{summary} + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/sessions.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/sessions.pm new file mode 100644 index 000000000..4df6743d8 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/sessions.pm @@ -0,0 +1,150 @@ +# +# 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::sqldatabase::mode::sessions; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'sessions_percent' => { + 'output' => 'Sessions ', + 'label' => 'sessions', + 'nlabel' => 'sqldatabase.sessions.count', + 'min' => '0', + 'max' => '' + } + }; + + 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' }, + 'server:s' => { name => 'server' } + }); + 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 and --server option OR --resource .'); + $self->{output}->option_exit(); + } + my $resource = $self->{option_results}->{resource}; + my $server = $self->{option_results}->{server}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Sql\/servers\/(.*)\/databases\/(.*)$/) { + $resource_group = $1; + $server = $2; + $resource = $2 . '/databases/' . $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'servers'; + $self->{az_resource_namespace} = 'Microsoft.Sql'; + $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 opened session on Azure SQL Database. +Metrics are available with: +- Tier 'DTU based' - Basic, Standard, Premium +- vCore based model - General purpose & Business critical +- HyperScale + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=sessions --custommode=api +--resource= --resource-group= --server= --aggregation='total' +--critical-sessions='100' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=sessions --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases/' +--aggregation='total' --critical-sessions='100' + +Default aggregation: 'average', other are not identified as relevant nor available by Microsoft. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). It is the database name. + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--server> + +Set server name (Required if resource's name is used). + +=item B<--warning-sessions> + +Warning threshold. + +=item B<--critical-sessions> + +Critical threshold. + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/storage.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/storage.pm new file mode 100644 index 000000000..810630af1 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/storage.pm @@ -0,0 +1,159 @@ +# +# 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::sqldatabase::mode::storage; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'storage' => { + 'output' => 'Storage used ', + 'label' => 'usage-bytes', + 'nlabel' => 'sqldatabase.storage.space.usage.bytes', + 'unit' => 'B', + 'min' => '0', + 'max' => '' + }, + 'storage_percent' => { + 'output' => 'Storage used percent', + 'label' => 'usage-percent', + 'nlabel' => 'sqldatabase.storage.space.usage.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '' + } + }; + + 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' }, + 'server:s' => { name => 'server' } + }); + 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 and --server option OR --resource .'); + $self->{output}->option_exit(); + } + my $resource = $self->{option_results}->{resource}; + my $server = $self->{option_results}->{server}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Sql\/servers\/(.*)\/databases\/(.*)$/) { + $resource_group = $1; + $server = $2; + $resource = $2 . '/databases/' . $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'servers'; + $self->{az_resource_namespace} = 'Microsoft.Sql'; + $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 SQL Database storage. +Metrics are available with: +- Tier 'DTU based' - Basic, Standard, Premium +- vCore based model - General purpose & Business critical +- HyperScale + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=storage --custommode=api +--resource= --resource-group= --server= --aggregation='maximum' +--warning-usage-percent='80'' --critical-usage-percent='90' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=storage --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases/' +--aggregation='maximum' --warning-usage-percent='80'' --critical-usage-percent='90' + +Default aggregation: 'maximum', other are not identified as relevant nor available by Microsoft. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). It is the database name. + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--server> + +Set server name (Required if resource's name is used). + +=item B<--warning-*> + +Warning threshold where '*' can be: 'usage-bytes','usage-percent'. + +=item B<--critical-*> + +Critical threshold where '*' can be: 'usage-bytes','usage-percent'. + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/mode/workers.pm b/centreon-plugins/cloud/azure/database/sqldatabase/mode/workers.pm new file mode 100644 index 000000000..85ad01b4e --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqldatabase/mode/workers.pm @@ -0,0 +1,150 @@ +# +# 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::sqldatabase::mode::workers; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'sessions_percent' => { + 'output' => 'Workers ', + 'label' => 'workers', + 'nlabel' => 'sqldatabase.workers.count', + 'min' => '0', + 'max' => '' + } + }; + + 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' }, + 'server:s' => { name => 'server' } + }); + 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 and --server option OR --resource .'); + $self->{output}->option_exit(); + } + my $resource = $self->{option_results}->{resource}; + my $server = $self->{option_results}->{server}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Sql\/servers\/(.*)\/databases\/(.*)$/) { + $resource_group = $1; + $server = $2; + $resource = $2 . '/databases/' . $3; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'servers'; + $self->{az_resource_namespace} = 'Microsoft.Sql'; + $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 active workers on Azure SQL Database. +Metrics are available with: +- Tier 'DTU based' - Basic, Standard, Premium +- vCore based model - General purpose & Business critical +- HyperScale + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=workers --custommode=api +--resource= --resource-group= --server= --aggregation='total' +--critical-workers='10' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::database::sqldatabase::plugin --mode=workers --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases/' +--aggregation='total' --critical-workers='10' + +Default aggregation: 'average', other are not identified as relevant nor available by Microsoft. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). It is the database name. + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--server> + +Set server name (Required if resource's name is used). + +=item B<--warning-workers> + +Warning threshold. + +=item B<--critical-workers> + +Critical threshold. + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/plugin.pm b/centreon-plugins/cloud/azure/database/sqldatabase/plugin.pm index db5a4a1fe..14618b4d5 100644 --- a/centreon-plugins/cloud/azure/database/sqldatabase/plugin.pm +++ b/centreon-plugins/cloud/azure/database/sqldatabase/plugin.pm @@ -31,13 +31,18 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'database-size' => 'cloud::azure::database::sqldatabase::mode::databasesize', - 'database-status' => 'cloud::azure::database::sqldatabase::mode::databasestatus', - 'list-databases' => 'cloud::azure::database::sqldatabase::mode::listdatabases', + 'app-resources' => 'cloud::azure::database::sqldatabase::mode::appresources', + 'connections' => 'cloud::azure::database::sqldatabase::mode::connections', + 'discovery' => 'cloud::azure::database::sqldatabase::mode::discovery', + 'deadlocks' => 'cloud::azure::database::sqldatabase::mode::deadlocks', + 'health' => 'cloud::azure::database::sqldatabase::mode::health', + 'sessions' => 'cloud::azure::database::sqldatabase::mode::sessions', + 'storage' => 'cloud::azure::database::sqldatabase::mode::storage', + 'workers' => 'cloud::azure::database::sqldatabase::mode::workers' ); - $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; - $self->{custom_modes}{api} = 'cloud::azure::custom::api'; + $self->{custom_modes}->{azcli} = 'cloud::azure::custom::azcli'; + $self->{custom_modes}->{api} = 'cloud::azure::custom::api'; return $self; } @@ -45,7 +50,7 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options(arguments => { - 'api-version:s' => { name => 'api_version', default => '2018-06-01-preview' }, + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, }); $self->SUPER::init(%options); @@ -57,6 +62,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Microsoft Azure SQL Database. +Check Microsoft Azure SQL Databases (Microsoft.Sql/Servers/Databases). =cut diff --git a/centreon-plugins/cloud/azure/database/sqlserver/mode/health.pm b/centreon-plugins/cloud/azure/database/sqlserver/mode/health.pm new file mode 100644 index 000000000..4ed0a0a63 --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqlserver/mode/health.pm @@ -0,0 +1,81 @@ +# +# 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::sqlserver::mode::health; + +use base qw(cloud::azure::management::monitor::mode::health); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Sql'; + $self->{type} = 'servers'; +} + +1; + +__END__ + +=head1 MODE + +Check SQL Server health. +(Useful to determine host status) + +=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-status> + +Set warning threshold for status (Default: ''). + +Can used special variables like: %{status}, %{summary} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /^Unavailable$/'). + +Can used special variables like: %{status}, %{summary} + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{status} =~ /^Unknown$/'). + +Can used special variables like: %{status}, %{summary} + +=item B<--ok-status> + +Set ok threshold for status (Default: '%{status} =~ /^Available$/'). + +Can used special variables like: %{status}, %{summary} + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/cloud/azure/database/sqlserver/mode/serverstatus.pm b/centreon-plugins/cloud/azure/database/sqlserver/mode/serverstatus.pm deleted file mode 100644 index f414f8d27..000000000 --- a/centreon-plugins/cloud/azure/database/sqlserver/mode/serverstatus.pm +++ /dev/null @@ -1,158 +0,0 @@ -# -# 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::sqlserver::mode::serverstatus; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); - -sub custom_status_output { - my ($self, %options) = @_; - - my $msg = sprintf("State '%s' [FQDN: %s]", - $self->{result_values}->{state}, - $self->{result_values}->{fqdn}); - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; - $self->{result_values}->{fqdn} = $options{new_datas}->{$self->{instance} . '_fqdn'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - return 0; -} - -sub prefix_server_output { - my ($self, %options) = @_; - - return "Server '" . $options{instance_value}->{display} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'servers', type => 1, cb_prefix_output => 'prefix_server_output', message_multiple => 'All servers are ok' }, - ]; - - $self->{maps_counters}->{servers} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'state' }, { name => 'fqdn' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "resource-group:s" => { name => 'resource_group' }, - "location:s" => { name => 'location' }, - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{state} ne "Ready"' }, - }); - - 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) = @_; - - $self->{servers} = {}; - my $servers = $options{custom}->azure_list_sqlservers(resource_group => $self->{option_results}->{resource_group}); - foreach my $server (@{$servers}) { - next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' - && $server->{name} !~ /$self->{option_results}->{filter_name}/); - next if (defined($self->{option_results}->{location}) && $self->{option_results}->{location} ne '' - && $server->{location} !~ /$self->{option_results}->{location}/); - - $self->{servers}->{$server->{id}} = { - display => $server->{name}, - state => ($server->{state}) ? $server->{state} : $server->{properties}->{state}, - fqdn => ($server->{fullyQualifiedDomainName}) ? $server->{fullyQualifiedDomainName} : $server->{properties}->{fullyQualifiedDomainName}, - }; - } - - if (scalar(keys %{$self->{servers}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No SQL servers found."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check SQL servers status. - -Example: -perl centreon_plugins.pl --plugin=cloud::azure::database::sqlserver::plugin --custommode=azcli --mode=server-status ---resource-group='MYRESOURCEGROUP' --verbose - -=over 8 - -=item B<--resource-group> - -Set resource group. - -=item B<--location> - -Set resource location. - -=item B<--filter-name> - -Filter server name (Can be a regexp). - -=item B<--warning-status> - -Set warning threshold for status (Default: ''). -Can used special variables like: %{state}, %{fqdn}, %{display} - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{state} ne "Ready"'). -Can used special variables like: %{state}, %{fqdn}, %{display} - -=back - -=cut diff --git a/centreon-plugins/cloud/azure/database/sqlserver/plugin.pm b/centreon-plugins/cloud/azure/database/sqlserver/plugin.pm index dbc6af05a..843a5014c 100644 --- a/centreon-plugins/cloud/azure/database/sqlserver/plugin.pm +++ b/centreon-plugins/cloud/azure/database/sqlserver/plugin.pm @@ -32,12 +32,12 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( 'discovery' => 'cloud::azure::database::sqlserver::mode::discovery', - 'list-servers' => 'cloud::azure::database::sqlserver::mode::listservers', - 'server-status' => 'cloud::azure::database::sqlserver::mode::serverstatus', + 'health' => 'cloud::azure::database::sqlserver::mode::health', + 'list-servers' => 'cloud::azure::database::sqlserver::mode::listservers' ); - $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; - $self->{custom_modes}{api} = 'cloud::azure::custom::api'; + $self->{custom_modes}->{azcli} = 'cloud::azure::custom::azcli'; + $self->{custom_modes}->{api} = 'cloud::azure::custom::api'; return $self; } @@ -45,7 +45,7 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options(arguments => { - 'api-version:s' => { name => 'api_version', default => '2018-06-01-preview' }, + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, }); $self->SUPER::init(%options);