Debian Codegraph @

src/hardware/ats/apc/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::ats::apc::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 => 'input', type => 1, cb_prefix_output => 'prefix_line_output', message_multiple => 'All input lines are ok', skipped_code => { -10 => 1 } }
33 ];
34
35 $self->{maps_counters}->{input} = [
36 { label => 'voltage', set => {
37 key_values => [ { name => 'atsInputVoltage' }, { name => 'display' } ],
38 output_template => 'Voltage : %.2f V',
39 perfdatas => [
40 { label => 'voltage', value => 'atsInputVoltage', template => '%s',
41 unit => 'V', label_extra_instance => 1, instance_use => 'display' },
42 ],
43 }
44 },
45 { label => 'current', set => {
46 key_values => [ { name => 'atsInputCurrent' }, { name => 'display' } ],
47 output_template => 'Current : %.2f A',
48 perfdatas => [
49 { label => 'current', value => 'atsInputCurrent', template => '%s',
50 unit => 'A', label_extra_instance => 1, instance_use => 'display' },
51 ],
52 }
53 },
54 { label => 'power', set => {
55 key_values => [ { name => 'atsInputPower' }, { name => 'display' } ],
56 output_template => 'Power : %.2f W',
57 perfdatas => [
58 { label => 'power', value => 'atsInputPower', template => '%s',
59 unit => 'W', label_extra_instance => 1, instance_use => 'display' },
60 ],
61 }
62 },
63 ];
64 }
65
66 sub prefix_line_output {
67 my ($self, %options) = @_;
68
69 return "Input Line '" . $options{instance_value}->{display} . "' ";
70 }
71
72 sub new {
73 my ($class, %options) = @_;
74 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
75 bless $self, $class;
76
77 $options{options}->add_options(arguments =>
78 {
79 });
80
81 return $self;
82 }
83
84 my $mapping = {
85 atsInputVoltage => { oid => '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.3' },
86 atsInputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.6' },
87 atsInputPower => { oid => '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.9' },
88 };
89 my $mapping2 = {
90 atsInputName => { oid => '.1.3.6.1.4.1.318.1.1.8.5.3.2.1.6' },
91 };
92 my $oid_atsInputPhaseEntry = '.1.3.6.1.4.1.318.1.1.8.5.3.3.1';
93
94 sub manage_selection {
95 my ($self, %options) = @_;
96
97 my $results = $options{snmp}->get_multiple_table(oids => [
98 { oid => $oid_atsInputPhaseEntry },
99 { oid => $mapping2->{atsInputName}->{oid} },
100 ],
101 nothing_quit => 1);
102
103 $self->{input} = {};
104 foreach my $oid (keys %{$results->{$oid_atsInputPhaseEntry}}) {
105 next if ($oid !~ /^$mapping->{atsInputVoltage}->{oid}\.(\d+)\.(.*)$/);
106 my ($input_index, $phase_index) = ($1, $2);
107 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results->{$oid_atsInputPhaseEntry}, instance => $input_index . '.' . $phase_index);
108 my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $results->{$mapping2->{atsInputName}->{oid}}, instance => $input_index);
109
110 my $name = defined($result2->{atsInputName}) && $result2->{atsInputName} ne '' ? $result2->{atsInputName} : $input_index;
111 $name .= '.' . $phase_index;
112 $self->{input}->{$name} = { display => $name };
113 foreach (keys %{$mapping}) {
114 $result->{$_} = undef if (defined($result->{$_}) && $result->{$_} == -1);
115 $self->{input}->{$name}->{$_} = $result->{$_};
116 }
117 }
118 }
119
120 1;
121
122 __END__
123
124 =head1 MODE
125
126 Check input phase metrics (voltage, current and power).
127
128 =over 8
129
130 =item B<--filter-counters>
131
132 Only display some counters (regexp can be used).
133 Example: --filter-counters='^power$'
134
135 =item B<--warning-*>
136
137 Warning threshold.
138 Can be: 'voltage', 'current', 'power'.
139
140 =item B<--critical-*>
141
142 Critical threshold.
143 Can be: 'voltage', 'current', 'power'.
144
145 =back
146
147 =cut