Debian Codegraph @

src/hardware/telephony/avaya/aes/snmp/mode/services.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 hardware::telephony::avaya::aes::snmp::mode::services;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
28
29 sub custom_service_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf(
33 "status: %s [state: '%s'] [license error: '%s']",
34 $self->{result_values}->{status},
35 $self->{result_values}->{state},
36 $self->{result_values}->{license_error}
37 );
38 return $msg;
39 }
40
41 sub custom_aep_status_output {
42 my ($self, %options) = @_;
43
44 my $msg = sprintf(
45 "state: %s [link state: '%s']",
46 $self->{result_values}->{session_state},
47 $self->{result_values}->{link_state}
48 );
49 return $msg;
50 }
51
52 sub set_counters {
53 my ($self, %options) = @_;
54
55 $self->{maps_counters_type} = [
56 { name => 'service', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok', skipped_code => { -10 => 1 } },
57 { name => 'aep', type => 1, cb_prefix_output => 'prefix_aep_output', message_multiple => 'All AEP connections are ok', skipped_code => { -10 => 1 } },
58 ];
59
60 $self->{maps_counters}->{service} = [
61 { label => 'status', threshold => 0, set => {
62 key_values => [ { name => 'status' }, { name => 'state' }, { name => 'license_error' }, { name => 'display' } ],
63 closure_custom_calc => \&catalog_status_calc,
64 closure_custom_output => $self->can('custom_service_status_output'),
65 closure_custom_perfdata => sub { return 0; },
66 closure_custom_threshold_check => \&catalog_status_threshold,
67 }
68 },
69 { label => 'tsapi-clients-connected', nlabel => 'service.tsapi.clients.connected.count', set => {
70 key_values => [ { name => 'avAesTsapiClientsConnected' } ],
71 output_template => 'client connected: %s',
72 perfdatas => [
73 { value => 'avAesTsapiClientsConnected', template => '%s', min => 0 },
74 ],
75 }
76 },
77 { label => 'dmcc-memory-usage', nlabel => 'service.dmcc.memory.usage.percentage', set => {
78 key_values => [ { name => 'mem_used_prct' } ],
79 output_template => 'memory used : %.2f %%',
80 perfdatas => [
81 { value => 'mem_used_prct', template => '%.2f', min => 0, max => 100, unit => '%' },
82 ],
83 }
84 },
85 ];
86
87 $self->{maps_counters}->{aep} = [
88 { label => 'aep-status', threshold => 0, set => {
89 key_values => [ { name => 'session_state' }, { name => 'link_state' }, { name => 'display' } ],
90 closure_custom_calc => \&catalog_status_calc,
91 closure_custom_output => $self->can('custom_aep_status_output'),
92 closure_custom_perfdata => sub { return 0; },
93 closure_custom_threshold_check => \&catalog_status_threshold,
94 }
95 },
96 ];
97 }
98
99 sub prefix_service_output {
100 my ($self, %options) = @_;
101
102 return "Service '" . $options{instance_value}->{display} . "' ";
103 }
104
105 sub prefix_aep_output {
106 my ($self, %options) = @_;
107
108 return "AEP session '" . $options{instance_value}->{display} . "' ";
109 }
110
111 sub new {
112 my ($class, %options) = @_;
113 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
114 bless $self, $class;
115
116 $options{options}->add_options(arguments => {
117 'filter-name:s' => { name => 'filter_name' },
118 'unknown-status:s' => { name => 'unknown_status', default => '' },
119 'warning-status:s' => { name => 'warning_status', default => '' },
120 'critical-status:s' => { name => 'critical_status', default => '%{state} ne "running" or %{status} ne "online"' },
121 'unknown-aep-status:s' => { name => 'unknown_aep_status', default => '' },
122 'warning-aep-status:s' => { name => 'warning_aep_status', default => '' },
123 'critical-aep-status:s' => { name => 'critical_aep_status', default => '%{link_state} ne "online" or %{session_state} ne "online"' },
124 });
125
126 return $self;
127 }
128
129 sub check_options {
130 my ($self, %options) = @_;
131 $self->SUPER::check_options(%options);
132
133 $self->change_macros(macros => [
134 'unknown_status', 'warning_status', 'critical_status',
135 'unknown_aep_status', 'warning_aep_status', 'critical_aep_status',
136 ]);
137 }
138
139 my %map_state = (
140 1 => 'ready', 2 => 'running', 3 => 'stopped',
141 4 => 'paused', 5 => 'stopping', 6 => 'starting',
142 7 => 'unknown', 8 => 'resourceUnavailable',
143 );
144 my %map_status = (
145 1 => 'resuming', 2 => 'initializing',
146 3 => 'online', 4 => 'offline',
147 5 => 'pausing', 6 => 'stopping',
148 7 => 'down', 8 => 'unknown', 9 => 'resourceUnavailable',
149 );
150 my %map_license_error = (
151 -1 => 'resourceUnavailable', 0 => 'normal', 1 => 'productNotFound',
152 2 => 'featureNotFound', 3 => 'serverConnection', 4 => 'invalidResponse',
153 5 => 'invalidRequest', 6 => 'internalError', 7 => 'invalidParameters',
154 8 => 'licenseExpired', 9 => 'noLicenseFound', 10 => 'unknownHost',
155 11 => 'tryAgain', 12 => 'noRecovery', 13 => 'noData', 14 => 'connectionRefused',
156 15 => 'noRouteToHost', 16 => 'authenticationError', 17 => 'incompatibleVersion',
157 18 => 'timeout', 19 => 'notLicenseServer', 20 => 'multiSiteInvalid',
158 21 => 'serverRestarting', 22 => 'sslConnection', 23 => 'invalidUrl',
159 24 => 'invalidProtocol', 99 => 'unknownError', 100 => 'gracePeriodExpired',
160 101 => 'invalidLicense', 102 => 'tooManyLicenses', 103 => 'dateTimeError',
161 );
162 my %map_aep_link_state = (
163 1 => 'offline', 2 => 'online', 3 => 'resourceUnavailable',
164 );
165 my $mapping = {
166 avAesTransportName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.1' },
167 avAesTransportState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.2', map => \%map_state },
168 avAesTransportStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.3', map => \%map_status },
169 avAesCvlanName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.2.1' },
170 avAesCvlanState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.2.2', map => \%map_state },
171 avAesCvlanStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.2.3', map => \%map_status },
172 avAesCvlanLicenseError => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.2.12', map => \%map_license_error },
173 avAesTsapiName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.1' },
174 avAesTsapiState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.2', map => \%map_state },
175 avAesTsapiStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.3', map => \%map_status },
176 avAesTsapiClientsConnected => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.8' },
177 avAesTsapiLicenseError => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.3.21', map => \%map_license_error },
178 avAesDlgName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.4.1' },
179 avAesDlgState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.4.2', map => \%map_state },
180 avAesDlgStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.4.3', map => \%map_status },
181 avAesDlgLicenseError => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.4.10', map => \%map_license_error },
182 avAesDmccName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.1' },
183 avAesDmccState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.2', map => \%map_state },
184 avAesDmccStatus => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.3', map => \%map_status },
185 avAesDmccUsedMemory => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.6' },
186 avAesDmccFreeMemory => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.7' },
187 avAesDmccLicenseError => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.5.20', map => \%map_license_error },
188 };
189
190 my $mapping2 = {
191 avAesAepLinkSessSwName => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.6.1.3' },
192 avAesAepLinkState => { oid => '.1.3.6.1.4.1.6889.2.27.2.1.1.6.1.5', map => \%map_aep_link_state },
193 };
194 my $oid_avAesAepLinkEntry = '.1.3.6.1.4.1.6889.2.27.2.1.1.6.1';
195 my $oid_avAesAepSessionState = '.1.3.6.1.4.1.6889.2.27.2.1.1.7.1.4';
196
197 sub manage_aep {
198 my ($self, %options) = @_;
199
200 $self->{aep} = {};
201 my $snmp_result = $options{snmp}->get_multiple_table(
202 oids => [
203 { oid => $oid_avAesAepLinkEntry, start => $mapping2->{avAesAepLinkSessSwName}->{oid}, end => $mapping2->{avAesAepLinkState}->{oid} },
204 { oid => $oid_avAesAepSessionState },
205 ],
206 );
207
208 foreach my $oid (keys %{$snmp_result->{$oid_avAesAepLinkEntry}}) {
209 next if ($oid !~ /^$mapping2->{avAesAepLinkSessSwName}->{oid}\.(.*)$/);
210 my $instance = $1;
211 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_avAesAepLinkEntry}, instance => $instance);
212 $self->{aep}->{$result->{avAesAepLinkSessSwName}} = {
213 display => $result->{avAesAepLinkSessSwName},
214 link_state => $result->{avAesAepLinkState},
215 };
216
217 $instance = length($result->{avAesAepLinkSessSwName}) . '.' . join('.', map(ord($_), split('', $result->{avAesAepLinkSessSwName})));
218 $self->{aep}->{$result->{avAesAepLinkSessSwName}}->{session_state} =
219 $map_aep_link_state{ $snmp_result->{$oid_avAesAepSessionState}->{$oid_avAesAepSessionState . '.' . $instance} };
220 }
221 }
222
223 sub add_service {
224 my ($self, %options) = @_;
225
226 return if (!defined($options{display}));
227 return if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
228 $options{display} !~ /$self->{option_results}->{filter_name}/);
229 $self->{service}->{$options{display}} = { %options };
230 }
231
232 sub manage_selection {
233 my ($self, %options) = @_;
234
235 $self->{service} = {};
236 my $snmp_result = $options{snmp}->get_leef(
237 oids => [ map($_->{oid} . '.0', values(%$mapping)) ], nothing_quit => 1
238 );
239
240 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
241 $self->add_service(
242 display => $result->{avAesTransportName},
243 state => $result->{avAesTransportState},
244 status => $result->{avAesTransportStatus},
245 license_error => 'normal',
246 );
247 $self->add_service(
248 display => $result->{avAesCvlanName},
249 state => $result->{avAesCvlanState},
250 status => $result->{avAesCvlanStatus},
251 license_error => $result->{avAesCvlanLicenseError},
252 );
253 $self->add_service(
254 display => $result->{avAesTsapiName},
255 state => $result->{avAesTsapiState},
256 status => $result->{avAesTsapiStatus},
257 license_error => $result->{avAesTsapiLicenseError},
258 avAesTsapiClientsConnected =>
259 defined($result->{avAesTsapiClientsConnected}) && $result->{avAesTsapiClientsConnected} != -1 ? $result->{avAesTsapiClientsConnected} : undef,
260 );
261 $self->add_service(
262 display => $result->{avAesDlgName},
263 state => $result->{avAesDlgState},
264 status => $result->{avAesDlgStatus},
265 license_error => $result->{avAesDlgLicenseError},
266 );
267 $self->add_service(
268 display => $result->{avAesDmccName},
269 state => $result->{avAesDmccState},
270 status => $result->{avAesDmccStatus},
271 license_error => $result->{avAesDmccLicenseError},
272 mem_used_prct =>
273 defined($result->{avAesDmccFreeMemory}) ? (($result->{avAesDmccUsedMemory} * 100) / ($result->{avAesDmccUsedMemory} + $result->{avAesDmccFreeMemory})) : undef
274 );
275
276 $self->manage_aep(%options);
277 }
278
279 1;
280
281 __END__
282
283 =head1 MODE
284
285 Check services.
286
287 =over 8
288
289 =item B<--filter-name>
290
291 Filter service name (can be a regexp).
292
293 =item B<--unknown-status>
294
295 Define the conditions to match for the status to be UNKNOWN.
296 You can use the following variables: %{status}, %{state}, %{license_error}, %{display}
297
298 =item B<--warning-status>
299
300 Define the conditions to match for the status to be WARNING.
301 You can use the following variables: %{status}, %{state}, %{license_error}, %{display}
302
303 =item B<--critical-status>
304
305 Define the conditions to match for the status to be CRITICAL (default: '%{state} ne "running" or %{status} ne "online"').
306 You can use the following variables: %{status}, %{state}, %{license_error}, %{display}
307
308 =item B<--unknown-aep-status>
309
310 Define the conditions to match for the status to be UNKNOWN.
311 You can use the following variables: %{link_state}, %{session_state}, %{display}
312
313 =item B<--warning-aep-status>
314
315 Define the conditions to match for the status to be WARNING.
316 You can use the following variables: %{link_state}, %{session_state}, %{display}
317
318 =item B<--critical-aep-status>
319
320 Define the conditions to match for the status to be CRITICAL (default: '%{link_state} ne "online" or %{session_state} ne "online"').
321 You can use the following variables: %{link_state}, %{session_state}, %{display}
322
323 =item B<--warning-*> B<--critical-*>
324
325 Thresholds.
326 Can be: 'tsapi-clients-connected', 'dmcc-memory-usage' (%).
327
328 =back
329
330 =cut
331