change office 365 plugins behaviour
This commit is contained in:
parent
60f13e0c4c
commit
01906c9cbb
|
@ -25,19 +25,120 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_active_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %total_options = ();
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => 'active_mailboxes',
|
||||
value => $self->{result_values}->{active},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
unit => 'mailboxes', min => 0, max => $self->{result_values}->{total});
|
||||
}
|
||||
|
||||
sub custom_active_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $threshold_value = $self->{result_values}->{active};
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_active};
|
||||
}
|
||||
my $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_active_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("Active mailboxes on %s : %d/%d (%.2f%%)",
|
||||
$self->{result_values}->{report_date},
|
||||
$self->{result_values}->{active},
|
||||
$self->{result_values}->{total},
|
||||
$self->{result_values}->{prct_active});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_active_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
|
||||
$self->{result_values}->{report_date} = $options{new_datas}->{$self->{instance} . '_report_date'};
|
||||
$self->{result_values}->{prct_active} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{active} * 100 / $self->{result_values}->{total} : 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_global_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Total (active mailboxes) ";
|
||||
}
|
||||
|
||||
sub prefix_mailbox_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "User '" . $options{instance_value}->{name} . "' ";
|
||||
return "Mailbox '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'active', type => 0 },
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
|
||||
{ name => 'mailboxes', type => 1, cb_prefix_output => 'prefix_mailbox_output', message_multiple => 'All email activity are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{active} = [
|
||||
{ label => 'active-mailboxes', set => {
|
||||
key_values => [ { name => 'active' }, { name => 'total' }, { name => 'report_date' } ],
|
||||
closure_custom_calc => $self->can('custom_active_calc'),
|
||||
closure_custom_output => $self->can('custom_active_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_active_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_active_perfdata')
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total-send-count', set => {
|
||||
key_values => [ { name => 'send_count' } ],
|
||||
output_template => 'Send Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_send_count', value => 'send_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-receive-count', set => {
|
||||
key_values => [ { name => 'receive_count' } ],
|
||||
output_template => 'Receive Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_receive_count', value => 'receive_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-read-count', set => {
|
||||
key_values => [ { name => 'read_count' } ],
|
||||
output_template => 'Read Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_read_count', value => 'read_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{mailboxes} = [
|
||||
{ label => 'send-count', set => {
|
||||
key_values => [ { name => 'send_count' }, { name => 'name' } ],
|
||||
|
@ -66,11 +167,6 @@ sub set_counters {
|
|||
],
|
||||
}
|
||||
},
|
||||
{ label => 'last-activity', threshold => 0, set => {
|
||||
key_values => [ { name => 'last_activity_date' }, { name => 'name' } ],
|
||||
output_template => 'Last Activity: %s',
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -83,7 +179,8 @@ sub new {
|
|||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-mailbox:s" => { name => 'filter_mailbox' },
|
||||
"active-only" => { name => 'active_only' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"filter-counters:s" => { name => 'filter_counters', default => 'active|total' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -92,11 +189,15 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$instance_mode = $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{active} = { active => 0, total => 0, report_date => '' };
|
||||
$self->{global} = { send_count => 0, receive_count => 0 , read_count => 0 };
|
||||
$self->{mailboxes} = {};
|
||||
|
||||
my $results = $options{custom}->office_get_exchange_activity();
|
||||
|
@ -107,21 +208,26 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $mailbox->{'User Principal Name'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
if ($self->{option_results}->{active_only} && defined($mailbox->{'Last Activity Date'}) && $mailbox->{'Last Activity Date'} eq '') {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $mailbox->{'User Principal Name'} . "': no activity.", debug => 1);
|
||||
|
||||
$self->{active}->{total}++;
|
||||
|
||||
if (!defined($mailbox->{'Last Activity Date'}) || $mailbox->{'Last Activity Date'} eq '' ||
|
||||
($mailbox->{'Last Activity Date'} ne $mailbox->{'Report Refresh Date'})) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $mailbox->{'User Principal Name'} . "': no activity.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{active}->{report_date} = $mailbox->{'Report Refresh Date'};
|
||||
$self->{active}->{active}++;
|
||||
|
||||
$self->{global}->{send_count} += $mailbox->{'Send Count'};
|
||||
$self->{global}->{receive_count} += $mailbox->{'Receive Count'};
|
||||
$self->{global}->{read_count} += $mailbox->{'Read Count'};
|
||||
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{name} = $mailbox->{'User Principal Name'};
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{send_count} = $mailbox->{'Send Count'};
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{receive_count} = $mailbox->{'Receive Count'};
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{read_count} = $mailbox->{'Read Count'};
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{last_activity_date} = $mailbox->{'Last Activity Date'};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{mailboxes}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No entry found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,16 +251,26 @@ Filter mailboxes.
|
|||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'send-count', 'receive-count', 'read-count'.
|
||||
Can be: 'active-mailboxes', 'total-send-count' (count),
|
||||
'total-receive-count' (count), 'total-read-count' (count),
|
||||
'send-count' (count), 'receive-count' (count), 'read-count' (count).
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'send-count', 'receive-count', 'read-count'.
|
||||
Can be: 'active-mailboxes', 'total-send-count' (count),
|
||||
'total-receive-count' (count), 'total-read-count' (count),
|
||||
'send-count' (count), 'receive-count' (count), 'read-count' (count).
|
||||
|
||||
=item B<--active-only>
|
||||
=item B<--filter-counters>
|
||||
|
||||
Filter only active entries ('Last Activity' set).
|
||||
Only display some counters (regexp can be used).
|
||||
Example to hide per user counters: --filter-counters='active|total'
|
||||
(Default: 'active|total')
|
||||
|
||||
=item B<--units>
|
||||
|
||||
Unit of thresholds (Default: '%') ('%', 'count').
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -27,6 +27,58 @@ use warnings;
|
|||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_active_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %total_options = ();
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => 'active_mailboxes',
|
||||
value => $self->{result_values}->{active},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
unit => 'mailboxes', min => 0, max => $self->{result_values}->{total});
|
||||
}
|
||||
|
||||
sub custom_active_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $threshold_value = $self->{result_values}->{active};
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_active};
|
||||
}
|
||||
my $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_active_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("Active mailboxes on %s : %d/%d (%.2f%%)",
|
||||
$self->{result_values}->{report_date},
|
||||
$self->{result_values}->{active},
|
||||
$self->{result_values}->{total},
|
||||
$self->{result_values}->{prct_active});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_active_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
|
||||
$self->{result_values}->{report_date} = $options{new_datas}->{$self->{instance} . '_report_date'};
|
||||
$self->{result_values}->{prct_active} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{active} * 100 / $self->{result_values}->{total} : 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -90,6 +142,12 @@ sub custom_status_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_global_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Total ";
|
||||
}
|
||||
|
||||
sub prefix_mailbox_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -100,9 +158,43 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'active', type => 0 },
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
|
||||
{ name => 'mailboxes', type => 1, cb_prefix_output => 'prefix_mailbox_output', message_multiple => 'All mailboxes usage are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{active} = [
|
||||
{ label => 'active-mailboxes', set => {
|
||||
key_values => [ { name => 'active' }, { name => 'total' }, { name => 'report_date' } ],
|
||||
closure_custom_calc => $self->can('custom_active_calc'),
|
||||
closure_custom_output => $self->can('custom_active_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_active_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_active_perfdata')
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total-usage-active', set => {
|
||||
key_values => [ { name => 'storage_used_active' } ],
|
||||
output_template => 'Usage (active mailboxes): %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'storage_used_active', value => 'storage_used_active_absolute', template => '%d',
|
||||
min => 0, unit => 'B' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-usage-inactive', set => {
|
||||
key_values => [ { name => 'storage_used_inactive' } ],
|
||||
output_template => 'Usage (inactive mailboxes): %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'storage_used_inactive', value => 'storage_used_inactive_absolute', template => '%d',
|
||||
min => 0, unit => 'B' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{mailboxes} = [
|
||||
{ label => 'usage', set => {
|
||||
key_values => [ { name => 'storage_used' }, { name => 'issue_warning_quota' },
|
||||
|
@ -113,9 +205,13 @@ sub set_counters {
|
|||
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||||
}
|
||||
},
|
||||
{ label => 'last-activity', threshold => 0, set => {
|
||||
key_values => [ { name => 'last_activity_date' }, { name => 'name' } ],
|
||||
output_template => 'Last Activity: %s',
|
||||
{ label => 'items', set => {
|
||||
key_values => [ { name => 'items' } ],
|
||||
output_template => 'Items: %d',
|
||||
perfdatas => [
|
||||
{ label => 'items', value => 'items_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
|
@ -129,10 +225,11 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-mailbox:s" => { name => 'filter_mailbox' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '%{used} > %{issue_warning_quota}' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{used} > %{prohibit_send_quota}' },
|
||||
"active-only" => { name => 'active_only' },
|
||||
"filter-mailbox:s" => { name => 'filter_mailbox' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '%{used} > %{issue_warning_quota}' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{used} > %{prohibit_send_quota}' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"filter-counters:s" => { name => 'filter_counters', default => 'active|total' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -159,6 +256,8 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{active} = { active => 0, total => 0, report_date => '' };
|
||||
$self->{global} = { storage_used_active => 0, storage_used_inactive => 0 };
|
||||
$self->{mailboxes} = {};
|
||||
|
||||
my $results = $options{custom}->office_get_exchange_mailbox_usage();
|
||||
|
@ -169,22 +268,27 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $mailbox->{'User Principal Name'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
if ($self->{option_results}->{active_only} && defined($mailbox->{'Last Activity Date'}) && $mailbox->{'Last Activity Date'} eq '') {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $mailbox->{'User Principal Name'} . "': no activity.", debug => 1);
|
||||
|
||||
$self->{active}->{total}++;
|
||||
|
||||
if (!defined($mailbox->{'Last Activity Date'}) || $mailbox->{'Last Activity Date'} eq '' ||
|
||||
($mailbox->{'Last Activity Date'} ne $mailbox->{'Report Refresh Date'})) {
|
||||
$self->{global}->{storage_used_inactive} += ($mailbox->{'Storage Used (Byte)'} ne '') ? $mailbox->{'Storage Used (Byte)'} : 0;
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $mailbox->{'User Principal Name'} . "': no activity.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{active}->{report_date} = $mailbox->{'Report Refresh Date'};
|
||||
$self->{active}->{active}++;
|
||||
|
||||
$self->{global}->{storage_used_active} += ($mailbox->{'Storage Used (Byte)'} ne '') ? $mailbox->{'Storage Used (Byte)'} : 0;
|
||||
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{name} = $mailbox->{'User Principal Name'};
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{storage_used} = ($mailbox->{'Storage Used (Byte)'} ne '') ? $mailbox->{'Storage Used (Byte)'} : 0;
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{issue_warning_quota} = $mailbox->{'Issue Warning Quota (Byte)'};
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{prohibit_send_quota} = $mailbox->{'Prohibit Send Quota (Byte)'};
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{prohibit_send_receive_quota} = $mailbox->{'Prohibit Send/Receive Quota (Byte)'};
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{last_activity_date} = $mailbox->{'Last Activity Date'};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{mailboxes}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No entry found.");
|
||||
$self->{output}->option_exit();
|
||||
$self->{mailboxes}->{$mailbox->{'User Principal Name'}}->{items} = ($mailbox->{'Item Count'} ne '') ? $mailbox->{'Item Count'} : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,19 +309,39 @@ https://docs.microsoft.com/en-us/office365/admin/activity-reports/mailbox-usage?
|
|||
|
||||
Filter mailboxes.
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'active-mailboxes', 'total-usage-active' (count),
|
||||
'total-usage-inactive' (count).
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'active-mailboxes', 'total-usage-active' (count),
|
||||
'total-usage-inactive' (count).
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status (Default: '%{used} > %{issue_warning_quota}').
|
||||
Can used special variables like: %{used}, %{issue_warning_quota}, %{prohibit_send_quota}, %{prohibit_send_receive_quota}
|
||||
Can used special variables like: %{used}, %{issue_warning_quota},
|
||||
%{prohibit_send_quota}, %{prohibit_send_receive_quota}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status (Default: '%{used} > %{prohibit_send_quota}').
|
||||
Can used special variables like: %{used}, %{issue_warning_quota}, %{prohibit_send_quota}, %{prohibit_send_receive_quota}
|
||||
Can used special variables like: %{used}, %{issue_warning_quota},
|
||||
%{prohibit_send_quota}, %{prohibit_send_receive_quota}
|
||||
|
||||
=item B<--active-only>
|
||||
=item B<--filter-counters>
|
||||
|
||||
Filter only active entries ('Last Activity' set).
|
||||
Only display some counters (regexp can be used).
|
||||
Example to hide per user counters: --filter-counters='active|total'
|
||||
(Default: 'active|total')
|
||||
|
||||
=item B<--units>
|
||||
|
||||
Unit of thresholds (Default: '%') ('%', 'count').
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -27,6 +27,58 @@ use warnings;
|
|||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_active_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %total_options = ();
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => 'active_sites',
|
||||
value => $self->{result_values}->{active},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
unit => 'sites', min => 0, max => $self->{result_values}->{total});
|
||||
}
|
||||
|
||||
sub custom_active_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $threshold_value = $self->{result_values}->{active};
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_active};
|
||||
}
|
||||
my $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_active_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("Active sites on %s : %d/%d (%.2f%%)",
|
||||
$self->{result_values}->{report_date},
|
||||
$self->{result_values}->{active},
|
||||
$self->{result_values}->{total},
|
||||
$self->{result_values}->{prct_active});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_active_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
|
||||
$self->{result_values}->{report_date} = $options{new_datas}->{$self->{instance} . '_report_date'};
|
||||
$self->{result_values}->{prct_active} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{active} * 100 / $self->{result_values}->{total} : 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -91,6 +143,12 @@ sub custom_usage_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_global_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Total ";
|
||||
}
|
||||
|
||||
sub prefix_site_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -101,9 +159,61 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'active', type => 0 },
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
|
||||
{ name => 'sites', type => 1, cb_prefix_output => 'prefix_site_output', message_multiple => 'All sites usage are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{active} = [
|
||||
{ label => 'active-sites', set => {
|
||||
key_values => [ { name => 'active' }, { name => 'total' }, { name => 'report_date' } ],
|
||||
closure_custom_calc => $self->can('custom_active_calc'),
|
||||
closure_custom_output => $self->can('custom_active_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_active_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_active_perfdata')
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total-usage-active', set => {
|
||||
key_values => [ { name => 'storage_used_active' } ],
|
||||
output_template => 'Usage (active sites): %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'storage_used_active', value => 'storage_used_active_absolute', template => '%d',
|
||||
min => 0, unit => 'B' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-usage-inactive', set => {
|
||||
key_values => [ { name => 'storage_used_inactive' } ],
|
||||
output_template => 'Usage (inactive sites): %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'storage_used_inactive', value => 'storage_used_inactive_absolute', template => '%d',
|
||||
min => 0, unit => 'B' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-file-count', set => {
|
||||
key_values => [ { name => 'file_count' } ],
|
||||
output_template => 'File Count (active sites): %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_file_count', value => 'file_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-active-file-count', set => {
|
||||
key_values => [ { name => 'active_file_count' } ],
|
||||
output_template => 'Active File Count (active sites): %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_active_file_count', value => 'active_file_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{sites} = [
|
||||
{ label => 'usage', set => {
|
||||
key_values => [ { name => 'storage_used' }, { name => 'storage_allocated' }, { name => 'url' }, { name => 'owner' } ],
|
||||
|
@ -131,11 +241,6 @@ sub set_counters {
|
|||
],
|
||||
}
|
||||
},
|
||||
{ label => 'last-activity', threshold => 0, set => {
|
||||
key_values => [ { name => 'last_activity_date' }, { name => 'url' }, { name => 'owner' } ],
|
||||
output_template => 'Last Activity: %s',
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -147,11 +252,11 @@ sub new {
|
|||
$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' },
|
||||
"active-only" => { name => 'active_only' },
|
||||
"filter-url:s" => { name => 'filter_url' },
|
||||
"filter-owner:s" => { name => 'filter_owner' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"free" => { name => 'free' },
|
||||
"filter-counters:s" => { name => 'filter_counters', default => 'active-sites|total' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -167,6 +272,8 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{active} = { active => 0, total => 0, report_date => '' };
|
||||
$self->{global} = { storage_used_active => 0, storage_used_inactive => 0, file_count => 0, active_file_count => 0 };
|
||||
$self->{sites} = {};
|
||||
|
||||
my $results = $options{custom}->office_get_onedrive_usage();
|
||||
|
@ -182,10 +289,22 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Owner Display Name'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
if ($self->{option_results}->{active_only} && defined($site->{'Last Activity Date'}) && $site->{'Last Activity Date'} eq '') {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no activity.", debug => 1);
|
||||
|
||||
$self->{active}->{total}++;
|
||||
|
||||
if (!defined($site->{'Last Activity Date'}) || $site->{'Last Activity Date'} eq '' ||
|
||||
($site->{'Last Activity Date'} ne $site->{'Report Refresh Date'})) {
|
||||
$self->{global}->{storage_used_inactive} += ($site->{'Storage Used (Byte)'} ne '') ? $site->{'Storage Used (Byte)'} : 0;
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no activity.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{active}->{report_date} = $site->{'Report Refresh Date'};
|
||||
$self->{active}->{active}++;
|
||||
|
||||
$self->{global}->{storage_used_active} += ($site->{'Storage Used (Byte)'} ne '') ? $site->{'Storage Used (Byte)'} : 0;
|
||||
$self->{global}->{file_count} += ($site->{'File Count'} ne '') ? $site->{'File Count'} : 0;
|
||||
$self->{global}->{active_file_count} += ($site->{'Active File Count'} ne '') ? $site->{'Active File Count'} : 0;
|
||||
|
||||
$self->{sites}->{$site->{'Site URL'}}->{url} = $site->{'Site URL'};
|
||||
$self->{sites}->{$site->{'Site URL'}}->{owner} = $site->{'Owner Display Name'};
|
||||
|
@ -193,12 +312,6 @@ sub manage_selection {
|
|||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,16 +336,28 @@ Can be: 'url', 'owner' (can be a regexp).
|
|||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'usage', 'file-count', 'active-file-count'.
|
||||
Can be: 'active-sites', 'total-usage-active' (count),
|
||||
'total-usage-inactive' (count), 'total-file-count' (count),
|
||||
'active-file-count' (count), 'usage' (count),
|
||||
'file-count' (count), 'active-file-count' (count).
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'usage', 'file-count', 'active-file-count'.
|
||||
Can be: 'active-sites', 'total-usage-active' (count),
|
||||
'total-usage-inactive' (count), 'total-file-count' (count),
|
||||
'active-file-count' (count), 'usage' (count),
|
||||
'file-count' (count), 'active-file-count' (count).
|
||||
|
||||
=item B<--active-only>
|
||||
=item B<--filter-counters>
|
||||
|
||||
Filter only active entries ('Last Activity' set).
|
||||
Only display some counters (regexp can be used).
|
||||
Example to hide per user counters: --filter-counters='active-sites|total'
|
||||
(Default: 'active-sites|total')
|
||||
|
||||
=item B<--units>
|
||||
|
||||
Unit of thresholds (Default: '%') ('%', 'count').
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -27,6 +27,58 @@ use warnings;
|
|||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_active_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %total_options = ();
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => 'active_sites',
|
||||
value => $self->{result_values}->{active},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
unit => 'sites', min => 0, max => $self->{result_values}->{total});
|
||||
}
|
||||
|
||||
sub custom_active_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $threshold_value = $self->{result_values}->{active};
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_active};
|
||||
}
|
||||
my $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_active_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("Active sites on %s : %d/%d (%.2f%%)",
|
||||
$self->{result_values}->{report_date},
|
||||
$self->{result_values}->{active},
|
||||
$self->{result_values}->{total},
|
||||
$self->{result_values}->{prct_active});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_active_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
|
||||
$self->{result_values}->{report_date} = $options{new_datas}->{$self->{instance} . '_report_date'};
|
||||
$self->{result_values}->{prct_active} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{active} * 100 / $self->{result_values}->{total} : 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -91,6 +143,12 @@ sub custom_usage_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_global_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Total ";
|
||||
}
|
||||
|
||||
sub prefix_site_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -101,9 +159,79 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'active', type => 0 },
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
|
||||
{ name => 'sites', type => 1, cb_prefix_output => 'prefix_site_output', message_multiple => 'All sites usage are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{active} = [
|
||||
{ label => 'active-sites', set => {
|
||||
key_values => [ { name => 'active' }, { name => 'total' }, { name => 'report_date' } ],
|
||||
closure_custom_calc => $self->can('custom_active_calc'),
|
||||
closure_custom_output => $self->can('custom_active_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_active_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_active_perfdata')
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total-usage-active', set => {
|
||||
key_values => [ { name => 'storage_used_active' } ],
|
||||
output_template => 'Usage (active sites): %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'storage_used_active', value => 'storage_used_active_absolute', template => '%d',
|
||||
min => 0, unit => 'B' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-usage-inactive', set => {
|
||||
key_values => [ { name => 'storage_used_inactive' } ],
|
||||
output_template => 'Usage (inactive sites): %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'storage_used_inactive', value => 'storage_used_inactive_absolute', template => '%d',
|
||||
min => 0, unit => 'B' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-file-count', set => {
|
||||
key_values => [ { name => 'file_count' } ],
|
||||
output_template => 'File Count (active sites): %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_file_count', value => 'file_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-active-file-count', set => {
|
||||
key_values => [ { name => 'active_file_count' } ],
|
||||
output_template => 'Active File Count (active sites): %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_active_file_count', value => 'active_file_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-visited-page-count', set => {
|
||||
key_values => [ { name => 'visited_page_count' } ],
|
||||
output_template => 'Visited Page Count (active sites): %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_visited_page_count', value => 'visited_page_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-page-view-count', set => {
|
||||
key_values => [ { name => 'page_view_count' } ],
|
||||
output_template => 'Page View Count (active sites): %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_page_view_count', value => 'page_view_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{sites} = [
|
||||
{ label => 'usage', set => {
|
||||
key_values => [ { name => 'storage_used' }, { name => 'storage_allocated' }, { name => 'url' }, { name => 'id' } ],
|
||||
|
@ -131,11 +259,11 @@ sub set_counters {
|
|||
],
|
||||
}
|
||||
},
|
||||
{ label => 'visited-file-count', set => {
|
||||
key_values => [ { name => 'visited_file_count' }, { name => 'url' }, { name => 'id' } ],
|
||||
output_template => 'Visited File Count: %d',
|
||||
{ label => 'visited-page-count', set => {
|
||||
key_values => [ { name => 'visited_page_count' }, { name => 'url' }, { name => 'id' } ],
|
||||
output_template => 'Visited Page Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'visited_file_count', value => 'visited_file_count_absolute', template => '%d',
|
||||
{ label => 'visited_page_count', value => 'visited_page_count_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'id_absolute' },
|
||||
],
|
||||
}
|
||||
|
@ -149,11 +277,6 @@ sub set_counters {
|
|||
],
|
||||
}
|
||||
},
|
||||
{ label => 'last-activity', threshold => 0, set => {
|
||||
key_values => [ { name => 'last_activity_date' }, { name => 'url' }, { name => 'id' } ],
|
||||
output_template => 'Last Activity: %s',
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -165,11 +288,11 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-url:s" => { name => 'filter_url' },
|
||||
"filter-id:s" => { name => 'filter_id' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"free" => { name => 'free' },
|
||||
"active-only" => { name => 'active_only' },
|
||||
"filter-url:s" => { name => 'filter_url' },
|
||||
"filter-id:s" => { name => 'filter_id' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"free" => { name => 'free' },
|
||||
"filter-counters:s" => { name => 'filter_counters', default => 'active-sites|total' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -185,6 +308,9 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{active} = { active => 0, total => 0, report_date => '' };
|
||||
$self->{global} = { storage_used_active => 0, storage_used_inactive => 0, file_count => 0,
|
||||
active_file_count => 0 , visited_file_count => 0 , page_view_count => 0 };
|
||||
$self->{sites} = {};
|
||||
|
||||
my $results = $options{custom}->office_get_sharepoint_site_usage();
|
||||
|
@ -200,26 +326,35 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site Id'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
if ($self->{option_results}->{active_only} && defined($site->{'Last Activity Date'}) && $site->{'Last Activity Date'} eq '') {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no activity.", debug => 1);
|
||||
|
||||
$self->{active}->{total}++;
|
||||
|
||||
if (!defined($site->{'Last Activity Date'}) || $site->{'Last Activity Date'} eq '' ||
|
||||
($site->{'Last Activity Date'} ne $site->{'Report Refresh Date'})) {
|
||||
$self->{global}->{storage_used_inactive} += ($site->{'Storage Used (Byte)'} ne '') ? $site->{'Storage Used (Byte)'} : 0;
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no activity.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{active}->{report_date} = $site->{'Report Refresh Date'};
|
||||
$self->{active}->{active}++;
|
||||
|
||||
$self->{global}->{storage_used_active} += ($site->{'Storage Used (Byte)'} ne '') ? $site->{'Storage Used (Byte)'} : 0;
|
||||
$self->{global}->{file_count} += ($site->{'File Count'} ne '') ? $site->{'File Count'} : 0;
|
||||
$self->{global}->{active_file_count} += ($site->{'Active File Count'} ne '') ? $site->{'Active File Count'} : 0;
|
||||
$self->{global}->{visited_page_count} += ($site->{'Visited Page Count'} ne '') ? $site->{'Visited Page Count'} : 0;
|
||||
$self->{global}->{page_view_count} += ($site->{'Page View Count'} ne '') ? $site->{'Page View Count'} : 0;
|
||||
|
||||
$self->{sites}->{$site->{'Site Id'}}->{id} = $site->{'Site Id'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{url} = $site->{'Site URL'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{file_count} = $site->{'File Count'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{active_file_count} = $site->{'Active File Count'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{visited_file_count} = $site->{'Visited Page Count'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{visited_page_count} = $site->{'Visited Page Count'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{page_view_count} = $site->{'Page View Count'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{storage_used} = $site->{'Storage Used (Byte)'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{storage_allocated} = $site->{'Storage Allocated (Byte)'};
|
||||
$self->{sites}->{$site->{'Site Id'}}->{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;
|
||||
|
@ -243,18 +378,28 @@ Can be: 'url', 'id' (can be a regexp).
|
|||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'usage', 'file-count', 'active-file-count',
|
||||
'visited-file-count', 'page-view-count'.
|
||||
Can be: 'active-sites', 'total-usage' (count), 'total-file-count' (count),
|
||||
'total-active-file-count' (count), 'total-visited-page-count' (count),
|
||||
'total-page-view-count' (count), 'usage' (count), 'file-count' (count), 'active-file-count' (count),
|
||||
'visited-page-count' (count), 'page-view-count' (count).
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'usage', 'file-count', 'active-file-count',
|
||||
'visited-file-count', 'page-view-count'.
|
||||
Can be: 'active-sites', 'total-usage' (count), 'total-file-count' (count),
|
||||
'total-active-file-count' (count), 'total-visited-page-count' (count),
|
||||
'total-page-view-count' (count), 'usage' (count), 'file-count' (count), 'active-file-count' (count),
|
||||
'visited-page-count' (count), 'page-view-count' (count).
|
||||
|
||||
=item B<--active-only>
|
||||
=item B<--filter-counters>
|
||||
|
||||
Filter only active entries ('Last Activity' set).
|
||||
Only display some counters (regexp can be used).
|
||||
Example to hide per user counters: --filter-counters='active-sites|total'
|
||||
(Default: 'active-sites|total')
|
||||
|
||||
=item B<--units>
|
||||
|
||||
Unit of thresholds (Default: '%') ('%', 'count').
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -25,6 +25,66 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_active_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %total_options = ();
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => 'active_users',
|
||||
value => $self->{result_values}->{active},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
unit => 'users', min => 0, max => $self->{result_values}->{total});
|
||||
}
|
||||
|
||||
sub custom_active_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $threshold_value = $self->{result_values}->{active};
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_active};
|
||||
}
|
||||
my $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_active_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("Active users on %s : %d/%d (%.2f%%)",
|
||||
$self->{result_values}->{report_date},
|
||||
$self->{result_values}->{active},
|
||||
$self->{result_values}->{total},
|
||||
$self->{result_values}->{prct_active});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_active_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
|
||||
$self->{result_values}->{report_date} = $options{new_datas}->{$self->{instance} . '_report_date'};
|
||||
$self->{result_values}->{prct_active} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{active} * 100 / $self->{result_values}->{total} : 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_global_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Total (active sites) ";
|
||||
}
|
||||
|
||||
sub prefix_user_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -35,9 +95,68 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'active', type => 0 },
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
|
||||
{ name => 'users', type => 1, cb_prefix_output => 'prefix_user_output', message_multiple => 'All users activity are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{active} = [
|
||||
{ label => 'active-users', set => {
|
||||
key_values => [ { name => 'active' }, { name => 'total' }, { name => 'report_date' } ],
|
||||
closure_custom_calc => $self->can('custom_active_calc'),
|
||||
closure_custom_output => $self->can('custom_active_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_active_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_active_perfdata')
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total-viewed-edited-file-count', set => {
|
||||
key_values => [ { name => 'viewed_edited_file_count' } ],
|
||||
output_template => 'Viewed or Edited File Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_viewed_edited_file_count', value => 'viewed_edited_file_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-synced-file-count', set => {
|
||||
key_values => [ { name => 'synced_file_count' } ],
|
||||
output_template => 'Synced File Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_synced_file_count', value => 'synced_file_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-shared-int-file-count', set => {
|
||||
key_values => [ { name => 'shared_int_file_count' } ],
|
||||
output_template => 'Shared Internally File Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_shared_int_file_count', value => 'shared_int_file_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-shared-ext-file-count', set => {
|
||||
key_values => [ { name => 'shared_ext_file_count' } ],
|
||||
output_template => 'Shared Externally File Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_shared_ext_file_count', value => 'shared_ext_file_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-visited-page-count', set => {
|
||||
key_values => [ { name => 'visited_page_count' } ],
|
||||
output_template => 'Visited Page Count (active sites): %d',
|
||||
perfdatas => [
|
||||
{ label => 'total_visited_page_count', value => 'visited_page_count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{users} = [
|
||||
{ label => 'viewed-edited-file-count', set => {
|
||||
key_values => [ { name => 'viewed_edited_file_count' }, { name => 'name' } ],
|
||||
|
@ -48,11 +167,11 @@ sub set_counters {
|
|||
],
|
||||
}
|
||||
},
|
||||
{ label => 'file-count', set => {
|
||||
key_values => [ { name => 'file_count' }, { name => 'name' } ],
|
||||
output_template => 'File Count: %d',
|
||||
{ label => 'synced-file-count', set => {
|
||||
key_values => [ { name => 'synced_file_count' }, { name => 'name' } ],
|
||||
output_template => 'Synced File Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'file_count', value => 'file_count_absolute', template => '%d',
|
||||
{ label => 'synced_file_count', value => 'synced_file_count_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
|
@ -84,11 +203,6 @@ sub set_counters {
|
|||
],
|
||||
}
|
||||
},
|
||||
{ label => 'last-activity', threshold => 0, set => {
|
||||
key_values => [ { name => 'last_activity_date' }, { name => 'name' } ],
|
||||
output_template => 'Last Activity: %s',
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -100,8 +214,9 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-user:s" => { name => 'filter_user' },
|
||||
"active-only" => { name => 'active_only' },
|
||||
"filter-user:s" => { name => 'filter_user' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"filter-counters:s" => { name => 'filter_counters', default => 'active|total' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -110,11 +225,17 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$instance_mode = $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{active} = { active => 0, total => 0, report_date => '' };
|
||||
$self->{global} = { storage_used_active => 0, storage_used_inactive => 0, synced_file_count => 0,
|
||||
viewed_edited_file_count => 0, shared_int_file_count => 0, shared_ext_file_count => 0,
|
||||
visited_file_count => 0 };
|
||||
$self->{users} = {};
|
||||
|
||||
my $results = $options{custom}->office_get_sharepoint_activity();
|
||||
|
@ -122,26 +243,33 @@ sub manage_selection {
|
|||
foreach my $user (@{$results}) {
|
||||
if (defined($self->{option_results}->{filter_user}) && $self->{option_results}->{filter_user} ne '' &&
|
||||
$user->{'User Principal Name'} !~ /$self->{option_results}->{filter_user}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no matching filter name.", debug => 1);
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
if ($self->{option_results}->{active_only} && defined($user->{'Last Activity Date'}) && $user->{'Last Activity Date'} eq '') {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1);
|
||||
|
||||
$self->{active}->{total}++;
|
||||
|
||||
if (!defined($user->{'Last Activity Date'}) || $user->{'Last Activity Date'} eq '' ||
|
||||
($user->{'Last Activity Date'} ne $user->{'Report Refresh Date'})) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{active}->{report_date} = $user->{'Report Refresh Date'};
|
||||
$self->{active}->{active}++;
|
||||
|
||||
$self->{global}->{viewed_edited_file_count} += ($user->{'Viewed Or Edited File Count'} ne '') ? $user->{'Viewed Or Edited File Count'} : 0;
|
||||
$self->{global}->{synced_file_count} += ($user->{'Synced File Count'} ne '') ? $user->{'Synced File Count'} : 0;
|
||||
$self->{global}->{shared_int_file_count} += ($user->{'Shared Internally File Count'} ne '') ? $user->{'Shared Internally File Count'} : 0;
|
||||
$self->{global}->{shared_ext_file_count} += ($user->{'Shared Externally File Count'} ne '') ? $user->{'Shared Externally File Count'} : 0;
|
||||
$self->{global}->{visited_page_count} += ($user->{'Visited Page Count'} ne '') ? $user->{'Visited Page Count'} : 0;
|
||||
|
||||
$self->{users}->{$user->{'User Principal Name'}}->{name} = $user->{'User Principal Name'};
|
||||
$self->{users}->{$user->{'User Principal Name'}}->{viewed_edited_file_count} = $user->{'Viewed Or Edited File Count'};
|
||||
$self->{users}->{$user->{'User Principal Name'}}->{file_count} = $user->{'Synced File Count'};
|
||||
$self->{users}->{$user->{'User Principal Name'}}->{synced_file_count} = $user->{'Synced File Count'};
|
||||
$self->{users}->{$user->{'User Principal Name'}}->{shared_int_file_count} = $user->{'Shared Internally File Count'};
|
||||
$self->{users}->{$user->{'User Principal Name'}}->{shared_ext_file_count} = $user->{'Shared Externally File Count'};
|
||||
$self->{users}->{$user->{'User Principal Name'}}->{visited_page_count} = $user->{'Visited Page Count'};
|
||||
$self->{users}->{$user->{'User Principal Name'}}->{last_activity_date} = $user->{'Last Activity Date'};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{users}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No entry found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,18 +293,30 @@ Filter users.
|
|||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'viewed-edited-file-count', 'file-count', 'shared-int-file-count',
|
||||
'shared-ext-file-count', 'visited-page-count'.
|
||||
Can be: 'active-users', 'total-viewed-edited-file-count' (count),
|
||||
'total-synced-file-count' (count), 'total-shared-int-file-count' (count),
|
||||
'total-shared-ext-file-count' (count), 'total-visited-page-count' (count),
|
||||
'viewed-edited-file-count' (count), 'synced-file-count' (count), 'shared-int-file-count' (count),
|
||||
'shared-ext-file-count' (count), 'visited-page-count' (count).
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'viewed-edited-file-count', 'file-count', 'shared-int-file-count',
|
||||
'shared-ext-file-count', 'visited-page-count'.
|
||||
Can be: 'active-users', 'total-viewed-edited-file-count' (count),
|
||||
'total-synced-file-count' (count), 'total-shared-int-file-count' (count),
|
||||
'total-shared-ext-file-count' (count), 'total-visited-page-count' (count),
|
||||
'viewed-edited-file-count' (count), 'synced-file-count' (count), 'shared-int-file-count' (count),
|
||||
'shared-ext-file-count' (count), 'visited-page-count' (count).
|
||||
|
||||
=item B<--active-only>
|
||||
=item B<--filter-counters>
|
||||
|
||||
Filter only active entries ('Last Activity' set).
|
||||
Only display some counters (regexp can be used).
|
||||
Example to hide per user counters: --filter-counters='active|total'
|
||||
(Default: 'active|total')
|
||||
|
||||
=item B<--units>
|
||||
|
||||
Unit of thresholds (Default: '%') ('%', 'count').
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -152,21 +152,37 @@ sub set_counters {
|
|||
{ label => 'team-chat', set => {
|
||||
key_values => [ { name => 'team_chat' }, { name => 'name' } ],
|
||||
output_template => 'Team Chat Message Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'team_chat', value => 'team_chat_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'private-chat', set => {
|
||||
key_values => [ { name => 'private_chat' }, { name => 'name' } ],
|
||||
output_template => 'Private Chat Message Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'private_chat', value => 'private_chat_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'call', set => {
|
||||
key_values => [ { name => 'call' }, { name => 'name' } ],
|
||||
output_template => 'Call Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'call', value => 'call_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'meeting', set => {
|
||||
key_values => [ { name => 'meeting' }, { name => 'name' } ],
|
||||
output_template => 'Meeting Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'meeting', value => 'meeting_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
|
@ -181,7 +197,7 @@ sub new {
|
|||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"filter-counters:s" => { name => 'filter_counters' },
|
||||
"filter-counters:s" => { name => 'filter_counters', default => 'active|total' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -260,6 +276,7 @@ Can be: 'active-users', 'total-team-chat' (count), 'total-private-chat' (count),
|
|||
|
||||
Only display some counters (regexp can be used).
|
||||
Example to hide per user counters: --filter-counters='total'
|
||||
(Default: 'active|total')
|
||||
|
||||
=item B<--units>
|
||||
|
||||
|
|
Loading…
Reference in New Issue