feat: initial commit — UniFi snap-in package
Full UniFi dashboard snap-in including: - WiFi/client/device stats with time-series snapshots - Client Dashboard with traffic, satisfaction, signal, download charts - Webhook alerting with debounced offline/online detection - AP snapshot collection, client snapshot collection - Device classification (type and OS) from OUI/hostname heuristics - Webhook cooldown, templates, and multi-platform delivery Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
17
src/Models/ApSnapshot.php
Normal file
17
src/Models/ApSnapshot.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Dashboard\Unifi\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ApSnapshot extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $table = 'unifi_ap_snapshots';
|
||||
protected $fillable = [
|
||||
'ap_mac', 'ap_name', 'num_sta', 'rx_bytes', 'tx_bytes',
|
||||
'tx_retries', 'tx_dropped', 'rx_dropped', 'tx_errors', 'rx_errors',
|
||||
'satisfaction', 'cu_2g', 'cu_5g', 'cu_6g', 'captured_at',
|
||||
];
|
||||
protected $casts = ['captured_at' => 'datetime'];
|
||||
}
|
||||
19
src/Models/ClientSnapshot.php
Normal file
19
src/Models/ClientSnapshot.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Dashboard\Unifi\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ClientSnapshot extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $table = 'unifi_client_snapshots';
|
||||
protected $fillable = [
|
||||
'mac', 'name', 'dev_cat', 'os_name', 'is_wired',
|
||||
'rx_bytes', 'tx_bytes', 'satisfaction', 'signal', 'captured_at',
|
||||
];
|
||||
protected $casts = [
|
||||
'captured_at' => 'datetime',
|
||||
'is_wired' => 'bool',
|
||||
];
|
||||
}
|
||||
13
src/Models/DeviceState.php
Normal file
13
src/Models/DeviceState.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Dashboard\Unifi\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DeviceState extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $table = 'unifi_device_states';
|
||||
protected $fillable = ['device_mac', 'device_name', 'was_online', 'consecutive_count', 'last_seen_at', 'updated_at'];
|
||||
protected $casts = ['was_online' => 'boolean', 'last_seen_at' => 'datetime', 'updated_at' => 'datetime'];
|
||||
}
|
||||
16
src/Models/KnownMac.php
Normal file
16
src/Models/KnownMac.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Dashboard\Unifi\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class KnownMac extends Model
|
||||
{
|
||||
protected $table = 'unifi_known_macs';
|
||||
protected $fillable = ['mac_address', 'device_name', 'device_type', 'owner', 'vlan_id', 'notes'];
|
||||
|
||||
public function setMacAddressAttribute($value)
|
||||
{
|
||||
$this->attributes['mac_address'] = strtolower($value);
|
||||
}
|
||||
}
|
||||
30
src/Models/PortalSession.php
Normal file
30
src/Models/PortalSession.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Dashboard\Unifi\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PortalSession extends Model
|
||||
{
|
||||
protected $table = 'unifi_portal_sessions';
|
||||
protected $fillable = [
|
||||
'user_id', 'mac_address', 'device_hostname', 'device_os', 'device_type',
|
||||
'ssid', 'vlan_id', 'ap_mac', 'is_active', 'authorized_at', 'expires_at',
|
||||
];
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'authorized_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class);
|
||||
}
|
||||
|
||||
public function setMacAddressAttribute($value)
|
||||
{
|
||||
$this->attributes['mac_address'] = strtolower($value);
|
||||
}
|
||||
}
|
||||
11
src/Models/VlanMapping.php
Normal file
11
src/Models/VlanMapping.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Dashboard\Unifi\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VlanMapping extends Model
|
||||
{
|
||||
protected $table = 'unifi_vlan_mappings';
|
||||
protected $fillable = ['group_name', 'match_type', 'match_value', 'vlan_id', 'max_devices', 'session_minutes', 'sort_order'];
|
||||
}
|
||||
14
src/Models/WebhookConfig.php
Normal file
14
src/Models/WebhookConfig.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Dashboard\Unifi\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebhookConfig extends Model
|
||||
{
|
||||
protected $table = 'unifi_webhook_configs';
|
||||
protected $fillable = ['name', 'url', 'secret', 'is_active', 'events', 'thresholds', 'device_filter', 'tracked_clients', 'templates', 'cooldown_minutes'];
|
||||
protected $casts = ['is_active' => 'boolean', 'events' => 'array', 'thresholds' => 'array', 'device_filter' => 'array', 'tracked_clients' => 'array', 'templates' => 'array'];
|
||||
|
||||
public function logs() { return $this->hasMany(WebhookLog::class, 'webhook_config_id'); }
|
||||
}
|
||||
15
src/Models/WebhookLog.php
Normal file
15
src/Models/WebhookLog.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Dashboard\Unifi\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebhookLog extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $table = 'unifi_webhook_logs';
|
||||
protected $fillable = ['webhook_config_id', 'event_type', 'payload', 'response_code', 'response_body', 'fired_at'];
|
||||
protected $casts = ['payload' => 'array', 'fired_at' => 'datetime'];
|
||||
|
||||
public function config() { return $this->belongsTo(WebhookConfig::class, 'webhook_config_id'); }
|
||||
}
|
||||
Reference in New Issue
Block a user