: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
}