| 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 apps::ibm::tsamp::local::mode::resourcegroups; |
| 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 sprintf( |
| 33 |
'operational state: %s [nominal: %s]', |
| 34 |
$self->{result_values}->{opState}, |
| 35 |
$self->{result_values}->{nominalState} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub prefix_rg_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return "Resource group '" . $options{instance} . "' "; |
| 43 |
} |
| 44 |
|
| 45 |
sub prefix_global_output { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
return 'Number of resource groups '; |
| 49 |
} |
| 50 |
|
| 51 |
sub set_counters { |
| 52 |
my ($self, %options) = @_; |
| 53 |
|
| 54 |
$self->{maps_counters_type} = [ |
| 55 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, |
| 56 |
{ name => 'rg', type => 1, cb_prefix_output => 'prefix_rg_output', message_multiple => 'All resource groups are ok', skipped_code => { -10 => 1 } } |
| 57 |
]; |
| 58 |
|
| 59 |
$self->{maps_counters}->{global} = []; |
| 60 |
foreach ('unknown', 'offline', 'online', 'failed_offline', |
| 61 |
'stuck_online', 'pending_online', 'pending_offline', 'ineligible') { |
| 62 |
my ($label, $output) = ($_, $_); |
| 63 |
$label =~ s/_/-/g; |
| 64 |
$output =~ s/_/ /g; |
| 65 |
push @{$self->{maps_counters}->{global}}, { |
| 66 |
label => 'total-' . $label, display_ok => 0, nlabel => 'resource_groups.' . $_ . '.count', set => { |
| 67 |
key_values => [ { name => $_ } ], |
| 68 |
output_template => $output . ': %s', |
| 69 |
perfdatas => [ |
| 70 |
{ template => '%s', min => 0 } |
| 71 |
] |
| 72 |
} |
| 73 |
}; |
| 74 |
} |
| 75 |
|
| 76 |
$self->{maps_counters}->{rg} = [ |
| 77 |
{ |
| 78 |
label => 'status', |
| 79 |
type => 2, |
| 80 |
unknown_default => '%{opState} =~ /unknown/i', |
| 81 |
warning_default => '%{opState} =~ /pending/i', |
| 82 |
critical_default => '%{opState} =~ /failed offline|stuck online/i || %{opState} ne %{nominalState}', |
| 83 |
set => { |
| 84 |
key_values => [ |
| 85 |
{ name => 'opState' }, { name => 'nominalState' }, { name => 'name' } |
| 86 |
], |
| 87 |
closure_custom_output => $self->can('custom_status_output'), |
| 88 |
closure_custom_perfdata => sub { return 0; }, |
| 89 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 90 |
} |
| 91 |
} |
| 92 |
]; |
| 93 |
} |
| 94 |
|
| 95 |
sub new { |
| 96 |
my ($class, %options) = @_; |
| 97 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 98 |
bless $self, $class; |
| 99 |
|
| 100 |
$options{options}->add_options(arguments => { |
| 101 |
'filter-rg-name:s' => { name => 'filter_rg_name' }, |
| 102 |
'exclude-rg-name:s' => { name => 'exclude_rg_name' } |
| 103 |
}); |
| 104 |
|
| 105 |
return $self; |
| 106 |
} |
| 107 |
|
| 108 |
sub manage_selection { |
| 109 |
my ($self, %options) = @_; |
| 110 |
|
| 111 |
my ($stdout) = $options{custom}->execute_command( |
| 112 |
command => 'lssam', |
| 113 |
command_options => '-nocolor' |
| 114 |
); |
| 115 |
|
| 116 |
$self->{global} = { |
| 117 |
unknown => 0, offline => 0, online => 0, failed_offline => 0, |
| 118 |
stuck_online => 0, pending_online => 0, pending_offline => 0, |
| 119 |
ineligible => 0 |
| 120 |
}; |
| 121 |
|
| 122 |
$self->{rg} = {}; |
| 123 |
while ($stdout =~ /^(\S.*)\s+IBM.ResourceGroup:(.*?)\s+.*?Nominal=(.*)\s*$/mig) { |
| 124 |
my ($name, $opState, $nominalState) = ($2, lc($1), lc($3)); |
| 125 |
if (defined($self->{option_results}->{filter_rg_name}) && $self->{option_results}->{filter_rg_name} ne '' && |
| 126 |
$name !~ /$self->{option_results}->{filter_rg_name}/) { |
| 127 |
$self->{output}->output_add(long_msg => "skipping resource group '" . $name . "': no matching filter.", debug => 1); |
| 128 |
next; |
| 129 |
} |
| 130 |
if (defined($self->{option_results}->{exclude_rg_name}) && $self->{option_results}->{exclude_rg_name} ne '' && |
| 131 |
$name =~ /$self->{option_results}->{exclude_rg_name}/) { |
| 132 |
$self->{output}->output_add(long_msg => "skipping resource group '" . $name . "': no matching filter.", debug => 1); |
| 133 |
next; |
| 134 |
} |
| 135 |
|
| 136 |
$self->{rg}->{$name} = { |
| 137 |
name => $name, |
| 138 |
opState => $opState, |
| 139 |
nominalState => $nominalState |
| 140 |
}; |
| 141 |
$opState =~ s/\s+/_/g; |
| 142 |
$self->{global}->{$opState}++; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
1; |
| 147 |
|
| 148 |
__END__ |
| 149 |
|
| 150 |
=head1 MODE |
| 151 |
|
| 152 |
Check resource groups. |
| 153 |
|
| 154 |
Command used: lssam -nocolor |
| 155 |
|
| 156 |
=over 8 |
| 157 |
|
| 158 |
=item B<--filter-counters> |
| 159 |
|
| 160 |
Only display some counters (regexp can be used). |
| 161 |
Example: --filter-counters='total' |
| 162 |
|
| 163 |
=item B<--filter-rg-name> |
| 164 |
|
| 165 |
Filter resource groups by name (can be a regexp). |
| 166 |
|
| 167 |
=item B<--exclude-rg-name> |
| 168 |
|
| 169 |
Exclude resource groups by name (can be a regexp). |
| 170 |
|
| 171 |
=item B<--unknown-status> |
| 172 |
|
| 173 |
Define the conditions to match for the status to be UNKNOWN (default: '%{opState} =~ /unknown/i'). |
| 174 |
You can use the following variables: %{opState}, %{nominalState}, %{name} |
| 175 |
|
| 176 |
=item B<--warning-status> |
| 177 |
|
| 178 |
Define the conditions to match for the status to be WARNING (default: '%{opState} =~ /pending/i'). |
| 179 |
You can use the following variables: %{opState}, %{nominalState}, %{name} |
| 180 |
|
| 181 |
=item B<--critical-status> |
| 182 |
|
| 183 |
Define the conditions to match for the status to be CRITICAL (default: '%{opState} =~ /failed offline|stuck online/i || %{opState} ne %{nominalState}'). |
| 184 |
You can use the following variables: %{opState}, %{nominalState}, %{name} |
| 185 |
|
| 186 |
=item B<--warning-*> B<--critical-*> |
| 187 |
|
| 188 |
Thresholds. |
| 189 |
Can be: 'total-unknown', 'total-offline', |
| 190 |
'total-online', 'total-failed-offline', 'total-stuck-online', 'total-pending-online', |
| 191 |
'total-pending-offline', 'total-ineligible'. |
| 192 |
|
| 193 |
=back |
| 194 |
|
| 195 |
=cut |