2021-10-06 07:29:47 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use LibreNMS\Alert\Transport;
|
2023-05-23 09:25:17 -05:00
|
|
|
use LibreNMS\Alert\Transport\Dummy;
|
2021-10-06 07:29:47 -05:00
|
|
|
|
|
|
|
|
class AlertTransport extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
protected $primaryKey = 'transport_id';
|
|
|
|
|
public $timestamps = false;
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'is_default' => 'boolean',
|
|
|
|
|
'transport_config' => 'array',
|
|
|
|
|
];
|
2023-05-23 09:25:17 -05:00
|
|
|
protected $fillable = ['transport_config'];
|
2021-10-06 07:29:47 -05:00
|
|
|
|
|
|
|
|
public function instance(): Transport
|
|
|
|
|
{
|
|
|
|
|
$class = Transport::getClass($this->transport_type);
|
|
|
|
|
|
2023-05-23 09:25:17 -05:00
|
|
|
if (class_exists($class)) {
|
|
|
|
|
return new $class($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Dummy;
|
2021-10-06 07:29:47 -05:00
|
|
|
}
|
|
|
|
|
}
|