Hello
I am wondering how I could get the state_translation achieved with the Model code structure (instead of doing selects in the code) ?
Here is the code (snmptrap handling) :
public function handle(Device $device, Trap $trap)
{
$device_array = $device->toArray();
$sensor = $device->sensors()->where('sensor_type', 'upsmgInputBadStatus')->first();
if (!$sensor) {
Log::warning("Snmptrap UpsmgUtilityRestored: Could not find matching sensor upsmgInputBadStatus for device: " . $device->hostname);
return;
}
$sensor->sensor_current = 2;
$sensor->save();
log_event("UPS power restored, state sensor " . $sensor->sensor_descr . " has changed to ".$sensor->sensor_current . ".", $device_array, "Power", 1);
}
The goal is to replace $sensor->sensor_current with its textual equivalent.
This can be done with select like in “./includes/polling/functions.inc.php” line 206 but the Object way would make more sense, I suppose.
Thanx
PipoCanaja