mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-28 08:04:36 +02:00
enh(ansible-tower): add filter-time option (#5225)
Co-authored-by: omercier <32134301+omercier@users.noreply.github.com> Adding a filter to the jobs mode of Ansible Tower plugin to check only the jobs finished less than x hours ago. REFS: CTOR-630
This commit is contained in:
parent
88be153235
commit
b118801a47
@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter);
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use Date::Parse;
|
||||||
use centreon::plugins::statefile;
|
use centreon::plugins::statefile;
|
||||||
|
|
||||||
sub prefix_output_global {
|
sub prefix_output_global {
|
||||||
@ -41,24 +42,24 @@ sub set_counters {
|
|||||||
|
|
||||||
$self->{maps_counters}->{global} = [
|
$self->{maps_counters}->{global} = [
|
||||||
{ label => 'total', nlabel => 'jobs.total.count', set => {
|
{ label => 'total', nlabel => 'jobs.total.count', set => {
|
||||||
key_values => [ { name => 'total' } ],
|
key_values => [ { name => 'total' } ],
|
||||||
output_template => 'total: %d',
|
output_template => 'total: %d',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ value => 'total', template => '%d', min => 0 }
|
{ value => 'total', template => '%d', min => 0 }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ((['successful', 1], ['failed', 1], ['running', 1], ['canceled', 0], ['pending', 0], ['default', 0])) {
|
foreach (([ 'successful', 1 ], [ 'failed', 1 ], [ 'running', 1 ], [ 'canceled', 0 ], [ 'pending', 0 ], [ 'default', 0 ])) {
|
||||||
push @{$self->{maps_counters}->{global}}, {
|
push @{$self->{maps_counters}->{global}}, {
|
||||||
label => $_->[0], nlabel => 'jobs.' . $_->[0] . '.count', display_ok => $_->[1], set => {
|
label => $_->[0], nlabel => 'jobs.' . $_->[0] . '.count', display_ok => $_->[1], set => {
|
||||||
key_values => [ { name => $_->[0] }, { name => 'total' } ],
|
key_values => [ { name => $_->[0] }, { name => 'total' } ],
|
||||||
output_template => $_->[0] . ': %d',
|
output_template => $_->[0] . ': %d',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ template => '%d', min => 0, max => 'total' }
|
{ template => '%d', min => 0, max => 'total' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,6 +71,7 @@ sub new {
|
|||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
'filter-name:s' => { name => 'filter_name' },
|
'filter-name:s' => { name => 'filter_name' },
|
||||||
|
'filter-time:s' => { name => 'filter_time' },
|
||||||
'display-failed-jobs' => { name => 'display_failed_jobs' },
|
'display-failed-jobs' => { name => 'display_failed_jobs' },
|
||||||
'memory' => { name => 'memory' }
|
'memory' => { name => 'memory' }
|
||||||
});
|
});
|
||||||
@ -85,8 +87,8 @@ sub check_options {
|
|||||||
if (defined($self->{option_results}->{memory})) {
|
if (defined($self->{option_results}->{memory})) {
|
||||||
$self->{statefile_cache}->check_options(%options);
|
$self->{statefile_cache}->check_options(%options);
|
||||||
centreon::plugins::misc::mymodule_load(
|
centreon::plugins::misc::mymodule_load(
|
||||||
output => $self->{output},
|
output => $self->{output},
|
||||||
module => 'Date::Parse',
|
module => 'Date::Parse',
|
||||||
error_msg => "Cannot load module 'Date::Parse'."
|
error_msg => "Cannot load module 'Date::Parse'."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -109,13 +111,17 @@ sub manage_selection {
|
|||||||
my $failed_jobs = {};
|
my $failed_jobs = {};
|
||||||
foreach my $job (@$jobs) {
|
foreach my $job (@$jobs) {
|
||||||
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
|
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
|
||||||
&& $job->{name} !~ /$self->{option_results}->{filter_name}/);
|
&& $job->{name} !~ /$self->{option_results}->{filter_name}/);
|
||||||
|
|
||||||
|
next if (defined($self->{option_results}->{filter_time})
|
||||||
|
&& defined($job->{finished})
|
||||||
|
&& $current_time - Date::Parse::str2time($job->{finished}) > $self->{option_results}->{filter_time} * 3600);
|
||||||
|
|
||||||
if (defined($self->{option_results}->{memory}) && defined($job->{finished})) {
|
if (defined($self->{option_results}->{memory}) && defined($job->{finished})) {
|
||||||
my $finished_time = Date::Parse::str2time($job->{finished});
|
my $finished_time = Date::Parse::str2time($job->{finished});
|
||||||
if (!defined($finished_time)) {
|
if (!defined($finished_time)) {
|
||||||
$self->{output}->output_add(
|
$self->{output}->output_add(
|
||||||
severity => 'UNKNOWN',
|
severity => 'UNKNOWN',
|
||||||
short_msg => "Can't parse date '" . $job->{finished} . "'"
|
short_msg => "Can't parse date '" . $job->{finished} . "'"
|
||||||
);
|
);
|
||||||
next;
|
next;
|
||||||
@ -151,16 +157,75 @@ Check jobs.
|
|||||||
|
|
||||||
=item B<--filter-name>
|
=item B<--filter-name>
|
||||||
|
|
||||||
Filter job name (can use regexp).
|
Define which jobs should be monitored based on their names. This option will be treated as a regular expression.
|
||||||
|
|
||||||
|
=item B<--filter-time>
|
||||||
|
|
||||||
|
Define which jobs should be monitored based on the age of their last execution. Jobs that finished longer than X hours ago will be ignored.
|
||||||
|
|
||||||
=item B<--display-failed-jobs>
|
=item B<--display-failed-jobs>
|
||||||
|
|
||||||
Display failed jobs list in verbose output.
|
Display failed jobs list in verbose output.
|
||||||
|
|
||||||
=item B<--warning-*> B<--critical-*>
|
=item B<--memory>
|
||||||
|
|
||||||
Thresholds.
|
Only check new jobs.
|
||||||
Can be: 'total', 'successful', 'failed', 'running', 'canceled', 'pending', 'default'.
|
|
||||||
|
=item B<--warning-total>
|
||||||
|
|
||||||
|
Threshold warning for total jobs.
|
||||||
|
|
||||||
|
=item B<--critical-total>
|
||||||
|
|
||||||
|
Threshold critical for total jobs.
|
||||||
|
|
||||||
|
=item B<--warning-successful>
|
||||||
|
|
||||||
|
Threshold warning for successful jobs.
|
||||||
|
|
||||||
|
=item B<--critical-successful>
|
||||||
|
|
||||||
|
Threshold critical for successful jobs.
|
||||||
|
|
||||||
|
=item B<--warning-failed>
|
||||||
|
|
||||||
|
Threshold warning for failed jobs.
|
||||||
|
|
||||||
|
=item B<--critical-failed>
|
||||||
|
|
||||||
|
Threshold critical for failed jobs.
|
||||||
|
|
||||||
|
=item B<--warning-running>
|
||||||
|
|
||||||
|
Threshold warning for running jobs.
|
||||||
|
|
||||||
|
=item B<--critical-running>
|
||||||
|
|
||||||
|
Threshold critical for running jobs.
|
||||||
|
|
||||||
|
=item B<--warning-canceled>
|
||||||
|
|
||||||
|
Threshold warning for canceled jobs.
|
||||||
|
|
||||||
|
=item B<--critical-canceled>
|
||||||
|
|
||||||
|
Threshold critical for canceled jobs.
|
||||||
|
|
||||||
|
=item B<--warning-pending>
|
||||||
|
|
||||||
|
Threshold warning for pending jobs.
|
||||||
|
|
||||||
|
=item B<--critical-pending>
|
||||||
|
|
||||||
|
Threshold critical for pending jobs.
|
||||||
|
|
||||||
|
=item B<--warning-default>
|
||||||
|
|
||||||
|
Threshold warning for default jobs.
|
||||||
|
|
||||||
|
=item B<--critical-default>
|
||||||
|
|
||||||
|
Threshold critical for default jobs.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -32,16 +32,18 @@ jobs ${tc}
|
|||||||
Ctn Run Command And Check Result As Strings ${command} ${expected_result}
|
Ctn Run Command And Check Result As Strings ${command} ${expected_result}
|
||||||
|
|
||||||
Examples: tc extraoptions expected_result --
|
Examples: tc extraoptions expected_result --
|
||||||
... 1 --filter-name='' OK: Jobs total: 2, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=2;;;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 1 --filter-name='' OK: Jobs total: 4, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=4;;;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 2 --filter-name=toto OK: Jobs total: 0, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=0;;;0; 'jobs.successful.count'=0;;;0;0 'jobs.failed.count'=0;;;0;0 'jobs.running.count'=0;;;0;0 'jobs.canceled.count'=0;;;0;0 'jobs.pending.count'=0;;;0;0 'jobs.default.count'=0;;;0;0
|
... 2 --filter-name=First job OK: Jobs total: 2, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=2;;;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
||||||
... 3 --filter-name=toto --critical-total=1:1 CRITICAL: Jobs total: 0 | 'jobs.total.count'=0;;1:1;0; 'jobs.successful.count'=0;;;0;0 'jobs.failed.count'=0;;;0;0 'jobs.running.count'=0;;;0;0 'jobs.canceled.count'=0;;;0;0 'jobs.pending.count'=0;;;0;0 'jobs.default.count'=0;;;0;0
|
... 3 --filter-name=toto --critical-total=1:1 CRITICAL: Jobs total: 0 | 'jobs.total.count'=0;;1:1;0; 'jobs.successful.count'=0;;;0;0 'jobs.failed.count'=0;;;0;0 'jobs.running.count'=0;;;0;0 'jobs.canceled.count'=0;;;0;0 'jobs.pending.count'=0;;;0;0 'jobs.default.count'=0;;;0;0
|
||||||
... 4 --filter-name='' --critical-total=1:1 CRITICAL: Jobs total: 2 | 'jobs.total.count'=2;;1:1;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 4 --filter-name='' --critical-total=1:1 CRITICAL: Jobs total: 4 | 'jobs.total.count'=4;;1:1;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 5 --filter-name='' --critical-total=2:2 OK: Jobs total: 2, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=2;;2:2;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 5 --filter-name='' --critical-total=4:4 OK: Jobs total: 4, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=4;;4:4;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 6 --critical-total=2:1 CRITICAL: Jobs total: 2 | 'jobs.total.count'=2;;2:1;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 6 --critical-total=4:3 CRITICAL: Jobs total: 4 | 'jobs.total.count'=4;;4:3;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 7 --filter-name='' --display-failed-jobs OK: Jobs total: 2, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=2;;;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 7 --filter-name='' --display-failed-jobs OK: Jobs total: 4, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=4;;;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 8 --filter-name='' --warning-total=1:1 WARNING: Jobs total: 2 | 'jobs.total.count'=2;1:1;;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 8 --filter-name='' --warning-total=1:1 WARNING: Jobs total: 4 | 'jobs.total.count'=4;1:1;;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 9 --filter-name='' --warning-total=2:2 OK: Jobs total: 2, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=2;2:2;;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 9 --filter-name='' --warning-total=4:4 OK: Jobs total: 4, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=4;4:4;;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 10 --filter-name=toto --warning-total=1:1 WARNING: Jobs total: 0 | 'jobs.total.count'=0;1:1;;0; 'jobs.successful.count'=0;;;0;0 'jobs.failed.count'=0;;;0;0 'jobs.running.count'=0;;;0;0 'jobs.canceled.count'=0;;;0;0 'jobs.pending.count'=0;;;0;0 'jobs.default.count'=0;;;0;0
|
... 10 --filter-name=toto --warning-total=1:1 WARNING: Jobs total: 0 | 'jobs.total.count'=0;1:1;;0; 'jobs.successful.count'=0;;;0;0 'jobs.failed.count'=0;;;0;0 'jobs.running.count'=0;;;0;0 'jobs.canceled.count'=0;;;0;0 'jobs.pending.count'=0;;;0;0 'jobs.default.count'=0;;;0;0
|
||||||
... 11 --warning-total=1:2 OK: Jobs total: 2, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=2;1:2;;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 11 --warning-total=3:4 OK: Jobs total: 4, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=4;3:4;;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 12 --warning-total=2:1 WARNING: Jobs total: 2 | 'jobs.total.count'=2;2:1;;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 12 --warning-total=4:3 WARNING: Jobs total: 4 | 'jobs.total.count'=4;4:3;;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
... 13 --critical-total=1:2 OK: Jobs total: 2, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=2;;1:2;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
... 13 --critical-total=3:4 OK: Jobs total: 4, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=4;;3:4;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
|
... 14 --filter-time=24 OK: Jobs total: 2, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=2;;;0; 'jobs.successful.count'=0;;;0;2 'jobs.failed.count'=0;;;0;2 'jobs.running.count'=0;;;0;2 'jobs.canceled.count'=0;;;0;2 'jobs.pending.count'=0;;;0;2 'jobs.default.count'=0;;;0;2
|
||||||
|
... 15 --filter-time=48 OK: Jobs total: 4, successful: 0, failed: 0, running: 0 | 'jobs.total.count'=4;;;0; 'jobs.successful.count'=0;;;0;4 'jobs.failed.count'=0;;;0;4 'jobs.running.count'=0;;;0;4 'jobs.canceled.count'=0;;;0;4 'jobs.pending.count'=0;;;0;4 'jobs.default.count'=0;;;0;4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user