| 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::oracle::gg::local::mode::processes; |
| 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('status: %s', |
| 33 |
$self->{result_values}->{status} |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
sub prefix_process_output { |
| 38 |
my ($self, %options) = @_; |
| 39 |
|
| 40 |
return sprintf( |
| 41 |
"Process '%s' ", |
| 42 |
$options{instance_value}->{name} |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
sub set_counters { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
$self->{maps_counters_type} = [ |
| 50 |
{ name => 'processes', type => 1, cb_prefix_output => 'prefix_process_output', message_multiple => 'All processes are ok', skipped_code => { -10 => 1 } } |
| 51 |
]; |
| 52 |
|
| 53 |
$self->{maps_counters}->{processes} = [ |
| 54 |
{ label => 'status', type => 2, critical_default => '%{status} =~ /ABENDED/i', set => { |
| 55 |
key_values => [ { name => 'status' }, { name => 'group' }, { name => 'type' }, { name => 'name' } ], |
| 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 => 'lag', nlabel => 'process.lag.seconds', set => { |
| 62 |
key_values => [ { name => 'lag_secs' }, { name => 'lag_human' } ], |
| 63 |
output_template => 'lag: %s', |
| 64 |
output_use => 'lag_human', |
| 65 |
perfdatas => [ |
| 66 |
{ template => '%s', min => 0, unit => 's', label_extra_instance => 1 } |
| 67 |
] |
| 68 |
} |
| 69 |
}, |
| 70 |
{ label => 'time-checkpoint', nlabel => 'process.time.checkpoint.seconds', set => { |
| 71 |
key_values => [ { name => 'time_secs' }, { name => 'time_human' } ], |
| 72 |
output_template => 'time since checkpoint: %s', |
| 73 |
output_use => 'time_human', |
| 74 |
perfdatas => [ |
| 75 |
{ template => '%s', min => 0, unit => 's', label_extra_instance => 1 } |
| 76 |
] |
| 77 |
} |
| 78 |
} |
| 79 |
]; |
| 80 |
} |
| 81 |
|
| 82 |
sub new { |
| 83 |
my ($class, %options) = @_; |
| 84 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 85 |
bless $self, $class; |
| 86 |
|
| 87 |
$options{options}->add_options(arguments => { |
| 88 |
'filter-name:s' => { name => 'filter_name' }, |
| 89 |
'filter-group:s' => { name => 'filter_group' }, |
| 90 |
'filter-type:s' => { name => 'filter_type' } |
| 91 |
}); |
| 92 |
|
| 93 |
return $self; |
| 94 |
} |
| 95 |
|
| 96 |
sub manage_selection { |
| 97 |
my ($self, %options) = @_; |
| 98 |
|
| 99 |
my ($stdout) = $options{custom}->execute_command( |
| 100 |
commands => 'INFO ALL' |
| 101 |
); |
| 102 |
|
| 103 |
$self->{processes} = {}; |
| 104 |
while ($stdout =~ /^(MANAGER|EXTRACT|REPLICAT)\s+(\S+)(.*?)(?:\n|\Z)/msig) { |
| 105 |
my ($type, $status, $data) = ($1, $2, $3); |
| 106 |
|
| 107 |
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && |
| 108 |
$type !~ /$self->{option_results}->{filter_type}/) { |
| 109 |
$self->{output}->output_add(long_msg => "skipping process '" . $type . "': no matching filter.", debug => 1); |
| 110 |
next; |
| 111 |
} |
| 112 |
|
| 113 |
if ($type eq 'MANAGER') { |
| 114 |
$self->{processes}->{$type} = { |
| 115 |
status => $status, |
| 116 |
name => $type, |
| 117 |
type => $type, |
| 118 |
group => '-' |
| 119 |
}; |
| 120 |
next; |
| 121 |
} |
| 122 |
|
| 123 |
next if ($data !~ /\s*(\S+)\s*(?:(\d+:\d+:\d+)\s+(\d+:\d+:\d+))?/); |
| 124 |
|
| 125 |
my ($group, $lag, $time) = ($1, $2, $3); |
| 126 |
my $name = $type . ':' . $group; |
| 127 |
if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' && |
| 128 |
$group !~ /$self->{option_results}->{filter_group}/) { |
| 129 |
$self->{output}->output_add(long_msg => "skipping process '" . $group . "': no matching filter.", debug => 1); |
| 130 |
next; |
| 131 |
} |
| 132 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 133 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 134 |
$self->{output}->output_add(long_msg => "skipping process '" . $group . "': no matching filter.", debug => 1); |
| 135 |
next; |
| 136 |
} |
| 137 |
|
| 138 |
$self->{processes}->{$name} = { |
| 139 |
status => $status, |
| 140 |
name => $name, |
| 141 |
type => $type, |
| 142 |
group => $group |
| 143 |
}; |
| 144 |
|
| 145 |
next if ($status eq 'STOPPED'); |
| 146 |
|
| 147 |
if (defined($lag)) { |
| 148 |
my ($hour, $min, $sec) = split(/:/, $lag); |
| 149 |
my $lag_secs = ($hour * 3600) + ($min * 60) + $sec; |
| 150 |
$self->{processes}->{$name}->{lag_secs} = $lag_secs; |
| 151 |
$self->{processes}->{$name}->{lag_human} = centreon::plugins::misc::change_seconds(value => $self->{processes}->{$name}->{lag_secs}); |
| 152 |
} |
| 153 |
if (defined($time)) { |
| 154 |
my ($hour, $min, $sec) = split(/:/, $time); |
| 155 |
my $time_secs = ($hour * 3600) + ($min * 60) + $sec; |
| 156 |
$self->{processes}->{$name}->{time_secs} = $time_secs; |
| 157 |
$self->{processes}->{$name}->{time_human} = centreon::plugins::misc::change_seconds(value => $self->{processes}->{$name}->{time_secs}); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
1; |
| 164 |
|
| 165 |
__END__ |
| 166 |
|
| 167 |
=head1 MODE |
| 168 |
|
| 169 |
Monitor processes. |
| 170 |
|
| 171 |
=over 8 |
| 172 |
|
| 173 |
=item B<--filter-name> |
| 174 |
|
| 175 |
Filter processes by name (can be a regexp). |
| 176 |
|
| 177 |
name is the following concatenation: type:group (eg.: EXTRACT:DB_test) |
| 178 |
|
| 179 |
=item B<--filter-group> |
| 180 |
|
| 181 |
Filter processes by group (can be a regexp). |
| 182 |
|
| 183 |
=item B<--filter-type> |
| 184 |
|
| 185 |
Filter processes by type (can be a regexp). |
| 186 |
|
| 187 |
=item B<--unknown-status> |
| 188 |
|
| 189 |
Define the conditions to match for the status to be UNKNOWN. |
| 190 |
You can use the following variables: %{status}, %{name}, %{group}, %{type} |
| 191 |
|
| 192 |
=item B<--warning-status> |
| 193 |
|
| 194 |
Define the conditions to match for the status to be WARNING. |
| 195 |
You can use the following variables: %{status}, %{name}, %{group}, %{type} |
| 196 |
|
| 197 |
=item B<--critical-status> |
| 198 |
|
| 199 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /ABENDED/i'). |
| 200 |
You can use the following variables: %{status}, %{name}, %{group}, %{type} |
| 201 |
|
| 202 |
=item B<--warning-*> B<--critical-*> |
| 203 |
|
| 204 |
Thresholds. |
| 205 |
Can be: 'lag' (s), 'time-checkpoint' (s). |
| 206 |
|
| 207 |
=back |
| 208 |
|
| 209 |
=cut |