add office365 onedrive plugin
This commit is contained in:
parent
e202ece0ee
commit
d01628dc66
|
@ -0,0 +1,123 @@
|
|||
#
|
||||
# Copyright 2018 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package cloud::microsoft::office365::sharepoint::mode::listsites;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-url:s" => { name => 'filter_url' },
|
||||
"filter-id:s" => { name => 'filter_id' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $results = $options{custom}->office_get_sharepoint_site_usage();
|
||||
|
||||
foreach my $site (@{$results}) {
|
||||
if (defined($self->{option_results}->{filter_url}) && $self->{option_results}->{filter_url} ne '' &&
|
||||
$site->{'Site URL'} !~ /$self->{option_results}->{filter_url}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' &&
|
||||
$site->{'Site Id'} !~ /$self->{option_results}->{filter_id}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site Id'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{sites}->{$site->{'Site Id'}} = {
|
||||
id => $site->{'Site Id'},
|
||||
url => $site->{'Site URL'},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
foreach my $site (sort keys %{$self->{sites}}) {
|
||||
$self->{output}->output_add(long_msg => sprintf("[id = %s] [url = %s]",
|
||||
$self->{sites}->{$site}->{id},
|
||||
$self->{sites}->{$site}->{url}));
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List sites:');
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->add_disco_format(elements => ['id', 'url']);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
foreach my $site (sort keys %{$self->{sites}}) {
|
||||
$self->{output}->add_disco_entry(
|
||||
id => $self->{sites}->{$site}->{id},
|
||||
url => $self->{sites}->{$site}->{url},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
List sites.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-*>
|
||||
|
||||
Filter sites.
|
||||
Can be: 'url', 'id' (can be a regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,230 @@
|
|||
#
|
||||
# Copyright 2018 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package cloud::microsoft::office365::onedrive::mode::usage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
$self->{output}->perfdata_add(label => 'used' . $extra_label,
|
||||
unit => 'B',
|
||||
value => $self->{result_values}->{used},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
min => 0, max => $self->{result_values}->{total});
|
||||
}
|
||||
|
||||
sub custom_usage_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($exit, $threshold_value);
|
||||
$threshold_value = $self->{result_values}->{used};
|
||||
$threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free}));
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value,
|
||||
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
sub custom_usage_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
||||
|
||||
my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_value . " " . $total_unit,
|
||||
$used_value . " " . $used_unit, $self->{result_values}->{prct_used},
|
||||
$free_value . " " . $free_unit, $self->{result_values}->{prct_free});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_usage_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_url'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_storage_allocated'};
|
||||
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_storage_used'};
|
||||
|
||||
if ($self->{result_values}->{total} != 0) {
|
||||
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
|
||||
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
|
||||
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
|
||||
} else {
|
||||
$self->{result_values}->{free} = '0';
|
||||
$self->{result_values}->{prct_used} = '0';
|
||||
$self->{result_values}->{prct_free} = '0';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_site_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Site '" . $options{instance_value}->{url} . "' [Owner: " . $options{instance_value}->{owner} . "] ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'sites', type => 1, cb_prefix_output => 'prefix_site_output', message_multiple => 'All sites usage are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{sites} = [
|
||||
{ label => 'usage', set => {
|
||||
key_values => [ { name => 'storage_used' }, { name => 'storage_allocated' }, { name => 'url' }, { name => 'owner' } ],
|
||||
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
|
||||
}
|
||||
},
|
||||
{ label => 'file-count', set => {
|
||||
key_values => [ { name => 'file_count' }, { name => 'url' }, { name => 'owner' } ],
|
||||
output_template => 'File Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'file_count', value => 'file_count_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'url_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'active-file-count', set => {
|
||||
key_values => [ { name => 'active_file_count' }, { name => 'url' }, { name => 'owner' } ],
|
||||
output_template => 'Active File Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'active_file_count', value => 'active_file_count_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'url_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'last-activity', threshold => 0, set => {
|
||||
key_values => [ { name => 'last_activity_date' }, { name => 'url' }, { name => 'owner' } ],
|
||||
output_template => 'Last Activity: %s',
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-url:s" => { name => 'filter_url' },
|
||||
"filter-owner:s" => { name => 'filter_owner' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"free" => { name => 'free' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$instance_mode = $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{sites} = {};
|
||||
|
||||
my $results = $options{custom}->office_get_onedrive_usage();
|
||||
|
||||
foreach my $site (@{$results}) {
|
||||
if (defined($self->{option_results}->{filter_url}) && $self->{option_results}->{filter_url} ne '' &&
|
||||
$site->{'Site URL'} !~ /$self->{option_results}->{filter_url}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_owner}) && $self->{option_results}->{filter_owner} ne '' &&
|
||||
$site->{'Owner Display Name'} !~ /$self->{option_results}->{filter_owner}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Owner Display Name'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{sites}->{$site->{'Site URL'}}->{url} = $site->{'Site URL'};
|
||||
$self->{sites}->{$site->{'Site URL'}}->{owner} = $site->{'Owner Display Name'};
|
||||
$self->{sites}->{$site->{'Site URL'}}->{file_count} = $site->{'File Count'};
|
||||
$self->{sites}->{$site->{'Site URL'}}->{active_file_count} = $site->{'Active File Count'};
|
||||
$self->{sites}->{$site->{'Site URL'}}->{storage_used} = $site->{'Storage Used (Byte)'};
|
||||
$self->{sites}->{$site->{'Site URL'}}->{storage_allocated} = $site->{'Storage Allocated (Byte)'};
|
||||
$self->{sites}->{$site->{'Site URL'}}->{last_activity_date} = $site->{'Last Activity Date'};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{sites}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No entry found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check usage (reporting period over the last 7 days).
|
||||
|
||||
(See link for details about metrics :
|
||||
https://docs.microsoft.com/en-us/office365/admin/activity-reports/onedrive-for-business-usage?view=o365-worldwide)
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-*>
|
||||
|
||||
Filter sites.
|
||||
Can be: 'url', 'owner' (can be a regexp).
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'usage', 'file-count', 'active-file-count'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'usage', 'file-count', 'active-file-count'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,49 @@
|
|||
#
|
||||
# Copyright 2018 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package cloud::microsoft::office365::onedrive::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ( $class, %options ) = @_;
|
||||
my $self = $class->SUPER::new( package => __PACKAGE__, %options );
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{ $self->{modes} } = (
|
||||
'usage' => 'cloud::microsoft::office365::onedrive::mode::usage',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{graphapi} = 'cloud::microsoft::office365::custom::graphapi';
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Microsoft Office 365.
|
||||
|
||||
=cut
|
Loading…
Reference in New Issue