| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package cloud::microsoft::office365::skype::mode::usersactivity; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Time::Local; |
| 28 |
|
| 29 |
sub custom_active_perfdata { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my %total_options = (); |
| 33 |
if ($self->{instance_mode}->{option_results}->{units} eq '%') { |
| 34 |
$total_options{total} = $self->{result_values}->{total}; |
| 35 |
$total_options{cast_int} = 1; |
| 36 |
} |
| 37 |
|
| 38 |
if ($self->{result_values}->{report_date} =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/) { |
| 39 |
$self->{output}->perfdata_add(label => 'perfdate', value => timelocal(0,0,12,$3,$2-1,$1-1900)); |
| 40 |
} |
| 41 |
|
| 42 |
$self->{output}->perfdata_add( |
| 43 |
label => 'active_users', |
| 44 |
nlabel => 'skype.users.active.count', |
| 45 |
value => $self->{result_values}->{active}, |
| 46 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), |
| 47 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), |
| 48 |
unit => 'users', min => 0, max => $self->{result_values}->{total} |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
sub custom_active_threshold { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
my $threshold_value = $self->{result_values}->{active}; |
| 56 |
if ($self->{instance_mode}->{option_results}->{units} eq '%') { |
| 57 |
$threshold_value = $self->{result_values}->{prct_active}; |
| 58 |
} |
| 59 |
my $exit = $self->{perfdata}->threshold_check( |
| 60 |
value => $threshold_value, |
| 61 |
threshold => [ |
| 62 |
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, |
| 63 |
{ label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } |
| 64 |
] |
| 65 |
); |
| 66 |
return $exit; |
| 67 |
} |
| 68 |
|
| 69 |
sub custom_active_output { |
| 70 |
my ($self, %options) = @_; |
| 71 |
|
| 72 |
return sprintf( |
| 73 |
"Active users on %s : %d/%d (%.2f%%)", |
| 74 |
$self->{result_values}->{report_date}, |
| 75 |
$self->{result_values}->{active}, |
| 76 |
$self->{result_values}->{total}, |
| 77 |
$self->{result_values}->{prct_active} |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
sub custom_active_calc { |
| 82 |
my ($self, %options) = @_; |
| 83 |
|
| 84 |
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'}; |
| 85 |
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; |
| 86 |
$self->{result_values}->{report_date} = $options{new_datas}->{$self->{instance} . '_report_date'}; |
| 87 |
$self->{result_values}->{prct_active} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{active} * 100 / $self->{result_values}->{total} : 0; |
| 88 |
|
| 89 |
return 0; |
| 90 |
} |
| 91 |
|
| 92 |
sub prefix_global_output { |
| 93 |
my ($self, %options) = @_; |
| 94 |
|
| 95 |
return "Total "; |
| 96 |
} |
| 97 |
|
| 98 |
sub prefix_user_output { |
| 99 |
my ($self, %options) = @_; |
| 100 |
|
| 101 |
return "User '" . $options{instance_value}->{name} . "' "; |
| 102 |
} |
| 103 |
|
| 104 |
sub set_counters { |
| 105 |
my ($self, %options) = @_; |
| 106 |
|
| 107 |
$self->{maps_counters_type} = [ |
| 108 |
{ name => 'active', type => 0 }, |
| 109 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, |
| 110 |
{ name => 'users', type => 1, cb_prefix_output => 'prefix_user_output', message_multiple => 'All users activity are ok' } |
| 111 |
]; |
| 112 |
|
| 113 |
$self->{maps_counters}->{active} = [ |
| 114 |
{ label => 'active-users', set => { |
| 115 |
key_values => [ { name => 'active' }, { name => 'total' }, { name => 'report_date' } ], |
| 116 |
closure_custom_calc => $self->can('custom_active_calc'), |
| 117 |
closure_custom_output => $self->can('custom_active_output'), |
| 118 |
closure_custom_threshold_check => $self->can('custom_active_threshold'), |
| 119 |
closure_custom_perfdata => $self->can('custom_active_perfdata') |
| 120 |
} |
| 121 |
}, |
| 122 |
]; |
| 123 |
|
| 124 |
$self->{maps_counters}->{global} = [ |
| 125 |
{ label => 'total-peer-to-peer-sessions', nlabel => 'skype.users.sessions.p2p.total.count', set => { |
| 126 |
key_values => [ { name => 'peer_to_peer_sessions' } ], |
| 127 |
output_template => 'Peer-to-peer Sessions Count: %d', |
| 128 |
perfdatas => [ |
| 129 |
{ label => 'total_peer_to_peer_sessions', template => '%d', |
| 130 |
min => 0 } |
| 131 |
] |
| 132 |
} |
| 133 |
}, |
| 134 |
{ label => 'total-organized-conference', nlabel => 'skype.users.conferences.organized.total.count', set => { |
| 135 |
key_values => [ { name => 'organized_conference' } ], |
| 136 |
output_template => 'Organized Conference Count: %d', |
| 137 |
perfdatas => [ |
| 138 |
{ label => 'total_organized_conference', template => '%d', |
| 139 |
min => 0 } |
| 140 |
] |
| 141 |
} |
| 142 |
}, |
| 143 |
{ label => 'total-participated-conference', nlabel => 'skype.users.conferences.participated.total.count', set => { |
| 144 |
key_values => [ { name => 'participated_conference' } ], |
| 145 |
output_template => 'Participated Conference Count: %d', |
| 146 |
perfdatas => [ |
| 147 |
{ label => 'total_participated_conference', template => '%d', |
| 148 |
min => 0 } |
| 149 |
] |
| 150 |
} |
| 151 |
} |
| 152 |
]; |
| 153 |
|
| 154 |
$self->{maps_counters}->{users} = [ |
| 155 |
{ label => 'peer-to-peer-sessions', nlabel => 'skype.users.sessions.p2p.count', set => { |
| 156 |
key_values => [ { name => 'peer_to_peer_sessions' }, { name => 'name' } ], |
| 157 |
output_template => 'Peer-to-peer Sessions Count: %d', |
| 158 |
perfdatas => [ |
| 159 |
{ label => 'peer_to_peer_sessions', template => '%d', |
| 160 |
min => 0, label_extra_instance => 1, instance_use => 'name' } |
| 161 |
] |
| 162 |
} |
| 163 |
}, |
| 164 |
{ label => 'organized-conference', nlabel => 'skype.users.conferences.organized.count', set => { |
| 165 |
key_values => [ { name => 'organized_conference' }, { name => 'name' } ], |
| 166 |
output_template => 'Organized Conference Count: %d', |
| 167 |
perfdatas => [ |
| 168 |
{ label => 'organized_conference', template => '%d', |
| 169 |
min => 0, label_extra_instance => 1, instance_use => 'name' } |
| 170 |
] |
| 171 |
} |
| 172 |
}, |
| 173 |
{ label => 'participated-conference', nlabel => 'skype.users.conferences.participated.count', set => { |
| 174 |
key_values => [ { name => 'participated_conference' }, { name => 'name' } ], |
| 175 |
output_template => 'Participated Conference Count: %d', |
| 176 |
perfdatas => [ |
| 177 |
{ label => 'participated_conference', template => '%d', |
| 178 |
min => 0, label_extra_instance => 1, instance_use => 'name' } |
| 179 |
] |
| 180 |
} |
| 181 |
} |
| 182 |
]; |
| 183 |
} |
| 184 |
|
| 185 |
sub new { |
| 186 |
my ($class, %options) = @_; |
| 187 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 188 |
bless $self, $class; |
| 189 |
|
| 190 |
$options{options}->add_options(arguments => { |
| 191 |
"filter-user:s" => { name => 'filter_user' }, |
| 192 |
"units:s" => { name => 'units', default => '%' }, |
| 193 |
"filter-counters:s" => { name => 'filter_counters', default => 'active|total' } |
| 194 |
}); |
| 195 |
|
| 196 |
return $self; |
| 197 |
} |
| 198 |
|
| 199 |
sub manage_selection { |
| 200 |
my ($self, %options) = @_; |
| 201 |
|
| 202 |
$self->{active} = { active => 0, total => 0, report_date => '' }; |
| 203 |
$self->{global} = { peer_to_peer_sessions => 0, organized_conference => 0, participated_conference => 0 }; |
| 204 |
$self->{users} = {}; |
| 205 |
|
| 206 |
my $results = $options{custom}->office_get_skype_activity(param => "period='D7'"); |
| 207 |
my $results_daily = []; |
| 208 |
if (scalar(@{$results})) { |
| 209 |
$self->{active}->{report_date} = @{$results}[0]->{'Report Refresh Date'}; |
| 210 |
$results_daily = $options{custom}->office_get_skype_activity(param => "date=" . $self->{active}->{report_date}); |
| 211 |
} |
| 212 |
|
| 213 |
foreach my $user (@{$results}, @{$results_daily}) { |
| 214 |
if (defined($self->{option_results}->{filter_user}) && $self->{option_results}->{filter_user} ne '' && |
| 215 |
$user->{'User Principal Name'} !~ /$self->{option_results}->{filter_user}/) { |
| 216 |
$self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no matching filter name.", debug => 1); |
| 217 |
next; |
| 218 |
} |
| 219 |
|
| 220 |
if ($user->{'Report Period'} != 1) { |
| 221 |
if (!defined($user->{'Last Activity Date'}) || ($user->{'Last Activity Date'} ne $self->{active}->{report_date})) { |
| 222 |
$self->{output}->output_add(long_msg => "skipping '" . $user->{'User Principal Name'} . "': no activity.", debug => 1); |
| 223 |
} |
| 224 |
$self->{active}->{total}++; |
| 225 |
next; |
| 226 |
} |
| 227 |
|
| 228 |
$self->{active}->{active}++; |
| 229 |
|
| 230 |
$self->{global}->{peer_to_peer_sessions} += $user->{'Total Peer-to-peer Session Count'}; |
| 231 |
$self->{global}->{organized_conference} += $user->{'Total Organized Conference Count'}; |
| 232 |
$self->{global}->{participated_conference} += $user->{'Total Participated Conference Count'}; |
| 233 |
|
| 234 |
$self->{users}->{$user->{'User Principal Name'}}->{name} = $user->{'User Principal Name'}; |
| 235 |
$self->{users}->{$user->{'User Principal Name'}}->{peer_to_peer_sessions} = $user->{'Total Peer-to-peer Session Count'}; |
| 236 |
$self->{users}->{$user->{'User Principal Name'}}->{organized_conference} = $user->{'Total Organized Conference Count'}; |
| 237 |
$self->{users}->{$user->{'User Principal Name'}}->{participated_conference} = $user->{'Total Participated Conference Count'}; |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
1; |
| 242 |
|
| 243 |
__END__ |
| 244 |
|
| 245 |
=head1 MODE |
| 246 |
|
| 247 |
Check users activity (reporting period over the last refreshed day). |
| 248 |
|
| 249 |
(see link for details about metrics : |
| 250 |
https://docs.microsoft.com/en-us/SkypeForBusiness/skype-for-business-online-reporting/activity-report) |
| 251 |
|
| 252 |
=over 8 |
| 253 |
|
| 254 |
=item B<--filter-user> |
| 255 |
|
| 256 |
Filter users. |
| 257 |
|
| 258 |
=item B<--warning-*> |
| 259 |
|
| 260 |
Warning threshold. |
| 261 |
Can be: 'active-users', 'total-peer-to-peer-sessions' (count), |
| 262 |
'total-organized-conference' (count), 'total-participated-conference' (count), |
| 263 |
'peer-to-peer-sessions' (count), 'organized-conference' (count), |
| 264 |
'participated-conference' (count). |
| 265 |
|
| 266 |
=item B<--critical-*> |
| 267 |
|
| 268 |
Critical threshold. |
| 269 |
Can be: 'active-users', 'total-peer-to-peer-sessions' (count), |
| 270 |
'total-organized-conference' (count), 'total-participated-conference' (count), |
| 271 |
'peer-to-peer-sessions' (count), 'organized-conference' (count), |
| 272 |
'participated-conference' (count). |
| 273 |
|
| 274 |
=item B<--filter-counters> |
| 275 |
|
| 276 |
Only display some counters (regexp can be used). |
| 277 |
Example to hide per user counters: --filter-counters='total' |
| 278 |
(default: 'active|total') |
| 279 |
|
| 280 |
=item B<--units> |
| 281 |
|
| 282 |
Unit of thresholds (default: '%') ('%', 'count'). |
| 283 |
|
| 284 |
=back |
| 285 |
|
| 286 |
=cut |