From 09db096c31748e44d75bfaa728d4272d085b829d Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Wed, 6 Feb 2019 11:11:48 +0100 Subject: [PATCH] enh office 365 teams plugin --- .../office365/teams/mode/devicesusage.pm | 17 ++++++++++++++--- .../office365/teams/mode/usersactivity.pm | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/centreon-plugins/cloud/microsoft/office365/teams/mode/devicesusage.pm b/centreon-plugins/cloud/microsoft/office365/teams/mode/devicesusage.pm index 95156255a..9e587c4bb 100644 --- a/centreon-plugins/cloud/microsoft/office365/teams/mode/devicesusage.pm +++ b/centreon-plugins/cloud/microsoft/office365/teams/mode/devicesusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::microsoft::office365::teams::mode::devicesusage; +package cloud::microsoft::office365::teams::mode::deviceusage; use base qw(centreon::plugins::templates::counter); @@ -169,6 +169,7 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { + "filter-user:s" => { name => 'filter_user' }, "units:s" => { name => 'units', default => '%' }, "filter-counters:s" => { name => 'filter_counters' }, }); @@ -191,9 +192,15 @@ sub manage_selection { my $results = $options{custom}->office_get_teams_device_usage(); - $self->{active}->{total} = scalar(@{$results}); - 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); + 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); @@ -225,6 +232,10 @@ https://docs.microsoft.com/en-us/office365/admin/activity-reports/microsoft-team =over 8 +=item B<--filter-user> + +Filter users. + =item B<--warning-*> Threshold warning. diff --git a/centreon-plugins/cloud/microsoft/office365/teams/mode/usersactivity.pm b/centreon-plugins/cloud/microsoft/office365/teams/mode/usersactivity.pm index d266ddcd5..108d783f3 100644 --- a/centreon-plugins/cloud/microsoft/office365/teams/mode/usersactivity.pm +++ b/centreon-plugins/cloud/microsoft/office365/teams/mode/usersactivity.pm @@ -196,6 +196,7 @@ sub new { $self->{version} = '1.0'; $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' }, }); @@ -219,9 +220,15 @@ sub manage_selection { my $results = $options{custom}->office_get_teams_activity(); - $self->{active}->{total} = scalar(@{$results}); - 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); + 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); @@ -258,6 +265,10 @@ https://docs.microsoft.com/en-us/office365/admin/activity-reports/microsoft-team =over 8 +=item B<--filter-user> + +Filter users. + =item B<--warning-*> Threshold warning.