From 1784e9452f082c8e29c7e4616c10dce7102edf95 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Fri, 4 Sep 2020 14:27:26 +0200 Subject: [PATCH] enh(o365) Many enhancements (#2042) * enh(o365) Add new labels * enh(o365) Properly report refresh date even if there's no active item * enh(o365) Add new labels * enh(o365) Add new labels * enh(o365) Rename onedrive usage to site-usage * enh(o365) Add onedrive users-activity mode * enh(o365) Help update * enh(o365) Properly init counters * enh(o365) Use daily data * enh(o365) Add perfdate perfdata * enh(o365) Generate correct local perdate * enh(o365) Generate daily perfdate at 12:00 rather than 00:00 * Remove Exchange instance label cleaning * Remove other modes instance label cleaning --- cloud/microsoft/office365/custom/graphapi.pm | 35 +- .../office365/exchange/mode/emailactivity.pm | 92 +++--- .../office365/exchange/mode/mailboxusage.pm | 39 ++- .../onedrive/mode/{usage.pm => siteusage.pm} | 91 ++++-- .../office365/onedrive/mode/usersactivity.pm | 299 ++++++++++++++++++ cloud/microsoft/office365/onedrive/plugin.pm | 3 +- .../office365/sharepoint/mode/siteusage.pm | 124 +++++--- .../sharepoint/mode/usersactivity.pm | 80 +++-- .../office365/skype/mode/devicesusage.pm | 60 ++-- .../office365/skype/mode/usersactivity.pm | 41 ++- .../office365/teams/mode/devicesusage.pm | 60 ++-- .../office365/teams/mode/usersactivity.pm | 45 +-- 12 files changed, 701 insertions(+), 268 deletions(-) rename cloud/microsoft/office365/onedrive/mode/{usage.pm => siteusage.pm} (77%) create mode 100644 cloud/microsoft/office365/onedrive/mode/usersactivity.pm diff --git a/cloud/microsoft/office365/custom/graphapi.pm b/cloud/microsoft/office365/custom/graphapi.pm index b78a7daaf..40878cad4 100644 --- a/cloud/microsoft/office365/custom/graphapi.pm +++ b/cloud/microsoft/office365/custom/graphapi.pm @@ -272,7 +272,7 @@ sub request_api_csv { sub office_get_sharepoint_site_usage_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getSharePointSiteUsageDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getSharePointSiteUsageDetail(" . $options{param} . ")"; return $url; } @@ -289,7 +289,7 @@ sub office_get_sharepoint_site_usage { sub office_get_sharepoint_activity_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getSharePointActivityUserDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getSharePointActivityUserDetail(" . $options{param} . ")"; return $url; } @@ -306,7 +306,7 @@ sub office_get_sharepoint_activity { sub office_get_onedrive_usage_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getOneDriveUsageAccountDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getOneDriveUsageAccountDetail(" . $options{param} . ")"; return $url; } @@ -316,6 +316,23 @@ sub office_get_onedrive_usage { my $full_url = $self->office_get_onedrive_usage_set_url(%options); my $response = $self->request_api_csv(method => 'GET', full_url => $full_url, hostname => ''); + + return $response; +} + +sub office_get_onedrive_activity_set_url { + my ($self, %options) = @_; + + my $url = $self->{graph_endpoint} . "/v1.0/reports/getOneDriveActivityUserDetail(" . $options{param} . ")"; + + return $url; +} + +sub office_get_onedrive_activity { + my ($self, %options) = @_; + + my $full_url = $self->office_get_onedrive_activity_set_url(%options); + my $response = $self->request_api_csv(method => 'GET', full_url => $full_url, hostname => ''); return $response; } @@ -323,7 +340,7 @@ sub office_get_onedrive_usage { sub office_get_exchange_activity_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getEmailActivityUserDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getEmailActivityUserDetail(" . $options{param} . ")"; return $url; } @@ -340,7 +357,7 @@ sub office_get_exchange_activity { sub office_get_exchange_mailbox_usage_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getMailboxUsageDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getMailboxUsageDetail(" . $options{param} . ")"; return $url; } @@ -357,7 +374,7 @@ sub office_get_exchange_mailbox_usage { sub office_get_teams_activity_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getTeamsUserActivityUserDetail(" . $options{param} . ")"; return $url; } @@ -374,7 +391,7 @@ sub office_get_teams_activity { sub office_get_teams_device_usage_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getTeamsDeviceUsageUserDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getTeamsDeviceUsageUserDetail(" . $options{param} . ")"; return $url; } @@ -391,7 +408,7 @@ sub office_get_teams_device_usage { sub office_get_skype_activity_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getSkypeForBusinessActivityUserDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getSkypeForBusinessActivityUserDetail(" . $options{param} . ")"; return $url; } @@ -408,7 +425,7 @@ sub office_get_skype_activity { sub office_get_skype_device_usage_set_url { my ($self, %options) = @_; - my $url = $self->{graph_endpoint} . "/v1.0/reports/getSkypeForBusinessDeviceUsageUserDetail(period='D7')"; + my $url = $self->{graph_endpoint} . "/v1.0/reports/getSkypeForBusinessDeviceUsageUserDetail(" . $options{param} . ")"; return $url; } diff --git a/cloud/microsoft/office365/exchange/mode/emailactivity.pm b/cloud/microsoft/office365/exchange/mode/emailactivity.pm index 7cf50eb44..bbdf7b812 100644 --- a/cloud/microsoft/office365/exchange/mode/emailactivity.pm +++ b/cloud/microsoft/office365/exchange/mode/emailactivity.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,11 +35,14 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_mailboxes', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_users', nlabel => 'exchange.users.active.count', 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}); + unit => 'users', min => 0, max => $self->{result_values}->{total}); } sub custom_active_threshold { @@ -58,7 +62,7 @@ sub custom_active_threshold { sub custom_active_output { my ($self, %options) = @_; - my $msg = sprintf("Active mailboxes on %s : %d/%d (%.2f%%)", + my $msg = sprintf("Active users on %s : %d/%d (%.2f%%)", $self->{result_values}->{report_date}, $self->{result_values}->{active}, $self->{result_values}->{total}, @@ -80,13 +84,13 @@ sub custom_active_calc { sub prefix_global_output { my ($self, %options) = @_; - return "Total (active mailboxes) "; + return "Total (active users) "; } sub prefix_mailbox_output { my ($self, %options) = @_; - return "Mailbox '" . $options{instance_value}->{name} . "' "; + return "User '" . $options{instance_value}->{name} . "' "; } sub set_counters { @@ -95,11 +99,11 @@ sub set_counters { $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' }, + { name => 'users', type => 1, cb_prefix_output => 'prefix_mailbox_output', message_multiple => 'All email activity are ok' }, ]; $self->{maps_counters}->{active} = [ - { label => 'active-mailboxes', set => { + { 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'), @@ -109,7 +113,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-send-count', set => { + { label => 'total-send-count', nlabel => 'exchange.users.emails.sent.total.count', set => { key_values => [ { name => 'send_count' } ], output_template => 'Send Count: %d', perfdatas => [ @@ -118,7 +122,7 @@ sub set_counters { ], } }, - { label => 'total-receive-count', set => { + { label => 'total-receive-count', nlabel => 'exchange.users.emails.received.total.count', set => { key_values => [ { name => 'receive_count' } ], output_template => 'Receive Count: %d', perfdatas => [ @@ -127,7 +131,7 @@ sub set_counters { ], } }, - { label => 'total-read-count', set => { + { label => 'total-read-count', nlabel => 'exchange.users.emails.read.total.count', set => { key_values => [ { name => 'read_count' } ], output_template => 'Read Count: %d', perfdatas => [ @@ -137,8 +141,8 @@ sub set_counters { } }, ]; - $self->{maps_counters}->{mailboxes} = [ - { label => 'send-count', set => { + $self->{maps_counters}->{users} = [ + { label => 'send-count', nlabel => 'exchange.users.emails.sent.count', set => { key_values => [ { name => 'send_count' }, { name => 'name' } ], output_template => 'Send Count: %d', perfdatas => [ @@ -147,7 +151,7 @@ sub set_counters { ], } }, - { label => 'receive-count', set => { + { label => 'receive-count', nlabel => 'exchange.users.emails.received.count', set => { key_values => [ { name => 'receive_count' }, { name => 'name' } ], output_template => 'Receive Count: %d', perfdatas => [ @@ -156,7 +160,7 @@ sub set_counters { ], } }, - { label => 'read-count', set => { + { label => 'read-count', nlabel => 'exchange.users.emails.read.count', set => { key_values => [ { name => 'read_count' }, { name => 'name' } ], output_template => 'Read Count: %d', perfdatas => [ @@ -174,7 +178,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-mailbox:s" => { name => 'filter_mailbox' }, + "filter-user:s" => { name => 'filter_user' }, "units:s" => { name => 'units', default => '%' }, "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, }); @@ -187,36 +191,40 @@ sub manage_selection { $self->{active} = { active => 0, total => 0, report_date => '' }; $self->{global} = { send_count => 0, receive_count => 0 , read_count => 0 }; - $self->{mailboxes} = {}; + $self->{users} = {}; - my $results = $options{custom}->office_get_exchange_activity(); + my $results = $options{custom}->office_get_exchange_activity(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_exchange_activity(param => "date=" . $self->{active}->{report_date}); + } - 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; - } - - $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); + foreach my $user (@{$results}, @{$results_daily}) { + 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); + next; + } + + if ($user->{'Report Period'} != 1) { + if (!defined($user->{'Last Activity Date'}) || ($user->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1); + } + $self->{active}->{total}++; 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->{global}->{send_count} += $user->{'Send Count'}; + $self->{global}->{receive_count} += $user->{'Receive Count'}; + $self->{global}->{read_count} += $user->{'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->{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'}; } } @@ -226,28 +234,28 @@ __END__ =head1 MODE -Check email activity (reporting period over the last 7 days). +Check email activity (reporting period over the last refreshed day). (See link for details about metrics : https://docs.microsoft.com/en-us/office365/admin/activity-reports/email-activity?view=o365-worldwide) =over 8 -=item B<--filter-mailbox> +=item B<--filter-user> -Filter mailboxes. +Filter users. =item B<--warning-*> Threshold warning. -Can be: 'active-mailboxes', 'total-send-count' (count), +Can be: 'active-users', '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: 'active-mailboxes', 'total-send-count' (count), +Can be: 'active-users', 'total-send-count' (count), 'total-receive-count' (count), 'total-read-count' (count), 'send-count' (count), 'receive-count' (count), 'read-count' (count). diff --git a/cloud/microsoft/office365/exchange/mode/mailboxusage.pm b/cloud/microsoft/office365/exchange/mode/mailboxusage.pm index acca62088..f8a47f768 100644 --- a/cloud/microsoft/office365/exchange/mode/mailboxusage.pm +++ b/cloud/microsoft/office365/exchange/mode/mailboxusage.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,7 +35,10 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_mailboxes', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_mailboxes', nlabel => 'exchange.mailboxes.active.count', 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), @@ -83,7 +87,7 @@ sub custom_usage_perfdata { 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, + $self->{output}->perfdata_add(label => 'used' . $extra_label, nlabel => $self->{result_values}->{display} . '#exchange.mailboxes.usage.bytes', unit => 'B', value => $self->{result_values}->{used}, min => 0); @@ -172,22 +176,22 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-usage-active', set => { + { label => 'total-usage-active', nlabel => 'exchange.mailboxes.active.usage.total.bytes', 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', template => '%d', + { label => 'total_usage_active', value => 'storage_used_active', template => '%d', min => 0, unit => 'B' }, ], } }, - { label => 'total-usage-inactive', set => { + { label => 'total-usage-inactive', nlabel => 'exchange.mailboxes.inactive.usage.total.bytes', 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', template => '%d', + { label => 'total_usage_inactive', value => 'storage_used_inactive', template => '%d', min => 0, unit => 'B' }, ], } @@ -203,12 +207,12 @@ sub set_counters { closure_custom_threshold_check => $self->can('custom_status_threshold'), } }, - { label => 'items', set => { - key_values => [ { name => 'items' } ], + { label => 'items', nlabel => 'exchange.mailboxes.items.count', set => { + key_values => [ { name => 'items' }, { name => 'name' } ], output_template => 'Items: %d', perfdatas => [ { label => 'items', value => 'items', template => '%d', - min => 0 }, + min => 0, label_extra_instance => 1, instance_use => 'name' }, ], } }, @@ -245,25 +249,28 @@ sub manage_selection { $self->{global} = { storage_used_active => 0, storage_used_inactive => 0 }; $self->{mailboxes} = {}; - my $results = $options{custom}->office_get_exchange_mailbox_usage(); + my $results = $options{custom}->office_get_exchange_mailbox_usage(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + #$results_daily = $options{custom}->office_get_exchange_mailbox_usage(param => "date=" . $self->{active}->{report_date}); + } - foreach my $mailbox (@{$results}) { + foreach my $mailbox (@{$results}, @{$results_daily}) { 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; } - + $self->{active}->{total}++; - if (!defined($mailbox->{'Last Activity Date'}) || $mailbox->{'Last Activity Date'} eq '' || - ($mailbox->{'Last Activity Date'} ne $mailbox->{'Report Refresh Date'})) { + if (!defined($mailbox->{'Last Activity Date'}) || ($mailbox->{'Last Activity Date'} ne $self->{active}->{report_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; @@ -283,7 +290,7 @@ __END__ =head1 MODE -Check mailbox usage (reporting period over the last 7 days). +Check mailbox usage (reporting period over the last refreshed day). (See link for details about metrics : https://docs.microsoft.com/en-us/office365/admin/activity-reports/mailbox-usage?view=o365-worldwide) diff --git a/cloud/microsoft/office365/onedrive/mode/usage.pm b/cloud/microsoft/office365/onedrive/mode/siteusage.pm similarity index 77% rename from cloud/microsoft/office365/onedrive/mode/usage.pm rename to cloud/microsoft/office365/onedrive/mode/siteusage.pm index e22e1fd97..bb493fa3b 100644 --- a/cloud/microsoft/office365/onedrive/mode/usage.pm +++ b/cloud/microsoft/office365/onedrive/mode/siteusage.pm @@ -18,12 +18,13 @@ # limitations under the License. # -package cloud::microsoft::office365::onedrive::mode::usage; +package cloud::microsoft::office365::onedrive::mode::siteusage; use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,7 +35,10 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_sites', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_sites', nlabel => 'onedrive.sites.active.count', 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), @@ -83,7 +87,7 @@ sub custom_usage_perfdata { 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, + $self->{output}->perfdata_add(label => 'used' . $extra_label, nlabel => $self->{result_values}->{display} . '#onedrive.sites.usage.bytes', 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), @@ -173,36 +177,45 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-usage-active', set => { + { label => 'total-usage-active', nlabel => 'onedrive.sites.active.usage.total.bytes', 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', template => '%d', + { label => 'total_usage_active', value => 'storage_used_active', template => '%d', min => 0, unit => 'B' }, ], } }, - { label => 'total-usage-inactive', set => { + { label => 'total-usage-inactive', nlabel => 'onedrive.sites.inactive.usage.total.bytes', 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', template => '%d', + { label => 'total_usage_inactive', value => 'storage_used_inactive', template => '%d', min => 0, unit => 'B' }, ], } }, - { label => 'total-file-count', set => { - key_values => [ { name => 'file_count' } ], + { label => 'total-file-count-active', nlabel => 'onedrive.sites.active.files.total.count', set => { + key_values => [ { name => 'file_count_active' } ], output_template => 'File Count (active sites): %d', perfdatas => [ - { label => 'total_file_count', value => 'file_count', template => '%d', + { label => 'total_file_count_active', value => 'file_count_active', template => '%d', min => 0 }, ], } }, - { label => 'total-active-file-count', set => { + { label => 'total-file-count-inactive', nlabel => 'onedrive.sites.inactive.files.total.count', set => { + key_values => [ { name => 'file_count_inactive' } ], + output_template => 'File Count (inactive sites): %d', + perfdatas => [ + { label => 'total_file_count_inactive', value => 'file_count_inactive', template => '%d', + min => 0 }, + ], + } + }, + { label => 'total-active-file-count', nlabel => 'onedrive.sites.files.active.total.count', set => { key_values => [ { name => 'active_file_count' } ], output_template => 'Active File Count (active sites): %d', perfdatas => [ @@ -221,7 +234,7 @@ sub set_counters { closure_custom_threshold_check => $self->can('custom_usage_threshold'), } }, - { label => 'file-count', set => { + { label => 'file-count', nlabel => 'onedrive.sites.files.count', set => { key_values => [ { name => 'file_count' }, { name => 'url' }, { name => 'owner' } ], output_template => 'File Count: %d', perfdatas => [ @@ -230,7 +243,7 @@ sub set_counters { ], } }, - { label => 'active-file-count', set => { + { label => 'active-file-count', nlabel => 'onedrive.sites.files.active.count', set => { key_values => [ { name => 'active_file_count' }, { name => 'url' }, { name => 'owner' } ], output_template => 'Active File Count: %d', perfdatas => [ @@ -262,12 +275,18 @@ 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->{global} = { storage_used_active => 0, storage_used_inactive => 0, + file_count_active => 0, file_count_inactive => 0, active_file_count => 0 }; $self->{sites} = {}; - my $results = $options{custom}->office_get_onedrive_usage(); + my $results = $options{custom}->office_get_onedrive_usage(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_onedrive_usage(param => "date=" . $self->{active}->{report_date}); + } - foreach my $site (@{$results}) { + foreach my $site (@{$results}, @{$results_daily}) { 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); @@ -279,20 +298,20 @@ sub manage_selection { next; } - $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); + if ($site->{'Report Period'} != 1) { + if (!defined($site->{'Last Activity Date'}) || ($site->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{global}->{storage_used_inactive} += ($site->{'Storage Used (Byte)'} ne '') ? $site->{'Storage Used (Byte)'} : 0; + $self->{global}->{file_count_inactive} += ($site->{'File Count'} ne '') ? $site->{'File Count'} : 0; + $self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no activity.", debug => 1); + } + $self->{active}->{total}++; 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}->{file_count_active} += ($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'}; @@ -310,10 +329,10 @@ __END__ =head1 MODE -Check usage (reporting period over the last 7 days). +Check sites usage (reporting period over the last refreshed day). (See link for details about metrics : -https://docs.microsoft.com/en-us/office365/admin/activity-reports/onedrive-for-business-usage?view=o365-worldwide) +https://docs.microsoft.com/en-us/microsoft-365/admin/activity-reports/onedrive-for-business-usage?view=o365-worldwide) =over 8 @@ -325,18 +344,20 @@ Can be: 'url', 'owner' (can be a regexp). =item B<--warning-*> Threshold warning. -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). +Can be: 'active-sites', +'total-usage-active' (count), 'total-usage-inactive' (count), +'total-file-count-active' (count), 'total-file-count-inactive' (count), +'total-active-file-count' (count), +'usage' (count), 'file-count' (count), 'active-file-count' (count). =item B<--critical-*> Threshold critical. -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). +Can be: 'active-sites', +'total-usage-active' (count), 'total-usage-inactive' (count), +'total-file-count-active' (count), 'total-file-count-inactive' (count), +'total-active-file-count' (count), +'usage' (count), 'file-count' (count), 'active-file-count' (count). =item B<--filter-counters> diff --git a/cloud/microsoft/office365/onedrive/mode/usersactivity.pm b/cloud/microsoft/office365/onedrive/mode/usersactivity.pm new file mode 100644 index 000000000..207dde26d --- /dev/null +++ b/cloud/microsoft/office365/onedrive/mode/usersactivity.pm @@ -0,0 +1,299 @@ +# +# Copyright 2020 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::usersactivity; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Time::Local; + +sub custom_active_perfdata { + my ($self, %options) = @_; + + my %total_options = (); + if ($self->{instance_mode}->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_users', nlabel => 'onedrive.users.active.count', + 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 ($self->{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) = @_; + + return "User '" . $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 => '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', nlabel => 'onedrive.users.files.viewed.total.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', template => '%d', + min => 0 }, + ], + } + }, + { label => 'total-synced-file-count', nlabel => 'onedrive.users.files.synced.total.count', set => { + key_values => [ { name => 'synced_file_count' } ], + output_template => 'Synced File Count: %d', + perfdatas => [ + { label => 'total_synced_file_count', value => 'synced_file_count', template => '%d', + min => 0 }, + ], + } + }, + { label => 'total-shared-int-file-count', nlabel => 'onedrive.users.files.shared.internally.total.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', template => '%d', + min => 0 }, + ], + } + }, + { label => 'total-shared-ext-file-count', nlabel => 'onedrive.users.files.shared.externally.total.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', template => '%d', + min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{users} = [ + { label => 'viewed-edited-file-count', nlabel => 'onedrive.users.files.viewed.count', set => { + key_values => [ { name => 'viewed_edited_file_count' }, { name => 'name' } ], + output_template => 'Viewed or Edited File Count: %d', + perfdatas => [ + { label => 'viewed_edited_file_count', value => 'viewed_edited_file_count', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'name' }, + ], + } + }, + { label => 'synced-file-count', nlabel => 'onedrive.users.files.synced.count', set => { + key_values => [ { name => 'synced_file_count' }, { name => 'name' } ], + output_template => 'Synced File Count: %d', + perfdatas => [ + { label => 'synced_file_count', value => 'synced_file_count', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'name' }, + ], + } + }, + { label => 'shared-int-file-count', nlabel => 'onedrive.users.files.shared.internally.count', set => { + key_values => [ { name => 'shared_int_file_count' }, { name => 'name' } ], + output_template => 'Shared Internally File Count: %d', + perfdatas => [ + { label => 'shared_int_file_count', value => 'shared_int_file_count', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'name' }, + ], + } + }, + { label => 'shared-ext-file-count', nlabel => 'onedrive.users.files.shared.externally.count', set => { + key_values => [ { name => 'shared_ext_file_count' }, { name => 'name' } ], + output_template => 'Shared Externally File Count: %d', + perfdatas => [ + { label => 'shared_ext_file_count', value => 'shared_ext_file_count', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'name' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-user:s" => { name => 'filter_user' }, + "units:s" => { name => 'units', default => '%' }, + "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{active} = { active => 0, total => 0, report_date => '' }; + $self->{global} = { viewed_edited_file_count => 0, synced_file_count => 0, + shared_int_file_count => 0, shared_ext_file_count => 0 }; + $self->{users} = {}; + + my $results = $options{custom}->office_get_onedrive_activity(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_onedrive_activity(param => "date=" . $self->{active}->{report_date}); + } + + foreach my $user (@{$results}, @{$results_daily}) { + 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); + next; + } + + if ($user->{'Report Period'} != 1) { + if (!defined($user->{'Last Activity Date'}) || ($user->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1); + } + $self->{active}->{total}++; + next; + } + + $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->{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'}}->{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'}; + } +} + +1; + +__END__ + +=head1 MODE + +Check users activity (reporting period over the last refreshed day). + +(See link for details about metrics : +https://docs.microsoft.com/en-us/microsoft-365/admin/activity-reports/onedrive-for-business-activity?view=o365-worldwide) + +=over 8 + +=item B<--filter-user> + +Filter users. + +=item B<--warning-*> + +Threshold warning. +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), +'viewed-edited-file-count' (count), 'synced-file-count' (count), +'shared-int-file-count' (count), 'shared-ext-file-count' (count). + +=item B<--critical-*> + +Threshold critical. +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), +'viewed-edited-file-count' (count), 'synced-file-count' (count), +'shared-int-file-count' (count), 'shared-ext-file-count' (count). + +=item B<--filter-counters> + +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 + +=cut diff --git a/cloud/microsoft/office365/onedrive/plugin.pm b/cloud/microsoft/office365/onedrive/plugin.pm index 32ea800c8..232442e5b 100644 --- a/cloud/microsoft/office365/onedrive/plugin.pm +++ b/cloud/microsoft/office365/onedrive/plugin.pm @@ -32,7 +32,8 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( 'list-sites' => 'cloud::microsoft::office365::onedrive::mode::listsites', - 'usage' => 'cloud::microsoft::office365::onedrive::mode::usage', + 'site-usage' => 'cloud::microsoft::office365::onedrive::mode::siteusage', + 'users-activity' => 'cloud::microsoft::office365::onedrive::mode::usersactivity', ); $self->{custom_modes}{graphapi} = 'cloud::microsoft::office365::custom::graphapi'; diff --git a/cloud/microsoft/office365/sharepoint/mode/siteusage.pm b/cloud/microsoft/office365/sharepoint/mode/siteusage.pm index 35ddd321a..17c8719b3 100644 --- a/cloud/microsoft/office365/sharepoint/mode/siteusage.pm +++ b/cloud/microsoft/office365/sharepoint/mode/siteusage.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,7 +35,10 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_sites', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_sites', nlabel => 'sharepoint.sites.active.count', 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), @@ -83,7 +87,7 @@ sub custom_usage_perfdata { 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, + $self->{output}->perfdata_add(label => 'used' . $extra_label, nlabel => $self->{result_values}->{display} . '#sharepoint.sites.usage.bytes', 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), @@ -124,7 +128,7 @@ sub custom_usage_output { sub custom_usage_calc { my ($self, %options) = @_; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_id'}; + $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'}; @@ -173,36 +177,45 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-usage-active', set => { + { label => 'total-usage-active', nlabel => 'sharepoint.sites.active.usage.total.bytes', 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', template => '%d', + { label => 'total_usage_active', value => 'storage_used_active', template => '%d', min => 0, unit => 'B' }, ], } }, - { label => 'total-usage-inactive', set => { + { label => 'total-usage-inactive', nlabel => 'sharepoint.sites.inactive.usage.total.bytes', 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', template => '%d', + { label => 'total_usage_inactive', value => 'storage_used_inactive', template => '%d', min => 0, unit => 'B' }, ], } }, - { label => 'total-file-count', set => { - key_values => [ { name => 'file_count' } ], + { label => 'total-file-count-active', nlabel => 'sharepoint.sites.active.files.total.count', set => { + key_values => [ { name => 'file_count_active' } ], output_template => 'File Count (active sites): %d', perfdatas => [ - { label => 'total_file_count', value => 'file_count', template => '%d', + { label => 'total_file_count_active', value => 'file_count_active', template => '%d', min => 0 }, ], } }, - { label => 'total-active-file-count', set => { + { label => 'total-file-count-inactive', nlabel => 'sharepoint.sites.inactive.files.total.count', set => { + key_values => [ { name => 'file_count_inactive' } ], + output_template => 'File Count (inactive sites): %d', + perfdatas => [ + { label => 'total_file_count_inactive', value => 'file_count_inactive', template => '%d', + min => 0 }, + ], + } + }, + { label => 'total-active-file-count', nlabel => 'sharepoint.sites.files.active.total.count', set => { key_values => [ { name => 'active_file_count' } ], output_template => 'Active File Count (active sites): %d', perfdatas => [ @@ -211,7 +224,7 @@ sub set_counters { ], } }, - { label => 'total-visited-page-count', set => { + { label => 'total-visited-page-count', nlabel => 'sharepoint.sites.pages.visited.total.count', set => { key_values => [ { name => 'visited_page_count' } ], output_template => 'Visited Page Count (active sites): %d', perfdatas => [ @@ -220,7 +233,7 @@ sub set_counters { ], } }, - { label => 'total-page-view-count', set => { + { label => 'total-page-view-count', nlabel => 'sharepoint.sites.pages.viewed.total.count', set => { key_values => [ { name => 'page_view_count' } ], output_template => 'Page View Count (active sites): %d', perfdatas => [ @@ -239,39 +252,39 @@ sub set_counters { closure_custom_threshold_check => $self->can('custom_usage_threshold'), } }, - { label => 'file-count', set => { + { label => 'file-count', nlabel => 'sharepoint.sites.files.count', set => { key_values => [ { name => 'file_count' }, { name => 'url' }, { name => 'id' } ], output_template => 'File Count: %d', perfdatas => [ { label => 'file_count', value => 'file_count', template => '%d', - min => 0, label_extra_instance => 1, instance_use => 'id' }, + min => 0, label_extra_instance => 1, instance_use => 'url' }, ], } }, - { label => 'active-file-count', set => { + { label => 'active-file-count', nlabel => 'sharepoint.sites.files.active.count', set => { key_values => [ { name => 'active_file_count' }, { name => 'url' }, { name => 'id' } ], output_template => 'Active File Count: %d', perfdatas => [ { label => 'active_file_count', value => 'active_file_count', template => '%d', - min => 0, label_extra_instance => 1, instance_use => 'id' }, + min => 0, label_extra_instance => 1, instance_use => 'url' }, ], } }, - { label => 'visited-page-count', set => { + { label => 'visited-page-count', nlabel => 'sharepoint.sites.pages.visited.count', set => { key_values => [ { name => 'visited_page_count' }, { name => 'url' }, { name => 'id' } ], output_template => 'Visited Page Count: %d', perfdatas => [ { label => 'visited_page_count', value => 'visited_page_count', template => '%d', - min => 0, label_extra_instance => 1, instance_use => 'id' }, + min => 0, label_extra_instance => 1, instance_use => 'url' }, ], } }, - { label => 'page-view-count', set => { + { label => 'page-view-count', nlabel => 'sharepoint.sites.pages.viewed.count', set => { key_values => [ { name => 'page_view_count' }, { name => 'url' }, { name => 'id' } ], output_template => 'Page View Count: %d', perfdatas => [ { label => 'page_view_count', value => 'page_view_count', template => '%d', - min => 0, label_extra_instance => 1, instance_use => 'id' }, + min => 0, label_extra_instance => 1, instance_use => 'url' }, ], } }, @@ -298,13 +311,19 @@ 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->{global} = { storage_used_active => 0, storage_used_inactive => 0, + file_count_active => 0, file_count_inactive => 0, + active_file_count => 0 , visited_page_count => 0 , page_view_count => 0 }; $self->{sites} = {}; - my $results = $options{custom}->office_get_sharepoint_site_usage(); + my $results = $options{custom}->office_get_sharepoint_site_usage(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_sharepoint_site_usage(param => "date=" . $self->{active}->{report_date}); + } - foreach my $site (@{$results}) { + foreach my $site (@{$results}, @{$results_daily}) { 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); @@ -316,33 +335,33 @@ sub manage_selection { next; } - $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); + if ($site->{'Report Period'} != 1) { + if (!defined($site->{'Last Activity Date'}) || ($site->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{global}->{storage_used_inactive} += ($site->{'Storage Used (Byte)'} ne '') ? $site->{'Storage Used (Byte)'} : 0; + $self->{global}->{file_count_inactive} += ($site->{'File Count'} ne '') ? $site->{'File Count'} : 0; + $self->{output}->output_add(long_msg => "skipping '" . $site->{'Site URL'} . "': no activity.", debug => 1); + } + $self->{active}->{total}++; 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}->{file_count_active} += ($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_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'}; + $self->{sites}->{$site->{'Site URL'}}->{url} = $site->{'Site URL'}; + $self->{sites}->{$site->{'Site URL'}}->{id} = $site->{'Site Id'}; + $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'}}->{visited_page_count} = $site->{'Visited Page Count'}; + $self->{sites}->{$site->{'Site URL'}}->{page_view_count} = $site->{'Page View 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'}; } } @@ -352,10 +371,10 @@ __END__ =head1 MODE -Check sites usage (reporting period over the last 7 days). +Check sites usage (reporting period over the last refreshed day). (See link for details about metrics : -https://docs.microsoft.com/en-us/office365/admin/activity-reports/sharepoint-site-usage?view=o365-worldwide) +https://docs.microsoft.com/en-us/microsoft-365/admin/activity-reports/sharepoint-site-usage?view=o365-worldwide) =over 8 @@ -367,18 +386,23 @@ Can be: 'url', 'id' (can be a regexp). =item B<--warning-*> Threshold warning. -Can be: 'active-sites', 'total-usage-active' (count), -'total-usage-inactive' (count), 'total-file-count' (count), +Can be: 'active-sites', +'total-usage-active' (count), 'total-usage-inactive' (count), +'total-file-count-active' (count), 'total-file-count-inactive' (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), +'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: 'active-sites', 'total-usage' (count), 'total-file-count' (count), +Can be: 'active-sites', +'total-usage-active' (count), 'total-usage-inactive' (count), +'total-file-count-active' (count), 'total-file-count-inactive' (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), +'total-page-view-count' (count), +'usage' (count), 'file-count' (count), 'active-file-count' (count), 'visited-page-count' (count), 'page-view-count' (count). =item B<--filter-counters> diff --git a/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm b/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm index f27210261..5906a7386 100644 --- a/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm +++ b/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,7 +35,10 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_users', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_users', nlabel => 'sharepoint.users.active.count', 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), @@ -109,7 +113,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-viewed-edited-file-count', set => { + { label => 'total-viewed-edited-file-count', nlabel => 'sharepoint.users.files.viewed.total.count', set => { key_values => [ { name => 'viewed_edited_file_count' } ], output_template => 'Viewed or Edited File Count: %d', perfdatas => [ @@ -118,7 +122,7 @@ sub set_counters { ], } }, - { label => 'total-synced-file-count', set => { + { label => 'total-synced-file-count', nlabel => 'sharepoint.users.files.synced.total.count', set => { key_values => [ { name => 'synced_file_count' } ], output_template => 'Synced File Count: %d', perfdatas => [ @@ -127,7 +131,7 @@ sub set_counters { ], } }, - { label => 'total-shared-int-file-count', set => { + { label => 'total-shared-int-file-count', nlabel => 'sharepoint.users.files.shared.internally.total.count', set => { key_values => [ { name => 'shared_int_file_count' } ], output_template => 'Shared Internally File Count: %d', perfdatas => [ @@ -136,7 +140,7 @@ sub set_counters { ], } }, - { label => 'total-shared-ext-file-count', set => { + { label => 'total-shared-ext-file-count', nlabel => 'sharepoint.users.files.shared.externally.total.count', set => { key_values => [ { name => 'shared_ext_file_count' } ], output_template => 'Shared Externally File Count: %d', perfdatas => [ @@ -145,7 +149,7 @@ sub set_counters { ], } }, - { label => 'total-visited-page-count', set => { + { label => 'total-visited-page-count', nlabel => 'sharepoint.users.pages.visited.total.count', set => { key_values => [ { name => 'visited_page_count' } ], output_template => 'Visited Page Count (active sites): %d', perfdatas => [ @@ -156,7 +160,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{users} = [ - { label => 'viewed-edited-file-count', set => { + { label => 'viewed-edited-file-count', nlabel => 'sharepoint.users.files.viewed.count', set => { key_values => [ { name => 'viewed_edited_file_count' }, { name => 'name' } ], output_template => 'Viewed or Edited File Count: %d', perfdatas => [ @@ -165,7 +169,7 @@ sub set_counters { ], } }, - { label => 'synced-file-count', set => { + { label => 'synced-file-count', nlabel => 'sharepoint.users.files.synced.count', set => { key_values => [ { name => 'synced_file_count' }, { name => 'name' } ], output_template => 'Synced File Count: %d', perfdatas => [ @@ -174,7 +178,7 @@ sub set_counters { ], } }, - { label => 'shared-int-file-count', set => { + { label => 'shared-int-file-count', nlabel => 'sharepoint.users.files.shared.internally.count', set => { key_values => [ { name => 'shared_int_file_count' }, { name => 'name' } ], output_template => 'Shared Internally File Count: %d', perfdatas => [ @@ -183,7 +187,7 @@ sub set_counters { ], } }, - { label => 'shared-ext-file-count', set => { + { label => 'shared-ext-file-count', nlabel => 'sharepoint.users.files.shared.externally.count', set => { key_values => [ { name => 'shared_ext_file_count' }, { name => 'name' } ], output_template => 'Shared Externally File Count: %d', perfdatas => [ @@ -192,7 +196,7 @@ sub set_counters { ], } }, - { label => 'visited-page-count', set => { + { label => 'visited-page-count', nlabel => 'sharepoint.users.pages.visited.count', set => { key_values => [ { name => 'visited_page_count' }, { name => 'name' } ], output_template => 'Visited Page Count: %d', perfdatas => [ @@ -222,29 +226,33 @@ 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, + $self->{global} = { viewed_edited_file_count => 0, synced_file_count => 0, + shared_int_file_count => 0, shared_ext_file_count => 0, visited_page_count => 0 }; $self->{users} = {}; - my $results = $options{custom}->office_get_sharepoint_activity(); + my $results = $options{custom}->office_get_sharepoint_activity(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_sharepoint_activity(param => "date=" . $self->{active}->{report_date}); + } - foreach my $user (@{$results}) { + foreach my $user (@{$results}, @{$results_daily}) { 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); next; } - - $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); + if ($user->{'Report Period'} != 1) { + if (!defined($user->{'Last Activity Date'}) || ($user->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1); + } + $self->{active}->{total}++; 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; @@ -268,10 +276,10 @@ __END__ =head1 MODE -Check users activity (reporting period over the last 7 days). +Check users activity (reporting period over the last refreshed day). (See link for details about metrics : -https://docs.microsoft.com/en-us/office365/admin/activity-reports/sharepoint-activity?view=o365-worldwide) +https://docs.microsoft.com/en-us/microsoft-365/admin/activity-reports/sharepoint-activity?view=o365-worldwide) =over 8 @@ -282,20 +290,24 @@ Filter users. =item B<--warning-*> Threshold warning. -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). +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: '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). +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<--filter-counters> diff --git a/cloud/microsoft/office365/skype/mode/devicesusage.pm b/cloud/microsoft/office365/skype/mode/devicesusage.pm index a32b1ac55..c868a4712 100644 --- a/cloud/microsoft/office365/skype/mode/devicesusage.pm +++ b/cloud/microsoft/office365/skype/mode/devicesusage.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,11 +35,14 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_users', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_devices', nlabel => 'skype.devices.active.count', 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}); + unit => 'devices', min => 0, max => $self->{result_values}->{total}); } sub custom_active_threshold { @@ -58,7 +62,7 @@ sub custom_active_threshold { sub custom_active_output { my ($self, %options) = @_; - my $msg = sprintf("Active users on %s : %d/%d (%.2f%%)", + my $msg = sprintf("Active devices on %s : %d/%d (%.2f%%)", $self->{result_values}->{report_date}, $self->{result_values}->{active}, $self->{result_values}->{total}, @@ -92,7 +96,7 @@ sub set_counters { ]; $self->{maps_counters}->{active} = [ - { label => 'active-users', set => { + { label => 'active-devices', 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'), @@ -102,7 +106,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'windows', set => { + { label => 'windows', nlabel => 'skype.devices.windows.count', set => { key_values => [ { name => 'windows' } ], output_template => 'Windows: %d', perfdatas => [ @@ -111,7 +115,7 @@ sub set_counters { ], } }, - { label => 'ipad', set => { + { label => 'ipad', nlabel => 'skype.devices.ipad.count', set => { key_values => [ { name => 'ipad' } ], output_template => 'iPad: %d', perfdatas => [ @@ -120,7 +124,7 @@ sub set_counters { ], } }, - { label => 'iphone', set => { + { label => 'iphone', nlabel => 'skype.devices.iphone.count', set => { key_values => [ { name => 'iphone' } ], output_template => 'iPhone: %d', perfdatas => [ @@ -129,7 +133,7 @@ sub set_counters { ], } }, - { label => 'android-phone', set => { + { label => 'android-phone', nlabel => 'skype.devices.android.count', set => { key_values => [ { name => 'android_phone' } ], output_template => 'Android Phone: %d', perfdatas => [ @@ -138,7 +142,7 @@ sub set_counters { ], } }, - { label => 'windows-phone', set => { + { label => 'windows-phone', nlabel => 'skype.devices.windowsphone.count', set => { key_values => [ { name => 'windows_phone' } ], output_template => 'Windows Phone: %d', perfdatas => [ @@ -169,26 +173,36 @@ sub manage_selection { $self->{active} = { active => 0, total => 0, report_date => '' }; $self->{global} = { windows => 0, ipad => 0, iphone => 0, android_phone => 0, windows_phone => 0 }; - my $results = $options{custom}->office_get_skype_device_usage(); - - foreach my $user (@{$results}) { - $self->{active}->{report_date} = $user->{'Report Refresh Date'} if ($self->{active}->{report_date} eq ''); + my $results = $options{custom}->office_get_skype_device_usage(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_skype_device_usage(param => "date=" . $self->{active}->{report_date}); + } + foreach my $user (@{$results}, @{$results_daily}) { 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); next; } - - $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); + my $used_devices = 0; + $used_devices++ if ($user->{'Used Windows'} =~ /Yes/); + $used_devices++ if ($user->{'Used iPad'} =~ /Yes/); + $used_devices++ if ($user->{'Used iPhone'} =~ /Yes/); + $used_devices++ if ($user->{'Used Android Phone'} =~ /Yes/); + $used_devices++ if ($user->{'Used Windows Phone'} =~ /Yes/); + + if ($user->{'Report Period'} != 1) { + if (!defined($user->{'Last Activity Date'}) || ($user->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1); + } + $self->{active}->{total} += $used_devices; next; } - $self->{active}->{active}++; + $self->{active}->{active} += $used_devices; $self->{global}->{windows}++ if ($user->{'Used Windows'} =~ /Yes/); $self->{global}->{ipad}++ if ($user->{'Used iPad'} =~ /Yes/); @@ -204,10 +218,10 @@ __END__ =head1 MODE -Check devices usage (reporting period over the last 7 days). +Check devices usage (reporting period over the last refreshed day). (See link for details about metrics : -https://docs.microsoft.com/en-us/office365/admin/activity-reports/microsoft-teams-device-usage?view=o365-worldwide) +https://docs.microsoft.com/en-us/SkypeForBusiness/skype-for-business-online-reporting/device-usage-report) =over 8 @@ -218,14 +232,14 @@ Filter users. =item B<--warning-*> Threshold warning. -Can be: 'active-users', 'windows' (count), 'ipad' (count), +Can be: 'active-devices', 'windows' (count), 'ipad' (count), 'iphone' (count), 'android-phone' (count), 'windows-phone' (count). =item B<--critical-*> Threshold critical. -Can be: 'active-users', 'windows' (count), 'ipad' (count), +Can be: 'active-devices', 'windows' (count), 'ipad' (count), 'iphone' (count), 'android-phone' (count), 'windows-phone' (count). diff --git a/cloud/microsoft/office365/skype/mode/usersactivity.pm b/cloud/microsoft/office365/skype/mode/usersactivity.pm index f7361d085..895cf8d86 100644 --- a/cloud/microsoft/office365/skype/mode/usersactivity.pm +++ b/cloud/microsoft/office365/skype/mode/usersactivity.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,7 +35,10 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_users', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_users', nlabel => 'skype.users.active.count', 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), @@ -109,7 +113,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-peer-to-peer-sessions', set => { + { label => 'total-peer-to-peer-sessions', nlabel => 'skype.users.sessions.p2p.total.count', set => { key_values => [ { name => 'peer_to_peer_sessions' } ], output_template => 'Peer-to-peer Sessions Count: %d', perfdatas => [ @@ -118,7 +122,7 @@ sub set_counters { ], } }, - { label => 'total-organized-conference', set => { + { label => 'total-organized-conference', nlabel => 'skype.users.conferences.organized.total.count', set => { key_values => [ { name => 'organized_conference' } ], output_template => 'Organized Conference Count: %d', perfdatas => [ @@ -127,7 +131,7 @@ sub set_counters { ], } }, - { label => 'total-participated-conference', set => { + { label => 'total-participated-conference', nlabel => 'skype.users.conferences.participated.total.count', set => { key_values => [ { name => 'participated_conference' } ], output_template => 'Participated Conference Count: %d', perfdatas => [ @@ -138,7 +142,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{users} = [ - { label => 'peer-to-peer-sessions', set => { + { label => 'peer-to-peer-sessions', nlabel => 'skype.users.sessions.p2p.count', set => { key_values => [ { name => 'peer_to_peer_sessions' }, { name => 'name' } ], output_template => 'Peer-to-peer Sessions Count: %d', perfdatas => [ @@ -147,7 +151,7 @@ sub set_counters { ], } }, - { label => 'organized-conference', set => { + { label => 'organized-conference', nlabel => 'skype.users.conferences.organized.count', set => { key_values => [ { name => 'organized_conference' }, { name => 'name' } ], output_template => 'Organized Conference Count: %d', perfdatas => [ @@ -156,7 +160,7 @@ sub set_counters { ], } }, - { label => 'participated-conference', set => { + { label => 'participated-conference', nlabel => 'skype.users.conferences.participated.count', set => { key_values => [ { name => 'participated_conference' }, { name => 'name' } ], output_template => 'Participated Conference Count: %d', perfdatas => [ @@ -189,22 +193,25 @@ sub manage_selection { $self->{global} = { peer_to_peer_sessions => 0, organized_conference => 0, participated_conference => 0 }; $self->{users} = {}; - my $results = $options{custom}->office_get_skype_activity(); - - foreach my $user (@{$results}) { - $self->{active}->{report_date} = $user->{'Report Refresh Date'} if ($self->{active}->{report_date} eq ''); + my $results = $options{custom}->office_get_skype_activity(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_skype_activity(param => "date=" . $self->{active}->{report_date}); + } + foreach my $user (@{$results}, @{$results_daily}) { 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); next; } - $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); + if ($user->{'Report Period'} != 1) { + if (!defined($user->{'Last Activity Date'}) || ($user->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1); + } + $self->{active}->{total}++; next; } @@ -227,7 +234,7 @@ __END__ =head1 MODE -Check users activity (reporting period over the last 7 days). +Check users activity (reporting period over the last refreshed day). (See link for details about metrics : https://docs.microsoft.com/en-us/SkypeForBusiness/skype-for-business-online-reporting/activity-report) diff --git a/cloud/microsoft/office365/teams/mode/devicesusage.pm b/cloud/microsoft/office365/teams/mode/devicesusage.pm index 8edb722b4..54431abe2 100644 --- a/cloud/microsoft/office365/teams/mode/devicesusage.pm +++ b/cloud/microsoft/office365/teams/mode/devicesusage.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,11 +35,14 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_users', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_devices', nlabel => 'teams.devices.active.count', 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}); + unit => 'devices', min => 0, max => $self->{result_values}->{total}); } sub custom_active_threshold { @@ -58,7 +62,7 @@ sub custom_active_threshold { sub custom_active_output { my ($self, %options) = @_; - my $msg = sprintf("Active users on %s : %d/%d (%.2f%%)", + my $msg = sprintf("Active devices on %s : %d/%d (%.2f%%)", $self->{result_values}->{report_date}, $self->{result_values}->{active}, $self->{result_values}->{total}, @@ -92,7 +96,7 @@ sub set_counters { ]; $self->{maps_counters}->{active} = [ - { label => 'active-users', set => { + { label => 'active-devices', 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'), @@ -102,7 +106,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'windows', set => { + { label => 'windows', nlabel => 'teams.devices.windows.count', set => { key_values => [ { name => 'windows' } ], output_template => 'Windows: %d', perfdatas => [ @@ -111,7 +115,7 @@ sub set_counters { ], } }, - { label => 'mac', set => { + { label => 'mac', nlabel => 'teams.devices.mac.count', set => { key_values => [ { name => 'mac' } ], output_template => 'Mac: %d', perfdatas => [ @@ -120,7 +124,7 @@ sub set_counters { ], } }, - { label => 'web', set => { + { label => 'web', nlabel => 'teams.devices.web.count', set => { key_values => [ { name => 'web' } ], output_template => 'Web: %d', perfdatas => [ @@ -129,7 +133,7 @@ sub set_counters { ], } }, - { label => 'ios', set => { + { label => 'ios', nlabel => 'teams.devices.ios.count', set => { key_values => [ { name => 'ios' } ], output_template => 'iOS: %d', perfdatas => [ @@ -138,7 +142,7 @@ sub set_counters { ], } }, - { label => 'android-phone', set => { + { label => 'android-phone', nlabel => 'teams.devices.android.count', set => { key_values => [ { name => 'android_phone' } ], output_template => 'Android Phone: %d', perfdatas => [ @@ -147,7 +151,7 @@ sub set_counters { ], } }, - { label => 'windows-phone', set => { + { label => 'windows-phone', nlabel => 'teams.devices.windowsphone.count', set => { key_values => [ { name => 'windows_phone' } ], output_template => 'Windows Phone: %d', perfdatas => [ @@ -178,25 +182,37 @@ sub manage_selection { $self->{active} = { active => 0, total => 0, report_date => '' }; $self->{global} = { windows => 0, mac => 0, web => 0, ios => 0, android_phone => 0, windows_phone => 0 }; - my $results = $options{custom}->office_get_teams_device_usage(); + my $results = $options{custom}->office_get_teams_device_usage(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_teams_device_usage(param => "date=" . $self->{active}->{report_date}); + } - foreach my $user (@{$results}) { + foreach my $user (@{$results}, @{$results_daily}) { 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); next; } - - $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); + my $used_devices = 0; + $used_devices++ if ($user->{'Used Windows'} =~ /Yes/); + $used_devices++ if ($user->{'Used Mac'} =~ /Yes/); + $used_devices++ if ($user->{'Used Web'} =~ /Yes/); + $used_devices++ if ($user->{'Used iOS'} =~ /Yes/); + $used_devices++ if ($user->{'Used Android Phone'} =~ /Yes/); + $used_devices++ if ($user->{'Used Windows Phone'} =~ /Yes/); + + if ($user->{'Report Period'} != 1) { + if (!defined($user->{'Last Activity Date'}) || ($user->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1); + } + $self->{active}->{total} += $used_devices; next; } - $self->{active}->{report_date} = $user->{'Report Refresh Date'}; - $self->{active}->{active}++; + $self->{active}->{active} += $used_devices; $self->{global}->{windows}++ if ($user->{'Used Windows'} =~ /Yes/); $self->{global}->{mac}++ if ($user->{'Used Mac'} =~ /Yes/); @@ -213,7 +229,7 @@ __END__ =head1 MODE -Check devices usage (reporting period over the last 7 days). +Check devices usage (reporting period over the last refreshed day). (See link for details about metrics : https://docs.microsoft.com/en-us/office365/admin/activity-reports/microsoft-teams-device-usage?view=o365-worldwide) @@ -227,14 +243,14 @@ Filter users. =item B<--warning-*> Threshold warning. -Can be: 'active-users', 'windows' (count), 'mac' (count), +Can be: 'active-devices', 'windows' (count), 'mac' (count), 'web' (count), 'ios' (count), 'android-phone' (count), 'windows-phone' (count). =item B<--critical-*> Threshold critical. -Can be: 'active-users', 'windows' (count), 'mac' (count), +Can be: 'active-devices', 'windows' (count), 'mac' (count), 'web' (count), 'ios' (count), 'android-phone' (count), 'windows-phone' (count). diff --git a/cloud/microsoft/office365/teams/mode/usersactivity.pm b/cloud/microsoft/office365/teams/mode/usersactivity.pm index 0d13a29ff..f589d2010 100644 --- a/cloud/microsoft/office365/teams/mode/usersactivity.pm +++ b/cloud/microsoft/office365/teams/mode/usersactivity.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Time::Local; sub custom_active_perfdata { my ($self, %options) = @_; @@ -34,7 +35,10 @@ sub custom_active_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'active_users', + $self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; + $self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); + + $self->{output}->perfdata_add(label => 'active_users', nlabel => 'teams.users.active.count', 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), @@ -109,7 +113,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-team-chat', set => { + { label => 'total-team-chat', nlabel => 'teams.users.messages.team.total.count', set => { key_values => [ { name => 'team_chat' } ], output_template => 'Team Chat Message Count: %d', perfdatas => [ @@ -118,7 +122,7 @@ sub set_counters { ], } }, - { label => 'total-private-chat', set => { + { label => 'total-private-chat', nlabel => 'teams.users.messages.private.total.count', set => { key_values => [ { name => 'private_chat' } ], output_template => 'Private Chat Message Count: %d', perfdatas => [ @@ -127,7 +131,7 @@ sub set_counters { ], } }, - { label => 'total-call', set => { + { label => 'total-call', nlabel => 'teams.users.call.total.count', set => { key_values => [ { name => 'call' } ], output_template => 'Call Count: %d', perfdatas => [ @@ -136,7 +140,7 @@ sub set_counters { ], } }, - { label => 'total-meeting', set => { + { label => 'total-meeting', nlabel => 'teams.users.meeting.total.count', set => { key_values => [ { name => 'meeting' } ], output_template => 'Meeting Count: %d', perfdatas => [ @@ -147,7 +151,7 @@ sub set_counters { }, ]; $self->{maps_counters}->{users} = [ - { label => 'team-chat', set => { + { label => 'team-chat', nlabel => 'teams.users.messages.team.count', set => { key_values => [ { name => 'team_chat' }, { name => 'name' } ], output_template => 'Team Chat Message Count: %d', perfdatas => [ @@ -156,7 +160,7 @@ sub set_counters { ], } }, - { label => 'private-chat', set => { + { label => 'private-chat', nlabel => 'teams.users.messages.private.count', set => { key_values => [ { name => 'private_chat' }, { name => 'name' } ], output_template => 'Private Chat Message Count: %d', perfdatas => [ @@ -165,7 +169,7 @@ sub set_counters { ], } }, - { label => 'call', set => { + { label => 'call', nlabel => 'teams.users.call.count', set => { key_values => [ { name => 'call' }, { name => 'name' } ], output_template => 'Call Count: %d', perfdatas => [ @@ -174,7 +178,7 @@ sub set_counters { ], } }, - { label => 'meeting', set => { + { label => 'meeting', nlabel => 'teams.users.meeting.count', set => { key_values => [ { name => 'meeting' }, { name => 'name' } ], output_template => 'Meeting Count: %d', perfdatas => [ @@ -207,24 +211,28 @@ sub manage_selection { $self->{global} = { team_chat => 0, private_chat => 0, call => 0, meeting => 0 }; $self->{users} = {}; - my $results = $options{custom}->office_get_teams_activity(); + my $results = $options{custom}->office_get_teams_activity(param => "period='D7'"); + my $results_daily = []; + if (scalar(@{$results})) { + $self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; + $results_daily = $options{custom}->office_get_teams_activity(param => "date=" . $self->{active}->{report_date}); + } - foreach my $user (@{$results}) { + foreach my $user (@{$results}, @{$results_daily}) { 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); next; } - $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); + if ($user->{'Report Period'} != 1) { + if (!defined($user->{'Last Activity Date'}) || ($user->{'Last Activity Date'} ne $self->{active}->{report_date})) { + $self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1); + } + $self->{active}->{total}++; next; } - $self->{active}->{report_date} = $user->{'Report Refresh Date'}; $self->{active}->{active}++; $self->{global}->{team_chat} += $user->{'Team Chat Message Count'}; @@ -237,7 +245,6 @@ sub manage_selection { $self->{users}->{$user->{'User Principal Name'}}->{private_chat} = $user->{'Private Chat Message Count'}; $self->{users}->{$user->{'User Principal Name'}}->{call} = $user->{'Call Count'}; $self->{users}->{$user->{'User Principal Name'}}->{meeting} = $user->{'Meeting Count'}; - $self->{users}->{$user->{'User Principal Name'}}->{last_activity_date} = $user->{'Last Activity Date'}; } } @@ -247,7 +254,7 @@ __END__ =head1 MODE -Check users activity (reporting period over the last 7 days). +Check users activity (reporting period over the last refreshed day). (See link for details about metrics : https://docs.microsoft.com/en-us/office365/admin/activity-reports/microsoft-teams-user-activity?view=o365-worldwide)