fix(cgi-bin): transform all memory sizes to JSON numbers

main
Tsu-ba-me 4 years ago
parent 552ed66829
commit e1c3064303
  1. 13
      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}).")", 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}) 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} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->total' => $hash->{total} }});
} }
elsif ($scan_hardware_ram_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} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->total' => $hash->{total} }});
} }
push @{$hash->{nodes}}, { push @{$hash->{nodes}}, {
host_uuid => $host_uuid, host_uuid => $host_uuid,
total => $scan_hardware_ram_total, total => int($scan_hardware_ram_total),
free => $scan_hardware_memory_free, free => int($scan_hardware_memory_free),
swap_total => $scan_hardware_swap_total, swap_total => int($scan_hardware_swap_total),
swap_used => $scan_hardware_swap_free, swap_used => int($scan_hardware_swap_free),
}; };
} }
} }

Loading…
Cancel
Save