# Different tcp-check for each server

**URL:** <https://discourse.haproxy.org/t/different-tcp-check-for-each-server/6952>\
**Category:** Help!\
**Created:** [October 1, 2021, 5:19pm UTC](https://discourse.haproxy.org/t/different-tcp-check-for-each-server/6952 "2021-10-01T17:19:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pestevao](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pestevao](https://discourse.haproxy.org/u/pestevao)\
**Post date:** [October 1, 2021, 5:19pm UTC](https://discourse.haproxy.org/t/different-tcp-check-for-each-server/6952/1 "2021-10-01T17:19:23Z")

</div>

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:

```auto
     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](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/2X/2/22342af6617a4757fb1cc15fa4d09827bde2b9b7.png)

Thank you,

Pedro

---

<div class="post-metadata">

**Author:** ![capflam](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/capflam/32/236_2.png) [@capflam](https://discourse.haproxy.org/u/capflam)\
**Post date:** [October 1, 2021, 6:10pm UTC](https://discourse.haproxy.org/t/different-tcp-check-for-each-server/6952/2 "2021-10-01T18:10:19Z")

</div>

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

```auto
  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):

```auto
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.

---

<div class="post-metadata">

**Author:** ![pestevao](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pestevao](https://discourse.haproxy.org/u/pestevao)\
**Post date:** [October 6, 2021, 11:58am UTC](https://discourse.haproxy.org/t/different-tcp-check-for-each-server/6952/3 "2021-10-06T11:58:59Z")

</div>

> [@capflam](#):
>
> `tcp-check expect string-lf role:%[srv_name,word(2,_)]`

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!

---

<div class="post-metadata">

**Author:** ![alexsunny123](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@alexsunny123](https://discourse.haproxy.org/u/alexsunny123)\
**Post date:** [October 11, 2021, 12:23pm UTC](https://discourse.haproxy.org/t/different-tcp-check-for-each-server/6952/4 "2021-10-11T12:23:31Z")

</div>

thanks for the awesome information.

---

<div class="post-metadata">

**Author:** ![alexsunny123](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@alexsunny123](https://discourse.haproxy.org/u/alexsunny123)\
**Post date:** [September 12, 2022, 8:59am UTC](https://discourse.haproxy.org/t/different-tcp-check-for-each-server/6952/5 "2022-09-12T08:59:01Z")

</div>

> [@alexsunny123](#):
>
> thanks for the awesome information.  
> [https://ometv.onl](https://ometv.onl) [https://chatroulette.top](https://chatroulette.top) [https://omegle.wtf](https://omegle.wtf) [https://bazoocam.cam](https://bazoocam.cam)

thanks my issue has been fixed.
