# CFM

Cybersecurity &amp; Firewall Manager Documentation

# Overview

Project purpose, structure, key components

# Overview

\# CFM Project Overview

\## Purpose  
CFM is a Security - Firewall Management project designed to manage spam detection, blocklists, feed processing, and admin control using a web interface.

\## Layers  
\- Models: Handle data and relationships  
\- Controllers: Process web/API requests  
\- Commands: Automate backend tasks  
\- Filament: Admin UI for managing keywords, feeds, and settings  
\- Routes: Web and API access  
\- Cron Jobs: Scheduled feed updates and maintenance

\## Key Features  
\- Spam keyword detection (loose &amp; strict modes)  
\- Blocklist/whitelist management (IP and domain-based)  
\- Feed processing system (with logging and rule generation)  
\- Central API for querying blocklists  
\- Admin UI for managing everything  
\- Clamav Rule generation  
\- Phishlist database  
\- RBLDNS database  
\- Hash Management (MD5 / SHA1 / SHA2) for Clamav signatures  
\- Mail filters  
\- Synchronizing files to server through agents  
\- Updating lists through agents  
\- Manage global user unblocking

This documentation is organized by feature and component to help understand and extend the system.

# Introduction - Welcome to CFM

## 🚀 CFM Feature Summary

CFM is a powerful system for managing threat intelligence, spam filtering, phishing protection, and reputation data — backed by automation and agent-based sync.

---

### 🛡️ Security &amp; Threat Intelligence

- **Blocklist &amp; Whitelist Management** (IP &amp; domain)
- **Reverse DNS**, **ASN**, **GeoIP**, and **country resolution**
- **Keyword-based spam detection**
- **Phishing URL detection &amp; logging**

---

### 🔁 Automation &amp; Scheduling

- Scheduled **feed imports**, **auto-deletion**, and **rule generation**
- Commands for IP list generation, rule updates, config sync
- Cron-style job scheduling with overlap protection

---

### 🛰️ Agent Infrastructure (C++-Based)

- Syncs config and rule files
- Reports **blocks**, **unblocks**, and **last seen**
- Triggers service restarts after updates
- Integrates with unblock portal for auto-removal
- Sends **Slack alerts** for offline agents

---

### 🧪 Antivirus &amp; RBL Integration

- Generates **ClamAV signatures** from phishing URLs and file hashes (MD5/SHA1/SHA256)
- Maintains **SpamAssassin-compatible phishing DB**
- Exports **RBL and URIBL zones** for RBLDNSD

---

### 💻 API &amp; External Access

- Token-authenticated API for:
    
    
    - Checking block status
    - Reporting blocks/unblocks
    - Fetching rules/feeds
    - Submitting config/trigger reports
- Optional **rate limiting** and **IP filtering**

---

### 📊 Admin Panel (Filament)

- Dashboard with real-time widgets and charts
- Interfaces for:
    
    
    - Spam keywords
    - Block/allow lists
    - Feed logs
    - Unblock requests
    - Agent activity

---

### 🌐 Web Interface

- Public-facing **Unblock Request Form**
- Feed endpoints (IP, domain, phishing, etc.)
- Admin redirect and login flow

---

### 💡 Bonus Features

- File-based config sync with integrity hashing
- Config-targeting for agent groups
- Slack alerts and activity logs
- Multi-source feed support (manual, API, auto)

### 🔑 Key Features

✅ **Blocklist &amp; Whitelist Management**  
Manage IPs and domains across multiple lists, including manual entries, feed imports, and API-reported threats.

✅ **Spam &amp; Phishing Protection**

- Keyword-based spam filtering (supports Greek/Greeklish, loose/strict)
- Maintains a live phishing URL database
- Generates **ClamAV-compatible** virus definitions from phishing URLs and file hashes (MD5/SHA1/SHA256)

✅ **RBL &amp; URIBL Generator**  
Creates real-time blocklists and URI lists (RBLDNSD format) for DNS-based blacklisting — used by SpamAssassin, Postfix, etc.

✅ **GeoIP Intelligence for Blocklist Entries**  
Automatically resolves:

- Reverse DNS (PTR)
- ASN and ISP
- Country and region This enables rich filtering, analytics, and decision-making.

