Forum Discussion
How to Apply Irule Through CLI: Idea is to Share the tmsh script to create a Batch script which Windows Team can work edit accordingly
Hi Team,
The below is the Irule which we apply for the maintenance page which we applied through GUI, Kindly assist in letting know how can we apply through CLI,. This we need to give it to Application Team who can make a batch file, which they wanted to edit as per the requirement.
================================
when HTTP_REQUEST { Check active members of pool, if 0 respond with Apology Page. if { [active_members total-poc.redprairielabs.net-Pool] == 0 } { HTTP::respond 200 content {
The App is undergoing site maintenance This APP is currently down as it undergoing site maintenance. It will be available soon! Please check back again shortly. We apologize for the inconvenience.
If you need to reach us, please call 1-469-357-6900 or email HostingSD@jda.com.
}
}
}
==========================================
Thanks and Regards Parveez
13 Replies
- Kevin_Stewart
Employee
I don't know yet that you can actually create an iRule on the command line, within the single tmsh create command. One workaround is to create the iRule first and then pipe it to the tmsh create command. Example:
printf "when HTTP_REQUEST { log local0. \"here\" }" > test-rule tmsh create ltm rule my-test-rule `cat test-rule`
Then to apply it to a virtual server:
tmsh modify virtual my-virtual rules { my-test-rule }
- Parveez_70209
Nimbostratus
Hi Kevin,
Ok, the main idea was as everytime server patching activities happen and carried out by Application as well as Windows Team, so everytime they need to manually attach/add the "Irule for Maintenance" to the Virtual-Server.
So, now they wanted to create a batch file where they will just edit/need to mention the Irule-Name as well as the Virtual-server where it needs to go using the tmsh command help too.
So, if I understood it correctly, we have to provide the below right to them, so that they can modify/add in their batch file:
tmsh modify virtual my-virtual rules { my-test-rule }
How can the above tmsh looklike , for example: we have Virtual-Server name: ABC.COM-HTTP and Irule for Maintenance as: "Maintenance-Irule"
Kindly guide.
Thanks and Regards Parveez
- Kevin_Stewart
Employee
tmsh modify virtual ABC.COM-HTTP rules { Maintenance-Irule }
- dbizzle_20930
Nimbostratus
i'm not sure what's in your maintenance irule but you could create a separate VIP that handles that maintenance irule itself. The idea being you have another irule on the VIP undergoing maintenance that detects pool status and if down, sends a 301 redirect to the maintenance VIP.
This way nothing has to be touched on the F5 when they do maintenance on the servers - its automagic!
- Christopher_Boo
Cirrostratus
I redirect to an app specific maintenance URL on a different server when the pool is down. The app team can modify that maintenance page however they want whenever they want without any interaction with the LTM. Works well for us... Chris
- Parveez_70209
Nimbostratus
Hi Kevin,
cd D:\ABCLTM\Lenweb10\Enable
plink.exe -ssh bmcnetop@10.28.32.46 -pw N3t0p$01 -m Lenweb10_Enable.txt
where Lenweb10_Enable.txt contains for example the below:
- For enable :
tmsh modify ltm pool all members modify {10.25.128.10:11080 {state up session enabled}}
- For Disable:
tmsh modify ltm pool all members modify {10.25.128.10:11080 {state up session disabled}} tmsh modify ltm pool all members modify {10.25.128.10:12080 {state up session disabled}} tmsh modify ltm pool all members modify {10.25.128.10:13080 {state up session disabled}} tmsh modify ltm pool all members modify {10.25.128.10:14080 {state up session disabled}}
Similarly, we thought of using the suggested command into the below script for calling the Maintenance page:
tmsh modify virtual ABC.COM-HTTP rules { Maintenance-Irule }
where ABC.COM-HTTP = Virtual-Server name Maintenance-Irule = name of the Maintenance-Irule
But while application team run the command:
tmsh modify virtual ABC.COM-HTTP rules { Maintenance-Irule } , they got an error specifying virtual keyword is unrecognized.
Thanks and Regards Parveez
- Parveez_70209
Nimbostratus
Hi Kevin,
Kindly guide, some information I posted above after testing the same.
Thanks and Regards Parveez
- nitass
Employee
it seems okay in my gear.
e.g.
before root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } source 0.0.0.0/0 source-address-translation { type automap } vs-index 6 } plink C:\>plink -ssh root@172.28.24.11 -pw root "tmsh modify ltm virtual bar rules { myrule }" C:\> after root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } rules { myrule } source 0.0.0.0/0 source-address-translation { type automap } vs-index 6 }
- omniplex
Nimbostratus
I think it was overlooked, but the error you are getting is because you have:
You are missing the ltm portion, it should read:tmsh modify virtual ABC.COM-HTTP rules { Maintenance-Irule }
tmsh modify ltm virtual ABC.COM-HTTP rules { Maintenance-Irule }
- Wallace1
Nimbostratus
So is there a way to add the irule without removing the old irules? Or is there a method to delete the 1 rule and replace it with another?
Thanks,
Wallace
- Wallace1
Nimbostratus
So is there a way to add the irule without removing the old irules? Or is there a method to delete the 1 rule and replace it with another?
Thanks,
Wallace
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com