Help for tool netwatch

{
: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

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
}
};

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
    }
}

thank you