01-Dec-2022 08:32 - edited 01-Dec-2022 09:03
Hello,
I want to make a script that sends alerts to /var/log/ltm every minute when the pool is not up.
Here is the script I designed:
modify script pool_script {
app-service none
definition {
set errorcode [catch {exec tmsh show ltm pool | grep Ltm | awk {{ print $(NF-2) }}} result]
set result [split $result "\n"]
tmsh::log_dest file
tmsh::log_level debug
foreach i $result {
set pool "[lindex $i 1]"
if { [tmsh::show ltm pool] contains "Availability : available" } then {
} else {
tmsh::log debug "F5 Pool:${pool} Status -> Not available."
}
}
}
description none
events none
}
I thought it worked, but then I realized that the log only appears when the first pool doesn't start as it should.
Please tell me how to change my script...
Any help is appreciate.
Solved! Go to Solution.
01-Dec-2022 09:11 - edited 01-Dec-2022 09:12
Hi MIchaelyang,
check the iCall script below to get a picture how to LTM configs could be enumerated with foreach loops. No need to [exec] native BASH commands... 😉
sys icall handler periodic check_pool_state {
interval 120
script check_pool_state
}
sys icall script check_pool_state {
app-service none
definition {
tmsh::log_dest file
tmsh::log_level debug
foreach temp(pool_config) [tmsh::get_config /ltm pool] {
set temp(pool_name) [tmsh::get_name $temp(pool_config)]
if { [tmsh::show /ltm pool $temp(pool_name)] contains "Availability : available" } then {
# Everything is fine...
} else {
tmsh::log debug "Pool Check: $temp(pool_name) is unhealthy"
}
}
}
description none
events none
}
Cheers, Kai
01-Dec-2022 08:53
Hi Michaelyang,
on a quick view: You are not passing $pool to the "tmsh::show ltm virtual" command...
Cheers, Kai
01-Dec-2022 08:58
Hi Kai_Wike,
Sorry, I sent the wrong one
I've updated it...
01-Dec-2022 09:08
As i said... you are not passing the $pool variable into the the "tmsh::show ltm virtual" command. In this case you check if a single pool of all your pools is available. It should be "tmsh::show ltm virtual $pool"
Beside of this the [exec] part can be avoided... Give me a sec to give you a quick coding how to access and enumerate LTM configurations within TMSH scripts...
Cheers, Kai
01-Dec-2022 09:09
Hi Kai_Wike,
Sorry, I sent the wrong one
I've updated it again...
Thank you
01-Dec-2022 09:15
Still the same problem. Check the script I've just posted. During the foreach loop it passes the currently processed $temp(pool_name) to the [tmsh::show] command, so that you analyse the state of the just processed pool. If you dont pass the pool name to the show command, then you would analyse all pools at the same time.
Cheers, Kai
01-Dec-2022 09:39
Hi Kai_Wike,
Thanks for your help.
I'll look into it..
Thanks
01-Dec-2022 09:41
You are welcome.
I pretty much like to see you enjoying iCall. You truly deserve Kudos for your creativity 😉
Cheers, Kai
01-Dec-2022 09:11 - edited 01-Dec-2022 09:12
Hi MIchaelyang,
check the iCall script below to get a picture how to LTM configs could be enumerated with foreach loops. No need to [exec] native BASH commands... 😉
sys icall handler periodic check_pool_state {
interval 120
script check_pool_state
}
sys icall script check_pool_state {
app-service none
definition {
tmsh::log_dest file
tmsh::log_level debug
foreach temp(pool_config) [tmsh::get_config /ltm pool] {
set temp(pool_name) [tmsh::get_name $temp(pool_config)]
if { [tmsh::show /ltm pool $temp(pool_name)] contains "Availability : available" } then {
# Everything is fine...
} else {
tmsh::log debug "Pool Check: $temp(pool_name) is unhealthy"
}
}
}
description none
events none
}
Cheers, Kai