Community discussions

MUM Europe 2020
 
Technetium
newbie
Topic Author
Posts: 46
Joined: Sun Oct 16, 2016 10:56 pm

Netwatch logging and send log daily by email

Thu Jun 29, 2017 3:00 pm

I'm a beginner of RouterOS ;)
I would like to set up a lan monitoring tool that send me the log daily.
Email is already configured.

Using netwatch i want log only if a host is down.
But how can i write a specific log only dedicated to netwatch and send it only daily by email ?
How can i "reset" the file after successful sending it ?
 
Shadeofspirit
Member Candidate
Member Candidate
Posts: 204
Joined: Fri May 27, 2016 12:15 am
Location: Minsk
Contact:

Re: Netwatch logging and send log daily by email

Thu Jun 29, 2017 3:11 pm

I'm a beginner of RouterOS ;)
I would like to set up a lan monitoring tool that send me the log daily.
Email is already configured.

Using netwatch i want log only if a host is down.
But how can i write a specific log only dedicated to netwatch and send it only daily by email ?
How can i "reset" the file after successful sending it ?
what do you want to have in log?
create new "action" and "rule" in system logging (save to file)
make schedule to send this file and delete after sending
MTCNA, MTCWE
 
Technetium
newbie
Topic Author
Posts: 46
Joined: Sun Oct 16, 2016 10:56 pm

Re: Netwatch logging and send log daily by email

Sat Jul 01, 2017 2:56 pm

In log i want write a string like "PC1 is down".

I don't understand how to use "action" and "rule" of logging system to obtain a file only dedicated to netwatch message.

I don't understand how to log only netwatch log because script can write only on 4 topics.. "debug, error, info and warning".. so, how can i create a rule to filter only netwatch message ?
 
Shadeofspirit
Member Candidate
Member Candidate
Posts: 204
Joined: Fri May 27, 2016 12:15 am
Location: Minsk
Contact:

Re: Netwatch logging and send log daily by email

Sun Jul 02, 2017 11:34 am

In log i want write a string like "PC1 is down".

I don't understand how to use "action" and "rule" of logging system to obtain a file only dedicated to netwatch message.

I don't understand how to log only netwatch log because script can write only on 4 topics.. "debug, error, info and warning".. so, how can i create a rule to filter only netwatch message ?
try smth like this:
create new action in logging (type - disk, file count 1, file name - any name you want)
create new rule (topics: script, warning action: your new action, prefix - any you want )
in netwach in down action add command (or add to the script what you run on "down"event this line: /log warning "PC is down at $[/system clock get time]" )

after that add to the scheduler script to send e-mail with file (file will have name you had written in "action" + .0.txt)
to send file you can use smth like:
/tool e-mail send to=yourmail@gmail.com subject="Netwach lof file" file="netwachlog.0.txt"

to clear log file after sending just delete file
/file remove netwachlog.0.txt
also you can add logging for "up" event
MTCNA, MTCWE
 
Technetium
newbie
Topic Author
Posts: 46
Joined: Sun Oct 16, 2016 10:56 pm

Re: Netwatch logging and send log daily by email

Sun Jul 02, 2017 12:15 pm

Thanks very clear and it works ;)

I'm a beginner of RouterOs and after many research i found that from script i have to save any messages about topics we select (es. warning or info or..) and after (download, email..) filter it to select the messages that interest us.
In my mind, working on linux system, i would like to create a log file dedicated to each action that i want log, but in routerOs isn't possible.
Now i'm in the hell of those who study a new system xD

Some other question:
I haven't found how to check a filesize of a file.. or how to check if the mail was really sent without error.
In case of lack of connection, error on authentication etc.. a simple script (example i've found on internet, also in this forum) will not send the email and after delete in any case the log file. That's terribly wrong in my mind.
 
Shadeofspirit
Member Candidate
Member Candidate
Posts: 204
Joined: Fri May 27, 2016 12:15 am
Location: Minsk
Contact:

Re: Netwatch logging and send log daily by email

Sun Jul 02, 2017 12:38 pm

Thanks very clear and it works ;)

I'm a beginner of RouterOs and after many research i found that from script i have to save any messages about topics we select (es. warning or info or..) and after (download, email..) filter it to select the messages that interest us.
In my mind, working on linux system, i would like to create a log file dedicated to each action that i want log, but in routerOs isn't possible.
Now i'm in the hell of those who study a new system xD

Some other question:
I haven't found how to check a filesize of a file.. or how to check if the mail was really sent without error.
In case of lack of connection, error on authentication etc.. a simple script (example i've found on internet, also in this forum) will not send the email and after delete in any case the log file. That's terribly wrong in my mind.
i can't help with checking send email (i didn't have to setup this). in my cases i usually setup logging to remote servers and for critical systems have telegram alerts
MTCNA, MTCWE
 
Technetium
newbie
Topic Author
Posts: 46
Joined: Sun Oct 16, 2016 10:56 pm

Re: Netwatch logging and send log daily by email

Sun Jul 02, 2017 2:26 pm

i can't help with checking send email (i didn't have to setup this). in my cases i usually setup logging to remote servers and for critical systems have telegram alerts
This setup work if the device is supposed to be constantly connected. If the connection stops, the message to syslog server are lost.
On server i use both, local log and remote syslog server. If the connection fail, after i can recover the local log on request or wait until the automatic send of the log by mail.
I think you use the same approach.
 
