PHP code example of nawasara / alerting

1. Go to this page and download the library: Download nawasara/alerting library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nawasara / alerting example snippets


use Nawasara\Alerting\Facades\Alerter;
use Nawasara\Alerting\Models\AlertRule;

public function boot(): void
{
    Alerter::registerRule(AlertRule::make([
        'key' => 'proxmox.node.disk_critical',
        'severity' => 'critical',
        'category' => 'infrastructure',
        'cooldown_minutes' => 60,
        'description' => 'Node disk usage ≥ 95%',
        'subject_template' => '[CRITICAL] Disk hampir penuh di {context.node}: {context.disk_pct}%',
    ]));
}

Alerter::fire(
    ruleKey: 'proxmox.node.disk_critical',
    targetType: 'ProxmoxNode',
    targetId: (string) $node->id,
    context: [
        'node' => $node->name,
        'disk_pct' => 96.3,
        'storage' => 'local-lvm',
    ],
);

Alerter::resolve(
    ruleKey: 'proxmox.node.disk_critical',
    targetType: 'ProxmoxNode',
    targetId: (string) $node->id,
);
bash
composer migrate
php artisan db:seed --class="Nawasara\Alerting\Database\Seeders\PermissionSeeder"