Debian Codegraph @

src/hardware/devices/polycom/dma/snmp/mode/clusters.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 hardware::devices::polycom::dma::snmp::mode::clusters;
22
23 use base qw(centreon::plugins::templates::counter);
24 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
25
26 use strict;
27 use warnings;
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'global', type => 0 },
34 { name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok', skipped_code => { -10 => 1 } }
35 ];
36
37 $self->{maps_counters}->{global} = [
38 { label => 'dma-total-clusters', nlabel => 'dma.clusters.total.count', set => {
39 key_values => [ { name => 'clusters_count' } ],
40 output_template => 'Total clusters : %s',
41 perfdatas => [ { template => '%d', min => 0 } ]
42 }
43 },
44 ];
45
46 $self->{maps_counters}->{cluster} = [
47 {
48 label => 'cluster-status',
49 type => 2,
50 critical_default => '%{cluster_status} =~ /outOfService/i',
51 display_ok => 0,
52 set => {
53 key_values => [ { name => 'cluster_status' }, { name => 'display' } ],
54 closure_custom_output => $self->can('custom_cluster_status_output'),
55 closure_custom_perfdata => sub { return 0; },
56 closure_custom_threshold_check => \&catalog_status_threshold_ng
57 }
58 },
59 {
60 label => 'license-status',
61 type => 2,
62 critical_default => '%{license_status} =~ /invalid/i',
63 display_ok => 0,
64 set => {
65 key_values => [ { name => 'license_status' }, { name => 'display' } ],
66 closure_custom_output => $self->can('custom_license_status_output'),
67 closure_custom_perfdata => sub { return 0; },
68 closure_custom_threshold_check => \&catalog_status_threshold
69 }
70 },
71 { label => 'cluster-active-calls', nlabel => 'dma.cluster.activecalls.count', set => {
72 key_values => [ { name => 'active_calls' }, { name => 'licenses_total' }, { name => 'display' } ],
73 output_template => 'Active calls : %s',
74 perfdatas => [
75 { template => '%s', max => 'licenses_total', label_extra_instance => 1, instance_use => 'display' }
76 ]
77 }
78 },
79 { label => 'cluster-license-usage-free', nlabel => 'dma.cluster.licenses.free.count', set => {
80 key_values => [ { name => 'licenses_free' }, { name => 'display' } ],
81 output_template => 'Free licenses : %s',
82 perfdatas => [
83 { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
84 ]
85 }
86 },
87 { label => 'cluster-license-usage-prct', nlabel => 'dma.cluster.licenses.usage.percentage', set => {
88 key_values => [ { name => 'licenses_used_prct' }, { name => 'display' } ],
89 output_template => 'Licenses percentage usage : %.2f%%',
90 perfdatas => [
91 { template => '%.2f', min => 0, unit => '%', label_extra_instance => 1, instance_use => 'display' }
92 ]
93 }
94 }
95 ];
96 }
97
98 sub prefix_cluster_output {
99 my ($self, %options) = @_;
100
101 return "Cluster '" . $options{instance_value}->{display} . "' ";
102 }
103
104 sub custom_cluster_status_output {
105 my ($self, %options) = @_;
106
107 return sprintf('Cluster status: %s', $self->{result_values}->{cluster_status});
108 }
109
110 sub custom_license_status_output {
111 my ($self, %options) = @_;
112
113 return sprintf('License status: %s', $self->{result_values}->{license_status});
114 }
115
116 sub new {
117 my ($class, %options) = @_;
118 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
119 bless $self, $class;
120
121 $options{options}->add_options(arguments => {
122 'filter-cluster:s' => { name => 'filter_cluster' }
123 });
124
125 return $self;
126 }
127
128 my %map_cluster_status = (1 => 'inService', 2 => 'busyOut', 3 => 'outOfService');
129 my %map_licensing_status = (1 => 'valid', 2 => 'invalid', 3 => 'notInstalled');
130
131 my $mapping_status = {
132 stClClusterName => { oid => '.1.3.6.1.4.1.13885.13.2.2.3.2.1.2' },
133 stClClusterStatus => { oid => '.1.3.6.1.4.1.13885.13.2.2.3.2.1.3', map => \%map_cluster_status }
134 };
135
136 my $mapping_licenses = {
137 stLicClusterName => { oid => '.1.3.6.1.4.1.13885.13.2.2.3.3.1.2' },
138 stLicLicenseStatus => { oid => '.1.3.6.1.4.1.13885.13.2.2.3.3.1.3', map => \%map_licensing_status},
139 stLicLicensedCalls => { oid => '.1.3.6.1.4.1.13885.13.2.2.3.3.1.4' },
140 stLicCallserverActiveCalls => { oid => '.1.3.6.1.4.1.13885.13.2.2.3.3.1.5' }
141 };
142
143 my $oid_stClustersEntry = '.1.3.6.1.4.1.13885.13.2.2.3.2.1';
144 my $oid_stLicensesEntry = '.1.3.6.1.4.1.13885.13.2.2.3.3.1';
145
146 my $oid_stClustersCount = '.1.3.6.1.4.1.13885.13.2.2.3.1.0'; #global
147
148 sub manage_selection {
149 my ($self, %options) = @_;
150
151 my $global_result = $options{snmp}->get_leef(
152 oids => [ $oid_stClustersCount ],
153 nothing_quit => 1
154 );
155
156 $self->{global} = { clusters_count => $global_result->{$oid_stClustersCount} };
157
158 $self->{clusters_result} = {};
159 $self->{clusters_result} = $options{snmp}->get_multiple_table(
160 oids => [
161 { oid => $oid_stClustersEntry },
162 { oid => $oid_stLicensesEntry }
163 ],
164 nothing_quit => 1
165 );
166
167 foreach my $oid (keys %{$self->{clusters_result}->{$oid_stClustersEntry}}) {
168 next if ($oid !~ /^$mapping_status->{stClClusterName}->{oid}\.(.*)$/);
169 my $instance = $1;
170
171 my $result_status = $options{snmp}->map_instance(mapping => $mapping_status, results => $self->{clusters_result}->{$oid_stClustersEntry}, instance => $instance);
172 my $result_licenses = $options{snmp}->map_instance(mapping => $mapping_licenses, results => $self->{clusters_result}->{$oid_stLicensesEntry}, instance => $instance);
173
174 if (defined($self->{option_results}->{filter_cluster}) && $self->{option_results}->{filter_cluster} ne '' &&
175 $result_status->{stClClusterName} !~ /$self->{option_results}->{filter_cluster}/) {
176 $self->{output}->output_add(long_msg => "skipping '" . $result_status->{stClClusterName} . "': no matching filter.", debug => 1);
177 next;
178 }
179
180 my ($licenses_used, $licenses_total) = ($result_licenses->{stLicCallserverActiveCalls}, $result_licenses->{stLicLicensedCalls});
181 my $licenses_free = $licenses_total - $licenses_used;
182
183 $self->{cluster}->{$instance} = {
184 display => $result_status->{stClClusterName},
185 cluster_status => $result_status->{stClClusterStatus},
186 active_calls => $result_licenses->{stLicCallserverActiveCalls},
187 license_status => $result_licenses->{stLicLicenseStatus},
188 licenses_total => $licenses_total,
189 licenses_free => $licenses_free,
190 licenses_used_prct => ( $licenses_used * 100 ) / $licenses_total
191 };
192 }
193 }
194
195 1;
196
197 __END__
198
199 =head1 MODE
200
201 Check information about clusters in the Polycom DMA supercluster.
202
203 =over 8
204
205 =item B<--filter-cluster>
206
207 Filter on one or several cluster (POSIX regexp)
208
209 =item B<--warning-cluster-status>
210
211 Custom Warning threshold of the cluster state (default: none)
212 Syntax: --warning-cluster-status='%{cluster_status} =~ /busyOut/i'
213
214
215 =item B<--critical-cluster-status>
216
217 Custom Critical threshold of the cluster state
218 (default: '%{cluster_status} =~ /outOfService/i' )
219 Syntax: --critical-cluster-status='%{cluster_status} =~ /busyOut/i'
220
221
222 =item B<--warning-license-status>
223
224 Custom Warning threshold of the cluster license state (default: none)
225 Syntax: --warning-license-status='%{license_status} =~ /notinstalled/i'
226
227
228 =item B<--critical-license-status>
229
230 Custom Critical threshold of the cluster license state
231 (default: '%{license_status} =~ /invalid/i')
232 Syntax: --critical-license-status='%{license_status} =~ /notinstalled/i'
233
234 =item B<--warning-* --critical-*>
235
236 Warning & Critical Thresholds for the collected metrics. Possible values:
237
238 [PER-CLUSTER] cluster-active-calls cluster-license-usage-free cluster-license-usage-prct
239
240 [GLOBAL] dma-total-clusters
241
242 =back
243
244 =cut
245
246