✅ **Automated Feed Processing**  
Processes threat feeds on a schedule with logs and rule generation.

✅ **Agent Communication &amp; API**  
Lightweight agents (or servers) can:

- Report blocked IPs back to CFM
- Fetch updates and policy
- Submit files, triggers, logs, etc.

✅ **Dashboard with Widgets &amp; Metrics**  
Summarized view of:

- Top IPs by country or source
- Phishing trends
- Recent feed activity
- System health and jobs

✅ **Unblock Request Portal**  
Public-facing form for users to request delisting — reviewed via admin panel.

✅ **Full Admin UI via Filament**  
Modern interface for managing:

- Spam keywords
- Feeds &amp; logs
- Phishing database
- Block/allow lists
- Scheduled jobs
- Settings &amp; tokens

✅ **Scheduled Jobs &amp; Artisan Tools**

- Generate IP and domain blocklists
- Run cleanup jobs
- Sync filesystem configs
- Rebuild ClamAV signatures
- Trigger per-feed processing

✅ **Agent Infrastructure (C++ Powered)**  
Includes high-performance **C++ agents** deployed on remote servers that:

- 🔄 Sync configuration and rule files from CFM
- 📤 Report blocked and unblocked IPs
- 🧼 Remove blocks upon updates or unblocks
- ♻️ Restart services (e.g., mail, firewall) when needed
- 🧭 Report "last seen" heartbeat to monitor health
- 🔔 Trigger Slack alerts if an agent goes offline
- 🤝 Integrate with the public unblock form to re-allow mistakenly blocked users

✅ **Blocklist &amp; Whitelist Management**  
Manage IPs and domains across multiple lists (manual, API, or feed-driven), enriched with PTR, ASN, country, and GeoIP.

✅ **Phishing &amp; Spam Defense**

- Greek-aware spam keyword detection (strict/loose)
- Maintains a phishing URL database
- Generates **ClamAV virus signatures** from URLs and hashes (MD5/SHA1/SHA256)
- Exports phishing data for **SpamAssassin compatibility**

✅ **RBL &amp; URIBL Generation**  
Creates and serves real-time DNS blacklists (RBLDNSD format) for both IP and domain-based blocklists.

✅ **Scheduled Feed Ingestion &amp; Rule Generation**  
Automates external feed syncing and keyword/rule building via Laravel Scheduler and Artisan commands.

✅ **Admin Dashboard**  
Modern UI with dashboard widgets, charts, and management panels for:

- Blocked items
- Keyword rules
- Feed logs
- Unblock requests
- Agent status

✅ **Unblock Request Portal**  
Frontend form where blocked users can request removal — triggers backend unblock workflows and agent sync.

✅ **API Interface**  
Secure, token-authenticated API to:

- Check IP/domain status
- Report blocks/unblocks
- Pull feed or rule updates
- Trigger diagnostics or config checks

✅ **ClamAV + CSF Integration**  
Outputs live files for:

- IP blocklists (`csf.deny`)
- ClamAV custom signatures
- RBLDNSD-based DNS lists

---

### 💡 Bonus Features

- Slack integration for agent down alerts
- Per-country analytics of blocked IPs
- Top reporters / sources breakdown
- File-based config sync and hashing
- Agent group targeting for rules

---

---

### 🧠 Use Cases

- Internal **spam firewall**
- Self-hosted **RBL/URIBL provider**
- **CSF / UFW / iptables** blocklist hub
- Aggregator for multiple **threat feeds**
- **Email security gateway** enhancement
- Coordinated threat response via **reporting agents**

---

### 💡 Built With

- Laravel + Filament (UI)
- MySQL (DB)
- Tailwind (optional UI)
- GeoLite2 (GeoIP)
- Artisan + Laravel Scheduler
- RBLDNSD &amp; SpamAssassin compatibility
- API-first design

# Models

Model summaries, fields, relationships, usage

# Models Overview

This project includes the following Eloquent models, each representing a key part of the system's architecture:

