I’ve configured some services using Apply For but the array contains spaces (as these are the only valid separation signs). As a result the services objects are created with space(s) in its name (which I don’t like). Is there any chance to avoid this? E.g. adding replace() to the definition or any other trick?
Do you have an example? We use it with the director. If you like I could compare how the director render this in our environment
I could provide an example, sure. But this is always confusing as I use the director and conf files mixed (which is highly discouraged). Means host are managed via director, service via conf files.
I need an example, I have a hard time imaging what you’re trying to achieve.
apply Service "application_pool_" for (pool in host.vars.application_customer_pools) {
display_name = "application Pool " + pool
check_command = "by_ssh"
vars.application_pool_temp = pool.split(" ")
vars.application_pool_name = vars.application_pool_temp[0]
vars.application_customer = vars.application_pool_temp[1]
vars.by_ssh_command = "/opt/application/check_pool.py"
vars.by_ssh_arguments = {
"-n" = "$application_pool_name$"
"-c" = 10
"-w" = 15
"-t" = "$application_customer$"
}
}
host.vars.application_customer_pools is an array, containing:
[ “Customer1 PoolA”, “Customer1 PoolB”, “Customer2 PoolA” ]
Ok, some things to note:
- The split() array does not have any out-of-bounds-checks
- The temporary variable should only exist in the local scope, but not exported to other interfaces.
var application_pool_temp = pool.split(" ")
if (len(application_pool_temp) == 2) {
vars.application_pool_name = application_pool_temp[0]
vars.application_pool_name = application_pool_temp[1]
}
- display_name can be modified with pool.replace(" ", “-”) or similar
display_name = "application Pool " + pool.replace(" ", "-")
2 Likes