Debian Codegraph @

src/network/alcatel/oxe/snmp/mode/domains.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 network::alcatel::oxe::snmp::mode::domains;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_perfdata {
29 my ($self, %options) = @_;
30
31 $self->{output}->perfdata_add(
32 nlabel => $self->{nlabel},
33 instances => $self->{result_values}->{display},
34 value => $self->{result_values}->{used},
35 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
36 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
37 min => 0, max => $self->{result_values}->{total}
38 );
39 }
40
41 sub custom_usage_threshold {
42 my ($self, %options) = @_;
43
44 my $exit = $self->{perfdata}->threshold_check(
45 value => $self->{result_values}->{prct_used},
46 threshold => [
47 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
48 { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' }
49 ]
50 );
51 return $exit;
52 }
53
54 sub custom_usage_output {
55 my ($self, %options) = @_;
56
57 my $msg = sprintf("%s Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
58 $self->{result_values}->{label_output},
59 $self->{result_values}->{total},
60 $self->{result_values}->{used}, $self->{result_values}->{prct_used},
61 $self->{result_values}->{free}, $self->{result_values}->{prct_free});
62 return $msg;
63 }
64
65 sub custom_cac_usage_calc {
66 my ($self, %options) = @_;
67
68 if ($options{new_datas}->{$self->{instance} . '_cacAllowed'} <= 0) {
69 $self->{error_msg} = "skipped (no allowed)";
70 return -2;
71 }
72 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
73 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_cacAllowed'};
74 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_cacUsed'};
75 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
76 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
77 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
78 $self->{result_values}->{label_output} = $options{extra_options}->{label_output};
79 return 0;
80 }
81
82 sub custom_conference_usage_calc {
83 my ($self, %options) = @_;
84
85 if ($options{new_datas}->{$self->{instance} . '_confAvailable'} <= 0) {
86 $self->{error_msg} = "skipped (no available)";
87 return -2;
88 }
89 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
90 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_confAvailable'};
91 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_confBusy'};
92 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
93 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
94 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
95 $self->{result_values}->{label_output} = $options{extra_options}->{label_output};
96 return 0;
97 }
98
99 sub custom_dsp_usage_calc {
100 my ($self, %options) = @_;
101
102 if ($options{new_datas}->{$self->{instance} . '_dspRessAvailable'} <= 0) {
103 $self->{error_msg} = "skipped (no available)";
104 return -2;
105 }
106 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
107 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_dspRessAvailable'};
108 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_dspRessBusy'};
109 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
110 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
111 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
112 $self->{result_values}->{label_output} = $options{extra_options}->{label_output};
113 return 0;
114 }
115
116 sub set_counters {
117 my ($self, %options) = @_;
118
119 $self->{maps_counters_type} = [
120 { name => 'domain', type => 1, cb_prefix_output => 'prefix_domain_output', message_multiple => 'All domains are ok', skipped_code => { -2 => 1, -10 => 1 } }
121 ];
122
123 $self->{maps_counters}->{domain} = [
124 { label => 'cac-usage', nlabel => 'domain.communications.external.current.count', set => {
125 key_values => [ { name => 'cacUsed' }, { name => 'cacAllowed' }, { name => 'display '} ],
126 closure_custom_calc => $self->can('custom_cac_usage_calc'),
127 closure_custom_calc_extra_options => { label_output => 'External Communication' },
128 closure_custom_output => $self->can('custom_usage_output'),
129 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
130 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
131 }
132 },
133 { label => 'cac-overrun', nlabel => 'domain.communications.external.overrun.count', set => {
134 key_values => [ { name => 'cacOverrun' } ],
135 output_template => 'conference overrun: %s',
136 perfdatas => [
137 { template => '%s', min => 0, label_extra_instance => 1 }
138 ]
139 }
140 },
141 { label => 'conference-usage', nlabel => 'domain.conference.circuits.current.count', set => {
142 key_values => [ { name => 'confBusy' }, { name => 'confAvailable' }, { name => 'display '} ],
143 closure_custom_calc => $self->can('custom_conference_usage_calc'),
144 closure_custom_calc_extra_options => { label_output => 'Conference circuits' },
145 closure_custom_output => $self->can('custom_usage_output'),
146 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
147 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
148 }
149 },
150 { label => 'conf-outoforder', nlabel => 'domain.conference.circuits.outoforder.count', set => {
151 key_values => [ { name => 'confOutOfOrder' } ],
152 output_template => 'conference out of order: %s',
153 perfdatas => [
154 { template => '%s', min => 0, label_extra_instance => 1 }
155 ]
156 }
157 },
158 { label => 'dsp-usage', nlabel => 'domain.compressors.current.count', set => {
159 key_values => [ { name => 'dspRessBusy' }, { name => 'dspRessAvailable' }, { name => 'display '} ],
160 closure_custom_calc => $self->can('custom_dsp_usage_calc'),
161 closure_custom_calc_extra_options => { label_output => 'DSP Compressors' },
162 closure_custom_output => $self->can('custom_usage_output'),
163 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
164 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
165 }
166 },
167 { label => 'dsp-outofservice', nlabel => 'domain.compressors.outofservice.count', set => {
168 key_values => [ { name => 'dspRessOutOfService' } ],
169 output_template => 'compressor out of service: %s',
170 perfdatas => [
171 { template => '%s', min => 0, label_extra_instance => 1 }
172 ]
173 },
174 },
175 { label => 'dsp-overrun', nlabel => 'domain.compressors.overrun.count', set => {
176 key_values => [ { name => 'dspRessOverrun' } ],
177 output_template => 'compressor overrun: %s',
178 perfdatas => [
179 { template => '%s', min => 0, label_extra_instance => 1 }
180 ]
181 },
182 }
183 ];
184 }
185
186 sub prefix_domain_output {
187 my ($self, %options) = @_;
188
189 return "Domain '" . $options{instance_value}->{display} . "' ";
190 }
191
192 sub new {
193 my ($class, %options) = @_;
194 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
195 bless $self, $class;
196
197 $options{options}->add_options(arguments => {
198 "filter-domain:s" => { name => 'filter_domain' },
199 });
200
201 return $self;
202 }
203
204 my $mapping = {
205 confAvailable => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.2' },
206 confBusy => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.3' },
207 confOutOfOrder => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.4' },
208 dspRessAvailable => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.5' },
209 dspRessBusy => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.6' },
210 dspRessOutOfService => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.7' },
211 dspRessOverrun => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.8' },
212 cacAllowed => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.9' },
213 cacUsed => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.10' },
214 cacOverrun => { oid => '.1.3.6.1.4.1.637.64.4400.1.3.1.10' }
215 };
216
217 sub manage_selection {
218 my ($self, %options) = @_;
219
220 my $oid_ipDomainEntry = '.1.3.6.1.4.1.637.64.4400.1.3.1';
221 my $snmp_result = $options{snmp}->get_table(
222 oid => $oid_ipDomainEntry,
223 nothing_quit => 1
224 );
225
226 $self->{domain} = {};
227 foreach my $oid (keys %$snmp_result) {
228 next if ($oid !~ /^$mapping->{cacAllowed}->{oid}\.(\d+)/);
229 my $instance = $1;
230 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
231 if (defined($self->{option_results}->{filter_domain}) && $self->{option_results}->{filter_domain} ne '' &&
232 $instance !~ /$self->{option_results}->{filter_domain}/) {
233 $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching filter.", debug => 1);
234 next;
235 }
236
237 $self->{domain}->{$instance} = {
238 display => $instance,
239 %{$result}
240 };
241 }
242
243 if (scalar(keys %{$self->{domain}}) <= 0) {
244 $self->{output}->add_option_msg(short_msg => "No domain found.");
245 $self->{output}->option_exit();
246 }
247 }
248
249 1;
250
251 __END__
252
253 =head1 MODE
254
255 Check Domain usages.
256
257 =over 8
258
259 =item B<--filter-domain>
260
261 Filter by domain (regexp can be used).
262
263 =item B<--warning-*>
264
265 Warning threshold.
266 Can be: 'cac-usage' (%), 'conference-usage' (%),
267 'cac-overrun' (absolute), conf-outoforder (absolute),
268 'dsp-usage' (absolute), 'dsp-outofservice' (absolute),
269 'dsp-overrun' (absolute)
270
271 =item B<--critical-*>
272
273 Critical threshold.
274 Can be: 'cac-usage' (%), 'conference-usage' (%),
275 'cac-overrun' (absolute), conf-outoforder (absolute),
276 'dsp-usage' (absolute), 'dsp-outofservice' (absolute),
277 'dsp-overrun' (absolute)
278
279 =back
280
281 =cut