Page 1 of 1

A strange bug in firmware 7.16.1: netwatch and variable $ip

Posted: Tue Oct 22, 2024 9:48 am
by vadimsachkov
I noticed a strange bug in version 7.16.1 of the script. I will demonstrate it in the following example::
:local ip 8.8.8.8;
:local HostIP 8.8.8.8;

/tool netwatch print stats;

:if ([:typeof $ip]="ip" && [:len [/tool netwatch find host=$ip comment="ping"]]=0 ) do={
 	if ([:typeof $HostIP]="ip" && [:len [/tool netwatch find host=$HostIP comment="ping"]]=0 ) do={
		put "not found \$ip $ip and  not found \$HostIP $HostIP. Adding netwatch to $HostIP"; 
		/tool netwatch add host=$HostIP comment="ping" interval=60 timeout=1000ms
	}  else={
		:put "not Found \$ip $ip , but Found \$HostIP $HostIP. WHY??????   Nothing to do"; 
	}
	
} else={
	:put "Found IP $ip . Nothing to do"; 
}

/tool netwatch print stats;
The task of the script is to add a host with the address, for example, 8.8.8.8, to netwatch, if it has not been added before.
If I assign an IP address to the $ip domain, then the script will not find this netwatch element anyway.
If I assign the same ip to a variable with a different name, for example HostIP, then the script works fine.

The script must be executed twice. The first time he will not find the netwatch element 8.8.8.8 . and the second time he must definitely find it

Here's how it runs on the version RB4011iGS+ 7.15.3 (stable) EVERYTHING IS CORRECT HERE
[admin@Mik4011] > sys scr ru tesn 
Flags: X - disabled 

not found $ip 8.8.8.8 and  not found $HostIP 8.8.8.8. Adding netwatch to 8.8.8.8

Flags: X - disabled 
 0   ;;; ping
     type=simple host=8.8.8.8 timeout=1s interval=1m status=unknown 

[admin@Mik4011] > sys scr ru tesn 
Flags: X - disabled 
 0   ;;; ping
     type=simple host=8.8.8.8 timeout=1s interval=1m status=up since=2024-10-22 09:17:50 done-tests=1 failed-tests=0 

Found IP 8.8.8.8 . Nothing to do

Flags: X - disabled 
 0   ;;; ping
     type=simple host=8.8.8.8 timeout=1s interval=1m status=up since=2024-10-22 09:17:50 done-tests=1 failed-tests=0 
[admin@Mik4011] > 

Here's how it runs on the version RB951Ui-2HnD 7.16.1 (stable) THERE IS A BUG HERE with the use of a variable called $ip

vadim@M61] > sys scr ru testn 
Flags: X - disabled 

not found $ip 8.8.8.8 and  not found $HostIP 8.8.8.8. Adding netwatch to 8.8.8.8

Flags: X - disabled 
 0   ;;; ping
     type=simple host=8.8.8.8 timeout=1s interval=1m status=unknown 

[admin@M61] > sys scr ru testn 
Flags: X - disabled 
 0   ;;; ping
     type=simple host=8.8.8.8 timeout=1s interval=1m status=up since=2024-10-22 09:20:00 done-tests=1 failed-tests=0 

not Found $ip 8.8.8.8 , but Found $HostIP 8.8.8.8. WHY??????   Nothing to do

Flags: X - disabled 
 0   ;;; ping
     type=simple host=8.8.8.8 timeout=1s interval=1m status=up since=2024-10-22 09:20:00 done-tests=1 failed-tests=0 

Re: A strange bug in firmware 7.16.1: netwatch and variable $ip

Posted: Tue Oct 22, 2024 12:44 pm
by rextended
It is the usual common mistake of anyone who writes scripts without thinking or without knowledge.

"ip" and other words that are or could be reserved words in scripts, should be absolutely avoided.

Sometimes it also happens that experts make mistakes with unsuspected words.

Sometimes it is enough to read the guide.
https://help.mikrotik.com/docs/spaces/R ... 8/Netwatch
ip: IP address - the result of A record-type probe
About that $ip, is bugged on 7.16.1
viewtopic.php?t=211157&start=300#p1104591