Debian Codegraph @

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