Python plugin: Mikrotik RouterOS

Python and python framework

Moderator: leecollings

Post Reply
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Python plugin: Mikrotik RouterOS

Post 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 7198 times
up.png
up.png (14.06 KiB) Viewed 7198 times
status.png
status.png (16.91 KiB) Viewed 6610 times
Last edited by mrinner on Monday 04 December 2017 14:19, edited 3 times in total.
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post 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.
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post 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 7216 times
Winbox.zip
(13.73 KiB) Downloaded 170 times
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

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

Post by mrinner »

@proohu01, Thanks! Icon added and logging fixed. Just update plugin (git pull) and restart domoticz.
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post 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.
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

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

Post 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.
korniza
Posts: 157
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6028
Location: Greece
Contact:

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

Post 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.
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)
mrinner
Posts: 56
Joined: Tuesday 22 August 2017 20:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Belarus
Contact:

Re: Python plugin: Mikrotik RouterOS

Post 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)
Kruu
Posts: 49
Joined: Tuesday 17 January 2017 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python plugin: Mikrotik RouterOS

Post 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?
Gianni
Posts: 230
Joined: Saturday 21 July 2018 19:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Home@Belgium
Contact:

Re: Python plugin: Mikrotik RouterOS

Post 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 
skom
Posts: 18
Joined: Sunday 15 March 2020 9:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Poland
Contact:

Re: Python plugin: Mikrotik RouterOS

Post 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 :(
gikah
Posts: 5
Joined: Monday 27 May 2019 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Contact:

Re: Python plugin: Mikrotik RouterOS

Post 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.
marekkubica1980
Posts: 1
Joined: Tuesday 31 March 2020 18:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Mikrotik RouterOS

Post 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].
Maikel76
Posts: 71
Joined: Friday 14 August 2020 6:34
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Bangkok
Contact:

Re: Python plugin: Mikrotik RouterOS

Post 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
Scripting is my passion, dzVents, LUA, Bash
Dashticz v3.10.7 Beta --Raspbian Buster
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest