From eec6443e2dbfed079b295a5d60fd08cf80aad698 Mon Sep 17 00:00:00 2001 From: Ewald van Geffen Date: Sun, 22 May 2016 01:02:07 +0200 Subject: - Bug 363 support for post-hook: allows to run script once route/firewall change have been applied. --- src/lbdata.hh | 1 + src/lbdatafactory.cc | 11 +++++++++++ src/lbdatafactory.hh | 3 +++ src/lbdecision.cc | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) (limited to 'src') diff --git a/src/lbdata.hh b/src/lbdata.hh index 0b4175c..aaaa896 100644 --- a/src/lbdata.hh +++ b/src/lbdata.hh @@ -227,6 +227,7 @@ class LBData { bool _flush_conntrack; bool _sticky_inbound_connections; string _hook; + string _post_hook; }; #endif //__LBDATA_HH__ diff --git a/src/lbdatafactory.cc b/src/lbdatafactory.cc index bf49b36..6870737 100644 --- a/src/lbdatafactory.cc +++ b/src/lbdatafactory.cc @@ -157,6 +157,9 @@ LBDataFactory::process(const vector &path, int depth, const string &key, else if (path[0] == "hook") { process_hook(l_key,l_value); } + else if (path[0] == "post-hook") { + process_post_hook(l_key,l_value); + } else if (path[0] == "health") { if (depth == 2 && key == "interface") { process_health(l_key,l_value); @@ -249,6 +252,14 @@ LBDataFactory::process_hook(const string &key, const string &value) } } +void +LBDataFactory::process_post_hook(const string &key, const string &value) +{ + if (value.empty() == false) { + _lb_data._post_hook = value; + } +} + void LBDataFactory::process_health(const string &key, const string &value) { diff --git a/src/lbdatafactory.hh b/src/lbdatafactory.hh index 9178e00..f213993 100644 --- a/src/lbdatafactory.hh +++ b/src/lbdatafactory.hh @@ -58,6 +58,9 @@ private: void process_hook(const string &key, const string &value); + void + process_post_hook(const string &key, const string &value); + void process_health_interface(const string &key, const string &value); diff --git a/src/lbdecision.cc b/src/lbdecision.cc index d66849c..a86a878 100644 --- a/src/lbdecision.cc +++ b/src/lbdecision.cc @@ -433,6 +433,25 @@ LBDecision::run(LBData &lb_data) } ++iter; } + + map::iterator post_iter = state_changed_coll.begin(); + while (post_iter != state_changed_coll.end()) { + //set state + //set interface + if (lb_data._post_hook.empty() == false) { + setenv("WLB_INTERFACE_NAME",post_iter->first.c_str(),1); + setenv("WLB_INTERFACE_STATE",post_iter->second.c_str(),1); + + syslog(LOG_WARNING, "executing script: %s",lb_data._post_hook.c_str()); + + execute(lb_data._post_hook, stdout); + //unset state + //unset interface + unsetenv("WLB_INTERFACE_NAME"); + unsetenv("WLB_INTERFACE_STATE"); + } + ++post_iter; + } } /** -- cgit v1.2.3