Debian Codegraph @

src/network/cisco/callmanager/snmp/mode/ccmusage.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::ccmusage;
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 'status : ' . $self->{result_values}->{status};
33 }
34
35 sub custom_status_calc {
36 my ($self, %options) = @_;
37
38 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_ccmStatus'};
39 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_ccmName'};
40 return 0;
41 }
42
43 sub prefix_ccm_output {
44 my ($self, %options) = @_;
45
46 return "CCM '" . $options{instance_value}->{ccmName} . "' ";
47 }
48
49 sub set_counters {
50 my ($self, %options) = @_;
51
52 $self->{maps_counters_type} = [
53 { name => 'global', type => 0 },
54 { name => 'ccm', type => 1, cb_prefix_output => 'prefix_ccm_output', message_multiple => 'All CCM are ok' }
55 ];
56
57 $self->{maps_counters}->{ccm} = [
58 { label => 'status', type => 2, critical_default => '%{status} !~ /up/', set => {
59 key_values => [ { name => 'ccmStatus' }, { name => 'ccmName' } ],
60 closure_custom_calc => $self->can('custom_status_calc'),
61 closure_custom_output => $self->can('custom_status_output'),
62 closure_custom_perfdata => sub { return 0; },
63 closure_custom_threshold_check => \&catalog_status_threshold_ng
64 }
65 }
66 ];
67
68 my @map = (
69 ['phones-registered', 'Phones Registered : %s', 'ccmRegisteredPhones', 'phones.registered.count'],
70 ['phones-unregistered', 'Phones Unregistered : %s', 'ccmUnregisteredPhones', 'phones.unregistered.count'],
71 ['phones-rejected', 'Phones Rejected : %s', 'ccmRejectedPhones', 'phones.rejected.count'],
72 ['gateways-registered', 'Gateways Registered : %s', 'ccmRegisteredGateways', 'gateways.registered.count'],
73 ['gateways-unregistered', 'Gateways Unregistered : %s', 'ccmUnregisteredGateways', 'gateways.unregistered.count'],
74 ['gateways-rejected', 'Gateways Rejected : %s', 'ccmRejectedGateways', 'gateways.rejected.count'],
75 ['mediadevices-registered', 'Media Devices Registered : %s', 'ccmRegisteredMediaDevices', 'media_devices.registered.count'],
76 ['mediadevices-unregistered', 'Media Devices Unregistered : %s', 'ccmUnregisteredMediaDevices', 'media_devices.unregistered.count'],
77 ['mediadevices-rejected', 'Media Devices Rejected : %s', 'ccmRejectedMediaDevices', 'media_devices.rejected.count']
78 );
79
80 $self->{maps_counters}->{global} = [];
81 foreach (@map) {
82 my $label = $_->[0];
83 $label =~ tr/-/_/;
84 push @{$self->{maps_counters}->{global}}, {
85 label => $_->[0], nlabel => $_->[3], set => {
86 key_values => [ { name => $_->[2] } ],
87 output_template => $_->[1],
88 perfdatas => [
89 { label => $label, value => $_->[2] , template => '%s', min => 0 }
90 ]
91 }
92 };
93 }
94 }
95
96 sub new {
97 my ($class, %options) = @_;
98 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
99 bless $self, $class;
100
101 $options{options}->add_options(arguments => {
102 });
103
104 return $self;
105 }
106
107 my %mapping_status = (1 => 'unknown', 2 => 'up', 3 => 'down');
108
109 my $mapping = {
110 ccmRegisteredPhones => { oid => '.1.3.6.1.4.1.9.9.156.1.5.5' },
111 ccmUnregisteredPhones => { oid => '.1.3.6.1.4.1.9.9.156.1.5.6' },
112 ccmRejectedPhones => { oid => '.1.3.6.1.4.1.9.9.156.1.5.7' },
113 ccmRegisteredGateways => { oid => '.1.3.6.1.4.1.9.9.156.1.5.8' },
114 ccmUnregisteredGateways => { oid => '.1.3.6.1.4.1.9.9.156.1.5.9' },
115 ccmRejectedGateways => { oid => '.1.3.6.1.4.1.9.9.156.1.5.10' },
116 ccmRegisteredMediaDevices => { oid => '.1.3.6.1.4.1.9.9.156.1.5.11' },
117 ccmUnregisteredMediaDevices => { oid => '.1.3.6.1.4.1.9.9.156.1.5.12' },
118 ccmRejectedMediaDevices => { oid => '.1.3.6.1.4.1.9.9.156.1.5.13' }
119 };
120 my $mapping2 = {
121 ccmName => { oid => '.1.3.6.1.4.1.9.9.156.1.1.2.1.2' },
122 ccmStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.1.2.1.5', map => \%mapping_status }
123 };
124
125 my $oid_ccmGlobalInfo = '.1.3.6.1.4.1.9.9.156.1.5';
126 my $oid_ccmEntry = '.1.3.6.1.4.1.9.9.156.1.1.2.1';
127
128 sub manage_selection {
129 my ($self, %options) = @_;
130
131 my $snmp_result = $options{snmp}->get_multiple_table(
132 oids => [
133 { oid => $oid_ccmGlobalInfo, end => $mapping->{ccmRejectedMediaDevices}->{oid} },
134 { oid => $oid_ccmEntry, end => $mapping2->{ccmStatus}->{oid} }
135 ],
136 nothing_quit => 1
137 );
138 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_ccmGlobalInfo}, instance => '0');
139 $self->{global} = $result;
140
141 $self->{ccm} = {};
142 foreach my $oid (keys %{$snmp_result->{$oid_ccmEntry}}) {
143 next if ($oid !~ /^$mapping2->{ccmStatus}->{oid}\.(.*)/);
144 my $instance = $1;
145 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_ccmEntry}, instance => $instance);
146
147 $self->{ccm}->{$instance} = $result;
148 }
149 }
150
151 1;
152
153 __END__
154
155 =head1 MODE
156
157 Check cisco call manager global usage.
158
159 =over 8
160
161 =item B<--filter-counters>
162
163 Only display some counters (regexp can be used).
164 Example: --filter-counters='phone'
165
166 =item B<--warning-status>
167
168 Define the conditions to match for the status to be WARNING (default: '').
169 You can use the following variables: %{status}, %{display}
170
171 =item B<--critical-status>
172
173 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /up/').
174 You can use the following variables: %{status}, %{display}
175
176 =item B<--warning-*> B<--critical-*>
177
178 Thresholds.
179
180 Can be: 'phones-registered', 'phones-unregistered', 'phones-rejected',
181 'gateways-registered', 'gateways-unregistered', 'gateways-rejected',
182 'mediadevices-registered', 'mediadevices-unregistered', 'mediadevices-rejected'.
183
184 =back
185
186 =cut