shokinn / hetzner-ddns-for-mikrotik

A Mikrotik script to update DDNS entries via Hetzner's DNS API
MIT License
3 stars 0 forks source link

Script dont work. No mesage in Log #1

Open SvenPausH opened 9 months ago

SvenPausH commented 9 months ago

Hello Philipp, I created the script with the mikrotik json parser. Unfortunately the script doesn't work. No message appears in the log and I don't understand why.

shokinn commented 9 months ago

Hi Sven,

  1. Please check if all scripts are created correctly with the correct names (they are case sensitive!).
  2. Check if you set the correct Policies for each script.
  3. Please run the script via the Terminal and check if it prints any errors:
    /system/script/run ddns-hetzner
  4. If it does not print any errors a. Insert a :log error "[Hetzner DDNS] DEBUG" command starting in the 1st line b. Run the script c. Check the log can find the log message Hetzner DDNS] DEBUG d. If you CAN see the message, move it part, by part down the script and check when you don't get a message anymore. e. If you CAN'T see the message, check your logging configuration. Mine is configured as following:
    [xxx@xxx] > /system/logging/print 
    Flags: * - DEFAULT
    Columns: TOPICS, ACTION
    #   TOPICS    ACTION
    0 * info      memory
    1 * error     memory
    2 * warning   memory
    3 * critical  echo
SvenPausH commented 9 months ago

Hi, i have 4 Lines whith errors.

Line 134:
:set apiResponse ([/tool/fetch "$apiUrl/zones?page=$apiNextPage&search_name=$configZone" http-method=get http-header-field="Auth-API-Token:$apiKey" output=user as-value]->"data"); Line 162 :local records ([$JSONLoads ([/tool/fetch "$apiUrl/records?zone_id=$zoneId" http-method=get http-header-field="Auth-API-Token:$apiKey" output=user as-value]->"data")]->"records"); Line 171 :set apiResponse ([/tool/fetch "$apiUrl/records/$recordId" http-method=put http-header-field="Content-Type:application/json,Auth-API-Token:$apiKey" http-data=$payload output=user as-value]->"status"); Line 173 :set apiResponse ([/tool/fetch "$apiUrl/records" http-method=post http-header-field="Content-Type:application/json,Auth-API-Token:$apiKey" http-data=$payload output=user as-value]->"status");

If I comment this out then the script runs. Do you see the error?

SvenPausH commented 9 months ago

Hi, ok i understand. :set apiResponse ([/tool/fetch "$apiUrl/zones?page=$apiNextPage&search_name=$configZone" http-method=get http-header-field="Auth-API-Token:$apiKey" output=user as-value]->"data");

There ist a slash to much /tool fetch is better :set apiResponse ([/tool fetch "$apiUrl/zones?page=$apiNextPage&search_name=$configZone" http-method=get http-header-field="Auth-API-Token:$apiKey" output=user as-value]->"data");

shokinn commented 9 months ago

Hmm /tool fetch and /tool/fetch should work both the same (you can test this also in the terminal).

What I think is that the JParseFunctions are not loaded correctly.

Please try to load the JParseFuctions from your Terminal (so they are available for the whole system)

/system script run "JParseFunctions"; global JSONLoad; global JSONLoads; global JSONUnload

And run the script again afterwards.

If this works for you I would suggest to run the JParseFuctions via the Scheduler on startup.

[xxx@xxx] > /system/scheduler/print                    
Columns: NAME, START-DATE, START-TIME, INTERVAL, ON-EVENT, RUN-COUNT
# NAME             START-DATE  START-TIME  INTERVAL  ON-EVENT         RUN-COUNT
0 xxx                          startup     0s        xxx                      0
1 JParseFunctions              startup     0s        JParseFunctions          0
2 ddns-hetzner     2023-11-10  00:00:00    5m        ddns-hetzner         21810
[xxx@xxx] > /system/scheduler/print detail value-list from=JParseFunctions 
        name: JParseFunctions
  start-time: startup
    interval: 0s
    on-event: JParseFunctions
       owner: xxx
      policy: read,write,test
   run-count: 0
SvenPausH commented 9 months ago

Hello, No, unfortunately it's not what you think. Which ROS version do you have? I still have v6. Has anything changed in v7?

[admin@MikroTik4011] > /tool fetch failure: required parameters missing

[admin@MikroTik4011] > /tool/fetch 
expected command name (line 1 column 6)
shokinn commented 9 months ago

I'm on ROS 7, since it was the default for my device (RB5009). Don't know if anything has changed, but I guess since both options (with slashes or spaces as seperators) are working on v7. But haven't looked into it detailed, so you have to check it by yourself. I'm sorry.

When you've fixed it for v6 (and it's also working for v7, without using deprecated options and/or behavior). I'm happy to merge a PR :)

SvenPausH commented 9 months ago

Hello, in ROS7 both spellings are permitted. If you adapt your script it will run with ROS6 and ROS7.


  MMM      MMM       KKK                          TTTTTTTTTTT      KKK
  MMMM    MMMM       KKK                          TTTTTTTTTTT      KKK
  MMM MMMM MMM  III  KKK  KKK  RRRRRR     OOOOOO      TTT     III  KKK  KKK
  MMM  MM  MMM  III  KKKKK     RRR  RRR  OOO  OOO     TTT     III  KKKKK
  MMM      MMM  III  KKK KKK   RRRRRR    OOO  OOO     TTT     III  KKK KKK
  MMM      MMM  III  KKK  KKK  RRR  RRR   OOOOOO      TTT     III  KKK  KKK

  MikroTik RouterOS 7.12.1 (c) 1999-2023       https://www.mikrotik.com/

Press F1 for help

[admin@MikroTik] > /tool/fetch 
failure: required parameters missing
[admin@MikroTik] > /tool fetch  
failure: required parameters missing
[admin@MikroTik] >
shokinn commented 9 months ago

Seems like: https://mikrotik.com/download/changelogs#show-tab-tree_1-id-7cd31cf6820896d838535a73cafb15ca

But they state:

!) new Command Line Interface (CLI) style (RouterOS v6 commands are still supported);

They state, it's still supported, I don't know how long they will carry the old CLI version with them and I don't want to downgrade my script to an "old" cli version.
Also I don't plan to build a v6 compatible version by myself, since 1st I'm not interested in and 2nd I currently don't have to time to do so.

However, as I wrote previously I'm happy to accept a PR with a RouterOS v6 compatible version of the script.