Debian Codegraph @

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