<div class="overflow-x-auto contain-inline-size" id="bkmrk-model-purpose-%2F-desc"><table data-end="1774" data-start="285"><thead data-end="331" data-start="285"><tr data-end="331" data-start="285"><th data-end="306" data-start="285">Model</th><th data-end="331" data-start="306">Purpose / Description</th></tr></thead><tbody data-end="1774" data-start="380"><tr data-end="452" data-start="380"><td>`Agent`</td><td>Represents remote scanning or reporting agents.</td></tr><tr data-end="531" data-start="453"><td>`AgentGroup`</td><td>Groups agents for easier configuration and targeting.</td></tr><tr data-end="603" data-start="532"><td>`AutoDeleteRule`</td><td>Defines automatic deletion logic for old data.</td></tr><tr data-end="675" data-start="604"><td>`Blocklist`</td><td>Stores IPs flagged as malicious or suspicious.</td></tr><tr data-end="771" data-start="676"><td>`Config`</td><td>Represents configuration entries, either file-based or database-based.</td></tr><tr data-end="839" data-start="772"><td>`ConfigTarget`</td><td>Associates configs with agents or systems.</td></tr><tr data-end="925" data-start="840"><td>`DataFeed`</td><td>Represents external data sources (e.g., threat intel feeds).</td></tr><tr data-end="1004" data-start="926"><td>`ExecutionTarget`</td><td>Tracks where specific actions or rules were executed.</td></tr><tr data-end="1078" data-start="1005"><td>`Hash`</td><td>Handles hash-based uniqueness or matching logic.</td></tr><tr data-end="1155" data-start="1079"><td>`MailFeeder`</td><td>Ingests and analyzes email headers or body content.</td></tr><tr data-end="1226" data-start="1156"><td>`MailFromFilter`</td><td>Applies filtering rules based on mail sender.</td></tr><tr data-end="1285" data-start="1227"><td>`Notifier`</td><td>Manages alerts and notifications.</td></tr><tr data-end="1343" data-start="1286"><td>`PhishList`</td><td>Stores phishing domains or URLs.</td></tr><tr data-end="1422" data-start="1344"><td>`RbldnsdUri`</td><td>Manages RBLDNSD-compatible URI blocklists/whitelists.</td></tr><tr data-end="1513" data-start="1423"><td>`SpamKeyword`</td><td>Contains keyword rules for spam detection (Greek/Greeklish/etc.).</td></tr><tr data-end="1575" data-start="1514"><td>`Token`</td><td>Access tokens for API or agent auth.</td></tr><tr data-end="1638" data-start="1576"><td>`Trigger`</td><td>Defines rule triggers and conditions.</td></tr><tr data-end="1703" data-start="1639"><td>`UnblockRequest`</td><td>Handles user-submitted unblock appeals.</td></tr><tr data-end="1774" data-start="1704"><td>`User`</td><td>Represents authenticated users in the system.</td></tr></tbody></table>

</div>

# API Routes

Route list, methods, paths, expected input/output

# API routes

## API Routes

These routes provide a secure, token-authenticated interface for interacting with blocklists, agent configurations, and unblocking systems.

All routes are protected via the `TokenAuthentication` middleware.

---

### 🔒 Authentication

All API endpoints require a valid token passed via headers or parameters.

---

### 📌 Blocklist Endpoints

<div class="overflow-x-auto contain-inline-size" id="bkmrk-method-path-descript"><table data-end="961" data-start="469"><thead data-end="550" data-start="469"><tr data-end="550" data-start="469"><th data-end="478" data-start="469">Method</th><th data-end="508" data-start="478">Path</th><th data-end="550" data-start="508">Description</th></tr></thead><tbody data-end="961" data-start="633"><tr data-end="714" data-start="633"><td>POST</td><td>`/blocklist/report`</td><td>Report an IP to be blocked</td></tr><tr data-end="797" data-start="715"><td>POST</td><td>`/blocklist/unblock`</td><td>Request removal of an IP from blocklist</td></tr><tr data-end="879" data-start="798"><td>GET</td><td>`/blocklist/check`</td><td>Check if an IP is blocked</td></tr><tr data-end="961" data-start="880"><td>GET</td><td>`/blocklist/fetch`</td><td>Fetch all blocklisted IPs</td></tr></tbody></table>

</div>---

### 📌 Whitelist Endpoints

