Community discussions

MikroTik App
 
thinair
newbie
Topic Author
Posts: 26
Joined: Thu Aug 23, 2007 3:43 pm

Usage Warning - Script Conversion from v3 to v2

Sat Jun 07, 2008 2:29 pm

Is someone able to convert the following script to work with 2.9.51?
:local name
:local surname
:local usage
:local bytesin
:local bytesout
:local bytestotal
:local megstotal
:local cap
:local comment
:local newcomment
:local invoice
:local newinvoice
:local lastmonth
:local monthname
:local lastwarning
:local newmonth
:local newwarning
:local percentage
:local percentile
:local warninglevel
:local warn
:local update
:local email
:local server

:set server [:resolve smtp.yourserver.com]
/tool user-manager user
:foreach i in=[/tool user-manager user find subscriber=admin] do={

:set name [get $i first-name]
:set surname [get $i last-name]
:set comment [get $i comment]
:set bytesin [get $i download-used]
:set bytesout [get $i upload-used]
:set bytestotal ($bytesin + $bytesout)
:set email [get $i email]

#Test Comment: 10001 3000 50 09

:set megstotal ($bytestotal / 1000000)
:set cap [:pick $comment 5 9]
:set invoice [:pick $comment 0 5]
:set newinvoice ($invoice)
:set lastwarning [:pick $comment 9 11]
:set lastmonth [:pick $comment 11 13]
:set percentage (($megstotal * 100) / $cap)

#classifying your current cap percentile
#I ended up not using the Percentile variable
#The Percentile variable just describes where, more or less,
#the user's current usage percentage is.

:if ([$percentage] < 50) do={ :set percentile 1050 ; :set warninglevel 10 }

:if ([$percentage] > 50) do={
:if ([$percentage] < 75) do={ :set percentile 5075 ; :set warninglevel 50 }
:if ([$percentage] > 75) do={ :set percentile 7590 ; :set warninglevel 75 }
}

:if ([$percentage] > 75) do={
:if ([$percentage] < 90) do={ :set percentile 7590 ; :set warninglevel 75 }
:if ([$percentage] > 90) do={ :set percentile 9010 ; :set warninglevel 90 }
}

:if ([$percentage] > 90) do={
:if ([$percentage] < 100) do={ :set percentile 9010 ; :set warninglevel 90 }
:if ([$percentage] > 100) do={ :set percentile 1000 ; :set warninglevel 99 }
}

# Parse warning necessity

:if ([$warninglevel] > $lastwarning) do={ :set warn true ; :set update true }
:if ([$warninglevel] = $lastwarning) do={ :set warn false ; :set update false }
:if ([$warninglevel] < $lastwarning) do={ :set warn false ; :set update true }

:if ([$update] = true) do={ :set newwarning $warninglevel ; :set newinvoice $invoice ; :set newmonth $lastmonth } else={ :set newwarning $lastwarning ; :set newinvoice $invoice ; :set newmonth $lastmonth }
:if ([$warn] = true) do={

/tool e-mail send to=$email from=NoReply@YourWISP.com server=$server subject="Usage Warning: Usage at $percentage" body="Dear $name $surname

This message is to inform you of your current usage.
The current warning trigger is $warninglevel%.

You have downloaded $megstotal MB, which is $percentage%
of your $cap MB cap.

This is an Automatically generated E-mail
that is sent out when users reach 50%, 75%, 90% and 100% of their cap.

If any information contained in this E-mail is incorrect,
please inform us immediately.
If you have received this E-mail in error,
please reply to this E-mail stating that you are not the intended recipient,
and delete this message.

Thank You

Auto Billing & Accounting
YourWISP Name
accounts@YourWISP.com
AnyAdditionalContactInfo"

:log info "Sent Warning Level $warninglevel% to $email"

/tool e-mail send to=accounts@YourWISP.com from=NoReply@YourWISP.com server=$server subject="Usage Warning for $name $surname" body="Usage Notification for $name $surname
Usage: $megstotal
Cap: $cap
Percentage: $percentage%"

:log info "Sent Notification for $name $surname to Accounts" }

:set newcomment "$newinvoice$cap$newwarning$newmonth"
/tool user-manager user set $i comment=$newcomment
}
 
thinair
newbie
Topic Author
Posts: 26
Joined: Thu Aug 23, 2007 3:43 pm

Re: Usage Warning - Script Conversion from v3 to v2

Sat Jun 07, 2008 2:29 pm

This doesn't seem to work for me when trying on 2.9.51, script doesn't want to run!
 
User avatar
airstream
Member Candidate
Member Candidate
Posts: 188
Joined: Fri Feb 03, 2006 6:33 am
Location: New Zealand

Re: Usage Warning - Script Conversion from v3 to v2

Sat Jun 14, 2008 7:16 am

This doesn't seem to work for me when trying on 2.9.51, script doesn't want to run!
Unfortunately these billing scripts written by Krige posted on the wiki will not work for ROS V2.9, they need to be completely re-written. We have re written these scripts and have working scripts for V2.9 and V3.0 that have added features such as real time bandwidth throttling etc but am awaiting instructions from the original author (krige) regarding the publication of these scripts.
 
User avatar
jordantrx
Long time Member
Long time Member
Posts: 505
Joined: Tue Oct 23, 2007 8:58 pm
Location: WAY upstate NY

Re: Usage Warning - Script Conversion from v3 to v2

Sun Jun 15, 2008 3:52 pm

This doesn't seem to work for me when trying on 2.9.51, script doesn't want to run!
Unfortunately these billing scripts written by Krige posted on the wiki will not work for ROS V2.9, they need to be completely re-written. We have re written these scripts and have working scripts for V2.9 and V3.0 that have added features such as real time bandwidth throttling etc but am awaiting instructions from the original author (krige) regarding the publication of these scripts.
Having trouble getting ahold of him airstream? -Jordan

Who is online

Users browsing this forum: No registered users and 29 guests