mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix bills api percentage calculation with cdr/quota of zero (#11352)
PHP allows division by zero but the api will fail when trying to encode the response to json as reported at https://github.com/librenms/librenms/pull/11295#issuecomment-604290389
This commit is contained in:
@@ -1382,13 +1382,21 @@ function list_bills(\Illuminate\Http\Request $request)
|
||||
if (strtolower($bill['bill_type']) == "cdr") {
|
||||
$allowed = format_si($bill['bill_cdr'])."bps";
|
||||
$used = format_si($rate_data['rate_95th'])."bps";
|
||||
$percent = round(($rate_data['rate_95th'] / $bill['bill_cdr']) * 100, 2);
|
||||
if ($bill['bill_cdr'] > 0) {
|
||||
$percent = round(($rate_data['rate_95th'] / $bill['bill_cdr']) * 100, 2);
|
||||
} else {
|
||||
$percent = "-";
|
||||
}
|
||||
$overuse = $rate_data['rate_95th'] - $bill['bill_cdr'];
|
||||
$overuse = (($overuse <= 0) ? "-" : format_si($overuse));
|
||||
} elseif (strtolower($bill['bill_type']) == "quota") {
|
||||
$allowed = format_bytes_billing($bill['bill_quota']);
|
||||
$used = format_bytes_billing($rate_data['total_data']);
|
||||
$percent = round(($rate_data['total_data'] / ($bill['bill_quota'])) * 100, 2);
|
||||
if ($bill['bill_quota'] > 0) {
|
||||
$percent = round(($rate_data['total_data'] / ($bill['bill_quota'])) * 100, 2);
|
||||
} else {
|
||||
$percent = "-";
|
||||
}
|
||||
$overuse = $rate_data['total_data'] - $bill['bill_quota'];
|
||||
$overuse = (($overuse <= 0) ? "-" : format_bytes_billing($overuse));
|
||||
}
|
||||
|
Reference in New Issue
Block a user