mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Save guessed limits (#16396)
* Save guessed limits Previous code was guessing, then not saving the guess * Move to creating, which revealed that limits were swapped * Apply fixes from StyleCI --------- Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
This commit is contained in:
@@ -99,7 +99,7 @@ class Sensor extends DeviceRelatedModel implements Keyable
|
|||||||
|
|
||||||
public function guessLimits(): void
|
public function guessLimits(): void
|
||||||
{
|
{
|
||||||
$this->sensor_limit = match ($this->sensor_class) {
|
$this->sensor_limit_low = match ($this->sensor_class) {
|
||||||
'temperature' => $this->sensor_current - 10,
|
'temperature' => $this->sensor_current - 10,
|
||||||
'voltage' => $this->sensor_current * 0.85,
|
'voltage' => $this->sensor_current * 0.85,
|
||||||
'humidity' => 30,
|
'humidity' => 30,
|
||||||
@@ -110,7 +110,7 @@ class Sensor extends DeviceRelatedModel implements Keyable
|
|||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->sensor_limit_low = match ($this->sensor_class) {
|
$this->sensor_limit = match ($this->sensor_class) {
|
||||||
'temperature' => $this->sensor_current + 20,
|
'temperature' => $this->sensor_current + 20,
|
||||||
'voltage' => $this->sensor_current * 1.15,
|
'voltage' => $this->sensor_current * 1.15,
|
||||||
'humidity' => 70,
|
'humidity' => 70,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Observers;
|
|||||||
use App\Models\Eventlog;
|
use App\Models\Eventlog;
|
||||||
use App\Models\Sensor;
|
use App\Models\Sensor;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use LibreNMS\Enum\Severity;
|
use LibreNMS\Enum\Severity;
|
||||||
|
|
||||||
class SensorObserver
|
class SensorObserver
|
||||||
@@ -20,6 +21,8 @@ class SensorObserver
|
|||||||
{
|
{
|
||||||
// fix inverted limits
|
// fix inverted limits
|
||||||
if ($sensor->sensor_limit !== null && $sensor->sensor_limit_low !== null && $sensor->sensor_limit_low > $sensor->sensor_limit) {
|
if ($sensor->sensor_limit !== null && $sensor->sensor_limit_low !== null && $sensor->sensor_limit_low > $sensor->sensor_limit) {
|
||||||
|
Log::error('Fixing swapped sensor limits');
|
||||||
|
|
||||||
// Fix high/low thresholds (i.e. on negative numbers)
|
// Fix high/low thresholds (i.e. on negative numbers)
|
||||||
[$sensor->sensor_limit, $sensor->sensor_limit_low] = [$sensor->sensor_limit_low, $sensor->sensor_limit];
|
[$sensor->sensor_limit, $sensor->sensor_limit_low] = [$sensor->sensor_limit_low, $sensor->sensor_limit];
|
||||||
}
|
}
|
||||||
@@ -29,6 +32,14 @@ class SensorObserver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function creating(Sensor $sensor): void
|
||||||
|
{
|
||||||
|
$guess_limits = \LibreNMS\Config::get('sensors.guess_limits', true);
|
||||||
|
if ($guess_limits && $sensor->sensor_current !== null && $sensor->sensor_limit === null && $sensor->sensor_limit_low === null) {
|
||||||
|
$sensor->guessLimits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the service "created" event.
|
* Handle the service "created" event.
|
||||||
*
|
*
|
||||||
@@ -37,11 +48,6 @@ class SensorObserver
|
|||||||
*/
|
*/
|
||||||
public function created(Sensor $sensor): void
|
public function created(Sensor $sensor): void
|
||||||
{
|
{
|
||||||
$guess_limits = \LibreNMS\Config::get('sensors.guess_limits', true);
|
|
||||||
if ($guess_limits && $sensor->sensor_current !== null && $sensor->sensor_limit === null && $sensor->sensor_limit_low === null) {
|
|
||||||
$sensor->guessLimits();
|
|
||||||
}
|
|
||||||
|
|
||||||
EventLog::log('Sensor Added: ' . $sensor->sensor_class . ' ' . $sensor->sensor_type . ' ' . $sensor->sensor_index . ' ' . $sensor->sensor_descr, $sensor->device_id, 'sensor', Severity::Notice, $sensor->sensor_id);
|
EventLog::log('Sensor Added: ' . $sensor->sensor_class . ' ' . $sensor->sensor_type . ' ' . $sensor->sensor_index . ' ' . $sensor->sensor_descr, $sensor->device_id, 'sensor', Severity::Notice, $sensor->sensor_id);
|
||||||
|
|
||||||
if ($this->runningInConsole) {
|
if ($this->runningInConsole) {
|
||||||
|
|||||||
Reference in New Issue
Block a user