| 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::hp::storeonce::3::restapi::mode::fcsusage; |
| 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_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return 'status: ' . $self->{result_values}->{health}; |
| 33 |
} |
| 34 |
|
| 35 |
sub prefix_fcs_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return "Federated catalyst store '" . $options{instance_value}->{display} . "' "; |
| 39 |
} |
| 40 |
|
| 41 |
sub set_counters { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{maps_counters_type} = [ |
| 45 |
{ name => 'fcs', type => 1, cb_prefix_output => 'prefix_fcs_output', message_multiple => 'All federated catalyst stores are ok' } |
| 46 |
]; |
| 47 |
|
| 48 |
$self->{maps_counters}->{fcs} = [ |
| 49 |
{ |
| 50 |
label => 'status', |
| 51 |
type => 2, |
| 52 |
warning_default => '%{is_online} == 1 and %{health} =~ /warning/i', |
| 53 |
critical_default => '%{is_online} == 1 and %{health} =~ /critical/i', |
| 54 |
set => { |
| 55 |
key_values => [ { name => 'is_online' }, { name => 'health' }, { name => 'display' } ], |
| 56 |
closure_custom_output => $self->can('custom_status_output'), |
| 57 |
closure_custom_perfdata => sub { return 0; }, |
| 58 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 59 |
} |
| 60 |
}, |
| 61 |
{ label => 'usage', nlabel => 'fcs.space.usage.bytes', set => { |
| 62 |
key_values => [ { name => 'used' }, { name => 'display' } ], |
| 63 |
output_template => 'Used: %s %s', |
| 64 |
output_change_bytes => 1, |
| 65 |
perfdatas => [ |
| 66 |
{ template => '%s', unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 67 |
] |
| 68 |
} |
| 69 |
}, |
| 70 |
{ label => 'dedup', nlabel => 'fcs.deduplication.ratio.count', set => { |
| 71 |
key_values => [ { name => 'dedup' }, { name => 'display' } ], |
| 72 |
output_template => 'Dedup Ratio: %.2f', |
| 73 |
perfdatas => [ |
| 74 |
{ template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 75 |
] |
| 76 |
} |
| 77 |
}, |
| 78 |
{ label => 'items', nlabel => 'fcs.items.count', set => { |
| 79 |
key_values => [ { name => 'num_items' }, { name => 'display' } ], |
| 80 |
output_template => 'Num Items: %s', |
| 81 |
perfdatas => [ |
| 82 |
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 83 |
] |
| 84 |
} |
| 85 |
} |
| 86 |
]; |
| 87 |
} |
| 88 |
|
| 89 |
sub new { |
| 90 |
my ($class, %options) = @_; |
| 91 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 92 |
bless $self, $class; |
| 93 |
|
| 94 |
$options{options}->add_options(arguments => { |
| 95 |
'filter-name:s' => { name => 'filter_name' } |
| 96 |
}); |
| 97 |
|
| 98 |
return $self; |
| 99 |
} |
| 100 |
|
| 101 |
my %mapping_health_level = ( |
| 102 |
0 => 'unknown', |
| 103 |
1 => 'ok', |
| 104 |
2 => 'information', |
| 105 |
3 => 'warning', |
| 106 |
4 => 'critical' |
| 107 |
); |
| 108 |
|
| 109 |
sub manage_selection { |
| 110 |
my ($self, %options) = @_; |
| 111 |
|
| 112 |
$self->{fcs} = {}; |
| 113 |
my $result = $options{custom}->get(path => '/cluster/servicesets/*all*/teaming/services/cat/stores', ForceArray => ['store']); |
| 114 |
if (defined($result->{stores}->{store})) { |
| 115 |
foreach my $entry (@{$result->{stores}->{store}}) { |
| 116 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 117 |
$entry->{properties}->{name} !~ /$self->{option_results}->{filter_name}/) { |
| 118 |
$self->{output}->output_add(long_msg => "skipping '" . $entry->{properties}->{name} . "': no matching filter.", debug => 1); |
| 119 |
next; |
| 120 |
} |
| 121 |
|
| 122 |
$self->{fcs}->{$entry->{properties}->{id}} = { |
| 123 |
display => $entry->{properties}->{name}, |
| 124 |
health => $mapping_health_level{$entry->{properties}->{healthLevel}}, |
| 125 |
is_online => $entry->{properties}->{isOnline} eq 'true' ? 1 : 0, |
| 126 |
used => $entry->{properties}->{diskBytes}, |
| 127 |
dedup => $entry->{properties}->{dedupeRatio}, |
| 128 |
num_items => $entry->{properties}->{numItems} |
| 129 |
}; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if (scalar(keys %{$self->{fcs}}) <= 0) { |
| 134 |
$self->{output}->add_option_msg(short_msg => "No federated catalyst store found."); |
| 135 |
$self->{output}->option_exit(); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
1; |
| 140 |
|
| 141 |
__END__ |
| 142 |
|
| 143 |
=head1 MODE |
| 144 |
|
| 145 |
Check federated catalyst store usages. |
| 146 |
|
| 147 |
=over 8 |
| 148 |
|
| 149 |
=item B<--filter-counters> |
| 150 |
|
| 151 |
Only display some counters (regexp can be used). |
| 152 |
Example: --filter-counters='^status$' |
| 153 |
|
| 154 |
=item B<--filter-name> |
| 155 |
|
| 156 |
Filter name (can be a regexp). |
| 157 |
|
| 158 |
=item B<--warning-status> |
| 159 |
|
| 160 |
Define the conditions to match for the status to be WARNING (default: '%{is_online} == 1 and %{health} =~ /warning/i'). |
| 161 |
You can use the following variables: %{health}, %{is_online}, %{display} |
| 162 |
|
| 163 |
=item B<--critical-status> |
| 164 |
|
| 165 |
Define the conditions to match for the status to be CRITICAL (default: '%{is_online} == 1 and %{health} =~ /critical/i'). |
| 166 |
You can use the following variables: %{health}, %{is_online}, %{display} |
| 167 |
|
| 168 |
=item B<--warning-*> |
| 169 |
|
| 170 |
Warning threshold. |
| 171 |
Can be: 'usage', 'dedup', 'items'. |
| 172 |
|
| 173 |
=item B<--critical-*> |
| 174 |
|
| 175 |
Critical threshold. |
| 176 |
Can be: 'usage', 'dedup', 'items'. |
| 177 |
|
| 178 |
=back |
| 179 |
|
| 180 |
=cut |