<div class="overflow-x-auto contain-inline-size" id="bkmrk-method-path-descript-1"><table data-end="1323" data-start="996"><thead data-end="1077" data-start="996"><tr data-end="1077" data-start="996"><th data-end="1005" data-start="996">Method</th><th data-end="1035" data-start="1005">Path</th><th data-end="1077" data-start="1035">Description</th></tr></thead><tbody data-end="1323" data-start="1160"><tr data-end="1241" data-start="1160"><td>POST</td><td>`/whitelist/report`</td><td>Report a whitelisted IP or domain</td></tr><tr data-end="1323" data-start="1242"><td>POST</td><td>`/whitelist/remove`</td><td>Remove a record from the whitelist</td></tr></tbody></table>

</div>---

### 🛰️ Agent Endpoints

<div class="overflow-x-auto contain-inline-size" id="bkmrk-method-path-descript-2"><table data-end="1948" data-start="1355"><thead data-end="1453" data-start="1355"><tr data-end="1453" data-start="1355"><th data-end="1369" data-start="1355">Method</th><th data-end="1409" data-start="1369">Path</th><th data-end="1453" data-start="1409">Description</th></tr></thead><tbody data-end="1948" data-start="1553"><tr data-end="1651" data-start="1553"><td>GET/POST</td><td>`/agent/config-check`</td><td>Validate agent config from server side</td></tr><tr data-end="1750" data-start="1652"><td>GET/POST</td><td>`/agent/list-files`</td><td>List tracked files for integrity checks</td></tr><tr data-end="1849" data-start="1751"><td>GET</td><td>`/blocklist/pending-unblocks`</td><td>Fetch unblock requests for review</td></tr><tr data-end="1948" data-start="1850"><td>POST</td><td>`/blocklist/unblock-confirm`</td><td>Confirm that an IP was unblocked</td></tr></tbody></table>

</div>---

These routes form the backbone of external system interaction with the CFM platform, especially useful for:

- **Server agents** checking their config
- **Security automation** scripts reporting IPs
- **Unblock portals** submitting requests for delisting

## 🌐 Web Routes

These routes handle the core frontend and admin-facing interactions, including redirects, unblock forms, and feed outputs.

---

### 🏠 Root Redirect

<div class="overflow-x-auto contain-inline-size" id="bkmrk-method-path-behavior"><table data-end="428" data-start="287"><thead data-end="315" data-start="287"><tr data-end="315" data-start="287"><th data-end="296" data-start="287">Method</th><th data-end="303" data-start="296">Path</th><th data-end="315" data-start="303">Behavior</th></tr></thead><tbody data-end="428" data-start="345"><tr data-end="428" data-start="345"><td>GET</td><td>`/`</td><td>Redirects to `/admin` if logged in, otherwise to `/admin/login`</td></tr></tbody></table>

</div>---

### 🔓 Public Unblock Interface

<div class="overflow-x-auto contain-inline-size" id="bkmrk-method-path-descript-3"><table data-end="731" data-start="468"><thead data-end="533" data-start="468"><tr data-end="533" data-start="468"><th data-end="477" data-start="468">Method</th><th data-end="491" data-start="477">Path</th><th data-end="533" data-start="491">Description</th></tr></thead><tbody data-end="731" data-start="600"><tr data-end="665" data-start="600"><td>GET</td><td>`/unblock`</td><td>Shows unblock request form</td></tr><tr data-end="731" data-start="666"><td>POST</td><td>`/unblock`</td><td>Submits unblock request to backend</td></tr></tbody></table>

</div>Used by users or systems mistakenly blocked to appeal removal.

---

### 📄 Feed Files (Token Protected)

Accessible only with valid token via `TokenAuthentication`.

