Fix #1886
This commit is contained in:
parent
b9479bc02b
commit
1ee9b28e1f
|
@ -81,13 +81,12 @@ 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 =>v{
|
||||||
{
|
'resource:s@' => { name => 'resource' },
|
||||||
"resource:s@" => { name => 'resource' },
|
'resource-group:s' => { name => 'resource_group' },
|
||||||
"resource-group:s" => { name => 'resource_group' },
|
'filter-metric:s' => { name => 'filter_metric' }
|
||||||
"filter-metric:s" => { name => 'filter_metric' },
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ 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}->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();
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{az_resource} = $self->{option_results}->{resource};
|
$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_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group}));
|
||||||
$self->{az_resource_type} = 'virtualMachines';
|
$self->{az_resource_type} = 'virtualMachines';
|
||||||
|
|
|
@ -635,6 +635,26 @@ sub azure_list_sqldatabases {
|
||||||
return $response->{value};
|
return $response->{value};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub azure_get_log_analytics_set_url {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $uri = URI::Encode->new({encode_reserved => 1});
|
||||||
|
my $encoded_query = $uri->encode($options{query});
|
||||||
|
my $encoded_interval = $uri->encode($options{interval});
|
||||||
|
my $url = $self->{management_endpoint} . '/v1/workspaces/' . $options{workspace_id} . '/query?query=' . $encoded_query . '×pan=' . $encoded_interval;
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub azure_get_log_analytics {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $full_url = $self->azure_get_log_analytics_set_url(%options);
|
||||||
|
my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => '');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|
|
@ -507,6 +507,22 @@ sub azure_list_sqldatabases {
|
||||||
return $raw_results;
|
return $raw_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub azure_get_log_analytics_set_cmd {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||||
|
|
||||||
|
my $cmd_options = "monitor log-analytics query --workspace '$options{workspace_id}' --analytics-query \"$options{query}\" --timespan '$options{interval}'";
|
||||||
|
return $cmd_options;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub azure_get_log_analytics {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $cmd_options = $self->azure_get_log_analytics_set_cmd(%options);
|
||||||
|
return $self->execute(cmd_options => $cmd_options);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
#
|
||||||
|
# Copyright 2020 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::monitor::mode::logs;
|
||||||
|
|
||||||
|
use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
sub set_counters {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{maps_counters_type} = [
|
||||||
|
{ name => 'global', type => 0 }
|
||||||
|
];
|
||||||
|
|
||||||
|
$self->{maps_counters}->{global} = [
|
||||||
|
{ label => 'total', nlabel => 'logs.total.count', set => {
|
||||||
|
key_values => [ { name => 'total' } ],
|
||||||
|
output_template => 'total logs: %s',
|
||||||
|
perfdatas => [
|
||||||
|
{ value => 'total_absolute', template => '%s', min => 0 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
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 => {
|
||||||
|
'workspace-id:s' => { name => 'workspace_id' },
|
||||||
|
'query:s' => { name => 'query'}
|
||||||
|
});
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
|
if (!defined($self->{option_results}->{workspace_id}) || $self->{option_results}->{workspace_id} eq '') {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Need to specify --workspace-id <id>.");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!defined($self->{option_results}->{query}) || $self->{option_results}->{query} eq '') {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Need to specify a query.");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my ($log_results) = $options{custom}->azure_get_log_analytics(
|
||||||
|
workspace_id => $self->{option_results}->{workspace_id},
|
||||||
|
query => $self->{option_results}->{query},
|
||||||
|
interval => $self->{az_interval}
|
||||||
|
);
|
||||||
|
|
||||||
|
$self->{global} = { total => 0 };
|
||||||
|
foreach my $table (@{$log_results->{tables}}) {
|
||||||
|
foreach (@{$table->{rows}}) {
|
||||||
|
$self->{global}->{total} += $_->[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 MODE
|
||||||
|
|
||||||
|
Check logs queries.
|
||||||
|
You should set option: --management-endpoint='https://api.loganalytics.io'
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=item B<--workspace-id>
|
||||||
|
|
||||||
|
Set workspace id (Required).
|
||||||
|
|
||||||
|
=item B<--query>
|
||||||
|
|
||||||
|
Set query (Required).
|
||||||
|
Syntax: https://docs.microsoft.com/en-us/azure/kusto/query/
|
||||||
|
|
||||||
|
=item B<--warning-*> B<--critical-*>
|
||||||
|
|
||||||
|
Thresholds.
|
||||||
|
Can be: count.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
|
@ -31,10 +31,11 @@ sub new {
|
||||||
|
|
||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
%{$self->{modes}} = (
|
%{$self->{modes}} = (
|
||||||
|
'alert' => 'cloud::azure::management::monitor::mode::alert',
|
||||||
'discovery' => 'cloud::azure::management::monitor::mode::discovery',
|
'discovery' => 'cloud::azure::management::monitor::mode::discovery',
|
||||||
'get-metrics' => 'cloud::azure::management::monitor::mode::getmetrics',
|
'get-metrics' => 'cloud::azure::management::monitor::mode::getmetrics',
|
||||||
'health' => 'cloud::azure::management::monitor::mode::health',
|
'health' => 'cloud::azure::management::monitor::mode::health',
|
||||||
'alert' => 'cloud::azure::management::monitor::mode::alert',
|
'logs' => 'cloud::azure::management::monitor::mode::logs'
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli';
|
$self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli';
|
||||||
|
|
Loading…
Reference in New Issue