Debian Codegraph @

src/hardware/telephony/avaya/cm/snmp/mode/trunks.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::cm::snmp::mode::trunks;
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_sig_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf(
33 "state: %s [far node: %s]",
34 $self->{result_values}->{state},
35 $self->{result_values}->{far_node}
36 );
37 return $msg;
38 }
39
40 sub set_counters {
41 my ($self, %options) = @_;
42
43 $self->{maps_counters_type} = [
44 { name => 'sig', type => 1, cb_prefix_output => 'prefix_sig_output', message_multiple => 'All signaling groups are ok', skipped_code => { -10 => 1 } },
45 ];
46
47 $self->{maps_counters}->{sig} = [
48 { label => 'sig-status', threshold => 0, set => {
49 key_values => [ { name => 'state' }, { name => 'far_node' }, { name => 'display' } ],
50 closure_custom_calc => \&catalog_status_calc,
51 closure_custom_output => $self->can('custom_sig_status_output'),
52 closure_custom_perfdata => sub { return 0; },
53 closure_custom_threshold_check => \&catalog_status_threshold,
54 }
55 },
56 ];
57 }
58
59 sub prefix_sig_output {
60 my ($self, %options) = @_;
61
62 return "Signaling group '" . $options{instance_value}->{display} . "' ";
63 }
64
65 sub new {
66 my ($class, %options) = @_;
67 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
68 bless $self, $class;
69
70 $options{options}->add_options(arguments => {
71 'filter-sigid:s' => { name => 'filter_sigid' },
72 'unknown-sig-status:s' => { name => 'unknown_sig_status', default => '' },
73 'warning-sig-status:s' => { name => 'warning_sig_status', default => '' },
74 'critical-sig-status:s' => { name => 'critical_sig_status', default => '%{state} =~ /out-of-service/' },
75 });
76
77 return $self;
78 }
79
80 sub check_options {
81 my ($self, %options) = @_;
82 $self->SUPER::check_options(%options);
83
84 $self->change_macros(macros => [
85 'unknown_sig_status', 'warning_sig_status', 'critical_sig_status',
86 ]);
87 }
88
89 my $mapping = {
90 avCmListSigGrpFarNode => { oid => '.1.3.6.1.4.1.6889.2.73.8.1.84.1.1.12' },
91 avCmStatusSigGrpGrpState => { oid => '.1.3.6.1.4.1.6889.2.73.8.1.85.1.1.4' },
92 };
93
94 sub manage_selection {
95 my ($self, %options) = @_;
96
97 $self->{sig} = {};
98 my $snmp_result = $options{snmp}->get_multiple_table(
99 oids => [
100 { oid => $mapping->{avCmListSigGrpFarNode}->{oid} },
101 { oid => $mapping->{avCmStatusSigGrpGrpState}->{oid} },
102 ],
103 return_type => 1,
104 nothing_quit => 1
105 );
106
107 foreach my $oid (keys %$snmp_result) {
108 next if ($oid !~ /^$mapping->{avCmStatusSigGrpGrpState}->{oid}\.(.*)$/);
109 my $instance = $1;
110 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
111
112 if (defined($self->{option_results}->{filter_sigid}) && $self->{option_results}->{filter_sigid} ne '' &&
113 $instance !~ /$self->{option_results}->{filter_sigid}/) {
114 $self->{output}->output_add(long_msg => "skipping signaling group '" . $instance . "': no matching filter.", debug => 1);
115 next;
116 }
117
118 $self->{sig}->{$instance} = {
119 display => $instance,
120 state => $result->{avCmStatusSigGrpGrpState},
121 far_node => defined($result->{avCmListSigGrpFarNode}) && $result->{avCmListSigGrpFarNode} ne '' ? $result->{avCmListSigGrpFarNode} : '-',
122 };
123 }
124 }
125
126 1;
127
128 __END__
129
130 =head1 MODE
131
132 Check trunks.
133
134 =over 8
135
136 =item B<--filter-sigid>
137
138 Filter signaling group instance (can be a regexp).
139
140 =item B<--unknown-sig-status>
141
142 Define the conditions to match for the status to be UNKNOWN.
143 You can use the following variables: %{state}, %{far_node}, %{display}
144
145 =item B<--warning-sig-status>
146
147 Define the conditions to match for the status to be WARNING.
148 You can use the following variables: %{state}, %{far_node}, %{display}
149
150 =item B<--critical-sig-status>
151
152 Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /out-of-service/').
153 You can use the following variables: %{state}, %{far_node}, %{display}
154
155 =back
156
157 =cut
158