Debian Codegraph @

src/storage/emc/xtremio/restapi/mode/storagecontrollers.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::emc::xtremio::restapi::mode::storagecontrollers;
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
29 sub custom_service_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "health: %s",
34 $self->{result_values}->{health}
35 );
36 }
37
38 sub sc_long_output {
39 my ($self, %options) = @_;
40
41 return "checking storage controller '" . $options{instance} . "'";
42 }
43
44 sub prefix_sc_output {
45 my ($self, %options) = @_;
46
47 return "storage controller '" . $options{instance} . "' ";
48 }
49
50 sub prefix_indicator_output {
51 my ($self, %options) = @_;
52
53 return "indicator '" . $options{instance_value}->{indicator} . "' ";
54 }
55
56 sub set_counters {
57 my ($self, %options) = @_;
58
59 $self->{maps_counters_type} = [
60 { name => 'sc', type => 3, cb_prefix_output => 'prefix_sc_output', cb_long_output => 'sc_long_output',
61 indent_long_output => ' ', message_multiple => 'All storage controllers are ok',
62 group => [
63 { name => 'indicators', display_long => 1, cb_prefix_output => 'prefix_indicator_output', message_multiple => 'All health indicators are ok', type => 1, skipped_code => { -10 => 1 } }
64 ]
65 }
66 ];
67
68 $self->{maps_counters}->{indicators} = [
69 {
70 label => 'health-indicator',
71 type => 2,
72 critical_default => '%{health} !~ /healthy|normal|level_1_clear/i',
73 set => {
74 key_values => [ { name => 'health' }, { name => 'indicator' } ],
75 closure_custom_output => $self->can('custom_service_status_output'),
76 closure_custom_perfdata => sub { return 0; },
77 closure_custom_threshold_check => \&catalog_status_threshold_ng
78 }
79 }
80 ];
81 }
82
83 sub new {
84 my ($class, %options) = @_;
85 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
86 bless $self, $class;
87
88 $options{options}->add_options(arguments => {
89 'filter-name:s' => { name => 'filter_name' }
90 });
91
92 return $self;
93 }
94
95 sub manage_selection {
96 my ($self, %options) = @_;
97
98 my $urlbase = '/api/json/types/';
99 my @items = $options{custom}->get_items(
100 url => $urlbase,
101 obj => 'storage-controllers'
102 );
103
104 my @indicators = (
105 'dimm-health-state','node-health-state','current-health-state', 'journal-state', 'temperature-health-state', 'fan-health-state',
106 'node-fp-temperature-state', 'sas1-port-health-state', 'sas2-port-health-state'
107 );
108
109 $self->{sc} = {};
110 foreach my $item (@items) {
111 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
112 $item !~ /$self->{option_results}->{filter_name}/) {
113 $self->{output}->output_add(long_msg => "skipping storage controller '" . $item . "'.", debug => 1);
114 next;
115 }
116
117 my $details = $options{custom}->get_details(
118 url => $urlbase,
119 obj => 'storage-controllers',
120 name => $item
121 );
122
123 $self->{sc}->{$item} = { indicators => {} };
124 foreach (@indicators) {
125 next if (!defined($details->{$_}));
126
127 $self->{sc}->{$item}->{indicators}->{$_} = {
128 indicator => $_,
129 health => $details->{$_}
130 };
131 }
132 }
133 }
134
135 1;
136
137 __END__
138
139 =head1 MODE
140
141 Check storage controllers.
142
143 =over 8
144
145 =item B<--filter-name>
146
147 Filter storage controllers by name (can be a regexp).
148
149 =item B<--unknown-health-indicator>
150
151 Define the conditions to match for the status to be UNKNOWN.
152 You can use the following variables: %{health}, %{indicator}
153
154 =item B<--warning-health-indicator>
155
156 Define the conditions to match for the status to be WARNING.
157 You can use the following variables: %{health}, %{indicator}
158
159 =item B<--critical-health-indicator>
160
161 Define the conditions to match for the status to be CRITICAL (default: '%{health} !~ /done|normal|null/i').
162 You can use the following variables: %{health}, %{indicator}
163
164 =back
165
166 =cut