Debian Codegraph @

src/hardware/ups/mge/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::mge::snmp::mode::outputlines;
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 => 'oline', type => 1, cb_prefix_output => 'prefix_oline_output', message_multiple => 'All output lines are ok', skipped_code => { -10 => 1 } },
34 ];
35
36 $self->{maps_counters}->{global} = [
37 { label => 'stdev-3phases', nlabel => 'output.3phases.stdev.gauge', set => {
38 key_values => [ { name => 'stdev' } ],
39 output_template => 'Load Standard Deviation : %.2f',
40 perfdatas => [
41 { label => 'stdev', value => 'stdev', template => '%.2f' },
42 ],
43 }
44 },
45 ];
46
47 $self->{maps_counters}->{oline} = [
48 { label => 'load', nlabel => 'line.output.load.percentage', set => {
49 key_values => [ { name => 'mgoutputLoadPerPhase', no_value => 0 } ],
50 output_template => 'Load : %.2f %%',
51 perfdatas => [
52 { value => 'mgoutputLoadPerPhase', template => '%.2f',
53 min => 0, max => 100, unit => '%', label_extra_instance => 1 },
54 ],
55 }
56 },
57 { label => 'current', nlabel => 'line.output.current.ampere', set => {
58 key_values => [ { name => 'mgoutputCurrent', no_value => 0 } ],
59 output_template => 'Current : %.2f A',
60 perfdatas => [
61 { value => 'mgoutputCurrent', template => '%.2f',
62 min => 0, unit => 'A', label_extra_instance => 1 },
63 ],
64 }
65 },
66 { label => 'voltage', nlabel => 'line.output.voltage.volt', set => {
67 key_values => [ { name => 'mgoutputVoltage', no_value => 0 } ],
68 output_template => 'Voltage : %.2f V',
69 perfdatas => [
70 { value => 'mgoutputVoltage', template => '%.2f',
71 unit => 'V', label_extra_instance => 1 },
72 ],
73 }
74 },
75 { label => 'frequence', nlabel => 'line.output.frequence.hertz', set => {
76 key_values => [ { name => 'mgoutputFrequency', no_value => -1 } ],
77 output_template => 'Frequence : %.2f Hz',
78 perfdatas => [
79 { value => 'mgoutputFrequency', template => '%.2f',
80 unit => 'Hz', label_extra_instance => 1 },
81 ],
82 }
83 },
84 ];
85 }
86
87 sub new {
88 my ($class, %options) = @_;
89 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
90 bless $self, $class;
91
92 $options{options}->add_options(arguments => {
93 });
94
95 return $self;
96 }
97
98 sub prefix_oline_output {
99 my ($self, %options) = @_;
100
101 return "Output Line '" . $options{instance_value}->{display} . "' ";
102 }
103
104 sub stdev {
105 my ($self, %options) = @_;
106
107 # Calculate stdev
108 my $total = 0;
109 my $num_present = scalar(keys %{$self->{oline}});
110 foreach my $instance (keys %{$self->{oline}}) {
111 next if (!defined($self->{oline}->{$instance}->{mgoutputLoadPerPhase}));
112 $total += $self->{oline}->{$instance}->{mgoutputLoadPerPhase};
113 }
114
115 my $mean = $total / $num_present;
116 $total = 0;
117 foreach my $instance (keys %{$self->{oline}}) {
118 next if (!defined($self->{oline}->{$instance}->{mgoutputLoadPerPhase}));
119 $total += ($mean - $self->{oline}->{$instance}->{mgoutputLoadPerPhase}) ** 2;
120 }
121 my $stdev = sqrt($total / $num_present);
122 $self->{global} = { stdev => $stdev };
123 }
124
125 my $mapping = {
126 mgoutputVoltage => { oid => '.1.3.6.1.4.1.705.1.7.2.1.2' }, # in dV
127 mgoutputFrequency => { oid => '.1.3.6.1.4.1.705.1.7.2.1.3' }, # in dHz
128 mgoutputLoadPerPhase => { oid => '.1.3.6.1.4.1.705.1.7.2.1.4' }, # in %
129 mgoutputCurrent => { oid => '.1.3.6.1.4.1.705.1.7.2.1.5' }, # in dA
130 };
131 my $oid_upsmgOutputPhaseEntry = '.1.3.6.1.4.1.705.1.7.2.1';
132
133 sub manage_selection {
134 my ($self, %options) = @_;
135
136 $self->{oline} = {};
137 my $snmp_result = $options{snmp}->get_table(
138 oid => $oid_upsmgOutputPhaseEntry,
139 nothing_quit => 1
140 );
141 foreach my $oid (keys %{$snmp_result}) {
142 $oid =~ /^$oid_upsmgOutputPhaseEntry\.\d+\.(.*)$/;
143 my $instance = $1;
144 next if (defined($self->{oline}->{$instance}));
145
146 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
147 $result->{mgoutputVoltage} *= 0.1 if (defined($result->{mgoutputVoltage}));
148 $result->{mgoutputFrequency} *= 0.1 if (defined($result->{mgoutputFrequency}));
149 $result->{mgoutputCurrent} *= 0.1 if (defined($result->{mgoutputCurrent}));
150 $self->{oline}->{$instance} = { display => $instance, %$result };
151 }
152
153 if (scalar(keys %{$self->{oline}}) > 1) {
154 $self->stdev();
155 }
156 }
157
158 1;
159
160 __END__
161
162 =head1 MODE
163
164 Check Output lines metrics (load, voltage, current).
165
166 =over 8
167
168 =item B<--warning-*>
169
170 Warning threshold.
171 Can be: 'load', 'voltage', 'current', 'frequence', 'stdev-3phases'.
172
173 =item B<--critical-*>
174
175 Critical threshold.
176 Can be: 'load', 'voltage', 'current', 'frequence', 'stdev-3phases'.
177
178 =back
179
180 =cut