Debian Codegraph @

src/cloud/microsoft/office365/azuread/mode/directorysizeusage.pm

raw
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::azuread::mode::directorysizeusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_used_perfdata {
29 my ($self, %options) = @_;
30
31 my %total_options = ();
32 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
33 $total_options{total} = $self->{result_values}->{total};
34 $total_options{cast_int} = 1;
35 }
36
37 $self->{output}->perfdata_add(
38 nlabel => 'azure.ad.directory.usage.count',
39 value => $self->{result_values}->{used},
40 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
41 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
42 min => 0, max => $self->{result_values}->{total}
43 );
44 }
45
46 sub custom_used_threshold {
47 my ($self, %options) = @_;
48
49 my $threshold_value = $self->{result_values}->{used};
50 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
51 $threshold_value = $self->{result_values}->{prct_used};
52 }
53 my $exit = $self->{perfdata}->threshold_check(
54 value => $threshold_value,
55 threshold => [
56 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
57 { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' }
58 ]
59 );
60 return $exit;
61
62 }
63
64 sub custom_used_output {
65 my ($self, %options) = @_;
66
67 return sprintf(
68 "Directory size usage : %d/%d (%.2f%%)",
69 $self->{result_values}->{used},
70 $self->{result_values}->{total},
71 $self->{result_values}->{prct_used}
72 );
73 }
74
75 sub custom_used_calc {
76 my ($self, %options) = @_;
77
78 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
79 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
80 $self->{result_values}->{prct_used} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{used} * 100 / $self->{result_values}->{total} : 0;
81 return 0;
82 }
83
84 sub set_counters {
85 my ($self, %options) = @_;
86
87 $self->{maps_counters_type} = [
88 { name => 'directory', type => 0 }
89 ];
90
91 $self->{maps_counters}->{directory} = [
92 { label => 'usage', set => {
93 key_values => [ { name => 'used' }, { name => 'total' } ],
94 closure_custom_calc => $self->can('custom_used_calc'),
95 closure_custom_output => $self->can('custom_used_output'),
96 closure_custom_threshold_check => $self->can('custom_used_threshold'),
97 closure_custom_perfdata => $self->can('custom_used_perfdata')
98 }
99 },
100 ];
101 }
102
103 sub new {
104 my ($class, %options) = @_;
105 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
106 bless $self, $class;
107
108 $options{options}->add_options(arguments => {
109 "units:s" => { name => 'units', default => '%' }
110 });
111
112 return $self;
113 }
114
115 sub manage_selection {
116 my ($self, %options) = @_;
117
118 my $results = $options{custom}->azuread_get_organization();
119
120 $self->{directory} = {
121 used => @{$results}[0]->{'directorySizeQuota'}->{'used'},
122 total => @{$results}[0]->{'directorySizeQuota'}->{'total'}
123 }
124 }
125
126 1;
127
128 __END__
129
130 =head1 MODE
131
132 Check Azure AD directory size usage/quota.
133
134 =over 8
135
136 =item B<--warning-usage>
137
138 Warning threshold.
139
140 =item B<--critical-usage>
141
142 Critical threshold.
143
144 =item B<--units>
145
146 Unit of thresholds (default: '%') ('%', 'count').
147
148 =back
149
150 =cut