🔧 Extending Monitron
Monitron SaaS is designed to be extensible. Here's how to add new monitor types, notification channels, and AI features.
📡 Adding a New Monitor Type
Step 1: Add to Enum
// app/Enums/MonitorType.php
case MY_CUSTOM = 'my_custom';
Add label, color, icon, category, and default port in the respective methods.
Step 2: Create Handler
// app/Monitors/MyCustomMonitor.php
<?php
namespace App\Monitors;
use App\DTOs\MonitorCheckResult;
use App\Enums\MonitorStatus;
use App\Enums\MonitorType;
use App\Models\Monitor;
use App\Monitors\Contracts\MonitorHandler;
class MyCustomMonitor implements MonitorHandler
{
public function check(Monitor $monitor): MonitorCheckResult
{
$start = microtime(true);
try {
// Your check logic here
$success = true;
$responseTime = (microtime(true) - $start) * 1000;
return new MonitorCheckResult(
status: $success ? MonitorStatus::UP : MonitorStatus::DOWN,
responseTimeMs: (int) $responseTime,
);
} catch (\Throwable $e) {
return new MonitorCheckResult(
status: MonitorStatus::DOWN,
errorMessage: $e->getMessage(),
);
}
}
public function type(): MonitorType
{
return MonitorType::MY_CUSTOM;
}
}
Step 3: Register Handler
// app/Services/MonitorRegistry.php
// Add to the constructor or register method:
$this->register('my_custom', MyCustomMonitor::class);
Step 4: Add Form Fields
In MonitorResource.php, add a section for your type's specific configuration fields.
🔔 Adding a New Notification Channel
Step 1: Add to Enum
// app/Enums/NotificationChannel.php
case MY_CHANNEL = 'my_channel';
Step 2: Add Dispatch Method
// app/Services/NotificationDispatcher.php
protected function sendMyChannel(array $config, string $message, array $context): bool
{
// Your notification logic
return true;
}
Step 3: Wire into Dispatch
Add a case for your channel in the main dispatch() method of NotificationDispatcher.
🤖 Adding a New AI Feature
Step 1: Create Service
// app/Services/AI/MyFeature.php
<?php
namespace App\Services\AI;
class MyFeature
{
public function __construct(protected AiService $ai) {}
public function analyze(): ?array
{
if (!$this->ai->isConfigured()) return null;
return $this->ai->json(
'Your system prompt here',
'Your user message with context'
);
}
}
Step 2: Register as Singleton
// app/Providers/MonitorServiceProvider.php
$this->app->singleton(MyFeature::class);
Step 3: Add Toggle
Add a toggle in AiSettings.php and check it before using the feature.