Debian Codegraph @

src/hardware/ats/eaton/snmp/mode/system.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::eaton::snmp::mode::system;
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 = 'operation mode : ' . $self->{result_values}->{operation_mode};
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{operation_mode} = $options{new_datas}->{$self->{instance} . '_operation_mode'};
40 return 0;
41 }
42
43 sub set_counters {
44 my ($self, %options) = @_;
45
46 $self->{maps_counters_type} = [
47 { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } },
48 ];
49
50 $self->{maps_counters}->{global} = [
51 { label => 'status', threshold => 0, set => {
52 key_values => [ { name => 'operation_mode' } ],
53 closure_custom_calc => $self->can('custom_status_calc'),
54 closure_custom_output => $self->can('custom_status_output'),
55 closure_custom_perfdata => sub { return 0; },
56 closure_custom_threshold_check => \&catalog_status_threshold,
57 }
58 },
59 { label => 'temperature', nlabel => 'system.temperature.celsius', set => {
60 key_values => [ { name => 'temperature' } ],
61 output_template => 'temperature : %s C',
62 perfdatas => [
63 { label => 'temperature', value => 'temperature', template => '%s',
64 unit => 'C' },
65 ],
66 }
67 },
68 { label => 'humidity', nlabel => 'system.humidity.percentage', set => {
69 key_values => [ { name => 'humidity' } ],
70 output_template => 'humidity : %s %%',
71 perfdatas => [
72 { label => 'humidity', value => 'humidity', template => '%s',
73 unit => '%', min => 9, max => 100 },
74 ],
75 }
76 },
77 ];
78 }
79
80 sub new {
81 my ($class, %options) = @_;
82 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
83 bless $self, $class;
84
85 $options{options}->add_options(arguments => {
86 "unknown-status:s" => { name => 'unknown_status', default => '' },
87 "warning-status:s" => { name => 'warning_status', default => '' },
88 "critical-status:s" => { name => 'critical_status', default => '%{operation_mode} !~ /source1|source2/i' },
89 });
90
91 return $self;
92 }
93
94 sub check_options {
95 my ($self, %options) = @_;
96 $self->SUPER::check_options(%options);
97
98 $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
99 }
100
101 my $map_opmode = {
102 1 => 'initialization',
103 2 => 'diagnosis',
104 3 => 'off',
105 4 => 'source1',
106 5 => 'source2',
107 6 => 'safe',
108 7 => 'fault',
109 };
110 my $oid_ats2OperationMode = '.1.3.6.1.4.1.534.10.2.2.4.0';
111 my $oid_ats2EnvRemoteTemp = '.1.3.6.1.4.1.534.10.2.5.1.0';
112 my $oid_ats2EnvRemoteHumidity = '.1.3.6.1.4.1.534.10.2.5.2.0';
113 my $oid_atsMeasureTemperatureC = '.1.3.6.1.4.1.534.10.1.3.3.0';
114 my $oid_atsMessureOperationMode = '.1.3.6.1.4.1.534.10.1.3.7.0';
115
116 sub check_ats2 {
117 my ($self, %options) = @_;
118
119 return if (!defined($options{result}->{$oid_ats2OperationMode}));
120
121 $self->{global} = {
122 operation_mode => $map_opmode->{$options{result}->{$oid_ats2OperationMode}},
123 temperature => $options{result}->{$oid_ats2EnvRemoteTemp},
124 humidity => $options{result}->{$oid_ats2EnvRemoteHumidity}
125 };
126 }
127
128 sub check_ats {
129 my ($self, %options) = @_;
130
131 return if (defined($self->{global}));
132
133 $self->{global} = {
134 operation_mode => $map_opmode->{$options{result}->{$oid_atsMessureOperationMode}},
135 temperature => $options{result}->{$oid_atsMeasureTemperatureC},
136 };
137 }
138
139 sub manage_selection {
140 my ($self, %options) = @_;
141
142 my $snmp_result = $options{snmp}->get_leef(oids => [
143 $oid_ats2OperationMode, $oid_ats2EnvRemoteTemp, $oid_ats2EnvRemoteHumidity,
144 $oid_atsMeasureTemperatureC, $oid_atsMessureOperationMode,
145 ], nothing_quit => 1);
146 $self->check_ats2(result => $snmp_result);
147 $self->check_ats(result => $snmp_result);
148 }
149
150 1;
151
152 __END__
153
154 =head1 MODE
155
156 Check system (operation mode, temperature).
157
158 =over 8
159
160 =item B<--filter-counters>
161
162 Only display some counters (regexp can be used).
163 Example: --filter-counters='^status$'
164
165 =item B<--unknown-status>
166
167 Define the conditions to match for the status to be UNKNOWN (default: '').
168 You can use the following variables: operation_mode
169
170 =item B<--warning-status>
171
172 Define the conditions to match for the status to be WARNING (default: '').
173 You can use the following variables: operation_mode
174
175 =item B<--critical-status>
176
177 Define the conditions to match for the status to be CRITICAL (default: '%{operation_mode} !~ /source1|source2/i').
178 You can use the following variables: %{operation_mode}
179
180 =item B<--warning-*>
181
182 Warning threshold.
183 Can be: 'temperature', 'humidity'.
184
185 =item B<--critical-*>
186
187 Critical threshold.
188 Can be: 'temperature', 'humidity'.
189
190 =back
191
192 =cut