Need help debugging a MikroTik RouterOS script for monitoring user data usage

Stängt Publicerat 11 månader sedan Betalades vid leverans
Stängt Betalades vid leverans

I have a MikroTik RouterOS script that is intended to monitor user data usage in the User Manager, check if users are reaching their data limit, and send notifications via Telegram if they are close to or have reached their limit. However, I keep encountering an error: "input does not match any value of value-name."

The script's main objectives are:

Loop through all users in the User Manager.

Collect user data and traffic information.

Check if the user is active and has a GID set in the "Phone" section.

Get the user's profile and transfer limit.

Calculate the remaining transfer and check if it's less than 10GB or if the limit has been reached.

Send traffic info to each Telegram group associated with the user (GIDs are separated by a comma in the "Phone" section).

Schedule the script to run every 10 hours.

The script I'm currently working with is as follows:

:local botToken "YOUR_BOT_TOKEN"

:local apiURL "[login to view URL]$botToken/sendMessage"

:local sendMessage do={

:local chatID ($1)

:local messageText ($2)

/tool fetch mode=https url="$apiURL" http-method="post" http-data="chat_id=$chatID&text=$messageText" dst-path="/dev/null"

}

/tool user-manager user

:foreach user in=[find] do={

:local username [/tool user-manager user get $user name]

:local phoneInfo [/tool user-manager user get $user phone]

:local uploadUsed [/tool user-manager user get $user upload-used]

:local downloadUsed [/tool user-manager user get $user download-used]

:local totalDataUsed ($uploadUsed + $downloadUsed)

:local userDisabled [/tool user-manager user get $user disabled]

:local actualProfile [/tool user-manager user get $user actual-profile]

:if (($userDisabled = false) && ($phoneInfo != "")) do={

:local userProfile [/tool user-manager profile print as-value where id=$actualProfile]

:local transferLimit ($userProfile->"transfer-limit")

:local remainingTransfer ($transferLimit - $totalDataUsed)

:local trafficInfo ""

:if ($remainingTransfer < (10 * 1024 * 1024 * 1024)) do={

:set trafficInfo ("Warning: " . $username . " has less than 10GB left to reach their limit.")

} else={

:if ($remainingTransfer <= 0) do={

:set trafficInfo ("User \"" . $username . "\" has reached their traffic limit of " . $transferLimit . ". Current usage: " . $totalDataUsed . ".")

}

}

:if ($trafficInfo != "") do={

:local gidList [:toarray [:pick $phoneInfo 0 [:find $phoneInfo ","]]]

:foreach gid in=$gidList do={

$sendMessage $gid $trafficInfo

}

}

}

}

/system scheduler

add name="traffic_notifier" interval=10h on-event="Notice"

I need assistance in debugging the script to resolve the "input does not match any value of value-name" error and ensure it works as intended. Any help would be greatly appreciated.

To successfully debug and fix the script, you should have the following skills:

Strong understanding of MikroTik RouterOS and its scripting language.

Familiarity with the User Manager package in RouterOS.

Good problem-solving skills to identify and resolve the script issues.

Scripting Felsökning Felsökning

Projekt-id: #36563336

About the project

1 offert Distansprojekt Aktivt 10 månader sedan

1 frilansare har i genomsnitt lagt bud på $100 för detta jobb

rumyr

Hi, I'm interested in your project and I would like to debug your script. Please feel free to contact me if you have any queries. Best Regards, Tanvir Rumman

$100 USD inom 7 dagar
(2 omdömen)
1.1