Forum Discussion
James_Thomson
Employee
Jul 25, 2005Question about No Nodes Available Rule
I recently posted this rule to emulate the 4.X feature that logged No Nodes available.
when LB_FAILED {
if { [LB::server addr] eq "" } {
log "No nodes available - pool [LB::server]"
...
Jul 25, 2005
You could use a global variable and increment it's value for each request. When it reaches your threashold then log your message and reset it to zero.
You could also use the modulus ( % ) operator but unRuleY mentioned previously that it was very expensive so I provided the example using the == operator.
when RULE_INIT {
Initialize the counter to 0.
set ::log_ctr 0
}
when HTTP_REQUEST {
Increment the counter
incr ::log_ctr
If counter has reached 50, log the message and reset counter
if { $::log_ctr == 50 } {
log "Rule has been called $::log_ctr times"
set ::log_ctr 0
}
}
In this code, I'm using the default global namespace. You could define your own namespace if you wanted to. This would be useful if you are using global variables in different rules and want to somehow distinguish them.
set my_ns::log_ctr 0
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects