feat(api): update mikrotik-install script for enhanced packet tracking
Build and Push EvoFirewall Docker Image / build-and-push (push) Successful in 2m2s
Build and Push EvoFirewall Docker Image / create-release (push) Skipped

- 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.
This commit is contained in:
Denozordec
2026-07-23 23:26:23 +07:00
parent f2a2310d3e
commit 837b29735f
2 changed files with 22 additions and 3 deletions
@@ -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)
}
}
+1
View File
@@ -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`):