OpenScript

Reply
Frequent Visitor
Posts: 1
Registered: ‎04-26-2015

How can I know real server, where forward client?

Hi all! Please, someone can tell me, how can I get real server name, which accepted client? Yes, I can write openscript, which forward clients temselves, but I think something wrong:

 

Algorithm:

1. If client have balancer cookie, send him to real server written into cookie

2. If not, then check health status real server, check numbers of connection and forward client to the less connection server.

 

use strict;

use OS_SLB;
use OS_IP;
use OS_TCP;
use OS_CONN;
use OS_HTTP_REQUEST;

my $log_string;
my %real_servers;
my $port;
my $client_ip;

sub BEGIN {

}
sub HTTP_REQUEST {

  %real_servers = ("cc-test-09", 0,
                    "cc-test-10", 0,
                    "cc-test-11", 0,
                    "cc-test-12", 0);

  $port = 9085;
  
  $client_ip = OS_IP::src;

  # Do we have our cookie into client request?
  my $hreq_cookie = OS_HTTP_REQUEST::cookie("ServerID");
  if (defined $hreq_cookie) {
    # Forward client to his server
    OS_SLB::forward($hreq_cookie);
  }
  else {
    # Forward client to server that has less connections

    # How many connection have real servers?
    foreach my $server_name (keys %real_servers)
    {
      # Real server is live?
      if (OS_SLB::is_server_up("server-name" => $server_name, "port" => $port) == 1) {
        $real_servers{$server_name} = OS_SLB::get_server_port_current_connections($server_name, $port);
      }
      # Syslog
      $log_string = "Server ". $server_name . " has " .  $real_servers{$server_name} . " connection. ";
      OS_SLB::log($log_string);
    }
    # Make reverse array
    my %real_conn = reverse %real_servers;
    foreach my $conn (sort keys %real_conn){
      # Send user to real server
      OS_SLB::forward ($real_conn{$conn});
      my $index = OS_CONN::client_connection;
      $log_string = "Client: " . $client_ip . " Target: ". $real_conn{$conn} . " Index:" . $index;
      OS_SLB::log($log_string);
      # Make and push cookie to client
      OS_HTTP_REQUEST::cookie_persist(
        "name" =>"ServerID",
        "domain" => "test.example.com",
        "path" => "/",
        "age" => "30"); # Minutes
      OS_HTTP_REQUEST::cookie("ServerID", $real_conn{$conn});
      last;
    }
  }

  # Syslog
  #$log_string = "Connection successful: from ". $client_ip;
  #OS_SLB::log($log_string);

}
sub SERVER_SELECTION_FAILURE {
  $log_string = "Connection failed: from ". $client_ip;
  OS_SLB::log($log_string);
}

 But, cookie not send to client and client forwarded to wrong real server. I don't understand how is it work. 

Collegues, I just want only know which real server accepted of client - I don't want L7 load balancing, someone know how can I do it? Maybe CLI command or Syslog, or SNMP, etc.? Please, help!

Highlighted
Occasional Contributor
Posts: 7
Registered: ‎11-13-2015

Re: How can I know real server, where forward client?

Hey MixaSg,

 

 

Am I correct when saying this isn't inserting the cookie?

Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.

vADC is now Pulse Secure
Download FREE NVMe eBook