Skip to content

Commit

Permalink
cast_number() => Number::cast()
Browse files Browse the repository at this point in the history
  • Loading branch information
mpikzink committed Jan 9, 2025
1 parent 2d63f5f commit 36fa4b9
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 82 deletions.
14 changes: 8 additions & 6 deletions LibreNMS/Device/Sensor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
namespace LibreNMS\Device;

use App\Models\Eventlog;
use Illuminate\Support\Facades\Log;
use LibreNMS\Config;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\Discovery\DiscoveryModule;
use LibreNMS\Interfaces\Polling\PollerModule;
use LibreNMS\OS;
use LibreNMS\RRD\RrdDefinition;
use LibreNMS\Util\Number;
use LibreNMS\Util\StringHelpers;

class Sensor implements DiscoveryModule, PollerModule
Expand Down Expand Up @@ -136,7 +138,7 @@ public function __construct(
$this->valid = is_numeric($this->current);
}

d_echo('Discovered ' . get_called_class() . ' ' . print_r($sensor, true));
Log::debug('Discovered ' . get_called_class() . ' ' . print_r($sensor, true));
}

/**
Expand Down Expand Up @@ -323,14 +325,14 @@ protected static function pollSensorType($os, $type, $sensors, $prefetch = [])
// process data or run custom polling
$typeInterface = static::getPollingInterface($type);
if ($os instanceof $typeInterface) {
d_echo("Using OS polling for $type\n");
Log::debug("Using OS polling for $type\n");
$function = static::getPollingMethod($type);
$data = $os->$function($sensors);
} else {
$data = static::processSensorData($sensors, $prefetch);
}

d_echo($data);
Log::debug($data);

self::recordSensorData($os, $sensors, $data);
}
Expand All @@ -357,7 +359,7 @@ private static function fetchSnmpData($device, $sensors)
array_walk($snmp_data, function (&$oid) {
preg_match('/-?\d+(\.\d+)?(e-?\d+)?/i', $oid, $matches);
if (isset($matches[0])) {
$oid = cast_number($matches[0]);
$oid = Number::cast($matches[0]);
} else {
$oid = trim('"', $oid); // allow string only values
}
Expand Down Expand Up @@ -409,11 +411,11 @@ protected static function processSensorValue(array $data, string $aggregator, in
}

if ($divisor && $sensor_value !== 0) {
$sensor_value = (cast_number($sensor_value) / $divisor);
$sensor_value = (Number::cast($sensor_value) / $divisor);
}

if ($multiplier) {
$sensor_value = (cast_number($sensor_value) * $multiplier);
$sensor_value = (Number::cast($sensor_value) * $multiplier);
}

return $sensor_value;
Expand Down
3 changes: 2 additions & 1 deletion LibreNMS/OS/Arubaos.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use LibreNMS\Interfaces\Discovery\Sensors\WirelessUtilizationDiscovery;
use LibreNMS\Interfaces\Polling\Sensors\WirelessFrequencyPolling;
use LibreNMS\OS;
use LibreNMS\Util\Number;
use SnmpQuery;

class Arubaos extends OS implements
Expand Down Expand Up @@ -162,7 +163,7 @@ public function discoverWirelessPower()

protected function decodeChannel($channel)
{
return cast_number($channel) & 255; // mask off the channel width information
return Number::cast($channel) & 255; // mask off the channel width information
}

private function discoverInstantRadio($type, $oid, $desc = 'Radio %s')
Expand Down
Loading

0 comments on commit 36fa4b9

Please sign in to comment.