Community discussions

MikroTik App
 
djbdgzmn
just joined
Topic Author
Posts: 1
Joined: Fri Apr 22, 2022 3:18 pm

PPP Simple Queue on up with Telegram Script

Fri Apr 22, 2022 3:31 pm

Good day!

I have been trying to learn scripting with Mikrotik,
I want to add simple queue once the PPP user is up and send a telegram bot message a notification that a client goes up, and another script that deletes the simple queue once the client disconnects.

But the problem is, sometimes the on down telegram script does not work, it deletes the simple queue but it does not send notification to my telegram. Did I miss something?


Here is the on up script

:local bot "your telegram bot id"
:local chat "your telegram chat id"
:local time ([/system clock get time])
:local date ([/system clock get date])
:local ips [/ppp active get [find name=$user] address];
:local comment [/ppp active get [find name=$user] comment];
:local profile [/ppp secret get [find name=$user] profile];


/tool fetch url="https://api.telegram.org/bot$botId/sendMessage?chat_id=$chatId&text=\E2\9C\85  Client $comment is now connected!%0ATime: $time %0ADate: $date%0AUser: $user%0AProfile: $profile%0AIP Client: $ips" mode=http keep-result=no;



:local address [/ppp active get [/ppp active find name="$user"] address]
:local qQ "pcq-upload-default/pcq-download-default"
:log warning "$user login with ip $address"

:local sqName "||=>> pppoe-$user"
:local cq1 "[1] Gaming-$user"
:local cq2 "[2] Light Traffic-$user"
:local cq3 "[3] Heavy Traffic-$user"


:local limitT "40M/40M"
:local limit1 "5M/5M"
:local limit2 "35M/35M"
:local limit3 "35M/35M"

:local pm1 "games"
:local pm2 "management_traffic,facebook_traffic,light_traffic"
:local pm3 "streaming_traffic,heavy_traffic,no-mark,Stream"

/queue simple add name=$sqName parent=$sqParent target=$address max-limit=$limitT
/queue simple add name="$cq1" max-limit=$limit1 limit-at=$limit1 target=$address parent=$sqName queue=$qQ packet-marks=$pm1 priority=1/1
/queue simple add name="$cq2" max-limit=$limit2 limit-at=$limit2 target=$address parent=$sqName queue=$qQ packet-marks=$pm2 priority=4/4
/queue simple add name="$cq3" max-limit=$limit3 limit-at=$limit3 target=$address parent=$sqName queue=$qQ packet-marks=$pm3 priority=8/8
/queue simple move [find name="$sqName"] [:pick [find] 0]
====================================

here is the on down script
:local sqName
:set sqName "pppoe-$user"
/queue simple remove [find parent=$sqName]
/queue simple remove [find name=$sqName]
/queue simple remove $sqName


:local bot "your telegram bot id"
:local chat "your telegram chat id"
:local remote [/ppp secret get [find name=$user] remote]
:local profile [/ppp secret get [find name=$user] profile]
:local last [/ppp secret get [find name=$user] last-logged-out]
:local lastdic [/ppp secret get [find name=$user] last-disconnect-reason]
:local comment [/ppp active get [find name=$user] comment]

/tool fetch url="https://api.telegram.org/bot$bot/sendMessage?chat_id=$chat&text=\E2\9D\8C Client $comment has been disconnected%0ALocal IP Address: $remote%0A%0AUser: $userProfile: $profile%0ALast Logout: $last%0ALast Disconnect Reason: $lastdic" mode=http keep-result=no;
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: PPP Simple Queue on up with Telegram Script  [SOLVED]

Fri Apr 22, 2022 3:34 pm

The second line do error and stop the script... $sqName is already removed from first line...
/queue simple remove [find name=$sqName]
/queue simple remove $sqName

Who is online

Users browsing this forum: Jotne and 6 guests