<div class="overflow-x-auto contain-inline-size" id="bkmrk-method-path-descript-4"><table data-end="1424" data-start="900"><thead data-end="974" data-start="900"><tr data-end="974" data-start="900"><th data-end="909" data-start="900">Method</th><th data-end="935" data-start="909">Path</th><th data-end="974" data-start="935">Description</th></tr></thead><tbody data-end="1424" data-start="1050"><tr data-end="1124" data-start="1050"><td>GET</td><td>`/whitelist.txt`</td><td>IP/domain whitelist</td></tr><tr data-end="1199" data-start="1125"><td>GET</td><td>`/blacklist.txt`</td><td>IP blacklist (for CSF, etc.)</td></tr><tr data-end="1274" data-start="1200"><td>GET</td><td>`/phishlist.txt`</td><td>Phishing domain list</td></tr><tr data-end="1349" data-start="1275"><td>GET</td><td>`/domainblacklist.txt`</td><td>Domain blocklist for RBLDNSD</td></tr><tr data-end="1424" data-start="1350"><td>GET</td><td>`/domainwhitelist.txt`</td><td>Domain whitelist for RBLDNSD</td></tr></tbody></table>

</div>

# Artisan Commands and Scheduled Tasks (Crons)

Command list, arguments/options, usage

# Artisan Commands

# Command Line Commands (Artisan)

CFM includes a number of custom Laravel Artisan commands to help automate and manage blocklists, phishing detection, feed ingestion, and other system behaviors.

To view available commands, use the following in your project root:

```
php artisan
```

Below is an overview of the key command groups available in CFM:

<div id="bkmrk-">---

</div>## 🔌 `agents`

<table id="bkmrk-command-description-"><tbody><tr><th>Command</th><th>Description</th></tr><tr><td>`agents:check-notifications`</td><td>Checks the last-seen status of each agent and sends notifications (e.g., Slack) if any are down.</td></tr></tbody></table>

<div id="bkmrk--1">---

</div>## 🗑️ `autodelete`

<table id="bkmrk-command-description--1"><tbody><tr><td>Command</td><td>Description</td></tr><tr><td>`autodelete:run`</td><td>Runs `AutoDeleteJob` to remove old records (e.g., blocklist entries, logs) based on custom rules.</td></tr></tbody></table>

<div id="bkmrk--2">---

</div>## 🚫 `blocklist`

<table id="bkmrk-command-description--2"><tbody><tr><td>Command</td><td>Description</td></tr><tr><td>`blocklist:fetch-geodata`</td><td>Bulk fetches GeoIP data for blocklist entries (country, ASN, etc.).</td></tr><tr><td>`blocklist:resolve-geodata`</td><td>Resolves GeoIP data with optional processing limits for batching.</td></tr><tr><td>`blocklist:resolve-ptr`</td><td>Resolves PTR (Reverse DNS) records for IPs in batches. Parallel processing supported.</td></tr></tbody></table>

<div id="bkmrk--3">---

</div>## 🧹 `cache`

<table id="bkmrk-command-description--3"><tbody><tr><td>Command</td><td>Description</td></tr><tr><td>`cache:clear`</td><td>Clears the Laravel application cache.</td></tr></tbody></table>

<div id="bkmrk--4">---

</div>## 🦠 `clamav`

<table id="bkmrk-command-description--4"><tbody><tr><td>Command</td><td>Description</td></tr><tr><td>`clamav:generate-signatures`</td><td>Generates ClamAV-compatible signature files from phishing URLs and malware file hashes (MD5, SHA1, SHA256).</td></tr></tbody></table>

<div id="bkmrk--5">---

</div>## ⚙️ `config`

> *This section may include config sync-related commands, depending on future additions.*

<div id="bkmrk--6">---

</div>## 🌐 `data-feeds`

<table id="bkmrk-command-description--5"><tbody><tr><td>Command</td><td>Description</td></tr><tr><td>`data-feeds:fetch`</td><td>Fetches and processes all active data feeds configured in the system.</td></tr><tr><td>`import:blocklist`</td><td>Imports a list of IPs into the blocklist, whitelist, or greylist.</td></tr><tr><td>`import:domains`</td><td>Imports domains into the blocklist or whitelist.</td></tr><tr><td>`import:mail-filters`</td><td>Imports email sender/domain filters from a file.</td></tr></tbody></table>

<div id="bkmrk--7">---

</div>## 📄 `iplists`

<table id="bkmrk-command-description--6"><tbody><tr><td>Command</td><td>Description</td></tr><tr><td>`iplists:generate`</td><td>Generates `whitelist.txt`, `greylist.txt`, and `blacklist.txt` files from the database for CSF or DNS use.</td></tr></tbody></table>

