akram
February 7, 2010, 7:57am
1
here is the script
:local text
:set text [/ip firewall filter {:foreach i in=[find] do={:put (“src-address=”.[get $i src-address]." dst-address=“.[get $i dst-address].” bytes=".[get $i bytes]);}} ]
:log info “testing - $text”
/tool e-mail send server=“192.168.1.134” from=“noreply@domain.com ” to=“me@domain.com ” subject=“report” body="report -
$text
Regards,
Akram
it only give me the last line in the log and also in the email , is there a way to fix my script to make it all the data list? thanks everyone
When you set the “text” variable, you are overwriting the previous values. Try this:
:set text ("This is line 1\n")
:set text ($text . "This is line 2\n")
The “\n” inserts a line feed (newline). Note on the second “set”, it inserts the previous “$text” entry before the second line is added.
akram
February 7, 2010, 1:25pm
3
sorry i don’t understand where i can put the line u mean
but i tried but still give me all the lines same the last line
can u edit my script and tell me?
:local text ""
/ip firewall filter
{
:foreach i in=[find] do={
:set text ($text."src-address=".[get $i src-address]." dst-address=".[get $i dst-address]." bytes=".[get $i bytes]."\n");
}
}
:log info "testing - $text"
akram
February 7, 2010, 1:42pm
6
i works 100 % but i need to add enter better each line
is it possible?
you mean, in e-mail? try replacing ‘\n’ with ‘\r\n’
Hey Chupaka! Thanks for the code. Very early SuperBowl Sunday here and I am just gettting some coffee in me now. I think he means a blank line between the lines. I use “\n\n”.
some windows programs don’t recognize \n, so probably he needs “\r\n\r\n”
You may be correct. I have checked it with Outlook, Outlook Express, and Thunderbird (Linux) only. It is possible that port 80 email readers would not like the single “\n”.
akram
February 7, 2010, 2:41pm
11
i tested and it works thanks with \r\n\r\n
i wanna do something else
i want the bytes appear in MB
like src=192.168.1.3 bytes = 195 MB
how can i do that ,how to muliteply the byte to 1024 and add MB in the line
plz help
Chupaka
February 7, 2010, 3:47pm
12
not multiply, but divide ))
replace
bytes=".[get $i bytes]."
with
bytes=".([get $i bytes] / 1024 / 1024)."M
akram
February 7, 2010, 5:25pm
13
perfect ,thanks very very much
here the hole script for everyone who want it
:local text ""
:local MB
:set MB " MB"
/ip firewall filter
{
:foreach i in=[find] do={
:set text ($text."src-address=".[get $i src-address]." dst-address=".[get $i dst-address]. " bytes=".([get $i bytes] / 1024 / 1024).$MB."\r\n\r\n" )
;
}
}
:log info "test Download/Upload Report - $text
------- Report Ends -------"
/tool e-mail send server="192.168.1.134" from="noreply@domain.com" to="someone@domain.com" subject="Manual usage report" body="Download & Upload report -
$text
Regards,
someone@domain.com"