Debian Codegraph @

src/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.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::mediagateway::snmp::mode::controllerstatus;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions;
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf("controller registration state is '%s' [h248 link status: '%s']", $self->{result_values}->{registration_state}, $self->{result_values}->{h248_link_status});
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{registration_state} = $options{new_datas}->{$self->{instance} . '_cmgRegistrationState'};
40 $self->{result_values}->{h248_link_status} = $options{new_datas}->{$self->{instance} . '_cmgH248LinkStatus'};
41 return 0;
42 }
43
44 sub set_counters {
45 my ($self, %options) = @_;
46
47 $self->{maps_counters_type} = [
48 { name => 'global', type => 0 },
49 ];
50
51 $self->{maps_counters}->{global} = [
52 { label => 'status', threshold => 0, set => {
53 key_values => [ { name => 'cmgRegistrationState' }, { name => 'cmgH248LinkStatus' } ],
54 closure_custom_calc => $self->can('custom_status_calc'),
55 closure_custom_output => $self->can('custom_status_output'),
56 closure_custom_perfdata => sub { return 0; },
57 closure_custom_threshold_check => \&centreon::plugins::templates::catalog_functions::catalog_status_threshold,
58 }
59 },
60 ];
61 }
62
63 sub new {
64 my ($class, %options) = @_;
65 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
66 bless $self, $class;
67
68 $options{options}->add_options(arguments => {
69 'unknown-status:s' => { name => 'unknown_status', default => '' },
70 'warning-status:s' => { name => 'warning_status', default => '' },
71 'critical-status:s' => { name => 'critical_status', default => '%{h248_link_status} =~ /down/i || %{registration_state} =~ /notRegistred/i' },
72 });
73
74 return $self;
75 }
76
77 sub check_options {
78 my ($self, %options) = @_;
79 $self->SUPER::check_options(%options);
80
81 $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
82 }
83
84 my %map_registration_state = (
85 1 => 'registred',
86 2 => 'notRegistred',
87 );
88 my %map_h248_link_status = (
89 1 => 'up',
90 2 => 'down',
91 );
92
93 my $mapping = {
94 cmgRegistrationState => { oid => '.1.3.6.1.4.1.6889.2.9.1.3.1', map => \%map_registration_state },
95 cmgH248LinkStatus => { oid => '.1.3.6.1.4.1.6889.2.9.1.3.3', map => \%map_h248_link_status },
96 };
97
98 sub manage_selection {
99 my ($self, %options) = @_;
100
101
102 my $snmp_result = $options{snmp}->get_leef(
103 oids => [$mapping->{cmgRegistrationState}->{oid} . '.0', $mapping->{cmgH248LinkStatus}->{oid} . '.0'],
104 nothing_quit => 1
105 );
106
107 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
108 $self->{global} = { %$result };
109 }
110
111 1;
112
113 __END__
114
115 =head1 MODE
116
117 Check controller status.
118
119 =over 8
120
121 =item B<--unknown-status>
122
123 Define the conditions to match for the status to be UNKNOWN (default: '').
124 You can use the following variables: %{h248_link_status}, %{registration_state}
125
126 =item B<--warning-status>
127
128 Define the conditions to match for the status to be WARNING (default: '').
129 You can use the following variables: %{h248_link_status}, %{registration_state}
130
131 =item B<--critical-status>
132
133 Define the conditions to match for the status to be CRITICAL (default: '%{h248_link_status} =~ /down/i || %{registration_state} =~ /notRegistred/i').
134 You can use the following variables: %{h248_link_status}, %{registration_state}
135
136 =back
137
138 =cut