<div id="bkmrk--8">---

</div>## 📬 `mailfromfilters`

<table id="bkmrk-command-description--7"><tbody><tr><td>Command</td><td>Description</td></tr><tr><td>`mailfromfilters:generate`</td><td>Generates `mailfromfilters.cf` used by the mail filtering system, based on DB entries.</td></tr></tbody></table>

<div id="bkmrk--9">---

</div>## 🧠 `spamassassin`

<table id="bkmrk-command-description--8"><tbody><tr><td>Command</td><td>Description</td></tr><tr><td>`spamassassin:generate-rules`</td><td>Generates a SpamAssassin custom keyword rule file from the `spam_keywords` table. Supports strict and loose matching, Greek normalization, etc.</td></tr></tbody></table>

<div id="bkmrk--10">---

</div>These commands allow you to maintain and automate your security infrastructure directly from the console, and can be scheduled or run on-demand as needed.

# Scheduled Tasks / Cron and Supervisor settings

## ⏱️ Scheduled Commands (Cron)

Scheduled tasks are defined in `routes/console.php` and executed using Laravel's `schedule:run` command. They can be run via a cron shell script or with a process manager like **Supervisor**.

### Shell Cron Example:

\#!/bin/bash  
cd "$(dirname "$0")"  
php artisan schedule:run &gt;&gt; /dev/null 2&gt;&amp;1

### Supervisor Setup (Recommended)

**Service file:** `supervisor.service`

\[Unit\]  
Description=Supervisor process control system for UNIX  
After=network.target

\[Service\]  
ExecStart=/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf  
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown  
ExecReload=/usr/bin/supervisorctl -c /etc/supervisor/supervisord.conf $OPTIONS reload  
Restart=on-failure  
RestartSec=50s

**Program config:** `/etc/supervisor/conf.d/cfm.conf`

\[program:cfm\]  
command=php /home/cfm/artisan queue:work redis --memory=2048 --tries=3 --timeout=600  
user=cfm  
autostart=true  
autorestart=true  
numprocs=2  
redirect\_stderr=true  
stdout\_logfile=/var/log/supervisor/cfm.log

### Scheduled Commands

<table id="bkmrk-command-schedule-des"><tbody><tr><td>Command</td><td>Schedule</td><td>Description</td></tr><tr><td>`iplists:generate`</td><td>Every 10 minutes</td><td>Generate updated IP lists from the DB</td></tr><tr><td>`clamav:generate-signatures`</td><td>Hourly at :50</td><td>Generate ClamAV signature files</td></tr><tr><td>`agents:check-notifications`</td><td>Every minute</td><td>Check agent status and send alerts</td></tr><tr><td>`autodelete:run`</td><td>Daily at 08:00</td><td>Run AutoDelete cleanup job</td></tr><tr><td>`config:sync-storage`</td><td>Every 5 minutes</td><td>Sync configuration files from disk</td></tr><tr><td>`blocklist:resolve-ptr`</td><td>Every 10 minutes</td><td>Resolve PTR records in batches</td></tr><tr><td>`blocklist:resolve-geodata`</td><td>Every 10 minutes</td><td>Resolve ASN/Country data in bulk</td></tr><tr><td>`unblocks:cleanup`</td><td>Every 5 minutes</td><td>Cleanup old unblock requests</td></tr><tr><td>`phishlist:generate`</td><td>Every 30 minutes</td><td>Regenerate phishing domain list</td></tr><tr><td>`mailfromfilters:generate`</td><td>Hourly</td><td>Regenerate mailfromfilters.cf</td></tr><tr><td>`execution:dispatch`</td><td>Every minute</td><td>Dispatch queued execution rules</td></tr><tr><td>`DataFeedJob (callback)`</td><td>Every minute</td><td>Dispatch data feed jobs for active feeds</td></tr></tbody></table>

These scheduled commands are critical for keeping data up-to-date, automating cleanup, syncing feeds and configurations, and dispatching jobs to agents or queues.

# DataFeedProcessor

How the core logic handles feeds

# Admin Interface

Pages, forms, tables, actions

# Configuration

.env setup, configs, scheduler, RBL settings

# Integration / Agent Guide

