| 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::sailpoint::identitynow::restapi::mode::listsources; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
$options{options}->add_options(arguments => { |
| 34 |
'filter-name:s' => { name => 'filter_name' } |
| 35 |
}); |
| 36 |
|
| 37 |
return $self; |
| 38 |
} |
| 39 |
|
| 40 |
sub check_options { |
| 41 |
my ($self, %options) = @_; |
| 42 |
$self->SUPER::init(%options); |
| 43 |
} |
| 44 |
|
| 45 |
sub manage_selection { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
my $sources = $options{custom}->get_sources(); |
| 49 |
my $results = []; |
| 50 |
foreach my $source (@{$sources}) { |
| 51 |
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 52 |
$source->{name} !~ /$self->{option_results}->{filter_name}/); |
| 53 |
|
| 54 |
push @$results, { |
| 55 |
id => $source->{id}, |
| 56 |
name => $source->{name}, |
| 57 |
description => $source->{description}, |
| 58 |
type => $source->{type}, |
| 59 |
status => $source->{status} |
| 60 |
}; |
| 61 |
} |
| 62 |
|
| 63 |
return $results; |
| 64 |
} |
| 65 |
|
| 66 |
sub run { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
my $sources = $self->manage_selection(%options); |
| 70 |
foreach my $source (@$sources) { |
| 71 |
$self->{output}->output_add( |
| 72 |
long_msg => sprintf( |
| 73 |
"[id: %s][name: %s][description: %s][type: %s][status: %s]", |
| 74 |
$source->{id}, |
| 75 |
$source->{name}, |
| 76 |
$source->{description}, |
| 77 |
$source->{type}, |
| 78 |
$source->{status} |
| 79 |
) |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
$self->{output}->output_add( |
| 84 |
severity => 'OK', |
| 85 |
short_msg => 'List sources:' |
| 86 |
); |
| 87 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 88 |
$self->{output}->exit(); |
| 89 |
} |
| 90 |
|
| 91 |
sub disco_format { |
| 92 |
my ($self, %options) = @_; |
| 93 |
|
| 94 |
$self->{output}->add_disco_format(elements => ['id', 'name', 'description', 'type', 'status']); |
| 95 |
} |
| 96 |
|
| 97 |
sub disco_show { |
| 98 |
my ($self, %options) = @_; |
| 99 |
|
| 100 |
my $sources = $self->manage_selection(%options); |
| 101 |
foreach my $source (@$sources) { |
| 102 |
$self->{output}->add_disco_entry(%$source); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
1; |
| 107 |
|
| 108 |
__END__ |
| 109 |
|
| 110 |
=head1 MODE |
| 111 |
|
| 112 |
List sources. |
| 113 |
|
| 114 |
=over 8 |
| 115 |
|
| 116 |
=item B<--filter-name> |
| 117 |
|
| 118 |
Filter source name (can be a regexp). |
| 119 |
|
| 120 |
=back |
| 121 |
|
| 122 |
=cut |