Skip to content

Commit ee2159f

Browse files
committed
fix: Fix additional content merged into json even when not required on partial content
1 parent c512952 commit ee2159f

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ inventory:
2525
* fix #1017: Don't cleanup cpu on win32 from (R) trademark to keep cpu naming
2626
the same between OS
2727
* fix #1023: Improve iLO ip address resolution on Windows
28+
* Fix additional content merged into json even when not required on partial content
2829

2930
remoteinventory:
3031
* fix RedHat RHN systemid set as WINPRODID

lib/GLPI/Agent/Inventory.pm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,6 @@ sub getContent {
297297
itemtype => empty($self->{_itemtype}) ? "Computer" : $self->{_itemtype},
298298
);
299299

300-
# Support json file on additional-content with json output
301-
$content->mergeContent(content => delete $self->{_json_merge})
302-
if $self->{_json_merge};
303-
304300
# Normalize content to follow inventory format specs from https://github.com/glpi-project/inventory_format
305301
$content->normalize($params{server_version});
306302

@@ -335,11 +331,6 @@ sub mergeContent {
335331

336332
die "no content to merge\n" unless $content;
337333

338-
if ($self->getFormat() eq 'json') {
339-
$self->{_json_merge} = $content;
340-
return;
341-
}
342-
343334
foreach my $section (keys %$content) {
344335
if (ref $content->{$section} eq 'ARRAY') {
345336
# a list of entry

lib/GLPI/Agent/Protocol/Message.pm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,37 @@ sub set {
8888
}
8989

9090
sub get {
91-
my ($self, $what) = @_;
91+
my ($self, $what, $transform, $how) = @_;
9292

9393
return unless defined($self->{_message});
9494

95-
return $self->{_message}->{$what} if defined($what);
95+
if (defined($what)) {
96+
return _uppercase_keys($self->{_message}->{$what})
97+
if $transform && $how && $transform eq "transform" && $how eq "upperkeys";
98+
99+
return $self->{_message}->{$what};
100+
}
96101

97102
return $self->{_message};
98103
}
99104

105+
sub _uppercase_keys {
106+
my ($ref) = shift;
107+
108+
if (ref($ref) eq "HASH") {
109+
my $newref = {};
110+
foreach my $key (keys(%{$ref})) {
111+
$newref->{uc($key)} = _uppercase_keys($ref->{$key});
112+
}
113+
return $newref;
114+
} elsif (ref($ref) eq "ARRAY") {
115+
return [ map { _uppercase_keys($_) } @{$ref} ];
116+
}
117+
118+
# Not a ref, just return unmodified value
119+
return $ref;
120+
}
121+
100122
sub merge {
101123
my ($self, %params) = @_;
102124

lib/GLPI/Agent/Task/Inventory.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ sub _injectContent {
595595
my $json = GLPI::Agent::Protocol::Message->new(
596596
file => $file,
597597
);
598-
$content = $json->get('content');
598+
$content = $json->get('content', transform => "upperkeys");
599599
unless ($content) {
600600
$self->{logger}->error(
601601
"failing to import $file file content in the inventory"

t/tasks/esx.t

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ foreach my $test (keys %tests) {
138138
} "$test: set json format";
139139

140140
# Fix version client with the test one to avoid false positive while agent version is evolving
141-
$inventory->mergeContent({
142-
versionclient => $tests{$test}->{client}
143-
});
141+
$inventory->{content}->{VERSIONCLIENT} = $tests{$test}->{client};
144142

145143
my $content;
146144
lives_ok {

0 commit comments

Comments
 (0)