From 25eef8bfb91c2c57907ab79f4ba6bcd9fe0064cb Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Wed, 30 Mar 2011 12:09:58 -0700 Subject: check in for Bug 6959 Add the ability to run a user defined script to determine wan load-balancing interface health includes sample http test (scripts/http_test.pl). Configuration will look as follows: wan { interface-health eth0 { nexthop 10.3.0.1 test 1 { test-script /tmp/http_test.pl type user-defined } } interface-health eth1 { nexthop 10.3.0.1 test 1 { test-script /tmp/http_test.pl type user-defined } } With corresponding output: vyatta@vyatta# run show wan-load-balance Interface: eth0 Status: active Last Status Change: Wed Mar 30 19:03:59 2011 +Test: user Script: /tmp/http_test.pl Last Interface Success: 0s Last Interface Failure: n/a # Interface Failure(s): 0 Interface: eth1 Status: failed Last Status Change: Wed Mar 30 19:03:59 2011 -Test: user Script: /tmp/http_test.pl Last Interface Success: n/a Last Interface Failure: 0s # Interface Failure(s): 52 Scripts returns 0 for success, non-zero for failure. --- src/lbdatafactory.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/lbdatafactory.cc') diff --git a/src/lbdatafactory.cc b/src/lbdatafactory.cc index a9030b3..653e270 100644 --- a/src/lbdatafactory.cc +++ b/src/lbdatafactory.cc @@ -19,6 +19,7 @@ #include "lbdata.hh" #include "lbtest_icmp.hh" #include "lbtest_ttl.hh" +#include "lbtest_user.hh" #include "lbdatafactory.hh" using namespace std; @@ -173,6 +174,9 @@ LBDataFactory::process(const vector &path, int depth, const string &key, else if (depth == 4 && key == "ttl") { process_health_interface_rule_type_udp(l_key,l_value); } + else if (depth == 4 && key == "test-script") { + process_health_interface_rule_type_user(l_key,l_value); + } } else if (path[0] == "rule") { if (depth > 0 && path[1] == "source") { @@ -319,13 +323,20 @@ LBDataFactory::process_health_interface_rule_type_udp(const string &key, const s } } +void +LBDataFactory::process_health_interface_rule_type_user(const string &key, const string &value) +{ + if (_test_iter != _health_iter->second._test_coll.end()) { + if (key == "test-script") { + ((LBTestUser*)_test_iter->second)->set_script((string&)value); + } + } +} + void LBDataFactory::process_health_interface_rule_type(const string &key, const string &value) { if (value == "ping") { - if (_debug) { - cout << "LBDataFactory::process_health_interface_rule_type(): setting up icmp test" << endl; - } LBTestICMP *test = new LBTestICMP(_debug); _health_iter->second._test_coll.insert(pair(_current_test_rule_number,test)); } @@ -333,6 +344,10 @@ LBDataFactory::process_health_interface_rule_type(const string &key, const strin LBTestTTL *test = new LBTestTTL(_debug); _health_iter->second._test_coll.insert(pair(_current_test_rule_number,test)); } + else if (value == "user-defined") { + LBTestUser *test = new LBTestUser(_debug); + _health_iter->second._test_coll.insert(pair(_current_test_rule_number,test)); + } _test_iter = _health_iter->second._test_coll.find(_current_test_rule_number); } -- cgit v1.2.3