Community discussions

MikroTik App
 
iRZ0mbie
just joined
Topic Author
Posts: 4
Joined: Sat Nov 07, 2020 3:39 am

Auto Add Static IP to Netwatch for Logging

Sat Nov 07, 2020 3:54 am

Hey there, Im new here and hope to contribute and get some help.

I've written a script which will seek out any static IP address and add it to Netwatch with an up and down comment for logging and a short interval. It works quite well and its very useful if you have several IP's you need to add to Netwatch.
:foreach leaseId in=[/ip dhcp-server lease find where !dynamic] do={/tool netwatch add host=[/ip dhcp-server lease get $leaseId address] interval=10 down-script=":log info DOWN" up-script="log info UP"}
This works great if you only need to use it once. I want to set up the script to run in system scheduler and automatically add any static IP to the Netwatch. Currently if you run the script in scheduler it will repeatedly add every static IP to Netwatch. I need the script to omit adding any IP that is already monitored by Netwatch. A bonus would be to have the static IP comment added to the corresponding Netwatch comment.

Thanks in advance and I hope this script is helpful to some..
 
iRZ0mbie
just joined
Topic Author
Posts: 4
Joined: Sat Nov 07, 2020 3:39 am

Re: Auto Add Static IP to Netwatch for Logging

Tue Jan 19, 2021 2:56 am

### Netwatch Population Script / Script will add all static IP's to netwatch, copy comment to netwatch, set interval to 10 and set up and down scripts to log comment as up or down respectively. 
:foreach leaseId in=[/ip dhcp-server lease find where !dynamic] do=[
:local ip [/ip dhcp-server lease get $leaseId address];:local comment [/ip dhcp-server lease get $leaseId comment];
:tool netwatch add host=$ip comment=$comment interval="10" down-script=":log info $comment is DOWN" up-script=":log info $comment is UP";:log info "Added $comment to Netwatch"]

Who is online

Users browsing this forum: alexantao and 19 guests