Debian Codegraph @

src/apps/voip/asterisk/ami/mode/channelusage.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::channelusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'global', type => 0 },
34 ];
35
36 $self->{maps_counters}->{global} = [
37 { label => 'channels-active', nlabel => 'channels.active.count', set => {
38 key_values => [ { name => 'channels_active' } ],
39 output_template => 'channels active: %s',
40 perfdatas => [
41 { label => 'channels_active', template => '%s', min => 0 }
42 ]
43 }
44 },
45 { label => 'calls-active', nlabel => 'calls.active.count', set => {
46 key_values => [ { name => 'calls_active' } ],
47 output_template => 'calls active: %s',
48 perfdatas => [
49 { label => 'calls_active', template => '%s', min => 0 }
50 ]
51 }
52 },
53 { label => 'extcalls-active', nlabel => 'extcalls.active.count', set => {
54 key_values => [ { name => 'extcalls_active' } ],
55 output_template => 'external calls active: %s',
56 perfdatas => [
57 { label => 'extcalls_active', template => '%s', min => 0 }
58 ]
59 }
60 },
61 { label => 'calls-count', nlabel => 'calls.processed.count', set => {
62 key_values => [ { name => 'calls_count', diff => 1 } ],
63 output_template => 'calls count: %s',
64 perfdatas => [
65 { label => 'calls_count', template => '%s', min => 0 }
66 ]
67 }
68 }
69 ];
70 }
71
72 sub new {
73 my ($class, %options) = @_;
74 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
75 bless $self, $class;
76
77 $options{options}->add_options(arguments =>
78 {
79 });
80
81 return $self;
82 }
83
84 sub manage_selection {
85 my ($self, %options) = @_;
86
87 my $result = $options{custom}->command(cmd => 'core show channels');
88 $self->{global} = { channels_active => 0, calls_active => 0,
89 calls_count => undef, extcalls_active => 0 };
90
91 $self->{global}->{channels_active} = $1
92 if ($result =~ /^(\d+)\s+active\s+channels/ms);
93 $self->{global}->{calls_active} = $1
94 if ($result =~ /^(\d+)\s+active\s+calls/ms);
95 $self->{global}->{calls_count} = $1
96 if ($result =~ /^(\d+)\s+calls\s+processed/ms);
97
98 my $count = 0;
99 $count++ while ($result =~ /Outgoing\s+Line/msig);
100 $self->{global}->{extcalls_active} = $count;
101
102 $self->{cache_name} = "asterisk_" . '_' . $self->{mode} . '_' . $options{custom}->get_connect_info() . '_' .
103 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
104 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
105 }
106
107 1;
108
109 __END__
110
111 =head1 MODE
112
113 Check channel usage: active calls, external calls.
114
115 =over 8
116
117 =item B<--warning-*>
118
119 Warning threshold.
120 Can be: 'channels-active', 'calls-active', 'extcalls-active',
121 'calls-count'.
122
123 =item B<--critical-*>
124
125 Critical threshold.
126 Can be: 'channels-active', 'calls-active', 'extcalls-active',
127 'calls-count'.
128
129 =back
130
131 =cut