Community discussions

MikroTik App
 
aanistratenko
just joined
Topic Author
Posts: 8
Joined: Fri Mar 10, 2023 10:27 pm

Netwatch with fetch stopped working after 7.13

Wed Jan 17, 2024 11:56 pm

Hi.
After update firmaware to 7.13 stopped working fetch url in Netwatch.
Also try from 7.13.2 and 7.14.beta7 with same problem.

Example in Netwatch Up/Down:
/tool fetch url="https://api.telegram.org/bot***/sendMes ... e=Markdown"

At this time from terminal and Script work fine:
[admin@GW-BG-Home] > /tool fetch url="https://api.telegram.org/bot***/sendMes ... e=Markdown"
status: finished
downloaded: 0KiBC-z pause]
total: 0KiB
duration: 1s
And I recieve "message" in Telegram.

Is problem with new firmware or we have any new settings or rules somewhere?
 
jaclaz
Long time Member
Long time Member
Posts: 667
Joined: Tue Oct 03, 2023 4:21 pm

Re: Netwatch with fetch stopped working after 7.13

Thu Jan 18, 2024 12:08 am

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.
 
ukrainian
just joined
Posts: 1
Joined: Fri Jan 12, 2024 2:39 pm

Re: Netwatch with fetch stopped working after 7.13

Thu Jan 18, 2024 1:17 pm

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:
1. modify Netwatch, add additonal paramter "output=" with value that is not file;
2. create new script that dont-require-permissions and call this script from Netwatch.
https://help.mikrotik.com/docs/display/ROS/Netwatch
https://help.mikrotik.com/docs/display/ ... repository
Best regards"


In my case adding at the end of the script "output=none" resolved the issue:
/tool fetch url="https://api.telegram.org/botToken/sendM ... ext=Device is DOWN" output=none
 
aanistratenko
just joined
Topic Author
Posts: 8
Joined: Fri Mar 10, 2023 10:27 pm

Re: Netwatch with fetch stopped working after 7.13

Thu Jan 18, 2024 10:06 pm

Thanks for variant!

I tryed to run script
/tool fetch url="https://api.telegram.org/bot***/sendMessage?chat_id=***&text=message1&parse_mode=Markdown"
from netwatch up
/system script run fetch
and get error in log
could not run script fetch: not enough permissions
If in scrips check "Dont require permissions" - working!

So i think that problem is in Netwatch permissions in new ROS7, but dont unerstand how to resolve it...
 
jaclaz
Long time Member
Long time Member
Posts: 667
Joined: Tue Oct 03, 2023 4:21 pm

Re: Netwatch with fetch stopped working after 7.13

Thu Jan 18, 2024 11:17 pm

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.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3509
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Netwatch with fetch stopped working after 7.13

Thu Jan 18, 2024 11:38 pm

(deleted - just read what support said a few posts above)
 
karanik
just joined
Posts: 11
Joined: Thu Oct 07, 2021 12:15 am

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 2:43 pm

Hi

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"

Script: TelegramNetwatch
:global myVar1;
:local  myVar2;
:local MessageText "\F0\9F\9F\A2 $netDev $myVar1 $myVar2 is UP";
:local SendTelegramMessage [:parse [/system script  get Function_Telegram source]];
$SendTelegramMessage MessageText=$MessageText;
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 3:07 pm

"call this script from Netwatch"
mean that you must RUN the script, not READ the script...

Otherwise it makes no sense, you could have put the source script directly inside the event in Netwatch...

Read again the response from Support, and don't INTERPRET it, but try to UNDERSTAND it...
viewtopic.php?p=1050035#p1049636

Now I am trying to transfer the name with variable from netwatch to script. How can I do this?
Don't go off-topic, search and use the already existing topic on how to pass parameters to a script launched by different users/environments.
 
karanik
just joined
Posts: 11
Joined: Thu Oct 07, 2021 12:15 am

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 3:13 pm

"call this script from Netwatch"
mean that you must RUN the script, not READ the script...

