Debian Codegraph @

src/hardware/devices/polycom/rprm/snmp/mode/sites.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::sites;
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 => 'site', type => 1, cb_prefix_output => 'prefix_site_output', message_multiple => 'All sites are ok', skipped_code => { -10 => 1 } }
34 ];
35
36 $self->{maps_counters}->{global} = [
37 { label => 'rprm-total-sites', nlabel => 'rprm.sites.total.count', set => {
38 key_values => [ { name => 'sites_count' } ],
39 output_template => 'Total sites: %s',
40 perfdatas => [ { template => '%d', min => 0 } ]
41 }
42 }
43 ];
44
45 $self->{maps_counters}->{site} = [
46 { label => 'site-active-calls', nlabel => 'rprm.site.calls.active.count', set => {
47 key_values => [ { name => 'site_active_calls' }, { name => 'display' } ],
48 output_template => 'current active calls: %s',
49 perfdatas => [
50 { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
51 ]
52 }
53 },
54 { label => 'site-bandwidth-used-prct', nlabel => 'rprm.site.bandwidth.used.percentage', set => {
55 key_values => [ { name => 'site_bandwidth_used_prct' }, { name => 'display' } ],
56 output_template => 'current bandwidth usage: %.2f %%',
57 perfdatas => [
58 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
59 ]
60 }
61 },
62 { label => 'site-bandwidth-total', nlabel => 'rprm.site.bandwidth.total.bytespersecond', set => {
63 key_values => [ { name => 'site_bandwidth_total' }, { name => 'display' } ],
64 closure_custom_output => $self->can('custom_bandwidth_total_output'),
65 perfdatas => [
66 { template => '%.2f', min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }
67 ]
68 }
69 },
70 { label => 'site-callbitrate', nlabel => 'rprm.site.callbitrate.average.ratio', set => {
71 key_values => [ { name => 'site_callbitrate' }, { name => 'display' } ],
72 output_template => 'Average call bit rate: %.2f',
73 perfdatas => [
74 { template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }
75 ]
76 }
77 },
78 { label => 'site-packetloss-prct', nlabel => 'rprm.site.packetloss.average.percentage', set => {
79 key_values => [ { name => 'site_packetloss_prct' }, { name => 'display' } ],
80 output_template => 'Average packetloss: %.2f %%',
81 perfdatas => [
82 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
83 ]
84 }
85 },
86 { label => 'site-jitter', nlabel => 'rprm.site.jitter.average.milliseconds', set => {
87 key_values => [ { name => 'site_jitter' }, { name => 'display' } ],
88 output_template => 'Average jitter time: %.2f ms',
89 perfdatas => [
90 { template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
91 ]
92 }
93 },
94 { label => 'site-delay', nlabel => 'rprm.site.delay.average.milliseconds', set => {
95 key_values => [ { name => 'site_delay' }, { name => 'display' } ],
96 output_template => 'Average delay time: %.2f ms',
97 perfdatas => [
98 { template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
99 ]
100 }
101 }
102 ];
103 }
104
105 sub new {
106 my ($class, %options) = @_;
107 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
108 bless $self, $class;
109
110 $options{options}->add_options(arguments => {
111 'filter-site:s' => { name => 'filter_site' }
112 });
113
114 return $self;
115 }
116
117 sub prefix_site_output {
118 my ($self, %options) = @_;
119
120 return "Site '" . $options{instance_value}->{display} . "' ";
121 }
122
123 sub custom_bandwidth_total_output {
124 my ($self, %options) = @_;
125
126 my ($bandwidth, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{site_bandwidth_total}, network => 1);
127 return sprintf("Total allowed bandwidth: %.2f %s/s", $bandwidth, $unit);
128 }
129
130 sub manage_selection {
131 my ($self, %options) = @_;
132
133 my $mapping = {
134 serviceTopologySiteName => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.2' },
135 serviceTopologySiteTerritoryId => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.3' },
136 serviceTopologySiteCallCount => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.4' },
137 serviceTopologySiteBandwidthUsed => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.5' },
138 serviceTopologySiteBandwidthTotal => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.6' },
139 serviceTopologySiteAverageCallBitRate => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.7' },
140 serviceTopologySitePacketLoss => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.8' },
141 serviceTopologySiteAverageJitter => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.9' },
142 serviceTopologySiteAverageDelay => { oid => '.1.3.6.1.4.1.13885.102.1.2.14.4.1.10' }
143 };
144
145 my $oid_serviceTopologySiteEntry = '.1.3.6.1.4.1.13885.102.1.2.14.4.1';
146 my $oid_serviceTopologySiteCount = '.1.3.6.1.4.1.13885.102.1.2.14.3.0';
147
148 my $global_result = $options{snmp}->get_leef(oids => [$oid_serviceTopologySiteCount], nothing_quit => 1);
149
150 $self->{global} = { sites_count => $global_result->{$oid_serviceTopologySiteCount} };
151
152 my $site_result = $options{snmp}->get_table(
153 oid => $oid_serviceTopologySiteEntry,
154 nothing_quit => 1
155 );
156
157 foreach my $oid (keys %{$site_result}) {
158 next if ($oid !~ /^$mapping->{serviceTopologySiteName}->{oid}\.(.*)$/);
159 my $instance = $1;
160 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $site_result, instance => $instance);
161
162 $result->{serviceTopologySiteName} = centreon::plugins::misc::trim($result->{serviceTopologySiteName});
163 if (defined($self->{option_results}->{filter_site}) && $self->{option_results}->{filter_site} ne '' &&
164 $result->{serviceTopologySiteName} !~ /$self->{option_results}->{filter_site}/) {
165 $self->{output}->output_add(long_msg => "skipping '" . $result->{serviceTopologySiteName} . "': no matching filter.", debug => 1);
166 next;
167 }
168
169 my $site_bandwidth_total = $result->{serviceTopologySiteBandwidthTotal} * 1000000 ; #Mbps
170 $result->{serviceTopologySiteName} =~ s/\ /\_/g; #instance perfdata compat
171
172 $self->{site}->{$instance} = {
173 display => $result->{serviceTopologySiteName},
174 site_active_calls => $result->{serviceTopologySiteCallCount},
175 site_bandwidth_used_prct => $result->{serviceTopologySiteBandwidthUsed},
176 site_bandwidth_total => $site_bandwidth_total,
177 site_callbitrate => $result->{serviceTopologySiteAverageCallBitRate},
178 site_packetloss_prct => $result->{serviceTopologySitePacketLoss},
179 site_jitter => $result->{serviceTopologySiteAverageJitter},
180 site_delay => $result->{serviceTopologySiteAverageDelay}
181 };
182 }
183 }
184
185 1;
186
187 __END__
188
189 =head1 MODE
190
191 Check Polycom RPRM sites.
192
193 =over 8
194
195 =item B<--filter-site>
196
197 Filter on one or several site (POSIX regexp)
198
199 =item B<--warning-* --critical-*>
200
201 Warning & Critical Thresholds. Possible values:
202
203 [GLOBAL] rprm-total-sites
204
205 [SITE] site-active-calls, site-bandwidth-used-prct,
206 site-bandwidth-total, site-callbitrate, site-packetloss-prct,
207 site-jitter, site-delay
208
209 =back
210
211 =cut