Debian Codegraph @

src/hardware/telephony/avaya/cm/snmp/mode/licenses.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::telephony::avaya::cm::snmp::mode::licenses;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_station_output {
29 my ($self, %options) = @_;
30
31 my $msg = sprintf("station capacity total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
32 $self->{result_values}->{total},
33 $self->{result_values}->{used},
34 $self->{result_values}->{prct_used},
35 $self->{result_values}->{free},
36 $self->{result_values}->{prct_free}
37 );
38 return $msg;
39 }
40
41 sub set_counters {
42 my ($self, %options) = @_;
43
44 $self->{maps_counters_type} = [
45 { name => 'station', type => 0, skipped_code => { -10 => 1 } },
46 ];
47
48 $self->{maps_counters}->{station} = [
49 { label => 'stations-usage', nlabel => 'stations.capacity.usage.count', set => {
50 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
51 closure_custom_output => $self->can('custom_station_output'),
52 perfdatas => [
53 { value => 'used', template => '%d', min => 0, max => 'total', cast_int => 1 },
54 ],
55 }
56 },
57 { label => 'stations-usage-free', display_ok => 0, nlabel => 'stations.capacity.free.count', set => {
58 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
59 closure_custom_output => $self->can('custom_station_output'),
60 perfdatas => [
61 { value => 'free', template => '%d', min => 0, max => 'total', cast_int => 1 },
62 ],
63 }
64 },
65 { label => 'stations-usage-prct', display_ok => 0, nlabel => 'stations.capacity.usage.percentage', set => {
66 key_values => [ { name => 'prct_used' } ],
67 output_template => 'station capacity used : %.2f %%',
68 perfdatas => [
69 { value => 'prct_used', template => '%.2f', min => 0, max => 100, unit => '%' },
70 ],
71 }
72 }
73 ];
74 }
75
76 sub new {
77 my ($class, %options) = @_;
78 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
79 bless $self, $class;
80
81 $options{options}->add_options(arguments => {
82 });
83
84 return $self;
85 }
86
87 my $mapping = {
88 avCmCapacityLicStatCapUsed => { oid => '.1.3.6.1.4.1.6889.2.73.8.1.20.4' },
89 avCmCapacityLicStatCapLicLimit => { oid => '.1.3.6.1.4.1.6889.2.73.8.1.20.6' },
90 };
91
92 sub manage_selection {
93 my ($self, %options) = @_;
94
95 my $results = $options{snmp}->get_leef(
96 oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
97 nothing_quit => 1
98 );
99 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => 0);
100
101 $self->{station} = {
102 total => $result->{avCmCapacityLicStatCapLicLimit},
103 used => $result->{avCmCapacityLicStatCapUsed},
104 free => $result->{avCmCapacityLicStatCapLicLimit} - $result->{avCmCapacityLicStatCapUsed},
105 prct_used => $result->{avCmCapacityLicStatCapUsed} * 100 / $result->{avCmCapacityLicStatCapLicLimit},
106 prct_free => ($result->{avCmCapacityLicStatCapLicLimit} - $result->{avCmCapacityLicStatCapUsed}) * 100 / $result->{avCmCapacityLicStatCapLicLimit},
107 };
108 }
109
110 1;
111
112 __END__
113
114 =head1 MODE
115
116 Check licenses usage.
117
118 =over 8
119
120 =item B<--warning-*> B<--critical-*>
121
122 Thresholds.
123 Can be: 'stations-usage', 'stations-usage-free', 'stations-usage-prct' (%).
124
125 =back
126
127 =cut