Debian Codegraph @

src/hardware/ups/powerware/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::powerware::snmp::mode::outputlines;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub prefix_oline_output {
29 my ($self, %options) = @_;
30
31 return "Output 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 => 'oline', type => 1, cb_prefix_output => 'prefix_oline_output', message_multiple => 'All output lines are ok', skipped_code => { -10 => 1 } },
40 ];
41
42 $self->{maps_counters}->{global} = [
43 { label => 'load', nlabel => 'lines.output.load.percentage', set => {
44 key_values => [ { name => 'xupsOutputLoad', no_value => -1 } ],
45 output_template => 'Load : %.2f %%',
46 perfdatas => [
47 { template => '%.2f', min => 0, max => 100 }
48 ]
49 }
50 },
51 { label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => {
52 key_values => [ { name => 'xupsOutputFrequency', no_value => 0 } ],
53 output_template => 'Frequence : %.2f Hz',
54 perfdatas => [
55 { template => '%.2f', unit => 'Hz' }
56 ]
57 }
58 }
59 ];
60
61 $self->{maps_counters}->{oline} = [
62 { label => 'current', nlabel => 'line.output.current.ampere', set => {
63 key_values => [ { name => 'xupsOutputCurrent', no_value => 0 } ],
64 output_template => 'Current : %.2f A',
65 perfdatas => [
66 { template => '%.2f', min => 0, unit => 'A', label_extra_instance => 1 }
67 ]
68 }
69 },
70 { label => 'voltage', nlabel => 'line.output.voltage.volt', set => {
71 key_values => [ { name => 'xupsOutputVoltage', no_value => 0 } ],
72 output_template => 'Voltage : %.2f V',
73 perfdatas => [
74 { template => '%.2f', unit => 'V', label_extra_instance => 1 }
75 ]
76 }
77 },
78 { label => 'power', nlabel => 'line.output.power.watt', set => {
79 key_values => [ { name => 'xupsOutputWatts', no_value => 0 } ],
80 output_template => 'Power: %.2f W',
81 perfdatas => [
82 { template => '%.2f', unit => 'W', label_extra_instance => 1 }
83 ]
84 }
85 }
86 ];
87 }
88
89 sub new {
90 my ($class, %options) = @_;
91 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
92 bless $self, $class;
93
94 $options{options}->add_options(arguments => {
95 });
96
97 return $self;
98 }
99
100 my $mapping = {
101 xupsOutputVoltage => { oid => '.1.3.6.1.4.1.534.1.4.4.1.2' }, # in V
102 xupsOutputCurrent => { oid => '.1.3.6.1.4.1.534.1.4.4.1.3' }, # in A
103 xupsOutputWatts => { oid => '.1.3.6.1.4.1.534.1.4.4.1.4' } # in W
104 };
105 my $mapping2 = {
106 xupsOutputLoad => { oid => '.1.3.6.1.4.1.534.1.4.1' }, # in %
107 xupsOutputFrequency => { oid => '.1.3.6.1.4.1.534.1.4.2' } # in dHZ
108 };
109
110 my $oid_xupsOutput = '.1.3.6.1.4.1.534.1.4';
111 my $oid_xupsOutputEntry = '.1.3.6.1.4.1.534.1.4.4.1';
112
113 sub manage_selection {
114 my ($self, %options) = @_;
115
116 $self->{oline} = {};
117 my $snmp_result = $options{snmp}->get_table(
118 oid => $oid_xupsOutput,
119 nothing_quit => 1
120 );
121
122 foreach my $oid (keys %{$snmp_result}) {
123 next if ($oid !~ /^$oid_xupsOutputEntry\.\d+\.(.*)$/);
124 my $instance = $1;
125 next if (defined($self->{oline}->{$instance}));
126
127 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
128 $self->{oline}->{$instance} = { display => $instance, %$result };
129 }
130
131 if (scalar(keys %{$self->{oline}}) <= 0) {
132 $self->{output}->add_option_msg(short_msg => "No output lines found.");
133 $self->{output}->option_exit();
134 }
135
136 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => '0');
137
138 $result->{xupsOutputFrequency} = defined($result->{xupsOutputFrequency}) ? ($result->{xupsOutputFrequency} * 0.1) : 0;
139 $result->{xupsOutputLoad} = defined($result->{xupsOutputLoad}) ? $result->{xupsOutputLoad} : -1;
140 $self->{global} = { %$result };
141 }
142
143 1;
144
145 __END__
146
147 =head1 MODE
148
149 Check Output lines metrics (load, voltage, current and true power) (XUPS-MIB).
150
151 =over 8
152
153 =item B<--warning-*>
154
155 Warning threshold.
156 Can be: 'load', 'voltage', 'current', 'power'.
157 Load is a rate for X phase.
158
159 =item B<--critical-*>
160
161 Critical threshold.
162 Can be: 'load', 'voltage', 'current', 'power'.
163 Load is a rate for X phase.
164
165 =back
166
167 =cut