Debian Codegraph @

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