Debian Codegraph @

src/hardware/devices/aeg/acm/snmp/mode/rectifierstatus.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::devices::aeg::acm::snmp::mode::rectifierstatus;
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 custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf("status is '%s'", $self->{result_values}->{status});
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_rectState'};
40 return 0;
41 }
42
43 sub prefix_rect_output {
44 my ($self, %options) = @_;
45
46 return "Rectifier '" . $options{instance_value}->{display} . "' ";
47 }
48
49 sub set_counters {
50 my ($self, %options) = @_;
51
52 $self->{maps_counters_type} = [
53 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
54 { name => 'rect', type => 1, cb_prefix_output => 'prefix_rect_output', message_multiple => 'All rectifiers are ok', skipped_code => { -10 => 1 } },
55 ];
56
57 $self->{maps_counters}->{global} = [
58 { label => 'voltage', set => {
59 key_values => [ { name => 'rectVoltage' } ],
60 output_template => 'Voltage : %s V',
61 perfdatas => [
62 { label => 'voltage', value => 'rectVoltage', template => '%s',
63 unit => 'V' },
64 ],
65 }
66 },
67 { label => 'current', set => {
68 key_values => [ { name => 'rectCurrent' } ],
69 output_template => 'Current : %s A',
70 perfdatas => [
71 { label => 'current', value => 'rectCurrent', template => '%s',
72 min => 0, unit => 'A' },
73 ],
74 }
75 },
76 { label => 'faulty-count', set => {
77 key_values => [ { name => 'nbrOfFaultyRect' } ],
78 output_template => 'Faulty rectifiers : %s',
79 perfdatas => [
80 { label => 'faulty_count', value => 'nbrOfFaultyRect', template => '%s',
81 min => 0, unit => '' },
82 ],
83 }
84 },
85 ];
86
87 $self->{maps_counters}->{rect} = [
88 { label => 'status', threshold => 0, set => {
89 key_values => [ { name => 'rectState' }, { name => 'display' } ],
90 closure_custom_calc => $self->can('custom_status_calc'),
91 closure_custom_output => $self->can('custom_status_output'),
92 closure_custom_perfdata => sub { return 0; },
93 closure_custom_threshold_check => \&catalog_status_threshold,
94 }
95 },
96 ];
97 }
98
99 sub new {
100 my ($class, %options) = @_;
101 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
102 bless $self, $class;
103
104 $options{options}->add_options(arguments => {
105 "warning-status:s" => { name => 'warning_status', default => '' },
106 "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /ok|notInstalled/i' },
107 });
108
109 return $self;
110 }
111
112 sub check_options {
113 my ($self, %options) = @_;
114 $self->SUPER::check_options(%options);
115
116 $self->change_macros(macros => ['warning_status', 'critical_status']);
117 }
118
119 my %map_state = (
120 1 => 'ok',
121 255 => 'notInstalled',
122 );
123
124 my $mapping_acm1000 = {
125 rectVoltage => { oid => '.1.3.6.1.4.1.15416.37.2.1', divider => '100' },
126 rectCurrent => { oid => '.1.3.6.1.4.1.15416.37.2.2', divider => '100' },
127 nbrOfFaultyRect => { oid => '.1.3.6.1.4.1.15416.37.2.4' },
128 };
129 my $mapping_acmi1000 = {
130 rectVoltage => { oid => '.1.3.6.1.4.1.15416.38.2.1', divider => '100' },
131 rectCurrent => { oid => '.1.3.6.1.4.1.15416.38.2.2', divider => '100' },
132 nbrOfFaultyRect => { oid => '.1.3.6.1.4.1.15416.38.2.4' },
133 };
134 my $mapping_acm1d = {
135 rectState => { oid => '.1.3.6.1.4.1.15416.29.3.1.2' },
136 };
137 my $oid_acm1000DcPlant = '.1.3.6.1.4.1.15416.37.2';
138 my $oid_acmi1000DcPlant = '.1.3.6.1.4.1.15416.38.2';
139 my $oid_acm1dRectEntry = '.1.3.6.1.4.1.15416.29.3.1';
140
141 sub manage_selection {
142 my ($self, %options) = @_;
143
144 $self->{global} = {};
145 $self->{rect} = {};
146 $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_acm1000DcPlant },
147 { oid => $oid_acmi1000DcPlant },
148 { oid => $oid_acm1dRectEntry },
149 ],
150 nothing_quit => 1);
151
152 my $result_acm1000 = $options{snmp}->map_instance(mapping => $mapping_acm1000, results => $self->{results}->{$oid_acm1000DcPlant}, instance => '0');
153 my $result_acmi1000 = $options{snmp}->map_instance(mapping => $mapping_acmi1000, results => $self->{results}->{$oid_acmi1000DcPlant}, instance => '0');
154
155 foreach my $name (keys %{$mapping_acm1000}) {
156 if (defined($result_acm1000->{$name})) {
157 $self->{global}->{$name} = $result_acm1000->{$name};
158 $self->{global}->{$name} = $result_acm1000->{$name} / $mapping_acm1000->{$name}->{divider} if defined($mapping_acm1000->{$name}->{divider});
159 }
160 }
161 foreach my $name (keys %{$mapping_acmi1000}) {
162 if (defined($result_acmi1000->{$name})) {
163 $self->{global}->{$name} = $result_acmi1000->{$name};
164 $self->{global}->{$name} = $result_acmi1000->{$name} / $mapping_acmi1000->{$name}->{divider} if defined($mapping_acmi1000->{$name}->{divider});
165 }
166 }
167
168 foreach my $oid (keys %{$self->{results}->{$oid_acm1dRectEntry}}) {
169 next if ($oid !~ /^$mapping_acm1d->{rectState}->{oid}\.(.*)$/);
170 my $instance = $1;
171
172 $self->{rect}->{$instance} = {
173 rectState => $map_state{$self->{results}->{$oid_acm1dRectEntry}->{$mapping_acm1d->{rectState}->{oid} . '.' . $instance}},
174 display => $instance
175 };
176 }
177 }
178
179 1;
180
181 __END__
182
183 =head1 MODE
184
185 Check rectifiers status and statistics.
186
187 =over 8
188
189 =item B<--filter-counters>
190
191 Only display some counters (regexp can be used).
192 Example: --filter-counters='^status|current$'
193
194 =item B<--warning-status>
195
196 Define the conditions to match for the status to be WARNING (default: '').
197 You can use the following variables: %{status}
198
199 =item B<--critical-status>
200
201 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /ok|notInstalled/i').
202 You can use the following variables: %{status}
203
204 =item B<--warning-*>
205
206 Warning threshold.
207 Can be: 'voltage', 'current', 'faulty-count'.
208
209 =item B<--critical-*>
210
211 Critical threshold.
212 Can be: 'voltage', 'current', 'faulty-count'.
213
214 =back
215
216 =cut