Debian Codegraph @

src/storage/huawei/oceanstor/snmp/mode/controllers.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 storage::huawei::oceanstor::snmp::mode::controllers;
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_ng);
28 use storage::huawei::oceanstor::snmp::mode::resources qw($health_status $running_status);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'health status: %s [running status: %s]',
35 $self->{result_values}->{health_status},
36 $self->{result_values}->{running_status}
37 );
38 }
39
40 sub ctrl_long_output {
41 my ($self, %options) = @_;
42
43 return sprintf(
44 "checking controller '%s'",
45 $options{instance_value}->{id}
46 );
47 }
48
49 sub prefix_ctrl_output {
50 my ($self, %options) = @_;
51
52 return sprintf(
53 "controller '%s' ",
54 $options{instance_value}->{id}
55 );
56 }
57
58 sub set_counters {
59 my ($self, %options) = @_;
60
61 $self->{maps_counters_type} = [
62 { name => 'controllers', type => 3, cb_prefix_output => 'prefix_ctrl_output', cb_long_output => 'ctrl_long_output',
63 indent_long_output => ' ', message_multiple => 'All controllers are ok',
64 group => [
65 { name => 'status', type => 0, skipped_code => { -10 => 1 } },
66 { name => 'cpu', type => 0, skipped_code => { -10 => 1 } },
67 { name => 'memory', type => 0, skipped_code => { -10 => 1 } }
68 ]
69 }
70 ];
71
72 $self->{maps_counters}->{status} = [
73 {
74 label => 'status',
75 type => 2,
76 warning_default => '%{health_status} =~ /degraded|partially broken/i',
77 critical_default => '%{health_status} =~ /fault|fail/i',
78 set => {
79 key_values => [ { name => 'health_status' }, { name => 'running_status' }, { name => 'id' } ],
80 closure_custom_output => $self->can('custom_status_output'),
81 closure_custom_perfdata => sub { return 0; },
82 closure_custom_threshold_check => \&catalog_status_threshold_ng
83 }
84 }
85 ];
86
87 $self->{maps_counters}->{cpu} = [
88 { label => 'cpu-utilization', nlabel => 'controller.cpu.utilization.percentage', set => {
89 key_values => [ { name => 'cpu_usage' } ],
90 output_template => 'cpu usage: %.2f %%',
91 perfdatas => [
92 { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
93 ]
94 }
95 }
96 ];
97
98 $self->{maps_counters}->{memory} = [
99 { label => 'memory-usage', nlabel => 'controller.memory.usage.percentage', set => {
100 key_values => [ { name => 'memory_usage' } ],
101 output_template => 'memory used: %.2f %%',
102 output_change_bytes => 1,
103 perfdatas => [
104 { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
105 ]
106 }
107 }
108 ];
109 }
110
111 sub new {
112 my ($class, %options) = @_;
113 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
114 bless $self, $class;
115
116 $options{options}->add_options(arguments => {
117 'filter-id:s' => { name => 'filter_id' }
118 });
119
120 return $self;
121 }
122
123 my $mapping = {
124 health_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.2.1.2', map => $health_status }, # hwInfoControllerHealthStatus
125 running_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.2.1.3', map => $running_status }, # hwInfoControllerRunningStatus
126 cpu_usage => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.2.1.8' }, # hwInfoControllerCPUUsage
127 memory_usage => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.2.1.9' }, # hwInfoControllerMemoryUsage
128 };
129
130 sub manage_selection {
131 my ($self, %options) = @_;
132
133 my $oid_controller_id = '.1.3.6.1.4.1.34774.4.1.23.5.2.1.1'; # hwInfoControllerID
134 my $snmp_result = $options{snmp}->get_table(
135 oid => $oid_controller_id,
136 nothing_quit => 1
137 );
138
139 $self->{controllers} = {};
140 foreach (keys %$snmp_result) {
141 /^$oid_controller_id\.(.*)$/;
142 my $instance = $1;
143
144 if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' &&
145 $snmp_result->{$_} !~ /$self->{option_results}->{filter_id}/) {
146 $self->{output}->output_add(long_msg => "skipping controller '" . $snmp_result->{$_} . "'.", debug => 1);
147 next;
148 }
149
150 $self->{controllers}->{ $snmp_result->{$_} } = {
151 id => $snmp_result->{$_},
152 instance => $instance
153 };
154 }
155
156 return if (scalar(keys %{$self->{controllers}}) <= 0);
157
158 $options{snmp}->load(
159 oids => [ map($_->{oid}, values(%$mapping)) ],
160 instances => [ map($_->{instance}, values(%{$self->{controllers}})) ],
161 instance_regexp => '^(.*)$'
162 );
163 $snmp_result = $options{snmp}->get_leef();
164 foreach (keys %{$self->{controllers}}) {
165 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{controllers}->{$_}->{instance});
166
167 $self->{controllers}->{$_}->{memory} = { memory_usage => $result->{memory_usage} };
168 $self->{controllers}->{$_}->{cpu} = { cpu_usage => $result->{cpu_usage} };
169 $self->{controllers}->{$_}->{status} = {
170 running_status => $result->{running_status},
171 health_status => $result->{health_status},
172 id => $_
173 };
174 }
175 }
176
177 1;
178
179 __END__
180
181 =head1 MODE
182
183 Check controllers.
184
185 =over 8
186
187 =item B<--filter-id>
188
189 Filter controller by ID (can be a regexp).
190
191 =item B<--unknown-status>
192
193 Define the conditions to match for the status to be UNKNOWN.
194 You can use the following variables: %{health_status}, %{running_status}, %{id}
195
196 =item B<--warning-status>
197
198 Define the conditions to match for the status to be WARNING (default: '%{health_status} =~ /degraded|partially broken/i').
199 You can use the following variables: %{health_status}, %{running_status}, %{id}
200
201 =item B<--critical-status>
202
203 Define the conditions to match for the status to be CRITICAL (default: '%{health_status} =~ /fault|fail/i').
204 You can use the following variables: %{health_status}, %{running_status}, %{id}
205
206 =item B<--warning-*> B<--critical-*>
207
208 Thresholds.
209 Can be: 'cpu-utilization', 'memory-usage'.
210
211 =back
212
213 =cut