<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: API calls to get config from Panorama (object, object groups, policies etc.) in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/227092#M1756</link>
    <description>&lt;P&gt;Hey Sly!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While the &lt;A href="https://github.com/kevinsteves/pan-python" target="_self"&gt;pan-python&lt;/A&gt;/&lt;A href="https://github.com/PaloAltoNetworks/pandevice" target="_self"&gt;pandevice&lt;/A&gt; and Ansible/Terraform frameworks really handy, for doing something as simple as pulling information from the Panorama/firewall config I tend to prefer rolling my own. In particular using the &lt;A href="https://github.com/martinblech/xmltodict" target="_self"&gt;xmltodict&lt;/A&gt;&amp;nbsp;module and then navigating the config as a Python dictionary can be much more intuitive and pythonic as you build out your program. Here's a sample function you can use for pulling in the Panorama configuration (in Python 3.6.5):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import requests&lt;BR /&gt;import xmltodict&lt;BR /&gt;&lt;BR /&gt;def get_config(ip: str, api_key: str) -&amp;gt; dict:
    try:
        api_call_dict = {
            'key': api_key,
            'type': 'config',
            'action': 'get',
            'xpath': f"/config"
        }&lt;BR /&gt;        url = f"https://{ip}/api"
        response = requests.post(url, api_call_dict, verify=False)
        parsed_response = xmltodict.parse(response.text)
        panorama_config = parsed_response['response']['result']['config']
        return panorama_config
    except BaseException as be:
        print(f"get_config() failed due to {be}.")
        return {}&lt;/PRE&gt;&lt;P&gt;You could then access the shared address objects by running the function like this:&lt;/P&gt;&lt;PRE&gt;pano_ip = '10.1.1.1'
pano_api_key = 'ABCDEFKEY'
pano_cfg = get_config(pano_ip, pano_api_key)
print(pano_cfg['shared']['address'])&lt;/PRE&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;&lt;P&gt;Nasir&lt;/P&gt;</description>
    <pubDate>Tue, 14 Aug 2018 21:13:08 GMT</pubDate>
    <dc:creator>nbilal</dc:creator>
    <dc:date>2018-08-14T21:13:08Z</dc:date>
    <item>
      <title>API calls to get config from Panorama (object, object groups, policies etc.)</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/224069#M1736</link>
      <description>&lt;P&gt;How can I get device group specific policies as well as shared object, object groups etc. from the Panorama. I tried with API browser and cli&amp;nbsp;(with debug cli&amp;nbsp;on) but could not find specific path/command. I have checked the xml&amp;nbsp;running config and can see the path however not sure how to use it and the type of operation. Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 18:24:31 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/224069#M1736</guid>
      <dc:creator>Sly_Cooper</dc:creator>
      <dc:date>2018-07-30T18:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: API calls to get config from Panorama (object, object groups, policies etc.)</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/224070#M1737</link>
      <description>&lt;P&gt;At this point, there are multiple ways to get and configure the firewall and Panorama without building a framework from scratch:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;High level integrations:&lt;/P&gt;
&lt;P&gt;* Ansible -&amp;nbsp;&lt;A href="http://panwansible.readthedocs.io/en/latest/" target="_blank"&gt;http://panwansible.readthedocs.io/en/latest/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;* Terraform -&amp;nbsp;&lt;A href="https://www.terraform.io/docs/providers/panos/index.html" target="_blank"&gt;https://www.terraform.io/docs/providers/panos/index.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Programatic integrations:&lt;/P&gt;
&lt;P&gt;* pandevice (python) -&amp;nbsp;&lt;A href="https://github.com/PaloAltoNetworks/pandevice" target="_blank"&gt;https://github.com/PaloAltoNetworks/pandevice&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Technically there's also pango (which Terraform support is built on), but that code should be considered alpha, as it sometimes makes breaking changes, so I wouldn't recommend using it directly right now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 18:34:15 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/224070#M1737</guid>
      <dc:creator>gfreeman</dc:creator>
      <dc:date>2018-07-30T18:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: API calls to get config from Panorama (object, object groups, policies etc.)</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/224448#M1742</link>
      <description>&lt;P&gt;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/46544"&gt;@gfreeman&lt;/a&gt;&amp;nbsp;Can I use Terraform or Ansible purely for getting data (no updating)? I am using Python with pan-python now.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 16:08:08 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/224448#M1742</guid>
      <dc:creator>Sly_Cooper</dc:creator>
      <dc:date>2018-08-01T16:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: API calls to get config from Panorama (object, object groups, policies etc.)</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/224450#M1744</link>
      <description>&lt;P&gt;To some extent yes.&amp;nbsp; Ansible has facts and Terraform has data sources.&amp;nbsp; If you give me a bit more info on what kind of data you'd want, I can be more specific..?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition to that, pan-python is a good library (it's what pandevice is built on top of).&amp;nbsp; pandevice functions very differently from pan-python, however if you're already not afraid of the API, maybe pandevice could be a good path forward.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 16:23:26 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/224450#M1744</guid>
      <dc:creator>gfreeman</dc:creator>
      <dc:date>2018-08-01T16:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: API calls to get config from Panorama (object, object groups, policies etc.)</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/227092#M1756</link>
      <description>&lt;P&gt;Hey Sly!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While the &lt;A href="https://github.com/kevinsteves/pan-python" target="_self"&gt;pan-python&lt;/A&gt;/&lt;A href="https://github.com/PaloAltoNetworks/pandevice" target="_self"&gt;pandevice&lt;/A&gt; and Ansible/Terraform frameworks really handy, for doing something as simple as pulling information from the Panorama/firewall config I tend to prefer rolling my own. In particular using the &lt;A href="https://github.com/martinblech/xmltodict" target="_self"&gt;xmltodict&lt;/A&gt;&amp;nbsp;module and then navigating the config as a Python dictionary can be much more intuitive and pythonic as you build out your program. Here's a sample function you can use for pulling in the Panorama configuration (in Python 3.6.5):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import requests&lt;BR /&gt;import xmltodict&lt;BR /&gt;&lt;BR /&gt;def get_config(ip: str, api_key: str) -&amp;gt; dict:
    try:
        api_call_dict = {
            'key': api_key,
            'type': 'config',
            'action': 'get',
            'xpath': f"/config"
        }&lt;BR /&gt;        url = f"https://{ip}/api"
        response = requests.post(url, api_call_dict, verify=False)
        parsed_response = xmltodict.parse(response.text)
        panorama_config = parsed_response['response']['result']['config']
        return panorama_config
    except BaseException as be:
        print(f"get_config() failed due to {be}.")
        return {}&lt;/PRE&gt;&lt;P&gt;You could then access the shared address objects by running the function like this:&lt;/P&gt;&lt;PRE&gt;pano_ip = '10.1.1.1'
pano_api_key = 'ABCDEFKEY'
pano_cfg = get_config(pano_ip, pano_api_key)
print(pano_cfg['shared']['address'])&lt;/PRE&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;&lt;P&gt;Nasir&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 21:13:08 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/api-calls-to-get-config-from-panorama-object-object-groups/m-p/227092#M1756</guid>
      <dc:creator>nbilal</dc:creator>
      <dc:date>2018-08-14T21:13:08Z</dc:date>
    </item>
  </channel>
</rss>

