Debian Codegraph @

src/hardware/ups/socomec/netvision/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::socomec::netvision::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 => 'frequency', 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 => 'current', 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 => 'voltage', no_value => 0 } ],
64 output_template => 'voltage: %.2f V',
65 perfdatas => [
66 { template => '%.2f', unit => 'V', label_extra_instance => 1 }
67 ]
68 }
69 }
70 ];
71 }
72
73 sub new {
74 my ($class, %options) = @_;
75 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
76 bless $self, $class;
77
78 $options{options}->add_options(arguments => {
79 });
80
81 return $self;
82 }
83
84 my $mapping = {
85 netvision5 => {
86 voltage => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.3.3.1.2' }, # upsInputVoltage (dV)
87 current => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.3.3.1.3' } # upsInputCurrent (dA)
88 },
89 netvision6 => {
90 voltage => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.2' }, # upsInputVoltage (dV)
91 current => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.3' } # upsInputCurrent (dA)
92 }
93 };
94 my $mapping2 = {
95 netvision5 => {
96 frequency => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.3.2' } # upsInputFrequency (dHZ)
97 },
98 netvision6 => {
99 frequency => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.3.2' } # upsInputFrequency (dHZ)
100 }
101 };
102 my $tables = {
103 netvision5 => {
104 upsInput => '.1.3.6.1.4.1.4555.1.1.1.1.3',
105 upsInputEntry => '.1.3.6.1.4.1.4555.1.1.1.1.3.3.1'
106 },
107 netvision6 => {
108 upsInput => '.1.3.6.1.4.1.4555.1.1.7.1.3',
109 upsInputEntry => '.1.3.6.1.4.1.4555.1.1.7.1.3.3.1'
110 }
111 };
112
113 sub manage_selection {
114 my ($self, %options) = @_;
115
116 my $label = 'netvision6';
117 my $snmp_result = $options{snmp}->get_table(
118 oid => $tables->{$label}->{upsInput},
119 start => $mapping2->{$label}->{frequency}->{oid},
120 end => $mapping->{$label}->{current}->{oid}
121 );
122 if (scalar(keys %$snmp_result) <= 0) {
123 $label = 'netvision5';
124 $snmp_result = $options{snmp}->get_table(
125 oid => $tables->{$label}->{upsInput},
126 start => $mapping2->{$label}->{frequency}->{oid},
127 end => $mapping->{$label}->{current}->{oid},
128 nothing_quit => 1
129 );
130 }
131
132 $self->{iline} = {};
133 foreach my $oid (keys %$snmp_result) {
134 next if ($oid !~ /^$tables->{$label}->{upsInputEntry}\.\d+\.(.*)$/);
135 my $instance = $1;
136 next if (defined($self->{iline}->{$instance}));
137
138 my $result = $options{snmp}->map_instance(mapping => $mapping->{$label}, results => $snmp_result, instance => $instance);
139 foreach ('current', 'voltage') {
140 $result->{$_} = 0 if (defined($result->{$_}) && (
141 $result->{$_} eq '' || $result->{$_} == -1 || $result->{$_} == 65535 || $result->{$_} == 655350));
142 $result->{$_} *= 0.1;
143 }
144
145 $self->{iline}->{$instance} = {
146 display => $instance,
147 %$result
148 };
149 }
150
151 if (scalar(keys %{$self->{iline}}) <= 0) {
152 $self->{output}->add_option_msg(short_msg => "No input lines found.");
153 $self->{output}->option_exit();
154 }
155
156 $self->{global} = $options{snmp}->map_instance(mapping => $mapping2->{$label}, results => $snmp_result, instance => 0);
157 $self->{global}->{frequency} = defined($self->{global}->{frequency}) && $self->{global}->{frequency} != -1 && $self->{global}->{frequency} != 65535
158 ? ($self->{global}->{frequency} * 0.1) : 0;
159 }
160
161 1;
162
163 __END__
164
165 =head1 MODE
166
167 Check Input lines metrics (frequence, voltage, current).
168
169 =over 8
170
171 =item B<--warning-*> B<--critical-*>
172
173 Thresholds.
174 Can be: 'frequence', 'voltage', 'current'.
175
176 =back
177
178 =cut