| 1 |
# |
| 2 |
# Copyright 2024 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 network::cisco::meraki::cloudcontroller::restapi::mode::apirequests; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
|
| 29 |
sub set_counters { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{maps_counters_type} = [ |
| 33 |
{ name => 'organizations', type => 1, cb_prefix_output => 'prefix_organization_output', message_multiple => 'All organizations are ok' } |
| 34 |
]; |
| 35 |
|
| 36 |
$self->{maps_counters}->{organizations} = [ |
| 37 |
{ label => 'api-requests-200', nlabel => 'organization.api.requests.200.count', set => { |
| 38 |
key_values => [ { name => 'requests_200' }, { name => 'display' } ], |
| 39 |
output_template => 'code 200: %s', |
| 40 |
perfdatas => [ |
| 41 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 42 |
] |
| 43 |
} |
| 44 |
}, |
| 45 |
{ label => 'api-requests-404', nlabel => 'organization.api.requests.404.count', set => { |
| 46 |
key_values => [ { name => 'requests_404' }, { name => 'display' } ], |
| 47 |
output_template => 'code 404: %s', |
| 48 |
perfdatas => [ |
| 49 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 50 |
] |
| 51 |
} |
| 52 |
}, |
| 53 |
{ label => 'api-requests-429', nlabel => 'organization.api.requests.429.count', set => { |
| 54 |
key_values => [ { name => 'requests_429' }, { name => 'display' } ], |
| 55 |
output_template => 'code 429: %s', |
| 56 |
perfdatas => [ |
| 57 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 58 |
] |
| 59 |
} |
| 60 |
} |
| 61 |
]; |
| 62 |
} |
| 63 |
|
| 64 |
sub prefix_organization_output { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
return "Organization '" . $options{instance_value}->{display} . "' requests "; |
| 68 |
} |
| 69 |
|
| 70 |
sub new { |
| 71 |
my ($class, %options) = @_; |
| 72 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 73 |
bless $self, $class; |
| 74 |
|
| 75 |
$options{options}->add_options(arguments => { |
| 76 |
'filter-organization-name:s' => { name => 'filter_organization_name' } |
| 77 |
}); |
| 78 |
|
| 79 |
return $self; |
| 80 |
} |
| 81 |
|
| 82 |
sub manage_selection { |
| 83 |
my ($self, %options) = @_; |
| 84 |
|
| 85 |
my $orgs = $options{custom}->get_organizations(); |
| 86 |
|
| 87 |
$self->{organizations} = {}; |
| 88 |
foreach my $orgId (keys %$orgs) { |
| 89 |
next if (defined($self->{option_results}->{filter_organization_name}) && $self->{option_results}->{filter_organization_name} ne '' && |
| 90 |
$orgs->{orgId}->{name} !~ /$self->{option_results}->{filter_organization_name}/); |
| 91 |
my $api_requests = $options{custom}->get_organization_api_requests_overview(orgs => [$orgId]); |
| 92 |
$self->{organizations}->{$orgId} = { |
| 93 |
display => $orgs->{$orgId}->{name}, |
| 94 |
requests_200 => defined($api_requests->{$orgId}->{responseCodeCounts}->{200}) ? $api_requests->{$orgId}->{responseCodeCounts}->{200} : 0, |
| 95 |
requests_404 => defined($api_requests->{$orgId}->{responseCodeCounts}->{404}) ? $api_requests->{$orgId}->{responseCodeCounts}->{404} : 0, |
| 96 |
requests_429 => defined($api_requests->{$orgId}->{responseCodeCounts}->{429}) ? $api_requests->{$orgId}->{responseCodeCounts}->{429} : 0 |
| 97 |
}; |
| 98 |
} |
| 99 |
|
| 100 |
if (scalar(keys %{$self->{organizations}}) <= 0) { |
| 101 |
$self->{output}->add_option_msg(short_msg => "No organizations found."); |
| 102 |
$self->{output}->option_exit(); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
1; |
| 107 |
|
| 108 |
__END__ |
| 109 |
|
| 110 |
=head1 MODE |
| 111 |
|
| 112 |
Check api requests. |
| 113 |
|
| 114 |
=over 8 |
| 115 |
|
| 116 |
=item B<--filter-organization-name> |
| 117 |
|
| 118 |
Filter organization name (can be a regexp). |
| 119 |
|
| 120 |
=item B<--warning-*> B<--critical-*> |
| 121 |
|
| 122 |
Thresholds. |
| 123 |
Can be: 'api-requests-200', 'api-requests-404', 'api-requests-429'. |
| 124 |
|
| 125 |
=back |
| 126 |
|
| 127 |
=cut |