Shadeofspirit
Member Candidate
Member Candidate
Posts: 204
Joined: Fri May 27, 2016 12:15 am
Location: Minsk
Contact:

Re: Netwatch logging and send log daily by email

Sun Jul 02, 2017 2:57 pm

i can't help with checking send email (i didn't have to setup this). in my cases i usually setup logging to remote servers and for critical systems have telegram alerts
This setup work if the device is supposed to be constantly connected. If the connection stops, the message to syslog server are lost.
On server i use both, local log and remote syslog server. If the connection fail, after i can recover the local log on request or wait until the automatic send of the log by mail.
I think you use the same approach.
in my case log from netwatch comes to remote syslog server, so all the information about connection state is on it. and as i had said - the state of critical services comes also by telegram bot
MTCNA, MTCWE
 
ovdeathiam
just joined
Posts: 20
Joined: Wed Jul 16, 2014 11:15 am

Re: Netwatch logging and send log daily by email

Fri Aug 11, 2017 10:17 pm

I have something simmilar already configured.
Zrzut ekranu z 2017-08-11 21.19.07.png
Logs are saved to _GoogleDNS.txt untill it's full then it is renamed to have a timestamp and a new clear file is created. You could change it to what you need.

  • Netwatch settings:
    Host: 8.8.8.8
    Interval: 00:00:02
    Timeout: 1000
  • Script up:
    :local workdir "log/google/"
    :local name "GoogleDNS"
    
    :local scl [/system clock get];
    :local months {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"};
    :set ($scl->"y") [:pick ($scl->"date") 7 11];
    :set ($scl->"mn") [:pick ($scl->"date") 0 3];
    :set ($scl->"m") ($months->($scl->"mn"));
    :set ($scl->"d") [:pick ($scl->"date") 4 6];
    :set ($scl->"H") [:pick ($scl->"time") 0 2];
    :set ($scl->"M") [:pick ($scl->"time") 3 5];
    :set ($scl->"S") [:pick ($scl->"time") 6 8];
    :set ($scl->"timestamp") (($scl->"y").".".($scl->"m").".".($scl->"d")."_".($scl->"H").".".($scl->"M").".".($scl->"S"));
    
    :local tempfile ($workdir."_".$name.".txt");
    :local output (" - UP ".($scl->"timestamp")."\r\n");
    
    :local newcontent ([/file get "$tempfile" contents].$output); :delay 1;
    /file set [/file find name="$tempfile"] contents=$newcontent;
    :log debug message=($name.": UP");
    
  • Down:
    :local workdir "log/google/"
    :local name "GoogleDNS"
    
    :local scl [/system clock get];
    :local months {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"};
    :set ($scl->"y") [:pick ($scl->"date") 7 11];
    :set ($scl->"mn") [:pick ($scl->"date") 0 3];
    :set ($scl->"m") ($months->($scl->"mn"));
    :set ($scl->"d") [:pick ($scl->"date") 4 6];
    :set ($scl->"H") [:pick ($scl->"time") 0 2];
    :set ($scl->"M") [:pick ($scl->"time") 3 5];
    :set ($scl->"S") [:pick ($scl->"time") 6 8];
    :set ($scl->"timestamp") (($scl->"y").".".($scl->"m").".".($scl->"d")."_".($scl->"H").".".($scl->"M").".".($scl->"S"));
    
    :local tempfile ($workdir."_".$name.".txt");
    :local logfile ($workdir.$name."_".($scl->"timestamp").".txt");
    :local output ($name." - DOWN ".($scl->"timestamp"));
    
    :if ([:len [/file find where size > "3072" name~$tempfile;]] > 0) do={
        :local tempcontent ([file get "$tempfile" contents]);
        /file print file="$logfile"; :delay 1;/file set [/file find name="$logfile"] contents=$tempcontent;
        /file set [/file find name="$tempfile"] contents="";
        }
    
    :if ([:len [/file find where name~$tempfile;]] > 0) do={} else={
        /file print file="$tempfile"; :delay 1; /file set "$tempfile" contents="";
        }
    
    :local newcontent ([/file get "$tempfile" contents].$output);
    /file set [/file find name="$tempfile"] contents=$newcontent;
    
    :log debug message=($name.": DOWN")
    
You do not have the required permissions to view the files attached to this post.
 
User avatar
JohnTRIVOLTA
Member Candidate
Member Candidate
Posts: 208
Joined: Sun Dec 25, 2016 2:05 pm
Location: BG/Sofia

Re: Netwatch logging and send log daily by email

Fri Aug 11, 2017 11:12 pm

I'm a beginner of RouterOS ;)
I would like to set up a lan monitoring tool that send me the log daily.
Email is already configured.

Using netwatch i want log only if a host is down.
But how can i write a specific log only dedicated to netwatch and send it only daily by email ?
How can i "reset" the file after successful sending it ?
I use this script https://rickfreyconsulting.com/send-logs-via-e-mail/ by Rick Frey , and i just add a schedule and a script to clear the log аbout 15 seconds after being sent.
/system scheduler
add interval=1d name="clear logs" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/21/2017 start-time=20:00:15
/system script
add name="clear logs" owner=ico policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="/\
    system logging action set disk disk-lines-per-file=1; :delay 5;\r\
    \n/system logging action set disk disk-lines-per-file=10000"

Who is online

Users browsing this forum: No registered users and 13 guests