| 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 network::mitel::3300icp::snmp::mode::licenses; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
|
| 29 |
sub custom_user_calc { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{result_values}->{purchased} = $options{new_datas}->{$self->{instance} . '_mitelIpera3000IPUsrLicPurchased'}; |
| 33 |
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_mitelIpera3000IPUsrLicUsed'}; |
| 34 |
$self->{result_values}->{prct} = ($self->{result_values}->{purchased} != 0) ? $self->{result_values}->{used} / $self->{result_values}->{purchased} * 100 : 0; |
| 35 |
return 0; |
| 36 |
} |
| 37 |
|
| 38 |
sub custom_device_calc { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
$self->{result_values}->{purchased} = $options{new_datas}->{$self->{instance} . '_mitelIpera3000IPDevLicPurchased'}; |
| 42 |
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_mitelIpera3000IPDevLicUsed'}; |
| 43 |
$self->{result_values}->{prct} = ($self->{result_values}->{purchased} != 0) ? $self->{result_values}->{used} / $self->{result_values}->{purchased} * 100 : 0; |
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
sub custom_usage_perfdata { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
$self->{output}->perfdata_add(label => 'licenses_' . $self->{label}, |
| 51 |
value => $self->{result_values}->{used}, |
| 52 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{purchased}, cast_int => 1), |
| 53 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{purchased}, cast_int => 1), |
| 54 |
min => 0, max => $self->{result_values}->{purchased}); |
| 55 |
} |
| 56 |
|
| 57 |
sub custom_usage_output { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
return sprintf("%s licenses used: %s/%s (%.2f %%)", ucfirst($self->{label}), |
| 61 |
$self->{result_values}->{used}, |
| 62 |
$self->{result_values}->{purchased}, |
| 63 |
$self->{result_values}->{prct}); |
| 64 |
} |
| 65 |
|
| 66 |
sub set_counters { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
$self->{maps_counters_type} = [ |
| 70 |
{ name => 'global', type => 0 }, |
| 71 |
]; |
| 72 |
|
| 73 |
$self->{maps_counters}->{global} = [ |
| 74 |
{ label => 'user', set => { |
| 75 |
key_values => [ { name => 'mitelIpera3000IPUsrLicPurchased' }, { name => 'mitelIpera3000IPUsrLicUsed' } ], |
| 76 |
closure_custom_calc => $self->can('custom_user_calc'), |
| 77 |
closure_custom_output => $self->can('custom_usage_output'), |
| 78 |
threshold_use => 'prct', |
| 79 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 80 |
} |
| 81 |
}, |
| 82 |
{ label => 'device', set => { |
| 83 |
key_values => [ { name => 'mitelIpera3000IPDevLicPurchased' }, { name => 'mitelIpera3000IPDevLicUsed' } ], |
| 84 |
closure_custom_calc => $self->can('custom_device_calc'), |
| 85 |
closure_custom_output => $self->can('custom_usage_output'), |
| 86 |
threshold_use => 'prct', |
| 87 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 88 |
} |
| 89 |
}, |
| 90 |
]; |
| 91 |
} |
| 92 |
|
| 93 |
sub new { |
| 94 |
my ($class, %options) = @_; |
| 95 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 96 |
bless $self, $class; |
| 97 |
|
| 98 |
$options{options}->add_options(arguments => |
| 99 |
{ |
| 100 |
}); |
| 101 |
|
| 102 |
return $self; |
| 103 |
} |
| 104 |
|
| 105 |
sub check_options { |
| 106 |
my ($self, %options) = @_; |
| 107 |
$self->SUPER::check_options(%options); |
| 108 |
} |
| 109 |
|
| 110 |
my $oid_mitelIpera3000IPUsrLicPurchased = '.1.3.6.1.4.1.1027.4.1.1.2.1.2.1.0'; |
| 111 |
my $oid_mitelIpera3000IPUsrLicUsed = '.1.3.6.1.4.1.1027.4.1.1.2.1.2.2.0'; |
| 112 |
my $oid_mitelIpera3000IPDevLicPurchased = '.1.3.6.1.4.1.1027.4.1.1.2.1.2.3.0'; |
| 113 |
my $oid_mitelIpera3000IPDevLicUsed = '.1.3.6.1.4.1.1027.4.1.1.2.1.2.4.0'; |
| 114 |
|
| 115 |
sub manage_selection { |
| 116 |
my ($self, %options) = @_; |
| 117 |
|
| 118 |
my $result = $options{snmp}->get_leef(oids => [ $oid_mitelIpera3000IPUsrLicPurchased, |
| 119 |
$oid_mitelIpera3000IPUsrLicUsed, |
| 120 |
$oid_mitelIpera3000IPDevLicPurchased, |
| 121 |
$oid_mitelIpera3000IPDevLicUsed ], |
| 122 |
nothing_quit => 1); |
| 123 |
|
| 124 |
$self->{global} = { |
| 125 |
mitelIpera3000IPUsrLicPurchased => $result->{$oid_mitelIpera3000IPUsrLicPurchased}, |
| 126 |
mitelIpera3000IPUsrLicUsed => $result->{$oid_mitelIpera3000IPUsrLicUsed}, |
| 127 |
mitelIpera3000IPDevLicPurchased => $result->{$oid_mitelIpera3000IPDevLicPurchased}, |
| 128 |
mitelIpera3000IPDevLicUsed => $result->{$oid_mitelIpera3000IPDevLicUsed}, |
| 129 |
}; |
| 130 |
} |
| 131 |
|
| 132 |
1; |
| 133 |
|
| 134 |
__END__ |
| 135 |
|
| 136 |
=head1 MODE |
| 137 |
|
| 138 |
Check call server licenses used versus purchased. |
| 139 |
|
| 140 |
=over 8 |
| 141 |
|
| 142 |
=item B<--warning-*> |
| 143 |
|
| 144 |
Warning threshold. |
| 145 |
Can be: 'user' (%), 'device' (%). |
| 146 |
|
| 147 |
=item B<--critical-*> |
| 148 |
|
| 149 |
Critical threshold. |
| 150 |
Can be: 'user' (%), 'device' (%). |
| 151 |
|
| 152 |
=back |
| 153 |
|
| 154 |
=cut |