- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mx_firewall_control.py invalid format txt or json
Hello,
I try to use the script mx_firewall_control.py to update rulesets L3 but I've got a error message with the commands to add a ruleset.
PS C:\Meraki Python Scripts> python mxfirewallcontrol.py -o "XXXXX" -f "type:network, name: Template site MX67" -c append-file:update_input.txt
2023-07-20 18:43:07 -- Retrieving organization info...
GET https://api.meraki.com/api/v1/organizations
200
2023-07-20 18:43:07 -- Selecting networks and templates according to filters... GET https://api.meraki.com/api/v1/organizations/YYYYY/networks
200
2023-07-20 18:43:08 -- SIMULATION MODE. CHANGES WILL NOT BE SAVED. USE "-m commit" TO OVERRIDE
2023-07-20 18:43:08 -- ERROR 28: Invalid input file format "update_input.txt" 2023-07-20 18:43:08 -- ERROR: Unable to load source ruleset
But I think to follow and apply correctly the format for the file as explained on the README (to be honest, it's just a test so I don't modify a lot the template txt file provided). Also the txt file is in the same folder than the .PY.
Below the extract of the txt file (1 line per rule):
{"protocol":"any", "srcPort":"Any", "srcCidr":"10.1.1.1", "destPort":"Any","destCidr":"any", "policy":"deny", "syslogEnabled":false, "comment":"Line 1"}
{"protocol":"any", "srcPort":"Any", "srcCidr":"10.2.2.2", "destPort":"Any","destCidr":"any", "policy":"deny", "syslogEnabled":false, "comment":"Line 2"}
Also I tried to use the direct command, and I've the same type of error with an invalid format.
PS C:\Meraki Python Scripts> python mxfirewallcontrol.py -o "XXXXX" -f"type:network, name:Template site MX67" -c insert:1:"[{""protocol"":""any"", ""srcPort"":""Any"", ""srcCidr"":""10.6.0.1"", ""destPort"":""Any"", ""destCidr"":""any"", ""policy"":""deny"", ""syslogEnabled"":false, ""comment"":""Line 3""}]" -m commit
2023-07-20 18:59:43 -- Retrieving organization info...
GET https://api.meraki.com/api/v1/organizations
200
2023-07-20 18:59:44 -- Selecting networks and templates according to filters... GET https://api.meraki.com/api/v1/organizations/YYYYY/networks
200
2023-07-20 18:59:44 -- SIMULATION MODE. CHANGES WILL NOT BE SAVED. USE "-m commit" TO OVERRIDE
2023-07-20 18:59:44 -- ERROR: ERROR 50: Ruleset to be added must be given in JSON format
What I'm doing wrong ?
Here the source code: GITHUB Automation Meraki
PS1: I don't have any issue for the "print" command
PS2: I use Windows10/Visual Studio Code to launch the script.
In advance, thank you very much
Solved! Go to solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
I solved the issue with text file. it's required to add and an "ENTER"/"RETURN" at the end of the file.
Regarding the other issue, I don't find the solution but you can close this topic, my main use is with the text file method.
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try changing (this and the other references) from:
"srcCidr":"10.1.1.1"
to:
"srcCidr":"10.1.1.1/32"
So it is in CIDR format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually it is saying "Ruleset to be added must be given in JSON format". Your example you supplied looks like well formed JSON to me.
Perhaps trying breaking the file in two, and loading one half and then the other, and then narrowing it down from there. There must be an error in the source file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The JSON objects you provided seem to be correctly formatted, and there are no obvious syntax errors or missing commas.
The issue might be related to how the input data is being passed to the script, or how the script reads the input file?
Ensure that the update_input.txt file is saved with the proper encoding, such as UTF-8. You can check and change the encoding in Visual Studio Code by clicking on the "File" menu, then "Save with Encoding," and select "UTF-8" if it's not already set.
Otherwise, I reviewed the function loadruleset (responsible for loading a ruleset from a file and returning it as a list of JSON objects (rules)) catches any exceptions that occur during JSON parsing using a general except block so try to add some print statements to debug the function and check the values of p_filepath, buffer, jdump and the detailed exception at different stages to see if they match your expectations.
Let me knew If the issues persist!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
OK thank you, I will check this week.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
I solved the issue with text file. it's required to add and an "ENTER"/"RETURN" at the end of the file.
Regarding the other issue, I don't find the solution but you can close this topic, my main use is with the text file method.
Best regards,