Page 1 of 1

Python plugin: Mikrotik RouterOS

Posted: Monday 28 August 2017 18:03
by mrinner
Plugin for Mikrotik RouterOS

* Bandwidth usage monitor for selected interface (by interval requests)
* Manage interface status (realtime)

Can be found here: https://github.com/mrin/domoticz-routeros-plugin

Provides sub devices:
- Bandwidth UP
- Bandwidth Down
- Interface Status
down.png
down.png (14.3 KiB) Viewed 7209 times
up.png
up.png (14.06 KiB) Viewed 7209 times
status.png
status.png (16.91 KiB) Viewed 6621 times

Re: Python plugin: Mikrotik RouterOS [bw usage monitor]

Posted: Thursday 31 August 2017 8:50
by proohu01
Thanks for the plugin. It works like a charm.
The logging is a bit much though. It would be nice to make it less chatty.

Re: Python plugin: Mikrotik RouterOS [bw usage monitor]

Posted: Thursday 31 August 2017 10:25
by proohu01
I just wanted to make it look more familiar so I created a custon icon. This is the Winbox icon.
mikrotik.PNG
mikrotik.PNG (84.87 KiB) Viewed 7227 times
Winbox.zip
(13.73 KiB) Downloaded 173 times

Re: Python plugin: Mikrotik RouterOS [bw usage monitor]

Posted: Thursday 31 August 2017 12:08
by mrinner
@proohu01, Thanks! Icon added and logging fixed. Just update plugin (git pull) and restart domoticz.

Re: Python plugin: Mikrotik RouterOS [bw usage monitor]

Posted: Thursday 31 August 2017 12:59
by proohu01
Perfect. Thank you.

A bit off-topic perhaps but I was wondering if a similar method could be used to check whether or not a specific MAC addresses are present in the ARP table of the Microtik router. This way, precense detection for eg. my mobile phones would be more reliable and less batery intensive for the phone.

Re: Python plugin: Mikrotik RouterOS [bw usage monitor]

Posted: Thursday 31 August 2017 15:12
by mrinner
It's possible to get ARP table in plugin (console cmd "/ip arp print "). I want to try use BLE for presence detection (phone, nut3 tag), but in couple with ARP it's good idea, but seems like ARP cached for long time. Need to think how to use/add it.

Re: Python plugin: Mikrotik RouterOS [bw usage monitor]

Posted: Saturday 28 October 2017 8:29
by korniza
Thank you all for this plugin!
it was the gift I was waiting for so long. My question is if also displays status of this interface (active/disabled/disconnected) so to trigger another device/script.

Re: Python plugin: Mikrotik RouterOS

Posted: Monday 04 December 2017 14:22
by mrinner
Plugin update 0.1.0

Whats new:
* Manage interface status (status and manage in realtime)
* new core lib for communication with mikrotik for work in non-blocking mode (uses native domoticz framework connection)

Re: Python plugin: Mikrotik RouterOS

Posted: Friday 01 June 2018 19:29
by Kruu
I have 3g usb backup on mikrotik, is it possible to se when I am using 3g and when using eth1 for WAN?

Re: Python plugin: Mikrotik RouterOS

Posted: Wednesday 27 March 2019 10:32
by Gianni
sorry to bring this back up but is this plugin still working?

I installed everything,and in my log file i see that my api works and i got some replay from my router but i did not see any new devices under de device tab?
my log

Code: Select all

 2019-03-27 10:14:04.451 (RouterMikro) Sending 110 bytes of data