How external systems use the API or CLI

# Testing

Example API tests, test scenarios

# FAQ / Common Scenarios

Troubleshooting, usage examples

# Notification handling

- How the system handles and works around with notifications.

# Notifications  & Triggers

# 📡 CFM Notifications System

## Overview

The **CFM Notifications System** monitors the availability of network agents and provides customizable alerting when agents go offline or recover. It also integrates with **user-triggered unblock request monitoring**, helping administrators stay informed about potential abuse or false positives in blocking behavior.

The system is composed of four coordinated components:

1. **Agent Uptime Monitoring Controller**
2. **Notifier Configuration Resource**
3. **Trigger Mechanism Resource**
4. **Unblock Request Monitoring**

These components work together to detect agent status changes, define notification methods, and execute appropriate alerting workflows.

---

## 1. 🧭 Agent Uptime Monitoring

**Component**: `AgentNotificationController`

This controller is responsible for continuously checking the status of registered agents. It does so by comparing each agent's last heartbeat timestamp (`last_seen_at`) against the current time. If an agent hasn't communicated within a predefined time window (e.g., 60 seconds), it is considered **offline**.

### Key Behaviors

- **Recovery Detection**: If an agent previously marked as offline starts reporting again, the system logs a restoration event.
- **Outage Detection**: Agents not seen in the defined window are marked as down.
- **Notification Throttling**: Notifications are suppressed if a recent alert was already sent (e.g., within the past hour), avoiding redundant notifications.

---

## 2. 📣 Notifier Configuration

**Component**: `NotifierResource`

This resource allows administrators to configure various **notification channels**, which define **how alerts are sent**.

### Supported Notifier Types (examples):

- Email
- Slack
- Webhook
- Custom API callouts

Each notifier contains:

- A unique name.
- A target configuration (e.g., email address or webhook URL).
- A type identifier (used to trigger the appropriate method).
- Optionally, a list of tags or filters to determine relevance to specific agents.

---

## 3. 🎯 Trigger Mechanism

**Component**: `TriggerResource`

This module acts as the **brain of the notification system**, determining **when and which notifications** should be triggered based on agent status changes.

### Core Features

- **Linkage** between triggers and notifiers (one-to-many).
- **Conditions**: Triggers can be configured to react only to specific types of status changes (e.g., only on downtime, or both up/down events).
- **Tag Matching**: Allows targeting subsets of agents based on metadata.
- **Last Notified Tracking**: Stores timestamps of previous alerts per trigger-agent pair to control re-alerting frequency.

---

## 4. 🔓 Unblock Request Monitoring

**Integration Point**: `UnblockController` (external module)

This integration captures and processes **unblock requests submitted by end users** who are temporarily blocked by the system (e.g., via CSF or custom firewall logic).

### Features

- **Alerting on Unblock Attempts**: Notifies admins when a user requests to be unblocked.
- **Request Outcome Visibility**: Indicates if the user:
    
    
    - Was indeed blocked and unblocked.
    - Was never blocked.
    - Has requested unblocking too frequently (possible abuse).
- **Escalation Signals**: Excessive or suspicious unblock activity can flag issues for deeper inspection.

This feature provides security teams with real-time context on potentially malicious or misbehaving clients.

##   
🔐 Security Considerations

To protect system integrity and minimize attack surface:

- Internal logic is abstracted and modularized to reduce exposure.
- Logging is selectively enabled and avoids sensitive data leakage.
- Time-based checks and cooldown intervals prevent alert spam or abuse.
- All external interactions (e.g., sending to Slack or webhooks) should be validated and rate-limited.
- All external outbound notifications should be validated and rate-limited.
- Unblock request alerts help detect misuse or false positive blocks.

---

## ⚙️ Workflow Summary

1. The **Agent Uptime Controller** routinely checks agent heartbeat timestamps.
2. If a status change is detected (up or down), it invokes the **Trigger Mechanism**.
3. The **Trigger Mechanism** determines if and which notifications should be sent, based on tag matching and cooldown logic.
4. Matched **Notifiers** are executed asynchronously or in queue, depending on system setup.
5. If a user **requests unblocking**, an internal event is logged and optionally notifies admins based on thresholds or flags.