Hi i am trying tho get the usage warning script to work but with no luck. Please look at the script and let me know if im doing something wrong. I only need the usage warning script and not the other automated billing scripts. I cant see anything happening in the logs when i manually run the script.
: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 192.168.0.230
/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=accounts@megamax.za.net 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
Accounts
MEGAMAX
accounts@megamax.za.net"
:log info "Sent Warning Level $warninglevel% to $email"
/tool e-mail send to=agent1@megamax.za.net
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
}
Still no result in the log. created a test account of 50 megs and ran script manually on 50% 75% and 100% with no results being emailed to agent1.
I thought it might be smtp server and tried something small like script below and all worked hundred percent. i noticed however there is the "" after the /tool e-mail send \ but none in the warning script.
Could this have any effect?
Could it be my version?3.30 .
Am i correct in putting the smtp server in here?
You cannot run scripts in terminal like that. Each terminal line is its own implied scope, so variables are falling out of scope on each new line.
Wrap the entire script in a {} brace pair to maintain scope.
After breaking up the script in peices and runing it in parts i found a few problems
1st one Which admin helped with.
:foreach i in=[/tool user-manager user find subscriber=admin]
with this one
Code:
:foreach i in=[/tool user-manager user find subscriber=“admin”]
2nd one i found this } was stopping the script from running
:log info "Sent Notification for $name $surname to Accounts" }
:set newcomment "$newinvoice$cap$newwarning$newmonth"
/tool user-manager user set $i comment=$newcomment
}
I just removed the first } and the it started up
:log info "Sent Notification for $name $surname to Accounts"
:set newcomment "$newinvoice$cap$newwarning$newmonth"
/tool user-manager user set $i comment=$newcomment
}
Another problem i saw is that if there is no user email address in the usermanager it crashes. Is there a way to bypass the ones with no emails? i noticed that the moment i run the script manually it sends the emails but what i cant understand is if i run it again it sends the same users a email.Is it not supposed to remember that it sent a email to that person and not send a warning again?
Below is the script am am using currently Hope this helps others
: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 192.168.0.230
/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]
:set megstotal ($bytestotal / 1000000)
#Test Comment: 10001 3000 50 09
: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 }
/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
Accounts
MegaMax
accounts@megamx.za.net"
:log info "Sent Warning Level $warninglevel% to $email"
/tool e-mail send to=nawaal@maxwell.za.net 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 Usage Warning copy for $name $surname to Accounts"
:set newcomment "$newinvoice$cap$newwarning$newmonth"
/tool user-manager user set $i comment=$newcomment
}
Yes it was, but you dropped the line that handled that (which also explains the ‘ekstra’ } you had to remove, to make it run)
:if ([$warn] = true) do={
change above missing line with
:if ([$warn] = true && [:len $email] > 0) do={
Also be aware that if your costumer hit 100, warninglevel will not be set!
Personally I would have written it like this, but granted, it is a matter of taste.
I am testing this script and it is working for me, but one question - does rebooting/clearing queue data affect the running totals? I’m hoping not since this is why the queue comment field is used?