Debian Codegraph @

src/hardware/ats/apc/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::ats::apc::snmp::mode::outputlines;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'oline', type => 1, cb_prefix_output => 'prefix_line_output', message_multiple => 'All output lines are ok', skipped_code => { -10 => 1 } }
34 ];
35
36 $self->{maps_counters}->{oline} = [
37 { label => 'status', threshold => 0, set => {
38 key_values => [ { name => 'atsOutputPhaseState' }, { name => 'display' } ],
39 closure_custom_calc => $self->can('custom_status_calc'),
40 closure_custom_output => $self->can('custom_status_output'),
41 closure_custom_perfdata => sub { return 0; },
42 closure_custom_threshold_check => \&catalog_status_threshold,
43 }
44 },
45 { label => 'voltage', set => {
46 key_values => [ { name => 'atsOutputVoltage' }, { name => 'display' } ],
47 output_template => 'Voltage : %.2f V',
48 perfdatas => [
49 { label => 'voltage', value => 'atsOutputVoltage', template => '%s',
50 unit => 'V', label_extra_instance => 1, instance_use => 'display' },
51 ],
52 }
53 },
54 { label => 'current', set => {
55 key_values => [ { name => 'atsOutputCurrent' }, { name => 'display' } ],
56 output_template => 'Current : %.2f A',
57 perfdatas => [
58 { label => 'current', value => 'atsOutputCurrent', template => '%s',
59 unit => 'A', label_extra_instance => 1, instance_use => 'display' },
60 ],
61 }
62 },
63 { label => 'power', set => {
64 key_values => [ { name => 'atsOutputPower' }, { name => 'display' } ],
65 output_template => 'Power : %.2f W',
66 perfdatas => [
67 { label => 'power', value => 'atsOutputPower', template => '%s',
68 unit => 'W', label_extra_instance => 1, instance_use => 'display' },
69 ],
70 }
71 },
72 { label => 'load', set => {
73 key_values => [ { name => 'atsOutputLoad' }, { name => 'display' } ],
74 output_template => 'Load : %.2f VA',
75 perfdatas => [
76 { label => 'load', value => 'atsOutputLoad', template => '%s',
77 unit => 'VA', label_extra_instance => 1, instance_use => 'display' },
78 ],
79 }
80 },
81 { label => 'load-capacity', set => {
82 key_values => [ { name => 'atsOutputPercentLoad' }, { name => 'display' } ],
83 output_template => 'Load capacity : %.2f %%',
84 perfdatas => [
85 { label => 'load_capacity', value => 'atsOutputPercentLoad', template => '%s',
86 unit => '%', label_extra_instance => 1, instance_use => 'display', min => 0, max => 100 },
87 ],
88 }
89 },
90 ];
91 }
92
93 sub custom_status_output {
94 my ($self, %options) = @_;
95 my $msg = 'Status : ' . $self->{result_values}->{status};
96
97 return $msg;
98 }
99
100 sub custom_status_calc {
101 my ($self, %options) = @_;
102
103 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_atsOutputPhaseState'};
104 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
105 return 0;
106 }
107
108 sub prefix_line_output {
109 my ($self, %options) = @_;
110
111 return "Output Line '" . $options{instance_value}->{display} . "' ";
112 }
113
114 sub new {
115 my ($class, %options) = @_;
116 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
117 bless $self, $class;
118
119 $options{options}->add_options(arguments =>
120 {
121 "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /nearoverload/' },
122 "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /^(lowload|overload)$/' },
123 });
124
125 return $self;
126 }
127
128 sub check_options {
129 my ($self, %options) = @_;
130 $self->SUPER::check_options(%options);
131
132 $self->change_macros(macros => ['warning_status', 'critical_status']);
133 }
134
135 my %map_state = (1 => 'normal', 2 => 'lowload', 3 => 'nearoverload', 4 => 'overload');
136
137 my $mapping = {
138 atsOutputVoltage => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.3', factor => 1 },
139 atsOutputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.4', factor => 0.1 },
140 atsOutputLoad => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.7', factor => 1 },
141 atsOutputPercentLoad => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.10', factor => 1 },
142 atsOutputPower => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.13', factor => 1 },
143 atsOutputPhaseState => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.19', map => \%map_state },
144 };
145
146 my $oid_atsOutputPhaseEntry = '.1.3.6.1.4.1.318.1.1.8.5.4.3.1';
147
148 sub manage_selection {
149 my ($self, %options) = @_;
150
151 my $results = $options{snmp}->get_multiple_table(oids => [
152 { oid => $oid_atsOutputPhaseEntry },
153 ],
154 nothing_quit => 1);
155
156 $self->{oline} = {};
157 foreach my $oid (keys %{$results->{$oid_atsOutputPhaseEntry}}) {
158 next if ($oid !~ /^$mapping->{atsOutputVoltage}->{oid}\.(\d+)\.(.*)$/);
159 my ($output_index, $phase_index) = ($1, $2);
160 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results->{$oid_atsOutputPhaseEntry}, instance => $output_index . '.' . $phase_index);
161
162 my $name = $output_index . '.' . $phase_index;
163 $self->{oline}->{$name} = { display => $name };
164 foreach (keys %{$mapping}) {
165 if (defined($mapping->{$_}->{factor})) {
166 $result->{$_} = undef if (defined($result->{$_}) && $result->{$_} == -1);
167 $result->{$_} *= $mapping->{$_}->{factor} if (defined($result->{$_}));
168 }
169 $self->{oline}->{$name}->{$_} = $result->{$_};
170 }
171 }
172 }
173
174 1;
175
176 __END__
177
178 =head1 MODE
179
180 Check output phase metrics.
181
182 =over 8
183
184 =item B<--filter-counters>
185
186 Only display some counters (regexp can be used).
187 Example: --filter-counters='^power$'
188
189 =item B<--warning-*>
190
191 Warning threshold.
192 Can be: 'voltage', 'current', 'power', 'load', 'load-capacity'.
193
194 =item B<--critical-*>
195
196 Critical threshold.
197 Can be: 'voltage', 'current', 'power', 'load', 'load-capacity'.
198
199 =item B<--warning-status>
200
201 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /nearoverload/').
202 You can use the following variables: %{status}, %{display}
203
204 =item B<--critical-status>
205
206 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /^(lowload|overload)$/').
207 You can use the following variables: %{status}, %{display}
208
209 =back
210
211 =cut