[test@testAP] > :local content
[test@testAP] > :local i
[test@testAP] > :local sitename
[test@testAP] > :local gigs
[test@testAP] > :local email
[test@testAP] > :local megstotal
[test@testAP] > :local totalcurrent
[test@testAP] > :local bytesdowncurrent
[test@testAP] > :local bytesupcurrent
[test@testAP] > :local megsdowncurrent
[test@testAP] > :local megsupcurrent
[test@testAP] > :local percentage
[test@testAP] > :local lastwarning
[test@testAP] > :local warninglevel
[test@testAP] > :local warn
[test@testAP] > :local update
[test@testAP] > :local newwarning
[test@testAP] > :local bytesdownsaved
[test@testAP] > :local bytestotal
[test@testAP] >
[test@testAP] > #Script based on Automated billing script at
http://wiki.mikrotik.com/wiki/AutomatedBill
ing
[test@testAP] > #Details:
[test@testAP] > #This script checks all current simple queues and using values stored in the queue comme
nt will allow you keep track of usage by each site
[test@testAP] > #The details stored in the queue are broken down and used to determine when a user shoul
d be sent a usage warning at 50 75 90 and 100%
[test@testAP] > #You can create/modify a new entry as long as you follow this format
[test@testAP] > #1) If you just want to name an entry you may do so like "XYZ Router" in the queue name
[test@testAP] > #2) If you want to determine a data limit, enter it like "sitename!gigabytelimit#emailad
dress!00#0000" into the comment.
[test@testAP] > #3) If you just want to enter a comment on its own, you can do this so long as you don't
have an "!" in the field
[test@testAP] > #Breaking it down: sitename is a descriptive name, gigabyte limit is the monthy limit, e
mail address is the address you want notified
[test@testAP] > #00 is the last percentage warning level for this user, 0000 is the default value for a
new data store
[test@testAP] > #This version created by Andrew Cox -
http://www.accessplus.com.au
[test@testAP] > #v1.4 Updated 15/June/2009
[test@testAP] > :log info "------ Begining Daily Usage Reports -------"
[test@testAP] >
[test@testAP] > #For each queue in the list
[test@testAP] > :foreach i in=[/queue simple find comment !=""] do={
{...
{... #Pull comment out of queue and divide up accordingly
{... :set content [/queue simple get $i comment]
expected variable name (line 4 column 6)
[test@testAP] >
[test@testAP] > #Determine variables from comment
[test@testAP] > #Format is: sitename ! gigsallowed # who-to-email ! last warning level(0-50-75-90-99)
[test@testAP] > :if ([:find $content "!"] != "") do={
syntax error (line 1 column 14)
[test@testAP] > :local pos1 [:find $content "!"]
syntax error (line 1 column 23)
[test@testAP] > :local pos4 [:len $content]
syntax error (line 1 column 22)
[test@testAP] > :local pos2 ([:find [:pick $content ($pos1+1) $pos4] "#"]+$pos1+1)
syntax error (line 1 column 31)
[test@testAP] > :local pos3 ([:find [:pick $content ($pos2+1) $pos4] "!"]+$pos2)
syntax error (line 1 column 31)
[test@testAP] > :set sitename [:pick $content 0 ($pos1)]
expected variable name (line 1 column 8)
[test@testAP] > :set gigs [:pick $content ($pos1+1) $pos2]
expected variable name (line 1 column 8)
[test@testAP] > :set email [:pick $content ($pos2+1) ($pos3+1)]
expected variable name (line 1 column 8)
[test@testAP] > :set totalcurrent [/queue simple get $i bytes]
expected variable name (line 1 column 8)
[test@testAP] > :set lastwarning [:pick $content ($pos3+2) ($pos3+4)]
expected variable name (line 1 column 8)
[test@testAP] > :local pos5 [:find $totalcurrent "/"]
syntax error (line 1 column 23)
[test@testAP] > :local pos6 [:len $totalcurrent]
syntax error (line 1 column 22)
[test@testAP] > :set bytesupcurrent ([:pick $totalcurrent 0 ($pos5)])
expected variable name (line 1 column 8)
[test@testAP] > :set bytesdowncurrent ([:pick $totalcurrent ($pos5+1) $pos6])
expected variable name (line 1 column 8)
[test@testAP] > :set megsupcurrent ($bytesupcurrent / 1048576)
expected variable name (line 1 column 8)
[test@testAP] > :set bytesdownsaved ([:pick $content ($pos3+5) $pos4])
expected variable name (line 1 column 8)
[test@testAP] > :set bytestotal ($bytesdowncurrent + $bytesdownsaved)
expected variable name (line 1 column 8)
[test@testAP] > :set megsdowncurrent ($bytestotal / 1048576)
expected variable name (line 1 column 8)
[test@testAP] >
[test@testAP] > #Begin calculating usage percentage
[test@testAP] > :set percentage ( ( $bytestotal * 100) / ($gigs * 1073741824 ) )
expected variable name (line 1 column 8)
[test@testAP] > :log info "$sitename: $percentage%"
expected end of command (line 1 column 14)
[test@testAP] > :if ([$percentage] < 50) do={ :set warninglevel "00" }
syntax error (line 1 column 10)
[test@testAP] > :if ([$percentage] > 50) do={
syntax error (line 1 column 10)
[test@testAP] > :if ([$percentage] < 75) do={ :set warninglevel "50" }
syntax error (line 1 column 12)
[test@testAP] > :if ([$percentage] > 75) do={ :set warninglevel "75" }
syntax error (line 1 column 12)
[test@testAP] > }
[test@testAP] > :if ([$percentage] > 75) do={
syntax error (line 1 column 10)
[test@testAP] > :if ([$percentage] < 90) do={ :set warninglevel "75" }
syntax error (line 1 column 12)
[test@testAP] > :if ([$percentage] > 90) do={ :set warninglevel "90" }
syntax error (line 1 column 12)
[test@testAP] > }
[test@testAP] > :if ([$percentage] > 90) do={
syntax error (line 1 column 10)
[test@testAP] > :if ([$percentage] < 100) do={ :set warninglevel "90" }
syntax error (line 1 column 12)
[test@testAP] > :if ([$percentage] > 100) do={ :set warninglevel "99" }
syntax error (line 1 column 12)
[test@testAP] > }
[test@testAP] >
[test@testAP] > # Parse warning necessity
[test@testAP] > :if ([$warninglevel] > $lastwarning ) do={ :set warn "true" ; :set update "true" }
syntax error (line 1 column 9)
[test@testAP] > :if ([$warninglevel] = $lastwarning ) do={ :set warn "false" ; :set update "false" }
syntax error (line 1 column 9)
[test@testAP] > :if ([$warninglevel] < $lastwarning ) do={ :set warn "false" ; :set update "true" }
syntax error (line 1 column 9)
[test@testAP] >
[test@testAP] > #Update Warning Levels
[test@testAP] > :if ([$update] = true ) do={ :set newwarning $warninglevel } else={ :set newwarning $la
stwarning }
syntax error (line 1 column 9)
[test@testAP] > :if ([$warn] = true ) do={
syntax error (line 1 column 9)
[test@testAP] > #Check for email address in queue comment
[test@testAP] > :if ([$email] != "" ) do={
syntax error (line 1 column 9)
[test@testAP] > /tool e-mail send to="$email" from="
noreply@example.com" server="1.3.3.7" subject="$si
tename: Usage at $percentage" body="This message is to inform you of the current usage for $sitename
expected end of command (line 1 column 25)
[test@testAP] > The current warning trigger is $warninglevel%.
expected command name (line 1 column 1)
[test@testAP] >
[test@testAP] > This site has downloaded $megsdowncurrent MB, which is over $percentage% of the $gigs GB
monthly download allowance.
expected command name (line 1 column 1)
[test@testAP] >
[test@testAP] > This is an Automatically generated E-mail that is sent out when users reach 50%, 75%, 90
% and 100% of their cap.
expected command name (line 1 column 1)
[test@testAP] >
[test@testAP] > Traffic Monitor System,
expected command name (line 1 column 1)
[test@testAP] >
accounts@example.com"
syntax error (line 1 column 9)
[test@testAP] > }
[test@testAP] > #Send email to support/accounts also
[test@testAP] > /tool e-mail send to="
accounts@example.com" from="
noreply@example.com" server="1.3.3.7
" subject="$sitename: Usage at $percentage" body="Current usage for $sitename - trigger is $warninglevel%.
expected end of command (line 1 column 100)
[test@testAP] > $megsdowncurrent MB, which is over $percentage% of the $gigs GB monthly download allowan
ce.
syntax error (line 1 column 2)
[test@testAP] > Traffic Monitor System"
expected command name (line 1 column 1)
[test@testAP] > :log info "Sent Warning Level $warninglevel% to $email"
expected end of command (line 1 column 31)
[test@testAP] > }
[test@testAP] > #Set new warning level on queue comment
[test@testAP] > /queue simple set $i comment="$sitename!$gigs#$email!$newwarning#$bytestotal"
syntax error (line 1 column 20)
[test@testAP] > /queue simple reset-counters $i
syntax error (line 1 column 31)
[test@testAP] > }
[test@testAP] > }
[test@testAP] >