From e1c3064303a8c85f65a01331535a565d9afbc8f8 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 21 May 2021 17:29:07 -0400 Subject: [PATCH] fix(cgi-bin): transform all memory sizes to JSON numbers --- cgi-bin/get_memory | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cgi-bin/get_memory b/cgi-bin/get_memory index bf91b713..e4dfb5f3 100755 --- a/cgi-bin/get_memory +++ b/cgi-bin/get_memory @@ -118,24 +118,25 @@ AND scan_hardware_swap_free => $anvil->Convert->add_commas({number => $scan_hardware_swap_free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $scan_hardware_swap_free}).")", }}); + # Important: ensure all size values are integers, which will be auto-transformed to JSON number type. if (not $hash->{total}) { - $hash->{total} = $scan_hardware_ram_total; + $hash->{total} = int($scan_hardware_ram_total); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->total' => $hash->{total} }}); } elsif ($scan_hardware_ram_total < $hash->{total}) { - $hash->{total} = $scan_hardware_ram_total; + $hash->{total} = int($scan_hardware_ram_total); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->total' => $hash->{total} }}); } push @{$hash->{nodes}}, { host_uuid => $host_uuid, - total => $scan_hardware_ram_total, - free => $scan_hardware_memory_free, - swap_total => $scan_hardware_swap_total, - swap_used => $scan_hardware_swap_free, + total => int($scan_hardware_ram_total), + free => int($scan_hardware_memory_free), + swap_total => int($scan_hardware_swap_total), + swap_used => int($scan_hardware_swap_free), }; } }