| 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 apps::monitoring::iplabel::ekara::restapi::mode::discovery; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use JSON::XS; |
| 28 |
|
| 29 |
sub new { |
| 30 |
my ($class, %options) = @_; |
| 31 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 32 |
bless $self, $class; |
| 33 |
|
| 34 |
$options{options}->add_options(arguments => { |
| 35 |
'prettify' => { name => 'prettify' } |
| 36 |
}); |
| 37 |
|
| 38 |
return $self; |
| 39 |
} |
| 40 |
|
| 41 |
sub check_options { |
| 42 |
my ($self, %options) = @_; |
| 43 |
$self->SUPER::init(%options); |
| 44 |
} |
| 45 |
|
| 46 |
sub run { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
my $disco_stats; |
| 50 |
$disco_stats->{start_time} = time(); |
| 51 |
|
| 52 |
my $results = $options{custom}->request_api(endpoint => '/results-api/scenarios/status', method => 'GET'); |
| 53 |
|
| 54 |
$disco_stats->{end_time} = time(); |
| 55 |
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; |
| 56 |
$disco_stats->{discovered_items} = scalar(@$results); |
| 57 |
$disco_stats->{results} = $results; |
| 58 |
|
| 59 |
my $encoded_data; |
| 60 |
eval { |
| 61 |
if (defined($self->{option_results}->{prettify})) { |
| 62 |
$encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); |
| 63 |
} else { |
| 64 |
$encoded_data = JSON::XS->new->utf8->encode($disco_stats); |
| 65 |
} |
| 66 |
}; |
| 67 |
if ($@) { |
| 68 |
$encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; |
| 69 |
} |
| 70 |
|
| 71 |
$self->{output}->output_add(short_msg => $encoded_data); |
| 72 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); |
| 73 |
$self->{output}->exit(); |
| 74 |
} |
| 75 |
|
| 76 |
1; |
| 77 |
|
| 78 |
__END__ |
| 79 |
|
| 80 |
=head1 MODE |
| 81 |
|
| 82 |
IP Label Ekara scenarios discovery. |
| 83 |
|
| 84 |
=over 8 |
| 85 |
|
| 86 |
=back |
| 87 |
|
| 88 |
=cut |