node-red-contrib / node-red-contrib-mikrotik

Node-red node to work with Mikrotik WiFi router
ISC License
14 stars 14 forks source link

error for enabling/disabling Mikrotik firewall rules or address-list commands #31

Closed ckishappy closed 3 years ago

ckishappy commented 3 years ago

Hi, I get only errors when I trigger to enable or disable a firewall rule (same for address-list enable or disable). The simple commands like ["/system/health/print"] work well (triggered by inject or change nodes). See below the concrete change node & flow affected with the HomeKit switch triggering a change node to trigger the Mikrotik node. After executing the firewall filter change command, the Mikrotik Node response is: "Error executing cmd[["/firewall/filter/disable","=numbers=*1",".tag=qza34hdi"]]: {}". Not sure what it means? the .tag id is different per command executed.

Questions: 1) how can those enable/disable firewall rules or address-list commands be processed by the Mikrotik node? 2) how can I add multiple numbers of the firewall rules or address lists (i.e. filter rule number 1 and 2 as example) in the same string?

Firewall filter change node json (here for filter rule number 1): [ "/firewall/filter/disable", "=numbers=*1" ]

Full node-red flow with debug nodes:

[{"id":"12dc7621.ef2412","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"1a16243a.716d8c","type":"inject","z":"12dc7621.ef2412","name":"Initial Set On","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"{\"On\":1}","payloadType":"json","x":110,"y":140,"wires":[["ba2f4e50.e7a5a"]]},{"id":"ba2f4e50.e7a5a","type":"homekit-service","z":"12dc7621.ef2412","accessory":"a0542b28.0d191","name":"TV Internet","serviceName":"Switch","x":110,"y":200,"wires":[["6276acfe.c4b414"]]},{"id":"fcaccf64.b6c328","type":"change","z":"12dc7621.ef2412","name":"TV filter enable command","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\"/firewall/filter/enable\",\"=numbers=*1\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":220,"wires":[["1abd9c5.5b3bce4","3cc4ef13.9ab38"]]},{"id":"3cc4ef13.9ab38","type":"debug","z":"12dc7621.ef2412","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":260,"wires":[]},{"id":"b8c0358d.025468","type":"change","z":"12dc7621.ef2412","name":"TV filter disable command","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\"/firewall/filter/disable\",\"=numbers=*1\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":180,"wires":[["1abd9c5.5b3bce4","415d7309.9ed464"]]},{"id":"1abd9c5.5b3bce4","type":"mikrotik","z":"12dc7621.ef2412","device":"93b0bc47.fecbe8","name":"Mikrotik API","action":"9","command":"","command-type":"json","x":890,"y":200,"wires":[[]]},{"id":"338c8e57.7265aa","type":"switch","z":"12dc7621.ef2412","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":200,"wires":[["b8c0358d.025468"],["fcaccf64.b6c328"]]},{"id":"415d7309.9ed464","type":"debug","z":"12dc7621.ef2412","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":140,"wires":[]},{"id":"3335e825.090ff","type":"debug","z":"12dc7621.ef2412","name":"0","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":320,"y":140,"wires":[]},{"id":"6276acfe.c4b414","type":"template","z":"12dc7621.ef2412","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.On}}","output":"json","x":280,"y":200,"wires":[["338c8e57.7265aa","3335e825.090ff"]]},{"id":"a0542b28.0d191","type":"homekit-accessory","accessoryName":"Smarthome NR TEST","pinCode":"111-11-111","port":"9124","manufacturer":"Openhab","model":"Default Model","serialNo":"Default Serial Number","accessoryType":"2"},{"id":"93b0bc47.fecbe8","type":"mikrotik-device","host":"192.168.60.1","port":"8728","username":null,"password":null}]

konne commented 3 years ago

@ckishappy Hi, I'm not an expert for command with the winbox API but I expect a different command to handle your requested command: [ "/ip/firewall/nat/disable", "=numbers=1" ]

bye Konrad

ckishappy commented 3 years ago

Ah you got it! this one is correct indeed [ "/ip/firewall/nat/disable", "=numbers=1" ]. Thanks for correcting me on this one!!