enh office365 onedrive plugin

This commit is contained in:
Colin Gagnaire 2018-12-24 16:33:50 +01:00
parent d01628dc66
commit 9ecc0ccca8
2 changed files with 13 additions and 12 deletions

View File

@ -18,7 +18,7 @@
# limitations under the License. # limitations under the License.
# #
package cloud::microsoft::office365::sharepoint::mode::listsites; package cloud::microsoft::office365::onedrive::mode::listsites;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
@ -34,7 +34,7 @@ sub new {
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"filter-url:s" => { name => 'filter_url' }, "filter-url:s" => { name => 'filter_url' },
"filter-id:s" => { name => 'filter_id' }, "filter-owner:s" => { name => 'filter_owner' },
}); });
return $self; return $self;
@ -48,7 +48,7 @@ sub check_options {
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $results = $options{custom}->office_get_sharepoint_site_usage(); my $results = $options{custom}->office_get_onedrive_usage();
foreach my $site (@{$results}) { foreach my $site (@{$results}) {
if (defined($self->{option_results}->{filter_url}) && $self->{option_results}->{filter_url} ne '' && if (defined($self->{option_results}->{filter_url}) && $self->{option_results}->{filter_url} ne '' &&
@ -56,14 +56,14 @@ sub manage_selection {
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no matching filter name.", debug => 1); $self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no matching filter name.", debug => 1);
next; next;
} }
if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' && if (defined($self->{option_results}->{filter_owner}) && $self->{option_results}->{filter_owner} ne '' &&
$site->{'Site Id'} !~ /$self->{option_results}->{filter_id}/) { $site->{'Owner Display Name'} !~ /$self->{option_results}->{filter_owner}/) {
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site Id'} . "': no matching filter name.", debug => 1); $self->{output}->output_add(long_msg => "skipping '" . $site->{'Owner Display Name'} . "': no matching filter name.", debug => 1);
next; next;
} }
$self->{sites}->{$site->{'Site Id'}} = { $self->{sites}->{$site->{'Site URL'}} = {
id => $site->{'Site Id'}, owner => $site->{'Owner Display Name'},
url => $site->{'Site URL'}, url => $site->{'Site URL'},
} }
} }
@ -74,8 +74,8 @@ sub run {
$self->manage_selection(%options); $self->manage_selection(%options);
foreach my $site (sort keys %{$self->{sites}}) { foreach my $site (sort keys %{$self->{sites}}) {
$self->{output}->output_add(long_msg => sprintf("[id = %s] [url = %s]", $self->{output}->output_add(long_msg => sprintf("[owner = %s] [url = %s]",
$self->{sites}->{$site}->{id}, $self->{sites}->{$site}->{owner},
$self->{sites}->{$site}->{url})); $self->{sites}->{$site}->{url}));
} }
@ -88,7 +88,7 @@ sub run {
sub disco_format { sub disco_format {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['id', 'url']); $self->{output}->add_disco_format(elements => ['owner', 'url']);
} }
sub disco_show { sub disco_show {
@ -97,7 +97,7 @@ sub disco_show {
$self->manage_selection(%options); $self->manage_selection(%options);
foreach my $site (sort keys %{$self->{sites}}) { foreach my $site (sort keys %{$self->{sites}}) {
$self->{output}->add_disco_entry( $self->{output}->add_disco_entry(
id => $self->{sites}->{$site}->{id}, owner => $self->{sites}->{$site}->{owner},
url => $self->{sites}->{$site}->{url}, url => $self->{sites}->{$site}->{url},
); );
} }

View File

@ -31,6 +31,7 @@ sub new {
$self->{version} = '0.1'; $self->{version} = '0.1';
%{ $self->{modes} } = ( %{ $self->{modes} } = (
'list-sites' => 'cloud::microsoft::office365::onedrive::mode::listsites',
'usage' => 'cloud::microsoft::office365::onedrive::mode::usage', 'usage' => 'cloud::microsoft::office365::onedrive::mode::usage',
); );