Different tcp-check for each server

Hello,

I have a 3 server redis signalR backend that 1 of them is master and 2 slaves.

They return a “role:master” or “role:slave” string depend on their role. The role is fixed so the master and the slaves should always be on the same machines (even they can rotate automatically in case of failure).

The problem is that I don’t know and can’t find any clue on how to make the string check different by server in order to display “all healthy” in status page.

Right now I have a configuration like this:

     option tcp-smart-accept
     option tcp-smart-connect
     option tcpka
     option tcplog
     option tcp-check
     tcp-check send PING\r\n
     tcp-check expect string +PONG
     tcp-check send info\ replication\r\n
     tcp-check expect string role:master
     tcp-check send QUIT\r\n
     tcp-check expect string +OK

     server srv1 server1.internal:6380 check port 6380 fall 3 rise 3
     server srv2 server2.internal:6380 check port 6380 fall 3 rise 3
     server srv3 server3.internal:6380 check port 6380 fall 3 rise 3

The srv1 is the master and srv2 and srv3 are the slaves.

Is it possible to check the string “role:master” only on srv1 and the string “role:slave” on srv2 and srv3?

Like this the health check only pass in the srv1 because is the only that returns “role:master”, the others “are down” which isn’t really true.

image

Thank you,

Pedro

if the role of each server never changes, you can rename your server to add the role as a suffix:

  srv1 => srv1_master
  srv2 => srv2_slave
  srv3 => srv3_slave

This way, you can extract the role from the server name in the expect rule (untested):

tcp-check expect string-lf role:%[srv_name,word(2,_)]

If the role of a server may change for any reason, I guess you should use a regex instead of an exact match and consider that the server is alive if the response is well formed, independently on the role.

1 Like

Thank a lot @capflam!

Your solution works like a charm.

And is “bullet proof”! I check with a chang on the master to slave and one of the slaves to master and the nodes became red as expected as the health check failed.

Thanks, thanks, thanks!

thanks for the awesome information.