Hi,
Thought I’d share this solution I developed to mail our users their daily download stats. I am NOT using User manager at the moment. This method involves using filters on my mail server as well as the scripts on the Routerboard. This also excludes any users that have LES THAN 5 Mb daata download per day.
- Create a simple queue for each users IP address.
/queue simple
add burst-limit=1M/1M burst-threshold=1M/1M burst-time=1m/1m comment=KJ direction=both disabled=no \
dst-address=0.0.0.0/0 interface=all limit-at=0/0 max-limit=1M/1M name=10.254.253.1 packet-marks=http,ftp,other,p2p \
parent=none priority=4 queue=default-small/default-small target-addresses=10.254.253.1/32 total-queue=\
default-small
It should be noted that we use packet marking to prioritise traffic by means of mangle rules and queue tree. This is not covered here, but explains the simple queue measuring certain packets, admin packets (winbox/dude traffic) are not measured to the users account.
- Create the script that sends mails with the data required.
/system script
add name="Mail Each User Their Usage" policy=ftp,read,write,policy,winbox,password,sniff,sensitive source="{:global tra\
f;\r\
\n:global http \"0\";\r\
\n:global megsd \"0\";\r\
\n:global max \"0\";\r\
\n:global commnt \"\";\r\
\n\r\
\n/queue simple\r\
\n :for i from=1 to=43 do={\r\
\n :if ([/queue simple find name=\"10.254.253.\$i\"]!=\"\") do={:set traf [get [find name=\"10.254.253.\
\$i\"] bytes]; :set megsd ((([:pick \$traf ([:find \$traf \"/\"] +1) ([:len \$traf])]) + ([:pick \$traf 0 ([:find \
\$traf \"/\"] )]))/1048576);}\r\
\n :if ([/queue simple find name=\"10.254.253.\$i\"]!=\"\") do={:set max [get [find name=\"10.254.253.\$\
i\"] max-limit];}\r\
\n :set http (\$megsd)\r\
\n :set logmsg (\" \");\r\
\n :set commnt [get [find name=\"10.254.253.\$i\"] comment]\r\
\n :if (\$http>5) do={/tool e-mail send from=ad@es.mobi to=limit@es.mobi subject=\
\"Daily Data Usage Report - Unit \$i. @ \$megsd MB\" body=\"ES Unit \$i : \$megsd MB downloaded today. The unit is \
identified as \$commnt, the number after the /, being the MB downloaded as at 7am.\"; :delay 10s;}\r\
\n } \r\
\n } \r\
On the mail server, create a filter for the user that filters the :Unit $i. [“Unit 1” in this case] in the subject line and redirect that mail to the users e-mail account.
Finally, setup a scheduled task to (a) run the mail compiling/sending script, and then reset the queue totals.
Cheers
Brian