Debian Codegraph @

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