From 837b29735f359a3dea9b501b2d6b863d41135d01 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Thu, 23 Jul 2026 23:26:23 +0700 Subject: [PATCH] feat(api): update mikrotik-install script for enhanced packet tracking - Updated the `mikrotik-install.rsc` script to include cumulative packet tracking for dropped and accepted packets, improving visibility into firewall performance. - Adjusted the JSON report structure to reflect the new packet statistics, ensuring accurate data is sent during synchronization. - Enhanced logging to provide detailed insights into the synchronization process, including packet counts for better monitoring. These changes improve the overall functionality and monitoring capabilities of the agent installation and synchronization process. --- .../src/agent-scripts/mikrotik-install.rsc | 24 ++++++++++++++++--- docs/agents.md | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/api/src/agent-scripts/mikrotik-install.rsc b/apps/api/src/agent-scripts/mikrotik-install.rsc index 795803a..e1ccd27 100644 --- a/apps/api/src/agent-scripts/mikrotik-install.rsc +++ b/apps/api/src/agent-scripts/mikrotik-install.rsc @@ -49,7 +49,7 @@ :set token ("evofw_" . [:tostr [/system clock get time]] . [:tostr [/system resource get cpu-load]] . [:tostr [/system resource get free-memory]] . [:tostr [:rndnum from=100000 to=999999]]) } - :local body ("{\"name\":\"" . $EvofwName . "\",\"hostname\":\"" . [/system identity get name] . "\",\"platform\":\"mikrotik\",\"token\":\"" . $token . "\",\"client_version\":\"rsc/3\"") + :local body ("{\"name\":\"" . $EvofwName . "\",\"hostname\":\"" . [/system identity get name] . "\",\"platform\":\"mikrotik\",\"token\":\"" . $token . "\",\"client_version\":\"rsc/4\"") :if ([:typeof $EvofwInstallLinkId] != "nothing" && [:len $EvofwInstallLinkId] > 0) do={ :set body ($body . ",\"install_link_id\":\"" . $EvofwInstallLinkId . "\"") } @@ -134,14 +134,32 @@ :local denyCnt [:len [/ip firewall address-list find list=EVOFW_DENY]] :local allowCnt [:len [/ip firewall address-list find list=EVOFW_ALLOW]] :local cnt ($denyCnt + $allowCnt) - :local report ("{\"status\":\"ok\",\"prefix_count\":" . $cnt . ",\"kernel_method\":\"address-list\",\"source\":\"mikrotik\"}") + # Cumulative counters from permanent filter rules (survive address-list rebuild). + :local dropped 0 + :local accepted 0 + :do { + :foreach i in=[/ip firewall filter find where comment~"^evofw-deny-"] do={ + :set dropped ($dropped + [/ip firewall filter get $i packets]) + } + } on-error={} + :do { + :foreach i in=[/ip firewall filter find where comment=evofw-default-drop-forward] do={ + :set dropped ($dropped + [/ip firewall filter get $i packets]) + } + } on-error={} + :do { + :foreach i in=[/ip firewall filter find where comment=evofw-allow-accept-forward] do={ + :set accepted ($accepted + [/ip firewall filter get $i packets]) + } + } on-error={} + :local report ("{\"status\":\"ok\",\"prefix_count\":" . $cnt . ",\"packets_dropped\":" . $dropped . ",\"packets_accepted\":" . $accepted . ",\"kernel_method\":\"address-list\",\"source\":\"mikrotik\"}") :do { /tool fetch url=($EvofwCpUrl . "/v1/agent/apply-report") http-method=post http-header-field=("Authorization: Bearer " . $EvofwToken . ",Content-Type: application/json") http-data=$report keep-result=no } on-error={} :do { /tool fetch url=($EvofwCpUrl . "/v1/agent/heartbeat") http-method=post http-header-field=("Authorization: Bearer " . $EvofwToken . ",Content-Type: application/json") http-data="{\"source\":\"mikrotik\"}" keep-result=no } on-error={} - :log info ("evofw: sync done deny=" . $denyCnt . " allow=" . $allowCnt) + :log info ("evofw: sync done deny=" . $denyCnt . " allow=" . $allowCnt . " dropPkts=" . $dropped . " acceptPkts=" . $accepted) } } diff --git a/docs/agents.md b/docs/agents.md index 212435c..37cdf6d 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -70,6 +70,7 @@ Install RSC: 3. Scheduler `evofw-sync` каждую минуту: `GET /v1/agent/policy` (JSON) → rebuild address-list + toggle default. Не использует `/import` огромного `.rsc` (на больших списках часто падает молча). Лог: `/log print where message~"evofw"`. Ручной sync: `/system script run evofw-sync`. +Traffic ↓/↑ в UI — сумма `packets` с filter-правил `evofw-deny-*` / `evofw-allow-*` / `evofw-default-drop-*` (накопительно, пока правила не пересозданы re-install). **Default action** задаётся на **агенте** (`default_action: accept | drop`):