diff --git a/centreon-plugins/cloud/azure/custom/api.pm b/centreon-plugins/cloud/azure/custom/api.pm index 819d16319..7597e8975 100644 --- a/centreon-plugins/cloud/azure/custom/api.pm +++ b/centreon-plugins/cloud/azure/custom/api.pm @@ -243,6 +243,7 @@ sub convert_duration { my ($self, %options) = @_; my $duration; + if ($options{time_string} =~ /^P.*S$/) { centreon::plugins::misc::mymodule_load( output => $self->{output}, module => 'DateTime::Format::Duration::ISO8601', @@ -265,6 +266,30 @@ sub convert_duration { return $duration; } +sub convert_iso8601_to_epoch { + my ($self, %options) = @_; + + if ($options{time_string} =~ /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d.*)Z/) { + my $dt = DateTime->new( + year => $1, + month => $2, + day => $3, + hour => $4, + minute => $5, + second => $6, + nanosecond => $7 + ); + + my $epoch_time = $dt->epoch; + return $epoch_time; + + } + + $self->{output}->add_option_msg(short_msg => "Wrong date format: $options{time_string}"); + $self->{output}->option_exit(); + +} + sub json_decode { my ($self, %options) = @_; diff --git a/centreon-plugins/cloud/azure/management/recovery/mode/backupjobsstatus.pm b/centreon-plugins/cloud/azure/management/recovery/mode/backupjobsstatus.pm index a542da87b..e0de0c819 100644 --- a/centreon-plugins/cloud/azure/management/recovery/mode/backupjobsstatus.pm +++ b/centreon-plugins/cloud/azure/management/recovery/mode/backupjobsstatus.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -91,12 +91,12 @@ sub set_counters { ]; $self->{maps_counters}->{jobs} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', critical_default => '%{status} eq "Failed"', threshold => 0, set => { key_values => [ { name => 'status' }, { name => 'duration' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng, } }, ]; @@ -119,8 +119,7 @@ sub new { "resource-group:s" => { name => 'resource_group' }, "filter-name:s" => { name => 'filter_name' }, "filter-counters:s" => { name => 'filter_counters' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} eq "Failed"' }, + "lookback:s" => { name => 'lookback' } }); return $self; @@ -139,7 +138,6 @@ sub check_options { $self->{output}->option_exit(); } - $self->change_macros(macros => ['warning_status', 'critical_status']); } sub manage_selection { @@ -153,11 +151,16 @@ sub manage_selection { vault_name => $self->{option_results}->{vault_name}, resource_group => $self->{option_results}->{resource_group} ); + foreach my $job (@{$jobs}) { next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $job->{properties}->{entityFriendlyName} !~ /$self->{option_results}->{filter_name}/); my $duration = $options{custom}->convert_duration(time_string => $job->{properties}->{duration}); + my $end_time = $options{custom}->convert_iso8601_to_epoch(time_string => $job->{properties}->{endTime}); + + my $ts_timeframe = (defined($self->{option_results}->{lookback}) && $self->{option_results}->{lookback} ne '') ? (time() - $self->{option_results}->{lookback}) : 0; + next if (defined($self->{option_results}->{lookback}) && $self->{option_results}->{lookback} ne '' && $ts_timeframe > $end_time); $self->{jobs}->{$job->{id}} = { display => $job->{properties}->{entityFriendlyName}, @@ -186,7 +189,7 @@ Check backup jobs status. Example: perl centreon_plugins.pl --plugin=cloud::azure::management::recovery::plugin --custommode=azcli --mode=backup-jobs-status ---resource-group='MYRESOURCEGROUP' --vault-name='Loki' --filter-counters='^total-failed$' --critical-total-failed='0' --verbose +--resource-group='MYRESOURCEGROUP' --vault-name='Loki' --filter-counters='^total-failed$' --critical-total-failed='0' --lookback=43200 --verbose =over 8 @@ -207,6 +210,12 @@ Filter job name (Can be a regexp). Only display some counters (regexp can be used). Example: --filter-counters='^total-completed$' +=item B<--lookback> + +Specify in seconds since when you want to have backup job status. +Based on endTime property of the job. +Default: all existing job statuses are displayed. + =item B<--warning-status> Set warning threshold for status (Default: '').