2019-03-27 10:14:04.451 (RouterMikro) 1a 2f 69 6e 74 65 72 66 61 63 65 2f 6d 6f 6e 69 74 6f 72 2d ./interface/monitor-
2019-03-27 10:14:04.451 (RouterMikro) 74 72 61 66 66 69 63 0e 3d 69 6e 74 65 72 66 61 63 65 3d 57 traffic.=interface=W
2019-03-27 10:14:04.451 (RouterMikro) 61 6e 09 3d 6f 6e 63 65 3d 79 65 73 30 3d 2e 70 72 6f 70 6c an.=once=yes0=.propl
2019-03-27 10:14:04.451 (RouterMikro) 69 73 74 3d 72 78 2d 62 69 74 73 2d 70 65 72 2d 73 65 63 6f ist=rx-bits-per-seco
2019-03-27 10:14:04.452 (RouterMikro) 6e 64 2c 74 78 2d 62 69 74 73 2d 70 65 72 2d 73 65 63 6f 6e nd,tx-bits-per-secon
2019-03-27 10:14:04.452 (RouterMikro) 64 07 2e 74 61 67 3d 62 77 00 .. .. .. .. .. .. .. .. .. .. d..tag=bw.
2019-03-27 10:14:04.456 (RouterMikro) Pushing 'ReadEvent' on to queue
2019-03-27 10:14:04.502 (RouterMikro) Processing 'ReadEvent' message
2019-03-27 10:14:04.502 (RouterMikro) Received 81 bytes of data
2019-03-27 10:14:04.502 (RouterMikro) 03 21 72 65 07 2e 74 61 67 3d 62 77 1a 3d 72 78 2d 62 69 74 .!re..tag=bw.=rx-bit
2019-03-27 10:14:04.502 (RouterMikro) 73 2d 70 65 72 2d 73 65 63 6f 6e 64 3d 31 33 36 38 37 32 19 s-per-second=136872.
2019-03-27 10:14:04.502 (RouterMikro) 3d 74 78 2d 62 69 74 73 2d 70 65 72 2d 73 65 63 6f 6e 64 3d =tx-bits-per-second=
2019-03-27 10:14:04.502 (RouterMikro) 38 37 31 33 36 00 05 21 64 6f 6e 65 07 2e 74 61 67 3d 62 77 87136..!done..tag=bw
2019-03-27 10:14:04.502 (RouterMikro) 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
2019-03-27 10:14:04.502 (RouterMikro) Pushing 'onMessageCallback' on to queue
2019-03-27 10:14:04.502 (RouterMikro) Processing 'onMessageCallback' message
2019-03-27 10:14:04.502 (RouterMikro) Calling message handler 'onMessage'.
2019-03-27 10:14:09.428 (RouterMikro) Pushing 'onHeartbeatCallback' on to queue
2019-03-27 10:14:09.461 (RouterMikro) Processing 'onHeartbeatCallback' message
2019-03-27 10:14:09.462 (RouterMikro) Calling message handler 'onHeartbeat'.
2019-03-27 10:14:09.462 (RouterMikro) Pushing 'WriteDirective' on to queue
2019-03-27 10:14:09.462 (RouterMikro) Processing 'WriteDirective' message
2019-03-27 10:14:09.462 (RouterMikro) Sending 110 bytes of data
2019-03-27 10:14:09.462 (RouterMikro) 1a 2f 69 6e 74 65 72 66 61 63 65 2f 6d 6f 6e 69 74 6f 72 2d ./interface/monitor-
2019-03-27 10:14:09.462 (RouterMikro) 74 72 61 66 66 69 63 0e 3d 69 6e 74 65 72 66 61 63 65 3d 57 traffic.=interface=W
2019-03-27 10:14:09.462 (RouterMikro) 61 6e 09 3d 6f 6e 63 65 3d 79 65 73 30 3d 2e 70 72 6f 70 6c an.=once=yes0=.propl
2019-03-27 10:14:09.462 (RouterMikro) 69 73 74 3d 72 78 2d 62 69 74 73 2d 70 65 72 2d 73 65 63 6f ist=rx-bits-per-seco
2019-03-27 10:14:09.463 (RouterMikro) 6e 64 2c 74 78 2d 62 69 74 73 2d 70 65 72 2d 73 65 63 6f 6e nd,tx-bits-per-secon
2019-03-27 10:14:09.463 (RouterMikro) 64 07 2e 74 61 67 3d 62 77 00 .. .. .. .. .. .. .. .. .. .. d..tag=bw.
2019-03-27 10:14:09.467 (RouterMikro) Pushing 'ReadEvent' on to queue
2019-03-27 10:14:09.513 (RouterMikro) Processing 'ReadEvent' message
2019-03-27 10:14:09.513 (RouterMikro) Received 79 bytes of data 

