| 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 cloud::microsoft::office365::onedrive::mode::listsites; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 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 |
{ |
| 35 |
"filter-url:s" => { name => 'filter_url' }, |
| 36 |
"filter-owner:s" => { name => 'filter_owner' }, |
| 37 |
}); |
| 38 |
|
| 39 |
return $self; |
| 40 |
} |
| 41 |
|
| 42 |
sub check_options { |
| 43 |
my ($self, %options) = @_; |
| 44 |
$self->SUPER::check_options(%options); |
| 45 |
} |
| 46 |
|
| 47 |
sub manage_selection { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
my $results = $options{custom}->office_get_onedrive_usage(param => "period='D7'"); |
| 51 |
|
| 52 |
foreach my $site (@{$results}) { |
| 53 |
if (defined($self->{option_results}->{filter_url}) && $self->{option_results}->{filter_url} ne '' && |
| 54 |
$site->{'Site URL'} !~ /$self->{option_results}->{filter_url}/) { |
| 55 |
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no matching filter name.", debug => 1); |
| 56 |
next; |
| 57 |
} |
| 58 |
if (defined($self->{option_results}->{filter_owner}) && $self->{option_results}->{filter_owner} ne '' && |
| 59 |
$site->{'Owner Display Name'} !~ /$self->{option_results}->{filter_owner}/) { |
| 60 |
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Owner Display Name'} . "': no matching filter name.", debug => 1); |
| 61 |
next; |
| 62 |
} |
| 63 |
|
| 64 |
$self->{sites}->{$site->{'Site URL'}} = { |
| 65 |
owner => $site->{'Owner Display Name'}, |
| 66 |
url => $site->{'Site URL'}, |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
sub run { |
| 72 |
my ($self, %options) = @_; |
| 73 |
|
| 74 |
$self->manage_selection(%options); |
| 75 |
foreach my $site (sort keys %{$self->{sites}}) { |
| 76 |
$self->{output}->output_add(long_msg => sprintf("[owner = %s] [url = %s]", |
| 77 |
$self->{sites}->{$site}->{owner}, |
| 78 |
$self->{sites}->{$site}->{url})); |
| 79 |
} |
| 80 |
|
| 81 |
$self->{output}->output_add(severity => 'OK', |
| 82 |
short_msg => 'List sites:'); |
| 83 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 84 |
$self->{output}->exit(); |
| 85 |
} |
| 86 |
|
| 87 |
sub disco_format { |
| 88 |
my ($self, %options) = @_; |
| 89 |
|
| 90 |
$self->{output}->add_disco_format(elements => ['owner', 'url']); |
| 91 |
} |
| 92 |
|
| 93 |
sub disco_show { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
$self->manage_selection(%options); |
| 97 |
foreach my $site (sort keys %{$self->{sites}}) { |
| 98 |
$self->{output}->add_disco_entry( |
| 99 |
owner => $self->{sites}->{$site}->{owner}, |
| 100 |
url => $self->{sites}->{$site}->{url}, |
| 101 |
); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
1; |
| 106 |
|
| 107 |
__END__ |
| 108 |
|
| 109 |
=head1 MODE |
| 110 |
|
| 111 |
List sites. |
| 112 |
|
| 113 |
=over 8 |
| 114 |
|
| 115 |
=item B<--filter-*> |
| 116 |
|
| 117 |
Filter sites. |
| 118 |
Can be: 'url', 'id' (can be a regexp). |
| 119 |
|
| 120 |
=back |
| 121 |
|
| 122 |
=cut |