Debian Codegraph @

src/storage/emc/xtremio/restapi/mode/dpg.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::dpg;
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 dpg_long_output {
39 my ($self, %options) = @_;
40
41 return "checking data protection group '" . $options{instance} . "'";
42 }
43
44 sub prefix_dpg_output {
45 my ($self, %options) = @_;
46
47 return "data protection group '" . $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 => 'dpg', type => 3, cb_prefix_output => 'prefix_dpg_output', cb_long_output => 'dpg_long_output',
61 indent_long_output => ' ', message_multiple => 'All data protection groups 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} !~ /done|normal|null/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 => 'data-protection-groups'
102 );
103
104 my @indicators = ('dpg-state', 'protection-state', 'rebuild-in-progress', 'ssd-preparation-in-progress', 'rebalance-progress');
105
106 $self->{dpg} = {};
107 foreach my $item (@items) {
108 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
109 $item !~ /$self->{option_results}->{filter_name}/) {
110 $self->{output}->output_add(long_msg => "skipping dpg '" . $item . "'.", debug => 1);
111 next;
112 }
113
114 my $details = $options{custom}->get_details(
115 url => $urlbase,
116 obj => 'data-protection-groups',
117 name => $item
118 );
119
120 $self->{dpg}->{$item} = { indicators => {} };
121 foreach (@indicators) {
122 next if (!defined($details->{$_}));
123
124 $self->{dpg}->{$item}->{indicators}->{$_} = {
125 indicator => $_,
126 health => $details->{$_}
127 };
128 }
129 }
130 }
131
132 1;
133
134 __END__
135
136 =head1 MODE
137
138 Check data protection groups.
139
140 =over 8
141
142 =item B<--filter-name>
143
144 Filter data protection groups by name (can be a regexp).
145
146 =item B<--unknown-health-indicator>
147
148 Define the conditions to match for the status to be UNKNOWN.
149 You can use the following variables: %{health}, %{indicator}
150
151 =item B<--warning-health-indicator>
152
153 Define the conditions to match for the status to be WARNING.
154 You can use the following variables: %{health}, %{indicator}
155
156 =item B<--critical-health-indicator>
157
158 Define the conditions to match for the status to be CRITICAL (default: '%{health} !~ /done|normal|null/i').
159 You can use the following variables: %{health}, %{indicator}
160
161 =back
162
163 =cut