Forum Discussion

Randy_Toombs_35's avatar
Randy_Toombs_35
Icon for Nimbostratus rankNimbostratus
Mar 01, 2019

Disable learning mode from REST API

I have not been able to find it yet, is there a way I can disable the learning mode for a policy from the REST API? I have many ASM policies and would like to write a script to disable learning mode for all policies. I just have not been able to find the location in the API to disable the learning mode. See screen shot.

 

1 Reply

  • This can be accomplished via the following steps:

    Get the policy id for the policy or policies:

    All policies:

    https://{{bigip_mgmt}}/mgmt/tm/asm/policies?$select=name,id

    Filter for single policy by name:

    https://{{bigip_mgmt}}/mgmt/tm/asm/policies?$filter=name eq 'Child_1'&$select=name,id

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

    Then access the learning mode:

    https://{{bigip_mgmt}}/mgmt/tm/asm/policies/N92Kq8isMxe18Nzg3GzqTg/policy-builder?$select=learningMode

    {
        "kind": "tm:asm:policies:policy-builder:policy-builderstate",
        "selfLink": "https://localhost/mgmt/tm/asm/policies/N92Kq8isMxe18Nzg3GzqTg/policy-builder?$select=learningMode&ver=13.1.1",
        "learningMode": "manual"
    }
    

    Now change via Patch:

    https://{{bigip_mgmt}}/mgmt/tm/asm/policies/N92Kq8isMxe18Nzg3GzqTg/policy-builder

    Body:

    {
      "learningMode": "disabled"
     }
    

    Check the change has taken place:

    https://{{bigip_mgmt}}/mgmt/tm/asm/policies/N92Kq8isMxe18Nzg3GzqTg/policy-builder?$select=learningMode

    {
        "kind": "tm:asm:policies:policy-builder:policy-builderstate",
        "selfLink": "https://localhost/mgmt/tm/asm/policies/N92Kq8isMxe18Nzg3GzqTg/policy-builder?$select=learningMode&ver=13.1.1",
        "learningMode": "disabled"
    }
    

    Ensure you apply the policy to enforce the change.