From 920f5f903f56aacd2c2221436a7f6720080a2e5a Mon Sep 17 00:00:00 2001 From: Thibault S <48209914+thibaults-centreon@users.noreply.github.com> Date: Mon, 25 Jan 2021 11:07:53 +0100 Subject: [PATCH] add(plugin): Azure Load Balancer (#2536) --- cloud/azure/custom/mode.pm | 216 ++++++++++++++++++ .../network/loadbalancer/mode/datapath.pm | 141 ++++++++++++ .../network/loadbalancer/mode/discovery.pm | 60 +++++ .../network/loadbalancer/mode/healthprobe.pm | 142 ++++++++++++ cloud/azure/network/loadbalancer/mode/snat.pm | 161 +++++++++++++ .../network/loadbalancer/mode/throughput.pm | 152 ++++++++++++ cloud/azure/network/loadbalancer/plugin.pm | 64 ++++++ 7 files changed, 936 insertions(+) create mode 100644 cloud/azure/custom/mode.pm create mode 100644 cloud/azure/network/loadbalancer/mode/datapath.pm create mode 100644 cloud/azure/network/loadbalancer/mode/discovery.pm create mode 100644 cloud/azure/network/loadbalancer/mode/healthprobe.pm create mode 100644 cloud/azure/network/loadbalancer/mode/snat.pm create mode 100644 cloud/azure/network/loadbalancer/mode/throughput.pm create mode 100644 cloud/azure/network/loadbalancer/plugin.pm diff --git a/cloud/azure/custom/mode.pm b/cloud/azure/custom/mode.pm new file mode 100644 index 000000000..558e53a5f --- /dev/null +++ b/cloud/azure/custom/mode.pm @@ -0,0 +1,216 @@ +# +# 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::custom::mode; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +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 => { + 'filter-dimension:s' => { name => 'filter_dimension' }, + 'per-sec' => { name => 'per_second'} + }); + + $options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MODE OPTIONS', once => 1); + + return $self; +} + +sub custom_metric_calc { + my ($self, %options) = @_; + + $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; + $self->{result_values}->{value}->{absolute} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; + $self->{result_values}->{value}->{per_second} = $self->{result_values}->{value}->{absolute} / $self->{result_values}->{timeframe}; + $self->{result_values}->{metric} = $options{extra_options}->{metric}; + return 0; +} + +sub custom_metric_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check( + value => defined($self->{instance_mode}->{option_results}->{per_second}) ? $self->{result_values}->{value}->{per_second} : $self->{result_values}->{value}->{absolute}, + threshold => [ + { label => 'critical-' . $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{label} , exit_litteral => 'critical' }, + { label => 'warning-' . $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } + ] + ); + return $exit; +} + +sub custom_metric_perfdata { + my ($self, %options) = @_; + my $options = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}; + my $value = defined($self->{instance_mode}->{option_results}->{per_second}) ? $self->{result_values}->{value}->{per_second} : $self->{result_values}->{value}->{absolute}; + my $format = defined($self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{template}) ? $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{template} : '%.2f'; + if (defined($self->{instance_mode}->{option_results}->{per_second})) { + $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{nlabel} .= '.persecond'; + $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{unit} .= '/s'; + } + + $self->{output}->perfdata_add( + instances => $self->{instance}, + value => sprintf($format, $value), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{label}), + %{$options} + ); +} + +sub custom_metric_output { + my ($self, %options) = @_; + + my ($value, $unit) = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{unit} eq 'B' ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}->{absolute}) : + ($self->{result_values}->{value}->{absolute}, $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{unit}); + + if (defined($self->{instance_mode}->{option_results}->{per_second})) { + ($value, $unit) = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{unit} eq 'B' ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}->{per_second}) : + ($self->{result_values}->{value}->{per_second}, $unit); + $unit .= '/s'; + } + my $format = defined($self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{template}) ? $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{template} : '%.2f'; + + return sprintf('%s: ' . $format . '%s', $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{output}, $value, $unit); +} + +sub prefix_metric_output { + my ($self, %options) = @_; + + return "Instance '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + $self->{metrics_mapping} = $self->get_metrics_mapping; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } } + ] + } + ]; + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + my $entry = { + label => $self->{metrics_mapping}->{$metric}->{label}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold') + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + my $raw_results; + + if (defined($self->{option_results}->{filter_dimension}) && $self->{option_results}->{filter_dimension} ne '') { + $self->{az_dimension} = $self->{option_results}->{filter_dimension}; + } + + ($metric_results{$self->{az_resource}}, $raw_results) = $options{custom}->azure_get_metrics( + aggregations => $self->{az_aggregations}, + dimension => $self->{az_dimension}, + interval => $self->{az_interval}, + metrics => $self->{az_metrics}, + resource => $self->{az_resource}, + resource_group => $self->{az_resource_group}, + resource_namespace => $self->{az_resource_namespace}, + resource_type => $self->{az_resource_type}, + timeframe => $self->{az_timeframe} + ); + + foreach my $metric (@{$self->{az_metrics}}) { + foreach my $aggregation (@{$self->{az_aggregations}}) { + next if (!defined($metric_results{$self->{az_resource}}->{$metric}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$self->{az_resource}}->{display} = $self->{az_resource}; + $self->{metrics}->{$self->{az_resource}}->{statistics}->{lc($aggregation)}->{display} = lc($aggregation); + $self->{metrics}->{$self->{az_resource}}->{statistics}->{lc($aggregation)}->{timeframe} = $self->{az_timeframe}; + $self->{metrics}->{$self->{az_resource}}->{statistics}->{lc($aggregation)}->{$metric} = + defined($metric_results{$self->{az_resource}}->{$metric}->{lc($aggregation)}) ? + $metric_results{$self->{az_resource}}->{$metric}->{lc($aggregation)} : 0; + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Azure custom class for monitor based modes. + +=head1 CUSTOM MODE OPTIONS + +=over 8 + +=item B<--filter-dimension> + +Specify the metric dimension (required for some specific metrics) +Syntax example: +--filter-dimension="$metricname eq '$metricvalue'" + +=item B<--per-sec> + +Display the statistics based on a per-second period. + +=back + +=cut diff --git a/cloud/azure/network/loadbalancer/mode/datapath.pm b/cloud/azure/network/loadbalancer/mode/datapath.pm new file mode 100644 index 000000000..4e98545c3 --- /dev/null +++ b/cloud/azure/network/loadbalancer/mode/datapath.pm @@ -0,0 +1,141 @@ +# +# 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::network::loadbalancer::mode::datapath; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'vipavailability' => { + 'output' => 'Data Path (VIP) Availability', + 'label' => 'datapath-availability-percentage', + 'nlabel' => 'loadbalancer.datapath.availability.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '100' + } + }; + + return $metrics_mapping; +} + +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 => { + 'filter-metric:s' => { name => 'filter_metric' }, + 'resource:s' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' } + }); + + return $self; +} + +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 with --resource-group option or --resource .'); + $self->{output}->option_exit(); + } + 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\.Network\/loadBalancers\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'loadBalancers'; + $self->{az_resource_namespace} = 'Microsoft.Network'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; + $self->{az_aggregations} = ['Average']; + if (defined($self->{option_results}->{aggregation})) { + $self->{az_aggregations} = []; + foreach my $stat (@{$self->{option_results}->{aggregation}}) { + if ($stat ne '') { + push @{$self->{az_aggregations}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + push @{$self->{az_metrics}}, $metric; + } +} + +1; + +__END__ + +=head1 MODE + +Check Azure Network Load Balancers Data Path metrics. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::network::loadbalancer::plugin --mode=datapath --custommode=azcli +--resource= --resource-group= --aggregation='average' +--warning-datapath-availability-percentage='100:' --critical-datapath-availability-percentage='50:' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::network::loadbalancer::plugin --mode=datapath --custommode=azcli +--resource='/subscriptions//resourceGroups//providers/Microsoft.Network/loadBalancers/' +--aggregation='average' --warning-datapath-availability-percentage='100:' --critical-datapath-availability-percentage='50:' + +Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-datapath-availability-percentage> + +Warning threshold. + +=item B<--critical-datapath-availability-percentage> + +Critical threshold. + +=back + +=cut diff --git a/cloud/azure/network/loadbalancer/mode/discovery.pm b/cloud/azure/network/loadbalancer/mode/discovery.pm new file mode 100644 index 000000000..18c2cd0af --- /dev/null +++ b/cloud/azure/network/loadbalancer/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# 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::network::loadbalancer::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Network'; + $self->{type} = 'loadBalancers'; +} + +1; + +__END__ + +=head1 MODE + +Azure Load Balancers discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/cloud/azure/network/loadbalancer/mode/healthprobe.pm b/cloud/azure/network/loadbalancer/mode/healthprobe.pm new file mode 100644 index 000000000..eaaaadd95 --- /dev/null +++ b/cloud/azure/network/loadbalancer/mode/healthprobe.pm @@ -0,0 +1,142 @@ +# +# 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::network::loadbalancer::mode::healthprobe; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'dipavailability' => { + 'output' => 'Health probe status (DIP) availability', + 'label' => 'healthprobe-availibility-percentage', + 'nlabel' => 'loadbalancer.healthprobe.availability.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '100' + } + }; + + return $metrics_mapping; +} + +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 => { + 'filter-metric:s' => { name => 'filter_metric' }, + 'resource:s' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' } + }); + + return $self; +} + +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 with --resource-group option or --resource .'); + $self->{output}->option_exit(); + } + 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\.Network\/loadBalancers\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'loadBalancers'; + $self->{az_resource_namespace} = 'Microsoft.Network'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; + $self->{az_aggregations} = ['Average']; + if (defined($self->{option_results}->{aggregation})) { + $self->{az_aggregations} = []; + foreach my $stat (@{$self->{option_results}->{aggregation}}) { + if ($stat ne '') { + push @{$self->{az_aggregations}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{az_metrics}}, $metric; + } +} + +1; + +__END__ + +=head1 MODE + +Check Azure Network Load Balancers DIP metrics. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::network::loadbalancer::plugin --mode=healthprobe --custommode=azcli +--resource= --resource-group= --aggregation='average' +--warning-healthprobe-availibility-percentage=100: --critical-healthprobe-availibility-percentage='50:' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::network::loadbalancer::plugin --mode=datapath --custommode=azcli +--resource='/subscriptions//resourceGroups//providers/Microsoft.Network/loadBalancers/' +--aggregation='average' --warning-healthprobe-availibility-percentage=100: --critical-healthprobe-availibility-percentage='50:' + +Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<---warning-healthprobe-availibility-percentage> + +Warning threshold. + +=item B<--critical-healthprobe-availibility-percentage> + +Critical threshold. + +=back + +=cut diff --git a/cloud/azure/network/loadbalancer/mode/snat.pm b/cloud/azure/network/loadbalancer/mode/snat.pm new file mode 100644 index 000000000..63a6bbbd2 --- /dev/null +++ b/cloud/azure/network/loadbalancer/mode/snat.pm @@ -0,0 +1,161 @@ +# +# 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::network::loadbalancer::mode::snat; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'allocatedsnatports' => { + 'output' => 'Allocated SNAT Ports', + 'label' => 'snat-ports-allocated', + 'nlabel' => 'loadbalancer.snat.ports.allocated.count', + 'unit' => '', + 'template' => '%s', + 'min' => '0' + }, + 'snatconnectioncount' => { + 'output' => 'SNAT Connection Count', + 'label' => 'snat-connection-count', + 'nlabel' => 'loadbalancer.snat.connection.count', + 'unit' => '', + 'min' => '0' + }, + 'usedsnatports' => { + 'output' => 'Used SNAT Ports', + 'label' => 'snat-ports-used', + 'nlabel' => 'loadbalancer.snat.ports.used.count', + 'unit' => '', + 'min' => '0' + } + }; + + return $metrics_mapping; +} + +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 => { + 'filter-metric:s' => { name => 'filter_metric' }, + 'resource:s' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' } + }); + + return $self; +} + +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 with --resource-group option or --resource .'); + $self->{output}->option_exit(); + } + + 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\.Network\/loadBalancers\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'loadBalancers'; + $self->{az_resource_namespace} = 'Microsoft.Network'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; + $self->{az_aggregations} = ['Average']; + if (defined($self->{option_results}->{aggregation})) { + $self->{az_aggregations} = []; + foreach my $stat (@{$self->{option_results}->{aggregation}}) { + if ($stat ne '') { + push @{$self->{az_aggregations}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + push @{$self->{az_metrics}}, $metric; + } +} + +1; + +__END__ + +=head1 MODE + +Check Azure Network Load Balancers SNAT metrics. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::network::loadbalancer::plugin --mode=snat --custommode=azcli +--resource= --resource-group= --aggregation='average' +--warning-snat-connection-count='800' --critical-snat-connection-count=='900' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::network::loadbalancer::plugin --mode=datapath --custommode=azcli +--resource='/subscriptions//resourceGroups//providers/Microsoft.Network/loadBalancers/' +--aggregation='average' --warning-snat-connection-count='800' --critical-snat-connection-count=='900' + +Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--filter-metric> + +Filter on specific metrics. The Azure format must be used, for example: 'sessions_percent' +(Can be a regexp). + +=item B<---warning-*> + +Warning threshold where * can be: snat-connection-count, snat-ports-used, snat-ports-allocated. + +=item B<--critical-*> + +Critical threshold where * can be: snat-connection-count, snat-ports-used, snat-ports-allocated.. + +=back + +=cut diff --git a/cloud/azure/network/loadbalancer/mode/throughput.pm b/cloud/azure/network/loadbalancer/mode/throughput.pm new file mode 100644 index 000000000..9f503d811 --- /dev/null +++ b/cloud/azure/network/loadbalancer/mode/throughput.pm @@ -0,0 +1,152 @@ +# +# 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::network::loadbalancer::mode::throughput; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'bytecount' => { + 'output' => 'Byte Count', + 'label' => 'throughput-bytes', + 'nlabel' => 'loadbalancer.throughput.bytes', + 'unit' => 'B', + 'min' => '0' + }, + 'packetcount' => { + 'output' => 'Packet Count', + 'label' => 'throughput-packets', + 'nlabel' => 'loadbalancer.packets.count', + 'unit' => '', + 'min' => '0' + } + }; + + return $metrics_mapping; +} + +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 => { + 'filter-metric:s' => { name => 'filter_metric' }, + 'resource:s' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' } + }); + + return $self; +} + +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 with --resource-group option or --resource .'); + $self->{output}->option_exit(); + } + 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\.Network\/loadBalancers\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'loadBalancers'; + $self->{az_resource_namespace} = 'Microsoft.Network'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; + $self->{az_aggregations} = ['Average']; + if (defined($self->{option_results}->{aggregation})) { + $self->{az_aggregations} = []; + foreach my $stat (@{$self->{option_results}->{aggregation}}) { + if ($stat ne '') { + push @{$self->{az_aggregations}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{az_metrics}}, $metric; + } +} + +1; + +__END__ + +=head1 MODE + +Check Azure Network Load Balancers throughput metrics. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::network::loadbalancer::plugin --mode=throughput --custommode=azcli +--resource= --resource-group= --aggregation='average' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::network::loadbalancer::plugin --mode=datapath --custommode=azcli +--resource='/subscriptions//resourceGroups//providers/Microsoft.Network/loadBalancers/' +--aggregation='average' + +Default aggregation: 'average' / 'minimum' and 'maximum' are valid. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--filter-metric> + +Filter on specific metrics. The Azure format must be used, for example: 'sessions_percent' +(Can be a regexp). + +=item B<---warning-*> + +Warning threshold where * can be: throughput-packets, throughput-bytes. + +=item B<--critical-*> + +Critical threshold where * can be: throughput-packets, throughput-bytes. + +=back + +=cut diff --git a/cloud/azure/network/loadbalancer/plugin.pm b/cloud/azure/network/loadbalancer/plugin.pm new file mode 100644 index 000000000..a014ae73d --- /dev/null +++ b/cloud/azure/network/loadbalancer/plugin.pm @@ -0,0 +1,64 @@ +# +# 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::network::loadbalancer::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} = { + 'datapath' => 'cloud::azure::network::loadbalancer::mode::datapath', + 'discovery' => 'cloud::azure::network::loadbalancer::mode::discovery', + 'healthprobe' => 'cloud::azure::network::loadbalancer::mode::healthprobe', + 'snat' => 'cloud::azure::network::loadbalancer::mode::snat', + 'throughput' => 'cloud::azure::network::loadbalancer::mode::throughput' + }; + + $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 Network LoadBalancers. + +=cut