Have you tried using a separate script and set It as either the up or down script in netwatch?
There should be an entry (possibly cryptic) in the log if the script (triggered by netwatch) fails to execute because of missing permissions and or owner.
Hi,
I have the same issue with Netwatch - it stopped sending messages to telegram using fetch.
Asked the MikroTik help desk for advice and below is an answer from them:
_"Starting from RouterOS 7.13, to execute fetch requires ftp policy when you want to access (read, write files) and Netwach does not have such.
To fix this issue:
modify Netwatch, add additonal paramter “output=” with value that is not file;
This is how I understand the matter.
Netwatch can only have a limited set of policies.
A separate script can have all the policies BUT when called by Netwatch it “inherits” Netwatch as “owner”.
The script executes if BOTH the “owner” AND the policies are authorized.
It is a bit confusing but “permissions” mean both, i.e. the error in log is the same when either the owner has not enough authorizations or the script Is missing the specific needed policy (or both).
When you use dont-require-permissions on the external script you are essentially telling ROS to ignore “who” is calling the script (and the permissions connected to that identity) and only check that policies are covering the actions in the script (so the script needs the FTP policy).
Alternatively, if you specify output=none on that command the script doesn’t need anymore the ftp policy and can be executed directly from Netwatch.
I created a script that another script with TelegramFunction to bypass the problem with netwatch.
Script: TelegramNetwatch
:local MessageText "\F0\9F\9F\A2 $netDev is UP";
:local SendTelegramMessage [:parse [/system script get Function_Telegram source]];
$SendTelegramMessage MessageText=$MessageText;
Now on netwatch I added
:log info "NZXT PC Up Telegram";
/system script run TelegramNetwatch
:log info "NZXT PC Up Telegram END"
And message to telegram is working.
Now I am trying to transfer the name with variable from netwatch to script. How can I do this?
I tried this for testing but is not working. I added some variables for testing.
Netwatch
:log info "NZXT PC Up Telegram";
:global myVar1;
:local myVar2;
:set myVar1 100;
:set myVar2 “name”;
/system script run TelegramNetwatch
:log info "NZXT PC Up Telegram END"
:global testg
:local testl "script-test"
:log info "testg is $testg and testl is $testl"
on-up on netwatch
:log info "test netwatch up start"
:global testg "nw-test"
/system script run scriptnw
:log info "test netwatch up end"
the export
/system script
add dont-require-permissions=yes name=scriptnw owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":global testg\r\
\n:local testl \"script-test\"\r\
\n:log info \"testg is \$testg and testl is \$testl\"\r\
\n"
/tool netwatch
add disabled=no down-script="" host=1.1.1.1 http-codes="" test-script="" type=icmp up-script=":log info \"test netwatch up start\"\r\
\n:global testg \"nw-test\"\r\
\n/system script run scriptnw\r\
\n:log info \"test netwatch up end\"\r\
\n"
For me work all as expected (v7.13.2)…
13:31:48 netwatch,info event up [ type: icmp, host: 1.1.1.1 ]
13:31:48 script,info test netwatch up start
13:31:48 script,info testg is nw-test and testl is script-test
13:31:48 script,info test netwatch up end
As you can see, this is the difference between READING the source of the script and RUNNING the script…
Another issue that I have
It’s running the script TelegramNetwatchUp but not TelegramNetwatchDown. I mean Telegram not send the message on Down but send on Up.
In logs I am taking the line ":log info “$VarLocal $DevNameGlobal is Down” "
Scripts
TelegramNetwatchUp
:global DevNameGlobal
:local VarLocal "\F0\9F\9F\A2"
:log info "$VarLocal $DevNameGlobal is UP"
:local MessageText "$VarLocal $DevNameGlobal is UP";
:local SendTelegramMessage [:parse [/system script get Function_Telegram source]];
$SendTelegramMessage MessageText=$MessageText;
TelegramNetwatchDown
:global DevNameGlobal
:local VarLocal "\F0\9F\94\B4"
:log info "$VarLocal $DevNameGlobal is Down"
:local MessageText "$VarLocal $DevNameGlobal is Down";
:local SendTelegramMessage [:parse [/system script get Function_Telegram source]];
$SendTelegramMessage MessageText=$MessageText;
Netwatch
UP
:global DevNameGlobal "Grandstream GRP2602P - 192.168.1.39"
/system script run TelegramNetwatchUp
Down
:global DevNameGlobal "Grandstream GRP2602P - 192.168.1.39"
/system script run TelegramNetwatchDown
The export is
/system script
add dont-require-permissions=yes name=TelegramNetwatchUp owner=admin policy=\
ftp,reboot,read,write,test source=":global DevNameGlobal\r\
\n:local VarLocal \"\\F0\\9F\\9F\\A2\"\r\
\n:log info \"\$VarLocal \$DevNameGlobal is UP\"\r\
\n:local MessageText \"\$VarLocal \$DevNameGlobal is UP\";\r\
\n:local SendTelegramMessage [:parse [/system script get Function_Telegra\
m source]];\r\
\n\$SendTelegramMessage MessageText=\$MessageText;"
add dont-require-permissions=yes name=TelegramNetwatchDown owner=admin \
policy=ftp,reboot,read,write source=":global DevNameGlobal\r\
\n:local VarLocal \"\\F0\\9F\\94\\B4\"\r\
\n:log info \"\$VarLocal \$DevNameGlobal is Down\"\r\
\n:local MessageText \"\$VarLocal \$DevNameGlobal is Down\";\r\
\n:local SendTelegramMessage [:parse [/system script get Function_Telegra\
m source]];\r\
\n\$SendTelegramMessage MessageText=\$MessageText;"
add comment="Grandstream GRP2602P" disabled=no down-script=":global DevNameGlo\
bal \"Grandstream GRP2602P - 192.168.1.39\"\r\
\n/system script run TelegramNetwatchDown" host=192.168.1.39 http-codes=\
"" interval=20s test-script="" timeout=1s type=simple up-script=":global D\
evNameGlobal \"Grandstream GRP2602P - 192.168.1.39\"\r\
\n/system script run TelegramNetwatchUp"