Retrieving ASM Policy ID or md5hash without fetching entire ASM policy list

Is there a way to get the ASM policy ID or MD5Hash for ASM Policy without fetching all the existing policy. In the production environment we have more than 200+ ASM policy and fetching all 200 will have huge impact on CPU and memory.

To avoid any impact is there a way to fetch only the specified ASM policy.

Below is the example to fetch all the ASM policy and filter for name and ID curl -sku “admin:password” -X GET | ./jq ‘.items[] | "Name: " + .fullPath + " id: " + .id’

O/P:

"Name: /Common/Test_ASM_Policy  id: m16vXIW65asdSAJwkm2tX78"
"Name: /Common/Test_ASM_Policy1 id: mA6vXIW65asdSAJwkm2tX56"
"Name: /Common/Test_ASM_Policy2 id: mB6vXIW65asdSAJwkm2tX23"
"Name: /Common/Test_ASM_Policy3 id: mC6vXIW65asdSAJwkm2tX01"
"Name: /Common/Test_ASM_Policy4 id: mD6vXIW65asdSAJwkm2tX12"

Instead I need a command which can fetch Name and ID or ID alone. Or is there anywhere in files this ID is stored so that I can get the Policy ID from the file.

Thanks

Syed Nazir

Depending on the version you should be able to use select and filter to only return the values you want.

Example using ‘select’:

curl -sku admin:admin https://${bigip_mgmt}/mgmt/tm/asm/policies?\$select=name,id | jq .

{
  "kind": "tm:asm:policies:policycollectionstate",
  "selfLink": "https://localhost/mgmt/tm/asm/policies?$select=name%2Cid&ver=13.1.0",
  "totalItems": 3,
  "items": [
    {
      "kind": "tm:asm:policies:policystate",
      "selfLink": "https://localhost/mgmt/tm/asm/policies/fAbyu1LnMcZ4DIMoZbX8aQ?ver=13.1.0",
      "name": "pabnagd_testing",
      "id": "fAbyu1LnMcZ4DIMoZbX8aQ"
    },
    {
      "kind": "tm:asm:policies:policystate",
      "selfLink": "https://localhost/mgmt/tm/asm/policies/qeho9K6GhLF0y7x7kShkHw?ver=13.1.0",
      "name": "Policy_1",
      "id": "qeho9K6GhLF0y7x7kShkHw"
    },
    {
      "kind": "tm:asm:policies:policystate",
      "selfLink": "https://localhost/mgmt/tm/asm/policies/1ClbVJ8ymjI19OMzkHeN2Q?ver=13.1.0",
      "name": "Policy_2",
      "id": "1ClbVJ8ymjI19OMzkHeN2Q"
    }
  ]
}

Example using ‘filter’ and ‘select’ to extract a specific policy:

curl -sku admin:admin https://${bigip_mgmt}/mgmt/tm/asm/policies?\$filter=name%20eq%20"Policy_1"\&\$select=name,id | jq .

{
  "kind": "tm:asm:policies:policycollectionstate",
  "selfLink": "https://localhost/mgmt/tm/asm/policies?$select=name%2Cid&ver=13.1.0&$filter=name%20eq%20Policy_1",
  "totalItems": 1,
  "items": [
    {
      "kind": "tm:asm:policies:policystate",
      "selfLink": "https://localhost/mgmt/tm/asm/policies/qeho9K6GhLF0y7x7kShkHw?ver=13.1.0",
      "name": "Policy_1",
      "id": "qeho9K6GhLF0y7x7kShkHw"
    }
  ]
}