luqasz / librouteros

Python implementation of MikroTik RouterOS API
GNU General Public License v2.0
222 stars 50 forks source link

Import File Output #228

Closed luisvalleGH closed 10 months ago

luisvalleGH commented 10 months ago

I have to approachs that work perfectly and Import a file inside the Mikrotik correctly. The issue I'm facing is to get the output of the command.

Inside the console I got this

/import file-name=SNMP.rsc
Script Run OK (Whatever I print with :put inside the file)

Script file loaded and executed successfully (the actual mikrotik output)

Whe using the library and doing the command via API this are the two codes that work

api = connect(username=username, password=password, host=host)

path = api.path('/')

response = tuple(path('import', **{'file-name' : 'SNMP.rsc'}))
api = connect(username=username, password=password, host=host)

response = api('/import', **{'file-name':'SNMP.rsc'})

When I try to consume the generator response returning it or iterating it i got a trap error

{
  "detail": "Mikrotik Trap Error: no such item"
}
luqasz commented 10 months ago

I am confused. You wrote that code works and when you consume iterator, you get a error.

luisvalleGH commented 10 months ago

I am confused. You wrote that code works and when you consume iterator, you get a error.

The code works because the file is correctly imported into the Mikrotik, but it throws an error when it tries to bring the output. Try to print or iterate in the response and you'll get the error, unless this is a spected behaviour of the Mikrotik API and it's a fire and forget command where you don't get any output.

luqasz commented 10 months ago

I've done import on my router and all works fine. I have 7.12 version. Try importing same file from cli and see if it throws any error.

luisvalleGH commented 10 months ago

I've done import on my router and all works fine. I have 7.12 version. Try importing same file from cli and see if it throws any error.

Yes, the import works OK as I wrote before, what i can't get is the OUTPUT, I'm testing this in 6.x versions, in 7.x I'm using the Rest API.

luqasz commented 10 months ago

But there is no output from import.

luisvalleGH commented 10 months ago

But there is no output from import.

Ok, It's possible a concept error I have. After the file is imported the console hasta an output Script file loaded and executed successfully also during the script in the file you can log or :put lines in the console. This "Output" might not be considered in the API.

Thank's @luqasz , I'm closing the issue.