Debian Codegraph @

src/hardware/ups/apc/snmp/mode/outputlines.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::apc::snmp::mode::outputlines;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf("output status is '%s'", $self->{result_values}->{status});
33 }
34
35 sub set_counters {
36 my ($self, %options) = @_;
37
38 $self->{maps_counters_type} = [
39 { name => 'global', type => 0, skipped_code => { -10 => 1 } }
40 ];
41
42 $self->{maps_counters}->{global} = [
43 {
44 label => 'status',
45 type => 2,
46 unknown_default => '%{status} =~ /unknown/i',
47 critical_default => '%{status} !~ /onLine|rebooting/i',
48 set => {
49 key_values => [ { name => 'status' } ],
50 closure_custom_output => $self->can('custom_status_output'),
51 closure_custom_perfdata => sub { return 0; },
52 closure_custom_threshold_check => \&catalog_status_threshold_ng
53 }
54 },
55 { label => 'load', nlabel => 'lines.output.load.percentage', set => {
56 key_values => [ { name => 'load' } ],
57 output_template => 'load: %s %%',
58 perfdatas => [
59 { template => '%s', min => 0, max => 100, unit => '%' }
60 ]
61 }
62 },
63 { label => 'current', nlabel => 'lines.output.current.ampere', set => {
64 key_values => [ { name => 'current' } ],
65 output_template => 'current: %s A',
66 perfdatas => [
67 { template => '%s', min => 0, unit => 'A' }
68 ]
69 }
70 },
71 { label => 'voltage', nlabel => 'lines.output.voltage.volt', set => {
72 key_values => [ { name => 'voltage' } ],
73 output_template => 'voltage: %s V',
74 perfdatas => [
75 { template => '%s', unit => 'V' }
76 ]
77 }
78 },
79 { label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => {
80 key_values => [ { name => 'frequency' } ],
81 output_template => 'frequence: %s Hz',
82 perfdatas => [
83 { template => '%s', unit => 'Hz' }
84 ]
85 }
86 }
87 ];
88 }
89
90 sub new {
91 my ($class, %options) = @_;
92 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
93 bless $self, $class;
94
95 $options{options}->add_options(arguments => {});
96
97 return $self;
98 }
99
100 my $map_status = {
101 1 => 'unknown', 2 => 'onLine', 3 => 'onBattery', 4 => 'onSmartBoost',
102 5 => 'timedSleeping', 6 => 'softwareBypass', 7 => 'off',
103 8 => 'rebooting', 9 => 'switchedBypass', 10 => 'hardwareFailureBypass',
104 11 => 'sleepingUntilPowerReturn', 12 => 'onSmartTrim'
105 };
106
107 my $mapping = {
108 upsBasicOutputStatus => { oid => '.1.3.6.1.4.1.318.1.1.1.4.1.1', map => $map_status },
109 upsAdvOutputVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.4.2.1' },
110 upsAdvOutputFrequency => { oid => '.1.3.6.1.4.1.318.1.1.1.4.2.2' },
111 upsAdvOutputLoad => { oid => '.1.3.6.1.4.1.318.1.1.1.4.2.3' },
112 upsAdvOutputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.1.4.2.4' },
113 upsHighPrecOutputVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.1' }, # tenths of VAC
114 upsHighPrecOutputFrequency => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.2' }, # tenths of Hz
115 upsHighPrecOutputLoad => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.3' }, # tenths of percent
116 upsHighPrecOutputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.1.4.3.4' } # tenths of amperes
117 };
118
119 sub manage_selection {
120 my ($self, %options) = @_;
121
122 my $snmp_result = $options{snmp}->get_leef(
123 oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
124 nothing_quit => 1
125 );
126
127 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
128 $self->{global} = {
129 status => $result->{upsBasicOutputStatus},
130 voltage => defined($result->{upsHighPrecOutputVoltage}) && $result->{upsHighPrecOutputVoltage} =~ /\d/ ?
131 $result->{upsHighPrecOutputVoltage} * 0.1 : $result->{upsAdvOutputVoltage},
132 frequency => defined($result->{upsHighPrecOutputFrequency}) && $result->{upsHighPrecOutputFrequency} =~ /\d/ ?
133 $result->{upsHighPrecOutputFrequency} * 0.1 : $result->{upsAdvOutputFrequency},
134 load => defined($result->{upsHighPrecOutputLoad}) && $result->{upsHighPrecOutputLoad} =~ /\d/ ?
135 $result->{upsHighPrecOutputLoad} * 0.1 : $result->{upsAdvOutputLoad},
136 current => defined($result->{upsHighPrecOutputCurrent}) && $result->{upsHighPrecOutputCurrent} =~ /\d/ ?
137 $result->{upsHighPrecOutputCurrent} * 0.1 : $result->{upsAdvOutputCurrent},
138 };
139 }
140
141 1;
142
143 __END__
144
145 =head1 MODE
146
147 Check output lines.
148
149 =over 8
150
151 =item B<--filter-counters>
152
153 Only display some counters (regexp can be used).
154 Example: --filter-counters='^status|load$'
155
156 =item B<--unknown-status>
157
158 Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i').
159 You can use the following variables: %{status}
160
161 =item B<--warning-status>
162
163 Define the conditions to match for the status to be WARNING (default: '').
164 You can use the following variables: %{status}
165
166 =item B<--critical-status>
167
168 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /onLine|rebooting/i').
169 You can use the following variables: %{status}
170
171 =item B<--warning-*> B<--critical-*>
172
173 Thresholds.
174 Can be: 'load', 'voltage', 'current', 'frequence'.
175
176 =back
177
178 =cut