break(azure/virtual-networks): refactoring (#3265)
This commit is contained in:
parent
c16166a868
commit
f759d5877b
|
@ -574,9 +574,8 @@ sub azure_list_vpn_gateways {
|
||||||
sub azure_list_virtualnetworks_set_url {
|
sub azure_list_virtualnetworks_set_url {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription};
|
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" .
|
||||||
$url .= "/resourceGroups/" . $options{resource_group} if (defined($options{resource_group}) && $options{resource_group} ne '');
|
$options{resource_group} . "/providers/Microsoft.Network/virtualNetworks?api-version=" . $self->{api_version};
|
||||||
$url .= "/providers/Microsoft.Network/virtualNetworks?api-version=" . $self->{api_version};
|
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
@ -593,10 +592,9 @@ sub azure_list_virtualnetworks {
|
||||||
sub azure_list_vnet_peerings_set_url {
|
sub azure_list_vnet_peerings_set_url {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription};
|
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" .
|
||||||
$url .= "/resourceGroups/" . $options{resource_group} if (defined($options{resource_group}) && $options{resource_group} ne '');
|
$options{resource_group} . "/providers/Microsoft.Network/virtualNetworks/" .
|
||||||
$url .= "/providers/Microsoft.Network/virtualNetworks/" . $options{vnet_name} if (defined($options{vnet_name}) && $options{vnet_name} ne '');
|
$options{resource} . "/virtualNetworkPeerings?api-version=" . $self->{api_version};
|
||||||
$url .= "/virtualNetworkPeerings?api-version=" . $self->{api_version};
|
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,8 +448,7 @@ sub azure_list_virtualnetworks_set_cmd {
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||||
|
|
||||||
my $cmd_options = "network vnet list --only-show-errors --output json";
|
my $cmd_options = "network vnet list --resource-group '$options{resource_group}' --only-show-errors --output json ";
|
||||||
$cmd_options .= " --resource-group '$options{resource_group}'" if (defined($options{resource_group}) && $options{resource_group} ne '');
|
|
||||||
$cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne '');
|
$cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne '');
|
||||||
|
|
||||||
return $cmd_options;
|
return $cmd_options;
|
||||||
|
@ -469,7 +468,7 @@ sub azure_list_vnet_peerings_set_cmd {
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||||
|
|
||||||
my $cmd_options = "network vnet peering list --resource-group '$options{resource_group}' --vnet-name '$options{vnet_name}' --only-show-errors --output json";
|
my $cmd_options = "network vnet peering list --resource-group '$options{resource_group}' --vnet-name '$options{resource}' --only-show-errors --output json";
|
||||||
$cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne '');
|
$cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne '');
|
||||||
|
|
||||||
return $cmd_options;
|
return $cmd_options;
|
||||||
|
|
|
@ -34,7 +34,7 @@ sub new {
|
||||||
{
|
{
|
||||||
"resource-group:s" => { name => 'resource_group' },
|
"resource-group:s" => { name => 'resource_group' },
|
||||||
"location:s" => { name => 'location' },
|
"location:s" => { name => 'location' },
|
||||||
"filter-name:s" => { name => 'filter_name' },
|
"filter-name:s" => { name => 'filter_name' }
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -43,6 +43,11 @@ sub new {
|
||||||
sub check_options {
|
sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->SUPER::init(%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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
|
|
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||||
|
|
||||||
sub custom_status_output {
|
sub custom_status_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
@ -36,16 +36,6 @@ sub custom_status_output {
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_status_calc {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
$self->{result_values}->{peering_state} = $options{new_datas}->{$self->{instance} . '_peering_state'};
|
|
||||||
$self->{result_values}->{provisioning_state} = $options{new_datas}->{$self->{instance} . '_provisioning_state'};
|
|
||||||
$self->{result_values}->{peer} = $options{new_datas}->{$self->{instance} . '_peer'};
|
|
||||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub prefix_peering_output {
|
sub prefix_peering_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -60,15 +50,18 @@ sub set_counters {
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{peerings} = [
|
$self->{maps_counters}->{peerings} = [
|
||||||
{ label => 'status', threshold => 0, set => {
|
{
|
||||||
|
label => 'status',
|
||||||
|
type => 2,
|
||||||
|
critical_default => '%{peering_state} ne "Connected" || %{provisioning_state} ne "Succeeded"',
|
||||||
|
set => {
|
||||||
key_values => [ { name => 'peering_state' }, { name => 'provisioning_state' }, { name => 'peer' },
|
key_values => [ { name => 'peering_state' }, { name => 'provisioning_state' }, { name => 'peer' },
|
||||||
{ name => 'display' } ],
|
{ name => 'display' } ],
|
||||||
closure_custom_calc => $self->can('custom_status_calc'),
|
|
||||||
closure_custom_output => $self->can('custom_status_output'),
|
closure_custom_output => $self->can('custom_status_output'),
|
||||||
closure_custom_perfdata => sub { return 0; },
|
closure_custom_perfdata => sub { return 0; },
|
||||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,13 +70,10 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
|
||||||
"resource-group:s" => { name => 'resource_group' },
|
"resource-group:s" => { name => 'resource_group' },
|
||||||
"vnet-name:s" => { name => 'vnet_name' },
|
"resource:s" => { name => 'resource' },
|
||||||
"filter-name:s" => { name => 'filter_name' },
|
"filter-name:s" => { name => 'filter_name' }
|
||||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
|
||||||
"critical-status:s" => { name => 'critical_status', default => '%{peering_state} ne "Connected" || %{provisioning_state} ne "Succeeded"' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -93,16 +83,20 @@ sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->SUPER::check_options(%options);
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
if (!defined($self->{option_results}->{resource_group}) || $self->{option_results}->{resource_group} eq '') {
|
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
|
||||||
$self->{output}->add_option_msg(short_msg => "Need to specify --resource-group option");
|
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
if (!defined($self->{option_results}->{vnet_name}) || $self->{option_results}->{vnet_name} eq '') {
|
my $resource = $self->{option_results}->{resource};
|
||||||
$self->{output}->add_option_msg(short_msg => "Need to specify --vnet-name option");
|
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
|
||||||
$self->{output}->option_exit();
|
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Network\/virtualNetworks\/(.*)$/) {
|
||||||
|
$resource_group = $1;
|
||||||
|
$resource = $2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
$self->{az_resource} = $resource;
|
||||||
|
$self->{az_resource_group} = $resource_group;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
|
@ -110,8 +104,8 @@ sub manage_selection {
|
||||||
|
|
||||||
$self->{peerings} = {};
|
$self->{peerings} = {};
|
||||||
my $peerings = $options{custom}->azure_list_vnet_peerings(
|
my $peerings = $options{custom}->azure_list_vnet_peerings(
|
||||||
resource_group => $self->{option_results}->{resource_group},
|
resource_group => $self->{az_resource_group},
|
||||||
vnet_name => $self->{option_results}->{vnet_name}
|
resource => $self->{az_resource}
|
||||||
);
|
);
|
||||||
foreach my $peering (@{$peerings}) {
|
foreach my $peering (@{$peerings}) {
|
||||||
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
|
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
|
||||||
|
@ -144,8 +138,8 @@ __END__
|
||||||
Check virtual network peerings status.
|
Check virtual network peerings status.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
perl centreon_plugins.pl --plugin=cloud::azure::network::virtualnetwork::plugin --custommode=azcli --mode=peerings-status
|
perl centreon_plugins.pl --plugin=cloud::azure::network::virtualnetwork::plugin --custommode=awscli --mode=peerings-status
|
||||||
--resource-group='MYRESOURCEGROUP' --vnet-name='MyVNetName' --verbose
|
--resource-group='MYRESOURCEGROUP' --resource='MyVNetName' --verbose
|
||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
|
@ -153,7 +147,7 @@ perl centreon_plugins.pl --plugin=cloud::azure::network::virtualnetwork::plugin
|
||||||
|
|
||||||
Set resource group (Required).
|
Set resource group (Required).
|
||||||
|
|
||||||
=item B<--vnet-name>
|
=item B<--resource>
|
||||||
|
|
||||||
Set virtual network name (Required).
|
Set virtual network name (Required).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue