Debian Codegraph @

src/hardware/ups/hp/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::hp::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 catalog_status_calc);
28
29 sub custom_source_output {
30 my ($self, %options) = @_;
31
32 return sprintf("output source is '%s'", $self->{result_values}->{source});
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 { name => 'oline', type => 1, cb_prefix_output => 'prefix_oline_output', message_multiple => 'All output lines are ok', skipped_code => { -10 => 1 } },
41 ];
42
43 $self->{maps_counters}->{global} = [
44 { label => 'source', threshold => 0, set => {
45 key_values => [ { name => 'source' } ],
46 closure_custom_calc => \&catalog_status_calc,
47 closure_custom_output => $self->can('custom_source_output'),
48 closure_custom_perfdata => sub { return 0; },
49 closure_custom_threshold_check => \&catalog_status_threshold,
50 }
51 },
52 { label => 'load', nlabel => 'lines.output.load.percentage', set => {
53 key_values => [ { name => 'upsOutputLoad', no_value => -1 } ],
54 output_template => 'load: %.2f %%',
55 perfdatas => [
56 { value => 'upsOutputLoad', template => '%.2f', min => 0, max => 100 },
57 ],
58 }
59 },
60 { label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => {
61 key_values => [ { name => 'upsOutputFrequency', no_value => 0 } ],
62 output_template => 'frequence: %.2f Hz',
63 perfdatas => [
64 { value => 'upsOutputFrequency', template => '%.2f', unit => 'Hz' },
65 ],
66 }
67 },
68 ];
69
70 $self->{maps_counters}->{oline} = [
71 { label => 'current', nlabel => 'line.output.current.ampere', set => {
72 key_values => [ { name => 'upsOutputCurrent', no_value => 0 } ],
73 output_template => 'current: %.2f A',
74 perfdatas => [
75 { value => 'upsOutputCurrent', template => '%.2f',
76 min => 0, unit => 'A', label_extra_instance => 1 },
77 ],
78 }
79 },
80 { label => 'voltage', nlabel => 'line.output.voltage.volt', set => {
81 key_values => [ { name => 'upsOutputVoltage', no_value => 0 } ],
82 output_template => 'voltage: %s V',
83 perfdatas => [
84 { value => 'upsOutputVoltage', template => '%s',
85 unit => 'V', label_extra_instance => 1 },
86 ],
87 }
88 },
89 { label => 'power', nlabel => 'line.output.power.watt', set => {
90 key_values => [ { name => 'upsOutputWatts', no_value => 0 } ],
91 output_template => 'power: %s W',
92 perfdatas => [
93 { value => 'upsOutputWatts', template => '%s',
94 unit => 'W', label_extra_instance => 1 },
95 ],
96 }
97 },
98 ];
99 }
100
101 sub prefix_oline_output {
102 my ($self, %options) = @_;
103
104 return "Output line '" . $options{instance_value}->{display} . "' ";
105 }
106
107 sub new {
108 my ($class, %options) = @_;
109 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
110 bless $self, $class;
111
112 $options{options}->add_options(arguments => {
113 'unknown-source:s' => { name => 'unknown_source', default => '' },
114 'warning-source:s' => { name => 'warning_source', default => '' },
115 'critical-source:s' => { name => 'critical_source', default => '%{source} !~ /normal/i' },
116 });
117
118 return $self;
119 }
120
121 sub check_options {
122 my ($self, %options) = @_;
123 $self->SUPER::check_options(%options);
124
125 $self->change_macros(macros => ['warning_source', 'critical_source', 'unknown_source']);
126 }
127
128 my $map_source = {
129 1 => 'other', 2 => 'none', 3 => 'normal',
130 4 => 'bypass', 5 => 'battery', 6 => 'booster',
131 7 => 'reducer', 8 => 'parallelCapacity',
132 9 => 'parallelRedundant', 10 => 'highEfficiencyMode',
133 };
134
135 my $mapping = {
136 upsOutputVoltage => { oid => '.1.3.6.1.4.1.232.165.3.4.4.1.2' }, # in V
137 upsOutputCurrent => { oid => '.1.3.6.1.4.1.232.165.3.4.4.1.3' }, # in A
138 upsOutputWatts => { oid => '.1.3.6.1.4.1.232.165.3.4.4.1.4' }, # in W
139 };
140 my $mapping2 = {
141 upsOutputLoad => { oid => '.1.3.6.1.4.1.232.165.3.4.1' }, # in %
142 upsOutputFrequency => { oid => '.1.3.6.1.4.1.232.165.3.4.2' }, # in dHZ
143 upsOutputSource => { oid => '.1.3.6.1.4.1.232.165.3.4.5', map => $map_source },
144 };
145
146 my $oid_upsOutput = '.1.3.6.1.4.1.232.165.3.4';
147 my $oid_upsOutputEntry = '.1.3.6.1.4.1.232.165.3.4.4.1';
148
149 sub manage_selection {
150 my ($self, %options) = @_;
151
152 $self->{oline} = {};
153 my $snmp_result = $options{snmp}->get_table(
154 oid => $oid_upsOutput,
155 nothing_quit => 1
156 );
157
158 foreach my $oid (keys %$snmp_result) {
159 next if ($oid !~ /^$oid_upsOutputEntry\.\d+\.(.*)$/);
160 my $instance = $1;
161 next if (defined($self->{oline}->{$instance}));
162
163 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
164 $self->{oline}->{$instance} = { display => $instance, %$result };
165 }
166
167 if (scalar(keys %{$self->{oline}}) <= 0) {
168 $self->{output}->add_option_msg(short_msg => "No output lines found.");
169 $self->{output}->option_exit();
170 }
171
172 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => '0');
173
174 $result->{upsOutputFrequency} = defined($result->{upsOutputFrequency}) ? ($result->{upsOutputFrequency} * 0.1) : 0;
175 $result->{upsOutputLoad} = defined($result->{upsOutputLoad}) ? $result->{upsOutputLoad} : -1;
176 $result->{source} = $result->{upsOutputSource};
177
178 $self->{global} = $result;
179 }
180
181 1;
182
183 __END__
184
185 =head1 MODE
186
187 Check output lines metrics.
188
189 =over 8
190
191 =item B<--unknown-source>
192
193 Define the conditions to match for the status to be UNKNOWN (default: '').
194 You can use the following variables: %{source}.
195
196 =item B<--warning-source>
197
198 Define the conditions to match for the status to be WARNING (default: '').
199 You can use the following variables: %{source}.
200
201 =item B<--critical-source>
202
203 Define the conditions to match for the status to be CRITICAL (default: '%{source} !~ /normal/i').
204 You can use the following variables: %{source}.
205
206 =item B<--warning-*> B<--critical-*>
207
208 Thresholds.
209 Can be: 'load', 'voltage', 'current', 'power'.
210
211 =back
212
213 =cut