patch azure compute virtual machine and delete outdated vm-state mode in favor of health one (#3847)
This commit is contained in:
parent
4a75f3f7dc
commit
837e907e14
|
@ -64,6 +64,7 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'api-version:s' => { name => 'api_version', default => '2018-01-01'},
|
||||
'filter-metric:s' => { name => 'filter_metric' },
|
||||
'resource:s' => { name => 'resource' },
|
||||
'resource-group:s' => { name => 'resource_group' }
|
||||
|
@ -80,6 +81,8 @@ sub check_options {
|
|||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne "") ? $self->{option_results}->{api_version} : "2018-01-01";
|
||||
|
||||
my $resource = $self->{option_results}->{resource};
|
||||
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"api-version:s" => { name => 'api_version', default => '2018-01-01'},
|
||||
"filter-metric:s" => { name => 'filter_metric' },
|
||||
"resource:s" => { name => 'resource' },
|
||||
"resource-group:s" => { name => 'resource_group' }
|
||||
|
@ -88,6 +89,8 @@ sub check_options {
|
|||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne "") ? $self->{option_results}->{api_version} : "2018-01-01";
|
||||
|
||||
my $resource = $self->{option_results}->{resource};
|
||||
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ sub new {
|
|||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"api-version:s" => { name => 'api_version', default => "2022-03-01"},
|
||||
"resource-group:s" => { name => 'resource_group' },
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
});
|
||||
|
@ -42,8 +43,12 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
$self->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne '') ? $self->{option_results}->{api_version} : "2022-03-01";
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -57,6 +62,7 @@ sub run {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
|
||||
foreach my $vm (@{$self->{vms}}) {
|
||||
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
|
||||
&& $vm->{name} !~ /$self->{option_results}->{filter_name}/);
|
||||
|
@ -73,7 +79,7 @@ sub run {
|
|||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("[name = %s][computername = %s][resourcegroup = %s]" .
|
||||
"[location = %s][vmid = %s][vmsize = %s][os = %s][state = %s][tags = %s]",
|
||||
"[location = %s][vmid = %s][vmsize = %s][os = %s][tags = %s]",
|
||||
$vm->{name},
|
||||
$computer_name,
|
||||
$resource_group,
|
||||
|
@ -81,7 +87,6 @@ sub run {
|
|||
(defined($vm->{properties}->{vmId})) ? $vm->{properties}->{vmId} : $vm->{vmId},
|
||||
(defined($vm->{properties}->{hardwareProfile}->{vmSize})) ? $vm->{properties}->{hardwareProfile}->{vmSize} : $vm->{hardwareProfile}->{vmSize},
|
||||
(defined($vm->{properties}->{storageProfile}->{osDisk}->{osType})) ? $vm->{properties}->{storageProfile}->{osDisk}->{osType} : $vm->{storageProfile}->{osDisk}->{osType},
|
||||
(defined($vm->{powerState})) ? $vm->{powerState} : "-",
|
||||
join(',', @tags),
|
||||
));
|
||||
}
|
||||
|
@ -95,7 +100,7 @@ sub run {
|
|||
sub disco_format {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->add_disco_format(elements => ['name', 'computername', 'resourcegroup', 'location', 'vmid', 'vmsize', 'os', 'state', 'tags']);
|
||||
$self->{output}->add_disco_format(elements => ['name', 'computername', 'resourcegroup', 'location', 'vmid', 'vmsize', 'os', 'tags']);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
|
@ -123,7 +128,6 @@ sub disco_show {
|
|||
vmid => (defined($vm->{properties}->{vmId})) ? $vm->{properties}->{vmId} : $vm->{vmId},
|
||||
vmsize => (defined($vm->{properties}->{hardwareProfile}->{vmSize})) ? $vm->{properties}->{hardwareProfile}->{vmSize} : $vm->{hardwareProfile}->{vmSize},
|
||||
os => (defined($vm->{properties}->{storageProfile}->{osDisk}->{osType})) ? $vm->{properties}->{storageProfile}->{osDisk}->{osType} : $vm->{storageProfile}->{osDisk}->{osType},
|
||||
state => (defined($vm->{powerState})) ? $vm->{powerState} : "-",
|
||||
tags => join(',', @tags),
|
||||
);
|
||||
}
|
||||
|
@ -135,7 +139,7 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
List vitual machines.
|
||||
List virtual machines.
|
||||
|
||||
=over 8
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'api-version:s' => { name => 'api_version', default => '2018-01-01'},
|
||||
'resource:s' => { name => 'resource' },
|
||||
'resource-group:s' => { name => 'resource_group' }
|
||||
});
|
||||
|
@ -61,6 +62,9 @@ sub check_options {
|
|||
$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->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne "") ? $self->{option_results}->{api_version} : "2018-01-01";
|
||||
|
||||
my $resource = $self->{option_results}->{resource};
|
||||
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
|
||||
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Compute\/virtualMachines\/(.*)$/) {
|
||||
|
|
|
@ -56,8 +56,9 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'api-version:s' => { name => 'api_version', default => '2018-01-01'},
|
||||
"filter-metric:s" => { name => 'filter_metric' },
|
||||
"resource:s " => { name => 'resource' },
|
||||
"resource:s" => { name => 'resource' },
|
||||
"resource-group:s" => { name => 'resource_group' }
|
||||
});
|
||||
|
||||
|
@ -67,11 +68,14 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne "") ? $self->{option_results}->{api_version} : "2018-01-01";
|
||||
|
||||
my $resource = $self->{option_results}->{resource};
|
||||
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ sub new {
|
|||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"api-version:s" => { name => 'api_version', default => "2022-03-01"},
|
||||
"resource-group:s" => { name => 'resource_group' },
|
||||
"filter-type:s" => { name => 'filter_type' },
|
||||
"filter-size:s" => { name => 'filter_size' },
|
||||
|
@ -134,6 +135,9 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne "") ? $self->{option_results}->{api_version} : "2022-03-01";
|
||||
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
|
|
|
@ -1,178 +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::compute::virtualmachine::mode::vmsstate;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub prefix_global_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Total vitual machines ";
|
||||
}
|
||||
|
||||
sub prefix_vm_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Virtual machine '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
|
||||
{ name => 'vms', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total-running', nlabel => 'azure.compute.vm.running.count', set => {
|
||||
key_values => [ { name => 'running' } ],
|
||||
output_template => "running : %s",
|
||||
perfdatas => [
|
||||
{ label => 'total_running', value => 'running', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-stopped', nlabel => 'azure.compute.vm.stopped.count', set => {
|
||||
key_values => [ { name => 'stopped' } ],
|
||||
output_template => "stopped : %s",
|
||||
perfdatas => [
|
||||
{ label => 'total_stopped', value => 'stopped', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{vms} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'state' }, { name => 'name' } ],
|
||||
output_template => 'state: %s',
|
||||
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, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"resource-group:s" => { name => 'resource_group' },
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{global} = {
|
||||
running => 0, stopped => 0,
|
||||
};
|
||||
$self->{vms} = {};
|
||||
my $vms = $options{custom}->azure_list_vms(resource_group => $self->{option_results}->{resource_group}, show_details => 1);
|
||||
foreach my $vm (@{$vms}) {
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$vm->{name} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $vm->{name} . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{vms}->{$vm->{id}} = {
|
||||
display => $vm->{name},
|
||||
state => $vm->{powerState},
|
||||
};
|
||||
|
||||
foreach my $state (keys %{$self->{global}}) {
|
||||
$self->{global}->{$state}++ if ($vm->{powerState} =~ /$state/);
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{vms}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No virtual machines found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check virtual machines status (Only with az CLI).
|
||||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=cloud::azure::compute::virtualmachine::plugin --custommode=azcli --mode=vms-state
|
||||
--filter-name='.*' --filter-counters='^total-running$' --critical-total-running='10' --verbose
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--resource-group>
|
||||
|
||||
Set resource group (Optional).
|
||||
|
||||
=item B<--filter-name>
|
||||
|
||||
Filter resource name (Can be a regexp).
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^total-running$'
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{state}, %{display}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status (Default: '').
|
||||
Can used special variables like: %{state}, %{display}
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total-running', 'total-stopped'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total-running', 'total-stopped'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -50,9 +50,7 @@ sub new {
|
|||
sub init {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{options}->add_options(arguments => {
|
||||
'api-version:s' => { name => 'api_version', default => '2018-01-01' },
|
||||
});
|
||||
$self->{options}->add_options(arguments => { });
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"api-version:s" => { name => 'api_version', default => '2018-01-01'},
|
||||
"namespace:s" => { name => 'namespace' },
|
||||
"type:s" => { name => 'type' },
|
||||
"resource-group:s" => { name => 'resource_group' },
|
||||
|
@ -46,6 +47,8 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
$self->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne "") ? $self->{option_results}->{api_version} : 2018-01-01;
|
||||
|
||||
$self->{namespace} = $self->{option_results}->{namespace};
|
||||
$self->{type} = $self->{option_results}->{type};
|
||||
$self->{location} = $self->{option_results}->{location};
|
||||
|
|
|
@ -68,6 +68,7 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"api-version:s" => { name => 'api_version', default => '2018-01-01'},
|
||||
"resource:s" => { name => 'resource' },
|
||||
"resource-group:s" => { name => 'resource_group' },
|
||||
"resource-type:s" => { name => 'resource_type' },
|
||||
|
@ -90,6 +91,8 @@ sub check_options {
|
|||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne "") ? $self->{option_results}->{api_version} : 2018-01-01;
|
||||
|
||||
$self->{az_resource} = $self->{option_results}->{resource};
|
||||
$self->{az_resource_group} = $self->{option_results}->{resource_group};
|
||||
$self->{az_resource_type} = $self->{option_results}->{resource_type};
|
||||
|
|
Loading…
Reference in New Issue