Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral




APM automation with TMSH script


Here is one of tmsh script to provide APM automation 

Start ==================


proc script::init {} {
proc script::run {} {
    set userid [lindex $tmsh::argv 1]
    set hostname [lindex $tmsh::argv 2]
    set hostip [lindex $tmsh::argv 3]
    set rules [tmsh::list apm policy agent resource-assign cloud_ap_act_full_resource_assign_ag rules ]
    regsub -all "remote-desktop-resources \{" $rules "remote-desktop-resources add \{" rules
    set rules_index6 [lindex [lindex $rules 5] 1]
    set added "\{ expression 'expr \{ \[mcget \{session.logon.last.logonname\}\] == \"$userid\" \}' remote-desktop-resources add \{ /Common/$hostname \} \}"
    set final "rules { [append added $rules_index6] }"
    tmsh::create apm resource remote-desktop rdp $hostname ip $hostip port 3389 java-client enabled 
    tmsh::modify apm policy agent resource-assign cloud_ap_act_full_resource_assign_ag $final 
    tmsh::modify apm profile access cloud_ap generation-action increment
    tmsh::save sys config 
proc script::help {} {
End ====================
The script will receive three parameter, user name, host name and host ip, and it will then create a remote desktop (windows) resource for the specific user. The virtual server and access profile need to be configured first, since the script only modify the VPE. My recommendation is do not use tmsh to config access profile, I faced quite a lot challenge on that and end up decided to use tmsh scrpt to config VPE part only. This is quite simplified script and there is a lot of room to further enhance it to provide more APM automation functions.
TMSH script is powerful and have a fun with TMSH script. 
Best regards,

1 Answer(s):

Hello CJ,

Thank you for this very useful guide!!

I'm trying to do almost the same through a TCL script for various types of resources. The challenge is to correctly capture all the existing settings before adding a new resource.

With your proposal, however, I'm getting a parsing error:

Syntax Error: "{" unexpected argument

I believe there is something missing somewhere but I cannot figure where this is coming from...

Below is a sample of the generated $final command:

modify apm policy agent resource-assign AP_TEST-resources_assignment_act_full_resource_assign_1_ag rules { { expression 'expr { [mcget {session.custom.resources}] contains "SecondApp" }' portal-access-resources add { /Common/SecondApp } } { acls none app-tunnel-resources none bwc-dynamic-policy none bwc-static-policies none expression "expr { [mcget {session.custom.resources}] contains \"MyWeblink\" }" network-access-resources none pool none portal-access-resources none remote-desktop-resources none saml-resources none webtop none webtop-links '{ /Common/web_site }' } }

I'm still scratching my head but if you have any idea...

Thanks a lot again!!! Jérôme

Founded it :) 'add' was missing on the last part of it: webtop-links add '{ /Common/web_site }' } }

Your answer: