Debian Codegraph @

src/network/cisco/callmanager/snmp/mode/phoneusage.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 network::cisco::callmanager::snmp::mode::phoneusage;
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 my $msg = 'status: ' . $self->{result_values}->{status};
33 $msg .= ' [description: ' . $self->{result_values}->{description} . ']' if (defined($self->{result_values}->{description}) && $self->{result_values}->{description} ne '');
34 return $msg;
35 }
36
37 sub prefix_phone_output {
38 my ($self, %options) = @_;
39
40 return "Phone '" . $options{instance_value}->{name} . "' ";
41 }
42
43 sub prefix_global_output {
44 my ($self, %options) = @_;
45
46 return 'Total ';
47 }
48
49 sub set_counters {
50 my ($self, %options) = @_;
51
52 $self->{maps_counters_type} = [
53 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
54 { name => 'phone', type => 1, cb_prefix_output => 'prefix_phone_output', message_multiple => 'All phones are ok' }
55 ];
56
57 $self->{maps_counters}->{phone} = [
58 { label => 'status', type => 2, critical_default => '%{status} !~ /^registered/', set => {
59 key_values => [ { name => 'status' }, { name => 'description' }, { name => 'name' } ],
60 closure_custom_output => $self->can('custom_status_output'),
61 closure_custom_perfdata => sub { return 0; },
62 closure_custom_threshold_check => \&catalog_status_threshold_ng
63 }
64 }
65 ];
66
67 my @map = (
68 ['total-registered', 'registered: %s', 'registered', 'phones.registered.count'],
69 ['total-unregistered', 'unregistered: %s', 'unregistered', 'phones.unregistered.count'],
70 ['total-rejected', 'rejected: %s', 'rejected', 'phones.rejected.count'],
71 ['total-unknown', 'unknown: %s', 'unknown', 'phones.unknown.count'],
72 ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered', 'phones.partially_registered.count']
73 );
74
75 $self->{maps_counters}->{global} = [];
76 foreach (@map) {
77 my $label = $_->[0];
78 $label =~ tr/-/_/;
79 push @{$self->{maps_counters}->{global}}, {
80 label => $_->[0], nlabel => $_->[3], set => {
81 key_values => [ { name => $_->[2] } ],
82 output_template => $_->[1],
83 perfdatas => [
84 { label => $label, template => '%s', min => 0 }
85 ]
86 }
87 };
88 }
89 }
90
91 sub new {
92 my ($class, %options) = @_;
93 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
94 bless $self, $class;
95
96 $options{options}->add_options(arguments => {
97 'filter-name:s' => { name => 'filter_name' },
98 'filter-description:s' => { name => 'filter_description' }
99 });
100
101 return $self;
102 }
103
104 my $mapping_status = {
105 1 => 'unknown', 2 => 'registered', 3 => 'unregistered',
106 4 => 'rejected', 5 => 'partiallyregistered'
107 };
108
109 my $mapping = {
110 description => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.4' }, # ccmPhoneDescription
111 status => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.7', map => $mapping_status }, # ccmPhoneStatus
112 name => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.20' } # ccmPhoneName
113 };
114
115 sub manage_selection {
116 my ($self, %options) = @_;
117
118 my $snmp_result = $options{snmp}->get_multiple_table(
119 oids => [
120 { oid => $mapping->{description}->{oid} },
121 { oid => $mapping->{status}->{oid} },
122 { oid => $mapping->{name}->{oid} }
123 ],
124 return_type => 1,
125 nothing_quit => 1
126 );
127
128 $self->{phone} = {};
129 $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 };
130 foreach my $oid (keys %$snmp_result) {
131 next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)/);
132 my $instance = $1;
133 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
134
135 if (defined($result->{name}) &&
136 defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
137 $result->{name} !~ /$self->{option_results}->{filter_name}/) {
138 $self->{output}->output_add(long_msg => "skipping phone '" . $instance . "': no matching filter.", debug => 1);
139 next;
140 }
141 if (defined($result->{description}) &&
142 defined($self->{option_results}->{filter_description}) && $self->{option_results}->{filter_description} ne '' &&
143 $result->{description} !~ /$self->{option_results}->{filter_description}/) {
144 $self->{output}->output_add(long_msg => "skipping phone '" . $instance . "': no matching filter.", debug => 1);
145 next;
146 }
147
148 $self->{phone}->{$instance} = $result;
149 $self->{global}->{ $result->{status} }++;
150 }
151 }
152
153 1;
154
155 __END__
156
157 =head1 MODE
158
159 Check phone usage.
160
161 =over 8
162
163 =item B<--filter-counters>
164
165 Only display some counters (regexp can be used).
166 Example: --filter-counters='status'
167
168 =item B<--filter-name>
169
170 Filter phone by name (can be a regexp).
171
172 =item B<--filter-description>
173
174 Filter phone by description (can be a regexp).
175
176 =item B<--warning-status>
177
178 Define the conditions to match for the status to be WARNING.
179 You can use the following variables: %{status}, %{name}, %{description}
180
181 =item B<--critical-status>
182
183 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /^registered/').
184 You can use the following variables: %{status}, %{name}, %{description}
185
186 =item B<--warning-*> B<--critical-*>
187
188 Thresholds.
189
190 Can be: 'total-registered', 'total-unregistered', 'total-rejected',
191 'total-unknown', 'total-partiallyregistered'.
192
193 =back
194
195 =cut