| 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::alcatel::oxe::snmp::mode::pbxrole; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
my $thresholds = { |
| 29 |
role => [ |
| 30 |
['indeterminate', 'UNKNOWN'], |
| 31 |
['main', 'OK'], |
| 32 |
['stand-by', 'OK'], |
| 33 |
['inactive-pcs', 'OK'], |
| 34 |
['active-pcs', 'WARNING'] |
| 35 |
] |
| 36 |
}; |
| 37 |
my %map_role = ( |
| 38 |
0 => 'indeterminate', |
| 39 |
1 => 'main', |
| 40 |
2 => 'stand-by', |
| 41 |
3 => 'active-pcs', |
| 42 |
4 => 'inactive-pcs', |
| 43 |
); |
| 44 |
|
| 45 |
sub new { |
| 46 |
my ($class, %options) = @_; |
| 47 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 48 |
bless $self, $class; |
| 49 |
|
| 50 |
$options{options}->add_options(arguments => { |
| 51 |
'threshold-overload:s@' => { name => 'threshold_overload' }, |
| 52 |
}); |
| 53 |
|
| 54 |
return $self; |
| 55 |
} |
| 56 |
|
| 57 |
sub check_options { |
| 58 |
my ($self, %options) = @_; |
| 59 |
$self->SUPER::init(%options); |
| 60 |
|
| 61 |
$self->{overload_th} = {}; |
| 62 |
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { |
| 63 |
if ($val !~ /^(.*?),(.*?),(.*)$/) { |
| 64 |
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); |
| 65 |
$self->{output}->option_exit(); |
| 66 |
} |
| 67 |
my ($section, $status, $filter) = ($1, $2, $3); |
| 68 |
if ($self->{output}->is_litteral_status(status => $status) == 0) { |
| 69 |
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); |
| 70 |
$self->{output}->option_exit(); |
| 71 |
} |
| 72 |
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); |
| 73 |
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
sub run { |
| 78 |
my ($self, %options) = @_; |
| 79 |
$self->{snmp} = $options{snmp}; |
| 80 |
|
| 81 |
# Seems to have a bug to get '.0' |
| 82 |
my $oid_pbxRole = '.1.3.6.1.4.1.637.64.4400.1.4.0'; |
| 83 |
my $oid_pbxRole_buggy = '.1.3.6.1.4.1.637.64.4400.1.4'; |
| 84 |
my $result = $self->{snmp}->get_leef(oids => [$oid_pbxRole, $oid_pbxRole_buggy], nothing_quit => 1); |
| 85 |
|
| 86 |
my $pbx_role = defined($result->{$oid_pbxRole}) ? $map_role{$result->{$oid_pbxRole}} : $map_role{$result->{$oid_pbxRole_buggy}}; |
| 87 |
my $exit = $self->get_severity(section => 'role', value => $pbx_role); |
| 88 |
$self->{output}->output_add(severity => $exit, |
| 89 |
short_msg => sprintf("PBX Role is '%s'", $pbx_role)); |
| 90 |
|
| 91 |
$self->{output}->display(); |
| 92 |
$self->{output}->exit(); |
| 93 |
} |
| 94 |
|
| 95 |
sub get_severity { |
| 96 |
my ($self, %options) = @_; |
| 97 |
my $status = 'UNKNOWN'; # default |
| 98 |
|
| 99 |
if (defined($self->{overload_th}->{$options{section}})) { |
| 100 |
foreach (@{$self->{overload_th}->{$options{section}}}) { |
| 101 |
if ($options{value} =~ /$_->{filter}/i) { |
| 102 |
$status = $_->{status}; |
| 103 |
return $status; |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
foreach (@{$thresholds->{$options{section}}}) { |
| 108 |
if ($options{value} =~ /$$_[0]/i) { |
| 109 |
$status = $$_[1]; |
| 110 |
return $status; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
return $status; |
| 115 |
} |
| 116 |
|
| 117 |
1; |
| 118 |
|
| 119 |
__END__ |
| 120 |
|
| 121 |
=head1 MODE |
| 122 |
|
| 123 |
Check PBX Role. |
| 124 |
|
| 125 |
=over 8 |
| 126 |
|
| 127 |
=item B<--threshold-overload> |
| 128 |
|
| 129 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,status,regexp). |
| 130 |
Example: --threshold-overload='role,CRITICAL,^(?!(main)$)' |
| 131 |
|
| 132 |
=back |
| 133 |
|
| 134 |
=cut |