I was reading the documentation on load-balancing
and I was curious about the wan hook
script execution. I’ve got a basic script to curl
Mailgun for email notification working, but I am wanting to use the WLB_INTERFACE_NAME
and WLB_INTERFACE_STATE
so I can include which interface is live and which is down during WAN transition. But I don’t seem to be figuring it out, anyone using those environment variables in their wan hook
script?
I’m also interested in this as I see it being a future use-case at my day job. I can do some testing next week and will report back.
Hey @firedrow,
I was able to do some testing of this today and did not see any environment variables named WLB_INTERFACE_NAME
or WLB_INTERFACE_STATE
after configuring load-balancing. I’ve misplaced my notes but wanted to let you know my findings after waiting patiently.
I set up a basic 2-wan failover with one vyos node and I wrote a simple script to dump printenv
when the hook was triggered. I will try and get you all the variables that my test environment had, but I remember not seeing anything that looked like the information you’re after. A bug report is probably in order.
If you don’t mind sending me your script, or I guess I can just dump the environment variables myself. I’ll post a bug report. According to the load balance docs, they should be there.
I’m mistaken, the variables do exist. I was checking printenv
under a normal user and not root. It’s been one of those weeks.
The crude script would be:
#!/bin/sh
printenv > /tmp/printenv-dmp
and then cat /tmp/printenv-dmp
to get the environment variables when the hook is triggered. It’ll be overwritten every time though.
To use the variables in a script, you should be able to call them with $WLB_INTERFACE_NAME
and $WLB_INTERFACE_STATE
respectively.
#!/bin/sh
echo $WLB_INTERFACE_NAME is in state $WLB_INTERFACE_STATE
Frankly, that has always been a semi-undocumented, obscure feature.
Here’s the code in question: vyatta-wanloadbalance/lbdecision.cc at current · vyos/vyatta-wanloadbalance · GitHub
It indeed defines $WLB_INTERFACE_NAME
and $WLB_INTERFACE_STATE
Accodring to vyatta-wanloadbalance/lbdata.cc at current · vyos/vyatta-wanloadbalance · GitHub state can be ACTIVE
or FAILED
.
Hope this helps.
Ok, I have a workable load-balancing wan hook
script. The documentation had me confused:
Script execution
A script can be run when an interface state change occurs. Scripts are run from /config/scripts, for a different location specify the full path:
set load-balancing wan hook script-name
Two environment variables are available:
WLB_INTERFACE_NAME=[interfacename]
: Interface to be monitoredWLB_INTERFACE_STATE=[ACTIVE|FAILED]
: Interface state
I was hoping I could have my script specifically say “eth2 is failed, eth3 is active”. But if the variable is only filled in when the hook is triggered, then I can modify the email to list which interface is which and then who failed.