| 1 |
# |
| 2 |
# Copyright 2020 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package cloud::azure::network::publicip::mode::ddostraffic; |
| 22 |
|
| 23 |
use base qw(cloud::azure::custom::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub get_metrics_mapping { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
my $metrics_mapping = { |
| 32 |
'bytesdroppedddos' => { |
| 33 |
'output' => 'Inbound bytes dropped DDoS', |
| 34 |
'label' => 'ddos-dropped', |
| 35 |
'nlabel' => 'publicip.ddos.dropped.bytes', |
| 36 |
'unit' => 'B', |
| 37 |
'min' => '0' |
| 38 |
}, |
| 39 |
'bytesforwardedddos' => { |
| 40 |
'output' => 'Inbound bytes forwarded DDoS', |
| 41 |
'label' => 'ddos-forwarded', |
| 42 |
'nlabel' => 'publicip.ddos.forwarded.bytes', |
| 43 |
'unit' => 'B', |
| 44 |
'min' => '0' |
| 45 |
}, |
| 46 |
'bytesinddos' => { |
| 47 |
'output' => 'Inbound bytes DDoS', |
| 48 |
'label' => 'ddos-inbound', |
| 49 |
'nlabel' => 'publicip.ddos.inbound.bytes', |
| 50 |
'unit' => 'B', |
| 51 |
'min' => '0' |
| 52 |
}, |
| 53 |
'packetsdroppedddos' => { |
| 54 |
'output' => 'Inbound packets dropped DDoS', |
| 55 |
'label' => 'ddos-dropped-packets', |
| 56 |
'nlabel' => 'publicip.ddos.packets.countpersecond', |
| 57 |
'unit' => '/s', |
| 58 |
'min' => '0' |
| 59 |
}, |
| 60 |
'packetsforwardedddos' => { |
| 61 |
'output' => 'Inbound packets forwarded DDoS', |
| 62 |
'label' => 'ddos-forwarded-packets', |
| 63 |
'nlabel' => 'publicip.ddos.forwarded.countpersecond', |
| 64 |
'unit' => '/s', |
| 65 |
'min' => '0' |
| 66 |
}, |
| 67 |
'packetsinddos' => { |
| 68 |
'output' => 'Inbound packets DDoS', |
| 69 |
'label' => 'ddos-inbound-packets', |
| 70 |
'nlabel' => 'publicip.ddos.inbound.packets.countpersecond', |
| 71 |
'unit' => '/s', |
| 72 |
'min' => '0' |
| 73 |
} |
| 74 |
}; |
| 75 |
|
| 76 |
return $metrics_mapping; |
| 77 |
} |
| 78 |
|
| 79 |
sub new { |
| 80 |
my ($class, %options) = @_; |
| 81 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 82 |
bless $self, $class; |
| 83 |
|
| 84 |
$options{options}->add_options(arguments => { |
| 85 |
'filter-metric:s' => { name => 'filter_metric' }, |
| 86 |
'resource:s' => { name => 'resource' }, |
| 87 |
'resource-group:s' => { name => 'resource_group' } |
| 88 |
}); |
| 89 |
|
| 90 |
return $self; |
| 91 |
} |
| 92 |
|
| 93 |
sub check_options { |
| 94 |
my ($self, %options) = @_; |
| 95 |
$self->SUPER::check_options(%options); |
| 96 |
|
| 97 |
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') { |
| 98 |
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.'); |
| 99 |
$self->{output}->option_exit(); |
| 100 |
} |
| 101 |
my $resource = $self->{option_results}->{resource}; |
| 102 |
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; |
| 103 |
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Network\/publicIPAddresses\/(.*)$/) { |
| 104 |
$resource_group = $1; |
| 105 |
$resource = $2; |
| 106 |
} |
| 107 |
|
| 108 |
$self->{az_resource} = $resource; |
| 109 |
$self->{az_resource_group} = $resource_group; |
| 110 |
$self->{az_resource_type} = 'publicIPAddresses'; |
| 111 |
$self->{az_resource_namespace} = 'Microsoft.Network'; |
| 112 |
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; |
| 113 |
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; |
| 114 |
$self->{az_aggregations} = ['Maximum']; |
| 115 |
if (defined($self->{option_results}->{aggregation})) { |
| 116 |
$self->{az_aggregations} = []; |
| 117 |
foreach my $stat (@{$self->{option_results}->{aggregation}}) { |
| 118 |
if ($stat ne '') { |
| 119 |
push @{$self->{az_aggregations}}, ucfirst(lc($stat)); |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
foreach my $metric (keys %{$self->{metrics_mapping}}) { |
| 125 |
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' |
| 126 |
&& $metric !~ /$self->{option_results}->{filter_metric}/); |
| 127 |
|
| 128 |
push @{$self->{az_metrics}}, $metric; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
1; |
| 133 |
|
| 134 |
__END__ |
| 135 |
|
| 136 |
=head1 MODE |
| 137 |
|
| 138 |
Check Azure Public IP DDOS traffic metrics. |
| 139 |
|
| 140 |
Example: |
| 141 |
|
| 142 |
Using resource name: |
| 143 |
|
| 144 |
perl centreon_plugins.pl --plugin=cloud::azure::network::publicip::plugin --mode=ddos-traffic --custommode=api |
| 145 |
--resource=<publicip_id> --resource-group=<resourcegroup_id> --aggregation='maximum' |
| 146 |
--warning-ddos-inbound-packets='1000' --critical-ddos-inbound-packets='2000' |
| 147 |
|
| 148 |
Using resource ID: |
| 149 |
|
| 150 |
perl centreon_plugins.pl --plugin=cloud::azure::network::publicip::plugin --mode=ddos-traffic --custommode=api |
| 151 |
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Network/publicIPAddresses/<publicip_id>' |
| 152 |
--aggregation='maximum' --warning-ddos-inbound-packets='1000' --critical-ddos-inbound-packets='2000' |
| 153 |
|
| 154 |
Default aggregation: 'maximum' / 'average', 'total', 'minimum' and 'maximum' are valid. |
| 155 |
|
| 156 |
=over 8 |
| 157 |
|
| 158 |
=item B<--resource> |
| 159 |
|
| 160 |
Set resource name or ID (required). |
| 161 |
|
| 162 |
=item B<--resource-group> |
| 163 |
|
| 164 |
Set resource group (required if resource's name is used). |
| 165 |
|
| 166 |
=item B<---warning-*> |
| 167 |
|
| 168 |
Warning threshold where '*' can be: |
| 169 |
'ddos-dropped', 'ddos-forwarded', 'ddos-inbound', 'ddos-dropped-packets', |
| 170 |
'ddos-forwarded-packets', 'ddos-inbound-packets'. |
| 171 |
|
| 172 |
=item B<--critical-*> |
| 173 |
|
| 174 |
Critical threshold where '*' can be: |
| 175 |
'ddos-dropped', 'ddos-forwarded', 'ddos-inbound', 'ddos-dropped-packets', |
| 176 |
'ddos-forwarded-packets', 'ddos-inbound-packets'. |
| 177 |
|
| 178 |
=back |
| 179 |
|
| 180 |
=cut |