Enhanced Security Measures in Place:   To ensure a safer experience, we’ve implemented additional, temporary security measures for all users.

Using x-path with spaces

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Using x-path with spaces

L3 Networker

Hi,

The "load config partial from x-path" is great for copy or moving config but I can't work out how to get it to deal with spaces. e.g. if I want to copy a policy and the policy name has a space in it I can't get the correct syntax.

 

The XML API Browser gives me an x-path of .../entry[@name='Policy+Name+Here'] however the CLI returns an error "Server error : Failed to compose effective config to load. input file doesn't have anything at ..."

 

If I take the spaces out it works perfectly.

 

How do you get x-path to process spaces?


Thanks,
Shannon

13 REPLIES 13

L3 Networker

Note: just to clarify the actual policy name is "Policy Name Here" - the XML API Browser adds the "+" symbols shown in the original post automatically wherever a space exists, but the x-path call from the CLI does not seem to accept it.

L4 Transporter

Replace the plus signs with spaces. The name is already embraced by quotes. 

Hey - thanks for the response, unfortunately I have tried that and it still does not accept it. Does not like the syntax. I tried with single and double quotes.

Thanks,
Shannon

Hey @SARowe_NZ 

I had a similar issue with this when I was writing my Python code as I needed to move config around devices where other methods available wouldn't work. I have learned how to work with Python (only 2nd week in), in a very basic sense and have written this code. It is only very basic for the moment, but allows for bulk importing of objects. I am working on Policies and Network configurations this week.

So depending on your familiarity with Python this might help you out or at least get you started, if it's not working for you and want me to make some modifications to the code to allow it to work in your environment just let me know via the methods I have suggested in github repo.

 

All the best mate!

Daniel Bostock | Senior IT Operations Engineer, EML Payments | Blog: https://danielbostock.com

Hey Daniel,

Thanks for that - appreciate your help!

Unfortunately my knowledge of python is zero.

 

Surely it must be possible to parse a space in the CLI x-path call.

Cheers,

Shannon

@SARowe_NZ 

 

Hey in your initial comments you say you want to copy a policy, so to be clear is it only one policy at a time that you are copying or are you want to copy all security policies in one Palo to another Palo?

Daniel Bostock | Senior IT Operations Engineer, EML Payments | Blog: https://danielbostock.com

Hey,

That was an example - its actually lots of different configuration elements (policies / objects / VPNs etc). I'm moving config around between firewalls and different Templates/Device Groups on our Panorama. For the most part it is quite granular (per policy / vpn etc) which is the challenge. If it was all of them I could just use the root x-path for (e.g.) policies as the root x-path would have no spaces, but unfortunately much of this has to be done at individual item level.

 

Cheers,
Shannon

Ah ok yeah from my limited understanding and knowledge I can't really see how to modify the cli command to allow for random objects with spaces. Potentially if you are wanting to persist with x-path you may need to edit these xml config files prior to importing and strip the spaces with a find and replace, before uploading the configuration file to the Palo.

 

However I think spending some time Python or even using Powershells API module is the better way moving forward to do scripted tasks like this as the API's are far more flexible and programmable than x-path. But I do appreciate why you might not want to make this effort, so hopefully doing a find and replace might be a workable solution.

 

Daniel Bostock | Senior IT Operations Engineer, EML Payments | Blog: https://danielbostock.com

Thanks - given I'd be starting at the zero with python the learning curve would be too much and I'd need to dedicate too much time to justify it just for this. I have not looked at the powershell option though so that could definitely work, as I suspect it is much simpler for a script notice like me - I will check it out!

 

Cheers,

Shannon

Yeah I get ya mate, I would also recommend getting familiar with using Postman as well, it is a very helpful tool in writing a API call in powershell or any scripting language. For example you can formulate the API call with postman then get the code you need to put in powershell to make the script.

 

DanielBostock_0-1591333024749.png

 

 

Daniel Bostock | Senior IT Operations Engineer, EML Payments | Blog: https://danielbostock.com

Cool thanks for that - really appreciate all your help!

No worries mate, my pleasure, all the best with getting it sorted!

Daniel Bostock | Senior IT Operations Engineer, EML Payments | Blog: https://danielbostock.com

L2 Linker

In the CLI, use the policy name with spaces instead of the plus sign but enclose the entire xpath in double quotes.

  • 10619 Views
  • 13 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!