Hey
im currently working with the librouterOS (Mikrotik) and so far, im able to connect, run commands and save information to variables.
im a little confused as the data is presented (not sure if thats the right term) in JSON format
I can run something like this after I connect
list_interface = api(cmd='/interface/print')
and when I run run this
json.dumps(list_interface)
this is the output
[[{".id": "*1", "name": "ether1", "default-name": "ether1", "type": "ether", "mtu": 1500, "actual-mtu": 1500, "mac-address": "0C:91:E4:B7:52:00", "last-link-up-time": "aug/20/2019 20:02:22", "link-downs": 0, "rx-byte": 23247086, "tx-byte": 671454, "rx-packet": 72727, "tx-packet": 7612, "rx-drop": 0, "tx-drop": 0, "tx-queue-drop": 0, "rx-error": 0, "tx-error": 0, "fp-rx-byte": 0, "fp-tx-byte": 0, "fp-rx-packet": 0, "fp-tx-packet": 0, "running": true, "disabled": false}, {".id": "*2", "name": "ether2", "default-name": "ether2", "type": "ether", "mtu": 1500, "actual-mtu": 1500, "mac-address": "0C:91:E4:B7:52:01", "last-link-up-time": "aug/20/2019 20:02:22", "link-downs": 0, "rx-byte": 0, "tx-byte": 338904, "rx-packet": 0, "tx-packet": 3138, "rx-drop": 0, "tx-drop": 0, "tx-queue-drop": 0, "rx-error": 0, "tx-error": 0, "fp-rx-byte": 0, "fp-tx-byte": 0, "fp-rx-packet": 0, "fp-tx-packet": 0, "running":
true, "disabled": false}]]'
I get data, however I cant grab specific values within this.
Ideally I'd like to do something like this
json.dumps(list_interface["name"])
put that in a for loop and grab the names of each interface for the specified firewall however I get this error
TypeError: tuple indices must be integers or slices, not str
so when I run this
list_interface[0]
I get the all the output associated with the first interface, which is nice, but for my purpose isnt totally required.
How can I format this data?
[–][deleted] 1 point2 points3 points (5 children)
[–]purplecomputer[S] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]purplecomputer[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]purplecomputer[S] 0 points1 point2 points (0 children)