Forum Discussion

Andrew_Husking's avatar
Jan 31, 2017

RESTAPI - Delete sys connection

I've been doing some work with the Rest API, and have been able to successfully show the connection table and limit it to a client address.

 

However I'd like to delete the connections for a specific client, I've tried change the GET request to a DELETE to the following URI , however no connections are deleted.

 

Has anyone done this/know if it can be done? I've seen an old article stating that you can create a custom script to do this, however I'd like to use built in API's to achieve this.

 

TIA -Andrew

 

3 Replies

  • That's a very difficult question.

    First of all, iControl® REST API User Guide, Version 12.1.0 states that "With the exception of the asm module, query parameters are limited to GET requests" - so it does not work for DELETE. Also, because all the connection table entries are treated as one chunk of string data under

    apiRawValues
    (as you can see in the response to GET), it is theoretically not possible to pick selected entries.

    Interesting enough, in some TMOS versions, you may be able to DELETE entries selectively using the options query, however, it is not currently supported (to my knowledge).

    An alternative way to achieve this goal is to call the equivalent tmsh command via the

    /mgmt/tm/sys/bash
    endpoint (see Native tmsh/bash commands via REST API).

  • I've done this via cli script with some variables:

    cli script clearconns {
    proc script::init {} {
    }
    
    proc script::run {} {
      tmsh::delete sys connection cs-server-addr [lindex $tmsh::argv 1] cs-server-port [lindex $tmsh::argv 2] ss-server-addr [lindex $tmsh::argv 3] ss-server-port [lindex $tmsh::argv 4]
    }
    
    proc script::help {} {
    }
    
    proc script::tabc {} {
    }
        total-signing-status not-all-signed
    }
    

    This can be called from external via iControl REST, e.g. like this:

    POST -H "Content-Type: application/json" https://mybigip/mgmt/tm/cli/script -d '{"command":"run","utilCmdArgs":"clearconns 10.1.2.3%23 443 10.45.67.89%23 80"}'
    

    Don't forget to include the %nn suffix with the IP addresses when using route domains!

    HTH Martin