mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 07:34:35 +02:00
(plugin) cloud::azure::management::recovery - adding mode to monitor Azure replication health (#3858)
This commit is contained in:
parent
179c6002e6
commit
d872c90799
@ -459,6 +459,25 @@ sub azure_list_resources {
|
|||||||
return $full_response;
|
return $full_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub azure_list_replication_protected_items_set_url {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourceGroups/" .
|
||||||
|
$options{resource_group} . "/providers/Microsoft.RecoveryServices/vaults/" .
|
||||||
|
$options{vault_name} . "/replicationProtectedItems?api-version=" . $self->{api_version};
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub azure_list_replication_protected_items {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $full_url = $self->azure_list_replication_protected_items_set_url(%options);
|
||||||
|
my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => '');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
sub azure_list_subscriptions_set_url {
|
sub azure_list_subscriptions_set_url {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -283,6 +283,13 @@ sub azure_list_resources {
|
|||||||
return $raw_results;
|
return $raw_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub azure_list_replication_protected_items {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Unsupported custom mode for plugin mode 'replication-health'. Please use --custommode='api'.");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
sub azure_list_vm_sizes_set_cmd {
|
sub azure_list_vm_sizes_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -0,0 +1,152 @@
|
|||||||
|
#
|
||||||
|
# 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::management::recovery::mode::listreplicateditems;
|
||||||
|
|
||||||
|
use base qw(centreon::plugins::mode);
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
$options{options}->add_options(arguments =>
|
||||||
|
{
|
||||||
|
"vault-name:s" => { name => 'vault_name' },
|
||||||
|
"resource-group:s" => { name => 'resource_group' },
|
||||||
|
"filter-name:s" => { name => 'filter_name' },
|
||||||
|
});
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
$self->SUPER::init(%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}->{vault_name}) || $self->{option_results}->{vault_name} eq '') {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Need to specify --vault-name option");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{replicated_items} = $options{custom}->azure_list_replication_protected_items(
|
||||||
|
vault_name => $self->{option_results}->{vault_name},
|
||||||
|
resource_group => $self->{option_results}->{resource_group}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->manage_selection(%options);
|
||||||
|
foreach my $replicated_item (@{$self->{replicated_items}->{value}}) {
|
||||||
|
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
|
||||||
|
&& $replicated_item->{properties}->{friendlyName} !~ /$self->{option_results}->{filter_name}/);
|
||||||
|
my $resource_group = '-';
|
||||||
|
$resource_group = $replicated_item->{resourceGroup} if (defined($replicated_item->{resourceGroup}));
|
||||||
|
$resource_group = $1 if ($resource_group eq '-' && defined($replicated_item->{id}) && $replicated_item->{id} =~ /resource[gG]roups\/(.*)\/providers/);
|
||||||
|
|
||||||
|
my @tags;
|
||||||
|
foreach my $tag (keys %{$replicated_item->{tags}}) {
|
||||||
|
push @tags, $tag . ':' . $replicated_item->{tags}->{$tag};
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{output}->output_add(long_msg => sprintf("[name = %s][resourcegroup = %s][id = %s][replication_health = %s][failover_health = %s]",
|
||||||
|
$replicated_item->{properties}->{friendlyName},
|
||||||
|
$resource_group,
|
||||||
|
$replicated_item->{id},
|
||||||
|
$replicated_item->{properties}->{replicationHealth},
|
||||||
|
$replicated_item->{properties}->{failoverHealth},
|
||||||
|
join(',', @tags))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{output}->output_add(severity => 'OK',
|
||||||
|
short_msg => 'List replicated items:');
|
||||||
|
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||||
|
$self->{output}->exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub disco_format {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{output}->add_disco_format(elements => ['name', 'resourcegroup', 'id', 'replication_health', 'failover_health']);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub disco_show {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->manage_selection(%options);
|
||||||
|
foreach my $replicated_item (@{$self->{replicated_items}->{value}}) {
|
||||||
|
my $resource_group = '-';
|
||||||
|
$resource_group = $replicated_item->{resourceGroup} if (defined($replicated_item->{resourceGroup}));
|
||||||
|
$resource_group = $1 if ($resource_group eq '-' && defined($replicated_item->{id}) && $replicated_item->{id} =~ /resourceGroups\/(.*)\/providers/);
|
||||||
|
|
||||||
|
my @tags;
|
||||||
|
foreach my $tag (keys %{$replicated_item->{tags}}) {
|
||||||
|
push @tags, $tag . ':' . $replicated_item->{tags}->{$tag};
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{output}->add_disco_entry(
|
||||||
|
name => $replicated_item->{properties}->{FriendlyName},
|
||||||
|
resourcegroup => $resource_group,
|
||||||
|
id => $replicated_item->{id},
|
||||||
|
replication_health => $replicated_item->{properties}->{replicationHealth},
|
||||||
|
failover_health => $replicated_item->{properties}->{failoverHealth},
|
||||||
|
tags => join(',', @tags)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 MODE
|
||||||
|
|
||||||
|
List replicated items.
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=item B<--vault-name>
|
||||||
|
|
||||||
|
Set vault name (Mandatory).
|
||||||
|
|
||||||
|
=item B<--resource-group>
|
||||||
|
|
||||||
|
Set resource group (Mandatory).
|
||||||
|
|
||||||
|
=item B<--filter-name>
|
||||||
|
|
||||||
|
Filter on item name (Can be a regexp).
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
@ -0,0 +1,180 @@
|
|||||||
|
#
|
||||||
|
# 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::management::recovery::mode::replicationhealth;
|
||||||
|
|
||||||
|
use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||||
|
|
||||||
|
sub custom_replication_status_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $msg = sprintf("Replication status '%s'", $self->{result_values}->{replication_status});
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub custom_failover_status_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $msg = sprintf("Failover status '%s'", $self->{result_values}->{failover_status});
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub prefix_replication_item_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return "Replicated item '" . $options{instance_value}->{display} . "' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub set_counters {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{maps_counters_type} = [
|
||||||
|
{ name => 'items', type => 1, cb_prefix_output => 'prefix_replication_item_output', message_multiple => 'All replicated items are OK' }
|
||||||
|
];
|
||||||
|
|
||||||
|
$self->{maps_counters}->{items} = [
|
||||||
|
{ label => 'replication-status',
|
||||||
|
critical_default => '%{replication_status} eq "Critical"',
|
||||||
|
warning_default => '%{replication_status} eq "Warning"',
|
||||||
|
type => 2, set => {
|
||||||
|
key_values => [ { name => 'replication_status' }, { name => 'display' } ],
|
||||||
|
closure_custom_output => $self->can('custom_replication_status_output'),
|
||||||
|
closure_custom_perfdata => sub { return 0; },
|
||||||
|
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ label => 'failover-status',
|
||||||
|
critical_default => '%{failover_status} eq "Critical"',
|
||||||
|
warning_default => '%{failover_status} eq "Warning"',
|
||||||
|
type => 2, set => {
|
||||||
|
key_values => [ { name => 'failover_status' }, { name => 'display' } ],
|
||||||
|
closure_custom_output => $self->can('custom_failover_status_output'),
|
||||||
|
closure_custom_perfdata => sub { return 0; },
|
||||||
|
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
$options{options}->add_options(arguments =>
|
||||||
|
{
|
||||||
|
"api-version:s" => { name => 'api_version', default => '2021-08-01'},
|
||||||
|
"filter-name:s" => { name => 'filter_name' },
|
||||||
|
"vault-name:s" => { name => 'vault_name' },
|
||||||
|
"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_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}->{vault_name}) || $self->{option_results}->{vault_name} eq '') {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Need to specify --vault-name option");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{global} = {};
|
||||||
|
my $replicated_items = $options{custom}->azure_list_replication_protected_items(
|
||||||
|
vault_name => $self->{option_results}->{vault_name},
|
||||||
|
resource_group => $self->{option_results}->{resource_group}
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach my $replicated_item (@{$replicated_items->{value}}) {
|
||||||
|
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
|
||||||
|
&& $replicated_item->{properties}->{friendlyName} !~ /$self->{option_results}->{filter_name}/);
|
||||||
|
|
||||||
|
$self->{items}->{$replicated_item->{properties}->{friendlyName}} = {
|
||||||
|
display => $replicated_item->{properties}->{friendlyName},
|
||||||
|
replication_status => $replicated_item->{properties}->{replicationHealth},
|
||||||
|
failover_status => $replicated_item->{properties}->{failoverHealth}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scalar(keys %{$self->{items}}) <= 0) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "No replicated item found.");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 MODE
|
||||||
|
|
||||||
|
Check replicated items replication and failover health.
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=item B<--vault-name>
|
||||||
|
|
||||||
|
Set vault name (Required).
|
||||||
|
|
||||||
|
=item B<--resource-group>
|
||||||
|
|
||||||
|
Set resource group (Required).
|
||||||
|
|
||||||
|
=item B<--filter-name>
|
||||||
|
|
||||||
|
Filter item name (Can be a regexp).
|
||||||
|
|
||||||
|
=item B<--warning-replication-status>
|
||||||
|
|
||||||
|
Set warning threshold for replication health (Default: '%{replication_status} eq "Warning"').
|
||||||
|
Can used special variables like: %{status}, %{display}
|
||||||
|
|
||||||
|
=item B<--critical-replication-status>
|
||||||
|
|
||||||
|
Set critical threshold for replication health (Default: '%{replication_status} eq "Critical"').
|
||||||
|
Can used special variables like: %{status}, %{display}
|
||||||
|
|
||||||
|
=item B<--warning-failover-status>
|
||||||
|
|
||||||
|
Set warning threshold for failover status (Default: '%{failover_status} eq "Warning"').
|
||||||
|
Can used special variables like: %{status}, %{display}
|
||||||
|
|
||||||
|
=item B<--critical-failover-status>
|
||||||
|
|
||||||
|
Set critical threshold for failover status (Default: '%{failover_status} eq "Critical"').
|
||||||
|
Can used special variables like: %{status}, %{display}
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
@ -31,11 +31,13 @@ sub new {
|
|||||||
|
|
||||||
$self->{version} = '0.1';
|
$self->{version} = '0.1';
|
||||||
%{ $self->{modes} } = (
|
%{ $self->{modes} } = (
|
||||||
'backup-items-status' => 'cloud::azure::management::recovery::mode::backupitemsstatus',
|
'backup-items-status' => 'cloud::azure::management::recovery::mode::backupitemsstatus',
|
||||||
'backup-jobs-status' => 'cloud::azure::management::recovery::mode::backupjobsstatus',
|
'backup-jobs-status' => 'cloud::azure::management::recovery::mode::backupjobsstatus',
|
||||||
'discovery' => 'cloud::azure::management::recovery::mode::discovery',
|
'discovery' => 'cloud::azure::management::recovery::mode::discovery',
|
||||||
'list-backup-jobs' => 'cloud::azure::management::recovery::mode::listbackupjobs',
|
'list-backup-jobs' => 'cloud::azure::management::recovery::mode::listbackupjobs',
|
||||||
'list-vaults' => 'cloud::azure::management::recovery::mode::listvaults',
|
'list-vaults' => 'cloud::azure::management::recovery::mode::listvaults',
|
||||||
|
'list-replicated-items' => 'cloud::azure::management::recovery::mode::listreplicateditems',
|
||||||
|
'replication-health' => 'cloud::azure::management::recovery::mode::replicationhealth'
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli';
|
$self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli';
|
||||||
@ -58,6 +60,6 @@ __END__
|
|||||||
|
|
||||||
=head1 PLUGIN DESCRIPTION
|
=head1 PLUGIN DESCRIPTION
|
||||||
|
|
||||||
Check Microsoft Azure backup service.
|
Check Microsoft Azure backup service, replication and failover health.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
Loading…
x
Reference in New Issue
Block a user