Skip to content

Commit e2971a3

Browse files
committed
fix: Fix full-inventory-postpone feature to always send a full inventory if a section has disappeared.
This can be the case if no more monitor is connected for example.
1 parent ffd66d2 commit e2971a3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/GLPI/Agent/Inventory.pm

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ sub computeChecksum {
516516
$postpone = 0 unless $self->getFormat() eq 'json';
517517

518518
my $save_state = 0;
519+
my @delete_sections;
519520
foreach my $section (@checked_sections) {
520521
my ($sha, $len) = _checksum($section, $self->{content}->{$section});
521522
my $state = $last_state->get($section);
@@ -524,6 +525,8 @@ sub computeChecksum {
524525
$logger->debug("Section $section has disappeared since last inventory");
525526
$last_state->delete($section);
526527
$save_state++;
528+
# On missing section, a full inventory must be submitted
529+
$postpone = 0;
527530
}
528531
next;
529532
}
@@ -535,10 +538,9 @@ sub computeChecksum {
535538
defined($state->{len}) && $state->{len} == $len &&
536539
defined($state->{digest}) && $state->{digest} eq $digest
537540
) {
538-
# If we can postpone full inventory, remove section and set inventory as partial
541+
# In the case we will be able to postpone full inventory, keep section as to be removed
539542
if ($postpone && !$always_keep_sections{$section}) {
540-
delete $self->{content}->{$section};
541-
$self->isPartial(1);
543+
push @delete_sections, $section;
542544
}
543545
next;
544546
}
@@ -555,6 +557,14 @@ sub computeChecksum {
555557
$save_state++;
556558
}
557559

560+
# If we can postpone full inventory, remove section and set inventory as partial
561+
if ($postpone && @delete_sections) {
562+
foreach my $section (@delete_sections) {
563+
delete $self->{content}->{$section};
564+
}
565+
$self->isPartial(1);
566+
}
567+
558568
$logger->debug("Full inventory ".
559569
($postpone_config && $self->isPartial() ? "postponed: $postpone/$postpone_config" : "kept")
560570
);

0 commit comments

Comments
 (0)