Debian Codegraph @

src/network/cisco/callmanager/snmp/mode/ctiusage.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::ctiusage;
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} . '_ccmCTIDeviceStatus'};
39 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_ccmCTIDeviceName'};
40 return 0;
41 }
42
43 sub prefix_cti_output {
44 my ($self, %options) = @_;
45
46 return "Cti '" . $options{instance_value}->{ccmCTIDeviceName} . "' ";
47 }
48
49 sub prefix_global_output {
50 my ($self, %options) = @_;
51
52 return 'Total ';
53 }
54
55 sub set_counters {
56 my ($self, %options) = @_;
57
58 $self->{maps_counters_type} = [
59 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
60 { name => 'cti', type => 1, cb_prefix_output => 'prefix_cti_output', message_multiple => 'All ctis are ok' }
61 ];
62
63 $self->{maps_counters}->{cti} = [
64 { label => 'status', type => 2, critical_default => '%{status} !~ /^registered/', set => {
65 key_values => [ { name => 'ccmCTIDeviceStatus' }, { name => 'ccmCTIDeviceName' } ],
66 closure_custom_calc => $self->can('custom_status_calc'),
67 closure_custom_output => $self->can('custom_status_output'),
68 closure_custom_perfdata => sub { return 0; },
69 closure_custom_threshold_check => \&catalog_status_threshold_ng
70 }
71 }
72 ];
73
74 my @map = (
75 ['total-registered', 'registered: %s', 'registered'],
76 ['total-unregistered', 'unregistered: %s', 'unregistered'],
77 ['total-rejected', 'rejected: %s', 'rejected'],
78 ['total-unknown', 'unknown: %s', 'unknown'],
79 ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered']
80 );
81
82 $self->{maps_counters}->{global} = [];
83 foreach (@map) {
84 push @{$self->{maps_counters}->{global}}, {
85 label => $_->[0], nlabel => 'cti.devices.total.' . $_->[2] . '.count', set => {
86 key_values => [ { name => $_->[2] } ],
87 output_template => $_->[1],
88 perfdatas => [
89 { 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, force_new_perfdata => 1);
99 bless $self, $class;
100
101 $self->{version} = '1.0';
102 $options{options}->add_options(arguments => {
103 });
104
105 return $self;
106 }
107
108 my %mapping_status = (
109 1 => 'unknown', 2 => 'registered', 3 => 'unregistered',
110 4 => 'rejected', 5 => 'partiallyregistered'
111 );
112
113 my $mapping = {
114 ccmCTIDeviceName => { oid => '.1.3.6.1.4.1.9.9.156.1.8.1.1.2' },
115 ccmCTIDeviceStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.8.1.1.5', map => \%mapping_status }
116 };
117
118 my $oid_ccmCtiEntry = '.1.3.6.1.4.1.9.9.156.1.8.1.1';
119
120 sub manage_selection {
121 my ($self, %options) = @_;
122
123 my $snmp_result = $options{snmp}->get_table(
124 oid => $oid_ccmCtiEntry,
125 start => $mapping->{ccmCTIDeviceName}->{oid},
126 end => $mapping->{ccmCTIDeviceStatus}->{oid},
127 nothing_quit => 1
128 );
129
130 $self->{phone} = {};
131 $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 };
132 foreach my $oid (keys %$snmp_result) {
133 next if ($oid !~ /^$mapping->{ccmCTIDeviceStatus}->{oid}\.(.*)/);
134 my $instance = $1;
135 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
136
137 $self->{phone}->{$instance} = $result;
138 $self->{global}->{$result->{ccmCTIDeviceStatus}}++;
139 }
140 }
141
142 1;
143
144 __END__
145
146 =head1 MODE
147
148 Check cti usage.
149
150 =over 8
151
152 =item B<--filter-counters>
153
154 Only display some counters (regexp can be used).
155 Example: --filter-counters='status'
156
157 =item B<--warning-status>
158
159 Define the conditions to match for the status to be WARNING (default: '').
160 You can use the following variables: %{status}, %{display}
161
162 =item B<--critical-status>
163
164 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /^registered/').
165 You can use the following variables: %{status}, %{display}
166
167 =item B<--warning-*> B<--critical-*>
168
169 Thresholds.
170 Can be: 'total-registered', 'total-unregistered', 'total-rejected',
171 'total-unknown', 'total-partiallyregistered'.
172
173 =back
174
175 =cut