resourceid management (#3195)
This commit is contained in:
parent
69253afe18
commit
6fb5e91654
|
@ -691,6 +691,7 @@ sub azure_get_insights_analytics {
|
|||
foreach (@{$_->{rows}}) {
|
||||
$raw_results->{data}->{$j}->{tags} = @$_[$raw_results->{index}->{Tags}];
|
||||
$raw_results->{data}->{$j}->{computer} = @$_[$raw_results->{index}->{Computer}];
|
||||
$raw_results->{data}->{$j}->{resourceid} = @$_[$raw_results->{index}->{_ResourceId}];
|
||||
if (!defined($options{disco})) {
|
||||
$raw_results->{data}->{$j}->{timegenerated} = @$_[$raw_results->{index}->{TimeGenerated}];
|
||||
$raw_results->{data}->{$j}->{name} = @$_[$raw_results->{index}->{Name}];
|
||||
|
|
|
@ -84,9 +84,10 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-computer:s' => { name => 'filter_computer' },
|
||||
'filter-cpu:s' => { name => 'filter_cpu' },
|
||||
'workspace-id:s' => { name => 'workspace_id' }
|
||||
'filter-computer:s' => { name => 'filter_computer' },
|
||||
'filter-cpu:s' => { name => 'filter_cpu' },
|
||||
'filter-resourceid:s' => { name => 'filter_resourceid' },
|
||||
'workspace-id:s' => { name => 'workspace_id' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -103,6 +104,7 @@ sub manage_selection {
|
|||
|
||||
my $query = 'InsightsMetrics | where Namespace == "Processor" | summarize arg_max(TimeGenerated, *) by Tags, Name, Computer';
|
||||
$query .= '| where Computer == "' . $self->{option_results}->{filter_computer} . '"' if defined $self->{option_results}->{filter_computer} && $self->{option_results}->{filter_computer} ne '';
|
||||
$query .= '| where _ResourceId == "' . $self->{option_results}->{filter_resourceid} . '"' if defined $self->{option_results}->{filter_resourceid} && $self->{option_results}->{filter_resourceid} ne '';
|
||||
|
||||
my $results = $options{custom}->azure_get_insights_analytics(
|
||||
workspace_id => $self->{option_results}->{workspace_id},
|
||||
|
@ -164,6 +166,10 @@ perl centreon_plugins.pl --plugin=cloud::azure::management::insightsmetrics::plu
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--workspace-id>
|
||||
(Mandatory)
|
||||
Specify the Azure Log Analytics Workspace ID.
|
||||
|
||||
=item B<--filter-computer>
|
||||
|
||||
Filter on a specific Azure "computer".
|
||||
|
|
|
@ -32,7 +32,8 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'computer:s' => { name => 'computer' },
|
||||
'name' => { name => 'name' },
|
||||
'resource:s' => { name => 'resource' },
|
||||
'workspace-id:s' => { name => 'workspace_id' }
|
||||
});
|
||||
return $self;
|
||||
|
@ -42,8 +43,8 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{computer}) || $self->{option_results}->{computer} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --computer option.");
|
||||
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --resource option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +52,12 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $query = 'InsightsMetrics | where Namespace == "LogicalDisk" | distinct Tags, Computer | where Computer == "' . $self->{option_results}->{computer} . '"';
|
||||
my $query = 'InsightsMetrics | where Namespace == "LogicalDisk" | distinct Tags, _ResourceId, Computer';
|
||||
if (defined($self->{option_results}->{name})) {
|
||||
$query .= '| where Computer == "' . $self->{option_results}->{resource} . '"';
|
||||
} else {
|
||||
$query .= '| where _ResourceId == "' . $self->{option_results}->{resource} . '"';
|
||||
}
|
||||
|
||||
my $results = $options{custom}->azure_get_insights_analytics(
|
||||
workspace_id => $self->{option_results}->{workspace_id},
|
||||
|
@ -66,6 +72,11 @@ sub manage_selection {
|
|||
|
||||
$self->{logicaldisk}->{$decoded_tag->{"vm.azm.ms/mountId"}}->{name} = $decoded_tag->{"vm.azm.ms/mountId"};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{logicaldisk}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No logical disks found. Can be: filters, cache file.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
@ -107,8 +118,30 @@ __END__
|
|||
|
||||
List Azure Computer logical disks.
|
||||
|
||||
Example:
|
||||
|
||||
perl centreon_plugins.pl --plugin=cloud::azure::management::insightsmetrics::plugin --custommode=api --mode=list-logical-disks
|
||||
--subscription=1111 --tenant=2222 --client-id=3333 --client-secret=4444 --workspace-id=5555 --verbose --resource='azure-vm1'
|
||||
--name
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--workspace-id>
|
||||
(Mandatory)
|
||||
Specify the Azure Log Analytics Workspace ID.
|
||||
|
||||
=item B<--resource>
|
||||
|
||||
(Mandatory)
|
||||
Specify the Azure VM Resource ID or name. Short name can be used if the option --name is defined.
|
||||
Example: --resource='/subscriptions/1234abcd-5678-defg-9012-3456789abcde/resourcegroups/my_resourcegroup/providers/microsoft.compute/virtualmachines/azure-vm1'
|
||||
|
||||
=item B<--name>
|
||||
|
||||
(Optional)
|
||||
Use only the name of the VM resource rather than the full ID.
|
||||
Example: --resource='azure-vm1' --name
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -148,9 +148,10 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-computer:s' => { name => 'filter_computer' },
|
||||
'filter-disk:s' => { name => 'filter_disk' },
|
||||
'workspace-id:s' => { name => 'workspace_id' }
|
||||
'filter-computer:s' => { name => 'filter_computer' },
|
||||
'filter-disk:s' => { name => 'filter_disk' },
|
||||
'filter-resourceid:s' => { name => 'filter_resourceid' },
|
||||
'workspace-id:s' => { name => 'workspace_id' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -167,6 +168,7 @@ sub manage_selection {
|
|||
|
||||
my $query = 'InsightsMetrics | where Namespace == "LogicalDisk" | summarize arg_max(TimeGenerated, *) by Tags, Name, Computer';
|
||||
$query .= '| where Computer == "' . $self->{option_results}->{filter_computer} . '"' if defined $self->{option_results}->{filter_computer} && $self->{option_results}->{filter_computer} ne '';
|
||||
$query .= '| where _ResourceId == "' . $self->{option_results}->{filter_resourceid} . '"' if defined $self->{option_results}->{filter_resourceid} && $self->{option_results}->{filter_resourceid} ne '';
|
||||
|
||||
my $results = $options{custom}->azure_get_insights_analytics(
|
||||
workspace_id => $self->{option_results}->{workspace_id},
|
||||
|
@ -241,6 +243,10 @@ perl centreon_plugins.pl --plugin=cloud::azure::management::insightsmetrics::plu
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--workspace-id>
|
||||
(Mandatory)
|
||||
Specify the Azure Log Analytics Workspace ID.
|
||||
|
||||
=item B<--filter-computer>
|
||||
|
||||
Filter on a specific Azure "computer".
|
||||
|
|
|
@ -97,8 +97,9 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-computer:s' => { name => 'filter_computer' },
|
||||
'workspace-id:s' => { name => 'workspace_id' }
|
||||
'filter-computer:s' => { name => 'filter_computer' },
|
||||
'filter-resourceid:s' => { name => 'filter_resourceid' },
|
||||
'workspace-id:s' => { name => 'workspace_id' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -115,6 +116,7 @@ sub manage_selection {
|
|||
|
||||
my $query = 'InsightsMetrics | where Namespace == "Memory" | summarize arg_max(TimeGenerated, *) by Tags, Name, Computer';
|
||||
$query .= '| where Computer == "' . $self->{option_results}->{filter_computer} . '"' if defined $self->{option_results}->{filter_computer} && $self->{option_results}->{filter_computer} ne '';
|
||||
$query .= '| where _ResourceId == "' . $self->{option_results}->{filter_resourceid} . '"' if defined $self->{option_results}->{filter_resourceid} && $self->{option_results}->{filter_resourceid} ne '';
|
||||
|
||||
my $results = $options{custom}->azure_get_insights_analytics(
|
||||
workspace_id => $self->{option_results}->{workspace_id},
|
||||
|
@ -173,6 +175,10 @@ perl centreon_plugins.pl --plugin=cloud::azure::management::insightsmetrics::plu
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--workspace-id>
|
||||
(Mandatory)
|
||||
Specify the Azure Log Analytics Workspace ID.
|
||||
|
||||
=item B<--filter-computer>
|
||||
|
||||
Filter on a specific Azure "computer".
|
||||
|
|
Loading…
Reference in New Issue