Use standard sensor type names

This commit is contained in:
Tony Murray 2020-04-19 01:11:45 -05:00
parent fcbafbf577
commit 9eee7fad58
3 changed files with 35 additions and 29 deletions

View File

@ -55,33 +55,7 @@ class Sensor extends DeviceRelatedModel
public static function getTypes() public static function getTypes()
{ {
return ['Airflow', return array_keys(self::$icons);
'ber',
'Battery Charge',
'chromatic_dispersion',
'Cooling',
'count',
'Current',
'dBm',
'delay',
'Energy Efficiency Ratio',
'Fanspeed',
'Frequency',
'Humidity',
'Load',
'power_consumed',
'power_factor',
'Power',
'Pressure',
'quality_factor',
'Runtime',
'Wireless',
'snr',
'State',
'Temperature',
'Voltage',
'Water Flow Rate',
];
} }
// for the legacy menu // for the legacy menu

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class EventlogSensorReferenceCleanup extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
foreach (\App\Models\Sensor::getTypes() as $type) {
DB::table('eventlog')->where('type', ucfirst($type))->update(['type' => $type]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
foreach (\App\Models\Sensor::getTypes() as $type) {
DB::table('eventlog')->where('type', $type)->update(['type' => ucfirst($type)]);
}
}
}

View File

@ -199,10 +199,10 @@ function record_sensor_data($device, $all_sensors)
// FIXME also warn when crossing WARN level! // FIXME also warn when crossing WARN level!
if ($sensor['sensor_limit_low'] != '' && $prev_sensor_value > $sensor['sensor_limit_low'] && $sensor_value < $sensor['sensor_limit_low'] && $sensor['sensor_alert'] == 1) { if ($sensor['sensor_limit_low'] != '' && $prev_sensor_value > $sensor['sensor_limit_low'] && $sensor_value < $sensor['sensor_limit_low'] && $sensor['sensor_alert'] == 1) {
echo 'Alerting for '.$device['hostname'].' '.$sensor['sensor_descr']."\n"; echo 'Alerting for '.$device['hostname'].' '.$sensor['sensor_descr']."\n";
log_event("$class under threshold: $sensor_value $unit (< {$sensor['sensor_limit_low']} $unit)", $device, $class, 4, $sensor['sensor_id']); log_event("$class under threshold: $sensor_value $unit (< {$sensor['sensor_limit_low']} $unit)", $device, $sensor['sensor_class'], 4, $sensor['sensor_id']);
} elseif ($sensor['sensor_limit'] != '' && $prev_sensor_value < $sensor['sensor_limit'] && $sensor_value > $sensor['sensor_limit'] && $sensor['sensor_alert'] == 1) { } elseif ($sensor['sensor_limit'] != '' && $prev_sensor_value < $sensor['sensor_limit'] && $sensor_value > $sensor['sensor_limit'] && $sensor['sensor_alert'] == 1) {
echo 'Alerting for '.$device['hostname'].' '.$sensor['sensor_descr']."\n"; echo 'Alerting for '.$device['hostname'].' '.$sensor['sensor_descr']."\n";
log_event("$class above threshold: $sensor_value $unit (> {$sensor['sensor_limit']} $unit)", $device, $class, 4, $sensor['sensor_id']); log_event("$class above threshold: $sensor_value $unit (> {$sensor['sensor_limit']} $unit)", $device, $sensor['sensor_class'], 4, $sensor['sensor_id']);
} }
if ($sensor['sensor_class'] == 'state' && $prev_sensor_value != $sensor_value) { if ($sensor['sensor_class'] == 'state' && $prev_sensor_value != $sensor_value) {
$trans = array_column( $trans = array_column(