mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-26 23:24:27 +02:00
First test to add replication jobs
This commit is contained in:
parent
4a50605c36
commit
480b0b05f8
@ -251,6 +251,18 @@ sub cache_backup_job_session {
|
|||||||
return $datas;
|
return $datas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub cache_replica_job_session {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $datas = $self->get_replica_job_session(disable_cache => 1, timeframe => $options{timeframe});
|
||||||
|
$self->write_cache_file(
|
||||||
|
statefile => 'replica_job_session',
|
||||||
|
response => $datas
|
||||||
|
);
|
||||||
|
|
||||||
|
return $datas;
|
||||||
|
}
|
||||||
|
|
||||||
sub cache_repository {
|
sub cache_repository {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
@ -281,6 +293,24 @@ sub get_backup_job_session {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_replica_job_session {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return $self->get_cache_file_response(statefile => 'replica_job_session')
|
||||||
|
if (defined($self->{option_results}->{cache_use}) && !defined($options{disable_cache}));
|
||||||
|
|
||||||
|
my $creation_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601();
|
||||||
|
|
||||||
|
return $self->request_api(
|
||||||
|
endpoint => '/api/query',
|
||||||
|
get_param => [
|
||||||
|
'type=ReplicaJobSession',
|
||||||
|
'format=Entities',
|
||||||
|
'filter=CreationTime>=' . $creation_time
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
sub get_repository {
|
sub get_repository {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -229,6 +229,7 @@ sub manage_selection {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $jobs_exec = $options{custom}->get_backup_job_session(timeframe => $self->{option_results}->{timeframe});
|
my $jobs_exec = $options{custom}->get_backup_job_session(timeframe => $self->{option_results}->{timeframe});
|
||||||
|
my $jobs_replica = $options{custom}->get_replica_job_session(timeframe => $self->{option_results}->{timeframe});
|
||||||
|
|
||||||
my $ctime = time();
|
my $ctime = time();
|
||||||
|
|
||||||
@ -278,6 +279,50 @@ sub manage_selection {
|
|||||||
$self->{jobs}->{ $job->{JobUid} }->{failed}->{failed}++;
|
$self->{jobs}->{ $job->{JobUid} }->{failed}->{failed}++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach my $job (@{$jobs_replica->{Entities}->{ReplicaJobSessions}->{ReplicaJobSessions}}) {
|
||||||
|
next if (defined($self->{option_results}->{filter_uid}) && $self->{option_results}->{filter_uid} ne '' && $job->{JobUid} !~ /$self->{option_results}->{filter_uid}/);
|
||||||
|
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $job->{JobName} !~ /$self->{option_results}->{filter_name}/);
|
||||||
|
next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && $job->{JobType} !~ /$self->{option_results}->{filter_type}/);
|
||||||
|
|
||||||
|
if (!defined($self->{jobs}->{ $job->{JobUid} })) {
|
||||||
|
$self->{jobs}->{ $job->{JobUid} } = {
|
||||||
|
name => $job->{JobName},
|
||||||
|
type => $job->{JobType},
|
||||||
|
failed => { name => $job->{JobName}, total => 0, failed => 0 }
|
||||||
|
};
|
||||||
|
$self->{global}->{detected}++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$job->{CreationTimeUTC} =~ /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)/;
|
||||||
|
my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6);
|
||||||
|
my $epoch = $dt->epoch();
|
||||||
|
|
||||||
|
if (!defined($self->{jobs}->{ $job->{JobUid} }->{executions}) || $epoch > $self->{jobs}->{ $job->{JobUid} }->{executions}->{last}->{epoch}) {
|
||||||
|
$self->{jobs}->{ $job->{JobUid} }->{executions}->{last} = {
|
||||||
|
jobName => $job->{JobName},
|
||||||
|
started => $job->{CreationTimeUTC},
|
||||||
|
status => $job->{Result},
|
||||||
|
epoch => $epoch
|
||||||
|
};
|
||||||
|
|
||||||
|
$self->{jobs}->{ $job->{JobUid} }->{timers} = {
|
||||||
|
name => $job->{JobName},
|
||||||
|
lastExecSeconds => $ctime - $epoch,
|
||||||
|
lastExecHuman => centreon::plugins::misc::change_seconds(value => $ctime - $epoch)
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($job->{State} =~ /Starting|Working|Resuming/i) {
|
||||||
|
my $duration = $ctime - $epoch;
|
||||||
|
$self->{jobs}->{ $job->{JobUid} }->{timers}->{durationSeconds} = $duration;
|
||||||
|
$self->{jobs}->{ $job->{JobUid} }->{timers}->{durationHuman} = centreon::plugins::misc::change_seconds(value => $duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{jobs}->{ $job->{JobUid} }->{failed}->{total}++;
|
||||||
|
if (defined($job->{Result}) && $job->{Result} =~ /Failed/i) {
|
||||||
|
$self->{jobs}->{ $job->{JobUid} }->{failed}->{failed}++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $uid (keys %{$self->{jobs}}) {
|
foreach my $uid (keys %{$self->{jobs}}) {
|
||||||
$self->{jobs}->{$uid}->{failed}->{failedPrct} = $self->{jobs}->{$uid}->{failed}->{total} > 0 ? $self->{jobs}->{$uid}->{failed}->{failed} * 100 / $self->{jobs}->{$uid}->{failed}->{total} : 0;
|
$self->{jobs}->{$uid}->{failed}->{failedPrct} = $self->{jobs}->{$uid}->{failed}->{total} > 0 ? $self->{jobs}->{$uid}->{failed}->{failed} * 100 / $self->{jobs}->{$uid}->{failed}->{total} : 0;
|
||||||
@ -308,7 +353,7 @@ Filter jobs by type.
|
|||||||
|
|
||||||
=item B<--timeframe>
|
=item B<--timeframe>
|
||||||
|
|
||||||
Timeframe to get BackupJobSession (in seconds. Default: 86400).
|
Timeframe to get BackupJobSession and ReplicaJobSession (in seconds. Default: 86400).
|
||||||
|
|
||||||
=item B<--unit>
|
=item B<--unit>
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ sub manage_selection {
|
|||||||
|
|
||||||
my $results = {};
|
my $results = {};
|
||||||
my $jobs_exec = $options{custom}->cache_backup_job_session(timeframe => $self->{option_results}->{timeframe});
|
my $jobs_exec = $options{custom}->cache_backup_job_session(timeframe => $self->{option_results}->{timeframe});
|
||||||
|
my $jobs_replica = $options{custom}->get_replica_job_session(timeframe => $self->{option_results}->{timeframe});
|
||||||
|
|
||||||
foreach my $job (@{$jobs_exec->{Entities}->{BackupJobSessions}->{BackupJobSessions}}) {
|
foreach my $job (@{$jobs_exec->{Entities}->{BackupJobSessions}->{BackupJobSessions}}) {
|
||||||
next if (defined($results->{ $job->{JobUid} }));
|
next if (defined($results->{ $job->{JobUid} }));
|
||||||
|
|
||||||
@ -60,6 +62,15 @@ sub manage_selection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach my $job (@{$jobs_replica->{Entities}->{BackupJobSessions}->{BackupJobSessions}}) {
|
||||||
|
next if (defined($results->{ $job->{JobUid} }));
|
||||||
|
|
||||||
|
$results->{ $job->{JobUid} } = {
|
||||||
|
jobName => $job->{JobName},
|
||||||
|
jobType => $job->{JobType}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +128,7 @@ List jobs.
|
|||||||
|
|
||||||
=item B<--timeframe>
|
=item B<--timeframe>
|
||||||
|
|
||||||
Timeframe to get BackupJobSession (in seconds. Default: 86400).
|
Timeframe to get BackupJobSession and ReplicaJobSession (in seconds. Default: 86400).
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user