diff --git a/cloud/microsoft/office365/exchange/mode/emailactivity.pm b/cloud/microsoft/office365/exchange/mode/emailactivity.pm index 26d90e713..e64fe8843 100644 --- a/cloud/microsoft/office365/exchange/mode/emailactivity.pm +++ b/cloud/microsoft/office365/exchange/mode/emailactivity.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -sub prefix_user_output { +sub prefix_mailbox_output { my ($self, %options) = @_; return "User '" . $options{instance_value}->{name} . "' "; @@ -35,10 +35,10 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'users', type => 1, cb_prefix_output => 'prefix_user_output', message_multiple => 'All email activity are ok' }, + { name => 'mailboxes', type => 1, cb_prefix_output => 'prefix_mailbox_output', message_multiple => 'All email activity are ok' }, ]; - $self->{maps_counters}->{users} = [ + $self->{maps_counters}->{mailboxes} = [ { label => 'send-count', set => { key_values => [ { name => 'send_count' }, { name => 'name' } ], output_template => 'Send Count: %d', @@ -82,7 +82,8 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-user:s" => { name => 'filter_user' }, + "filter-mailbox:s" => { name => 'filter_mailbox' }, + "active-only" => { name => 'active_only' }, }); return $self; @@ -96,25 +97,29 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{users} = {}; + $self->{mailboxes} = {}; my $results = $options{custom}->office_get_exchange_activity(); - 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); + foreach my $mailbox (@{$results}) { + if (defined($self->{option_results}->{filter_mailbox}) && $self->{option_results}->{filter_mailbox} ne '' && + $mailbox->{'User Principal Name'} !~ /$self->{option_results}->{filter_mailbox}/) { + $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); next; } - $self->{users}->{$user->{'User Principal Name'}}->{name} = $user->{'User Principal Name'}; - $self->{users}->{$user->{'User Principal Name'}}->{send_count} = $user->{'Send Count'}; - $self->{users}->{$user->{'User Principal Name'}}->{receive_count} = $user->{'Receive Count'}; - $self->{users}->{$user->{'User Principal Name'}}->{read_count} = $user->{'Read Count'}; - $self->{users}->{$user->{'User Principal Name'}}->{last_activity_date} = $user->{'Last Activity Date'}; + $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->{users}}) <= 0) { + if (scalar(keys %{$self->{mailboxes}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); } @@ -133,9 +138,9 @@ https://docs.microsoft.com/en-us/office365/admin/activity-reports/email-activity =over 8 -=item B<--filter-user> +=item B<--filter-mailbox> -Filter users. +Filter mailboxes. =item B<--warning-*> @@ -147,6 +152,10 @@ Can be: 'send-count', 'receive-count', 'read-count'. Threshold critical. Can be: 'send-count', 'receive-count', 'read-count'. +=item B<--active-only> + +Filter only active entries ('Last Activity' set). + =back =cut diff --git a/cloud/microsoft/office365/exchange/mode/mailboxusage.pm b/cloud/microsoft/office365/exchange/mode/mailboxusage.pm index 76eb6b7c0..46e690813 100644 --- a/cloud/microsoft/office365/exchange/mode/mailboxusage.pm +++ b/cloud/microsoft/office365/exchange/mode/mailboxusage.pm @@ -90,20 +90,20 @@ sub custom_status_calc { return 0; } -sub prefix_user_output { +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 => 'users', type => 1, cb_prefix_output => 'prefix_user_output', message_multiple => 'All mailbox usage are ok' }, + { name => 'mailboxes', type => 1, cb_prefix_output => 'prefix_mailbox_output', message_multiple => 'All mailboxes usage are ok' }, ]; - $self->{maps_counters}->{users} = [ + $self->{maps_counters}->{mailboxes} = [ { label => 'usage', set => { key_values => [ { name => 'storage_used' }, { name => 'issue_warning_quota' }, { name => 'prohibit_send_quota' }, { name => 'prohibit_send_receive_quota' }, { name => 'name' } ], @@ -113,6 +113,11 @@ 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', + } + }, ]; } @@ -124,9 +129,10 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-user:s" => { name => 'filter_user' }, - "warning-status:s" => { name => 'warning_status', default => '%{storage_used} > %{issue_warning_quota}' }, - "critical-status:s" => { name => 'critical_status', default => '%{storage_used} > %{prohibit_send_quota}' }, + "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' }, }); return $self; @@ -153,26 +159,30 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{users} = {}; + $self->{mailboxes} = {}; my $results = $options{custom}->office_get_exchange_mailbox_usage(); - 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); + foreach my $mailbox (@{$results}) { + if (defined($self->{option_results}->{filter_mailbox}) && $self->{option_results}->{filter_mailbox} ne '' && + $mailbox->{'User Principal Name'} !~ /$self->{option_results}->{filter_mailbox}/) { + $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); next; } - $self->{users}->{$user->{'User Principal Name'}}->{name} = $user->{'User Principal Name'}; - $self->{users}->{$user->{'User Principal Name'}}->{storage_used} = $user->{'Storage Used (Byte)'}; - $self->{users}->{$user->{'User Principal Name'}}->{issue_warning_quota} = $user->{'Issue Warning Quota (Byte)'}; - $self->{users}->{$user->{'User Principal Name'}}->{prohibit_send_quota} = $user->{'Prohibit Send Quota (Byte)'}; - $self->{users}->{$user->{'User Principal Name'}}->{prohibit_send_receive_quota} = $user->{'Prohibit Send/Receive Quota (Byte)'}; - $self->{users}->{$user->{'User Principal Name'}}->{last_activity_date} = $user->{'Last Activity Date'}; + $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->{users}}) <= 0) { + if (scalar(keys %{$self->{mailboxes}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); } @@ -191,20 +201,24 @@ https://docs.microsoft.com/en-us/office365/admin/activity-reports/mailbox-usage? =over 8 -=item B<--filter-user> +=item B<--filter-mailbox> -Filter users. +Filter mailboxes. =item B<--warning-status> -Set warning threshold for status (Default: '%{storage_used} > %{issue_warning_quota}'). +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} =item B<--critical-status> -Set critical threshold for status (Default: '%{storage_used} > %{prohibit_send_quota}'). +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} +=item B<--active-only> + +Filter only active entries ('Last Activity' set). + =back =cut diff --git a/cloud/microsoft/office365/onedrive/mode/usage.pm b/cloud/microsoft/office365/onedrive/mode/usage.pm index b887b5f1f..af9da5a3c 100644 --- a/cloud/microsoft/office365/onedrive/mode/usage.pm +++ b/cloud/microsoft/office365/onedrive/mode/usage.pm @@ -151,6 +151,7 @@ sub new { "filter-owner:s" => { name => 'filter_owner' }, "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, + "active-only" => { name => 'active_only' }, }); return $self; @@ -181,6 +182,10 @@ 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); + next; + } $self->{sites}->{$site->{'Site URL'}}->{url} = $site->{'Site URL'}; $self->{sites}->{$site->{'Site URL'}}->{owner} = $site->{'Owner Display Name'}; @@ -225,6 +230,10 @@ Can be: 'usage', 'file-count', 'active-file-count'. Threshold critical. Can be: 'usage', 'file-count', 'active-file-count'. +=item B<--active-only> + +Filter only active entries ('Last Activity' set). + =back =cut diff --git a/cloud/microsoft/office365/sharepoint/mode/siteusage.pm b/cloud/microsoft/office365/sharepoint/mode/siteusage.pm index 8fe5af9ea..a36ff4019 100644 --- a/cloud/microsoft/office365/sharepoint/mode/siteusage.pm +++ b/cloud/microsoft/office365/sharepoint/mode/siteusage.pm @@ -149,6 +149,11 @@ sub set_counters { ], } }, + { label => 'last-activity', threshold => 0, set => { + key_values => [ { name => 'last_activity_date' }, { name => 'url' }, { name => 'id' } ], + output_template => 'Last Activity: %s', + } + }, ]; } @@ -164,6 +169,7 @@ sub new { "filter-id:s" => { name => 'filter_id' }, "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, + "active-only" => { name => 'active_only' }, }); return $self; @@ -194,7 +200,11 @@ 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); + next; + } + $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'}; @@ -203,6 +213,7 @@ sub manage_selection { $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) { @@ -241,6 +252,10 @@ Threshold critical. Can be: 'usage', 'file-count', 'active-file-count', 'visited-file-count', 'page-view-count'. +=item B<--active-only> + +Filter only active entries ('Last Activity' set). + =back =cut diff --git a/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm b/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm index b5c532a8b..bf1c1ba3e 100644 --- a/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm +++ b/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm @@ -101,6 +101,7 @@ sub new { $options{options}->add_options(arguments => { "filter-user:s" => { name => 'filter_user' }, + "active-only" => { name => 'active_only' }, }); return $self; @@ -124,6 +125,10 @@ sub manage_selection { $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); + next; + } $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'}; @@ -169,6 +174,10 @@ Threshold critical. Can be: 'viewed-edited-file-count', 'file-count', 'shared-int-file-count', 'shared-ext-file-count', 'visited-page-count'. +=item B<--active-only> + +Filter only active entries ('Last Activity' set). + =back =cut