Community discussions

MikroTik App
 
dakobg
Member Candidate
Member Candidate
Topic Author
Posts: 120
Joined: Mon Nov 06, 2017 8:58 am

SwOS api

Sun Feb 21, 2021 5:25 pm

With CSS610 as a new product, any plans for SwOS API ?
 
chubbs596
Frequent Visitor
Frequent Visitor
Posts: 90
Joined: Fri Dec 06, 2013 6:07 pm

Re: SwOS api

Thu Mar 18, 2021 10:21 am

We also want to see a API for SwOS and SwOS lite, and possible telnet/ssh access aswell
 
BuGless
just joined
Posts: 12
Joined: Wed Jul 20, 2022 6:54 pm
Location: The Netherlands

Re: SwOS api

Thu Jul 21, 2022 9:03 am

Actually, SwOS already has an API.
All we need is documentation for it (or reverse engineer it).
To wit:

URL: /link.b

The Authorization header uses a token to keep the session going.

The payload appears to be JSON (with a misleading text/plain MIME-type).
In that JSON payload I can already recognise:
en: Bitmask for all enabled ports. Disabled ports have a zero bit. Ports are numbered little endian style (i.e. bit zero = port 1).
fctc: Bitmask for flow-control TX. Ports are numbered the same as for en.
nm: Port names, normal array, ports are numbered normally.
fctr: Bitmask for flow-control RX. Same bitmask as other fields.
etc.

It's really easy to reverse engineer (which is a plus).
How about it, Mikrotik, and release the documentation for it?
 
User avatar
f008600
just joined
Posts: 12
Joined: Tue Mar 05, 2024 10:33 pm
Location: Germany
Contact:

Re: SwOS api

Mon Mar 11, 2024 11:51 am

How about it, Mikrotik, and release the documentation for it?
Any plans to document the binary/json API?
It seems that this API is in constant change (or SwOS Lite differs completely from SwOS, API wise).
 
gaileys
just joined
Posts: 3
Joined: Wed Mar 20, 2024 9:31 pm

Re: SwOS api

Wed Mar 20, 2024 9:35 pm

I was inspired. I have built a small docker application to act as a reverse proxy for any number of Mikrotik switches. I then make the call to the switch to pick up their config files "link.b" "sys.b" etc. and return json. I was frustrated that my Homepage dashboard only gave me widgets for RouterOS and not Switch OS.

I'm just testing this at home now and it only picks up Link status, Speed and name for each port but seems to work reliably at least for the two switches I have. I'll post on here in a wekk or so when I have completed it and where you can pull it from on docker hub. Now would be a good time to request anything specific you need.

Warning, because of my own needs this is brain dead when it comes to security and the router, username and password for the switch are in the url... I'll look at adding a post option which will hide thouse things.
 
gaileys
just joined
Posts: 3
Joined: Wed Mar 20, 2024 9:31 pm

Re: SwOS api

Mon Mar 25, 2024 1:27 pm

OK I have put this up on Docker Hub and I'm using it with Homepage to give me details of my two switches. https://hub.docker.com/repository/docke ... sw/general

Just do a GET on
/api/v1/getswitch/switchip/switchuser/password
I know that is dreadful, putting the username and password in the URL but the homepage custom api widget doesn't allow you to control the body of a post so that was the easiest way to do it without having to have a config for each switch.

Happy to modify or add features if people actually want to use it...
I was inspired. I have built a small docker application to act as a reverse proxy for any number of Mikrotik switches. I then make the call to the switch to pick up their config files "link.b" "sys.b" etc. and return json. I was frustrated that my Homepage dashboard only gave me widgets for RouterOS and not Switch OS.

I'm just testing this at home now and it only picks up Link status, Speed and name for each port but seems to work reliably at least for the two switches I have. I'll post on here in a wekk or so when I have completed it and where you can pull it from on docker hub. Now would be a good time to request anything specific you need.

Warning, because of my own needs this is brain dead when it comes to security and the router, username and password for the switch are in the url... I'll look at adding a post option which will hide thouse things.
Last edited by gaileys on Tue Mar 26, 2024 8:11 pm, edited 1 time in total.
 
User avatar
f008600
just joined
Posts: 12
Joined: Tue Mar 05, 2024 10:33 pm
Location: Germany
Contact:

Re: SwOS api

Tue Mar 26, 2024 9:27 am

Thanks @gaileys for your work, but I do not want to run a blackbox on my server/pc and enter username/passwort for my core switch into it. Do you have any git repo, so I can have a look at the source?
I am more interested in understanding the API than a "ready to use" solution. I want to integrate SwitchOS support into my switch manager lib, which already support Cisco, Juniper and other brands.

So, the question remains: Are there any chance to get some documentation on the SwitchOS (Lite) API?
 
gaileys
just joined
Posts: 3
Joined: Wed Mar 20, 2024 9:31 pm

Re: SwOS api

Tue Mar 26, 2024 1:26 pm

I haven't put this on git but could look to do that. The code is all Scala, and not very good scala at that as it was a quick and dirty solution; so you'd need to be comfortable with that. The easiest way to understand the api is to just use curl:
curl --compressed  --digest -u user:password -v http://192.168.5.2/link.b
The things you need to pull are !sys.b, link.b, stats.b and probably others, depending upon what you want to see, but you will find them all in index.html, together with Javascript to process them.

If you are a Javascript kind of a guy then index.html will tell you everything you need. I'm not so kind of figured out what I needed from clues in the naming conventions used inside the data packages. Most things are hex encoded so you'll need to parse out the data which is a Javascript object format as close as I can figure. Would have been so much easier if they were json encoded but hey.

I only have two Mikrotik switches to pull data from but most things seem to be comman between them. I don't run VLANS so none of that was of interest to me and hence I didn't have examples to reverse engineer...
 
hhjklhjghjflkhgfomhf
just joined
Posts: 2
Joined: Mon Mar 25, 2024 10:51 am

Re: SwOS api

Sat Apr 27, 2024 5:28 pm

I have partially implemented some stuff to manage my css326 with saltstack. Maybe, this can help to do better things:
https://github.com/y-martin/pkg-python3-mikrotik-swos
https://github.com/y-martin/salt_mikrotik_swos

I don't have implemented everything (for example I don't use ACL).
 
User avatar
f008600
just joined
Posts: 12
Joined: Tue Mar 05, 2024 10:33 pm
Location: Germany
Contact:

Re: SwOS api

Sun Apr 28, 2024 6:28 pm

I have partially implemented some stuff to manage my css326 with saltstack.[...]
Thanks! CSS326 works with SwOS. The API looks straightforward.
But SwOS Lite is a different beast :( Nobody reverse engineered this binary blob yet?
 
dvision1979
just joined
Posts: 1
Joined: Mon Nov 25, 2024 12:05 am

Re: SwOS api

Mon Nov 25, 2024 12:05 am

Is there also a module for homepage to use with your docker container?
Thanks.

Who is online

Users browsing this forum: No registered users and 2 guests