<?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 Im confused how to get the member list of a dynamic address group from a specific device-group using my rest api from panorama. in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/im-confused-how-to-get-the-member-list-of-a-dynamic-address/m-p/548302#M3390</link>
    <description>&lt;P&gt;I have the following working code.. which gives me the specific dynamic address groups which match my use case, and tells me the snippet of tag info i want to display to the consumers of my script. now i want to include the member list for each of these DAG as well and I cant seem to formulate the proper api call..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import requests&lt;BR /&gt;import json&lt;BR /&gt;from sys import argv&lt;BR /&gt;from requests.exceptions import HTTPError&lt;BR /&gt;import urllib3&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#disable SSL warnings&lt;BR /&gt;urllib3.disable_warnings()&lt;/P&gt;&lt;P&gt;#This function is intended to clean up the data in the key,value fields of the DAG and provide a clean format of just the POD number in a list. This only provide the output necessary for the&lt;BR /&gt;#consumer to determine if their tag is present and in use to fill this DAG.&lt;BR /&gt;def parse_tag_input(input_string):&lt;BR /&gt;# Remove surrounding brackets and quotes&lt;BR /&gt;input_string = input_string.strip("[']").strip()&lt;/P&gt;&lt;P&gt;# Split the input string based on "or" separator&lt;BR /&gt;items = input_string.split(" or ")&lt;/P&gt;&lt;P&gt;parsed_items = []&lt;BR /&gt;for item in items:&lt;BR /&gt;# Find the position of "Name."&lt;BR /&gt;start_index = item.find("Name.") + len("Name.")&lt;BR /&gt;# Find the position of the first underscore after "Name."&lt;BR /&gt;end_index = item.find("_", start_index)&lt;/P&gt;&lt;P&gt;# Extract the desired information from each item&lt;BR /&gt;parsed_item = item[start_index:end_index]&lt;BR /&gt;parsed_items.append(parsed_item)&lt;/P&gt;&lt;P&gt;return parsed_items&lt;BR /&gt;api_key = argv[1]&lt;BR /&gt;# this is the API call to make to retrieve the current list of all Dynamic Address Groups from the transit firewall&lt;BR /&gt;get_AddressGroups_url = '&lt;A href="https://my.panorama.com/restapi/v10.0/Objects/AddressGroups" target="_blank" rel="noopener"&gt;https://my.panorama.com/restapi/v10.0/Objects/AddressGroups&lt;/A&gt;'&lt;BR /&gt;podparams = {'location' : 'device-group', 'device-group' : 'Transit' }&lt;BR /&gt;podheaders = {'X-PAN-KEY' : api_key}&lt;/P&gt;&lt;P&gt;#this is what it will take to query the PaloAlto and get the dictionary which contains a list of address groups&lt;BR /&gt;#which we will loop through and print out the Dynamic Address Groups for POD's only&lt;BR /&gt;try:&lt;BR /&gt;get_address_groups_response = requests.get(get_AddressGroups_url, params= podparams, headers=podheaders, verify=False)&lt;BR /&gt;# if the response was successful, no Exception will be raised&lt;BR /&gt;get_address_groups_response.raise_for_status()&lt;BR /&gt;except HTTPError as http_err :&lt;BR /&gt;print(f'HTTP error occurred: {http_err}')&lt;BR /&gt;except Exception as err :&lt;BR /&gt;print(f'Other error occurred: {err}')&lt;BR /&gt;else :&lt;BR /&gt;pod_address_group_dict = json.loads(get_address_groups_response.text)&lt;/P&gt;&lt;P&gt;#the code block below will loop through the dictionary of address group object entries, and filter for only Dynamic Address Groups include the name "DAG-POD", then it will&lt;BR /&gt;#take that subset of list and read the key value pairs and search for the tags associated to this DAG.&lt;BR /&gt;for entry in pod_address_group_dict['result']['entry']:&lt;BR /&gt;current_list_of_DAG = []&lt;BR /&gt;if 'DAG-POD' in entry['@name']:&lt;BR /&gt;current_list_of_DAG.append(entry['@name'])&lt;BR /&gt;for DAG in current_list_of_DAG:&lt;BR /&gt;print("The following Dynamic Address Group already exist in the Palo Alto Firewalls: " + DAG + " and this group contains servers from the following PODS: ")&lt;BR /&gt;#print(DAG)&lt;BR /&gt;#print()&lt;BR /&gt;address_group_tags = list(entry['dynamic'].values())&lt;BR /&gt;tags_list = list(address_group_tags)&lt;BR /&gt;#this code below is what really takes the values from the dynamic attribute of the entry and makes it readable as well as removing duplicates.&lt;BR /&gt;#print(parse_tag_input(str(tags_list)))&lt;BR /&gt;clean_pod_list = list(set(parse_tag_input(str(tags_list))))&lt;BR /&gt;print(clean_pod_list)&lt;BR /&gt;print("\n\n")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this variable&amp;nbsp; above ( DAG )&amp;nbsp; will have the exact pod name that i want to use in my loop through the list of names. then i want to insert this name into an api call similar to below and get the members list or whatever it may be called.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ive been trying different flavors of this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://my.panorama.com" target="_blank" rel="noopener"&gt;https://my.panorama.com&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;/restapi/v10.0/Objects/AddressGroups?location=device-group&amp;amp;device-group=Transit&amp;amp;name=DAG&amp;amp;key="mykey"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;it sort of matches the xml api path...sort of.. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;XML API Url&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;A href="https://panorama.corp.alkamitech.com/api/?type=op&amp;amp;cmd=%3Cshow%3E%3Cobject%3E%3Cdynamic-address-group%3E%3Cname%3E%3C%2Fname%3E%3C%2Fdynamic-address-group%3E%3C%2Fobject%3E%3C%2Fshow%3E&amp;amp;REST_API_TOKEN=1151951527" target="_rest_api"&gt;/api/?type=op&amp;amp;cmd=&amp;lt;show&amp;gt;&amp;lt;object&amp;gt;&amp;lt;dynamic-address-group&amp;gt;&amp;lt;name&amp;gt;&amp;lt;/name&amp;gt;&amp;lt;/dynamic-address-group&amp;gt;&amp;lt;/object&amp;gt;&amp;lt;/show&amp;gt;&lt;/A&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 05 Jul 2023 20:31:33 GMT</pubDate>
    <dc:creator>JohnCrubaugh</dc:creator>
    <dc:date>2023-07-05T20:31:33Z</dc:date>
    <item>
      <title>Im confused how to get the member list of a dynamic address group from a specific device-group using my rest api from panorama.</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/im-confused-how-to-get-the-member-list-of-a-dynamic-address/m-p/548302#M3390</link>
      <description>&lt;P&gt;I have the following working code.. which gives me the specific dynamic address groups which match my use case, and tells me the snippet of tag info i want to display to the consumers of my script. now i want to include the member list for each of these DAG as well and I cant seem to formulate the proper api call..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import requests&lt;BR /&gt;import json&lt;BR /&gt;from sys import argv&lt;BR /&gt;from requests.exceptions import HTTPError&lt;BR /&gt;import urllib3&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#disable SSL warnings&lt;BR /&gt;urllib3.disable_warnings()&lt;/P&gt;&lt;P&gt;#This function is intended to clean up the data in the key,value fields of the DAG and provide a clean format of just the POD number in a list. This only provide the output necessary for the&lt;BR /&gt;#consumer to determine if their tag is present and in use to fill this DAG.&lt;BR /&gt;def parse_tag_input(input_string):&lt;BR /&gt;# Remove surrounding brackets and quotes&lt;BR /&gt;input_string = input_string.strip("[']").strip()&lt;/P&gt;&lt;P&gt;# Split the input string based on "or" separator&lt;BR /&gt;items = input_string.split(" or ")&lt;/P&gt;&lt;P&gt;parsed_items = []&lt;BR /&gt;for item in items:&lt;BR /&gt;# Find the position of "Name."&lt;BR /&gt;start_index = item.find("Name.") + len("Name.")&lt;BR /&gt;# Find the position of the first underscore after "Name."&lt;BR /&gt;end_index = item.find("_", start_index)&lt;/P&gt;&lt;P&gt;# Extract the desired information from each item&lt;BR /&gt;parsed_item = item[start_index:end_index]&lt;BR /&gt;parsed_items.append(parsed_item)&lt;/P&gt;&lt;P&gt;return parsed_items&lt;BR /&gt;api_key = argv[1]&lt;BR /&gt;# this is the API call to make to retrieve the current list of all Dynamic Address Groups from the transit firewall&lt;BR /&gt;get_AddressGroups_url = '&lt;A href="https://my.panorama.com/restapi/v10.0/Objects/AddressGroups" target="_blank" rel="noopener"&gt;https://my.panorama.com/restapi/v10.0/Objects/AddressGroups&lt;/A&gt;'&lt;BR /&gt;podparams = {'location' : 'device-group', 'device-group' : 'Transit' }&lt;BR /&gt;podheaders = {'X-PAN-KEY' : api_key}&lt;/P&gt;&lt;P&gt;#this is what it will take to query the PaloAlto and get the dictionary which contains a list of address groups&lt;BR /&gt;#which we will loop through and print out the Dynamic Address Groups for POD's only&lt;BR /&gt;try:&lt;BR /&gt;get_address_groups_response = requests.get(get_AddressGroups_url, params= podparams, headers=podheaders, verify=False)&lt;BR /&gt;# if the response was successful, no Exception will be raised&lt;BR /&gt;get_address_groups_response.raise_for_status()&lt;BR /&gt;except HTTPError as http_err :&lt;BR /&gt;print(f'HTTP error occurred: {http_err}')&lt;BR /&gt;except Exception as err :&lt;BR /&gt;print(f'Other error occurred: {err}')&lt;BR /&gt;else :&lt;BR /&gt;pod_address_group_dict = json.loads(get_address_groups_response.text)&lt;/P&gt;&lt;P&gt;#the code block below will loop through the dictionary of address group object entries, and filter for only Dynamic Address Groups include the name "DAG-POD", then it will&lt;BR /&gt;#take that subset of list and read the key value pairs and search for the tags associated to this DAG.&lt;BR /&gt;for entry in pod_address_group_dict['result']['entry']:&lt;BR /&gt;current_list_of_DAG = []&lt;BR /&gt;if 'DAG-POD' in entry['@name']:&lt;BR /&gt;current_list_of_DAG.append(entry['@name'])&lt;BR /&gt;for DAG in current_list_of_DAG:&lt;BR /&gt;print("The following Dynamic Address Group already exist in the Palo Alto Firewalls: " + DAG + " and this group contains servers from the following PODS: ")&lt;BR /&gt;#print(DAG)&lt;BR /&gt;#print()&lt;BR /&gt;address_group_tags = list(entry['dynamic'].values())&lt;BR /&gt;tags_list = list(address_group_tags)&lt;BR /&gt;#this code below is what really takes the values from the dynamic attribute of the entry and makes it readable as well as removing duplicates.&lt;BR /&gt;#print(parse_tag_input(str(tags_list)))&lt;BR /&gt;clean_pod_list = list(set(parse_tag_input(str(tags_list))))&lt;BR /&gt;print(clean_pod_list)&lt;BR /&gt;print("\n\n")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this variable&amp;nbsp; above ( DAG )&amp;nbsp; will have the exact pod name that i want to use in my loop through the list of names. then i want to insert this name into an api call similar to below and get the members list or whatever it may be called.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ive been trying different flavors of this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://my.panorama.com" target="_blank" rel="noopener"&gt;https://my.panorama.com&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;/restapi/v10.0/Objects/AddressGroups?location=device-group&amp;amp;device-group=Transit&amp;amp;name=DAG&amp;amp;key="mykey"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;it sort of matches the xml api path...sort of.. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;XML API Url&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;A href="https://panorama.corp.alkamitech.com/api/?type=op&amp;amp;cmd=%3Cshow%3E%3Cobject%3E%3Cdynamic-address-group%3E%3Cname%3E%3C%2Fname%3E%3C%2Fdynamic-address-group%3E%3C%2Fobject%3E%3C%2Fshow%3E&amp;amp;REST_API_TOKEN=1151951527" target="_rest_api"&gt;/api/?type=op&amp;amp;cmd=&amp;lt;show&amp;gt;&amp;lt;object&amp;gt;&amp;lt;dynamic-address-group&amp;gt;&amp;lt;name&amp;gt;&amp;lt;/name&amp;gt;&amp;lt;/dynamic-address-group&amp;gt;&amp;lt;/object&amp;gt;&amp;lt;/show&amp;gt;&lt;/A&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Jul 2023 20:31:33 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/im-confused-how-to-get-the-member-list-of-a-dynamic-address/m-p/548302#M3390</guid>
      <dc:creator>JohnCrubaugh</dc:creator>
      <dc:date>2023-07-05T20:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Im confused how to get the member list of a dynamic address group from a specific device-group using my rest api from panorama.</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/im-confused-how-to-get-the-member-list-of-a-dynamic-address/m-p/548489#M3392</link>
      <description>&lt;P&gt;Before making any API requests, you need to authenticate and obtain an access token. This token will be used to authorize subsequent API calls. You can refer to the Panorama API documentation or your specific API client documentation for details on how to authenticate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use the API endpoint to retrieve the details of the specific device group you're interested in. You'll need the device group's name or ID for this step. The endpoint may look something like this: /device-group/&amp;lt;device-group-id&amp;gt;. Make sure to replace &amp;lt;device-group-id&amp;gt; with the actual ID or name of your device group.&amp;nbsp;&lt;A href="https://www.mybalancenow.page/" target="_self"&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#FFFFFF"&gt;Target Card Balance Now&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;From the device group details, find the section that contains the dynamic address group you want to retrieve the member list from. Note the name or ID of the dynamic address group.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 04:19:21 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/im-confused-how-to-get-the-member-list-of-a-dynamic-address/m-p/548489#M3392</guid>
      <dc:creator>Dndopl</dc:creator>
      <dc:date>2023-07-07T04:19:21Z</dc:date>
    </item>
  </channel>
</rss>

