Community discussions

MikroTik App
 
faysalsy
just joined
Topic Author
Posts: 5
Joined: Tue Oct 01, 2019 6:53 pm

Help for tool netwatch

Sat Aug 28, 2021 2:11 pm

{
:foreach i in=[/ip neighbor find ] do={
  
 :local addr1   [/ip neighbor  get $i address ];
 
/tool netwatch
add host=$addr1

  }
HI:
I don't want to be added again
When he searches in the neighbors and is in the netwatch he does not add him again
It just adds new
Last edited by faysalsy on Mon Mar 14, 2022 10:05 pm, edited 1 time in total.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 724
Joined: Tue Dec 17, 2019 1:08 pm

Re: Help for tool netwatch

Fri Sep 03, 2021 11:17 am

Good Morning,

I kept it very simple and tried to change as little as possible from the original "script/exemple"
I hope it helps !

:foreach i in=[/ip neighbor find] do={
:local addr1 [/ip neighbor get $i address];
:if ([/tool netwatch find host=[$addr1]]) do={
# IP-Address is already being Netwatched
# Add Commands here if needed
} else={
# IP-Address isn't being Monitored
# Adding IP to Watchlist
/tool netwatch add host=$addr1
}
};
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help for tool netwatch  [SOLVED]

Sat Sep 04, 2021 2:36 am

Some sanitization is needed:
:foreach i in=[/ip neighbor find] do={
    :local addr [/ip neighbor get $i address]
    :if ($addr in 0.0.0.0/0) do={
        :if ([:len [/tool netwatch find where host=$addr]] = 0) do={
            # new neighbor IP for netwatch
            /tool netwatch add host=$addr down-script="" up-script="" comment="auto - $[/ip neighbor get $i identity]"
        } else={
            # netwatch entry already existant
        }
    } else={
        # address not set on neighbor device
    }
}
 
faysalsy
just joined
Topic Author
Posts: 5
Joined: Tue Oct 01, 2019 6:53 pm

Re: Help for tool netwatch

Sat Sep 04, 2021 9:48 am

thank you

Who is online

Users browsing this forum: No registered users and 24 guests