Debian Codegraph @

src/hardware/ups/hp/snmp/mode/inputlines.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::inputlines;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
33 { name => 'iline', type => 1, cb_prefix_output => 'prefix_iline_output', message_multiple => 'All input lines are ok', skipped_code => { -10 => 1 } },
34 ];
35
36 $self->{maps_counters}->{global} = [
37 { label => 'frequence', nlabel => 'lines.input.frequence.hertz', set => {
38 key_values => [ { name => 'upsInputFrequency', no_value => 0 } ],
39 output_template => 'frequence: %.2f Hz',
40 perfdatas => [
41 { value => 'upsInputFrequency', template => '%.2f',
42 unit => 'Hz' },
43 ],
44 }
45 },
46 ];
47
48 $self->{maps_counters}->{iline} = [
49 { label => 'current', nlabel => 'line.input.current.ampere', set => {
50 key_values => [ { name => 'upsInputCurrent', no_value => 0 } ],
51 output_template => 'current: %.2f A',
52 perfdatas => [
53 { value => 'upsInputCurrent', template => '%.2f',
54 min => 0, unit => 'A', label_extra_instance => 1 },
55 ],
56 }
57 },
58 { label => 'voltage', nlabel => 'line.input.voltage.volt', set => {
59 key_values => [ { name => 'upsInputVoltage', no_value => 0 } ],
60 output_template => 'voltage: %s V',
61 perfdatas => [
62 { value => 'upsInputVoltage', template => '%s',
63 unit => 'V', label_extra_instance => 1 },
64 ],
65 }
66 },
67 { label => 'power', nlabel => 'line.input.power.watt', set => {
68 key_values => [ { name => 'upsInputWatts', no_value => 0 } ],
69 output_template => 'power: %s W',
70 perfdatas => [
71 { value => 'upsInputWatts', template => '%s',
72 unit => 'W', label_extra_instance => 1 },
73 ],
74 }
75 },
76 ];
77 }
78
79 sub new {
80 my ($class, %options) = @_;
81 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
82 bless $self, $class;
83
84 $options{options}->add_options(arguments => {
85 });
86
87 return $self;
88 }
89
90 sub prefix_iline_output {
91 my ($self, %options) = @_;
92
93 return "Input Line '" . $options{instance_value}->{display} . "' ";
94 }
95
96 my $mapping = {
97 upsInputVoltage => { oid => '.1.3.6.1.4.1.232.165.3.3.4.1.2' }, # in V
98 upsInputCurrent => { oid => '.1.3.6.1.4.1.232.165.3.3.4.1.3' }, # in A
99 upsInputWatts => { oid => '.1.3.6.1.4.1.232.165.3.3.4.1.4' }, # in W
100 };
101 my $mapping2 = {
102 upsInputFrequency => { oid => '.1.3.6.1.4.1.232.165.3.3.1' }, # in dHZ
103 };
104 my $mapping3 = {
105 upsConfigLowOutputVoltageLimit => { oid => '.1.3.6.1.4.1.232.165.3.9.6' },
106 upsConfigHighOutputVoltageLimit => { oid => '.1.3.6.1.4.1.232.165.3.9.7' },
107 };
108
109 my $oid_upsInputEntry = '.1.3.6.1.4.1.232.165.3.3.4.1';
110 my $oid_upsConfig = '.1.3.6.1.4.1.232.165.3.9';
111
112 sub manage_selection {
113 my ($self, %options) = @_;
114
115 my $snmp_result = $options{snmp}->get_multiple_table(
116 oids => [
117 { oid => $mapping2->{upsInputFrequency}->{oid} },
118 { oid => $oid_upsInputEntry },
119 { oid => $oid_upsConfig, start => $mapping3->{upsConfigLowOutputVoltageLimit}->{oid}, end => $mapping3->{upsConfigHighOutputVoltageLimit}->{oid} },
120 ],
121 return_type => 1,
122 nothing_quit => 1
123 );
124
125 $self->{iline} = {};
126 foreach my $oid (keys %{$snmp_result}) {
127 next if ($oid !~ /^$oid_upsInputEntry\.\d+\.(.*)$/);
128 my $instance = $1;
129 next if (defined($self->{iline}->{$instance}));
130
131 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
132 $result->{upsInputCurrent} = 0 if (defined($result->{upsInputCurrent}) && $result->{upsInputCurrent} eq '');
133 $self->{iline}->{$instance} = { display => $instance, %$result };
134 }
135
136 if (scalar(keys %{$self->{iline}}) <= 0) {
137 $self->{output}->add_option_msg(short_msg => "No input lines found.");
138 $self->{output}->option_exit();
139 }
140
141 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => '0');
142 $result->{upsInputFrequency} = defined($result->{upsInputFrequency}) ? ($result->{upsInputFrequency} * 0.1) : 0;
143 $self->{global} = { %$result };
144
145 $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result, instance => '0');
146 if ((!defined($self->{option_results}->{'warning-instance-line-input-voltage-volt'}) || $self->{option_results}->{'warning-instance-line-input-voltage-volt'} eq '') &&
147 (!defined($self->{option_results}->{'critical-instance-line-input-voltage-volt'}) || $self->{option_results}->{'critical-instance-line-input-voltage-volt'} eq '')
148 ) {
149 my $th = '';
150 $th .= $result->{upsConfigHighOutputVoltageLimit} if (defined($result->{upsConfigHighOutputVoltageLimit}) && $result->{upsConfigHighOutputVoltageLimit} =~ /\d+/);
151 $th = $result->{upsConfigLowOutputVoltageLimit} . ':' . $th if (defined($result->{upsConfigLowOutputVoltageLimit}) && $result->{upsConfigLowOutputVoltageLimit} =~ /\d+/);
152 $self->{perfdata}->threshold_validate(label => 'critical-instance-line-input-voltage-volt', value => $th) if ($th ne '');
153 }
154 }
155
156 1;
157
158 __END__
159
160 =head1 MODE
161
162 Check input lines metrics.
163
164 =over 8
165
166 =item B<--warning-*> B<--critical-*>
167
168 Thresholds.
169 Can be: 'frequence', 'voltage', 'current', 'power'.
170
171 =back
172
173 =cut