This commit is contained in:
garnier-quentin 2019-02-05 14:30:32 +01:00
commit 1b8b665249
4 changed files with 336 additions and 28 deletions

View File

@ -194,27 +194,26 @@ sub run_global {
if (defined($options{config}->{cb_suffix_output})); if (defined($options{config}->{cb_suffix_output}));
$suffix_output = '' if (!defined($suffix_output)); $suffix_output = '' if (!defined($suffix_output));
if ($called_multiple == 1) { if ($called_multiple == 1 && $long_msg ne '') {
$self->{output}->output_add(long_msg => "$options{indent_long_output}${prefix_output}${long_msg}${suffix_output}"); $self->{output}->output_add(long_msg => $options{indent_long_output} . $prefix_output. $long_msg . $suffix_output);
} }
my $exit = $self->{output}->get_most_critical(status => [ @exits ]); my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
if ($called_multiple == 0) { if ($called_multiple == 0) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}" short_msg => $prefix_output . $short_msg . $suffix_output);
);
} else { } else {
$self->run_multiple_prefix_output(severity => $exit, $self->run_multiple_prefix_output(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}"); short_msg => $prefix_output . $short_msg . $suffix_output);
} }
} else { } else {
if ($long_msg ne '' && $multiple_parent == 0) { if ($long_msg ne '' && $multiple_parent == 0) {
if ($called_multiple == 0) { if ($called_multiple == 0) {
$self->{output}->output_add(short_msg => "${prefix_output}${long_msg}${suffix_output}") ; $self->{output}->output_add(short_msg => $prefix_output . $long_msg . $suffix_output) ;
} else { } else {
$self->run_multiple_prefix_output(severity => 'ok', $self->run_multiple_prefix_output(severity => 'ok',
short_msg => "${prefix_output}${long_msg}${suffix_output}"); short_msg => $prefix_output . $long_msg . $suffix_output);
} }
} }
} }
@ -226,6 +225,7 @@ sub run_instances {
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
my $display_status_lo = defined($options{display_status_long_output}) && $options{display_status_long_output} == 1 ? 1 : 0; my $display_status_lo = defined($options{display_status_long_output}) && $options{display_status_long_output} == 1 ? 1 : 0;
my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0; my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0;
my $no_message_multiple = 1;
$self->{lproblems} = 0; $self->{lproblems} = 0;
$self->{multiple} = 1; $self->{multiple} = 1;
@ -233,13 +233,9 @@ sub run_instances {
$self->{multiple} = 0; $self->{multiple} = 0;
} }
if ($self->{multiple} == 1 && $resume == 0) {
$self->{output}->output_add(severity => 'OK',
short_msg => $options{config}->{message_multiple});
}
my $message_separator = defined($options{config}->{message_separator}) ? my $message_separator = defined($options{config}->{message_separator}) ?
$options{config}->{message_separator}: ', '; $options{config}->{message_separator}: ', ';
foreach my $id (sort keys %{$self->{$options{config}->{name}}}) { foreach my $id (sort keys %{$self->{$options{config}->{name}}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = (); my @exits = ();
@ -249,6 +245,7 @@ sub run_instances {
next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' && next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' &&
$_->{label} !~ /$self->{option_results}->{filter_counters}/); $_->{label} !~ /$self->{option_results}->{filter_counters}/);
$no_message_multiple = 0;
$obj->set(instance => $id); $obj->set(instance => $id);
my ($value_check) = $obj->execute(new_datas => $self->{new_datas}, my ($value_check) = $obj->execute(new_datas => $self->{new_datas},
@ -288,7 +285,9 @@ sub run_instances {
# in mode grouped, we don't display 'ok' # in mode grouped, we don't display 'ok'
my $debug = 0; my $debug = 0;
$debug = 1 if ($display_status_lo == 1 && $self->{output}->is_status(value => $exit, compare => 'OK', litteral => 1)); $debug = 1 if ($display_status_lo == 1 && $self->{output}->is_status(value => $exit, compare => 'OK', litteral => 1));
$self->{output}->output_add(long_msg => ($display_status_lo == 1 ? lc($exit) . ': ' : '') . "${prefix_output}${long_msg}${suffix_output}", debug => $debug); if (scalar @{$self->{maps_counters}->{$options{config}->{name}}} > 0 && $long_msg ne '') {
$self->{output}->output_add(long_msg => ($display_status_lo == 1 ? lc($exit) . ': ' : '') . $prefix_output . $long_msg . $suffix_output, debug => $debug);
}
if ($resume == 1) { if ($resume == 1) {
$self->{most_critical_instance} = $self->{output}->get_most_critical(status => [ $self->{most_critical_instance}, $exit ]); $self->{most_critical_instance} = $self->{output}->get_most_critical(status => [ $self->{most_critical_instance}, $exit ]);
next; next;
@ -296,14 +295,17 @@ sub run_instances {
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}" short_msg => $prefix_output . $long_msg . $suffix_output);
);
} }
if ($self->{multiple} == 0) { if ($self->{multiple} == 0) {
$self->{output}->output_add(short_msg => "${prefix_output}${long_msg}${suffix_output}"); $self->{output}->output_add(short_msg => $prefix_output . $long_msg . $suffix_output);
} }
} }
if ($no_message_multiple == 0 && $self->{multiple} == 1 && $resume == 0) {
$self->{output}->output_add(short_msg => $options{config}->{message_multiple});
}
} }
sub run_group { sub run_group {
@ -372,18 +374,16 @@ sub run_multiple_instances {
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? $options{multiple_parent} : 0; my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? $options{multiple_parent} : 0;
my $indent_long_output = defined($options{indent_long_output}) ? $options{indent_long_output} : ''; my $indent_long_output = defined($options{indent_long_output}) ? $options{indent_long_output} : '';
my $no_message_multiple = 1;
my $multiple = 1; my $multiple = 1;
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
$multiple = 0; $multiple = 0;
} }
if ($multiple == 1 && $multiple_parent == 0) {
$self->{output}->output_add(short_msg => $options{config}->{message_multiple});
}
my $message_separator = defined($options{config}->{message_separator}) ? my $message_separator = defined($options{config}->{message_separator}) ?
$options{config}->{message_separator}: ', '; $options{config}->{message_separator}: ', ';
foreach my $id (sort keys %{$self->{$options{config}->{name}}}) { foreach my $id (sort keys %{$self->{$options{config}->{name}}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = (); my @exits = ();
@ -399,6 +399,8 @@ sub run_multiple_instances {
} elsif ($multiple_parent == 1 && $multiple == 0) { } elsif ($multiple_parent == 1 && $multiple == 0) {
$instance = $options{instance_parent}; $instance = $options{instance_parent};
} }
$no_message_multiple = 0;
$obj->set(instance => $instance); $obj->set(instance => $instance);
my ($value_check) = $obj->execute(new_datas => $self->{new_datas}, my ($value_check) = $obj->execute(new_datas => $self->{new_datas},
@ -438,19 +440,24 @@ sub run_multiple_instances {
$suffix_output = '' if (!defined($suffix_output)); $suffix_output = '' if (!defined($suffix_output));
my $exit = $self->{output}->get_most_critical(status => [ @exits ]); my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
$self->{output}->output_add(long_msg => "${indent_long_output}${prefix_output}${long_msg}${suffix_output}") if (scalar @{$self->{maps_counters}->{$options{config}->{name}}} > 0 && $long_msg ne '') {
$self->{output}->output_add(long_msg => $indent_long_output . $prefix_output . $long_msg . $suffix_output)
if (!defined($options{config}->{display_long}) || $options{config}->{display_long} != 0); if (!defined($options{config}->{display_long}) || $options{config}->{display_long} != 0);
}
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->run_multiple_prefix_output(severity => $exit, $self->run_multiple_prefix_output(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}" short_msg => $prefix_output . $short_msg . $suffix_output);
);
} }
if ($multiple == 0 && $multiple_parent == 0) { if ($multiple == 0 && $multiple_parent == 0) {
$self->run_multiple_prefix_output(severity => 'ok', short_msg => "${prefix_output}${long_msg}${suffix_output}"); $self->run_multiple_prefix_output(severity => 'ok', short_msg => $prefix_output . $long_msg . $suffix_output);
} }
} }
if ($no_message_multiple == 0 && $multiple == 1 && $multiple_parent == 0) {
$self->{output}->output_add(short_msg => $options{config}->{message_multiple});
}
} }
sub run_multiple_prefix_output { sub run_multiple_prefix_output {

View File

@ -195,6 +195,8 @@ sub request_api_json {
$self->settings(); $self->settings();
$self->{output}->output_add(long_msg => "URL: '" . $options{full_url} . "'", debug => 1);
my $content = $self->{http}->request(%options); my $content = $self->{http}->request(%options);
my $decoded; my $decoded;
@ -224,6 +226,8 @@ sub request_api_csv {
$self->settings(); $self->settings();
$self->{output}->output_add(long_msg => "URL: '" . $options{full_url} . "'", debug => 1);
my $content = $self->{http}->request(%options); my $content = $self->{http}->request(%options);
my $response = $self->{http}->get_response(); my $response = $self->{http}->get_response();
@ -358,6 +362,23 @@ sub office_get_exchange_mailbox_usage {
return $response; return $response;
} }
sub office_get_teams_activity_set_url {
my ($self, %options) = @_;
my $url = $self->{graph_endpoint} . "/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')";
return $url;
}
sub office_get_teams_activity {
my ($self, %options) = @_;
my $full_url = $self->office_get_teams_activity_set_url(%options);
my $response = $self->request_api_csv(method => 'GET', full_url => $full_url, hostname => '');
return $response;
}
1; 1;
__END__ __END__

View File

@ -0,0 +1,231 @@
#
# Copyright 2019 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::teams::mode::usersactivity;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_global_output {
my ($self, %options) = @_;
return "Total ";
}
sub prefix_user_output {
my ($self, %options) = @_;
return "User '" . $options{instance_value}->{name} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ 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}->{global} = [
{ label => 'total-team-chat', set => {
key_values => [ { name => 'team_chat' } ],
output_template => 'Team Chat Message Count: %d',
perfdatas => [
{ label => 'total_team_chat', value => 'team_chat_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'total-private-chat', set => {
key_values => [ { name => 'private_chat' } ],
output_template => 'Private Chat Message Count: %d',
perfdatas => [
{ label => 'total_private_chat', value => 'private_chat_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'total-call', set => {
key_values => [ { name => 'call' } ],
output_template => 'Call Count: %d',
perfdatas => [
{ label => 'total_call', value => 'call_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'total-meeting', set => {
key_values => [ { name => 'meeting' } ],
output_template => 'Meeting Count: %d',
perfdatas => [
{ label => 'total_meeting', value => 'meeting_absolute', template => '%d',
min => 0 },
],
}
},
];
$self->{maps_counters}->{users} = [
{ label => 'team-chat', set => {
key_values => [ { name => 'team_chat' }, { name => 'name' } ],
output_template => 'Team Chat Message Count: %d',
perfdatas => [
{ label => 'team_chat', value => 'team_chat_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
],
}
},
{ label => 'private-chat', set => {
key_values => [ { name => 'private_chat' }, { name => 'name' } ],
output_template => 'Private Chat Message Count: %d',
perfdatas => [
{ label => 'private_chat', value => 'private_chat_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
],
}
},
{ label => 'call', set => {
key_values => [ { name => 'call' }, { name => 'name' } ],
output_template => 'Call Count: %d',
perfdatas => [
{ label => 'call', value => 'call_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
],
}
},
{ label => 'meeting', set => {
key_values => [ { name => 'meeting' }, { name => 'name' } ],
output_template => 'Meeting Count: %d',
perfdatas => [
{ label => 'meeting', value => 'meeting_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
],
}
},
{ label => 'last-activity', threshold => 0, set => {
key_values => [ { name => 'last_activity_date' }, { name => 'name' } ],
output_template => 'Last Activity: %s',
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-counters:s" => { name => 'filter_counters' },
"filter-user:s" => { name => 'filter_user' },
"active-only" => { name => 'active_only' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{users} = {};
my $results = $options{custom}->office_get_teams_activity();
$self->{global} = { team_chat => 0, private_chat => 0, call => 0, meeting => 0 };
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;
}
if ($self->{option_results}->{active_only} && defined($user->{'Last Activity Date'}) && $user->{'Last Activity Date'} eq '') {
$self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1);
next;
}
$self->{users}->{$user->{'User Principal Name'}}->{name} = $user->{'User Principal Name'};
$self->{users}->{$user->{'User Principal Name'}}->{team_chat} = $user->{'Team Chat Message Count'};
$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'};
$self->{global}->{team_chat} += $user->{'Team Chat Message Count'};
$self->{global}->{private_chat} += $user->{'Private Chat Message Count'};
$self->{global}->{call} += $user->{'Call Count'};
$self->{global}->{meeting} += $user->{'Meeting Count'};
}
if (scalar(keys %{$self->{users}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check users activity (reporting period over the last 7 days).
(See link for details about metrics :
https://docs.microsoft.com/en-us/office365/admin/activity-reports/microsoft-teams-user-activity?view=o365-worldwide)
=over 8
=item B<--filter-user>
Filter users.
=item B<--warning-*>
Threshold warning.
Can be: 'total-team-chat', 'total-private-chat', 'total-call',
'total-meeting', 'team-chat', 'private-chat', 'call', 'meeting'.
=item B<--critical-*>
Threshold critical.
Can be: 'total-team-chat', 'total-private-chat', 'total-call',
'total-meeting', 'team-chat', 'private-chat', 'call', 'meeting'.
=item B<--active-only>
Filter only active entries ('Last Activity' set).
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example to hide per user counters: --filter-counters='total'
=back
=cut

View File

@ -0,0 +1,49 @@
#
# Copyright 2019 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::teams::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ( $class, %options ) = @_;
my $self = $class->SUPER::new( package => __PACKAGE__, %options );
bless $self, $class;
$self->{version} = '0.1';
%{ $self->{modes} } = (
'users-activity' => 'cloud::microsoft::office365::teams::mode::usersactivity',
);
$self->{custom_modes}{graphapi} = 'cloud::microsoft::office365::custom::graphapi';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Microsoft Office 365 Teams.
=cut