Otherwise it makes no sense, you could have put the script directly inside the event in Netwatch...

Read again the response from Support, and don't INTERPRET it, but try to UNDERSTAND it...
viewtopic.php?p=1050035#p1049636
That's what I do.
I Call the script and it's working properly.
Now I am trying to fetch the specific name of variable

Somehow to send the name I have in netwatch to the script.

Netwatch Script
:local MessageText "\F0\9F\9F\A2 $netDev is UP";
:local SendTelegramMessage [:parse [/system script get Function_Telegram source]];
$SendTelegramMessage MessageText=$MessageText;
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 3:17 pm

Function_Telegram source is here?
viewtopic.php?p=1050038#p1050021


What quotes you use??? These are WRONG...
name

MUST be "name"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 3:34 pm

Script
: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)...

log code

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...
 
jaclaz
Long time Member
Long time Member
Posts: 667
Joined: Tue Oct 03, 2023 4:21 pm

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 4:03 pm

Only as an additional hint, maybe the issue was with the authorizations of the target script:
add dont-require-permissions=yes name=scriptnw owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon:
The dont-require-permissions=yes is needed to run the script from Netwatch
The policy=policy is needed to have access to global variables.

See:
viewtopic.php?t=145437

In an alternate universe those would be called with proper names :!: , but we have to deal with what we have in this one :roll: ...
 
karanik
just joined
Posts: 11
Joined: Thu Oct 07, 2021 12:15 am

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 4:04 pm

Function_Telegram source is here?
viewtopic.php?p=1050038#p1050021


What quotes you use??? These are WRONG...
name

MUST be "name"
Thank you. This was the wrong.
 
karanik
just joined
Posts: 11
Joined: Thu Oct 07, 2021 12:15 am

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 5:01 pm

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" "
Image

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"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 5:08 pm

???

try to replace the line
:local MessageText "$VarLocal $DevNameGlobal is Down";
with this line
:local MessageText "$VarLocal $DevNameGlobal is NOT UP";

I have one suspect...
 
karanik
just joined
Posts: 11
Joined: Thu Oct 07, 2021 12:15 am

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 7:48 pm

I tried. Same issue. Also I tried to put only one word "test"
Is it possible to test it from export?

???

try to replace the line
:local MessageText "$VarLocal $DevNameGlobal is Down";
with this line
:local MessageText "$VarLocal $DevNameGlobal is NOT UP";

I have one suspect...
 
karanik
just joined
Posts: 11
Joined: Thu Oct 07, 2021 12:15 am

Re: Netwatch with fetch stopped working after 7.13

Fri Jan 19, 2024 8:00 pm

I just deleted and I created again the script and working properly.
Probably something stuck on creation.
 
sanakess
just joined
Posts: 1
Joined: Wed Mar 20, 2024 12:19 pm

Re: Netwatch with fetch stopped working after 7.13

Wed Mar 20, 2024 12:20 pm

new command
/tool fetch mode=https url="https://api.telegram.org/botXXX/sendMessage?chat_id=-XXX&parse_mode=html&text=gw: srv-01 - UP" http-method=post keep-result=no
take from here: https://it-git.ru/set-i-kommutacija/53- ... s-713.html
 
vanderleiromera
just joined
Posts: 3
Joined: Wed Dec 23, 2015 4:00 pm

Re: Netwatch with fetch stopped working after 7.13

Wed Mar 20, 2024 11:36 pm

new command
/tool fetch mode=https url="https://api.telegram.org/botXXX/sendMessage?chat_id=-XXX&parse_mode=html&text=gw: srv-01 - UP" http-method=post keep-result=no
take from here: https://it-git.ru/set-i-kommutacija/53- ... s-713.html
Thank you!
 
CHUPAPEE
just joined
Posts: 4
Joined: Tue Dec 12, 2023 5:52 am

Re: Netwatch with fetch stopped working after 7.13

Tue Apr 23, 2024 8:38 pm

its work thanks

Who is online

Users browsing this forum: No registered users and 5 guests