Hello,
Far as I know you need to create a rule, then add actions and conditions on it.
e.g.
# Create a policy draft
curl -kv -u admin:admin https://localhost/mgmt/tm/ltm/policy \
-X POST -H "Content-type:application/json" \
-d '{ "name": "/Common/Drafts/policy_vs_devcentral", "strategy": "first-match"}' | jq "."
# Add a rule
curl -kv -u "admin:admin" https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules \
-X POST -H "Content-type:application/json" \
-d '{"name": "ruleTest" }' | jq "."
# Add conditions and actions to a rule
curl -kv -u "admin:admin" -X PUT https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules/ruleTest \
-H "Content-type: application/json" \
-d @- << EOF | jq "."
{
"actions": [
{
"name": "0",
"request": true,
"forward": true,
"pool": "/Common/pool_test"
}
],
"conditions": [
{
"name":"0",
"request": true,
"httpHost": true,
"equals": true,
"values": [
"www.mydomain.net"
]
}
]
}
EOF
A tip to easy know all parameters for a certain rule, you create a manually example then retrieve that actions and conditions to understand what parameters you need to fill.
e.g.
I manually created a rule "ruleRedirect" to redirect traffic when host equals "www.test.net" and path equals "/" to a home page:
So, I get conditions and actions from that rule name:
curl -k -u "admin:admin" https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules/ruleRedirect/conditions |jq "."
{
"kind": "tm:ltm:policy:rules:conditions:conditionscollectionstate",
"selfLink": "https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules/ruleRedirect/conditions?ver=14.1.2.2",
"items": [
{
"kind": "tm:ltm:policy:rules:conditions:conditionsstate",
"name": "0",
"fullPath": "0",
"generation": 2463,
"selfLink": "https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules/ruleRedirect/conditions/0?ver=14.1.2.2",
"all": true,
"caseInsensitive": true,
"equals": true,
"external": true,
"httpHost": true,
"index": 0,
"present": true,
"remote": true,
"request": true,
"values": [
"www.test.net"
]
},
{
"kind": "tm:ltm:policy:rules:conditions:conditionsstate",
"name": "1",
"fullPath": "1",
"generation": 2463,
"selfLink": "https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules/ruleRedirect/conditions/1?ver=14.1.2.2",
"all": true,
"caseInsensitive": true,
"equals": true,
"external": true,
"httpUri": true,
"index": 0,
"present": true,
"remote": true,
"request": true,
"values": [
"/"
]
}
]
}
curl -k -u "admin:admin" https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules/ruleRedirect/actions |jq "."
{
"kind": "tm:ltm:policy:rules:actions:actionscollectionstate",
"selfLink": "https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules/ruleRedirect/actions?ver=14.1.2.2",
"items": [
{
"kind": "tm:ltm:policy:rules:actions:actionsstate",
"name": "0",
"fullPath": "0",
"generation": 2463,
"selfLink": "https://localhost/mgmt/tm/ltm/policy/~Common~Drafts~policy_vs_devcentral/rules/ruleRedirect/actions/0?ver=14.1.2.2",
"code": 0,
"expirySecs": 0,
"httpReply": true,
"length": 0,
"location": "https://www.test.net/home",
"offset": 0,
"port": 0,
"redirect": true,
"request": true,
"status": 0,
"timeout": 0,
"vlanId": 0
}
]
}
Now I know that to create a redirection rule this is the json body to push:
{
"conditions": [
{
"name": "0",
"request": true,
"httpHost": true,
"equals": true,
"values": [
"www.test.net"
]
},
{
"name": "1",
"request": true,
"httpUri": true,
"equals": true,
"values": [
"/"
]
} ],
"actions": [
{
"name": "0",
"request": true,
"httpReply": true,
"redirect": true,
"location": "https://www.test.net/home"
} ]
}
I hope this helps.
Regards