| 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::3par::ssh::mode::nodes; |
| 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 node_long_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
"checking node '%s'", |
| 34 |
$options{instance_value}->{node_id} |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
sub prefix_node_output { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
return sprintf( |
| 42 |
"node '%s' ", |
| 43 |
$options{instance_value}->{node_id} |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
sub prefix_cpu_output { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
return "CPU '" . $options{instance_value}->{cpu_id} . "' "; |
| 51 |
} |
| 52 |
|
| 53 |
sub set_counters { |
| 54 |
my ($self, %options) = @_; |
| 55 |
|
| 56 |
$self->{maps_counters_type} = [ |
| 57 |
{ |
| 58 |
name => 'nodes', type => 3, cb_prefix_output => 'prefix_node_output', cb_long_output => 'node_long_output', indent_long_output => ' ', message_multiple => 'All nodes are ok', |
| 59 |
group => [ |
| 60 |
{ name => 'global', type => 0 }, |
| 61 |
{ name => 'cpu', display_long => 1, cb_prefix_output => 'prefix_cpu_output', |
| 62 |
message_multiple => 'all CPUs usage are ok', type => 1, skipped_code => { -10 => 1 } } |
| 63 |
] |
| 64 |
} |
| 65 |
]; |
| 66 |
|
| 67 |
$self->{maps_counters}->{global} = [ |
| 68 |
{ |
| 69 |
label => 'status', |
| 70 |
type => 2, |
| 71 |
critical_default => '%{status} !~ /ok/i', |
| 72 |
set => { |
| 73 |
key_values => [ { name => 'status' }, { name => 'node_id' } ], |
| 74 |
output_template => 'status: %s', |
| 75 |
closure_custom_perfdata => sub { return 0; }, |
| 76 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 77 |
} |
| 78 |
} |
| 79 |
]; |
| 80 |
|
| 81 |
$self->{maps_counters}->{cpu} = [ |
| 82 |
{ label => 'cpu-utilization', nlabel => 'core.cpu.utilization.percentage', set => { |
| 83 |
key_values => [ { name => 'cpu_usage' } ], |
| 84 |
output_template => 'usage: %.2f %%', |
| 85 |
perfdatas => [ |
| 86 |
{ template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } |
| 87 |
] |
| 88 |
} |
| 89 |
} |
| 90 |
]; |
| 91 |
} |
| 92 |
|
| 93 |
sub new { |
| 94 |
my ($class, %options) = @_; |
| 95 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 96 |
bless $self, $class; |
| 97 |
|
| 98 |
$options{options}->add_options(arguments => { |
| 99 |
'filter-node-id:s' => { name => 'filter_node_id' } |
| 100 |
}); |
| 101 |
|
| 102 |
return $self; |
| 103 |
} |
| 104 |
|
| 105 |
sub manage_selection { |
| 106 |
my ($self, %options) = @_; |
| 107 |
|
| 108 |
my ($content) = $options{custom}->execute_command( |
| 109 |
commands => [ |
| 110 |
'echo "===statcpu==="', |
| 111 |
'statcpu -iter 1 -d 1', |
| 112 |
'echo "===shownode==="', |
| 113 |
'shownode -s' |
| 114 |
] |
| 115 |
); |
| 116 |
#===statcpu=== |
| 117 |
#17:34:58 01/27/2022 |
| 118 |
#node,cpu user sys idle intr/s ctxt/s |
| 119 |
# 0,0 1 0 99 |
| 120 |
# 0,1 1 1 98 |
| 121 |
# 0,2 0 1 99 |
| 122 |
# 0,3 1 1 98 |
| 123 |
# 0,4 0 1 99 |
| 124 |
# 0,5 0 1 99 |
| 125 |
# 0,6 4 1 95 |
| 126 |
# 0,7 0 0 100 |
| 127 |
# 0,total 1 1 98 7276 9026 |
| 128 |
# |
| 129 |
# 1,0 0 0 100 |
| 130 |
# 1,1 0 0 100 |
| 131 |
# 1,2 0 0 100 |
| 132 |
# 1,3 0 1 99 |
| 133 |
# 1,4 0 0 100 |
| 134 |
# 1,5 0 1 99 |
| 135 |
# 1,6 0 2 98 |
| 136 |
# 1,7 0 0 100 |
| 137 |
# 1,total 0 1 99 5312 4799 |
| 138 |
#===shownode=== |
| 139 |
#Node -State- -Detailed_State- |
| 140 |
# 0 OK OK |
| 141 |
# 1 OK OK |
| 142 |
|
| 143 |
$self->{nodes} = {}; |
| 144 |
if ($content =~ /===shownode===.*?\n(.*?)(===|\Z)/msi) { |
| 145 |
foreach my $line (split(/\n/, $1)) { |
| 146 |
next if ($line !~ /^\s*(\d+)\s+(\S+)/); |
| 147 |
my ($node_id, $status) = ($1, $2); |
| 148 |
|
| 149 |
next if (defined($self->{option_results}->{filter_node_id}) && $self->{option_results}->{filter_node_id} ne '' && |
| 150 |
$node_id !~ /$self->{option_results}->{filter_node_id}/); |
| 151 |
$self->{nodes}->{'node' . $node_id} = { |
| 152 |
node_id => $node_id, |
| 153 |
global => { node_id => $node_id, status => $status }, |
| 154 |
cpu => {} |
| 155 |
}; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
if ($content =~ /===statcpu===.*?\n(.*?)(===|\Z)/msi) { |
| 160 |
foreach my $line (split(/\n/, $1)) { |
| 161 |
next if ($line !~ /^\s*(\d+),(\d+)\s+\d+\s+\d+\s+(\d+)/); |
| 162 |
my ($node_id, $cpu_id, $idle) = ($1, $2, $3); |
| 163 |
next if (!defined($self->{nodes}->{'node' . $node_id})); |
| 164 |
|
| 165 |
$self->{nodes}->{'node' . $node_id}->{cpu}->{'cpu' . $cpu_id} = { |
| 166 |
cpu_id => $cpu_id, |
| 167 |
cpu_usage => 100 - $idle |
| 168 |
}; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
if (scalar(keys %{$self->{nodes}}) <= 0) { |
| 173 |
$self->{output}->add_option_msg(short_msg => "Couldn't get nodes information"); |
| 174 |
$self->{output}->option_exit(); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
1; |
| 179 |
|
| 180 |
__END__ |
| 181 |
|
| 182 |
=head1 MODE |
| 183 |
|
| 184 |
Check nodes. |
| 185 |
|
| 186 |
=over 8 |
| 187 |
|
| 188 |
=item B<--filter-node-id> |
| 189 |
|
| 190 |
Filter nodes by ID (can be a regexp). |
| 191 |
|
| 192 |
=item B<--unknown-status> |
| 193 |
|
| 194 |
Define the conditions to match for the status to be UNKNOWN. |
| 195 |
You can use the following variables: %{status}, %{node_id} |
| 196 |
|
| 197 |
=item B<--warning-status> |
| 198 |
|
| 199 |
Define the conditions to match for the status to be WARNING. |
| 200 |
You can use the following variables: %{status}, %{node_id} |
| 201 |
|
| 202 |
=item B<--critical-status> |
| 203 |
|
| 204 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /ok/i'). |
| 205 |
You can use the following variables: %{status}, %{node_id} |
| 206 |
|
| 207 |
=item B<--warning-*> B<--critical-*> |
| 208 |
|
| 209 |
Thresholds. |
| 210 |
Can be: 'cpu-utilization'. |
| 211 |
|
| 212 |
=back |
| 213 |
|
| 214 |
=cut |