Debian Codegraph @

src/hardware/devices/polycom/dma/snmp/mode/deviceregistrations.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::deviceregistrations;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'global', type => 0 },
33 { name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok', skipped_code => { -10 => 1 } }
34 ];
35
36 $self->{maps_counters}->{global} = [
37 { label => 'dma-total-registrations', nlabel => 'dma.registrations.count', set => {
38 key_values => [ { name => 'useDevRegistrationsCount' } ],
39 output_template => 'Total registrations : %s',
40 perfdatas => [
41 { template => '%d', min => 0 }
42 ]
43 }
44 }
45 ];
46
47 $self->{maps_counters}->{cluster} = [
48 { label => 'cluster-endpoint-active-registration', nlabel => 'dma.cluster.endpoint.registrations.active.count', set => {
49 key_values => [ { name => 'useDevRegActiveEndpointReg' }, { name => 'display'} ],
50 output_template => 'endpoint active registrations: %s',
51 perfdatas => [
52 { template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
53 ]
54 }
55 },
56 { label => 'cluster-endpoint-inactive-registration', nlabel => 'dma.cluster.endpoint.registrations.inactive.count', set => {
57 key_values => [ { name => 'useDevRegInactiveEndpointReg' }, { name => 'display'} ],
58 output_template => 'endpoint inactive registrations: %s',
59 perfdatas => [
60 { template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
61 ]
62 }
63 }
64 ];
65 }
66
67 sub new {
68 my ($class, %options) = @_;
69 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
70 bless $self, $class;
71
72 $options{options}->add_options(arguments => {
73 'filter-cluster:s' => { name => 'filter_cluster' },
74 });
75 return $self;
76 }
77
78 sub prefix_cluster_output {
79 my ($self, %options) = @_;
80
81 return "Cluster '" . $options{instance_value}->{display} . "' ";
82 }
83
84 my $mapping = {
85 useDevRegClusterName => { oid => '.1.3.6.1.4.1.13885.13.2.3.3.1.2.1.2' },
86 useDevRegActiveEndpointReg => { oid => '.1.3.6.1.4.1.13885.13.2.3.3.1.2.1.3' },
87 useDevRegInactiveEndpointReg => { oid => '.1.3.6.1.4.1.13885.13.2.3.3.1.2.1.4' },
88 };
89
90 my $oid_useDevRegistrationsEntry = '.1.3.6.1.4.1.13885.13.2.3.3.1.2.1';
91
92 sub manage_selection {
93 my ($self, %options) = @_;
94
95 my $oid_useDevRegistrationsCount = '.1.3.6.1.4.1.13885.13.2.3.3.1.1.0';
96 my $global_result = $options{snmp}->get_leef(
97 oids => [$oid_useDevRegistrationsCount],
98 nothing_quit => 1
99 );
100
101 $self->{global} = { useDevRegistrationsCount => $global_result->{$oid_useDevRegistrationsCount} };
102
103 $self->{cluster} = {};
104 my $cluster_result = $options{snmp}->get_table(
105 oid => $oid_useDevRegistrationsEntry,
106 nothing_quit => 1
107 );
108
109 foreach my $oid (keys %{$cluster_result}) {
110 next if ($oid !~ /^$mapping->{useDevRegClusterName}->{oid}\.(.*)$/);
111 my $instance = $1;
112 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $cluster_result, instance => $instance);
113
114 $result->{useDevRegClusterName} = centreon::plugins::misc::trim($result->{useDevRegClusterName});
115 if (defined($self->{option_results}->{filter_cluster}) && $self->{option_results}->{filter_cluster} ne '' &&
116 $result->{useDevRegClusterName} !~ /$self->{option_results}->{filter_cluster}/) {
117 $self->{output}->output_add(long_msg => "skipping '" . $result->{useDevRegClusterName} . "': no matching filter.", debug => 1);
118 next;
119 }
120
121 $self->{cluster}->{$instance} = {
122 display => $result->{useDevRegClusterName},
123 %$result
124 };
125 }
126 }
127
128 1;
129
130 __END__
131
132 =head1 MODE
133
134 Check global and per-cluster devices registrations metrics.
135
136 =over 8
137
138 =item B<--filter-cluster>
139
140 Filter on one or several cluster (POSIX regexp)
141
142 =item B<--warning-* --critical-*>
143
144 Warning & Critical Thresholds. Possible values:
145
146 [PER-CLUSTER] cluster-endpoint-active-registration cluster-endpoint-inactive-registration
147
148 [GLOBAL] dma-total-registrations
149
150 =back
151
152 =cut