mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix more divide by zero issues (#14954)
* Fix more divide by zero issues fixes: 14932 * Round to the nearest integer, then cast * Fix up dhcpatriot
This commit is contained in:
@@ -32,7 +32,6 @@ use LibreNMS\Interfaces\Module;
|
||||
use LibreNMS\OS;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use LibreNMS\Util\Number;
|
||||
use Log;
|
||||
|
||||
class PrinterSupplies implements Module
|
||||
{
|
||||
@@ -235,7 +234,7 @@ class PrinterSupplies implements Module
|
||||
// at least one piece of paper in tray
|
||||
$current = 50;
|
||||
} else {
|
||||
$current = $current / $capacity * 100;
|
||||
$current = Number::calculatePercent($current, $capacity);
|
||||
}
|
||||
|
||||
$papers->push(new PrinterSupply([
|
||||
|
@@ -30,6 +30,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\View\View;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
class GlobeController extends WidgetController
|
||||
{
|
||||
@@ -104,7 +105,7 @@ class GlobeController extends WidgetController
|
||||
$location->lat,
|
||||
$location->lng,
|
||||
$location->location,
|
||||
(1 - $up / $count) * 100, // percent down
|
||||
Number::calculatePercent($count - $up, $count), // percent down
|
||||
$count,
|
||||
$down_items->implode(',<br/> '),
|
||||
]);
|
||||
|
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Interfaces\Models\Keyable;
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
class Mempool extends DeviceRelatedModel implements Keyable
|
||||
{
|
||||
@@ -86,7 +87,7 @@ class Mempool extends DeviceRelatedModel implements Keyable
|
||||
}
|
||||
|
||||
if ($percent == null) {
|
||||
$this->mempool_perc = $this->mempool_used / $this->mempool_total * 100;
|
||||
$this->mempool_perc = (int) Number::calculatePercent($this->mempool_used, $this->mempool_total, 0);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@@ -71,7 +71,7 @@ if (! empty($dhcp_networks[$dhcp_networks_base_oid])) {
|
||||
$type = $value['type'];
|
||||
$divisor = $pool_data[$value['size_oid']];
|
||||
$descr = $value['description'] . ' (' . $pool_data[$value['oid']] . '/' . $divisor . ')';
|
||||
$current = (($pool_data[$value['oid']] / $divisor) * 100);
|
||||
$current = \LibreNMS\Util\Number::calculatePercent($pool_data[$value['oid']], $divisor);
|
||||
$group = $value['group'];
|
||||
|
||||
discover_sensor(
|
||||
|
@@ -402,7 +402,7 @@ vprn services are up when the service is administratively up however routing fun
|
||||
$operstate_status_color = 'danger';
|
||||
}
|
||||
|
||||
$fdb_usage_perc = $svc['svcTlsFdbNumEntries'] / $svc['svcTlsFdbTableSize'] * 100;
|
||||
$fdb_usage_perc = Number::calculatePercent($svc['svcTlsFdbNumEntries'], $svc['svcTlsFdbTableSize']);
|
||||
if ($fdb_usage_perc > 95) {
|
||||
$fdb_status_color = 'danger';
|
||||
} elseif ($fdb_usage_perc > 75) {
|
||||
|
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
$highlight_node = $vars['highlight_node'] ?? 0;
|
||||
$group = $vars['group'] ?? 0;
|
||||
@@ -276,8 +277,8 @@ foreach ($list as $items) {
|
||||
} else {
|
||||
$width = round(0.77 * pow($speed, 0.25));
|
||||
}
|
||||
$link_in_used = $items['local_ifspeed'] ? (($items['local_ifinoctets_rate'] * 8) / $items['local_ifspeed'] * 100) : 0;
|
||||
$link_out_used = $items['local_ifspeed'] ? (($items['local_ifoutoctets_rate'] * 8) / $items['local_ifspeed'] * 100) : 0;
|
||||
$link_in_used = Number::calculatePercent($items['local_ifinoctets_rate'], $items['local_ifspeed']);
|
||||
$link_out_used = Number::calculatePercent($items['local_ifoutoctets_rate'], $items['local_ifspeed']);
|
||||
if ($link_in_used > $link_out_used) {
|
||||
$link_used = $link_in_used;
|
||||
} else {
|
||||
|
@@ -4,6 +4,7 @@
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\Debug;
|
||||
use LibreNMS\Util\Number;
|
||||
|
||||
$install_dir = realpath(__DIR__ . '/..');
|
||||
chdir($install_dir);
|
||||
@@ -101,7 +102,7 @@ foreach ($devices as &$device) {
|
||||
$device['port_count'] = $count;
|
||||
$device['inactive_ratio'] = ($inactive == 0 ? 0 : ($inactive / $count));
|
||||
$device['diff_sec'] = $device['selective_time_sec'] - $device['full_time_sec'];
|
||||
$device['diff_perc'] = ($device['diff_sec'] / $device['full_time_sec']) * 100;
|
||||
$device['diff_perc'] = Number::calculatePercent($device['diff_sec'], $device['full_time_sec']);
|
||||
|
||||
// $enable_sel_value is negative and we want to enable it for all devices with an even lower value.
|
||||
// It also has to save more than 1 s, or we might enable it for devices with i.e. 100ms vs 50ms, which isn't needed.
|
||||
@@ -160,7 +161,7 @@ $inactive_ratio = array_sum(array_column($devices, 'inactive_ratio')) / count($d
|
||||
$total_full_time = array_sum(array_column($devices, 'full_time_sec'));
|
||||
$total_selective_time = array_sum(array_column($devices, 'selective_time_sec'));
|
||||
$difference = $total_selective_time - $total_full_time;
|
||||
$difference_perc = ($difference / $total_full_time) * 100;
|
||||
$difference_perc = Number::calculatePercent($difference, $total_full_time);
|
||||
$total_diff_color = ($difference > 0 ? "\033[0;31m" : "\033[0;32m");
|
||||
|
||||
printf(
|
||||
|
@@ -1137,7 +1137,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 7911,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 88.914170142839,
|
||||
"sensor_current": 88.91,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1162,7 +1162,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 1892,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 34.989429175476,
|
||||
"sensor_current": 34.99,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1187,7 +1187,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 123,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 62.60162601626,
|
||||
"sensor_current": 62.6,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1212,7 +1212,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 123,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 9.7560975609756,
|
||||
"sensor_current": 9.76,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1237,7 +1237,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 123,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 4.8780487804878,
|
||||
"sensor_current": 4.88,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1262,7 +1262,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 123,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 7.3170731707317,
|
||||
"sensor_current": 7.32,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1287,7 +1287,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 123,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 8.130081300813,
|
||||
"sensor_current": 8.13,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1312,7 +1312,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 251,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 4.7808764940239,
|
||||
"sensor_current": 4.78,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1337,7 +1337,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 123,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 8.130081300813,
|
||||
"sensor_current": 8.13,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1362,7 +1362,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 123,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 3.2520325203252,
|
||||
"sensor_current": 3.25,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1412,7 +1412,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 123,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 0.8130081300813,
|
||||
"sensor_current": 0.81,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1487,7 +1487,7 @@
|
||||
"group": "Authenticated DHCP",
|
||||
"sensor_divisor": 502,
|
||||
"sensor_multiplier": 100,
|
||||
"sensor_current": 92.03187250996,
|
||||
"sensor_current": 92.03,
|
||||
"sensor_limit": 100,
|
||||
"sensor_limit_warn": 95,
|
||||
"sensor_limit_low": null,
|
||||
@@ -1948,7 +1948,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 88.914170142839,
|
||||
"sensor_prev": 88.91,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -1973,7 +1973,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 34.989429175476,
|
||||
"sensor_prev": 34.99,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -1998,7 +1998,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 62.60162601626,
|
||||
"sensor_prev": 62.6,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2023,7 +2023,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 9.7560975609756,
|
||||
"sensor_prev": 9.76,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2048,7 +2048,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 4.8780487804878,
|
||||
"sensor_prev": 4.88,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2073,7 +2073,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 7.3170731707317,
|
||||
"sensor_prev": 7.32,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2098,7 +2098,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 8.130081300813,
|
||||
"sensor_prev": 8.13,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2123,7 +2123,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 4.7808764940239,
|
||||
"sensor_prev": 4.78,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2148,7 +2148,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 8.130081300813,
|
||||
"sensor_prev": 8.13,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2173,7 +2173,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 3.2520325203252,
|
||||
"sensor_prev": 3.25,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2223,7 +2223,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 0.8130081300813,
|
||||
"sensor_prev": 0.81,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
@@ -2298,7 +2298,7 @@
|
||||
"sensor_custom": "No",
|
||||
"entPhysicalIndex": null,
|
||||
"entPhysicalIndex_measured": null,
|
||||
"sensor_prev": 92.03187250996,
|
||||
"sensor_prev": 92.03,
|
||||
"user_func": null,
|
||||
"rrd_type": "GAUGE",
|
||||
"state_name": null
|
||||
|
Reference in New Issue
Block a user