Re: Python plugin: Mikrotik RouterOS

Posted: Sunday 15 March 2020 9:35
by skom
Regarding the presence detection of e.g. a telephone, I noticed that the status is updated on an ongoing basis in IP/DHCP Server/Leases in the Active Address column table. Maybe this information can be used to detect presence? Unfortunately, I don't know how I can check it using the API :(

Re: Python plugin: Mikrotik RouterOS

Posted: Thursday 19 March 2020 15:07
by gikah
Gianni wrote: ā†‘Wednesday 27 March 2019 10:32 sorry to bring this back up but is this plugin still working?
I can confirm that plugin is working correctly. I installed it today using readme file from github and it's work as expected since first run.

Re: Python plugin: Mikrotik RouterOS

Posted: Tuesday 31 March 2020 18:17
by marekkubica1980
Hi

I have some issues with the plugin , in the log files it looks the plug in manage to sucesfully log in to the api of mikrotik but could not receive any information . On the Mikrotik consol I do not see that the user for api was used at all. I tryied to monitor different interfaces change the mikrotik api settings and users double check the user and password all looks good . Do you have any idea . I am using Router OS v6.40.8 (bugfix).

Code: Select all

2020-03-31 18:13:17.465 (Python Plugin) Pushing 'onHeartbeatCallback' on to queue
2020-03-31 18:13:17.504 (Python Plugin) Processing 'onHeartbeatCallback' message
2020-03-31 18:13:17.504 (Python Plugin) Calling message handler 'onHeartbeat'.
2020-03-31 18:13:17.504 (Python Plugin) Mikrotik re-connecting...
2020-03-31 18:13:17.504 (Python Plugin) Pushing 'ConnectDirective' on to queue
2020-03-31 18:13:17.504 (Python Plugin) Processing 'ConnectDirective' message
2020-03-31 18:13:17.504 (Python Plugin) Transport set to: 'TCP/IP', 192.168.1.1:8728.
2020-03-31 18:13:17.505 (Python Plugin) Connect directive received, action initiated successfully.
2020-03-31 18:13:17.505 (Python Plugin) Pushing 'onConnectCallback' on to queue
2020-03-31 18:13:17.555 (Python Plugin) Processing 'onConnectCallback' message
2020-03-31 18:13:17.555 (Python Plugin) Calling message handler 'onConnect'.
2020-03-31 18:13:17.555 (Python Plugin) Mikrotik connected. Login...
2020-03-31 18:13:17.555 (Python Plugin) Pushing 'WriteDirective' on to queue
2020-03-31 18:13:17.555 (Python Plugin) Processing 'WriteDirective' message
2020-03-31 18:13:17.555 (Python Plugin) Sending 27 bytes of data
2020-03-31 18:13:17.555 (Python Plugin) 06 2f 6c 6f 67 69 6e 12 2e 74 61 67 3d 69 6e 69 74 69 61 6c ./login..tag=initial
2020-03-31 18:13:17.555 (Python Plugin) 5f 6c 6f 67 69 6e 00 .. .. .. .. .. .. .. .. .. .. .. .. .. _login.
2020-03-31 18:13:17.557 (Python Plugin) Pushing 'ReadEvent' on to queue
2020-03-31 18:13:17.606 (Python Plugin) Processing 'ReadEvent' message
2020-03-31 18:13:17.606 (Python Plugin) Received 64 bytes of data
2020-03-31 18:13:17.606 (Python Plugin) 05 21 64 6f 6e 65 12 2e 74 61 67 3d 69 6e 69 74 69 61 6c 5f .!done..tag=initial_
2020-03-31 18:13:17.606 (Python Plugin) 6c 6f 67 69 6e 25 3d 72 65 74 3d 36 33 33 64 34 35 30 34 30 login%=ret=633d45040
2020-03-31 18:13:17.606 (Python Plugin) 39 32 64 35 65 32 65 32 33 62 32 38 30 39 37 31 37 63 65 63 92d5e2e23b2809717cec
2020-03-31 18:13:17.606 (Python Plugin) 61 32 64 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. a2d.
2020-03-31 18:13:17.606 (Python Plugin) Pushing 'onMessageCallback' on to queue
2020-03-31 18:13:17.606 (Python Plugin) Processing 'onMessageCallback' message
2020-03-31 18:13:17.606 (Python Plugin) Calling message handler 'onMessage'.
2020-03-31 18:13:17.606 (Python Plugin) Pushing 'WriteDirective' on to queue
2020-03-31 18:13:17.607 (Python Plugin) Processing 'WriteDirective' message
2020-03-31 18:13:17.607 (Python Plugin) Sending 52 bytes of data
2020-03-31 18:13:17.607 (Python Plugin) 06 2f 6c 6f 67 69 6e 0b 3d 6e 61 6d 65 3d 64 6f 61 70 69 10 ./login.=name=doapi.
2020-03-31 18:13:17.607 (Python Plugin) 3d 70 61 73 73 77 6f 72 64 3d 61 70 69 61 70 69 0e 2e 74 61 =password=apiapi..ta
2020-03-31 18:13:17.607 (Python Plugin) 67 3d 61 75 74 68 6f 72 69 7a 65 00 .. .. .. .. .. .. .. .. g=authorize.
2020-03-31 18:13:17.608 (Python Plugin) Pushing 'ReadEvent' on to queue
2020-03-31 18:13:17.657 (Python Plugin) Processing 'ReadEvent' message
2020-03-31 18:13:17.657 (Python Plugin) Received 60 bytes of data
2020-03-31 18:13:17.657 (Python Plugin) 05 21 64 6f 6e 65 0e 2e 74 61 67 3d 61 75 74 68 6f 72 69 7a .!done..tag=authoriz
2020-03-31 18:13:17.657 (Python Plugin) 65 25 3d 72 65 74 3d 36 33 33 64 34 35 30 34 30 39 32 64 35 e%=ret=633d4504092d5
2020-03-31 18:13:17.657 (Python Plugin) 65 32 65 32 33 62 32 38 30 39 37 31 37 63 65 63 61 32 64 00 e2e23b2809717ceca2d.
2020-03-31 18:13:17.657 (Python Plugin) Pushing 'onMessageCallback' on to queue
2020-03-31 18:13:17.657 (Python Plugin) Processing 'onMessageCallback' message
2020-03-31 18:13:17.657 (Python Plugin) Calling message handler 'onMessage'.
2020-03-31 18:13:17.658 (Python Plugin) Mikrotik logged in successfully
2020-03-31 18:13:17.658 (Python Plugin) Pushing 'WriteDirective' on to queue
2020-03-31 18:13:17.658 (Python Plugin) Pushing 'WriteDirective' on to queue
2020-03-31 18:13:17.658 (Python Plugin) Processing 'WriteDirective' message
2020-03-31 18:13:17.658 (Python Plugin) Sending 96 bytes of data
2020-03-31 18:13:17.658 (Python Plugin) 11 2f 69 6e 74 65 72 66 61 63 65 2f 6c 69 73 74 65 6e 24 3d ./interface/listen$=
2020-03-31 18:13:17.658 (Python Plugin) 2e 70 72 6f 70 6c 69 73 74 3d 2e 69 64 2c 6e 61 6d 65 2c 72 .proplist=.id,name,r
2020-03-31 18:13:17.658 (Python Plugin) 75 6e 6e 69 6e 67 2c 64 69 73 61 62 6c 65 64 0a 3f 6e 61 6d unning,disabled.?nam
2020-03-31 18:13:17.658 (Python Plugin) 65 3d 73 66 70 31 1c 2e 74 61 67 3d 69 6e 74 65 72 66 61 63 e=sfp1..tag=interfac
2020-03-31 18:13:17.658 (Python Plugin) 65 5f 73 74 61 74 75 73 5f 75 70 64 61 74 65 00 .. .. .. .. e_status_update.
2020-03-31 18:13:17.658 (Python Plugin) Processing 'WriteDirective' message
2020-03-31 18:13:17.658 (Python Plugin) Sending 88 bytes of data
2020-03-31 18:13:17.658 (Python Plugin) 10 2f 69 6e 74 65 72 66 61 63 65 2f 70 72 69 6e 74 24 3d 2e ./interface/print$=.
2020-03-31 18:13:17.658 (Python Plugin) 70 72 6f 70 6c 69 73 74 3d 2e 69 64 2c 6e 61 6d 65 2c 72 75 proplist=.id,name,ru
2020-03-31 18:13:17.658 (Python Plugin) 6e 6e 69 6e 67 2c 64 69 73 61 62 6c 65 64 0a 3f 6e 61 6d 65 nning,disabled.?name
2020-03-31 18:13:17.658 (Python Plugin) 3d 73 66 70 31 15 2e 74 61 67 3d 69 6e 74 65 72 66 61 63 65 =sfp1..tag=interface
2020-03-31 18:13:17.658 (Python Plugin) 5f 73 74 61 74 75 73 00 .. .. .. .. .. .. .. .. .. .. .. .. _status.
2020-03-31 18:13:17.659 (Python Plugin) Pushing 'ReadEvent' on to queue
2020-03-31 18:13:17.659 (Python Plugin) Queued asynchronous read aborted (192.168.1.1:8728), [2] End of file.
2020-03-31 18:13:17.659 (Python Plugin) Pushing 'DisconnectedEvent' on to queue
2020-03-31 18:13:17.709 (Python Plugin) Processing 'ReadEvent' message
2020-03-31 18:13:17.709 (Python Plugin) Received 22 bytes of data
2020-03-31 18:13:17.709 (Python Plugin) 06 21 66 61 74 61 6c 0d 6e 6f 74 20 6c 6f 67 67 65 64 20 69 .!fatal.not.logged.i
2020-03-31 18:13:17.709 (Python Plugin) 6e 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. n.
2020-03-31 18:13:17.709 (Python Plugin) Pushing 'onMessageCallback' on to queue
2020-03-31 18:13:17.709 (Python Plugin) Processing 'DisconnectedEvent' message
2020-03-31 18:13:17.709 (Python Plugin) Disconnect event received for '192.168.1.1:8728'.
2020-03-31 18:13:17.709 (Python Plugin) Pushing 'onDisconnectCallback' on to queue
2020-03-31 18:13:17.709 (Python Plugin) Processing 'onMessageCallback' message
2020-03-31 18:13:17.709 (Python Plugin) Calling message handler 'onMessage'.
2020-03-31 18:13:17.709 (Python Plugin) Processing 'onDisconnectCallback' message
2020-03-31 18:13:17.709 (Python Plugin) Calling message handler 'onDisconnect'.
2020-03-31 18:13:17.709 Error: (Python Plugin) Mikrotik error. Reply [!fatal]. Message [not logged in]. Tag [None].

Re: Python plugin: Mikrotik RouterOS

Posted: Friday 14 August 2020 6:49
by Maikel76
mrinner wrote: ā†‘Monday 04 December 2017 14:22 Plugin update 0.1.0

Whats new:
* Manage interface status (status and manage in realtime)
* new core lib for communication with mikrotik for work in non-blocking mode (uses native domoticz framework connection)
Hi,
Iā€™m using a script to turn on and off WiFi and I would like to manage the WiFi interface trough this plugin. Is that possible or do I not understand it correctly?
Thanks a lot for your reply