Debian Codegraph @

src/hardware/devices/polycom/rprm/snmp/mode/sitelinks.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::rprm::snmp::mode::sitelinks;
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 => 'sitelink', type => 1, cb_prefix_output => 'prefix_sitelink_output', message_multiple => 'All SiteLinks are ok', skipped_code => { -10 => 1 } }
35 ];
36
37 $self->{maps_counters}->{global} = [
38 { label => 'rprm-total-sitelinks', nlabel => 'rprm.sitelinks.total.count', set => {
39 key_values => [ { name => 'sitelinks_count' } ],
40 output_template => 'Total sitelinks : %s',
41 perfdatas => [ { template => '%s', min => 0 } ]
42 }
43 }
44 ];
45
46 $self->{maps_counters}->{sitelink} = [
47 { label => 'sitelink-status', type => 2, critical_default => '%{sitelink_status} =~ /failed/i', set => {
48 key_values => [ { name => 'sitelink_status' }, { name => 'display' } ],
49 closure_custom_output => $self->can('custom_sitelink_status_output'),
50 closure_custom_perfdata => sub { return 0; },
51 closure_custom_threshold_check => \&catalog_status_threshold_ng
52 }
53 },
54 { label => 'sitelink-active-calls', nlabel => 'rprm.sitelink.calls.active.count', set => {
55 key_values => [ { name => 'sitelink_active_calls' }, { name => 'display' } ],
56 output_template => 'current active calls: %s',
57 perfdatas => [
58 { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
59 ]
60 }
61 },
62 { label => 'sitelink-bandwidth-used-prct', nlabel => 'rprm.sitelink.bandwidth.used.percentage', set => {
63 key_values => [ { name => 'sitelink_bandwidth_used_prct' }, { name => 'display' } ],
64 output_template => 'current bandwidth usage: %.2f %%',
65 perfdatas => [
66 { unit => '%', template => '%.2f', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
67 ]
68 }
69 },
70 { label => 'sitelink-bandwidth-total', nlabel => 'rprm.sitelink.bandwidth.total.bytespersecond', set => {
71 key_values => [ { name => 'sitelink_bandwidth_total' }, { name => 'display' } ],
72 closure_custom_output => $self->can('custom_bandwidth_total_output'),
73 perfdatas => [
74 { template => '%.2f', min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }
75 ]
76 }
77 },
78 { label => 'sitelink-callbitrate', nlabel => 'rprm.sitelink.callbitrate.average.ratio', set => {
79 key_values => [ { name => 'sitelink_callbitrate' }, { name => 'display' } ],
80 output_template => 'Average call bit rate: %.2f',
81 perfdatas => [
82 { template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }
83 ]
84 }
85 },
86 { label => 'sitelink-packetloss-prct', nlabel => 'rprm.sitelink.packetloss.average.percentage', set => {
87 key_values => [ { name => 'sitelink_packetloss_prct' }, { name => 'display' } ],
88 output_template => 'Average packetloss: %.2f %%',
89 perfdatas => [
90 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
91 ]
92 }
93 },
94 { label => 'sitelink-jitter', nlabel => 'rprm.sitelink.jitter.average.milliseconds', set => {
95 key_values => [ { name => 'sitelink_jitter' }, { name => 'display' } ],
96 output_template => 'Average jitter time: %.2f ms',
97 perfdatas => [
98 { template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
99 ]
100 }
101 },
102 { label => 'sitelink-delay', nlabel => 'rprm.sitelink.delay.average.milliseconds', set => {
103 key_values => [ { name => 'sitelink_delay' }, { name => 'display'} ],
104 output_template => 'Average delay time: %.2f ms',
105 perfdatas => [
106 { template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
107 ]
108 }
109 }
110 ];
111 }
112
113 sub new {
114 my ($class, %options) = @_;
115 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
116 bless $self, $class;
117
118 $options{options}->add_options(arguments => {
119 'filter-sitelink:s' => { name => 'filter_sitelink' }
120 });
121
122 return $self;
123 }
124
125 sub custom_sitelink_status_output {
126 my ($self, %options) = @_;
127
128 return sprintf('Current status: "%s"', $self->{result_values}->{sitelink_status});
129 }
130
131 sub prefix_sitelink_output {
132 my ($self, %options) = @_;
133
134 return "SiteLink '" . $options{instance_value}->{display} . "' ";
135 }
136
137 sub custom_bandwidth_total_output {
138 my ($self, %options) = @_;
139
140 my ($bandwidth, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{sitelink_bandwidth_total}, network => 1);
141
142 return sprintf("Total allowed bandwidth: %.2f %s/s", $bandwidth, $unit);
143 }
144
145 sub manage_selection {
146 my ($self, %options) = @_;
147
148 my $mapping = {
149 serviceTopologySiteLinkName => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.3' },
150 serviceTopologySiteLinkStatus => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.4' },
151 serviceTopologySiteLinkCallCount => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.7' },
152 serviceTopologySiteLinkBandwidthUsed => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.8' },
153 serviceTopologySiteLinkBandwidthTotal => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.9' },
154 serviceTopologySiteLinkAverageCallBitRate => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.10' },
155 serviceTopologySiteLinkPacketLoss => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.11' },
156 serviceTopologySiteLinkAverageJitter => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.12' },
157 serviceTopologySiteLinkAverageDelay => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.6.1.13' },
158 };
159
160 my %sitelink_status = ( 1 => 'disabled', 2 => 'ok', 3 => 'failed' );
161 my $oid_serviceTopologySiteLinkEntry = '.1.3.6.1.4.1.13885.102.1.2.14.6.1';
162 my $oid_serviceTopologySiteLinkCount = '.1.3.6.1.4.1.13885.102.1.2.14.5.0';
163
164 my $global_result = $options{snmp}->get_leef(oids => [$oid_serviceTopologySiteLinkCount], nothing_quit => 1);
165
166 $self->{global} = { sitelinks_count => $global_result->{$oid_serviceTopologySiteLinkCount} };
167
168 my $sitelink_result = $options{snmp}->get_table(
169 oid => $oid_serviceTopologySiteLinkEntry,
170 nothing_quit => 1
171 );
172
173 foreach my $oid (keys %{$sitelink_result}) {
174 next if ($oid !~ /^$mapping->{serviceTopologySiteLinkName}->{oid}\.(.*)$/);
175 my $instance = $1;
176 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $sitelink_result, instance => $instance);
177
178 $result->{serviceTopologySiteLinkName} = centreon::plugins::misc::trim($result->{serviceTopologySiteLinkName});
179 if (defined($self->{option_results}->{filter_sitelink}) && $self->{option_results}->{filter_sitelink} ne '' &&
180 $result->{serviceTopologySiteLinkName} !~ /$self->{option_results}->{filter_sitelink}/) {
181 $self->{output}->output_add(long_msg => "skipping '" . $result->{serviceTopologySiteLinkName} . "': no matching filter.", debug => 1);
182 next;
183 }
184
185 my $sitelink_bandwidth_total = $result->{serviceTopologySiteLinkBandwidthTotal} * 1000000 ; #Mbps
186 $result->{serviceTopologySiteLinkName} =~ s/\ /\_/g; #instance perfdata compat
187
188 $self->{sitelink}->{$instance} = {
189 display => $result->{serviceTopologySiteLinkName},
190 sitelink_status => $sitelink_status{$result->{serviceTopologySiteLinkStatus}},
191 sitelink_active_calls => $result->{serviceTopologySiteLinkCallCount},
192 sitelink_bandwidth_used_prct => $result->{serviceTopologySiteLinkBandwidthUsed},
193 sitelink_bandwidth_total => $sitelink_bandwidth_total,
194 sitelink_callbitrate => $result->{serviceTopologySiteLinkAverageCallBitRate},
195 sitelink_packetloss_prct => $result->{serviceTopologySiteLinkPacketLoss},
196 sitelink_jitter => $result->{serviceTopologySiteLinkAverageJitter},
197 sitelink_delay => $result->{serviceTopologySiteLinkAverageDelay}
198 };
199 }
200 }
201
202 1;
203
204 __END__
205
206 =head1 MODE
207
208 Check Polycom RPRM SiteLinks.
209
210 =over 8
211
212 =item B<--filter-sitelink>
213
214 Filter on one or several SiteLinks (POSIX regexp)
215
216 =item B<--warning-sitelink-status>
217
218 Custom Warning threshold of the SiteLink state (default: none)
219 Syntax: --warning-sitelink-status='%{sitelink_status} =~ /disabled/i'
220
221 =item B<--critical-sitelink-status>
222
223 Custom Critical threshold of the SiteLink state
224 (default: '%{sitelink_status} =~ /failed/i' )
225 Syntax: --critical-sitelink-status='%{sitelink_status} =~ /failed/i'
226
227 =item B<--warning-* --critical-*>
228
229 Warning & Critical Thresholds. Possible values:
230
231 [GLOBAL] rprm-total-sitelinks
232
233 [SITE] sitelink-active-calls, sitelink-bandwidth-used-prct,
234 sitelink-bandwidth-total, sitelink-callbitrate, sitelink-packetloss-prct,
235 sitelink-jitter, sitelink-delay
236
237 =back
238
239 =cut