Debian Codegraph @

src/apps/voip/asterisk/ami/mode/dahdistatus.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 apps::voip::asterisk::ami::mode::dahdistatus;
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_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf('status : %s', $self->{result_values}->{status});
33 }
34
35 sub prefix_dahdi_output {
36 my ($self, %options) = @_;
37
38 return "Line '" . $options{instance_value}->{description} . "' ";
39 }
40
41 sub set_counters {
42 my ($self, %options) = @_;
43
44 $self->{maps_counters_type} = [
45 { name => 'dahdi', type => 1, cb_prefix_output => 'prefix_dahdi_output', message_multiple => 'All dahdi lines are ok' },
46 ];
47
48 $self->{maps_counters}->{dahdi} = [
49 {
50 label => 'status',
51 type => 2,
52 warning_default => '%{status} =~ /UNCONFIGURED|YEL|BLU/i',
53 critical_default => '%{status} =~ /RED/i',
54 set => {
55 key_values => [ { name => 'description' }, { name => 'status' } ],
56 closure_custom_output => $self->can('custom_status_output'),
57 closure_custom_perfdata => sub { return 0; },
58 closure_custom_threshold_check => \&catalog_status_threshold_ng
59 }
60 },
61 ];
62 }
63
64 sub new {
65 my ($class, %options) = @_;
66 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
67 bless $self, $class;
68
69 $options{options}->add_options(arguments => {
70 "filter-description:s" => { name => 'filter_description' }
71 });
72
73 return $self;
74 }
75
76 sub manage_selection {
77 my ($self, %options) = @_;
78
79 # Status can be: OK, UNCONFIGURED, BLU, YEL, RED, REC (recover), NOP (notopen), UUU
80
81 #Description Alarms IRQ bpviol CRC4
82 #Wildcard TDM410P Board 1 OK 0 0 0
83 #Wildcard TDM800P Board 2 OK 0 0 0
84
85 #Description Alarms IRQ bpviol CRC Fra Codi Options LBO
86 #Wildcard TE131/TE133 Card 0 BLU/RED 0 0 0 CCS HDB3 0 db (CSU)/0-133 feet (DSX-1)
87 my $result = $options{custom}->command(cmd => 'dahdi show status');
88
89 $self->{dahdi} = {};
90 foreach my $line (split /\n/, $result) {
91 if ($line =~ /^(.*?)\s+((?:OK|UNCONFIGURED|BLU|YEL|RED|REC|NOP|UUU)[^\s]*)\s+/msg) {
92 my ($description, $status) = ($1, $2);
93 if (defined($self->{option_results}->{filter_description}) && $self->{option_results}->{filter_description} ne '' &&
94 $description !~ /$self->{option_results}->{filter_description}/) {
95 $self->{output}->output_add(long_msg => "skipping '" . $description . "': no matching filter.", debug => 1);
96 next;
97 }
98
99 $self->{dahdi}->{$description} = {
100 description => $description,
101 status => $status,
102 };
103 }
104 }
105
106 if (scalar(keys %{$self->{dahdi}}) <= 0) {
107 $self->{output}->add_option_msg(short_msg => "No dahdi lines found.");
108 $self->{output}->option_exit();
109 }
110 }
111
112 1;
113
114 __END__
115
116 =head1 MODE
117
118 Check status of dahdi lines.
119
120 =over 8
121
122 =item B<--filter-description>
123
124 Filter dahdi description (can be a regexp).
125
126 =item B<--warning-status>
127
128 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /UNCONFIGURED|YEL|BLU/i').
129 You can use the following variables: %{description}, %{status}
130
131 =item B<--critical-status>
132
133 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /RED/i').
134 You can use the following variables: %{description}, %{status}
135
136 =back
137
138 =cut