Add dedicated folder for loganalytics / kusto query (#2464)

This commit is contained in:
Simon Bomm 2020-12-30 11:40:46 +01:00 committed by GitHub
parent 9b7b78b426
commit b7bcd002fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 109 additions and 15 deletions

View File

@ -18,12 +18,35 @@
# limitations under the License.
#
package cloud::azure::management::monitor::mode::logs;
package cloud::azure::management::loganalytics::mode::kustoquery;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
sub custom_match_output {
my ($self, %options) = @_;
my $msg;
my $message;
if (defined($self->{instance_mode}->{option_results}->{custom_output}) && $self->{instance_mode}->{option_results}->{custom_output} ne '') {
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
$msg = sprintf("$self->{instance_mode}->{option_results}->{custom_output}", eval $self->{result_values}->{match});
};
} else {
$msg = sprintf("Total logs match '%d'", $self->{result_values}->{match});
}
if (defined($message)) {
$self->{output}->output_add(long_msg => 'printf substitution issue: ' . $message);
}
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
@ -33,11 +56,11 @@ sub set_counters {
];
$self->{maps_counters}->{global} = [
{ label => 'total', nlabel => 'logs.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'total logs: %s',
{ label => 'match', nlabel => 'match.count', set => {
key_values => [ { name => 'match' } ],
closure_custom_output => $self->can('custom_match_output'),
perfdatas => [
{ value => 'total', template => '%s', min => 0 }
{ template => '%s', min => 0 }
]
}
}
@ -50,8 +73,9 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'workspace-id:s' => { name => 'workspace_id' },
'query:s' => { name => 'query'}
'workspace-id:s' => { name => 'workspace_id' },
'query:s' => { name => 'query'},
'custom-output:s' => { name => 'custom_output'}
});
return $self;
@ -69,7 +93,7 @@ sub check_options {
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';
}
@ -83,10 +107,10 @@ sub manage_selection {
interval => $self->{az_interval}
);
$self->{global} = { total => 0 };
$self->{global} = { match => 0 };
foreach my $table (@{$log_results->{tables}}) {
foreach (@{$table->{rows}}) {
$self->{global}->{total} += $_->[0];
$self->{global}->{match}++;
}
}
}
@ -97,8 +121,16 @@ __END__
=head1 MODE
Check logs queries.
You should set option: --management-endpoint='https://api.loganalytics.io'
Perform a Kusto query and count results
Sample command:
perl centreon_plugins.pl --plugin=cloud::azure::management::loganalytics::plugin \
--custommode api --management-endpoint='https://api.loganalytics.io' --mode kusto-query \
--subscription=*********************** --tenant=*********************** \
--client-id=*********************** --client-secret=*********************** --workspace-id=*********************** \
--query 'Heartbeat | summarize LastCall = max(TimeGenerated) by Computer | where LastCall > ago(3d)' \
--custom-output='Number of syslog %d'
OK: Number of Syslog '2' | 'match.count'=2;;;0;
=over 8
@ -111,10 +143,14 @@ Set workspace id (Required).
Set query (Required).
Syntax: https://docs.microsoft.com/en-us/azure/kusto/query/
=item B<--warning-*> B<--critical-*>
=item B<--custom-output>
Set a custom message to output in printf format.
Exemple: 'Number of Syslog message collected %d'
=item B<--warning-match> B<--critical-match>
Thresholds.
Can be: count.
=back

View File

@ -0,0 +1,59 @@
#
# 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::loganalytics::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ( $class, %options ) = @_;
my $self = $class->SUPER::new( package => __PACKAGE__, %options );
bless $self, $class;
$self->{version} = '0.1';
%{ $self->{modes} } = (
'kusto-query' => 'cloud::azure::management::loganalytics::mode::kustoquery',
);
$self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli';
$self->{custom_modes}{api} = 'cloud::azure::custom::api';
return $self;
}
sub init {
my ($self, %options) = @_;
$self->{options}->add_options(arguments => {
'api-version:s' => { name => 'api_version', default => '2018-01-01' },
});
$self->SUPER::init(%options);
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Microsoft Azure Log Analytics
=cut

View File

@ -35,7 +35,6 @@ sub new {
'discovery' => 'cloud::azure::management::monitor::mode::discovery',
'get-metrics' => 'cloud::azure::management::monitor::mode::getmetrics',
'health' => 'cloud::azure::management::monitor::mode::health',
'logs' => 'cloud::azure::management::monitor::mode::logs'
);
$self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli';